Skip to content

Commit dede63e

Browse files
committed
fix(common): make defaultMaxBlobSizeStr a string literal so -ldflags -X works
A previous version initialised the variable via strconv.FormatUint(...), which Go's linker treats as a non-constant expression — so -ldflags -X silently no-ops the override. Every benchmark that tried to set a smaller MaxBlobSize at link time was actually running with the 128 MiB default, masking what we were measuring. The correct form is a plain string literal in the source. The Fibre cap is documented in the comment so the magic number stays self-explanatory; init() still parses and falls back to the literal value if parsing fails.
1 parent e0021d9 commit dede63e

1 file changed

Lines changed: 14 additions & 11 deletions

File tree

block/internal/common/consts.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,29 @@ package common
22

33
import "strconv"
44

5-
// fibreMaxPayload is the maximum payload Fibre will accept in a single
6-
// blob: protocol max blob size (1 << 27 = 128 MiB) minus the 5-byte
7-
// Fibre blob header (1 byte version + 4 byte data size). See
8-
// celestia-app/v9/fibre/blob.go (blobHeaderLen) and fibre/protocol_params.go
9-
// (MaxBlobSize). Sized to fit a full Fibre blob and nothing more.
10-
const fibreMaxPayload = (1 << 27) - 5
11-
125
// defaultMaxBlobSizeStr holds the string representation of the default blob
13-
// size limit. Override at link time via:
6+
// size limit. Anchored to Fibre's actual cap: protocol MaxBlobSize
7+
// (1 << 27 = 128 MiB) minus the 5-byte Fibre blob header (1 byte version +
8+
// 4 byte data size). See celestia-app/v9/fibre/blob.go (blobHeaderLen)
9+
// and fibre/protocol_params.go (MaxBlobSize).
10+
//
11+
// MUST be a string literal: Go's `-ldflags "-X ..."` only takes effect
12+
// on variables initialized to a string constant, NOT a function call.
13+
// A previous version used strconv.FormatUint here, which compiled but
14+
// silently ignored ldflag overrides.
15+
//
16+
// Override at link time via:
1417
//
15-
// go build -ldflags "-X github.com/evstack/ev-node/block/internal/common.defaultMaxBlobSizeStr=125829120"
16-
var defaultMaxBlobSizeStr = strconv.FormatUint(fibreMaxPayload, 10)
18+
// go build -ldflags "-X github.com/evstack/ev-node/block/internal/common.defaultMaxBlobSizeStr=33554432"
19+
var defaultMaxBlobSizeStr = "134217723" // 1 << 27 - 5 = 128 MiB - 5 B
1720

1821
// DefaultMaxBlobSize is the max blob size limit used for blob submission.
1922
var DefaultMaxBlobSize uint64
2023

2124
func init() {
2225
v, err := strconv.ParseUint(defaultMaxBlobSizeStr, 10, 64)
2326
if err != nil || v == 0 {
24-
DefaultMaxBlobSize = fibreMaxPayload
27+
DefaultMaxBlobSize = 134217723
2528
return
2629
}
2730
DefaultMaxBlobSize = v

0 commit comments

Comments
 (0)