Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions pkg/sync/p2p_message_size.go
Original file line number Diff line number Diff line change
@@ -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
Comment on lines +9 to +12

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

rg -n -C 4 'MaxMessageSize|serde\.(Read|Write|Marshal|Unmarshal)' --glob '*.go' .

Repository: evstack/ev-node

Length of output: 1867


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'Changed files/stat:\n'
git diff --stat || true

printf '\nRelevant files:\n'
fd -a 'p2p_message_size|blobsize|client\.(go|test\.go)|go.mod|go.sum' . | sed 's#^\./##'

printf '\ngo.mod dependency refs:\n'
rg -n 'go-libp2p-messenger|go-header|blobsize' go.mod go.sum || true

Repository: evstack/ev-node

Length of output: 2029


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'inspect p2p_message_size.go:\n'
cat -n pkg/sync/p2p_message_size.go 2>/dev/null || true

printf '\ninspect blobsize.go:\n'
fd -a 'blobsize.go' . | while read -r f; do
  echo "--- ${f#"$PWD/"}"
  cat -n "$f"
done

printf '\nprobe go-libp2p-messenger source if vendored/module cache available:\n'
go env GOMODCACHE GOPATH GOMOD 2>/dev/null | sed -n '1,20p'
go env GOMODCACHE 2>/dev/null | xargs -r find -path '*go-libp2p-messenger*' -maxdepth 4 -type d 2>/dev/null | head -20 || true

Repository: evstack/ev-node

Length of output: 1542


🏁 Script executed:

#!/bin/bash
set -euo pipefail

gocache="$(go env GOMODCACHE 2>/dev/null)"
printf 'GOMODCACHE=%s\n' "$gocache"
printf '\npackage cache entries:\n'
find "${gocache:-/go/pkg/mod}" -type f \( -name 'serde.go' -o -name 'serdes.go' -o -name 'go.mod' \) \
  | grep -E 'go-libp2p-messenger|go-header' | sort | head -50

printf '\nserde.go content if present:\n'
f="$(find "${gocache:-/go/pkg/mod}" -type f -path '*/go-libp2p-messenger@v0.2.2/serde/serde.go' | head -1 || true)"
if [ -n "${f:-}" ]; then
  wc -l "$f"
  sed -n '1,220p' "$f" | cat -n
fi

Repository: evstack/ev-node

Length of output: 4349


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'go-header peer and messenger references:\n'
find "${GOMODCACHE:-/go/pkg/mod}/github.com/celestiaorg/go-header@v0.8.5" -maxdepth 5 -type f -name '*.go' -print0 \
  | xargs -0 rg -n 'messenger|serde|NewLibP2P|HeaderRequest|HeaderResponse|Read\(|Write\(' || true

printf '\nSearch ev-node sync/p2p for go-header usage:\n'
rg -n -C 3 'go-header|HeaderRequest|HeaderResponse|Read\(|Write\(|p2p_message_size|MaxMessageSize' pkg go.mod --glob '*.go' || true

Repository: evstack/ev-node

Length of output: 36389


🏁 Script executed:

#!/bin/bash
set -euo pipefail

printf 'go-libp2p-messenger serializer.go source:\n'
sed -n '1,220p' "${GOMODCACHE:-/go/pkg/mod}/github.com/celestiaorg/go-libp2p-messenger@v0.2.2/serde/serializer.go" | cat -n

printf '\ngo-libp2p-messenger version 0.2.2 serializer.go length-pooling evidence:\n'
python3 - <<'PY'
from pathlib import Path
p = Path.home() / 'go/pkg/mod/github.com/celestiaorg/go-libp2p-messenger@v0.2.2/serde/serializer.go'
if p.exists():
    text = p.read_text()
    print(f'exists={p}')
    for name in ['func Read', 'func Write', 'func Marshal', 'MaxMessageSize', 'uvarintSize']:
        print(f'{name}={name in text}')
    # show key functions
    for name in ['func Read', 'func Write', 'func Marshal']:
        idx = text.find(f'func {name}')
        if idx != -1:
            start = text.rfind('\n', 0, idx-1)
            end = text.find('\nfunc ', start+1)
            print(f'\n-- {name} --')
            print(text[start+1:end if end != -1 else len(text)])
PY

Repository: evstack/ev-node

Length of output: 334


Avoid widening the process-wide serde limit before reading requests.

go-header reads inbound HeaderRequest with serde.Read, so this global setting also applies to requests. A peer can make go-libp2p-messenger allocate a buffer up to 2 * DefaultMaxBlobSize for the request length before HeaderRequest.Unmarshal rejects it. Keep serde.MaxMessageSize small enough for HeaderRequest, and widen the limit only where HeaderResponse serialization is constrained.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/sync/p2p_message_size.go` around lines 9 - 12, Remove the process-wide
`serde.MaxMessageSize` increase from init, keeping inbound HeaderRequest reads
bounded to the request’s actual size. Apply the larger limit only around
HeaderResponse serialization, using the relevant response-writing or
serialization function and restoring the previous limit afterward.

Source: MCP tools

}
34 changes: 34 additions & 0 deletions pkg/sync/p2p_message_size_test.go
Original file line number Diff line number Diff line change
@@ -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)
Comment on lines +30 to +33

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Set StatusCode_OK in the regression fixture.

The successful go-header server path serializes HeaderResponse with StatusCode_OK. This fixture leaves StatusCode at zero, so response.Size() excludes a field present in production. Set the status before calculating the size and marshaling the response.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@pkg/sync/p2p_message_size_test.go` around lines 30 - 33, Update the
HeaderResponse fixture in the regression test to set StatusCode to StatusCode_OK
before calling response.Size() and serde.Marshal, matching the successful
go-header server serialization path.

}
Loading