Skip to content

Commit 036b8d4

Browse files
authored
fix: support maximum block size in P2P sync (#3419)
1 parent f2e2f97 commit 036b8d4

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

pkg/sync/p2p_message_size.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package sync
2+
3+
import (
4+
"github.com/celestiaorg/go-libp2p-messenger/serde"
5+
6+
"github.com/evstack/ev-node/pkg/blobsize"
7+
)
8+
9+
func init() {
10+
// go-header wraps block data in another protobuf message, so leave room for
11+
// framing overhead beyond the maximum block payload.
12+
serde.MaxMessageSize = 2 * blobsize.DefaultMaxBlobSize
13+
}

pkg/sync/p2p_message_size_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package sync
2+
3+
import (
4+
"encoding/binary"
5+
"testing"
6+
7+
p2ppb "github.com/celestiaorg/go-header/p2p/pb"
8+
"github.com/celestiaorg/go-libp2p-messenger/serde"
9+
"github.com/stretchr/testify/require"
10+
11+
"github.com/evstack/ev-node/pkg/blobsize"
12+
"github.com/evstack/ev-node/types"
13+
)
14+
15+
func TestP2PMessageSizeSupportsMaxBlob(t *testing.T) {
16+
data := &types.P2PData{
17+
Data: &types.Data{
18+
Metadata: &types.Metadata{
19+
ChainID: "test-chain",
20+
Height: 1,
21+
Time: 1,
22+
},
23+
Txs: types.Txs{make([]byte, int(blobsize.DefaultMaxBlobSize))},
24+
},
25+
}
26+
27+
body, err := data.MarshalBinary()
28+
require.NoError(t, err)
29+
30+
response := &p2ppb.HeaderResponse{Body: body}
31+
buf := make([]byte, response.Size()+binary.MaxVarintLen64)
32+
_, err = serde.Marshal(response, buf)
33+
require.NoError(t, err)
34+
}

0 commit comments

Comments
 (0)