Skip to content

Commit

Permalink
pubsub: set max msg size (#1768)
Browse files Browse the repository at this point in the history
* set WithMaxMessageSize
  • Loading branch information
nkryuchkov authored Oct 30, 2024
1 parent ec7869a commit 73e99f5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
4 changes: 3 additions & 1 deletion message/validation/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,7 @@ const (
const (
maxPayloadDataSize = max(maxEncodedConsensusMsgSize, maxEncodedPartialSignatureSize)
maxSignedMsgSize = maxSignaturesSize + maxOperatorIDSize + msgTypeSize + identifierSize + maxPayloadDataSize + maxFullDataSize
maxEncodedMsgSize = maxSignedMsgSize + maxSignedMsgSize/encodingOverheadDivisor + 4
)

// MaxEncodedMsgSize defines max pubsub message size
const MaxEncodedMsgSize = maxSignedMsgSize + maxSignedMsgSize/encodingOverheadDivisor + 4
2 changes: 1 addition & 1 deletion message/validation/pubsub_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (mv *messageValidator) validatePubSubMessage(pMsg *pubsub.Message) error {
}

// Rule: Pubsub.Message.Message.Data size upper limit
if len(pMsg.GetData()) > maxEncodedMsgSize {
if len(pMsg.GetData()) > MaxEncodedMsgSize {
e := ErrPubSubDataTooBig
e.got = len(pMsg.GetData())
return e
Expand Down
7 changes: 4 additions & 3 deletions network/topics/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ import (
"net"
"time"

"github.com/ssvlabs/ssv/networkconfig"

pubsub "github.com/libp2p/go-libp2p-pubsub"
"github.com/libp2p/go-libp2p/core/discovery"
"github.com/libp2p/go-libp2p/core/host"
libp2pnetwork "github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/pkg/errors"
"go.uber.org/zap"

libp2pnetwork "github.com/libp2p/go-libp2p/core/network"
"github.com/ssvlabs/ssv/message/validation"
"github.com/ssvlabs/ssv/network"
"github.com/ssvlabs/ssv/network/commons"
"github.com/ssvlabs/ssv/network/peers"
"github.com/ssvlabs/ssv/network/topics/params"
"github.com/ssvlabs/ssv/networkconfig"
"github.com/ssvlabs/ssv/registry/storage"
)

Expand Down Expand Up @@ -136,6 +136,7 @@ func NewPubSub(ctx context.Context, logger *zap.Logger, cfg *PubSubConfig, metri
pubsub.WithSubscriptionFilter(sf),
pubsub.WithGossipSubParams(params.GossipSubParams()),
pubsub.WithMessageSignaturePolicy(pubsub.StrictNoSign),
pubsub.WithMaxMessageSize(validation.MaxEncodedMsgSize),
// pubsub.WithPeerFilter(func(pid peer.ID, topic string) bool {
// logger.Debug("pubsubTrace: filtering peer", zap.String("id", pid.String()), zap.String("topic", topic))
// return true
Expand Down

0 comments on commit 73e99f5

Please sign in to comment.