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(internal/blocksync): avoid double-calling types.BlockFromProto #3

Merged
merged 3 commits into from
Feb 16, 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 @@
- `[blocksync]` Avoid double-calling `types.BlockFromProto` for performance
reasons ([\#2016](https://github.com/cometbft/cometbft/pull/2016))
7 changes: 3 additions & 4 deletions blocksync/msgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,9 @@ func ValidateMsg(pb proto.Message) error {
return errors.New("negative Height")
}
case *bcproto.BlockResponse:
_, err := types.BlockFromProto(msg.Block)
if err != nil {
return err
}
// Avoid double-calling `types.BlockFromProto` for performance reasons.
// See https://github.com/cometbft/cometbft/issues/1964
return nil
case *bcproto.NoBlockResponse:
if msg.Height < 0 {
return errors.New("negative Height")
Expand Down
3 changes: 2 additions & 1 deletion blocksync/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ func (bcR *Reactor) ReceiveEnvelope(e p2p.Envelope) {
case *bcproto.BlockResponse:
bi, err := types.BlockFromProto(msg.Block)
if err != nil {
bcR.Logger.Error("Block content is invalid", "err", err)
bcR.Logger.Error("Peer sent us invalid block", "peer", e.Src, "msg", e.Message, "err", err)
bcR.Switch.StopPeerForError(e.Src, err)
return
}
bcR.pool.AddBlock(e.Src.ID(), bi, msg.Block.Size())
Expand Down
Loading