aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/transaction.h
diff options
context:
space:
mode:
authorAndrew Chow <github@achow101.com>2023-11-07 11:23:12 -0500
committerAndrew Chow <github@achow101.com>2023-11-07 11:29:29 -0500
commit3da69c464f16841a5c8d9fcc9c63238ab807d5ff (patch)
treed541cdd461867951a670f6610b941a1999cffcc3 /src/wallet/transaction.h
parent2b3f43b96ef0b674bf350f50f317477b8d3e1e56 (diff)
parentf06016d77d848133fc6568f287bb86b644c9fa69 (diff)
downloadbitcoin-3da69c464f16841a5c8d9fcc9c63238ab807d5ff.tar.xz
Merge bitcoin/bitcoin#28546: wallet: prevent bugs from invalid transaction heights with asserts, comments, and refactoring
f06016d77d848133fc6568f287bb86b644c9fa69 wallet: Add asserts to detect unset transaction height values (Ryan Ofsky) 262a78b13365e5318741187fde431c4974539494 wallet, refactor: Add CWalletTx::updateState function (Ryan Ofsky) Pull request description: Originally, this PR fixed a wallet migration bug that could cause the watchonly wallet created by legacy wallet migration to have incorrect transaction height values. A different fix for the bug was implemented in #28609, but that PR did not add any test coverage that would have caught the bug, and didn't include other changes from this PR intended to prevent problems from invalid transaction heights. This PR adds new asserts to catch invalid transaction heights, which would trigger test failures without bugfix in #28609. This PR also refactors code and adds comments to clarify assumptions and make it less likely a bug from invalid transaction height values would be introduced. ACKs for top commit: achow101: ACK f06016d77d848133fc6568f287bb86b644c9fa69 Sjors: utACK f06016d77d848133fc6568f287bb86b644c9fa69 furszy: Code review ACK f06016d Tree-SHA512: 82657c403724d60354f7676b53bcfcc95bdc5864e051a2eb8bfad09d8ad35615393b2d6b432b46f908def9be37bebded3a55ec9ae19e19371d35897fe842c92e
Diffstat (limited to 'src/wallet/transaction.h')
-rw-r--r--src/wallet/transaction.h8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h
index db858fa5ba..0c28628915 100644
--- a/src/wallet/transaction.h
+++ b/src/wallet/transaction.h
@@ -22,6 +22,10 @@
#include <variant>
#include <vector>
+namespace interfaces {
+class Chain;
+} // namespace interfaces
+
namespace wallet {
//! State of transaction confirmed in a block.
struct TxStateConfirmed {
@@ -326,6 +330,10 @@ public:
template<typename T> const T* state() const { return std::get_if<T>(&m_state); }
template<typename T> T* state() { return std::get_if<T>(&m_state); }
+ //! Update transaction state when attaching to a chain, filling in heights
+ //! of conflicted and confirmed blocks
+ void updateState(interfaces::Chain& chain);
+
bool isAbandoned() const { return state<TxStateInactive>() && state<TxStateInactive>()->abandoned; }
bool isConflicted() const { return state<TxStateConflicted>(); }
bool isInactive() const { return state<TxStateInactive>(); }