Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug when getting latest light header #465

Merged
merged 2 commits into from
Mar 22, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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