| 1459 | } |
| 1460 | |
| 1461 | VerifiedBlockRef BlockChain::verifyBlock(bytesConstRef _block, std::function<void(Exception&)> const& _onBad, ImportRequirements::value _ir) const |
| 1462 | { |
| 1463 | VerifiedBlockRef res; |
| 1464 | BlockHeader h; |
| 1465 | try |
| 1466 | { |
| 1467 | h = BlockHeader(_block); |
| 1468 | if (!!(_ir & ImportRequirements::PostGenesis) && (!h.parentHash() || h.number() == 0)) |
| 1469 | BOOST_THROW_EXCEPTION(InvalidParentHash() << errinfo_required_h256(h.parentHash()) << errinfo_currentNumber(h.number())); |
| 1470 | |
| 1471 | BlockHeader parent; |
| 1472 | if (!!(_ir & ImportRequirements::Parent)) |
| 1473 | { |
| 1474 | bytes parentHeader(headerData(h.parentHash())); |
| 1475 | if (parentHeader.empty()) |
| 1476 | BOOST_THROW_EXCEPTION(InvalidParentHash() << errinfo_required_h256(h.parentHash()) << errinfo_currentNumber(h.number())); |
| 1477 | parent = BlockHeader(parentHeader, HeaderData, h.parentHash()); |
| 1478 | } |
| 1479 | sealEngine()->verify((_ir & ImportRequirements::ValidSeal) ? Strictness::CheckEverything : Strictness::QuickNonce, h, parent, _block); |
| 1480 | res.info = h; |
| 1481 | } |
| 1482 | catch (Exception& ex) |
| 1483 | { |
| 1484 | ex << errinfo_phase(1); |
| 1485 | ex << errinfo_now(time(0)); |
| 1486 | ex << errinfo_block(_block.toBytes()); |
| 1487 | // only populate extraData if we actually managed to extract it. otherwise, |
| 1488 | // we might be clobbering the existing one. |
| 1489 | if (!h.extraData().empty()) |
| 1490 | ex << errinfo_extraData(h.extraData()); |
| 1491 | if (_onBad) |
| 1492 | _onBad(ex); |
| 1493 | throw; |
| 1494 | } |
| 1495 | |
| 1496 | RLP r(_block); |
| 1497 | unsigned i = 0; |
| 1498 | if (_ir & (ImportRequirements::UncleBasic | ImportRequirements::UncleParent | ImportRequirements::UncleSeals)) |
| 1499 | for (auto const& uncle: r[2]) |
| 1500 | { |
| 1501 | BlockHeader uh(uncle.data(), HeaderData); |
| 1502 | try |
| 1503 | { |
| 1504 | BlockHeader parent; |
| 1505 | if (!!(_ir & ImportRequirements::UncleParent)) |
| 1506 | { |
| 1507 | bytes parentHeader(headerData(uh.parentHash())); |
| 1508 | if (parentHeader.empty()) |
| 1509 | BOOST_THROW_EXCEPTION(InvalidUncleParentHash() << errinfo_required_h256(uh.parentHash()) << errinfo_currentNumber(h.number()) << errinfo_uncleNumber(uh.number())); |
| 1510 | parent = BlockHeader(parentHeader, HeaderData, uh.parentHash()); |
| 1511 | } |
| 1512 | sealEngine()->verify((_ir & ImportRequirements::UncleSeals) ? Strictness::CheckEverything : Strictness::IgnoreSeal, uh, parent); |
| 1513 | } |
| 1514 | catch (Exception& ex) |
| 1515 | { |
| 1516 | ex << errinfo_phase(1); |
| 1517 | ex << errinfo_uncleIndex(i); |
| 1518 | ex << errinfo_now(time(0)); |
no test coverage detected