-
Notifications
You must be signed in to change notification settings - Fork 37.8k
wallet: Add TxStateString function for debugging and logging #28544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsReviewers, this pull request conflicts with the following ones:
If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK dc1520b
I'm slightly more inclined to encapsulate the string representation into a toString()
per struct so we don't have to touch different functions when adding a new tx state. But.. that could be just me. Not blocking at all.
diff --git a/src/wallet/transaction.h b/src/wallet/transaction.h
--- a/src/wallet/transaction.h (revision 42056e6a2944b3f61aed376b3317551ca1241971)
+++ b/src/wallet/transaction.h (date 1695826678557)
@@ -29,10 +29,13 @@
int position_in_block;
explicit TxStateConfirmed(const uint256& block_hash, int height, int index) : confirmed_block_hash(block_hash), confirmed_block_height(height), position_in_block(index) {}
+
+ std::string toString() const { return strprintf("Confirmed (block=%s, index=%i)", confirmed_block_hash.ToString(), position_in_block); }
};
//! State of transaction added to mempool.
struct TxStateInMempool {
+ std::string toString() const { return strprintf("InMempool"); }
};
//! State of rejected transaction that conflicts with a confirmed block.
@@ -41,6 +44,8 @@
int conflicting_block_height;
explicit TxStateConflicted(const uint256& block_hash, int height) : conflicting_block_hash(block_hash), conflicting_block_height(height) {}
+
+ std::string toString() const { return strprintf("Conflicted (block=%s)", conflicting_block_hash.ToString()); }
};
//! State of transaction not confirmed or conflicting with a known block and
@@ -51,6 +56,8 @@
bool abandoned;
explicit TxStateInactive(bool abandoned = false) : abandoned(abandoned) {}
+
+ std::string toString() const { return strprintf("Inactive (abandoned=%i)", abandoned); }
};
//! State of transaction loaded in an unrecognized state with unexpected hash or
@@ -62,6 +69,8 @@
int index;
TxStateUnrecognized(const uint256& block_hash, int index) : block_hash(block_hash), index(index) {}
+
+ std::string toString() const { return strprintf("Unrecognized (block=%s, index=%i)", block_hash.ToString(), index); }
};
//! All possible CWalletTx states
@@ -109,6 +118,11 @@
}, state);
}
+//! Return TxState as a string for logging or debugging.
+static inline std::string TxStateString(const TxState& state)
+{
+ return std::visit([](const auto& s) { return s.toString(); }, state);
+}
/**
* Cachable amount subdivided into watchonly and spendable parts.
Co-authored-by: furszy <matiasfurszyfer@protonmail.com>
dc1520b
to
8a553c9
Compare
re: #28544 (review)
Agree this is nicer. It also lets the function work with Updated dc1520b -> 8a553c9 ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code ACK 8a553c9
utACK 8a553c9 |
ACK 8a553c9 |
… and logging 8a553c9 wallet: Add TxStateString function for debugging and logging (Ryan Ofsky) Pull request description: I found this useful while debugging silent conflict between bitcoin#10102 and bitcoin#27469 recently ACKs for top commit: ishaanam: utACK 8a553c9 achow101: ACK 8a553c9 furszy: Code ACK 8a553c9 Tree-SHA512: 87965c66bcb59a21e7639878bb567e583a0e624735721ff7ad1104eed6bb9fba60607d0e3de7be3304232b3a55f48bab7039ea9c26b0e81963e59f9acd94f666
I found this useful while debugging silent conflict between #10102 and #27469 recently