Skip to content

REST API: Add GetBlockHash API to algod v2#4566

Closed
Eric-Warehime wants to merge 2 commits into
algorand:masterfrom
Eric-Warehime:get-block-hash
Closed

REST API: Add GetBlockHash API to algod v2#4566
Eric-Warehime wants to merge 2 commits into
algorand:masterfrom
Eric-Warehime:get-block-hash

Conversation

@Eric-Warehime
Copy link
Copy Markdown
Contributor

Summary

Addresses algorand/algorand-sdk-testing#230 by implementing a new endpoint returning simply the hash of a Block header for a given round.

Test Plan

See added tests.

@Eric-Warehime Eric-Warehime marked this pull request as ready for review September 21, 2022 01:54
@codecov
Copy link
Copy Markdown

codecov Bot commented Sep 21, 2022

Codecov Report

Merging #4566 (873e31f) into master (e79e29c) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##           master    #4566      +/-   ##
==========================================
- Coverage   54.10%   54.09%   -0.02%     
==========================================
  Files         401      401              
  Lines       51625    51635      +10     
==========================================
  Hits        27931    27931              
- Misses      21343    21349       +6     
- Partials     2351     2355       +4     
Impacted Files Coverage Δ
daemon/algod/api/server/v2/handlers.go 0.00% <0.00%> (ø)
ledger/blockqueue.go 85.63% <0.00%> (-2.88%) ⬇️
crypto/merkletrie/trie.go 66.42% <0.00%> (-2.19%) ⬇️
crypto/merkletrie/node.go 91.62% <0.00%> (-1.87%) ⬇️
catchup/peerSelector.go 98.95% <0.00%> (-1.05%) ⬇️
catchup/service.go 68.14% <0.00%> (-0.50%) ⬇️
network/wsNetwork.go 64.82% <0.00%> (+0.19%) ⬆️
cmd/tealdbg/debugger.go 73.49% <0.00%> (+0.80%) ⬆️
network/wsPeer.go 68.46% <0.00%> (+2.42%) ⬆️
ledger/roundlru.go 96.22% <0.00%> (+5.66%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@winder winder changed the title algod: Add GetBlockHash API to algod v2 REST API: Add GetBlockHash API to algod v2 Sep 21, 2022
winder
winder previously approved these changes Sep 21, 2022
Copy link
Copy Markdown
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Comment thread daemon/algod/api/algod.oas2.json Outdated
err = protocol.DecodeJSON(rec.Body.Bytes(), &blkHashResponse)
require.NoError(t, err)
require.Equal(t, crypto.HashObj(blkResponse.Block.BlockHeader).String(), blkHashResponse.BlockHash)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe assert that the hash doesn't contain AAAAAAAA (the zero hash)

When I did this, I grabbed two blocks and asserted that block 2's "prev" was the equal to block 1's hash
master...cce:go-algorand:add-v2-block-hash#diff-c9875030556c016ef35a4b47373f5005ee03b961a82157bed9ef734881edddc3R253-R268

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty conflicted about the way "prev" is implemented...Because it's wrapped in a BlockHash object which overrides the String() method by prepending "blk-", these would produce different outputs

BlockHash(crypto.Digest([]byte{"AAAAAA"})).String()
crypto.Digest([]byte{"AAAAAA"}).String()

On the other hand, the crypto.Digest String() method does a base-32 encoding of the hash bytes when converting to a string.

I'm tempted to just return bytes from GetBlockHash and let the user do whatever conversion they want, but on the other hand I agree that if a returned BlockHash didn't match up with what was in "prev" it would be very confusing for the end user.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to be out for a while so I'll leave the decision up to @winder but in my opinion, returning "blk-1235" as a hash value from this API feels strange.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh good point, which format is "correct" for this purpose, the blk-XXX hash version or just XXX? It seems the REST API is already using the blk- prefixed version for the existing endpoint, so there's one point for consistency. I don't really know much about where else these blk- prefix hashes appear

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My only contributions here are some observations:

  1. algoexplorer seems to remove the blk-.
  2. Indexer b64 encodes it.

From this, it seems like everyone agrees that blk- is a little strange so this is a consistency question. For consistency, I think we should select the B32 encoding over B64. If someone wants to compare them they'll have to remove the blk- prefix.

@winder
Copy link
Copy Markdown
Contributor

winder commented Sep 23, 2022

Moving to #4580

@winder winder closed this Sep 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants