mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-10 22:18:54 +01:00
Require callers of AcceptBlockHeader() to perform anti-dos checks
In order to prevent memory DoS, we must ensure that we don't accept a new header into memory until we've performed anti-DoS checks, such as verifying that the header is part of a sufficiently high work chain. This commit adds a new argument to AcceptBlockHeader() so that we can ensure that all call-sites which might cause a new header to be accepted into memory have to grapple with the question of whether the header is safe to accept, or needs further validation. This patch also fixes two places where low-difficulty-headers could have been processed without such validation (processing an unrequested block from the network, and processing a compact block). Credit to Niklas Gögge for noticing this issue, and thanks to Sjors Provoost for test code.
This commit is contained in:
@@ -100,7 +100,7 @@ std::shared_ptr<CBlock> MinerTestingSetup::FinalizeBlock(std::shared_ptr<CBlock>
|
||||
// submit block header, so that miner can get the block height from the
|
||||
// global state and the node has the topology of the chain
|
||||
BlockValidationState ignored;
|
||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({pblock->GetBlockHeader()}, ignored));
|
||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlockHeaders({pblock->GetBlockHeader()}, true, ignored));
|
||||
|
||||
return pblock;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
|
||||
|
||||
bool ignored;
|
||||
// Connect the genesis block and drain any outstanding events
|
||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(std::make_shared<CBlock>(Params().GenesisBlock()), true, &ignored));
|
||||
BOOST_CHECK(Assert(m_node.chainman)->ProcessNewBlock(std::make_shared<CBlock>(Params().GenesisBlock()), true, true, &ignored));
|
||||
SyncWithValidationInterfaceQueue();
|
||||
|
||||
// subscribe to events (this subscriber will validate event ordering)
|
||||
@@ -179,13 +179,13 @@ BOOST_AUTO_TEST_CASE(processnewblock_signals_ordering)
|
||||
FastRandomContext insecure;
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
auto block = blocks[insecure.randrange(blocks.size() - 1)];
|
||||
Assert(m_node.chainman)->ProcessNewBlock(block, true, &ignored);
|
||||
Assert(m_node.chainman)->ProcessNewBlock(block, true, true, &ignored);
|
||||
}
|
||||
|
||||
// to make sure that eventually we process the full chain - do it here
|
||||
for (const auto& block : blocks) {
|
||||
if (block->vtx.size() == 1) {
|
||||
bool processed = Assert(m_node.chainman)->ProcessNewBlock(block, true, &ignored);
|
||||
bool processed = Assert(m_node.chainman)->ProcessNewBlock(block, true, true, &ignored);
|
||||
assert(processed);
|
||||
}
|
||||
}
|
||||
@@ -224,7 +224,7 @@ BOOST_AUTO_TEST_CASE(mempool_locks_reorg)
|
||||
{
|
||||
bool ignored;
|
||||
auto ProcessBlock = [&](std::shared_ptr<const CBlock> block) -> bool {
|
||||
return Assert(m_node.chainman)->ProcessNewBlock(block, /*force_processing=*/true, /*new_block=*/&ignored);
|
||||
return Assert(m_node.chainman)->ProcessNewBlock(block, /*force_processing=*/true, /*min_pow_checked=*/true, /*new_block=*/&ignored);
|
||||
};
|
||||
|
||||
// Process all mined blocks
|
||||
|
||||
Reference in New Issue
Block a user