-
Notifications
You must be signed in to change notification settings - Fork 38.7k
rpc: Add verifyrawtransactions call
#7552
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
e464634 to
4492928
Compare
|
Concept ACK. |
|
Concept ACK |
|
Concept-ACK. Should the sense of final and non-standard be inverted in the options? It would be surprising to pass a transaction to this RPC, have it pass.... then find that the network won't accept it. Practically speaking, except for special cases and developers standardness is pretty much as forceful as validity. An obvious future extension wrt finality would be adding a field in the result that says when the transaction will become final. |
|
edit: As suggested by @gmaxwell (I think), IMHO the best approach here is to give feedback to the user as to the earliest time they could be included. |
That's why those checks are enabled (true) by default. For specific cases they could be disabled. Only for the coinbase check I couldn't think of any reason why one'd want to disable it, so I left that out.
Yes, would be nice - by using an object both for the options and the error, I made the API extensible enough to add such bells and whistles. |
2845dc1 to
f757579
Compare
|
|
|
concept ack, but this is very incomplete, I suggest we keep it open without merging too fast. We're arbitrarily calling IsStandardTx() but not AreInputsStandard(). Those are just two easily functions containing relay/ming policy, but there's much more related code spread out there. Nit: Remove call to IsStandardTx() in verifytx, we can make another rpc call (or add an option in this one) called "verify tx according to consensus rules and also accept tx according to some confirgurable policy parameter". But please let's not add any policy code until we have a complete Consensus::VerifyTx(). Nit: Let's please introduce Consensus::VerifyTx() before exposing anything else, otherwise you'll have to duplicate some code from AcceptToMemoryPool and/or ConnectBlock. Could you please consider rebasing this PR on top of #7565 ? |
|
IMHO agreed this would be best implemented by I also like the idea of a parameter for rejection based purely on consensus, and irrespective of local node policy. |
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.
Nit: Appears to be missing the left parenthesis.
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.
or adding a superfluous right one
|
@jtimon I don't feel like doing all kinds of refactors here (too much risk to break other things). Please just review this for correctness. |
Right - that's possible already. Disable |
|
Fair enough, concept ack. |
Yes, that's a legit bug (I added it to TODOs in the opening post)
What other options would you imagine there? Adding more options to the options structure is free, so there could always be a "standard_policy": "string" added later. |
qa/rpc-tests/rawtransactions.py
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.
I wrote some code to test the ordering of dependent tx's, then realized this code here does the same thing my code did. If you want to also test calling verifyrawtransaxtions with dependent tx's, you could add this code at this point. It was suggested to me to copy-paste the git diff result:
diff --git a/qa/rpc-tests/rawtransactions.py b/qa/rpc-tests/rawtransactions.py
index 9039bc6..9dd8c84 100755
--- a/qa/rpc-tests/rawtransactions.py
+++ b/qa/rpc-tests/rawtransactions.py
@@ -226,6 +226,19 @@ class RawTransactionsTest(BitcoinTestFramework):
assert(err['code'] == 16)
assert(err['reason'].startswith('bad-txns-inputs-missingorspent'))
+ #check ordering of dependent tx's in verifyrawtransactions
+ parent = rawTxSigned['hex']
+ child = rawTx2
+ err1 = self.nodes[2].verifyrawtransactions([parent, child], {'include_mempool':True})
+ err2 = self.nodes[2].verifyrawtransactions([parent, child], {'include_mempool':False})
+ assert(err1 is None and err2 is None)
+
+ # out-of-order succeeds with mempool, fails without
+ err1 = self.nodes[2].verifyrawtransactions([child, parent], {'include_mempool':True})
+ err2 = self.nodes[2].verifyrawtransactions([child, parent], {'include_mempool':False})
+ assert(err1 is None and err2 is not None)
+ assert(err2['reason'].startswith('bad-txns-inputs-missingorspent'))
+
# mine the transaction into a block and check end result
rawTx = self.nodes[0].decoderawtransaction(rawTxSigned['hex'])
self.sync_all()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 add that test!
48a481a to
0ae331b
Compare
qa/rpc-tests/rawtransactions.py
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.
Assertion failed:
File "/home/travis/build/bitcoin/bitcoin/bitcoin-x86_64-unknown-linux-gnu/qa/rpc-tests/test_framework/test_framework.py", line 135, in main
self.run_test()
File "/home/travis/build/bitcoin/bitcoin/bitcoin-x86_64-unknown-linux-gnu/qa/rpc-tests/rawtransactions.py", line 64, in run_test
assert(err['code'] == 16)
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.
Hmm, interesting, so CheckSequenceLocks actually looks up the inputs, moving it after HaveInputs
(more consistent with AcceptToMemoryPool anyhow)
Add a RPC call to verify a set of raw transactions without propagating them. Implements bitcoin#4162. verifyrawtransactions ["hexstring",...] ( options ) Verifies one or more raw transactions (serialized, hex-encoded). If transactions depend on each other, they must be provided in order. Arguments: 1. ["hexstring",...] (array of strings, required) The hex string of the raw transactions) 2. options (json object, optional) { "include_mempool" (boolean, optional, default=true) Whether to include the mem pool "check_final" (boolean, optional, default=true) Check that the transactions will be final by next block "check_standard" (boolean, optional, default=true) Perform transaction standard checks } Result: null if the verification was successful, otherwise an error object: { "index":n, (numeric) Index in transactions array of failed transaction "hash":"hex", (string) Transaction hash of failed transaction "code": n, (numeric) Reject code "reason": "text" (string) Reject reason "debug_message": "text" (string) Reject debug message }
For future extensibility it's important that unrecognized options are rejected.
more consistent with AcceptToMemoryPool
Local for now, but this could, in time, be shared by various places that want to verify transactions.
3101397 to
da0595d
Compare
|
I've factored out the transaction verification to a (local) VerifyTransaction function. |
Use a more familiar structure now that VerifyTransaction is a function.
|
Too much disagreement on how this should be implemented, not going to bother anymore. |
|
I don’t understand why this is closed. I asked to wait for some refactors first. You said no, fair enough, they can be done later. Then you create the verifyTx function, but not in the consensus package or dir, and including policy code. I can't say I like that (I'm not going to link to the VerifyTx I like anymore because as said it requieres refactors and I was waiting for 0.12.1 first. I guess I wouldn't mind if the function was called VerifyAndAcceptTx or something like that. But why not continue with your original version? Wasn't I the only person complaining and didn't I said fair enough and concept ACK? |
Well someone else on IRC was worried that the output of this doesn't exactly match the output of I don't however want to just bolt this on to main.cpp in the current state. Without refactors that'd make the code even harder to understand, and makes it virtually impossible to handle multiple dependent transactions without actually writing to the mempool. So if this solution is not acceptable for the mean time, I suppose we should wait for those refactors to materialize first. |
|
Thank you. Why the additional requirement of this having to return the same as sendrawtx? Wouldn't everything be much easier if VerifyTx ONLY did consensus checks? As said we can have a VerifyAndAcceptTx later thatalso does relay/mempool policy stuff as well (but, yeah, I agree the policy code needs many refactors if you want to use any of the fee-related code in the CtxMempool and AcceptToMemoryPool from here). |
That is the default assumption. I suppose if we can document the differences (e.g. no mempool replacement, no fee checks) that'd help. If you want to do only consensus checks you can already do that with this code, just disable the standardness check (and possibly the use mempool flag). I do think checking standardness etc is useful in some cases though. |
|
Well, yeah, documenting the differences seems much simpler to make the relay/mempool policy checks complete. So called "standardness" is encapsulated in policy/policy.o and its dependencies, but completing the rest of the policy checks won't be so simple I think. If anyone else wants to continue this for master directly, I'm happy to re-review, though. |
|
Wouldn't the easiest way to make this feature is to create a dummy block, with a dummy coinbase, and add the transaction inside it and call ConnectBlock with fJustCheck to true ? |
|
I don't think the goal of this PR was offering the functionality the "easiest way", but since it was checking policy things as well, I'm not sure I ever understood the PR. |
|
At the API level, I think users care only about one parameter: Whether we check against Node Policy or Consensus Policy. I think the current PR was attempting too many options. I'll probably try to make it later since this PR already did most of the heavy work. |
Originally I meant this as a pre-check whether
Only three options! And I think all of them make sense in some context. |
Add a RPC call to verify a set of raw transactions without propagating them. It has an extensible API to customize verification options.
Implements #4162.
TODO:
RPC testCallAreInputsStandard()to check inputs for standardness