From 7c3a5d975d734ac135096f6a57f951382b88f538 Mon Sep 17 00:00:00 2001 From: hacheigriega Date: Mon, 22 Mar 2021 23:03:18 +0900 Subject: [PATCH] consider when height is zero --- relayer/tm-light-client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/relayer/tm-light-client.go b/relayer/tm-light-client.go index bf389a3df..dc6b43d08 100644 --- a/relayer/tm-light-client.go +++ b/relayer/tm-light-client.go @@ -280,7 +280,7 @@ func (c *Chain) MustGetLatestLightHeight() uint64 { return uint64(height) } -// GetLightSignedHeaderAtHeight returns a signed header at a particular height. +// GetLightSignedHeaderAtHeight returns a signed header at a particular height (0 - the latest). func (c *Chain) GetLightSignedHeaderAtHeight(height int64) (*tmclient.Header, error) { // create database connection db, df, err := c.NewLightDB() @@ -294,6 +294,13 @@ func (c *Chain) GetLightSignedHeaderAtHeight(height int64) (*tmclient.Header, er return nil, err } + if height == 0 { + height, err = client.LastTrustedHeight() + if err != nil { + return nil, err + } + } + // VerifyLightBlock will return the header at provided height if it already exists in store, // otherwise it retrieves from primary and verifies against trusted store before returning. sh, err := client.VerifyLightBlockAtHeight(context.Background(), height, time.Now())