Skip to content
Draft
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
Empty file added .changelog/6399.trivial.md
Empty file.
31 changes: 10 additions & 21 deletions go/consensus/cometbft/full/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -612,37 +612,26 @@ func (n *commonNode) GetLightBlock(ctx context.Context, height int64) (*consensu
return nil, err
}

var lb cmttypes.LightBlock

// Don't use the client as that imposes stupid pagination. Access the state database directly.
lb.ValidatorSet, err = n.stateStore.LoadValidators(tmHeight)
validators, err := n.stateStore.LoadValidators(tmHeight)
if err != nil {
return nil, consensusAPI.ErrVersionNotFound
}

// For future heights, leave the signed header empty and return only
// the validator set.
lastTmHeight, err := n.heightToCometBFTHeight(consensusAPI.HeightLatest)
commit, err := cmtcore.Commit(n.rpcCtx, &tmHeight)
if err != nil {
return nil, err
return nil, consensusAPI.ErrVersionNotFound
}
if commit == nil || commit.Header == nil {
return nil, consensusAPI.ErrVersionNotFound
}

if tmHeight <= lastTmHeight {
commit, err := cmtcore.Commit(n.rpcCtx, &tmHeight)
if err != nil {
return nil, fmt.Errorf("cometbft: failed to find block commit: %w", err)
}
if commit == nil {
return nil, fmt.Errorf("cometbft: block commit not found")
}
if commit.Header == nil {
return nil, fmt.Errorf("cometbft: block commit has no header")
}

lb.SignedHeader = &commit.SignedHeader
lb := cmttypes.LightBlock{
SignedHeader: &commit.SignedHeader,
ValidatorSet: validators,
}

return light.EncodeLightBlock(&lb, tmHeight)
return light.EncodeLightBlock(&lb)
}

// Implements consensusAPI.Backend.
Expand Down
6 changes: 2 additions & 4 deletions go/consensus/cometbft/light/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import (
)

// EncodeLightBlock creates a new consensus light bock from a CometBFT light block.
//
// The height must be provided explicitly, as the light block's header may be empty.
func EncodeLightBlock(lb *cmttypes.LightBlock, height int64) (*consensus.LightBlock, error) {
func EncodeLightBlock(lb *cmttypes.LightBlock) (*consensus.LightBlock, error) {
plb, err := lightBlockToProto(lb)
if err != nil {
return nil, fmt.Errorf("failed to convert light block: %w", err)
Expand All @@ -24,7 +22,7 @@ func EncodeLightBlock(lb *cmttypes.LightBlock, height int64) (*consensus.LightBl
}

return &consensus.LightBlock{
Height: height,
Height: lb.Height,
Meta: meta,
}, nil
}
Expand Down
2 changes: 1 addition & 1 deletion go/consensus/cometbft/stateless/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ func (c *Core) GetLightBlock(ctx context.Context, height int64) (*consensusAPI.L
if err != nil {
return nil, err
}
return light.EncodeLightBlock(lb, lb.Height)
return light.EncodeLightBlock(lb)
}

// GetValidators implements api.Backend.
Expand Down
Loading