Skip to content

Commit fa272ea

Browse files
author
MarcoFalke
committed
wallet: Avoid dropping confirmed coins
1 parent 888841e commit fa272ea

File tree

6 files changed

+55
-10
lines changed

6 files changed

+55
-10
lines changed

src/wallet/receive.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,6 @@ bool CachedTxIsFromMe(const CWallet& wallet, const CWalletTx& wtx, const isminef
279279
bool CachedTxIsTrusted(const CWallet& wallet, const CWalletTx& wtx, std::set<uint256>& trusted_parents)
280280
{
281281
AssertLockHeld(wallet.cs_wallet);
282-
// Quick answer in most cases
283-
if (!wallet.chain().checkFinalTx(*wtx.tx)) return false;
284282
int nDepth = wallet.GetTxDepthInMainChain(wtx);
285283
if (nDepth >= 1) return true;
286284
if (nDepth < 0) return false;

src/wallet/rpc/coins.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ static CAmount GetReceived(const CWallet& wallet, const UniValue& params, bool b
6060
if (depth < min_depth
6161
// Coinbase with less than 1 confirmation is no longer in the main chain
6262
|| (wtx.IsCoinBase() && (depth < 1 || !include_coinbase))
63-
|| (wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase)
64-
|| !wallet.chain().checkFinalTx(*wtx.tx)) {
63+
|| (wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase))
64+
{
6565
continue;
6666
}
6767

src/wallet/rpc/transactions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ static UniValue ListReceived(const CWallet& wallet, const UniValue& params, cons
114114

115115
// Coinbase with less than 1 confirmation is no longer in the main chain
116116
if ((wtx.IsCoinBase() && (nDepth < 1 || !include_coinbase))
117-
|| (wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase)
118-
|| !wallet.chain().checkFinalTx(*wtx.tx)) {
117+
|| (wallet.IsTxImmatureCoinBase(wtx) && !include_immature_coinbase))
118+
{
119119
continue;
120120
}
121121

src/wallet/spend.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,6 @@ void AvailableCoins(const CWallet& wallet, std::vector<COutput>& vCoins, const C
105105
const uint256& wtxid = entry.first;
106106
const CWalletTx& wtx = entry.second;
107107

108-
if (!wallet.chain().checkFinalTx(*wtx.tx)) {
109-
continue;
110-
}
111-
112108
if (wallet.IsTxImmatureCoinBase(wtx))
113109
continue;
114110

test/functional/test_runner.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,7 @@
308308
'feature_coinstatsindex.py --legacy-wallet',
309309
'feature_coinstatsindex.py --descriptors',
310310
'wallet_orphanedreward.py',
311+
'wallet_timelock.py',
311312
'p2p_node_network_limited.py',
312313
'p2p_permissions.py',
313314
'feature_blocksdir.py',

test/functional/wallet_timelock.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#!/usr/bin/env python3
2+
# Copyright (c) 2022 The Bitcoin Core developers
3+
# Distributed under the MIT software license, see the accompanying
4+
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
5+
6+
from test_framework.test_framework import BitcoinTestFramework
7+
from test_framework.util import assert_equal
8+
9+
10+
class WalletLocktimeTest(BitcoinTestFramework):
11+
def set_test_params(self):
12+
self.num_nodes = 1
13+
14+
def skip_test_if_missing_module(self):
15+
self.skip_if_no_wallet()
16+
17+
def run_test(self):
18+
node = self.nodes[0]
19+
20+
mtp_tip = node.getblockheader(node.getbestblockhash())["mediantime"]
21+
22+
self.log.info("Get new address with label")
23+
label = "timelock⌛🔓"
24+
address = node.getnewaddress(label=label)
25+
26+
self.log.info("Send to new address with locktime")
27+
node.send(
28+
outputs={address: 5},
29+
options={"locktime": mtp_tip - 1},
30+
)
31+
self.generate(node, 1)
32+
33+
self.log.info("Check that clock can not change finality of confirmed txs")
34+
amount_before_ad = node.getreceivedbyaddress(address)
35+
amount_before_lb = node.getreceivedbylabel(label)
36+
list_before_ad = node.listreceivedbyaddress(address_filter=address)
37+
list_before_lb = node.listreceivedbylabel(include_empty=False)
38+
balance_before = node.getbalances()["mine"]["trusted"]
39+
coin_before = node.listunspent(maxconf=1)
40+
node.setmocktime(mtp_tip - 1)
41+
assert_equal(node.getreceivedbyaddress(address), amount_before_ad)
42+
assert_equal(node.getreceivedbylabel(label), amount_before_lb)
43+
assert_equal(node.listreceivedbyaddress(address_filter=address), list_before_ad)
44+
assert_equal(node.listreceivedbylabel(include_empty=False), list_before_lb)
45+
assert_equal(node.getbalances()["mine"]["trusted"], balance_before)
46+
assert_equal(node.listunspent(maxconf=1), coin_before)
47+
48+
49+
if __name__ == "__main__":
50+
WalletLocktimeTest().main()

0 commit comments

Comments
 (0)