feat(rpc): wire UnmarshalWithLimit into Stream.Recv#3630
Conversation
…verride Stream.Recv now calls protoutils.UnmarshalWithLimit instead of Unmarshal, bounding per-message heap allocation to MsgSize * allocMultiplier. The multiplier defaults to 2 (a value load-tested against the largest message, LaneProposal at ~2MB wire / ~4MB alloc estimate). It is configurable via P2PConfig.ProtoAllocLimitMultiplier and applied at node startup through rpc.SetAllocMultiplier. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
PR SummaryMedium Risk Overview Each stream gets an Reviewed by Cursor Bugbot for commit 2fdc4ac. Bugbot is set up for automated code reviews on this repo. Configure here. |
|
The latest Buf updates on your PR. Results from workflow Buf / buf (pull_request).
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3630 +/- ##
==========================================
- Coverage 59.03% 58.16% -0.87%
==========================================
Files 2243 2169 -74
Lines 184689 176141 -8548
==========================================
- Hits 109028 102452 -6576
+ Misses 65933 64661 -1272
+ Partials 9728 9028 -700
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Summary
Stream.Recvis the single decode point for all inbound P2P v2 proto messages.This PR replaces
protoutils.Unmarshalwithprotoutils.UnmarshalWithLimitthere, bounding heap allocation per message to
MsgSize * allocMultiplierbefore Unmarshal runs.
allocMultiplierdefaults to 2. The largest inbound message isLaneProposalat ~2.07 MB wire; load testing showed its alloc estimate fitscomfortably within 4 MB (2 × MsgSize).
P2PConfig.ProtoAllocLimitMultiplier(TOML keyproto-alloc-limit-multiplier,default 2) lets operators override the multiplier without recompiling.
rpc.SetAllocMultiplieris called once increateRouterand applies to allsubsequently opened streams.
Files changed
sei-tendermint/internal/p2p/rpc/rpc.goallocLimittoStream; compute fromMsgSize × allocMultiplierinCall/Serve; callUnmarshalWithLimitinRecvsei-tendermint/config/config.goProtoAllocLimitMultiplier inttoP2PConfig, default 2sei-tendermint/node/setup.gorpc.SetAllocMultiplierfromcreateRouterwhen config value is non-zeroTest plan
go test ./sei-tendermint/internal/p2p/rpc/...— existing tests pass with newRecvsignaturego test ./sei-tendermint/internal/protoutils/...—UnmarshalWithLimitunit tests still greengo build ./sei-tendermint/...— compiles cleanlyproto-alloc-limit-multiplier = 1in config, confirm a large block message is rejected when wire bytes exceed MsgSize🤖 Generated with Claude Code