diff --git a/src/masternodes/mn_rpc.cpp b/src/masternodes/mn_rpc.cpp index 3637c929f1d..5b2a4320146 100644 --- a/src/masternodes/mn_rpc.cpp +++ b/src/masternodes/mn_rpc.cpp @@ -833,8 +833,14 @@ static UniValue clearmempool(const JSONRPCRequest& request) } ).Check(request); + SyncWithValidationInterfaceQueue(); + std::vector vtxid; - mempool.queryHashes(vtxid); + { + LOCK(mempool.cs); + mempool.queryHashes(vtxid); + mempool.clear(); + } { auto locked_chain = pwallet->chain().lock(); @@ -846,11 +852,6 @@ static UniValue clearmempool(const JSONRPCRequest& request) } } - { - LOCK(mempool.cs); - mempool.clear(); - } - UniValue removed(UniValue::VARR); for (const uint256& hash : vtxid) { removed.push_back(hash.ToString()); diff --git a/test/functional/feature_restore_utxo.py b/test/functional/feature_restore_utxo.py index 43b00a2520f..32a026646cb 100755 --- a/test/functional/feature_restore_utxo.py +++ b/test/functional/feature_restore_utxo.py @@ -7,9 +7,7 @@ from test_framework.test_framework import DefiTestFramework -from test_framework.authproxy import JSONRPCException -from test_framework.util import assert_equal -import time +from test_framework.util import assert_equal, disconnect_nodes class TestRestoreUTXOs(DefiTestFramework): def set_test_params(self): @@ -18,46 +16,12 @@ def set_test_params(self): self.extra_args = [['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1'], ['-txnotokens=0', '-amkheight=1', '-bayfrontheight=1']] - def clearmempool(self, node: int): - try: - self.nodes[node].clearmempool() - except JSONRPCException as e: - return False - return True - - def account_to_account(self, node: int, soure, destination): - try: - self.nodes[node].accounttoaccount(soure, {destination: "1@BTC"}) - except JSONRPCException as e: - return False - return True - - def account_to_account_loop(self, node: int, soure, destination): - count = 0 - while not self.account_to_account(node, soure, destination): - if count == 5: - return False - else: - count += 1 - time.sleep(1) - return True - - def rollback(self, count): - block = self.nodes[0].getblockhash(count) - self.nodes[0].invalidateblock(block) + block = self.nodes[1].getblockhash(count) self.nodes[1].invalidateblock(block) - assert(len(self.nodes[0].getrawmempool()) > 0) - assert(len(self.nodes[1].getrawmempool()) > 0) - while not self.clearmempool(0): - pass - while not self.clearmempool(1): - pass - assert_equal(len(self.nodes[0].getrawmempool()), 0) + self.nodes[1].clearmempool() assert_equal(len(self.nodes[1].getrawmempool()), 0) - assert_equal(self.nodes[0].getblockcount(), count - 1) assert_equal(self.nodes[1].getblockcount(), count - 1) - self.sync_blocks() def run_test(self): self.nodes[0].generate(101) @@ -82,6 +46,7 @@ def run_test(self): # Fund account self.nodes[0].accounttoaccount(self.nodes[0].get_genesis_keys().ownerAuthAddress, {node1_source: "1@BTC"}) self.nodes[0].generate(1) + self.sync_blocks() # Check UTXO assert_equal(len(self.nodes[1].listunspent()), 1) @@ -103,25 +68,18 @@ def run_test(self): 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 - node0_utxos = len(self.nodes[0].listunspent()) + disconnect_nodes(self.nodes[0], 1) + block = self.nodes[1].getblockcount() + 1 node1_utxos = len(self.nodes[1].listunspent()) # Test rollbacks - for x in range(50): - assert(self.account_to_account_loop(0, node0_source, node0_destination)) - self.nodes[0].generate(1) - self.sync_blocks() - assert(self.account_to_account_loop(1, node1_source, node1_destination)) - self.nodes[1].generate(1) - self.sync_blocks() + for _ in range(2): + for _ in range(5): + self.nodes[1].accounttoaccount(node1_source, {node1_source: "1@BTC"}) + self.nodes[1].generate(1) + self.nodes[1].accounttoaccount(node1_source, {node1_source: "1@BTC"}) + self.nodes[1].generate(1) self.rollback(block) - assert_equal(len(self.nodes[0].listunspent()), node0_utxos) assert_equal(len(self.nodes[1].listunspent()), node1_utxos) if __name__ == '__main__':