diff --git a/cmd/tendermint/commands/lite.go b/cmd/tendermint/commands/lite.go index 666c0d8b66d..b2a053cc784 100644 --- a/cmd/tendermint/commands/lite.go +++ b/cmd/tendermint/commands/lite.go @@ -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 diff --git a/lite2/rpc/client.go b/lite2/rpc/client.go index 4b6592cb2a4..2830839580f 100644 --- a/lite2/rpc/client.go +++ b/lite2/rpc/client.go @@ -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) }