actually ended up being pretty easy to remove for a time-based timelock
0diff --git a/test/functional/mempool_reorg.py b/test/functional/mempool_reorg.py
1index 3906117e8b..0f6124f9ab 100755
2--- a/test/functional/mempool_reorg.py
3+++ b/test/functional/mempool_reorg.py
4@@ -28,5 +28,6 @@ from test_framework.blocktools import (
5
6 # Number of blocks to create in temporary blockchain branch for reorg testing
7-FORK_LENGTH = 10
8+# Needs to be long enough to allow MTP to move arbitrarily forward
9+FORK_LENGTH = 20
10
11 class MempoolCoinbaseTest(BitcoinTestFramework):
12@@ -125,4 +126,8 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
13 wallet = self.wallet
14
15+ # Prevent clock from moving blocks further forward in time
16+ now = int(time.time())
17+ self.nodes[0].setmocktime(now)
18+
19 # Start with a 200 block chain
20 assert_equal(self.nodes[0].getblockcount(), 200)
21@@ -148,9 +153,11 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
22 spend_3 = wallet.create_self_transfer(utxo_to_spend=utxo_3)
23
24- self.log.info("Create another transaction which is time-locked to two blocks in the future")
25+ future = now + 300
26+
27+ self.log.info("Create another transaction which is time-locked to 300 seconds in the future")
28 utxo = wallet.get_utxo(txid=coinbase_txids[0])
29 timelock_tx = wallet.create_self_transfer(
30 utxo_to_spend=utxo,
31- locktime=self.nodes[0].getblockcount() + 2,
32+ locktime=future,
33 )['hex']
34
35@@ -174,7 +181,13 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
36 self.log.info("Generate a block")
37
38- # Prep for fork
39+ # Prep for fork, only go FORK_LENGTH seconds into the MTP future max
40 fork_blocks = create_empty_fork(self.nodes[0], fork_length=FORK_LENGTH)
41- self.generate(self.nodes[0], 1)
42+
43+ # Jump node and MTP 300 seconds and generate a slighty weaker chain than reorg one
44+ self.nodes[0].setmocktime(future)
45+ self.generate(self.nodes[0], FORK_LENGTH - 1)
46+ block_time = self.nodes[0].getblock(self.nodes[0].getbestblockhash())['time']
47+ assert(block_time >= now + 300)
48+
49 # generate() implicitly syncs blocks, so that peer 1 gets the block before timelock_tx
50 # Otherwise, peer 1 would put the timelock_tx in m_lazy_recent_rejects
51@@ -193,7 +206,11 @@ class MempoolCoinbaseTest(BitcoinTestFramework):
52 self.sync_blocks()
53
54+ # We went backwards in time to boot timelock_tx_id
55+ fork_block_time = self.nodes[0].getblock(self.nodes[0].getbestblockhash())['time']
56+ assert fork_block_time < block_time
57+
58 self.log.info("The time-locked transaction is now too immature and has been removed from the mempool")
59 self.log.info("spend_3_1 has been re-orged out of the chain and is back in the mempool")
60- assert_equal(set(self.nodes[0].getrawmempool()), {spend_1_id, spend_2_1_id, spend_3_1_id, timelock_tx_id})
61+ assert_equal(set(self.nodes[0].getrawmempool()), {spend_1_id, spend_2_1_id, spend_3_1_id})
62
63 self.log.info("Use invalidateblock to re-org back and make all those coinbase spends immature/invalid")