Skip to content

Commit 932f118

Browse files
committed
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.
1 parent 3d9c70c commit 932f118

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

src/validation.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,7 +3115,7 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
31153115
// process an unrequested block if it's new and has enough work to
31163116
// advance our tip, and isn't too many blocks ahead.
31173117
bool fAlreadyHave = pindex->nStatus & BLOCK_HAVE_DATA;
3118-
bool fHasMoreWork = (chainActive.Tip() ? pindex->nChainWork > chainActive.Tip()->nChainWork : true);
3118+
bool fHasMoreOrSameWork = (chainActive.Tip() ? pindex->nChainWork >= chainActive.Tip()->nChainWork : true);
31193119
// Blocks that are too out-of-order needlessly limit the effectiveness of
31203120
// pruning, because pruning will not delete block files that contain any
31213121
// blocks which are too close in height to the tip. Apply this test
@@ -3132,9 +3132,9 @@ static bool AcceptBlock(const std::shared_ptr<const CBlock>& pblock, CValidation
31323132
// and unrequested blocks.
31333133
if (fAlreadyHave) return true;
31343134
if (!fRequested) { // If we didn't ask for it:
3135-
if (pindex->nTx != 0) return true; // This is a previously-processed block that was pruned
3136-
if (!fHasMoreWork) return true; // Don't process less-work chains
3137-
if (fTooFarAhead) return true; // Block height is too high
3135+
if (pindex->nTx != 0) return true; // This is a previously-processed block that was pruned
3136+
if (!fHasMoreOrSameWork) return true; // Don't process less-work chains
3137+
if (fTooFarAhead) return true; // Block height is too high
31383138

31393139
// Protect against DoS attacks from low-work chains.
31403140
// If our tip is behind, a peer could try to send us

test/functional/p2p-acceptblock.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ def run_test(self):
142142
assert(tip_entry_found)
143143

144144
# But this block should be accepted by node since it has equal work.
145-
# TODO: We currently drop this block but likely shouldn't
146-
#self.nodes[0].getblock(block_h2f.hash)
145+
self.nodes[0].getblock(block_h2f.hash)
147146
self.log.info("Second height 2 block accepted, but not reorg'ed to")
148147

149148
# 4b. Now send another block that builds on the forking chain.
@@ -215,7 +214,6 @@ def run_test(self):
215214

216215
test_node.wait_for_verack()
217216
test_node.send_message(msg_block(block_h1f))
218-
test_node.send_message(msg_block(block_h2f)) # This should not be required
219217

220218
test_node.sync_with_ping()
221219
assert_equal(self.nodes[0].getblockcount(), 2)
@@ -239,7 +237,6 @@ def run_test(self):
239237

240238
# 7. Send the missing block for the third time (now it is requested)
241239
test_node.send_message(msg_block(block_h1f))
242-
test_node.send_message(msg_block(block_h2f)) # This should not be required
243240

244241
test_node.sync_with_ping()
245242
assert_equal(self.nodes[0].getblockcount(), 290)

0 commit comments

Comments
 (0)