Skip to content

Commit

Permalink
consider when height is zero (cosmos#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
hacheigriega committed Mar 22, 2021
1 parent 58174f4 commit 9b185c7
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion relayer/tm-light-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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())
Expand Down

0 comments on commit 9b185c7

Please sign in to comment.