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

l2Client := types.NewRetryableClient(aClient, eClient, aNextClient, eNextClient, config.L2.EthAddr, config.Logger)
// Fetch geth config at startup
gethCfg, err := types.FetchGethConfig(config.L2.EthAddr, logger)
if err != nil {
return nil, fmt.Errorf("failed to fetch geth config: %w", err)
}
logger.Info("Geth config fetched", "switchTime", gethCfg.SwitchTime, "useZktrie", gethCfg.UseZktrie)

l2Client := types.NewRetryableClient(aClient, eClient, aNextClient, eNextClient, gethCfg.SwitchTime, logger)
index, err := getNextL1MsgIndex(l2Client)
if err != nil {
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion node/derivation/derivation.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func NewDerivationClient(ctx context.Context, cfg *Config, syncer *sync.Syncer,
logger: logger,
RollupContractAddress: cfg.RollupContractAddress,
confirmations: cfg.L1.Confirmations,
l2Client: types.NewRetryableClient(aClient, eClient, aNextClient, eNextClient, cfg.L2.EthAddr, logger),
l2Client: types.NewRetryableClient(aClient, eClient, aNextClient, eNextClient, gethCfg.SwitchTime, logger),
cancel: cancel,
stop: make(chan struct{}),
startHeight: cfg.StartHeight,
Expand Down
36 changes: 10 additions & 26 deletions node/types/retryable_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ type configResponse struct {

// forkConfig represents a single fork configuration
type forkConfig struct {
ActivationTime uint64 `json:"activationTime"`
ChainId string `json:"chainId"`
ForkId string `json:"forkId"`
Precompiles map[string]string `json:"precompiles"`
SystemContracts map[string]string `json:"systemContracts"`
Morph *morphExtension `json:"morph,omitempty"`
ActivationTime uint64 `json:"activationTime"`
ChainId string `json:"chainId"`
ForkId string `json:"forkId"`
Precompiles map[string]string `json:"precompiles"`
SystemContracts map[string]string `json:"systemContracts"`
Morph *morphExtension `json:"morph,omitempty"`
}

// morphExtension contains Morph-specific configuration fields
Expand Down Expand Up @@ -111,15 +111,6 @@ func FetchGethConfig(rpcURL string, logger tmlog.Logger) (*GethConfig, error) {
return config, nil
}

// fetchMPTForkTime fetches the MPT fork time from geth via eth_config API (internal)
func fetchMPTForkTime(rpcURL string, logger tmlog.Logger) (uint64, error) {
config, err := FetchGethConfig(rpcURL, logger)
if err != nil {
return 0, err
}
return config.SwitchTime, nil
}

type RetryableClient struct {
authClient *authclient.Client // current geth
ethClient *ethclient.Client // current geth
Expand All @@ -131,22 +122,16 @@ type RetryableClient struct {
logger tmlog.Logger
}

// NewRetryableClient creates a new retryable client that fetches switch time from geth.
// The l2EthAddr is used to fetch the switch time via eth_config API.
// NewRetryableClient creates a new retryable client with the given switch time.
// Will retry calling the api, if the connection is refused.
//
// If nextAuthClient or nextEthClient is nil, switch is disabled and only current client is used.
// This is useful for nodes that don't need to switch geth (most nodes).
func NewRetryableClient(authClient *authclient.Client, ethClient *ethclient.Client, nextAuthClient *authclient.Client, nextEthClient *ethclient.Client, l2EthAddr string, logger tmlog.Logger) *RetryableClient {
//
// The switchTime should be fetched via FetchGethConfig before calling this function.
func NewRetryableClient(authClient *authclient.Client, ethClient *ethclient.Client, nextAuthClient *authclient.Client, nextEthClient *ethclient.Client, switchTime uint64, logger tmlog.Logger) *RetryableClient {
logger = logger.With("module", "retryClient")

// Fetch switch time from geth
switchTime, err := fetchMPTForkTime(l2EthAddr, logger)
if err != nil {
logger.Error("Failed to fetch switch time from geth, using 0", "error", err)
switchTime = 0
}

// If next client is not configured, disable switch
if nextAuthClient == nil || nextEthClient == nil {
logger.Info("L2Next client not configured, switch disabled")
Expand Down Expand Up @@ -191,7 +176,6 @@ func NewRetryableClient(authClient *authclient.Client, ethClient *ethclient.Clie
return rc
}


func (rc *RetryableClient) aClient() *authclient.Client {
if !rc.switched.Load() {
return rc.authClient
Expand Down
Loading