Accept unrequested blocks with work equal to our tip

This is a simple change that makes our accept requirements the
same as our request requirements, (ever so slightly) further
decoupling our consensus logic from our FindNextBlocksToDownload
logic in net_processing.
pull/476/merge
Matt Corallo 7 years ago
parent 3d9c70ca0f
commit 932f118e6a

@ -3115,7 +3115,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
// process an unrequested block if it's new and has enough work to // process an unrequested block if it's new and has enough work to
// advance our tip, and isn't too many blocks ahead. // advance our tip, and isn't too many blocks ahead.
bool fAlreadyHave = pindex->nStatus & BLOCK_HAVE_DATA; bool fAlreadyHave = pindex->nStatus & BLOCK_HAVE_DATA;
bool fHasMoreWork = (chainActive.Tip() ? pindex->nChainWork > chainActive.Tip()->nChainWork : true); bool fHasMoreOrSameWork = (chainActive.Tip() ? pindex->nChainWork >= chainActive.Tip()->nChainWork : true);
// Blocks that are too out-of-order needlessly limit the effectiveness of // Blocks that are too out-of-order needlessly limit the effectiveness of
// pruning, because pruning will not delete block files that contain any // pruning, because pruning will not delete block files that contain any
// blocks which are too close in height to the tip. Apply this test // blocks which are too close in height to the tip. Apply this test
@ -3133,7 +3133,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
if (fAlreadyHave) return true; if (fAlreadyHave) return true;
if (!fRequested) { // If we didn't ask for it: if (!fRequested) { // If we didn't ask for it:
if (pindex->nTx != 0) return true; // This is a previously-processed block that was pruned if (pindex->nTx != 0) return true; // This is a previously-processed block that was pruned
if (!fHasMoreWork) return true; // Don't process less-work chains if (!fHasMoreOrSameWork) return true; // Don't process less-work chains
if (fTooFarAhead) return true; // Block height is too high if (fTooFarAhead) return true; // Block height is too high
// Protect against DoS attacks from low-work chains. // Protect against DoS attacks from low-work chains.

@ -142,8 +142,7 @@ class AcceptBlockTest(BitcoinTestFramework):
assert(tip_entry_found) assert(tip_entry_found)
# But this block should be accepted by node since it has equal work. # But this block should be accepted by node since it has equal work.
# TODO: We currently drop this block but likely shouldn't self.nodes[0].getblock(block_h2f.hash)
#self.nodes[0].getblock(block_h2f.hash)
self.log.info("Second height 2 block accepted, but not reorg'ed to") self.log.info("Second height 2 block accepted, but not reorg'ed to")
# 4b. Now send another block that builds on the forking chain. # 4b. Now send another block that builds on the forking chain.
@ -215,7 +214,6 @@ class AcceptBlockTest(BitcoinTestFramework):
test_node.wait_for_verack() test_node.wait_for_verack()
test_node.send_message(msg_block(block_h1f)) test_node.send_message(msg_block(block_h1f))
test_node.send_message(msg_block(block_h2f)) # This should not be required
test_node.sync_with_ping() test_node.sync_with_ping()
assert_equal(self.nodes[0].getblockcount(), 2) assert_equal(self.nodes[0].getblockcount(), 2)
@ -239,7 +237,6 @@ class AcceptBlockTest(BitcoinTestFramework):
# 7. Send the missing block for the third time (now it is requested) # 7. Send the missing block for the third time (now it is requested)
test_node.send_message(msg_block(block_h1f)) test_node.send_message(msg_block(block_h1f))
test_node.send_message(msg_block(block_h2f)) # This should not be required
test_node.sync_with_ping() test_node.sync_with_ping()
assert_equal(self.nodes[0].getblockcount(), 290) assert_equal(self.nodes[0].getblockcount(), 290)

Loading…
Cancel
Save