Skip to content

fix(blocksync): backport of upstream #5860#47

Merged
bar-bera merged 1 commit into
bera-v1.xfrom
fix-mem-alloc-blowing
May 29, 2026
Merged

fix(blocksync): backport of upstream #5860#47
bar-bera merged 1 commit into
bera-v1.xfrom
fix-mem-alloc-blowing

Conversation

@bar-bera
Copy link
Copy Markdown

fix(blocksync): validate blocksync response sender and signature count (cometbft#5860)


Adds additional validation to blocksync, ensuring before response unmarshalling that we have made a BlockRequest to the peer that is sending us a BlockResponse recently, and also that the response contains a valid amount of commit signatures (not > MaxVoteCount). To do this preunmarshal validation, we have added a MsgBytesFilter interface that Reactors can implement. Currently only BLOCKSYNC does. The FilterMsgBytes function is called for both comet P2P and libp2p implementations, inside of the onReceive function when setting up a peer for comet p2p, and inside of handleStream for libp2p, just before unmarshalling the message in both.

Backport adaptations for bera-v1.x:

  • CHANGELOG.md not modified — left to fork's changelog flow.
  • internal/blocksync/reactor.go upstream's path is blocksync/reactor.go; git rename detection fails due to content divergence, so the modifications were manually added 1:1, beside a couple of divergencies:
    • enabled atomic.Bool field NOT added. Upstream's FilterMsgBytes does !r.enabled.Load() || !r.pool.IsRunning(); this fork uses !bcR.pool.IsRunning() alone. Left a comment in the code to explain why it should be ok.
    • bcstub import alias used for proto/tendermint/blocksync because bcproto already points to api/cometbft/blocksync/v1 in this fork.
  • lp2p/* modifications dropped — no libp2p in this fork.

@fridrik01
Copy link
Copy Markdown

I see there is missing block_sync/reactor_test.go and p2p/switch_test.go files in this PR which were in cometbft#5860, should we not include them as well?

Copy link
Copy Markdown
Collaborator

@calbera calbera left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utACK, lets get in the reactor_test.go at least

@bar-bera bar-bera force-pushed the fix-mem-alloc-blowing branch from 9401c41 to 2bbbb18 Compare May 29, 2026 10:00
cometbft#5860)

---

Adds additional validation to blocksync, ensuring _before response
unmarshalling_ that we have made a `BlockRequest` to the peer that is
sending us a `BlockResponse` recently, and also that the response
contains a valid amount of commit signatures (not > MaxVoteCount). To do
this preunmarshal validation, we have added a `MsgBytesFilter` interface
that `Reactors` can implement. Currently only `BLOCKSYNC` does. The
`FilterMsgBytes` function is called for both comet P2P and libp2p
implementations, inside of the `onReceive` function when setting up a
peer for comet p2p, and inside of `handleStream` for libp2p, just before
unmarshalling the message in both.

- [x] Tests written/updated
- [x] Changelog entry added in `CHANGELOG.md`
- [ ] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---

Backport adaptations for bera-v1.x:

- enabled atomic.Bool field NOT added.
- internal/blocksync/reactor.go was hand-edited rather than auto-merged.
- bcstub import alias used (proto/tendermint/blocksync) because bcproto
  already points to api/cometbft/blocksync/v1 in this fork.
- lp2p/* hunks dropped — no libp2p reactor in this fork.
- CHANGELOG.md not modified
- Tests
  - pool_test.go kept as is
  - reactor_test.go adapted (different imports)
  - p2p/switch_test.go dropped adapted (BroadcastAsync/Broadcast, same)

(cherry picked from commit 4590e7a)
@bar-bera bar-bera force-pushed the fix-mem-alloc-blowing branch from 2bbbb18 to c83f296 Compare May 29, 2026 10:28
@bar-bera
Copy link
Copy Markdown
Author

tests had minor divergencies, but yeah looking better the modifications are very tiny. ported now

Copy link
Copy Markdown

@fridrik01 fridrik01 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@bar-bera bar-bera merged commit ea32695 into bera-v1.x May 29, 2026
16 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants