Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resolve mempool segfault #1061

Merged
merged 2 commits into from
Jan 25, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()