-
Notifications
You must be signed in to change notification settings - Fork 123
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
feat(rpc): fill size field in getblock with verbosity=2 #9327
base: main
Are you sure you want to change the base?
Conversation
424da9f
to
83d1279
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.
Looks good to me, thank you.
let tx_count = CompactSizeMessage::try_from(txs.len()).unwrap(); | ||
let tx_raw = tx_count.zcash_serialize_to_vec().unwrap(); |
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.
Will it be better to return None
instead of panicking ?
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.
Blocks deserialized from the database are guaranteed to be serializable without errors. I should have used expect though, I will change it
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 in 826c6bf
Motivation
This fills the
size
field in thegetblock
RPC whenverbosity=2
.To support
verbosity=1
we would need to either take a performance hit (load all transactions from a block to get their sizes) or change the database to create a tx -> size index (which would be good to avoid if possible)Might close #9020
Solution
Add a
BlockAndSize
request to the state which reads the raw block header and txs, gets their sizes, computes the block size from them, and finally parses it all to return the block.Tests
I adjusted existing tests. I also tested it manually with
zcash-rpc-diff
.The block size calculation logic was also tested manually with a throwaway program that computed block sizes from the state with both approaches and asserted that they are equal.
Specifications & References
Follow-up Work
We need to decide if this is enough for now or if we want to support verbosity=1. In that case, we will need to create a new issue for it.
PR Checklist
C-exclude-from-changelog
label.