diff --git a/pkg/sync/p2p_message_size.go b/pkg/sync/p2p_message_size.go new file mode 100644 index 0000000000..e7a7bb9b98 --- /dev/null +++ b/pkg/sync/p2p_message_size.go @@ -0,0 +1,13 @@ +package sync + +import ( + "github.com/celestiaorg/go-libp2p-messenger/serde" + + "github.com/evstack/ev-node/pkg/blobsize" +) + +func init() { + // go-header wraps block data in another protobuf message, so leave room for + // framing overhead beyond the maximum block payload. + serde.MaxMessageSize = 2 * blobsize.DefaultMaxBlobSize +} diff --git a/pkg/sync/p2p_message_size_test.go b/pkg/sync/p2p_message_size_test.go new file mode 100644 index 0000000000..63dd16e80c --- /dev/null +++ b/pkg/sync/p2p_message_size_test.go @@ -0,0 +1,34 @@ +package sync + +import ( + "encoding/binary" + "testing" + + p2ppb "github.com/celestiaorg/go-header/p2p/pb" + "github.com/celestiaorg/go-libp2p-messenger/serde" + "github.com/stretchr/testify/require" + + "github.com/evstack/ev-node/pkg/blobsize" + "github.com/evstack/ev-node/types" +) + +func TestP2PMessageSizeSupportsMaxBlob(t *testing.T) { + data := &types.P2PData{ + Data: &types.Data{ + Metadata: &types.Metadata{ + ChainID: "test-chain", + Height: 1, + Time: 1, + }, + Txs: types.Txs{make([]byte, int(blobsize.DefaultMaxBlobSize))}, + }, + } + + body, err := data.MarshalBinary() + require.NoError(t, err) + + response := &p2ppb.HeaderResponse{Body: body} + buf := make([]byte, response.Size()+binary.MaxVarintLen64) + _, err = serde.Marshal(response, buf) + require.NoError(t, err) +}