Skip to content

Commit

Permalink
Merge pull request #3 from osmosis-labs/adam/avoid-double-call-block-…
Browse files Browse the repository at this point in the history
…proto

perf(internal/blocksync): avoid double-calling `types.BlockFromProto`…
  • Loading branch information
czarcas7ic committed Feb 16, 2024
1 parent 95b5f92 commit 57e011d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
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

0 comments on commit 57e011d

Please sign in to comment.