From 2a12c7b57b49475514810db171baf3ac25781b51 Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Tue, 25 Jan 2022 16:13:02 -0500 Subject: [PATCH] Merge bitcoin/bitcoin#24067: wallet: Actually treat (un)confirmed txs as (un)confirmed fac816544317cee6553d60cb0f5f24f6f9ec98de Remove unused checkFinalTx (MarcoFalke) fa272eab44553df9b0bed3ca20caf2a7bd193680 wallet: Avoid dropping confirmed coins (MarcoFalke) 888841ea8d38fc059ca06ef67af7f31f8d8418a4 interfaces: Remove unused is_final (MarcoFalke) dddd05e7a3389fcbd90bb4acdfe1f59945d9f381 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 fac816544317cee6553d60cb0f5f24f6f9ec98de prayank23: reACK https://github.com/bitcoin/bitcoin/pull/24067/commits/fac816544317cee6553d60cb0f5f24f6f9ec98de glozow: code review ACK fac8165443, I understand now how this fixes both issues. Tree-SHA512: 210afb855f4c6d903fee49eba6b1a9735d699cf0168b669eabb38178e53b3a522258b7cc669f52489c6cd3e38bf358afde12eef3ba2e2f2ffaeb06b8f652ccd0 --- src/interfaces/chain.h | 3 -- src/interfaces/wallet.h | 1 - src/node/interfaces.cpp | 5 --- src/qt/transactiondesc.cpp | 9 ----- src/qt/transactionrecord.cpp | 15 +------ src/qt/transactionrecord.h | 2 - src/qt/transactiontablemodel.cpp | 9 ----- src/wallet/interfaces.cpp | 1 - src/wallet/rpcwallet.cpp | 4 +- src/wallet/wallet.cpp | 64 ++++++++++++++++++++++++++++++ test/functional/test_runner.py | 1 + test/functional/wallet_timelock.py | 50 +++++++++++++++++++++++ 12 files changed, 118 insertions(+), 46 deletions(-) create mode 100755 test/functional/wallet_timelock.py diff --git a/src/interfaces/chain.h b/src/interfaces/chain.h index bdaa621a975f99..ecaffb1ef44fac 100644 --- a/src/interfaces/chain.h +++ b/src/interfaces/chain.h @@ -133,9 +133,6 @@ class Chain //! or one of its ancestors. virtual std::optional findLocatorFork(const CBlockLocator& locator) = 0; - //! Check if transaction will be final given chain height current time. - virtual bool checkFinalTx(const CTransaction& tx) = 0; - //! Check if transaction is locked by InstantSendManager virtual bool isInstantSendLockedTx(const uint256& hash) = 0; diff --git a/src/interfaces/wallet.h b/src/interfaces/wallet.h index 57a01676a32d9e..774ee255162740 100644 --- a/src/interfaces/wallet.h +++ b/src/interfaces/wallet.h @@ -424,7 +424,6 @@ struct WalletTxStatus int depth_in_main_chain; unsigned int time_received; uint32_t lock_time; - bool is_final; bool is_trusted; bool is_abandoned; bool is_coinbase; diff --git a/src/node/interfaces.cpp b/src/node/interfaces.cpp index 1a25271431f0b5..678f295aa91feb 100644 --- a/src/node/interfaces.cpp +++ b/src/node/interfaces.cpp @@ -771,11 +771,6 @@ class ChainImpl : public Chain } return std::nullopt; } - bool checkFinalTx(const CTransaction& tx) override - { - LOCK(cs_main); - return CheckFinalTxAtTip(*Assert(m_node.chainman->ActiveChain().Tip()), tx); - } bool isInstantSendLockedTx(const uint256& hash) override { if (m_node.llmq_ctx == nullptr || m_node.llmq_ctx->isman == nullptr) return false; diff --git a/src/qt/transactiondesc.cpp b/src/qt/transactiondesc.cpp index 9587e0fac20eb7..98df0a08a7cb22 100644 --- a/src/qt/transactiondesc.cpp +++ b/src/qt/transactiondesc.cpp @@ -18,7 +18,6 @@ #include #include #include -#include