From 6ba8f30e7b0b0bbb365fcca95b0c33af31f28ef4 Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Wed, 6 Dec 2017 11:49:37 -0500 Subject: [PATCH 1/2] don't attempt mempool entry for wallet transactions on startup if already in mempool --- src/wallet/wallet.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ee1894501..cb81ec37f 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -4114,6 +4114,11 @@ int CMerkleTx::GetBlocksToMaturity() const bool CWalletTx::AcceptToMemoryPool(const CAmount& nAbsurdFee, CValidationState& state) { + // Quick check to avoid re-setting fInMempool to false + if (mempool.exists(tx->GetHash())) { + return false; + } + // We must set fInMempool here - while it will be re-set to true by the // entered-mempool callback, if we did not there would be a race where a // user could call sendmoney in a loop and hit spurious out of funds errors From 6697a7089441deded836332e7ce3b4a1a9a3cbcd Mon Sep 17 00:00:00 2001 From: Gregory Sanders Date: Wed, 6 Dec 2017 12:08:40 -0500 Subject: [PATCH 2/2] add test for unconfirmed balance between restarts --- test/functional/mempool_persist.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/functional/mempool_persist.py b/test/functional/mempool_persist.py index 92f66be2f..31a96ec60 100755 --- a/test/functional/mempool_persist.py +++ b/test/functional/mempool_persist.py @@ -57,21 +57,27 @@ class MempoolPersistTest(BitcoinTestFramework): self.log.debug("Send 5 transactions from node2 (to its own address)") for i in range(5): self.nodes[2].sendtoaddress(self.nodes[2].getnewaddress(), Decimal("10")) + node2_balance = self.nodes[2].getbalance() self.sync_all() self.log.debug("Verify that node0 and node1 have 5 transactions in their mempools") assert_equal(len(self.nodes[0].getrawmempool()), 5) assert_equal(len(self.nodes[1].getrawmempool()), 5) - self.log.debug("Stop-start node0 and node1. Verify that node0 has the transactions in its mempool and node1 does not.") + self.log.debug("Stop-start the nodes. Verify that node0 has the transactions in its mempool and node1 does not. Verify that node2 calculates its balance correctly after loading wallet transactions.") self.stop_nodes() self.start_node(0) self.start_node(1) + self.start_node(2) # Give bitcoind a second to reload the mempool time.sleep(1) wait_until(lambda: len(self.nodes[0].getrawmempool()) == 5) + wait_until(lambda: len(self.nodes[2].getrawmempool()) == 5) assert_equal(len(self.nodes[1].getrawmempool()), 0) + # Verify accounting of mempool transactions after restart is correct + assert_equal(node2_balance, self.nodes[2].getbalance()) + self.log.debug("Stop-start node0 with -persistmempool=0. Verify that it doesn't load its mempool.dat file.") self.stop_nodes() self.start_node(0, extra_args=["-persistmempool=0"])