forked from bitcoin/bitcoin
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge bitcoin#24067: wallet: Actually treat (un)confirmed txs as (un)…
…confirmed fac8165 Remove unused checkFinalTx (MarcoFalke) fa272ea wallet: Avoid dropping confirmed coins (MarcoFalke) 888841e interfaces: Remove unused is_final (MarcoFalke) dddd05e qt: Treat unconfirmed txs as unconfirmed (MarcoFalke) Pull request description: The wallet has several issues: ## Unconfirmed txs in the GUI The GUI clumsily attempts to guess if unconfirmed txs are locked until a future time. This is currently based on the locktime only, not nSequence, thus wrong. Fix this by removing the clumsy code and treat all unconfirmed txs as unconfirmed. The GUI already prints whether a tx is in the mempool, in which case the user knows that the tx wasn't locked until a future time. If the tx is not in the mempool, it might be better to report the exact reject reason from the mempool instead of using incorrect heuristics. ## Confirmed txs in the wallet The wallet drops coins that it incorrectly assumes to be locked until a future time, even if they are already confirmed in the chain. This is because the wallet is using the wrong time (adjusted network time) instead of MTP, due to the `-1` default argument of `CheckFinalTx`. The issues are fixed in separate commits and there is even a test. ACKs for top commit: achow101: ACK fac8165 prayank23: reACK bitcoin@fac8165 glozow: code review ACK fac8165, I understand now how this fixes both issues. Tree-SHA512: 210afb855f4c6d903fee49eba6b1a9735d699cf0168b669eabb38178e53b3a522258b7cc669f52489c6cd3e38bf358afde12eef3ba2e2f2ffaeb06b8f652ccd0
- Loading branch information
1 parent
7c0d44c
commit 98ad066
Showing
10 changed files
with
52 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2022 The Bitcoin Core developers | ||
# Distributed under the MIT software license, see the accompanying | ||
# file COPYING or http://www.opensource.org/licenses/mit-license.php. | ||
|
||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.util import assert_equal | ||
|
||
|
||
class WalletLocktimeTest(BitcoinTestFramework): | ||
def set_test_params(self): | ||
self.num_nodes = 1 | ||
|
||
def skip_test_if_missing_module(self): | ||
self.skip_if_no_wallet() | ||
|
||
def run_test(self): | ||
node = self.nodes[0] | ||
|
||
mtp_tip = node.getblockheader(node.getbestblockhash())["mediantime"] | ||
|
||
self.log.info("Get new address with label") | ||
label = "timelock⌛🔓" | ||
address = node.getnewaddress(label=label) | ||
|
||
self.log.info("Send to new address with locktime") | ||
node.send( | ||
outputs={address: 5}, | ||
options={"locktime": mtp_tip - 1}, | ||
) | ||
self.generate(node, 1) | ||
|
||
self.log.info("Check that clock can not change finality of confirmed txs") | ||
amount_before_ad = node.getreceivedbyaddress(address) | ||
amount_before_lb = node.getreceivedbylabel(label) | ||
list_before_ad = node.listreceivedbyaddress(address_filter=address) | ||
list_before_lb = node.listreceivedbylabel(include_empty=False) | ||
balance_before = node.getbalances()["mine"]["trusted"] | ||
coin_before = node.listunspent(maxconf=1) | ||
node.setmocktime(mtp_tip - 1) | ||
assert_equal(node.getreceivedbyaddress(address), amount_before_ad) | ||
assert_equal(node.getreceivedbylabel(label), amount_before_lb) | ||
assert_equal(node.listreceivedbyaddress(address_filter=address), list_before_ad) | ||
assert_equal(node.listreceivedbylabel(include_empty=False), list_before_lb) | ||
assert_equal(node.getbalances()["mine"]["trusted"], balance_before) | ||
assert_equal(node.listunspent(maxconf=1), coin_before) | ||
|
||
|
||
if __name__ == "__main__": | ||
WalletLocktimeTest().main() |