test: Avoid generating a chain fork in `mempool_packages` RPC test

There was a race condition here between the block generated by node 0
being broadcast to node 1, and being invalidated by node 0. Due to the
changes we made to the difficulty adjustment algorithm, the invalidated
block and the block replacing it generated by node 0 would have the same
chain work; thus if node 1 observed the invalidated block, it would
never reorg to the replacement block.

We fix this by having node 0 reconsider the invalidated block before
generating its next block. This avoids the chain fork, and also clears
the mempool to provide better separation between test stages.

Co-authored-by: Daira Hopwood <daira@jacaranda.org>
This commit is contained in:
Jack Grigg 2023-04-18 17:00:54 +00:00
parent 786d8e32e1
commit 8342e350b1
1 changed files with 8 additions and 2 deletions

View File

@ -103,9 +103,10 @@ class MempoolPackagesTest(BitcoinTestFramework):
print("too-long-ancestor-chain successfully rejected")
# Check that prioritising a tx before it's added to the mempool works
self.nodes[0].generate(1)
[blockhash] = self.nodes[0].generate(1)
assert_equal(self.nodes[0].getrawmempool(True), {})
self.nodes[0].prioritisetransaction(chain[-1], None, 2000)
self.nodes[0].invalidateblock(self.nodes[0].getbestblockhash())
self.nodes[0].invalidateblock(blockhash)
mempool = self.nodes[0].getrawmempool(True)
descendant_fees = 0
@ -117,6 +118,11 @@ class MempoolPackagesTest(BitcoinTestFramework):
# TODO: check that node1's mempool is as expected
# Reconsider the above block to clear the mempool again before the next test phase.
self.nodes[0].reconsiderblock(blockhash)
assert_equal(self.nodes[0].getbestblockhash(), blockhash)
assert_equal(self.nodes[0].getrawmempool(True), {})
# TODO: test ancestor size limits
# Now test descendant chain limits