[RPC] Transaction details in getblock #8704

Open
wants to merge 2 commits into
from

Projects

None yet

5 participants

@achow101
Contributor

Adds an optional parameter extraVerbose to getblock to have transaction details displayed in a getblock call.

@dcousens
Contributor
dcousens commented Sep 12, 2016 edited

concept NACK, is two RPC requests really so bad?

edit: weak concept NACK

@achow101
Contributor

@dcousens yes, two RPC calls is really bad, especially when you want the details of all the transactions in a block. Then you end up running getrawtransaction thousands of times. Also, AFAICT, this doesn't require the txindex in order to get the transactions, unlike getrawtransaction.

@dcousens
Contributor
dcousens commented Sep 12, 2016 edited

@dcousens yes, two RPC calls is really bad

Why?
If you're following best practices (RPC is over localhost only) in terms of access, the latency should be irrelevant.

In a batched RPC call, the overhead is literally just 1RTT more.
Not N (aka, thousands), 1.

AFAICT, this doesn't require the txindex in order to get the transactions, unlike getrawtransaction.

Perhaps getrawtransaction should have an optional block parameter?

edit: In fact, adding that option would be significantly more useful than this RTT optimisation IMHO.

@achow101
Contributor

In a batched RPC call, the overhead is literally just 1RTT more.
Not N (aka, thousands), 1.

How?

edit: In fact, adding that option would be significantly more useful than this RTT optimisation IMHO.

Well the functionality to this was already in the code. The BlockToJson method took a parameter for txDetails which was by default false. This just lets you set that to true.

@dcousens
Contributor

http://www.jsonrpc.org/specification#batch

What language are you using? Your RPC library should be able to handle this quite easily.

@achow101
Contributor

Huh. Didn't know that. I've been using bash with either curl or bitcoin-cli and python.

@laanwj
Member
laanwj commented Sep 13, 2016 edited

Saving roundtrip time is not a valid reason to add a RPC API (see discussion in #8457).

Also, AFAICT, this doesn't require the txindex in order to get the transactions, unlike getrawtransaction.

This is the only important fact here: you cannot get this information any other way. getrawtransaction won't get you transactions in blocks, at least without tx index.

The only way to get this information right now is to getblock raw then parse the block locally.

So concept ACK because of that.

@dcousens
Contributor
dcousens commented Sep 13, 2016 edited

@laanwj would it maybe be better to add functionality via getrawtransaction w/ a block id? (perhaps in addition to this)

@laanwj
Member
laanwj commented Sep 14, 2016 edited

would it maybe be better to add functionality via getrawtransaction w/ a block id? (perhaps in addition to this)

Well yes a "gather transaction [X,...] from prespecified block Y" RPC call could be useful in some rare cases. But on the other hand it'll still have to read the entire block from disk and deserialize it. It's terribly inefficient already.
So if it decoded the entire block why not report details for the entire block as done here?

@dcousens
Contributor
dcousens commented Sep 14, 2016 edited

@laanwj indeed! Forgot about the resulting deserialization.

@luke-jr
Member
luke-jr commented Sep 22, 2016

Concept ACK for all the reasons @laanwj already discussed.

src/rpc/blockchain.cpp
throw runtime_error(
- "getblock \"hash\" ( verbose )\n"
+ "getblock \"hash\" ( verbose ) ( extraVerbose )\n"
@luke-jr
luke-jr Oct 18, 2016 Member

Double boolean here seems ugly. Maybe allow verbose to be boolean or a number 0-2 (with 2 being extraVerbose)?

@laanwj
laanwj Oct 18, 2016 Member

It is ugly, but overloading on type in JSON which is essentially dynamically typed is also ugly.

Named parameters as implemented in #8811 would make this more bearable.

@laanwj
laanwj Oct 18, 2016 edited Member

I do agree that for a new interface, a scale for verbosity would have made more sense instead of a boolean.
Maybe that's a better choice I'm just not sure. Changing the meaning of existing arguments is always annoying and means extra testing for backwards compatibility.

@laanwj
Member
laanwj commented Oct 26, 2016 edited

I'm starting to realize that @luke-jr's idea to accept 0-2 isn't such a bad idea after all. Just rename the argument 'verbosityLevel'. It is easier to use and understand from a user perspective than two booleans (we regularly get confused there in the tests ourselves). Also it'd remove having to deal with the redundant and nonsensical combo verbose=false extraVerbose=true.

It should still accept false and true too. For consistency we should do the same in getrawtransaction. This method currently accepts a verbose argument that can be 0 or 1 but not false or true. The mapping false:0,true:1 should be added there (not in this pull though).

Also: needs rebase.

@achow101 achow101 Optional parameter extraVerbose for getblock
Adds an optional parameter extraVerbose to getblock to have transaction details displayed in a getblock call.
b2b15f5
@achow101
Contributor

How should it document in the help message that the old behavior is still accepted?

@achow101
Contributor

Rebased and made verbose an int from 0-2

@luke-jr
Member
luke-jr commented Nov 24, 2016

@achow101 The old behaviour should be considered deprecated, and therefore not documented.

src/rpc/blockchain.cpp
"\nArguments:\n"
"1. \"hash\" (string, required) The block hash\n"
- "2. verbose (boolean, optional, default=true) true for a json object, false for the hex encoded data\n"
- "\nResult (for verbose = true):\n"
+ "2. verbose (boolean, optional, default=1) 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data\n"
@luke-jr
luke-jr Nov 24, 2016 Member

Should be renamed to verbosity.

@achow101 achow101 Use a verbosity instead of two verbose parameters
Instead of having verbose and extraVerbose, verbose is just changed to an int. This can have values from 0-2 for each level of verbosity.
82a491f
@achow101
Contributor

@luke-jr done

@luke-jr luke-jr added a commit to bitcoinknots/bitcoin that referenced this pull request Dec 21, 2016
@achow101 @luke-jr achow101 + luke-jr Use a verbosity instead of two verbose parameters
Instead of having verbose and extraVerbose, verbose is just changed to an int. This can have values from 0-2 for each level of verbosity.

Github-Pull: #8704
Rebased-From: 82a491f
645b21c
@achow101
Contributor

merge please?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment