Browse Source

lite2: correctly return the results of the "latest" block (#4931)

Closes #4837

- `/block_results`

  before:

  failed to update light client to 7: failed to obtain the header #7: signed header not found

  after:

  We can't return the latest block results because we won't be able to
  prove them. Return the results for the previous block instead.

- /block_results?height=X`

  no changes
pull/4943/head
Anton Kaliaev 4 years ago
committed by GitHub
parent
commit
8ab0a4c3b0
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 7 deletions
  1. +4
    -4
      cmd/tendermint/commands/lite.go
  2. +18
    -3
      lite2/rpc/client.go

+ 4
- 4
cmd/tendermint/commands/lite.go View File

@ -36,16 +36,16 @@ Example:
start a fresh instance:
lite cosmoshub-3 -p 52.57.29.196:26657 -w public-seed-node.cosmoshub.certus.one:26657
lite cosmoshub-3 -p http://52.57.29.196:26657 -w http://public-seed-node.cosmoshub.certus.one:26657
--height 962118 --hash 28B97BE9F6DE51AC69F70E0B7BFD7E5C9CD1A595B7DC31AFF27C50D4948020CD
continue from latest state:
lite cosmoshub-3 -p 52.57.29.196:26657 -w public-seed-node.cosmoshub.certus.one:26657
lite cosmoshub-3 -p http://52.57.29.196:26657 -w http://public-seed-node.cosmoshub.certus.one:26657
`,
RunE: runProxy,
Args: cobra.ExactArgs(1),
Example: `lite cosmoshub-3 -p 52.57.29.196:26657 -w public-seed-node.cosmoshub.certus.one:26657
Example: `lite cosmoshub-3 -p http://52.57.29.196:26657 -w http://public-seed-node.cosmoshub.certus.one:26657
--height 962118 --hash 28B97BE9F6DE51AC69F70E0B7BFD7E5C9CD1A595B7DC31AFF27C50D4948020CD`,
}
@ -102,7 +102,7 @@ func runProxy(cmd *cobra.Command, args []string) error {
db, err := dbm.NewGoLevelDB("lite-client-db", home)
if err != nil {
return fmt.Errorf("new goleveldb: %w", err)
return fmt.Errorf("can't create a db: %w", err)
}
var c *lite.Client


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

@ -302,8 +302,23 @@ func (c *Client) BlockByHash(hash []byte) (*ctypes.ResultBlock, error) {
return res, nil
}
// BlockResults returns the block results for the given height. If no height is
// provided, the results of the block preceding the latest are returned.
func (c *Client) BlockResults(height *int64) (*ctypes.ResultBlockResults, error) {
res, err := c.next.BlockResults(height)
var h int64
if height == nil {
res, err := c.next.Status()
if err != nil {
return nil, fmt.Errorf("can't get latest height: %w", err)
}
// Can't return the latest block results here because we won't be able to
// prove them. Return the results for the previous block instead.
h = res.SyncInfo.LatestBlockHeight - 1
} else {
h = *height
}
res, err := c.next.BlockResults(&h)
if err != nil {
return nil, err
}
@ -314,14 +329,14 @@ func (c *Client) BlockResults(height *int64) (*ctypes.ResultBlockResults, error)
}
// Update the light client if we're behind.
h, err := c.updateLiteClientIfNeededTo(res.Height + 1)
trustedHeader, err := c.updateLiteClientIfNeededTo(h + 1)
if err != nil {
return nil, err
}
// Verify block results.
results := types.NewResults(res.TxsResults)
if rH, tH := results.Hash(), h.LastResultsHash; !bytes.Equal(rH, tH) {
if rH, tH := results.Hash(), trustedHeader.LastResultsHash; !bytes.Equal(rH, tH) {
return nil, fmt.Errorf("last results %X does not match with trusted last results %X",
rH, tH)
}


Loading…
Cancel
Save