Browse Source

lite2: verify ConsensusHash in rpc client

______

For contributor use:

- [ ] Wrote tests
- [ ] Updated CHANGELOG_PENDING.md
- [ ] Linked to Github issue with discussion and accepted design OR link to spec that describes this work.
- [ ] Updated relevant documentation (`docs/`) and code comments
- [x] Re-reviewed `Files changed` in the Github PR explorer
pull/4625/head
Anton Kaliaev 5 years ago
committed by GitHub
parent
commit
26c9134f35
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 1 deletions
  1. +18
    -1
      lite2/rpc/client.go

+ 18
- 1
lite2/rpc/client.go View File

@ -156,7 +156,24 @@ func (c *Client) ConsensusState() (*ctypes.ResultConsensusState, error) {
}
func (c *Client) ConsensusParams(height *int64) (*ctypes.ResultConsensusParams, error) {
return c.next.ConsensusParams(height)
res, err := c.next.ConsensusParams(height)
if err != nil {
return nil, err
}
// Update the light client if we're behind.
h, err := c.updateLiteClientIfNeededTo(res.BlockHeight)
if err != nil {
return nil, err
}
// Verify hash.
if cH, tH := res.ConsensusParams.Hash(), h.ConsensusHash; !bytes.Equal(cH, tH) {
return nil, fmt.Errorf("params hash %X does not match trusted hash %X",
cH, tH)
}
return res, nil
}
func (c *Client) Health() (*ctypes.ResultHealth, error) {


Loading…
Cancel
Save