Skip to content

Commit

Permalink
Resolve mempool segfault (#1061)
Browse files Browse the repository at this point in the history
Co-authored-by: Prasanna Loganathar <[email protected]>
  • Loading branch information
Bushstar and prasannavl authored Jan 25, 2022
1 parent a9bb158 commit 2148a9b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/txmempool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,7 @@ void CTxMemPool::_clear()
{
mapLinks.clear();
mapTx.clear();
vTxHashes.clear();
mapNextTx.clear();
totalTxSize = 0;
cachedInnerUsage = 0;
Expand Down
43 changes: 36 additions & 7 deletions test/functional/feature_restore_utxo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()

0 comments on commit 2148a9b

Please sign in to comment.