Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. External sites
ReviewsSee the guideline and AI policy for information on the review process.
If your review is incorrectly listed, please copy-paste 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. |
6bbb69a to
6484500
Compare
|
🚧 At least one of the CI tasks failed. HintsTry to run the tests locally, according to the documentation. However, a CI failure may still
Leave a comment here, if you need help tracking down a confusing failure. |
|
concept ACK |
|
Concept ACK |
1 similar comment
|
Concept ACK |
fametrano
left a comment
There was a problem hiding this comment.
Concept ACK
One issue should be fixed before merge: rebroadcastwallettx fails with code -1 and an empty message when the transaction is out of the mempool and its feerate is above the wallet's -maxfeerate.
I ran the RPC on regtest at 6484500. Other mempool rejections keep their reason, such as "bad-txns-inputs-missingorspent" for a child whose parent expired. The empty message shows up when a user lowers -maxfeerate to 20 sat/vB and restarts without mempool.dat. Our own 50 sat/vB child of an incoming payment then stays out of the mempool, and the RPC returns {"code": -1, "message": ""}. For the same transaction, sendrawtransaction with maxfeerate=0.0002 returns -25 "Fee rate exceeds maximum configured by user (maxfeerate)".
The cause is that Chain::broadcastTransaction returns only a bool, and BroadcastTransaction sets no error string for MAX_FEE_EXCEEDED or MAX_FEE_RATE_EXCEEDED. sendrawtransaction falls back to TransactionErrorString in that case. The wallet's other callers only log the string or drop it, so this RPC is the first to show it to a user. The same fallback inside the Chain::broadcastTransaction wrapper would fix it, and the GUI action will need that message once it shows the result. I can share the probe script.
| GUIUtil::ExceptionSafeConnect(bumpFeeAction, &QAction::triggered, this, &TransactionView::bumpFee); | ||
| bumpFeeAction->setObjectName("bumpFeeAction"); | ||
| abandonAction = contextMenu->addAction(tr("A&bandon transaction"), this, &TransactionView::abandonTx); | ||
| m_rebroadcast_action = contextMenu->addAction(tr("Re&broadcast transaction"), this, &TransactionView::rebroadcastTx); |
There was a problem hiding this comment.
What is the & in Re&broadcast? It is also in A&bandon.
There was a problem hiding this comment.
It specifies the previous character as a shortcut key. With this menu open, the user can do ctrl + e to trigger this action rather than needing to move the mouse to it and clicking.
| [](const RPCMethod& self, const JSONRPCRequest& request) -> UniValue | ||
| { | ||
| std::shared_ptr<CWallet> const wallet = GetWalletForJSONRPCRequest(request); | ||
| if (!wallet) return UniValue::VNULL; |
There was a problem hiding this comment.
Should we not throw here? UniValue::VNULL is for "If rebroadcast is successfully initiated".
- if (!wallet) return UniValue::VNULL;
+ if (!wallet) {
+ throw JSONRPCError(RPC_WALLET_ERROR, "no wallet");
+ }There was a problem hiding this comment.
GetWalletForJSONRPCRequest never returns nullptr, this should really be a Assume return a reference. But this is the pattern that we currently use for all of the wallet RPCs.
8528931 to
96c0e43
Compare
| virtual bool transactionCanBeBroadcast(const Txid& txid) = 0; | ||
|
|
||
| //! Rebroadcast a transaction. | ||
| virtual util::Expected<void, wallet::WalletError> rebroadcastTransaction(const Txid& txid) = 0; |
There was a problem hiding this comment.
In commit "gui: Add rebroadcast tx menu action" (96c0e43)
Could this (and RebroadcastSingleTransaction) return util::Result<void> instead of util::Expected<void, wallet::WalletError>? That would make the interface say what it returns: an error message, with no codes callers are expected to handle.
WalletError can hold any of six codes, but this method only returns two, InvalidParameter and MiscError, and callers can't tell that from the declaration. None of them handles the codes differently either: the GUI shows the message, and the RPC only uses the code to pick an RPC error number. The WalletErrorCode documentation asks for a specific code only "when callers need to handle the condition differently", and GenericError otherwise (
Lines 63 to 65 in 0e38ad2
util::Result is meant for this case, functions reporting error strings to end users, and displayAddress() above already returns util::Result<void>. TransactionCanBeBroadcast could return it too, instead of util::Expected<void, bilingual_str>. The RPC could then throw RPC_WALLET_ERROR for failures. It would also stop "Wallet broadcast is disabled" from being reported as an invalid parameter. If the RPC should report an unknown txid the way gettransaction does (RPC_INVALID_ADDRESS_OR_KEY), it could check mapWallet itself before calling, without a wallet-wide code. Since rebroadcastwallettx is new, no client depends on its error codes yet.
Using util::Expected<void, bilingual_str> instead of util::Result<void> would be fine too. My main concern is the signature saying the function can return error codes that it never returns and no caller handles.
There was a problem hiding this comment.
My understanding is that for the QML GUI, they generally want error codes as some errors may be handled differently. While the GUI as I have implemented it currently does not use these codes, that does not preclude the future GUI work from using them either, and I'd prefer to avoid needing another interface change at that time as well. cc @pseudoramdom
Even for the new RPC, I think it makes sense to get the codes so that we can give reasonable RPC error codes. I think it is incorrect to return RPC_WALLET_ERROR for things that are clearly the user providing a transaction that cannot be broadcast, hence using InvalidParameter so that it can return RPC_INVALID_PARAMETER.
Furthermore, I agree that it is strange that "Wallet broadcast is disabled" is InvalidParameter, but I don't think the solution is to drop the error codes from the wallet, but rather that TransactionCanBeBroadcast should use util::Expected<void, WalletError> as well, which I've done.
96c0e43 to
55a2984
Compare
55a2984 to
0693ed2
Compare
polespinasa
left a comment
There was a problem hiding this comment.
This will need a release note.
Also might be worth taking a look at ralph comments, specially the GUI crash, the blocks sync and the empty error messages :)
| bool CWallet::TransactionCanBeBroadcast(const Txid& txid) const | ||
| { | ||
| LOCK(cs_wallet); | ||
| const CWalletTx* wtx = GetWalletTx(txid); | ||
| return wtx && TransactionCanBeBroadcast(*wtx); | ||
| } |
There was a problem hiding this comment.
in eba7a57 wallet, rpc: Add rebroadcastwallettx
Why do we need two separate functions?
This first one only adds one check, and because of the second one being private, they are never called independently outside the class.
Can't we add the if wtx check inside the private function and make it take a txid? A caller knowing the CWalletTx can always know a txid.
suggested diff
$ git diff
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp
index cf0c45a1b4..c420be2f5f 100644
--- a/src/wallet/wallet.cpp
+++ b/src/wallet/wallet.cpp
@@ -1835,7 +1835,7 @@ util::Expected<void, WalletError> CWallet::RebroadcastSingleTransaction(const Tx
if (it == mapWallet.end()) {
return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s not in wallet"), txid.ToString())}};
}
- if (!TransactionCanBeBroadcast(it->second)) {
+ if (!TransactionCanBeBroadcast(it->first)) {
return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast"), txid.ToString())}};
}
std::string err;
@@ -1849,21 +1849,17 @@ bool CWallet::TransactionCanBeBroadcast(const Txid& txid) const
{
LOCK(cs_wallet);
const CWalletTx* wtx = GetWalletTx(txid);
- return wtx && TransactionCanBeBroadcast(*wtx);
-}
-
-bool CWallet::TransactionCanBeBroadcast(const CWalletTx& wtx) const
-{
- AssertLockHeld(cs_wallet);
+ // Transaction is not in the wallet
+ if (!wtx) return false;
// Can't relay if wallet is not broadcasting
if (!GetBroadcastTransactions()) return false;
// Don't relay abandoned transactions
- if (wtx.isAbandoned()) return false;
+ if (wtx->isAbandoned()) return false;
// Don't try to submit coinbase transactions. These would fail anyway but would
// cause log spam.
- if (wtx.IsCoinBase()) return false;
+ if (wtx->IsCoinBase()) return false;
// Don't try to submit conflicted or confirmed transactions.
- if (GetTxDepthInMainChain(wtx) != 0) return false;
+ if (GetTxDepthInMainChain(*wtx) != 0) return false;
return true;
}
@@ -1873,7 +1869,7 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx,
{
AssertLockHeld(cs_wallet);
- if (!TransactionCanBeBroadcast(wtx)) return false;
+ if (!TransactionCanBeBroadcast(wtx.GetHash())) return false;
const char* what{""};
switch (broadcast_method) {
diff --git a/src/wallet/wallet.h b/src/wallet/wallet.h
index 0633e928e1..c64e53e0f5 100644
--- a/src/wallet/wallet.h
+++ b/src/wallet/wallet.h
@@ -446,8 +446,6 @@ private:
//! Update mempool conflicts for TRUC sibling transactions
void UpdateTrucSiblingConflicts(const CWalletTx& parent_wtx, const Txid& child_txid, bool add_conflict) EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
- bool TransactionCanBeBroadcast(const CWalletTx& wtx) const EXCLUSIVE_LOCKS_REQUIRED(cs_wallet);
-
public:
/**
* Main wallet lock.
There was a problem hiding this comment.
To avoid needing to do another mapWallet lookup for callers that already have a CWalletTx.
| @@ -1843,6 +1864,16 @@ bool CWallet::SubmitTxMemoryPoolAndRelay(CWalletTx& wtx, | |||
| if (wtx.IsCoinBase()) return false; | |||
| // Don't try to submit conflicted or confirmed transactions. | |||
| if (GetTxDepthInMainChain(wtx) != 0) return false; | |||
There was a problem hiding this comment.
in eba7a57 wallet, rpc: Add rebroadcastwallettx
Why not use wtx.isBlockConflicted()?
Also random and unrelated question. Why IsUnconfirmed() checks if there is any mempool conflict? That existance of a mempool conflict doesn't change the unconfirmed state...
There was a problem hiding this comment.
Why not use
wtx.isBlockConflicted()?
This is moved code.
Also random and unrelated question. Why
IsUnconfirmed()checks if there is any mempool conflict? That existance of a mempool conflict doesn't change the unconfirmed state...
Same reason it checks isAbandoned() and isConflicted - unconfirmed in this context means that this transaction is unconfirmed, and we want/expect it to become confirmed. If the transaction is abandoned or has a conflict already in the mempool, we either do not want it to become confirmed, or it cannot become confirmed.
| if (it == mapWallet.end()) { | ||
| return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s not in wallet"), txid.ToString())}}; | ||
| } |
There was a problem hiding this comment.
in eba7a57 wallet, rpc: Add rebroadcastwallettx
small nit, feel free to ignore
This check is duplicated, it is already done inside TransactionCanBeBroadcast. Not criticla and i guess you need the find function to call SubmitTxMemoryPoolAndRelay.
I tried to refactor it so TransactionCanBeBroadcast returns a CWalletTx instead of a Void in the next commit, but I think is not worth the work.
Mentioning in case you come with a better idea :)
None of these are relevant or things we care about at all. |
0693ed2 to
a0e6ed6
Compare
a0e6ed6 to
e27218f
Compare
pseudoramdom
left a comment
There was a problem hiding this comment.
Approach ACK. v small nits
| } | ||
|
|
||
| bool CWallet::TransactionCanBeBroadcast(const Txid& txid) const | ||
| util::Expected<void, WalletError> CWallet::TransactionCanBeBroadcast(const Txid& txid) const |
There was a problem hiding this comment.
In "wallet: Return specific error messages from TransactionCanBeBroadcast"
nit: it's odd that a function that reads like a bool but it now returns Expected<void, WalletError>
How about CheckTransactionForBroadcast?
| virtual bool abandonTransaction(const Txid& txid) = 0; | ||
|
|
||
| //! Return whether transaction can be broadcast. | ||
| virtual bool transactionCanBeBroadcast(const Txid& txid) = 0; |
There was a problem hiding this comment.
In gui: Add rebroadcast tx menu action
nit: canBroadcastTransaction reads a little better to me, though transactionCanBeBroadcast follows the existing transactionCanBeBumped and transactionCanBeAbandoned naming pattern.
| bool transactionCanBeBroadcast(const Txid& txid) override { return m_wallet->TransactionCanBeBroadcast(txid).has_value(); } | ||
| util::Expected<void, WalletError> rebroadcastTransaction(const Txid& txid) override | ||
| { | ||
| LOCK(m_wallet->cs_wallet); |
There was a problem hiding this comment.
In gui: Add rebroadcast tx menu action
RebroadcastSingleTransaction already takes cs_wallet internally, so this lock looks redundant?
There was a problem hiding this comment.
Indeed. Redundant/unnecessary locking is confusing and makes it somewhat more difficult to assess the code. It will have to be removed if/when some day we try to change cs_wallet from RecursiveMutex to Mutex.
I checked that just removing this LOCK(m_wallet->cs_wallet); line compiles without any clang warnings. Further, adding this in src/wallet/wallet.h:
- util::Expected<void, WalletError> RebroadcastSingleTransaction(const Txid& txid);
+ util::Expected<void, WalletError> RebroadcastSingleTransaction(const Txid& txid) EXCLUSIVE_LOCKS_REQUIRED(!cs_wallet);would be even better :)
| if (GetTxDepthInMainChain(wtx) != 0) return false; | ||
| return true; | ||
| if (GetTxDepthInMainChain(wtx) > 0) return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast, tx is confirmed"), wtx.GetHash().ToString())}}; | ||
| if (GetTxDepthInMainChain(wtx) < 0) return util::Unexpected{WalletError{WalletErrorCode::InvalidParameter, strprintf(_("%s is not eligible to be rebroadcast, tx is conflicted"), wtx.GetHash().ToString())}}; |
There was a problem hiding this comment.
Should we calculate the depth once and store in a local
const int depth{GetTxDepthInMainChain(wtx)};
vasild
left a comment
There was a problem hiding this comment.
ACK e27218f
Show Signature
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256
ACK e27218f7ad3482b46ea5e3f278393e68eb870b93
-----BEGIN PGP SIGNATURE-----
iQ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aWikCHR9dIeX/XaDcQl/1+fixOhS9tBhodeLO48q6
RtnrECErMMbmDkgQJ+pZLaYiuGj3Oe5Cvs46TKqYliWc7oT47vYTBvK66s2GvuiA
KZyHX/A6iMkyQJwfLKsDLlEAdqvpE9cKYh8tiq7EqvQX2aOISpV1EYEa4+Tb8VjJ
teb6rYmfHa+kXUw1aKP1LJKEgrdiRhAHpdsU2nLeL8I//KqaxUL48tptLMM9YIXR
TcAwp33wTimvhud57vI+W3pL6CqF+QaoR6dz6oyvlgdLoW5z5zsslkF/6P29xT0s
8XbGffthHeqnfUjvQ1h1LQTbJnRqtV8BwAg8+bFiSy+mWJUWyiG0uNaHUO0cuJFK
2PoGvuDveTQXu33q1k2CXRKTj/oPahumfG94SUDsyy9rNc3BsqHIhmcawPtbDXvS
lTA=
=+Pad
-----END PGP SIGNATURE-----
vasild's public key is on openpgp.org
|
reviewed e27218f I don't have much to add I think last two nits reported by ram would be nice to have, will ACK after they are resolved. |
|
The QML part of this in bitcoin-core/gui-qml#1143 |
|
Concept ACK |
|
concept ACK |

From the discussion in #36403, it is clear that there needs to be a way for users to rebroadcast a transaction. Currently, the way to do so requires getting the raw transaction, getting the hex, and using
sendrawtransaction. This PR addsrebroadcastwallettxRPC that takes a txid to attempt to rebroadcast that single transaction. An action is also added to the GUI menu for each transaction to do the same.