Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
3 changes: 2 additions & 1 deletion block/internal/syncing/assert.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package syncing

import (
"bytes"
"errors"
"fmt"

Expand All @@ -9,7 +10,7 @@ import (
)

func assertExpectedProposer(genesis genesis.Genesis, proposerAddr []byte) error {
if string(proposerAddr) != string(genesis.ProposerAddress) {
if !bytes.Equal(proposerAddr, genesis.ProposerAddress) {
return fmt.Errorf("unexpected proposer: got %x, expected %x",
proposerAddr, genesis.ProposerAddress)
}
Expand Down
11 changes: 10 additions & 1 deletion block/internal/syncing/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ const (
// fullnessThreshold is the fraction of DefaultMaxBlobSize above which a block
// is considered full. Exceeding it extends the grace period for that epoch.
fullnessThreshold = 0.8

// maxSeenBlockTxs is the upper bound on the seenBlockTxs map to prevent
Comment thread
tac0turtle marked this conversation as resolved.
Outdated
// unbounded memory growth between epoch prune cycles at high throughput.
maxSeenBlockTxs = 500_000
)

// Syncer handles block synchronization from DA and P2P sources.
Expand Down Expand Up @@ -93,6 +97,7 @@ type Syncer struct {
ctx context.Context
cancel context.CancelFunc
wg sync.WaitGroup
closeOnce sync.Once
hasCriticalError atomic.Bool

// P2P wait coordination
Expand Down Expand Up @@ -271,7 +276,7 @@ func (s *Syncer) Stop(ctx context.Context) error {
}

s.logger.Info().Msg("syncer stopped")
close(s.heightInCh)
s.closeOnce.Do(func() { close(s.heightInCh) })
Comment thread
tac0turtle marked this conversation as resolved.
Outdated
s.cancel = nil
return nil
}
Expand Down Expand Up @@ -896,6 +901,10 @@ func (s *Syncer) VerifyForcedInclusionTxs(ctx context.Context, daHeight uint64,
}
s.seenBlockTxsByHeight[daHeight] = hashes
s.daBlockBytes[daHeight] = blockBytes
if len(s.seenBlockTxs) > maxSeenBlockTxs {
s.logger.Warn().Int("size", len(s.seenBlockTxs)).Int("max", maxSeenBlockTxs).
Msg("seenBlockTxs map exceeds bound, forced inclusion verification may have reduced accuracy until next epoch prune")
}
s.forcedInclusionMu.Unlock()

if daHeight < daStart || daHeight < s.getLastState().DAHeight {
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ require (
github.com/evstack/ev-node/core v1.0.0
github.com/filecoin-project/go-jsonrpc v0.10.1
github.com/go-kit/kit v0.13.0
github.com/go-viper/mapstructure/v2 v2.4.0
github.com/goccy/go-yaml v1.19.2
github.com/hashicorp/golang-lru/v2 v2.0.7
github.com/hashicorp/raft v1.7.3
Expand All @@ -24,7 +25,6 @@ require (
github.com/libp2p/go-libp2p v0.47.0
github.com/libp2p/go-libp2p-kad-dht v0.38.0
github.com/libp2p/go-libp2p-pubsub v0.15.0
github.com/mitchellh/mapstructure v1.5.0
github.com/multiformats/go-multiaddr v0.16.1
github.com/prometheus/client_golang v1.23.2
github.com/rs/zerolog v1.34.0
Expand Down Expand Up @@ -64,7 +64,6 @@ require (
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/flatbuffers v25.1.24+incompatible // indirect
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,6 @@ github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1/go.mod h1:pD8Rv
github.com/minio/sha256-simd v0.1.1-0.20190913151208-6de447530771/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=
github.com/minio/sha256-simd v1.0.1/go.mod h1:Pz6AKMiUdngCLpeTL/RJY1M9rUuPMYujV5xJjtbRSN8=
github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/reflect2 v0.0.0-20180701023420-4b7aa43c6742/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"time"

"github.com/celestiaorg/go-square/v3/share"
"github.com/mitchellh/mapstructure"
"github.com/go-viper/mapstructure/v2"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"github.com/spf13/viper"
Expand Down
104 changes: 104 additions & 0 deletions types/serialization_fuzz_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
package types

import (
"testing"

"google.golang.org/protobuf/proto"

pb "github.com/evstack/ev-node/types/pb/evnode/v1"
)

func FuzzHeaderUnmarshalBinary(f *testing.F) {
// Seed with a valid marshalled header
h := Header{}
h.BaseHeader.Height = 1
h.BaseHeader.ChainID = "test"
h.BaseHeader.Time = 1000
if data, err := h.MarshalBinary(); err == nil {
f.Add(data)
}
f.Add([]byte{})
f.Add([]byte{0xff, 0xff, 0xff})

f.Fuzz(func(t *testing.T, data []byte) {
var h Header
if err := h.UnmarshalBinary(data); err != nil {
return
}
// Round-trip: if unmarshal succeeds, marshal should not panic
_, _ = h.MarshalBinary()
})
}

func FuzzDataUnmarshalBinary(f *testing.F) {
d := Data{Txs: Txs{[]byte("tx1"), []byte("tx2")}}
if data, err := d.MarshalBinary(); err == nil {
f.Add(data)
}
f.Add([]byte{})

f.Fuzz(func(t *testing.T, data []byte) {
var d Data
if err := d.UnmarshalBinary(data); err != nil {
return
}
_, _ = d.MarshalBinary()
})
}

func FuzzSignedHeaderUnmarshalBinary(f *testing.F) {
f.Add([]byte{})
f.Add([]byte{0x0a, 0x00})

f.Fuzz(func(t *testing.T, data []byte) {
var sh SignedHeader
if err := sh.UnmarshalBinary(data); err != nil {
return
}
_, _ = sh.MarshalBinary()
})
}

func FuzzSignedDataUnmarshalBinary(f *testing.F) {
f.Add([]byte{})
f.Add([]byte{0x0a, 0x00})

f.Fuzz(func(t *testing.T, data []byte) {
var sd SignedData
if err := sd.UnmarshalBinary(data); err != nil {
return
}
_, _ = sd.MarshalBinary()
})
}

func FuzzDAEnvelopeUnmarshalBinary(f *testing.F) {
f.Add([]byte{})

f.Fuzz(func(t *testing.T, data []byte) {
var sh SignedHeader
if _, err := sh.UnmarshalDAEnvelope(data); err != nil {
return
}
_, _ = sh.MarshalDAEnvelope(nil)
})
}

func FuzzStateFromProto(f *testing.F) {
s := State{ChainID: "test", LastBlockHeight: 1}
if p, err := s.ToProto(); err == nil {
if data, err := proto.Marshal(p); err == nil {
f.Add(data)
}
}
f.Add([]byte{})

f.Fuzz(func(t *testing.T, data []byte) {
var ps pb.State
if err := proto.Unmarshal(data, &ps); err != nil {
return
}
var s State
_ = s.FromProto(&ps)
})
}
Loading