From ef12bfcdb68b50ebd72615bcfcd23ec3f9b1f9d5 Mon Sep 17 00:00:00 2001 From: Peter Bushnell Date: Tue, 25 Jan 2022 09:43:57 +0000 Subject: [PATCH] Resolve mempool segfault --- src/txmempool.cpp | 1 + test/functional/feature_restore_utxo.py | 43 +++++++++++++++++++++---- 2 files changed, 37 insertions(+), 7 deletions(-) diff --git a/src/txmempool.cpp b/src/txmempool.cpp index 2cf4fc7981..a2de15f400 100644 --- a/src/txmempool.cpp +++ b/src/txmempool.cpp @@ -604,6 +604,7 @@ void CTxMemPool::_clear() { mapLinks.clear(); mapTx.clear(); + vTxHashes.clear(); mapNextTx.clear(); totalTxSize = 0; cachedInnerUsage = 0; diff --git a/test/functional/feature_restore_utxo.py b/test/functional/feature_restore_utxo.py index ef4af5694a..ccf9f7b3ac 100755 --- a/test/functional/feature_restore_utxo.py +++ b/test/functional/feature_restore_utxo.py @@ -16,6 +16,14 @@ def set_test_params(self): self.extra_args = [['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1'], ['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1']] + def rollback(self, count): + block = self.nodes[0].getblockhash(count) + self.nodes[0].invalidateblock(block) + self.nodes[1].invalidateblock(block) + self.nodes[0].clearmempool() + self.nodes[1].clearmempool() + self.sync_blocks() + def run_test(self): self.nodes[0].generate(101) self.sync_blocks() @@ -28,24 +36,24 @@ def run_test(self): }) self.nodes[0].generate(1) - self.nodes[0].minttokens("1@BTC") + self.nodes[0].minttokens("2@BTC") self.nodes[0].generate(1) - source = self.nodes[1].getnewaddress("", "legacy") + node1_source = self.nodes[1].getnewaddress("", "legacy") # Fund UTXO - self.nodes[0].sendtoaddress(source, 1) + self.nodes[0].sendtoaddress(node1_source, 1) # Fund account - self.nodes[0].accounttoaccount(self.nodes[0].get_genesis_keys().ownerAuthAddress, {source: "1@BTC"}) + self.nodes[0].accounttoaccount(self.nodes[0].get_genesis_keys().ownerAuthAddress, {node1_source: "1@BTC"}) self.nodes[0].generate(1) # Check UTXO assert_equal(len(self.nodes[1].listunspent()), 1) # Create account Tx - destination = self.nodes[1].getnewaddress("", "legacy") - self.nodes[1].accounttoaccount(source, {destination: "1@BTC"}) + node1_destination = self.nodes[1].getnewaddress("", "legacy") + self.nodes[1].accounttoaccount(node1_source, {node1_destination: "1@BTC"}) # Clear mempool self.nodes[1].clearmempool() @@ -54,7 +62,28 @@ def run_test(self): assert_equal(len(self.nodes[1].listunspent()), 1) # Create another account Tx - self.nodes[1].accounttoaccount(source, {destination: "1@BTC"}) + self.nodes[1].accounttoaccount(node1_source, {node1_destination: "1@BTC"}) + + # Clear mempool + self.nodes[1].clearmempool() + + # Set up for rollback tests + node0_source = self.nodes[0].getnewaddress("", "legacy") + node0_destination = self.nodes[0].getnewaddress("", "legacy") + self.nodes[0].accounttoaccount(self.nodes[0].get_genesis_keys().ownerAuthAddress, {node0_source: "1@BTC"}) + self.nodes[0].generate(1) + self.sync_blocks() + block = self.nodes[0].getblockcount() + 1 + + # Test rollbacks + for x in range(50): + self.nodes[0].accounttoaccount(node0_source, {node0_destination: "1@BTC"}) + self.nodes[0].generate(1) + self.sync_blocks() + self.nodes[1].accounttoaccount(node1_source, {node1_destination: "1@BTC"}) + self.nodes[1].generate(1) + self.sync_blocks() + self.rollback(block) if __name__ == '__main__': TestRestoreUTXOs().main()