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

perf(consensus/blockstore): Remove validate basic call from LoadBlock… #62

Merged
merged 1 commit into from
May 22, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
- `[blockstore]` Remove a redundant `Header.ValidateBasic` call in `LoadBlockMeta`, 75% reducing this time.
([\#2964](https://github.com/cometbft/cometbft/pull/2964))
2 changes: 1 addition & 1 deletion store/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ func (bs *BlockStore) LoadBlockMeta(height int64) *types.BlockMeta {
panic(fmt.Errorf("unmarshal to cmtproto.BlockMeta: %w", err))
}

blockMeta, err := types.BlockMetaFromProto(pbbm)
blockMeta, err := types.BlockMetaFromTrustedProto(pbbm)
if err != nil {
panic(fmt.Errorf("error from proto blockMeta: %w", err))
}
Expand Down
10 changes: 9 additions & 1 deletion types/block_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,14 @@ func (bm *BlockMeta) ToProto() *cmtproto.BlockMeta {
}

func BlockMetaFromProto(pb *cmtproto.BlockMeta) (*BlockMeta, error) {
bm, err := BlockMetaFromTrustedProto(pb)
if err != nil {
return nil, err
}
return bm, bm.ValidateBasic()
}

func BlockMetaFromTrustedProto(pb *cmtproto.BlockMeta) (*BlockMeta, error) {
if pb == nil {
return nil, errors.New("blockmeta is empty")
}
Expand All @@ -62,7 +70,7 @@ func BlockMetaFromProto(pb *cmtproto.BlockMeta) (*BlockMeta, error) {
bm.Header = h
bm.NumTxs = int(pb.NumTxs)

return bm, bm.ValidateBasic()
return bm, nil
}

// ValidateBasic performs basic validation.
Expand Down
2 changes: 1 addition & 1 deletion types/block_meta_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func TestBlockMeta_ToProto(t *testing.T) {
t.Run(tt.testName, func(t *testing.T) {
pb := tt.bm.ToProto()

bm, err := BlockMetaFromProto(pb)
bm, err := BlockMetaFromTrustedProto(pb)

if !tt.expErr {
require.NoError(t, err, tt.testName)
Expand Down
Loading