diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index ea52ee6cad..464411d536 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -774,6 +774,8 @@ void CWallet::AddToSpends(const COutPoint& outpoint, const uint256& wtxid) mapTxSpends.insert(std::make_pair(outpoint, wtxid)); setWalletUTXO.erase(outpoint); + setLockedCoins.erase(outpoint); + std::pair range; range = mapTxSpends.equal_range(outpoint); SyncMetaData(range); diff --git a/test/functional/wallet.py b/test/functional/wallet.py index e092619c92..2967220421 100755 --- a/test/functional/wallet.py +++ b/test/functional/wallet.py @@ -114,6 +114,15 @@ class WalletTest(BitcoinTestFramework): self.nodes[2].lockunspent, False, [{"txid": unspent_0["txid"], "vout": 999}]) + # An output should be unlocked when spent + unspent_0 = self.nodes[1].listunspent()[0] + self.nodes[1].lockunspent(False, [unspent_0]) + tx = self.nodes[1].createrawtransaction([unspent_0], { self.nodes[1].getnewaddress() : 1 }) + tx = self.nodes[1].fundrawtransaction(tx)['hex'] + tx = self.nodes[1].signrawtransactionwithwallet(tx)["hex"] + self.nodes[1].sendrawtransaction(tx) + assert_equal(len(self.nodes[1].listlockunspent()), 0) + # Have node1 generate 100 blocks (so node0 can recover the fee) self.nodes[1].generate(100) self.sync_all(self.nodes[0:3])