-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Convert Tendermint Block Response #4922
Convert Tendermint Block Response #4922
Conversation
…ddresses to the ValAddress type
…lock-response-conversion
Should I write some tests for this? If so, which ones? |
Codecov Report
@@ Coverage Diff @@
## master #4922 +/- ##
==========================================
- Coverage 54.79% 54.22% -0.58%
==========================================
Files 307 312 +5
Lines 18296 18611 +315
==========================================
+ Hits 10026 10092 +66
- Misses 7494 7733 +239
- Partials 776 786 +10 |
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.
Overall LGTM. I'd like to see a simple test to check that the block addresses start with the given prefix. Eg:
require.True(t, strings.HasPrefix(valAddress, "cosmos1"))
I've reverted back the go.sum and go.mod file to the master version. I've also added a simple test. However, I would like to have a test that you can make sure works properly. For this I would need
I'm also not able to reproduce what @alexanderbez said about the response not having the data inside it |
@RiccardoM I recommend you launch a local network and compare block responses pre and post changes. You'll see it's missing a bunch of the fields.
|
@alexanderbez thanks for the tip. I've updated the code to fix those errors. |
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 pretty close @RiccardoM! Just general feedback on style. Also, starting to feel that it's a shame to introduce so much code just to change a single field type :-/
@alexanderbez Solved everything. It feels a bit like a shame, but I think it improves a lot the developer UX |
Ping @alexanderbez the issues should be solved. Can we merge this? |
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.
LGTM. I'd even say we could move the wrapper types into /types
to provide an easy access to them for modules such as IBC.
Thoughts @alexanderbez @jackzampolin?
Up @alexanderbez, @jackzampolin @fedekunze. Updates on this? |
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.
Few changes are required
client/rpc/block_converter_test.go
Outdated
ctypes "github.com/tendermint/tendermint/rpc/core/types" | ||
) | ||
|
||
var defaultBlockJson = `{"block_meta":{"block_id":{"hash":"30CD3A9EF2082FF9F2575655E99E37ACC3936DC9E534ADF0BD7436C76258225C","parts":{"total":"1","hash":"463460DA73FA0AE441B6041BF2683AE625CE2D9FD290F4C86CD83D1A7FB9F439"}},"header":{"version":{"block":"10","app":"0"},"chain_id":"test-chain-RoCfX4","height":"16","time":"2019-10-16T09:47:21.054275229Z","num_txs":"0","total_txs":"0","last_block_id":{"hash":"168D140232DA3A59757658E257168B6BCE62024F574CA222C2D449BAB1AE4023","parts":{"total":"1","hash":"4E6D7A1C7DE6942470394C21B132A2D9F89B31908C3B6FA8C2AB96A87553B96E"}},"last_commit_hash":"3483509FCC8048496E9B85E1E4C90A3B6E5944F022FE3C0709096932A010F712","data_hash":"","validators_hash":"61E69204249E5EE6F777C0566040929276A1900CE665BCB11006CABF9A4ED9A3","next_validators_hash":"61E69204249E5EE6F777C0566040929276A1900CE665BCB11006CABF9A4ED9A3","consensus_hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","app_hash":"070A8213F67F494F7D27A6296C29F0DF62DFA18FD37FB592D9761A44DEE96528","last_results_hash":"","evidence_hash":"","proposer_address":"E8B4AF895B301C3D7108CA93A0B9234E3A2A4B21"}},"block":{"header":{"version":{"block":"10","app":"0"},"chain_id":"test-chain-RoCfX4","height":"16","time":"2019-10-16T09:47:21.054275229Z","num_txs":"0","total_txs":"0","last_block_id":{"hash":"168D140232DA3A59757658E257168B6BCE62024F574CA222C2D449BAB1AE4023","parts":{"total":"1","hash":"4E6D7A1C7DE6942470394C21B132A2D9F89B31908C3B6FA8C2AB96A87553B96E"}},"last_commit_hash":"3483509FCC8048496E9B85E1E4C90A3B6E5944F022FE3C0709096932A010F712","data_hash":"","validators_hash":"61E69204249E5EE6F777C0566040929276A1900CE665BCB11006CABF9A4ED9A3","next_validators_hash":"61E69204249E5EE6F777C0566040929276A1900CE665BCB11006CABF9A4ED9A3","consensus_hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","app_hash":"070A8213F67F494F7D27A6296C29F0DF62DFA18FD37FB592D9761A44DEE96528","last_results_hash":"","evidence_hash":"","proposer_address":"E8B4AF895B301C3D7108CA93A0B9234E3A2A4B21"},"data":{"txs":null},"evidence":{"evidence":null},"last_commit":{"block_id":{"hash":"168D140232DA3A59757658E257168B6BCE62024F574CA222C2D449BAB1AE4023","parts":{"total":"1","hash":"4E6D7A1C7DE6942470394C21B132A2D9F89B31908C3B6FA8C2AB96A87553B96E"}},"precommits":[{"type":2,"height":"15","round":"0","block_id":{"hash":"168D140232DA3A59757658E257168B6BCE62024F574CA222C2D449BAB1AE4023","parts":{"total":"1","hash":"4E6D7A1C7DE6942470394C21B132A2D9F89B31908C3B6FA8C2AB96A87553B96E"}},"timestamp":"2019-10-16T09:47:21.054275229Z","validator_address":"E8B4AF895B301C3D7108CA93A0B9234E3A2A4B21","validator_index":"0","signature":"eXB1NPmarUC5+2SCUQiWUCoGqtq0nrSn7giMAF/zWbfv3KmueE+1NoZ0CPLJAhBodz8Y8oL8xVy6ElA7J72kBw=="}]}}}` |
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.
Please avoid using global variables when writing test cases. This is currently used by one test case only
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.
Fixed
…on' into riccardo/block-response-conversion
// does not respect the JSON stdlib embedding semantics. | ||
func (b Block) MarshalJSON() ([]byte, error) { | ||
type blockJSON Block | ||
return json.Marshal(blockJSON(b)) |
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.
copylocks: call of blockJSON copies lock value: github.com/cosmos/cosmos-sdk/client/rpc.Block contains github.com/tendermint/tendermint/types.Block contains sync.Mutex (from govet
)
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.
We should probably return a reference to avoid mutex copying.
@alessio @alexanderbez mind reviewing again? |
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.
Tested this out again. Looks good but I think two fields are still missing.
|
||
// test when the block is not nil | ||
var block ctypes.ResultBlock | ||
defaultBlockJSON := `{"block_meta":{"block_id":{"hash":"30CD3A9EF2082FF9F2575655E99E37ACC3936DC9E534ADF0BD7436C76258225C","parts":{"total":"1","hash":"463460DA73FA0AE441B6041BF2683AE625CE2D9FD290F4C86CD83D1A7FB9F439"}},"header":{"version":{"block":"10","app":"0"},"chain_id":"test-chain-RoCfX4","height":"16","time":"2019-10-16T09:47:21.054275229Z","num_txs":"0","total_txs":"0","last_block_id":{"hash":"168D140232DA3A59757658E257168B6BCE62024F574CA222C2D449BAB1AE4023","parts":{"total":"1","hash":"4E6D7A1C7DE6942470394C21B132A2D9F89B31908C3B6FA8C2AB96A87553B96E"}},"last_commit_hash":"3483509FCC8048496E9B85E1E4C90A3B6E5944F022FE3C0709096932A010F712","data_hash":"","validators_hash":"61E69204249E5EE6F777C0566040929276A1900CE665BCB11006CABF9A4ED9A3","next_validators_hash":"61E69204249E5EE6F777C0566040929276A1900CE665BCB11006CABF9A4ED9A3","consensus_hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","app_hash":"070A8213F67F494F7D27A6296C29F0DF62DFA18FD37FB592D9761A44DEE96528","last_results_hash":"","evidence_hash":"","proposer_address":"E8B4AF895B301C3D7108CA93A0B9234E3A2A4B21"}},"block":{"header":{"version":{"block":"10","app":"0"},"chain_id":"test-chain-RoCfX4","height":"16","time":"2019-10-16T09:47:21.054275229Z","num_txs":"0","total_txs":"0","last_block_id":{"hash":"168D140232DA3A59757658E257168B6BCE62024F574CA222C2D449BAB1AE4023","parts":{"total":"1","hash":"4E6D7A1C7DE6942470394C21B132A2D9F89B31908C3B6FA8C2AB96A87553B96E"}},"last_commit_hash":"3483509FCC8048496E9B85E1E4C90A3B6E5944F022FE3C0709096932A010F712","data_hash":"","validators_hash":"61E69204249E5EE6F777C0566040929276A1900CE665BCB11006CABF9A4ED9A3","next_validators_hash":"61E69204249E5EE6F777C0566040929276A1900CE665BCB11006CABF9A4ED9A3","consensus_hash":"048091BC7DDC283F77BFBF91D73C44DA58C3DF8A9CBC867405D8B7F3DAADA22F","app_hash":"070A8213F67F494F7D27A6296C29F0DF62DFA18FD37FB592D9761A44DEE96528","last_results_hash":"","evidence_hash":"","proposer_address":"E8B4AF895B301C3D7108CA93A0B9234E3A2A4B21"},"data":{"txs":null},"evidence":{"evidence":null},"last_commit":{"block_id":{"hash":"168D140232DA3A59757658E257168B6BCE62024F574CA222C2D449BAB1AE4023","parts":{"total":"1","hash":"4E6D7A1C7DE6942470394C21B132A2D9F89B31908C3B6FA8C2AB96A87553B96E"}},"precommits":[{"type":2,"height":"15","round":"0","block_id":{"hash":"168D140232DA3A59757658E257168B6BCE62024F574CA222C2D449BAB1AE4023","parts":{"total":"1","hash":"4E6D7A1C7DE6942470394C21B132A2D9F89B31908C3B6FA8C2AB96A87553B96E"}},"timestamp":"2019-10-16T09:47:21.054275229Z","validator_address":"E8B4AF895B301C3D7108CA93A0B9234E3A2A4B21","validator_index":"0","signature":"eXB1NPmarUC5+2SCUQiWUCoGqtq0nrSn7giMAF/zWbfv3KmueE+1NoZ0CPLJAhBodz8Y8oL8xVy6ElA7J72kBw=="}]}}}` |
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.
Can we use block JSON that has all fields populated (i.e. txs and evidence). I submitted a tx (using this branch) and when querying the block, I don't see the tx under block.txs
. I bet the same will hold true for block.evidence
.
So ideally we have:
// ...
convertedBlock := ConvertBlockResult(&block)
expectedOut := `{...}`
bz, err := cdc.MarshalJSON(convertedBlock)
require.NoError(t, err)
require.Equal(t, expectedOut, string(bz))
// does not respect the JSON stdlib embedding semantics. | ||
func (b Block) MarshalJSON() ([]byte, error) { | ||
type blockJSON Block | ||
return json.Marshal(blockJSON(b)) |
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.
We should probably return a reference to avoid mutex copying.
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
Converts a
ResultBlock
into aCosmosResultBlock
having validator addresses represented as Bech32 addresses instead of Hex addresses.Closes #3544
docs/
)Unreleased
section inCHANGELOG.md
Files changed
in the github PR explorerFor Admin Use: