-
Notifications
You must be signed in to change notification settings - Fork 38.8k
rpc: Add testmempoolaccept #11742
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
rpc: Add testmempoolaccept #11742
Conversation
promag
left a comment
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.
Should note that two equal calls to testmempoolaccept in a short period can return different values?
src/rpc/rawtransaction.cpp
Outdated
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.
Fix alignment.
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.
done
src/rpc/rawtransaction.cpp
Outdated
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.
IMO as it is this block is not needed.
src/rpc/rawtransaction.cpp
Outdated
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.
Add test?
src/validation.cpp
Outdated
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.
Already default value. Or remove default value from declaration?
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.
Note this is ATMPWT, not ATMP ;)
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.
Ah!
fa6f969 to
e0c1f05
Compare
src/rpc/rawtransaction.cpp
Outdated
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.
Extra space.
src/rpc/rawtransaction.cpp
Outdated
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.
Send?
src/rpc/rawtransaction.cpp
Outdated
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.
error? optional?
50ec02e to
fa12a94
Compare
sipa
left a comment
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.
utACK fa12a9481ea7d930c75f109f3c10b200db70e501
src/txmempool.h
Outdated
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.
This first const has no effect.
|
I am so happy about this, big concept ACK. Some tests would be nice. |
|
Nice. Finally. A comment for the new parameter of |
TheBlueMatt
left a comment
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.
Cool.
src/rpc/rawtransaction.cpp
Outdated
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.
Seems somewhat redundant to return the parameter as-is, no?
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.
Thanks, will rename this to txid and the parameter to rawtx to make clear that they are different.
src/rpc/rawtransaction.cpp
Outdated
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.
Ugh, I meannnnn, checking against pcoinsTip really sucks. Maybe just call ATMP and then check for the "txn-already-known" return? Or just return false (since its not "accepted to mempool", so I'd kinda expect that) and the rejection reason will be txn-already-known.
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 guess this was borrowed from sendrawtransaction.
There, there is an extra test bool fHaveMempool = mempool.exists(hashTx),
but it could be replaced by checking the ATMP error txn-already-in-mempool.
However in other PR I recall @sipa said it was kind of bad thing to rely on these rejection reasons.
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.
Yeah, this is mostly a convenience check to provide a helpful message in case the tx recently confirmed for whatever reason. Otherwise you'd be left with missing_inputs, which is correct but might not be helpful at 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.
On a second thought, I don't think it makes sense to have the blockchain check here. Will return false as suggested by @TheBlueMatt
promag
left a comment
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.
Are you planning to add functional test in this PR?
src/rpc/rawtransaction.cpp
Outdated
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.
Missing \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.
There is no new line to indicate a paragraph, which groups the rpcs into two logical sections.
src/rpc/rawtransaction.cpp
Outdated
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.
when 'allowed' is false
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.
Thx, fixed.
a9bc799 to
293b972
Compare
|
Removed the unused imports to make travis green. |
293b972 to
fa82ebf
Compare
|
can someone remind me why this one is acceptable while the other ~dozen attempts have failed? |
|
@instagibbs Revelant history #7552 from @laanwj I think this one can work because it has a better name. |
instagibbs
left a comment
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.
utACK
src/rpc/rawtransaction.cpp
Outdated
| } else if (missing_inputs) { | ||
| result.push_back(Pair("reject-reason", "Missing inputs")); | ||
| } else { | ||
| result.push_back(Pair("reject-reason", state.GetRejectReason())); |
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 understand this is reflected in sendraw as well, but humor me: what times is state not IsInvalid but it would reject it?
|
@instagibbs Previous pulls were:
I think this pull ( |
|
conceptACK, seems useful and more accessible/convenient than current alternatives |
src/rpc/rawtransaction.cpp
Outdated
| // clang-format off | ||
| "testmempoolaccept [\"rawtxs\"] ( allowhighfees )\n" | ||
| "\nReturns if raw transaction (serialized, hex-encoded) would be accepted by mempool.\n" | ||
| "\nThis checks if the transaction violates our consesus or policy rules.\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.
Type: consesus.
Nit, s/our/the.
src/rpc/rawtransaction.cpp
Outdated
| "testmempoolaccept [\"rawtxs\"] ( allowhighfees )\n" | ||
| "\nReturns if raw transaction (serialized, hex-encoded) would be accepted by mempool.\n" | ||
| "\nThis checks if the transaction violates our consesus or policy rules.\n" | ||
| "\nAlso see sendrawtransaction call.\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.
Nit, just See sendrawtransaction.
src/rpc/rawtransaction.cpp
Outdated
|
|
||
| RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VBOOL}); | ||
| if (request.params[0].get_array().size() != 1) { | ||
| throw JSONRPCError(RPC_TYPE_ERROR, "Array must contain exactly one raw transaction for now"); |
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.
RPC_INVALID_PARAMETER instead? Type is already correct (it's an array at least).
src/rpc/rawtransaction.cpp
Outdated
| } | ||
|
|
||
| UniValue result(UniValue::VARR); | ||
|
|
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.
Nit, remove empty line.
src/rpc/rawtransaction.cpp
Outdated
| " {\n" | ||
| " \"txid\" (string) The transaction hash in hex\n" | ||
| " \"allowed\" (boolean) If the mempool allows this tx to be inserted\n" | ||
| " \"reject-reason\" (string) rejection string (only present when 'allowed' is false)\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.
Nit, upper case Rejection.
|
|
||
| ObserveSafeMode(); | ||
|
|
||
| RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VBOOL}); |
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.
Remove? Below there is request.params[0].get_array() and request.params[1].get_bool().
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.
That is the way we do it everywhere. I assume the rational is to fail early and provide useful feedback instead of accepting/processing each parameter separately and leaving any later ones unchecked.
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.
The error would be different thought. I don't think failing a bit later is that bad. This also doesn't work well with polymorphic arguments. At the end we have a mix of these, so I tend to use univalue getters to validate. We could add support to throw if any extra parameter is not get/validated.
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.
Yes, the error is different in that the RPCTypeCheck will tell you what the wrong type was, which is useful.
I fail to see how the edge case of polymorphic arguments is relevant to this pull request.
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.
nit, missing test for second argument type and also tests for missing/extra arguments.
src/rpc/rawtransaction.cpp
Outdated
| CValidationState state; | ||
| bool missing_inputs; | ||
| bool test_accept_res; | ||
| bool res = AcceptToMemoryPool(mempool, state, std::move(tx), &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.
Nit, we could avoid loose locks, I mean, it's more clear where the lock/unlock happens:
{
LOCK(cs_main);
bool res = AcceptToMemoryPool(...);
assert(!res);
}
src/rpc/rawtransaction.cpp
Outdated
| if (state.IsInvalid()) { | ||
| result_0.pushKV("reject-reason", strprintf("%i: %s", state.GetRejectCode(), state.GetRejectReason())); | ||
| } else if (missing_inputs) { | ||
| result_0.pushKV("reject-reason", "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.
Nit, not sure if relevant at all, but this format doesn't match with others. How about missing-inputs?
|
Added a commit to address @promag's feedback. |
|
Concept ACK |
|
I can do that refactoring in a follow up pr, if people think that is helpful. |
|
Fun-Fact: I just realized an identical implementation was committed in gfanti@7148d4b a year ago. (Not including rpc changes and tests) |
|
utACK b55555d |
b55555d rpc: Add testmempoolaccept (MarcoFalke) Pull request description: To check if a single raw transaction makes it into the current transaction pool, one had to call `sendrawtransaction`. However, on success, this adds the transaction to the mempool with no easy way to undo. The call `testmempoolaccept` is introduced to provide a way to solely check the result without changing the mempool state. Tree-SHA512: 5afd9311190135cee8fc1f229c7d39bf893f1028f29e28d34f70df820198ff97b4bf86b41cbbd6e6c36a5c30073cefa92d541c74a4939c7a2a6fa283dfd41b63
|
Post-merge utACK b55555d Change looks useful and well implemented. The tests are great! In some sense it's sad that the functional tests you've introduced for this particular RPC call are the only place where we're testing basic mempool rejection logic (e.g. |
|
yes, forgot to mention the tests were very extensive and impressive |
|
post merge fast review ack. +1 on this being interesting for the tests alone, even if nobody was going to use it (but I know some people will, and I remember concept acking something very similar before, for traceability, #7552 ). |
fafcad3 doc: Add testmempoolaccept to release-notes (MarcoFalke) Pull request description: Some fixups for #11742: * Add release notes for the new rpc * Fix a typo in the original pull * Make the mempool reference passed to `CheckInputsFromMempoolAndCache` const, since that function is called before we return from ATMP and we must not modify the mempool. Tree-SHA512: 72c459ba69f7698a69c91d2592f10f7fb1864846c7d8c525050d48286f92ba5ec5fe554c54235b52fbd9a8f00226c526ad84584641ec39084e1a1310a261510d
|
|
||
| RPCTypeCheck(request.params, {UniValue::VARR, UniValue::VBOOL}); | ||
| if (request.params[0].get_array().size() != 1) { | ||
| throw JSONRPCError(RPC_INVALID_PARAMETER, "Array must contain exactly one raw transaction for now"); |
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.
Hey @MarcoFalke, sorry for the throwback, but was there a plan have testmempoolaccept accept multiple transactions at some point?
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.
Yes, see #11742 (comment)
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.
Fwiw i opened an issue to track this some time ago #18480 . Feel free to pick it up if you want (just signal it so we don't end up both working on it :) ), as i'm not going to work on this soon.
b55555d rpc: Add testmempoolaccept (MarcoFalke) Pull request description: To check if a single raw transaction makes it into the current transaction pool, one had to call `sendrawtransaction`. However, on success, this adds the transaction to the mempool with no easy way to undo. The call `testmempoolaccept` is introduced to provide a way to solely check the result without changing the mempool state. Tree-SHA512: 5afd9311190135cee8fc1f229c7d39bf893f1028f29e28d34f70df820198ff97b4bf86b41cbbd6e6c36a5c30073cefa92d541c74a4939c7a2a6fa283dfd41b63
…ing const fafcad3 doc: Add testmempoolaccept to release-notes (MarcoFalke) Pull request description: Some fixups for bitcoin#11742: * Add release notes for the new rpc * Fix a typo in the original pull * Make the mempool reference passed to `CheckInputsFromMempoolAndCache` const, since that function is called before we return from ATMP and we must not modify the mempool. Tree-SHA512: 72c459ba69f7698a69c91d2592f10f7fb1864846c7d8c525050d48286f92ba5ec5fe554c54235b52fbd9a8f00226c526ad84584641ec39084e1a1310a261510d
b55555d rpc: Add testmempoolaccept (MarcoFalke) Pull request description: To check if a single raw transaction makes it into the current transaction pool, one had to call `sendrawtransaction`. However, on success, this adds the transaction to the mempool with no easy way to undo. The call `testmempoolaccept` is introduced to provide a way to solely check the result without changing the mempool state. Tree-SHA512: 5afd9311190135cee8fc1f229c7d39bf893f1028f29e28d34f70df820198ff97b4bf86b41cbbd6e6c36a5c30073cefa92d541c74a4939c7a2a6fa283dfd41b63
…ing const fafcad3 doc: Add testmempoolaccept to release-notes (MarcoFalke) Pull request description: Some fixups for bitcoin#11742: * Add release notes for the new rpc * Fix a typo in the original pull * Make the mempool reference passed to `CheckInputsFromMempoolAndCache` const, since that function is called before we return from ATMP and we must not modify the mempool. Tree-SHA512: 72c459ba69f7698a69c91d2592f10f7fb1864846c7d8c525050d48286f92ba5ec5fe554c54235b52fbd9a8f00226c526ad84584641ec39084e1a1310a261510d
To check if a single raw transaction makes it into the current transaction pool, one had to call
sendrawtransaction. However, on success, this adds the transaction to the mempool with no easy way to undo.The call
testmempoolacceptis introduced to provide a way to solely check the result without changing the mempool state.