Skip to content

Commit 9a5d8b3

Browse files
author
corey
committed
fix NewRetryableClient
1 parent 5dea362 commit 9a5d8b3

File tree

8 files changed

+22
-28
lines changed

8 files changed

+22
-28
lines changed

node/core/executor.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,14 @@ func NewExecutor(newSyncFunc NewSyncerFunc, config *Config, tmPubKey crypto.PubK
9898
logger.Info("L2Next geth not configured (no upgrade switch)")
9999
}
100100

101-
l2Client := types.NewRetryableClient(aClient, eClient, aNextClient, eNextClient, config.L2.EthAddr, config.Logger)
101+
// Fetch geth config at startup
102+
gethCfg, err := types.FetchGethConfig(config.L2.EthAddr, logger)
103+
if err != nil {
104+
return nil, fmt.Errorf("failed to fetch geth config: %w", err)
105+
}
106+
logger.Info("Geth config fetched", "switchTime", gethCfg.SwitchTime, "useZktrie", gethCfg.UseZktrie)
107+
108+
l2Client := types.NewRetryableClient(aClient, eClient, aNextClient, eNextClient, gethCfg.SwitchTime, logger)
102109
index, err := getNextL1MsgIndex(l2Client)
103110
if err != nil {
104111
return nil, err

node/derivation/derivation.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,8 @@ func NewDerivationClient(ctx context.Context, cfg *Config, syncer *sync.Syncer,
146146
}
147147
logger.Info("Geth config fetched", "switchTime", gethCfg.SwitchTime, "useZktrie", gethCfg.UseZktrie)
148148

149+
l2Client := types.NewRetryableClient(aClient, eClient, aNextClient, eNextClient, gethCfg.SwitchTime, logger)
150+
149151
return &Derivation{
150152
ctx: ctx,
151153
db: db,
@@ -159,7 +161,7 @@ func NewDerivationClient(ctx context.Context, cfg *Config, syncer *sync.Syncer,
159161
logger: logger,
160162
RollupContractAddress: cfg.RollupContractAddress,
161163
confirmations: cfg.L1.Confirmations,
162-
l2Client: types.NewRetryableClient(aClient, eClient, aNextClient, eNextClient, cfg.L2.EthAddr, logger),
164+
l2Client: l2Client,
163165
cancel: cancel,
164166
stop: make(chan struct{}),
165167
startHeight: cfg.StartHeight,

node/types/retryable_client.go

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,6 @@ func FetchGethConfig(rpcURL string, logger tmlog.Logger) (*GethConfig, error) {
111111
return config, nil
112112
}
113113

114-
// fetchMPTForkTime fetches the MPT fork time from geth via eth_config API (internal)
115-
func fetchMPTForkTime(rpcURL string, logger tmlog.Logger) (uint64, error) {
116-
config, err := FetchGethConfig(rpcURL, logger)
117-
if err != nil {
118-
return 0, err
119-
}
120-
return config.SwitchTime, nil
121-
}
122-
123114
type RetryableClient struct {
124115
authClient *authclient.Client // current geth
125116
ethClient *ethclient.Client // current geth
@@ -131,22 +122,16 @@ type RetryableClient struct {
131122
logger tmlog.Logger
132123
}
133124

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

143-
// Fetch switch time from geth
144-
switchTime, err := fetchMPTForkTime(l2EthAddr, logger)
145-
if err != nil {
146-
logger.Error("Failed to fetch switch time from geth, using 0", "error", err)
147-
switchTime = 0
148-
}
149-
150135
// If next client is not configured, disable switch
151136
if nextAuthClient == nil || nextEthClient == nil {
152137
logger.Info("L2Next client not configured, switch disabled")

ops/l2-genesis/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ replace github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.3.
66

77
require (
88
github.com/holiman/uint256 v1.2.4
9-
github.com/morph-l2/go-ethereum v1.10.14-0.20251219060125-03910bc750a2
9+
github.com/morph-l2/go-ethereum v1.10.14-0.20260113015804-82683159dfd0
1010
github.com/stretchr/testify v1.10.0
1111
github.com/urfave/cli v1.22.17
1212
)

ops/l2-genesis/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
141141
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
142142
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
143143
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
144-
github.com/morph-l2/go-ethereum v1.10.14-0.20251219060125-03910bc750a2 h1:FUv9gtnvF+1AVrkoNGYbVOesi7E+STjdfD2mcqVaEY0=
145-
github.com/morph-l2/go-ethereum v1.10.14-0.20251219060125-03910bc750a2/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
144+
github.com/morph-l2/go-ethereum v1.10.14-0.20260113015804-82683159dfd0 h1:tu77ClhPcySgkweTINJBoLkIdpKKjrDF+4JPMOBCBLk=
145+
github.com/morph-l2/go-ethereum v1.10.14-0.20260113015804-82683159dfd0/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
146146
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
147147
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
148148
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=

ops/tools/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ go 1.24.0
55
replace github.com/tendermint/tendermint => github.com/morph-l2/tendermint v0.3.2
66

77
require (
8-
github.com/morph-l2/go-ethereum v1.10.14-0.20251219060125-03910bc750a2
8+
github.com/morph-l2/go-ethereum v1.10.14-0.20260113015804-82683159dfd0
99
github.com/tendermint/tendermint v0.35.9
1010
)
1111

ops/tools/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,8 @@ github.com/mmcloughlin/addchain v0.4.0/go.mod h1:A86O+tHqZLMNO4w6ZZ4FlVQEadcoqky
163163
github.com/mmcloughlin/profile v0.1.1/go.mod h1:IhHD7q1ooxgwTgjxQYkACGA77oFTDdFVejUS1/tS/qU=
164164
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
165165
github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3RllmbCylyMrvgv0=
166-
github.com/morph-l2/go-ethereum v1.10.14-0.20251219060125-03910bc750a2 h1:FUv9gtnvF+1AVrkoNGYbVOesi7E+STjdfD2mcqVaEY0=
167-
github.com/morph-l2/go-ethereum v1.10.14-0.20251219060125-03910bc750a2/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
166+
github.com/morph-l2/go-ethereum v1.10.14-0.20260113015804-82683159dfd0 h1:tu77ClhPcySgkweTINJBoLkIdpKKjrDF+4JPMOBCBLk=
167+
github.com/morph-l2/go-ethereum v1.10.14-0.20260113015804-82683159dfd0/go.mod h1:tiFPeidxjoCmLj18ne9H3KQdIGTCvRC30qlef06Fd9M=
168168
github.com/morph-l2/tendermint v0.3.2 h1:Gu6Uj2G6c3YP2NAKFi7A46JZaOCdD4zfZDKCjt0pDm8=
169169
github.com/morph-l2/tendermint v0.3.2/go.mod h1:TtCzp9l6Z6yDUiwv3TbqKqw8Q8RKp3fSz5+adO1/Y8w=
170170
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=

0 commit comments

Comments
 (0)