Skip to content
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

getblockcount() and getblockhash() functions return conflicting results #2735

Closed
edwardlouissullivan opened this issue Nov 15, 2017 · 4 comments
Assignees
Labels
A-documentation Area: Documentation A-rpc-interface Area: RPC interface E-good-first-issue Effort: Suitable for someone new to the codebase. M-user-support User support issue
Milestone

Comments

@edwardlouissullivan
Copy link

edwardlouissullivan commented Nov 15, 2017

Issue overview

The getblockcount() and getblockhash() functions return inconsistent results when run from the zcash4mac client. I suspect that the bug is inside the daemon, because the daemon defines the two aforementioned functions.

Detailed bug description

When I ran the commands "./zcash-cli getblockhash 0" and "./zcash-cli getblockhash 219417" back to back, I received hash values for both, which implies that, at that moment, there were are at least 219418 blocks on the best block chain.

Next I ran the command "./zcash-cli getblockcount", which returned the value 219417.

Do you see the inconsistency? 219418 > 219417. The two methods suggest different values for the total number of blocks in the longest chain.

Both commands, getblockhash and getblockcount, in their "help" documentation, claim to refer to the longest or best block chain. I assume that "longest" and "best" mean the same thing in this context.


bulbasaur% ./zcash-cli help  getblockcount
getblockcount
Returns the number of blocks in the longest block chain.
bulbasaur% ./zcash-cli help  getblockhash
getblockhash index
Returns hash of block in best-block-chain at index provided.

Also, as shown above, the documentation for getblockcount specifically states that it returns the "number of blocks", not the index of the highest block.

For reference, these are the commands that I ran, presented in the same order that I ran them:

bulbasaur% ./zcash-cli getblockhash 219417
0000000014517fdeb0b61dbcd9501fc47b9f8bbd7198dd0ab1ea44fa420d2f1d
bulbasaur% ./zcash-cli getblockhash 0
00040fe8ec8471911baa1db1266ea15dd06b4a8a5c453883c000b031973dce08
bulbasaur% ./zcash-cli getblockcount
219417

Disclaimer

This "bug" might just be a minor case of imprecise language in the documentation.

Also, I don't know the details of the zcash protocol, so what I perceive as a bug might actually be the desired behavior.

@daira
Copy link
Contributor

daira commented Nov 15, 2017

I believe you're correct that getblockcount is supposed to return the number of blocks in the best block chain, not necessarily the longest. [Edit: minus one, as explained below.]

@ioptio ioptio added this to Blocked in User Support Nov 20, 2017
@daira daira added the A-rpc-interface Area: RPC interface label Nov 22, 2017
@mdr0id mdr0id added the M-user-support User support issue label Apr 16, 2018
@mms710 mms710 added this to Needs Prioritization in Arborist Team Jan 3, 2019
@mms710 mms710 assigned daira and unassigned daira Jan 28, 2019
@daira daira added the A-documentation Area: Documentation label Jan 28, 2019
@mms710 mms710 added this to Needs Prioritization in Encouraged Community Work via automation Jan 28, 2019
@mms710 mms710 removed this from Needs Prioritization in Arborist Team Jan 28, 2019
@daira
Copy link
Contributor

daira commented Jan 28, 2019

Blocks are indexed from 0 for the genesis block. getblockhash uses this zero-based index, while getblockcount actually returns the index (also called height) of the best block, not the number of blocks. Alternatively, it excludes the genesis block from the count.

We should change the documentation for getblockcount to clarify this. It should say:

getblockcount

Returns the height of the most recent block in the best valid block chain (equivalently,
the number of blocks in this chain excluding the genesis block).

Result:
n    (numeric) The height of the most recent block.

@daira daira added the E-good-first-issue Effort: Suitable for someone new to the codebase. label Jan 28, 2019
@daira daira removed their assignment Jan 28, 2019
@mms710 mms710 moved this from Needs Prioritization to Prioritized Backlog in Encouraged Community Work May 29, 2019
@elijahhampton
Copy link

Updated the CLI with the correct help message: @daira

#6767

@daira
Copy link
Contributor

daira commented Sep 23, 2023

Fixed by #6767.

@daira daira closed this as completed Sep 23, 2023
User Support automation moved this from Blocked to Complete Sep 23, 2023
Encouraged Community Work automation moved this from Prioritized Backlog to Done Sep 23, 2023
@daira daira added this to the Release 5.7.0 milestone Sep 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-documentation Area: Documentation A-rpc-interface Area: RPC interface E-good-first-issue Effort: Suitable for someone new to the codebase. M-user-support User support issue
Projects
User Support
  
Complete
Continuous Improvement
  
Awaiting triage
Development

No branches or pull requests

5 participants