-
Notifications
You must be signed in to change notification settings - Fork 36.5k
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
rename TransactionError:ALREADY_IN_CHAIN #30212
rename TransactionError:ALREADY_IN_CHAIN #30212
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. ConflictsNo conflicts as of last run. |
This addresses #19363 's concern:
...by now returning |
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.
Concept and code-review ACK aa422bc
I agree that the proposed names are more to the point and less confusing.
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 Review ACK aa422bc
src/node/transaction.cpp
Outdated
@@ -22,7 +22,7 @@ static TransactionError HandleATMPError(const TxValidationState& state, std::str | |||
err_string_out = state.ToString(); | |||
if (state.IsInvalid()) { | |||
if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { | |||
return TransactionError::MISSING_INPUTS; |
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.
Nice, I think we should also rename the one in TxValidationResult
enum.
g/TX_MISSING_INPUTS
/TX_MISSING_INPUT_OR_SPENT
/g
and update comments appropriately.
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.
I did consider this, but it felt much less exposed to the user, only via testmempoolaccept
AFAIK:
result_inner.pushKV("reject-reason", "missing-inputs");
Therefore as an "internal error", TX_MISSING_INPUTS
(for any reason) it felt more accurate to me to leave as is? Very happy to be persuaded away from this viewpoint though :)
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.
Therefore as an "internal error", TX_MISSING_INPUTS (for any reason) it felt more accurate to me to leave as is?
I was reviewing this based on the PR rationale in the OP. You stated that "a transaction's inputs are missing from the UTXO set, which could also be due to all inputs having already been spent (MISSING_INPUTS -> INPUTS_MISSING_OR_SPENT)." That's why I suggested that TxValidationResult
one should be changed just for uniformity. But Internally, you're right TX_MISSING_INPUTS
inferred or spent.
Maybe just update the testmempoolaccept
reject reason since it's user-facing?
But if you agree, you may have to update some functional tests that use it and maybe a release note since users heavily use the RPC.
This is a non blocking comment.
This PR is an improvement and will close the issue
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.
I also don't understand why the first commit is needed. The error message is already correct (and unchanged in this pull request): Untranslated("Inputs missing or spent")
.
I'd say it is fine to drop the commit (or keep it if you want). Just a style nit, either is fine.
aa422bc
to
b2b4b93
Compare
Rebased on master to fix merge conflict. Added an extra commit to cover |
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.
re-ACK b2b4b93
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.
re-ACK b2b4b93
b2b4b93
to
77ef75d
Compare
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 review ACK 77ef75d if test failure is fixed (see comment below)
Note: I didn't totally follow the original issue or how these changes resolve it, but all the changes here seem reasonable regardless.
77ef75d
to
a05f4ca
Compare
Code review ACK a05f4ca. Just changed psbt error string and fixed a test since the last review. |
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.
Approach ACK
Good work increasing clarity. In the past I've had a head-scratching moment with some of these before I learned the nuances, so this should help people.
Left a comment about release notes.
Tested:
- Ran unit/functional tests locally (passed)
- Manually exercised the following scenario (regtest):
- Created a transaction (and broadcasted).
- Generated one block to confirm.
- Attempted to call
sendrawtransaction
with the newly confirmed transaction. - Received
Transaction outputs already in UTXO set
as expected. - Performed
sendall
to spent all UTXOs. - Re-attempted to call
sendrawtransaction
with the the spent transaction. - Received
bad-txns-inputs-missingorspent
self.generate(self.nodes[2], 1) | ||
for node in self.nodes: | ||
testres = node.testmempoolaccept([tx['hex']])[0] | ||
assert_equal(testres['allowed'], False) | ||
assert_equal(testres['reject-reason'], 'txn-already-known') | ||
assert_raises_rpc_error(-27, 'Transaction already in block chain', node.sendrawtransaction, tx['hex']) | ||
assert_raises_rpc_error(-27, 'Transaction outputs already in utxo set', node.sendrawtransaction, tx['hex']) |
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.
Although it's only the error message (and the number stays the same), I still think its appropriate to add a release note for the change to the user.
https://github.com/bitcoin/bitcoin/blob/master/doc/developer-notes.md#release-notes
Release notes should be written for any PR that:
...
makes any other visible change to the end-user experience.
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.
Left a question. Also, I don't think this is a "refactor"
src/node/transaction.cpp
Outdated
@@ -22,7 +22,7 @@ static TransactionError HandleATMPError(const TxValidationState& state, std::str | |||
err_string_out = state.ToString(); | |||
if (state.IsInvalid()) { | |||
if (state.GetResult() == TxValidationResult::TX_MISSING_INPUTS) { | |||
return TransactionError::MISSING_INPUTS; |
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.
I also don't understand why the first commit is needed. The error message is already correct (and unchanged in this pull request): Untranslated("Inputs missing or spent")
.
I'd say it is fine to drop the commit (or keep it if you want). Just a style nit, either is fine.
src/rpc/protocol.h
Outdated
RPC_IN_WARMUP = -28, //!< Client still warming up | ||
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated | ||
|
||
//! Aliases for backward compatibility | ||
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR, | ||
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED, | ||
RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_CHAIN, | ||
RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_UTXO_SET, |
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.
95b09ed: The second commit is not a refactor, but claims to be one. However, it changes the rpc error messages. Also, it is removing the RPC_VERIFY_ALREADY_IN_CHAIN
from this header. Either this is fine, in which case this whole "backward compat" section can be removed, or it is not fine, in which case the symbol needs to be restored. C.f. d29a291
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.
re: #30212 (comment)
Good catch. It is inconsistent to have added backwards compatible aliases previously when renaming and not add them now when renaming again. But it looks like the backwards compatibility section was added in 2014 when it was might have less clear whether aliases were needed. I'd say now aliases are probably not needed and it would be better to remove this section.
src/common/messages.cpp
Outdated
case PSBTError::MISSING_INPUTS: | ||
return Untranslated("Inputs missing or spent"); | ||
case PSBTError::INPUTS_INVALID: | ||
return Untranslated("Invalid inputs"); |
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.
a05f4ca: This commit is not a refactor either.
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.
Agree on not calling the commits which change error messages refactoring. I do like first commit making error constant more consistent with error message, but agree it is not essential.
src/rpc/protocol.h
Outdated
RPC_IN_WARMUP = -28, //!< Client still warming up | ||
RPC_METHOD_DEPRECATED = -32, //!< RPC method is deprecated | ||
|
||
//! Aliases for backward compatibility | ||
RPC_TRANSACTION_ERROR = RPC_VERIFY_ERROR, | ||
RPC_TRANSACTION_REJECTED = RPC_VERIFY_REJECTED, | ||
RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_CHAIN, | ||
RPC_TRANSACTION_ALREADY_IN_CHAIN= RPC_VERIFY_ALREADY_IN_UTXO_SET, |
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.
re: #30212 (comment)
Good catch. It is inconsistent to have added backwards compatible aliases previously when renaming and not add them now when renaming again. But it looks like the backwards compatibility section was added in 2014 when it was might have less clear whether aliases were needed. I'd say now aliases are probably not needed and it would be better to remove this section.
test/functional/rpc_psbt.py
Outdated
@@ -704,7 +704,7 @@ def test_psbt_input_keys(psbt_input, keys): | |||
assert_equal(analysis['next'], 'creator') | |||
assert_equal(analysis['error'], 'PSBT is not valid. Input 0 specifies invalid prevout') | |||
|
|||
assert_raises_rpc_error(-25, 'Inputs missing or spent', self.nodes[0].walletprocesspsbt, 'cHNidP8BAJoCAAAAAkvEW8NnDtdNtDpsmze+Ht2LH35IJcKv00jKAlUs21RrAwAAAAD/////S8Rbw2cO1020OmybN74e3Ysffkglwq/TSMoCVSzbVGsBAAAAAP7///8CwLYClQAAAAAWABSNJKzjaUb3uOxixsvh1GGE3fW7zQD5ApUAAAAAFgAUKNw0x8HRctAgmvoevm4u1SbN7XIAAAAAAAEAnQIAAAACczMa321tVHuN4GKWKRncycI22aX3uXgwSFUKM2orjRsBAAAAAP7///9zMxrfbW1Ue43gYpYpGdzJwjbZpfe5eDBIVQozaiuNGwAAAAAA/v///wIA+QKVAAAAABl2qRT9zXUVA8Ls5iVqynLHe5/vSe1XyYisQM0ClQAAAAAWABRmWQUcjSjghQ8/uH4Bn/zkakwLtAAAAAAAAQEfQM0ClQAAAAAWABRmWQUcjSjghQ8/uH4Bn/zkakwLtAAAAA==') | |||
assert_raises_rpc_error(-25, 'Invalid inputs', self.nodes[0].walletprocesspsbt, 'cHNidP8BAJoCAAAAAkvEW8NnDtdNtDpsmze+Ht2LH35IJcKv00jKAlUs21RrAwAAAAD/////S8Rbw2cO1020OmybN74e3Ysffkglwq/TSMoCVSzbVGsBAAAAAP7///8CwLYClQAAAAAWABSNJKzjaUb3uOxixsvh1GGE3fW7zQD5ApUAAAAAFgAUKNw0x8HRctAgmvoevm4u1SbN7XIAAAAAAAEAnQIAAAACczMa321tVHuN4GKWKRncycI22aX3uXgwSFUKM2orjRsBAAAAAP7///9zMxrfbW1Ue43gYpYpGdzJwjbZpfe5eDBIVQozaiuNGwAAAAAA/v///wIA+QKVAAAAABl2qRT9zXUVA8Ls5iVqynLHe5/vSe1XyYisQM0ClQAAAAAWABRmWQUcjSjghQ8/uH4Bn/zkakwLtAAAAAAAAQEfQM0ClQAAAAAWABRmWQUcjSjghQ8/uH4Bn/zkakwLtAAAAA==') |
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.
In commit "refactor: PSBTError::MISSING_INPUTS" (a05f4ca)
I wonder if "invalid transaction inputs" might be a clearer message for a user than "invalid inputs." (I had suggested "invalid inputs" but in this context it seems vague.)
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.
Looking good to me 🥇
I will re-ACK after comments were addressed
a05f4ca
to
76eb6f3
Compare
🚧 At least one of the CI tasks failed. HintsMake sure to run all tests locally, according to the documentation. The failure may happen due to a number of reasons, for example:
Leave a comment here, if you need help tracking down a confusing failure. |
When using `sendrawtransaction` the ALREADY_IN_CHAIN error help string may be confusing. Rename TransactionError::ALREADY_IN_CHAIN to TransactionError::ALREADY_IN_UTXO_SET and update the rpc help string. Remove backwards compatibility alias as no longer required.
76eb6f3
to
e9de0a7
Compare
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 e9de0a7
Re-ran tests in #30212 (review) (successful)
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 e9de0a7
|
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 review ACK e9de0a7.
Since last review, change has been simplified, no longer renaming PSBTError::MISSING_INPUTS
to PSBTError::INPUTS_INVALID
and no longer renaming TransactionError::MISSING_INPUTS
to TransactionError::INPUTS_MISSING_OR_SPENT
I did think both of those renames were improvements, but it does simplify the PR to drop them. Also it makes it easier to see how this PR fixes #19363.
Also release notes were added
@@ -43,7 +43,7 @@ static RPCHelpMan sendrawtransaction() | |||
"\nThe transaction will be sent unconditionally to all peers, so using sendrawtransaction\n" | |||
"for manual rebroadcast may degrade privacy by leaking the transaction's origin, as\n" | |||
"nodes will normally not rebroadcast non-wallet transactions already in their mempool.\n" | |||
"\nA specific exception, RPC_TRANSACTION_ALREADY_IN_CHAIN, may throw if the transaction cannot be added to the mempool.\n" | |||
"\nA specific exception, RPC_TRANSACTION_ALREADY_IN_UTXO_SET, may throw if the transaction cannot be added to the mempool.\n" |
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.
In commit "rpc: clarify ALREADY_IN_CHAIN rpc errors" (87b1880)
Was already the case before this PR, but this documentation seems misleading because "already in utxo set" error is not the only error that can be triggered if transaction can't be added to the mempool.
As #19363 reports BroadcastTransaction will start returning MISSING_INPUTS instead of ALREADY_IN_UTXO_SET after the outputs are spent. Also it looks like BroadcastTransaction can returns MEMPOOL_REJECTED and MEMPOOL_ERROR which get translated into RPC_TRANSACTION_REJECTED and RPC_TRANSACTION_ERROR. So 3 different error codes may be returned if the transaction can't be added to the mempool, not just 1
Does Alternatively, the error constant could be renamed, with the error text/string left in place. |
Closes: #19363
Renaming this error improves clarity around the returned error both internally and externally when a transactions' outputs are already found in the utxo set (
TransactionError::ALREADY_IN_CHAIN -> TransactionError::ALREADY_IN_UTXO_SET
)