diff --git a/.changelog/6399.trivial.md b/.changelog/6399.trivial.md new file mode 100644 index 00000000000..e69de29bb2d diff --git a/go/consensus/cometbft/full/common.go b/go/consensus/cometbft/full/common.go index c771842351e..7b038bdcbb7 100644 --- a/go/consensus/cometbft/full/common.go +++ b/go/consensus/cometbft/full/common.go @@ -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. diff --git a/go/consensus/cometbft/light/block.go b/go/consensus/cometbft/light/block.go index d711f2f8311..e599066399f 100644 --- a/go/consensus/cometbft/light/block.go +++ b/go/consensus/cometbft/light/block.go @@ -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) @@ -24,7 +22,7 @@ func EncodeLightBlock(lb *cmttypes.LightBlock, height int64) (*consensus.LightBl } return &consensus.LightBlock{ - Height: height, + Height: lb.Height, Meta: meta, }, nil } diff --git a/go/consensus/cometbft/stateless/core.go b/go/consensus/cometbft/stateless/core.go index 8f4df9c54c0..ce2da1396cb 100644 --- a/go/consensus/cometbft/stateless/core.go +++ b/go/consensus/cometbft/stateless/core.go @@ -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.