Skip to content

Commit ca4a380

Browse files
test: add coverage for UB caused by FindMostWorkChain
when pruned node2 finally receives the blocks from node0, node2 will process duplicate entires in ReceivedBlockTransactions twice but it will only insert into setBlockIndexCandidates if the block has more work that the current chain tip. the duplicate entries in m_blocks_unlinked in this test are from height 1171 to 1294. before this commit - we invalidated height 1320 and chain tip became 1319. so we won't add duplicate entries (all have <1319) into setBlockIndexCandidates and won't have coverage for this UB scenario. with this commit - we invalidate height 1295 and chain tip became 1294. so we will process the duplicate entry 1294 in m_blocks_unlinked and have coverage for this UB. Co-authored-by: Martin Zumsande <[email protected]>
1 parent c787b3b commit ca4a380

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

‎test/functional/feature_pruning.py‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ def reorg_back(self):
236236
self.nodes[2].getblock(self.nodes[2].getblockhash(self.forkheight))
237237

238238
first_reorg_height = self.nodes[2].getblockcount()
239-
curchainhash = self.nodes[2].getblockhash(self.mainchainheight)
240-
self.nodes[2].invalidateblock(curchainhash)
239+
block_hash_1295 = self.nodes[2].getblockhash(1295)
240+
self.nodes[2].invalidateblock(block_hash_1295)
241241
goalbestheight = self.mainchainheight
242242
goalbesthash = self.mainchainhash2
243243

@@ -252,7 +252,7 @@ def reorg_back(self):
252252
if self.nodes[2].getblockcount() < self.mainchainheight:
253253
blocks_to_mine = first_reorg_height + 1 - self.mainchainheight
254254
self.log.info(f"Rewind node 0 to prev main chain to mine longer chain to trigger redownload. Blocks needed: {blocks_to_mine}")
255-
self.nodes[0].invalidateblock(curchainhash)
255+
self.nodes[0].invalidateblock(block_hash_1295)
256256
assert_equal(self.nodes[0].getblockcount(), self.mainchainheight)
257257
assert_equal(self.nodes[0].getbestblockhash(), self.mainchainhash2)
258258
goalbesthash = self.generate(self.nodes[0], blocks_to_mine, sync_fun=self.no_op)[-1]

0 commit comments

Comments
 (0)