-
Notifications
You must be signed in to change notification settings - Fork 37.7k
rpc: Return fee and prevout (utxos) to getrawtransaction #23319
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: Return fee and prevout (utxos) to getrawtransaction #23319
Conversation
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 ACK
2730b68
to
2598983
Compare
2598983
to
d3f084a
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.
Concept ACK.
It would be interesting to add a functional test case.
d3f084a
to
2e8ce71
Compare
I think this has been said on IRC already: Shouldn't this be hidden behind a flag like the RPC it is copied from? |
Agreed, wanted to discuss the implementation before diving in. |
To confirm we want the second (hybrid) parameter to have three verbosity levels:
|
Yes, if that is the behavior of the other RPC, it makes sense to copy it. |
You might want to also add the UTXOs being spent by the transaction. You're looking those up anyway. |
The tests can also be taken from the other RPC: https://github.com/bitcoin/bitcoin/pull/22918/files |
6c61582
to
83e5f6c
Compare
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. 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. |
@sipa Can you clarify a bit more on |
@dougEfresh The scriptPubKey and amount being spent for each input (together with information about the scriptPubKey like the output already has). |
Showing the utxos being spent is also being done by the other RPC. Any questions you might have should be answered by looking at the code changes of https://github.com/bitcoin/bitcoin/pull/22918/files |
2051110
to
2c56d72
Compare
thanks, added utxos with My latest change includes
|
assert_equal(gottx['in_active_chain'], True) | ||
if v == 2: | ||
# fee is in verbosity 2 only | ||
assert_equal(gottx['fee'], Decimal('0.00002820')) |
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.
What is supposed to guarantee this is correct?
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 value of fee is not important. I want to see that the field fee exists. Change it to assert('fee' in gottxt)
?
There are another tests (outside the scope of this PR) which validate the fee amount.
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.
Maybe do tx_fee = -self.nodes[2].gettransaction(tx)['fee']
immediately after sending and compare to that?
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.
No fee field in gettransaction
.
I added assert('fee' in gottxt)
but kept assert_equal(gottx['fee'], Decimal('0.00002820'))
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 fee
in getransaction. see https://developer.bitcoin.org/reference/rpc/gettransaction.html
I also agree with @luke-jr . There is no guarantee that fee calculation will always remain same, and thus better not to assert against hard coded values.
6216d8d
to
23eb378
Compare
23eb378
to
f5c7620
Compare
f5c7620
to
eae8f8e
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.
Strong ReACK eae8f8e
Its been almost an year since this PR is standing and its quite useful for wallet devs for obvious reasons.. Thanks to the PR author for chugging along..
I did a re-pass and have following non blocking observation regarding a specific blockhash
- verbosity
-txindex
combination.
const bool is_block_pruned{WITH_LOCK(cs_main, return chainman.m_blockman.IsBlockPruned(blockindex))}; | ||
|
||
if (verbosity == 1 || tx->IsCoinBase() || | ||
!blockindex || is_block_pruned || |
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.
It seems if verbosity==2
and !blockindex
this will trigger and we won't get the fee
and prevout
fields even when g_txindex
is available.. Is this expected behavior?
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.
You are correct. I have refactored the code to detect if blockhash was sent as a parameter.
What should we expect if the blockhash is not sent and the tx is in mempool? Should the fee field be available? (I would think so)
|
||
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, Chainstate& active_chainstate) | ||
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, Chainstate& active_chainstate, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_TXID) |
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.
static void TxToJSON(const CTransaction& tx, const uint256 hashBlock, UniValue& entry, Chainstate& active_chainstate, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_TXID) | |
static void TxToJSON(const CTransaction& tx, const uint256& hashBlock, UniValue& entry, Chainstate& active_chainstate, const CTxUndo* txundo = nullptr, TxVerbosity verbosity = TxVerbosity::SHOW_TXID) |
845913f
to
226b0b7
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.
Compiled and manually tested.
The RPC help result object could use some improvement. Right now the section is rendered like this:
"prevout" : { (json object)
"generated" : true|false, (boolean)
"value" : n, (numeric) The value in BTC
"height" : n, (numeric) previous block height
"scriptPubKey" : { (json object)
"asm" : "str", (string) the asm
"desc" : "str", (string) desc
"hex" : "str", (string) the hex
"address" : "str", (string, optional) The Bitcoin address (only if a well-defined address exists)
"type" : "str" (string) The type, eg 'pubkeyhash'
}
}
I guess there's no reason it should look much different to what's in getblock for verbosity=3? For reference:
"prevout" : { (json object) (Only if undo information is available)
"generated" : true|false, (boolean) Coinbase or not
"height" : n, (numeric) The height of the prevout
"value" : n, (numeric) The value in BTC
"scriptPubKey" : { (json object)
"asm" : "str", (string) Disassembly of the public key script
"desc" : "str", (string) Inferred descriptor for the output
"hex" : "hex", (string) The raw public key script bytes, hex-encoded
"address" : "str", (string, optional) The Bitcoin address (only if a well-defined address exists)
"type" : "str" (string) The type (one of: nonstandard, pubkey, pubkeyhash, scripthash, multisig, nulldata, witness_v0_scripthash, witness_v0_keyhash, witness_v1_taproot, witness_unknown)
}
}
226b0b7
to
6e5e745
Compare
I updated the RPC help to reflect getblock |
* Add optional fee response in BTC to getrawtransaction * Add optional prevout(s) response to getrawtransaction showing utxos being spent * Add getrawtransaction_verbosity functional test to validate fields
6e5e745
to
f866971
Compare
} | ||
// If request is verbosity >= 1 but no blockhash was given, then look up the blockindex | ||
if (request.params[2].isNull()) { | ||
LOCK(cs_main); |
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 like to avoid this lock, suggestions welcome.
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 f866971
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 f866971
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-tACK f866971
ACK f866971 |
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, thx. Left some doc nits.
}, | ||
RPCResult{"if verbose is set to true", | ||
RPCResult{"if verbosity is set to 1", | ||
// When updating this documentation, update `decoderawtransaction` in the same way. |
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: Is this dev comment still accurate, given that DecodeTxDoc
was split out for this reason?
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.
@MarcoFalke Fixed in #26734
Add fee response in BTC to getrawtransaction #23264
For Reviewers
fee
field andprevout