Skip to content

Commit 4eb6bd9

Browse files
committed
consensus, types: apply patch for issue 32
1 parent cfcd071 commit 4eb6bd9

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

consensus/reactor.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,12 +322,18 @@ func (conR *Reactor) Receive(e p2p.Envelope) {
322322
case *ProposalMessage:
323323
conR.conS.mtx.RLock()
324324
maxBytes := conR.conS.state.ConsensusParams.Block.MaxBytes
325+
maxBlobBytes := conR.conS.state.ConsensusParams.Blob.MaxBytes
325326
conR.conS.mtx.RUnlock()
326327
if err := msg.Proposal.ValidateBlockSize(maxBytes); err != nil {
327328
conR.Logger.Error("Rejecting oversized proposal", "peer", e.Src, "height", msg.Proposal.Height)
328329
conR.Switch.StopPeerForError(e.Src, ErrProposalTooManyParts)
329330
return
330331
}
332+
if err := msg.Proposal.ValidateBlobSize(maxBlobBytes); err != nil {
333+
conR.Logger.Error("Rejecting oversized proposal", "peer", e.Src, "height", msg.Proposal.Height)
334+
conR.Switch.StopPeerForError(e.Src, ErrProposalTooManyParts)
335+
return
336+
}
331337

332338
ps.SetHasProposal(msg.Proposal)
333339
conR.conS.peerMsgQueue <- msgInfo{msg, e.Src.ID()}

types/proposal.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ func (p *Proposal) ValidateBlockSize(maxBlockSizeBytes int64) error {
105105
return nil
106106
}
107107

108+
// ValidateBlobSize block size ensures that a proposal block is not larger
109+
// than a maximum number of bytes, based on the total amount of parts reported
110+
// in the PartSetHeader. If -1 is passed as the maxBlobSizeBytes,
111+
// types.MaxBlobSizeBytes will be used as the maximum.
112+
func (p *Proposal) ValidateBlobSize(maxBlobSizeBytes int64) error {
113+
if maxBlobSizeBytes == -1 {
114+
maxBlobSizeBytes = int64(MaxBlobSizeBytes)
115+
}
116+
totalParts := int64(p.BlobID.PartSetHeader.Total)
117+
maxParts := (maxBlobSizeBytes-1)/int64(PartSizeBytes) + 1
118+
if totalParts > maxParts {
119+
return fmt.Errorf("proposal has too many parts %d (max: %d)", totalParts, maxParts)
120+
}
121+
return nil
122+
}
123+
108124
// String returns a string representation of the Proposal.
109125
//
110126
// 1. height

0 commit comments

Comments
 (0)