Skip to content

Commit f5a234b

Browse files
Merge pull request #6385 from oasisprotocol/martin/fix/stateless-client/last-retained-height
client-stateless: GetLastRetainedHeight method returns light client's oldest height
2 parents 91d21cf + 4546610 commit f5a234b

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

.changelog/6382.bugfix.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
stateless-client: Fix incorrect GetLastRetainedHeight method
2+
3+
Previously, this method would return one of the provider's last retained
4+
heights which could cause issues with runtime light history reindexing.
5+
6+
This has been fixed, by setting the last retained height to the
7+
light client's last retained height, as this is the oldest height
8+
the stateless client can use to verify consensus data against.

go/consensus/cometbft/light/client.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ func (c *Client) LastTrustedHeight() (int64, error) {
122122
return height, nil
123123
}
124124

125+
// FirstTrustedHeight returns the first (oldest) trusted height.
126+
func (c *Client) FirstTrustedHeight() (int64, error) {
127+
height, err := c.lightClient.FirstTrustedHeight()
128+
if err != nil {
129+
return 0, err
130+
}
131+
if height == -1 {
132+
return 0, fmt.Errorf("no trusted headers")
133+
}
134+
return height, nil
135+
}
136+
125137
// VerifyHeader verifies the given header.
126138
func (c *Client) VerifyHeader(ctx context.Context, header *cmttypes.Header) error {
127139
c.mu.Lock()

go/consensus/cometbft/stateless/core.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,9 @@ func (c *Core) GetGenesisDocument(context.Context) (*genesisAPI.Document, error)
156156

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

164164
// GetLatestHeight implements api.Backend.

0 commit comments

Comments
 (0)