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
4 changes: 2 additions & 2 deletions node/core/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ func NewExecutor(newSyncFunc NewSyncerFunc, config *Config, tmPubKey crypto.PubK
logger.Info("L2Next geth not configured (no upgrade switch)")
}

// Fetch geth config at startup
gethCfg, err := types.FetchGethConfig(config.L2.EthAddr, logger)
// Fetch geth config at startup (with retry to wait for geth)
gethCfg, err := types.FetchGethConfigWithRetry(config.L2.EthAddr, logger)
if err != nil {
return nil, fmt.Errorf("failed to fetch geth config: %w", err)
}
Expand Down
4 changes: 2 additions & 2 deletions node/derivation/derivation.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ func NewDerivationClient(ctx context.Context, cfg *Config, syncer *sync.Syncer,
baseHttp := NewBasicHTTPClient(cfg.BeaconRpc, logger)
l1BeaconClient := NewL1BeaconClient(baseHttp)

// Fetch geth config once at startup for root validation skip logic
gethCfg, err := types.FetchGethConfig(cfg.L2.EthAddr, logger)
// Fetch geth config once at startup for root validation skip logic (with retry)
gethCfg, err := types.FetchGethConfigWithRetry(cfg.L2.EthAddr, logger)
if err != nil {
return nil, fmt.Errorf("failed to fetch geth config: %w", err)
}
Expand Down
21 changes: 19 additions & 2 deletions node/types/retryable_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ const (
ExecutionAborted = "execution aborted"
Timeout = "timed out"
DiscontinuousBlockError = "discontinuous block number"

// Geth connection retry settings
GethRetryAttempts = 60 // max retry attempts
GethRetryInterval = 5 * time.Second // interval between retries
)

// configResponse represents the eth_config RPC response (EIP-7910)
Expand Down Expand Up @@ -60,6 +64,21 @@ type GethConfig struct {
UseZktrie bool
}

// FetchGethConfigWithRetry fetches geth config with retry, waiting for geth to be ready.
func FetchGethConfigWithRetry(rpcURL string, logger tmlog.Logger) (*GethConfig, error) {
var lastErr error
for i := 0; i < GethRetryAttempts; i++ {
config, err := FetchGethConfig(rpcURL, logger)
if err == nil {
return config, nil
}
lastErr = err
logger.Info("Waiting for geth to be ready...", "attempt", i+1, "error", err)
time.Sleep(GethRetryInterval)
}
return nil, fmt.Errorf("geth not ready after %d attempts: %w", GethRetryAttempts, lastErr)
}

// FetchGethConfig fetches the geth configuration via eth_config API
func FetchGethConfig(rpcURL string, logger tmlog.Logger) (*GethConfig, error) {
client, err := rpc.Dial(rpcURL)
Expand Down Expand Up @@ -128,7 +147,6 @@ func (rc *RetryableClient) MPTForkTime() uint64 {
return rc.switchTime
}


// NewRetryableClient creates a new retryable client with the given switch time.
// Will retry calling the api, if the connection is refused.
//
Expand All @@ -152,7 +170,6 @@ func NewRetryableClient(authClient *authclient.Client, ethClient *ethclient.Clie
logger: logger,
}
}

// Check if switch time has already passed at startup
now := uint64(time.Now().Unix())
alreadySwitched := switchTime > 0 && now >= switchTime
Expand Down
Loading