Skip to content
Merged
Show file tree
Hide file tree
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
8 changes: 8 additions & 0 deletions .changelog/6382.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
stateless-client: Fix incorrect GetLastRetainedHeight method

Previously, this method would return one of the provider's last retained
heights which could cause issues with runtime light history reindexing.

This has been fixed, by setting the last retained height to the
light client's last retained height, as this is the oldest height
the stateless client can use to verify consensus data against.
12 changes: 12 additions & 0 deletions go/consensus/cometbft/light/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,18 @@ func (c *Client) LastTrustedHeight() (int64, error) {
return height, nil
}

// FirstTrustedHeight returns the first (oldest) trusted height.
func (c *Client) FirstTrustedHeight() (int64, error) {
height, err := c.lightClient.FirstTrustedHeight()
if err != nil {
return 0, err
}
if height == -1 {
return 0, fmt.Errorf("no trusted headers")
}
return height, nil
}

// VerifyHeader verifies the given header.
func (c *Client) VerifyHeader(ctx context.Context, header *cmttypes.Header) error {
c.mu.Lock()
Expand Down
6 changes: 3 additions & 3 deletions go/consensus/cometbft/stateless/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ func (c *Core) GetGenesisDocument(context.Context) (*genesisAPI.Document, error)

// GetLastRetainedHeight implements api.Backend.
func (c *Core) GetLastRetainedHeight(ctx context.Context) (int64, error) {
// The last retained height cannot be verified, nor does it need to be,
// as it is not sensitive information.
return c.provider.GetLastRetainedHeight(ctx)
// The last retained height equals to the last retained light client height
// as this is the oldest height stateless client can verify the data against.
return c.lightClient.FirstTrustedHeight()
}

// GetLatestHeight implements api.Backend.
Expand Down
Loading