Skip to content

Commit 1435f06

Browse files
committed
revert config addition + simplify logging
1 parent 21219ac commit 1435f06

4 files changed

Lines changed: 34 additions & 84 deletions

File tree

block/internal/syncing/syncer.go

Lines changed: 12 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"context"
66
"errors"
77
"fmt"
8-
"strings"
98
"sync"
109
"sync/atomic"
1110
"time"
@@ -261,22 +260,12 @@ func (s *Syncer) syncLoop() {
261260
// Process pending events from cache on every iteration
262261
s.processPendingEvents()
263262

264-
// Fetch events from DA layer first and optimistically p2p when necessary.
265-
// This is the default behavior.
266-
if !s.config.Sync.PreferP2P {
267-
if s.tryFetchFromDA(nextDARequestAt) {
268-
continue
269-
}
270-
if s.tryFetchFromP2P(lastHeaderHeight, lastDataHeight, blockTicker.C) {
271-
continue
272-
}
273-
} else {
274-
if s.tryFetchFromP2P(lastHeaderHeight, lastDataHeight, blockTicker.C) {
275-
continue
276-
}
277-
if s.tryFetchFromDA(nextDARequestAt) {
278-
continue
279-
}
263+
if s.tryFetchFromDA(nextDARequestAt) {
264+
continue
265+
}
266+
267+
if s.tryFetchFromP2P(lastHeaderHeight, lastDataHeight, blockTicker.C) {
268+
continue
280269
}
281270

282271
// Prevent busy-waiting when no events are available
@@ -309,17 +298,14 @@ func (s *Syncer) tryFetchFromDA(nextDARequestAt *time.Time) bool {
309298
}
310299

311300
// Back off exactly by DA block time to avoid overloading
312-
hffDelay := s.config.DA.BlockTime.Duration
313-
if hffDelay <= 0 {
314-
hffDelay = 2 * time.Second
301+
backoffDelay := s.config.DA.BlockTime.Duration
302+
if backoffDelay <= 0 {
303+
backoffDelay = 2 * time.Second
315304
}
316-
*nextDARequestAt = now.Add(hffDelay)
305+
*nextDARequestAt = now.Add(backoffDelay)
306+
307+
s.logger.Error().Err(err).Dur("delay", backoffDelay).Uint64("da_height", daHeight).Msg("failed to retrieve from DA; backing off DA requests")
317308

318-
if s.isHeightFromFutureError(err) {
319-
s.logger.Debug().Dur("delay", hffDelay).Uint64("da_height", daHeight).Msg("height from future; backing off DA requests")
320-
} else {
321-
s.logger.Error().Err(err).Dur("delay", hffDelay).Uint64("da_height", daHeight).Msg("failed to retrieve from DA; backing off DA requests")
322-
}
323309
return false
324310
}
325311

@@ -583,24 +569,6 @@ func (s *Syncer) sendNonBlockingSignal(ch chan struct{}, name string) {
583569
}
584570
}
585571

586-
// isHeightFromFutureError checks if the error is a height from future error
587-
func (s *Syncer) isHeightFromFutureError(err error) bool {
588-
if err == nil {
589-
return false
590-
}
591-
if errors.Is(err, coreda.ErrHeightFromFuture) || errors.Is(err, common.ErrHeightFromFutureStr) {
592-
return true
593-
}
594-
msg := err.Error()
595-
if msg == "" {
596-
return false
597-
}
598-
if strings.Contains(msg, coreda.ErrHeightFromFuture.Error()) || strings.Contains(msg, common.ErrHeightFromFutureStr.Error()) {
599-
return true
600-
}
601-
return false
602-
}
603-
604572
// processPendingEvents fetches and processes pending events from cache
605573
// optimistically fetches the next events from cache until no matching heights are found
606574
func (s *Syncer) processPendingEvents() {

block/internal/syncing/syncer_test.go

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package syncing
33
import (
44
"context"
55
crand "crypto/rand"
6-
"errors"
76
"testing"
87
"time"
98

@@ -191,18 +190,6 @@ func TestSequentialBlockSync(t *testing.T) {
191190
assert.True(t, ok)
192191
}
193192

194-
func TestSyncer_isHeightFromFutureError(t *testing.T) {
195-
s := &Syncer{}
196-
// exact error
197-
err := common.ErrHeightFromFutureStr
198-
assert.True(t, s.isHeightFromFutureError(err))
199-
// string-wrapped error
200-
err = errors.New("some context: " + common.ErrHeightFromFutureStr.Error())
201-
assert.True(t, s.isHeightFromFutureError(err))
202-
// unrelated
203-
assert.False(t, s.isHeightFromFutureError(errors.New("boom")))
204-
}
205-
206193
func TestSyncer_sendNonBlockingSignal(t *testing.T) {
207194
s := &Syncer{logger: zerolog.Nop()}
208195
ch := make(chan struct{}, 1)

pkg/config/config.go

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@ const (
2828
FlagRootDir = "home"
2929
// FlagDBPath is a flag for specifying the database path
3030
FlagDBPath = FlagPrefixEvnode + "db_path"
31-
// FlagClearCache is a flag for clearing the cache
32-
FlagClearCache = FlagPrefixEvnode + "clear_cache"
3331

3432
// Node configuration flags
3533

@@ -49,11 +47,8 @@ const (
4947
FlagLazyBlockTime = FlagPrefixEvnode + "node.lazy_block_interval"
5048
// FlagReadinessMaxBlocksBehind configures how many blocks behind best-known head is still considered ready
5149
FlagReadinessMaxBlocksBehind = FlagPrefixEvnode + "node.readiness_max_blocks_behind"
52-
53-
// Sync configuration flags
54-
55-
// FlagSyncP2PPrefer is a flag to prioritize p2p over da fetching
56-
FlagSyncP2PPrefer = FlagPrefixEvnode + "sync.prefer_p2p"
50+
// FlagClearCache is a flag for clearing the cache
51+
FlagClearCache = FlagPrefixEvnode + "clear_cache"
5752

5853
// Data Availability configuration flags
5954

@@ -135,14 +130,10 @@ const (
135130
// Config stores Rollkit configuration.
136131
type Config struct {
137132
RootDir string `mapstructure:"-" yaml:"-" comment:"Root directory where rollkit files are located"`
138-
ClearCache bool `mapstructure:"clear_cache" yaml:"-" comment:"Clear the cache"`
133+
ClearCache bool `mapstructure:"-" yaml:"-" comment:"Clear the cache"`
139134

140135
// Base configuration
141136
DBPath string `mapstructure:"db_path" yaml:"db_path" comment:"Path inside the root directory where the database is located"`
142-
143-
// Sync configuration (not in yaml)
144-
Sync SyncConfig `mapstructure:"sync" yaml:"-"`
145-
146137
// P2P configuration
147138
P2P P2PConfig `mapstructure:"p2p" yaml:"p2p"`
148139

@@ -165,12 +156,6 @@ type Config struct {
165156
Signer SignerConfig `mapstructure:"signer" yaml:"signer"`
166157
}
167158

168-
// SyncConfig contains synchronization configuration parameters
169-
// Those are used in flags are not set in the ev-node config.
170-
type SyncConfig struct {
171-
PreferP2P bool `mapstructure:"prefer_p2p" yaml:"-" comment:"Prefer P2P over DA fetching"`
172-
}
173-
174159
// DAConfig contains all Data Availability configuration parameters
175160
type DAConfig struct {
176161
Address string `mapstructure:"address" yaml:"address" comment:"Address of the data availability layer service (host:port). This is the endpoint where Rollkit will connect to submit and retrieve data."`
@@ -324,9 +309,6 @@ func AddFlags(cmd *cobra.Command) {
324309
cmd.Flags().String(FlagDBPath, def.DBPath, "path for the node database")
325310
cmd.Flags().Bool(FlagClearCache, def.ClearCache, "clear the cache")
326311

327-
// Sync configuration flags
328-
cmd.Flags().Bool(FlagSyncP2PPrefer, def.Sync.PreferP2P, "prefer P2P over DA fetching")
329-
330312
// Node configuration flags
331313
cmd.Flags().Bool(FlagAggregator, def.Node.Aggregator, "run node in aggregator mode")
332314
cmd.Flags().Bool(FlagLight, def.Node.Light, "run light client")
@@ -372,9 +354,6 @@ func AddFlags(cmd *cobra.Command) {
372354
cmd.Flags().String(FlagSignerType, def.Signer.SignerType, "type of signer to use (file, grpc)")
373355
cmd.Flags().String(FlagSignerPath, def.Signer.SignerPath, "path to the signer file or address")
374356
cmd.Flags().String(FlagSignerPassphrase, "", "passphrase for the signer (required for file signer and if aggregator is enabled)")
375-
376-
// FlagSyncP2PPrefer is only relevant for sync nodes.
377-
cmd.MarkFlagsMutuallyExclusive(FlagSyncP2PPrefer, FlagAggregator)
378357
}
379358

380359
// Load loads the node configuration in the following order of precedence:

pkg/config/config_test.go

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ func TestAddFlags(t *testing.T) {
5454

5555
// Test specific flags
5656
assertFlagValue(t, flags, FlagDBPath, DefaultConfig().DBPath)
57-
assertFlagValue(t, flags, FlagClearCache, false)
5857

5958
// Node flags
6059
assertFlagValue(t, flags, FlagAggregator, DefaultConfig().Node.Aggregator)
@@ -105,8 +104,25 @@ func TestAddFlags(t *testing.T) {
105104
// RPC flags
106105
assertFlagValue(t, flags, FlagRPCAddress, DefaultConfig().RPC.Address)
107106

108-
// Sync flags
109-
assertFlagValue(t, flags, FlagSyncP2PPrefer, false)
107+
// Count the number of flags we're explicitly checking
108+
expectedFlagCount := 39 // Update this number if you add more flag checks above
109+
110+
// Get the actual number of flags (both regular and persistent)
111+
actualFlagCount := 0
112+
flags.VisitAll(func(flag *pflag.Flag) {
113+
actualFlagCount++
114+
})
115+
persistentFlags.VisitAll(func(flag *pflag.Flag) {
116+
actualFlagCount++
117+
})
118+
119+
// Verify that the counts match
120+
assert.Equal(
121+
t,
122+
expectedFlagCount,
123+
actualFlagCount,
124+
"Number of flags doesn't match. If you added a new flag, please update the test.",
125+
)
110126
}
111127

112128
func TestLoad(t *testing.T) {

0 commit comments

Comments
 (0)