diff --git a/cmd/flags/common.go b/cmd/flags/common.go index 76822e22e..584ad0fba 100644 --- a/cmd/flags/common.go +++ b/cmd/flags/common.go @@ -107,6 +107,7 @@ var ( Name: "rpc.timeout", Usage: "Timeout in seconds for RPC calls", Category: commonCategory, + Value: 1 * time.Minute, } WaitReceiptTimeout = &cli.DurationFlag{ Name: "rpc.waitReceiptTimeout", diff --git a/driver/chain_syncer/calldata/syncer_test.go b/driver/chain_syncer/calldata/syncer_test.go index 8b8fc323f..941537b47 100644 --- a/driver/chain_syncer/calldata/syncer_test.go +++ b/driver/chain_syncer/calldata/syncer_test.go @@ -17,6 +17,7 @@ import ( "github.com/taikoxyz/taiko-client/driver/state" "github.com/taikoxyz/taiko-client/internal/testutils" "github.com/taikoxyz/taiko-client/internal/utils" + "github.com/taikoxyz/taiko-client/pkg/rpc" "github.com/taikoxyz/taiko-client/proposer" ) @@ -47,12 +48,14 @@ func (s *CalldataSyncerTestSuite) SetupTest() { s.Nil(err) proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests - s.Nil(proposer.InitFromConfig(context.Background(), prop, (&proposer.Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{ + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + }, AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), L1ProposerPrivKey: l1ProposerPrivKey, ProposeInterval: &proposeInterval, @@ -65,7 +68,7 @@ func (s *CalldataSyncerTestSuite) SetupTest() { SgxAndPseZkevmTierFee: common.Big256, MaxTierFeePriceBumps: 3, TierFeePriceBump: common.Big2, - }))) + })) s.p = prop } diff --git a/driver/chain_syncer/chain_syncer_test.go b/driver/chain_syncer/chain_syncer_test.go index 99bac25d4..beba6b918 100644 --- a/driver/chain_syncer/chain_syncer_test.go +++ b/driver/chain_syncer/chain_syncer_test.go @@ -49,12 +49,14 @@ func (s *ChainSyncerTestSuite) SetupTest() { s.Nil(err) proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests - s.Nil(proposer.InitFromConfig(context.Background(), prop, (&proposer.Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{ + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + }, AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), L1ProposerPrivKey: l1ProposerPrivKey, ProposeInterval: &proposeInterval, @@ -68,7 +70,7 @@ func (s *ChainSyncerTestSuite) SetupTest() { MaxTierFeePriceBumps: 3, TierFeePriceBump: common.Big2, ExtraData: "test", - }))) + })) s.p = prop } diff --git a/driver/config.go b/driver/config.go index c8cb1bf69..faea036ee 100644 --- a/driver/config.go +++ b/driver/config.go @@ -10,21 +10,15 @@ import ( "github.com/taikoxyz/taiko-client/cmd/flags" "github.com/taikoxyz/taiko-client/pkg/jwt" + "github.com/taikoxyz/taiko-client/pkg/rpc" ) // Config contains the configurations to initialize a Taiko driver. type Config struct { - L1Endpoint string - L2Endpoint string - L2EngineEndpoint string - L2CheckPoint string - TaikoL1Address common.Address - TaikoL2Address common.Address - JwtSecret string + *rpc.ClientConfig P2PSyncVerifiedBlocks bool P2PSyncTimeout time.Duration - BackOffRetryInterval time.Duration - RPCTimeout *time.Duration + RPCTimeout time.Duration } // NewConfigFromCliContext creates a new config instance from @@ -44,24 +38,21 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { return nil, errors.New("empty L2 check point URL") } - var timeout *time.Duration - - if c.IsSet(flags.RPCTimeout.Name) { - duration := c.Duration(flags.RPCTimeout.Name) - timeout = &duration - } - + var timeout = c.Duration(flags.RPCTimeout.Name) return &Config{ - L1Endpoint: c.String(flags.L1WSEndpoint.Name), - L2Endpoint: c.String(flags.L2WSEndpoint.Name), - L2EngineEndpoint: c.String(flags.L2AuthEndpoint.Name), - L2CheckPoint: l2CheckPoint, - TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)), - TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)), - JwtSecret: string(jwtSecret), + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: c.String(flags.L1WSEndpoint.Name), + L2Endpoint: c.String(flags.L2WSEndpoint.Name), + L2CheckPoint: l2CheckPoint, + TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)), + TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)), + L2EngineEndpoint: c.String(flags.L2AuthEndpoint.Name), + JwtSecret: string(jwtSecret), + RetryInterval: c.Duration(flags.BackOffRetryInterval.Name), + Timeout: timeout, + }, P2PSyncVerifiedBlocks: p2pSyncVerifiedBlocks, P2PSyncTimeout: c.Duration(flags.P2PSyncTimeout.Name), - BackOffRetryInterval: c.Duration(flags.BackOffRetryInterval.Name), RPCTimeout: timeout, }, nil } diff --git a/driver/config_test.go b/driver/config_test.go index a95c1febb..2130026bd 100644 --- a/driver/config_test.go +++ b/driver/config_test.go @@ -31,7 +31,7 @@ func (s *DriverTestSuite) TestNewConfigFromCliContext() { s.Equal(taikoL1, c.TaikoL1Address.String()) s.Equal(taikoL2, c.TaikoL2Address.String()) s.Equal(120*time.Second, c.P2PSyncTimeout) - s.Equal(rpcTimeout, *c.RPCTimeout) + s.Equal(rpcTimeout, c.RPCTimeout) s.NotEmpty(c.JwtSecret) s.Nil(new(Driver).InitFromCli(context.Background(), ctx)) s.True(c.P2PSyncVerifiedBlocks) diff --git a/driver/driver.go b/driver/driver.go index d12775081..ed9334ab5 100644 --- a/driver/driver.go +++ b/driver/driver.go @@ -28,6 +28,7 @@ const ( // Driver keeps the L2 execution engine's local block chain in sync with the TaikoL1 // contract. type Driver struct { + *Config rpc *rpc.Client l2ChainSyncer *chainSyncer.L2ChainSyncer state *state.State @@ -36,9 +37,8 @@ type Driver struct { l1HeadSub event.Subscription syncNotify chan struct{} - backOffRetryInterval time.Duration - ctx context.Context - wg sync.WaitGroup + ctx context.Context + wg sync.WaitGroup } // InitFromCli New initializes the given driver instance based on the command line flags. @@ -48,28 +48,18 @@ func (d *Driver) InitFromCli(ctx context.Context, c *cli.Context) error { return err } - return InitFromConfig(ctx, d, cfg) + return d.InitFromConfig(ctx, cfg) } // InitFromConfig initializes the driver instance based on the given configurations. -func InitFromConfig(ctx context.Context, d *Driver, cfg *Config) (err error) { +func (d *Driver) InitFromConfig(ctx context.Context, cfg *Config) (err error) { d.l1HeadCh = make(chan *types.Header, 1024) d.wg = sync.WaitGroup{} d.syncNotify = make(chan struct{}, 1) d.ctx = ctx - d.backOffRetryInterval = cfg.BackOffRetryInterval - - if d.rpc, err = rpc.NewClient(d.ctx, &rpc.ClientConfig{ - L1Endpoint: cfg.L1Endpoint, - L2Endpoint: cfg.L2Endpoint, - L2CheckPoint: cfg.L2CheckPoint, - TaikoL1Address: cfg.TaikoL1Address, - TaikoL2Address: cfg.TaikoL2Address, - L2EngineEndpoint: cfg.L2EngineEndpoint, - JwtSecret: cfg.JwtSecret, - RetryInterval: cfg.BackOffRetryInterval, - Timeout: cfg.RPCTimeout, - }); err != nil { + d.Config = cfg + + if d.rpc, err = rpc.NewClient(d.ctx, cfg.ClientConfig); err != nil { return err } @@ -143,7 +133,7 @@ func (d *Driver) eventLoop() { // doSyncWithBackoff performs a synchronising operation with a backoff strategy. doSyncWithBackoff := func() { - if err := backoff.Retry(d.doSync, backoff.NewConstantBackOff(d.backOffRetryInterval)); err != nil { + if err := backoff.Retry(d.doSync, backoff.NewConstantBackOff(d.RetryInterval)); err != nil { log.Error("Sync L2 execution engine's block chain error", "error", err) } } @@ -210,7 +200,7 @@ func (d *Driver) reportProtocolStatus() { maxNumBlocks = configs.BlockMaxProposals return nil }, - backoff.NewConstantBackOff(d.backOffRetryInterval), + backoff.NewConstantBackOff(d.RetryInterval), ); err != nil { log.Error("Failed to get protocol state variables", "error", err) return diff --git a/driver/driver_test.go b/driver/driver_test.go index 85cd69589..7c465f3f7 100644 --- a/driver/driver_test.go +++ b/driver/driver_test.go @@ -14,6 +14,7 @@ import ( "github.com/taikoxyz/taiko-client/bindings/encoding" "github.com/taikoxyz/taiko-client/internal/testutils" "github.com/taikoxyz/taiko-client/pkg/jwt" + "github.com/taikoxyz/taiko-client/pkg/rpc" "github.com/taikoxyz/taiko-client/proposer" ) @@ -27,37 +28,41 @@ type DriverTestSuite struct { func (s *DriverTestSuite) SetupTest() { s.ClientTestSuite.SetupTest() - // Init driver + // InitFromConfig driver jwtSecret, err := jwt.ParseSecretFromFile(os.Getenv("JWT_SECRET")) s.Nil(err) s.NotEmpty(jwtSecret) d := new(Driver) ctx, cancel := context.WithCancel(context.Background()) - s.Nil(InitFromConfig(ctx, d, &Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), - L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - JwtSecret: string(jwtSecret), + s.Nil(d.InitFromConfig(ctx, &Config{ + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), + L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + JwtSecret: string(jwtSecret), + }, })) s.d = d s.cancel = cancel - // Init proposer + // InitFromConfig proposer p := new(proposer.Proposer) l1ProposerPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROPOSER_PRIVATE_KEY"))) s.Nil(err) proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests - s.Nil(proposer.InitFromConfig(context.Background(), p, &proposer.Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + s.Nil(p.InitFromConfig(context.Background(), &proposer.Config{ + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + }, AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), L1ProposerPrivKey: l1ProposerPrivKey, ProposeInterval: &proposeInterval, diff --git a/pkg/rpc/client.go b/pkg/rpc/client.go index e0b2706bc..fcdae30f0 100644 --- a/pkg/rpc/client.go +++ b/pkg/rpc/client.go @@ -56,8 +56,8 @@ type ClientConfig struct { L2EngineEndpoint string JwtSecret string RetryInterval time.Duration - Timeout *time.Duration - BackOffMaxRetrys *big.Int + Timeout time.Duration + BackOffMaxRetries uint64 } // NewClient initializes all RPC clients used by Taiko client software. @@ -65,17 +65,16 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { ctxWithTimeout, cancel := ctxWithTimeoutOrDefault(ctx, defaultTimeout) defer cancel() - if cfg.BackOffMaxRetrys == nil { - defaultRetrys := new(big.Int).SetInt64(10) - cfg.BackOffMaxRetrys = defaultRetrys + if cfg.BackOffMaxRetries == 0 { + cfg.BackOffMaxRetries = 10 } - l1EthClient, err := DialClientWithBackoff(ctxWithTimeout, cfg.L1Endpoint, cfg.RetryInterval, cfg.BackOffMaxRetrys) + l1EthClient, err := DialClientWithBackoff(ctxWithTimeout, cfg.L1Endpoint, cfg.RetryInterval, cfg.BackOffMaxRetries) if err != nil { return nil, err } - l2EthClient, err := DialClientWithBackoff(ctxWithTimeout, cfg.L2Endpoint, cfg.RetryInterval, cfg.BackOffMaxRetrys) + l2EthClient, err := DialClientWithBackoff(ctxWithTimeout, cfg.L2Endpoint, cfg.RetryInterval, cfg.BackOffMaxRetries) if err != nil { return nil, err } @@ -84,13 +83,8 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { l1RPC *EthClient l2RPC *EthClient ) - if cfg.Timeout != nil { - l1RPC = NewEthClientWithTimeout(l1EthClient, *cfg.Timeout) - l2RPC = NewEthClientWithTimeout(l2EthClient, *cfg.Timeout) - } else { - l1RPC = NewEthClientWithDefaultTimeout(l1EthClient) - l2RPC = NewEthClientWithDefaultTimeout(l2EthClient) - } + l1RPC = NewEthClientWithTimeout(l1EthClient, cfg.Timeout) + l2RPC = NewEthClientWithTimeout(l2EthClient, cfg.Timeout) taikoL1, err := bindings.NewTaikoL1Client(cfg.TaikoL1Address, l1RPC) if err != nil { @@ -160,7 +154,7 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { cfg.L2EngineEndpoint, cfg.JwtSecret, cfg.RetryInterval, - cfg.BackOffMaxRetrys, + cfg.BackOffMaxRetries, ); err != nil { return nil, err } @@ -172,16 +166,11 @@ func NewClient(ctx context.Context, cfg *ClientConfig) (*Client, error) { ctxWithTimeout, cfg.L2CheckPoint, cfg.RetryInterval, - cfg.BackOffMaxRetrys) + cfg.BackOffMaxRetries) if err != nil { return nil, err } - - if cfg.Timeout != nil { - l2CheckPoint = NewEthClientWithTimeout(l2CheckPointEthClient, *cfg.Timeout) - } else { - l2CheckPoint = NewEthClientWithDefaultTimeout(l2CheckPointEthClient) - } + l2CheckPoint = NewEthClientWithTimeout(l2CheckPointEthClient, cfg.Timeout) } client := &Client{ diff --git a/pkg/rpc/client_test.go b/pkg/rpc/client_test.go index bcb810820..4100494b5 100644 --- a/pkg/rpc/client_test.go +++ b/pkg/rpc/client_test.go @@ -30,7 +30,6 @@ func newTestClient(t *testing.T) *Client { } func newTestClientWithTimeout(t *testing.T) *Client { - timeout := 5 * time.Second client, err := NewClient(context.Background(), &ClientConfig{ L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), @@ -40,7 +39,7 @@ func newTestClientWithTimeout(t *testing.T) *Client { L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), JwtSecret: os.Getenv("JWT_SECRET"), RetryInterval: backoff.DefaultMaxInterval, - Timeout: &timeout, + Timeout: 5 * time.Second, }) require.Nil(t, err) diff --git a/pkg/rpc/dial.go b/pkg/rpc/dial.go index 00dc933e9..6d7fee94f 100644 --- a/pkg/rpc/dial.go +++ b/pkg/rpc/dial.go @@ -3,7 +3,6 @@ package rpc import ( "context" "fmt" - "math/big" "net/url" "time" @@ -21,7 +20,7 @@ func DialClientWithBackoff( ctx context.Context, url string, retryInterval time.Duration, - maxRetrys *big.Int) (*ethclient.Client, error) { + maxRetrys uint64) (*ethclient.Client, error) { var client *ethclient.Client if err := backoff.Retry( func() (err error) { @@ -36,7 +35,7 @@ func DialClientWithBackoff( return nil }, - backoff.WithMaxRetries(backoff.NewConstantBackOff(retryInterval), maxRetrys.Uint64()), + backoff.WithMaxRetries(backoff.NewConstantBackOff(retryInterval), maxRetrys), ); err != nil { return nil, err } @@ -51,7 +50,7 @@ func DialEngineClientWithBackoff( url string, jwtSecret string, retryInterval time.Duration, - maxRetrys *big.Int, + maxRetry uint64, ) (*EngineClient, error) { var engineClient *EngineClient if err := backoff.Retry( @@ -68,7 +67,7 @@ func DialEngineClientWithBackoff( engineClient = &EngineClient{client} return nil }, - backoff.WithMaxRetries(backoff.NewConstantBackOff(retryInterval), maxRetrys.Uint64()), + backoff.WithMaxRetries(backoff.NewConstantBackOff(retryInterval), maxRetry), ); err != nil { return nil, err } diff --git a/pkg/rpc/dial_test.go b/pkg/rpc/dial_test.go index 5aff63a80..f01ccd4cc 100644 --- a/pkg/rpc/dial_test.go +++ b/pkg/rpc/dial_test.go @@ -2,7 +2,6 @@ package rpc import ( "context" - "math/big" "os" "testing" "time" @@ -24,7 +23,7 @@ func TestDialEngineClientWithBackoff(t *testing.T) { os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), string(jwtSecret), 12*time.Second, - new(big.Int).SetUint64(10), + 10, ) require.Nil(t, err) @@ -40,7 +39,7 @@ func TestDialClientWithBackoff(t *testing.T) { context.Background(), os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), 12*time.Second, - new(big.Int).SetUint64(10), + 10, ) require.Nil(t, err) @@ -57,7 +56,7 @@ func TestDialClientWithBackoff_CtxError(t *testing.T) { ctx, "invalid", -1, - new(big.Int).SetUint64(10), + 10, ) require.NotNil(t, err) } @@ -75,7 +74,7 @@ func TestDialEngineClientWithBackoff_CtxError(t *testing.T) { "invalid", string(jwtSecret), -1, - new(big.Int).SetUint64(10), + 10, ) require.NotNil(t, err2) } diff --git a/pkg/rpc/ethclient.go b/pkg/rpc/ethclient.go index f5378d879..e2dfe41e1 100644 --- a/pkg/rpc/ethclient.go +++ b/pkg/rpc/ethclient.go @@ -26,20 +26,10 @@ func NewEthClientWithTimeout( if ethclient == nil { return nil } - - return &EthClient{Client: ethclient, timeout: timeout} -} - -// NewEthClientWithDefaultTimeout creates a new EthClient instance with the default -// timeout. -func NewEthClientWithDefaultTimeout( - ethclient *ethclient.Client, -) *EthClient { - if ethclient == nil { - return nil + if timeout == 0 { + timeout = defaultTimeout } - - return &EthClient{Client: ethclient, timeout: defaultTimeout} + return &EthClient{Client: ethclient, timeout: timeout} } // ChainID retrieves the current chain ID for transaction replay protection. diff --git a/proposer/config.go b/proposer/config.go index 24778c516..4a6834c26 100644 --- a/proposer/config.go +++ b/proposer/config.go @@ -13,15 +13,12 @@ import ( "github.com/urfave/cli/v2" "github.com/taikoxyz/taiko-client/cmd/flags" + "github.com/taikoxyz/taiko-client/pkg/rpc" ) // Config contains all configurations to initialize a Taiko proposer. type Config struct { - L1Endpoint string - L2Endpoint string - TaikoL1Address common.Address - TaikoL2Address common.Address - TaikoTokenAddress common.Address + *rpc.ClientConfig AssignmentHookAddress common.Address L1ProposerPrivKey *ecdsa.PrivateKey ExtraData string @@ -30,10 +27,8 @@ type Config struct { LocalAddressesOnly bool ProposeEmptyBlocksInterval *time.Duration MaxProposedTxListsPerEpoch uint64 - ProposeBlockTxGasLimit *uint64 - BackOffRetryInterval time.Duration + ProposeBlockTxGasLimit uint64 ProposeBlockTxReplacementMultiplier uint64 - RPCTimeout *time.Duration WaitReceiptTimeout time.Duration ProposeBlockTxGasTipCap *big.Int ProverEndpoints []*url.URL @@ -69,7 +64,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { proposeEmptyBlocksInterval = &interval } - localAddresses := []common.Address{} + var localAddresses []common.Address if c.IsSet(flags.TxPoolLocals.Name) { for _, account := range strings.Split(c.String(flags.TxPoolLocals.Name), ",") { if trimmed := strings.TrimSpace(account); !common.IsHexAddress(trimmed) { @@ -79,12 +74,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { } } - var proposeBlockTxGasLimit *uint64 - if c.IsSet(flags.ProposeBlockTxGasLimit.Name) { - gasLimit := c.Uint64(flags.ProposeBlockTxGasLimit.Name) - proposeBlockTxGasLimit = &gasLimit - } - proposeBlockTxReplacementMultiplier := c.Uint64(flags.ProposeBlockTxReplacementMultiplier.Name) if proposeBlockTxReplacementMultiplier == 0 { return nil, fmt.Errorf( @@ -93,12 +82,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { ) } - var timeout *time.Duration - if c.IsSet(flags.RPCTimeout.Name) { - duration := c.Duration(flags.RPCTimeout.Name) - timeout = &duration - } - var proposeBlockTxGasTipCap *big.Int if c.IsSet(flags.ProposeBlockTxGasTipCap.Name) { proposeBlockTxGasTipCap = new(big.Int).SetUint64(c.Uint64(flags.ProposeBlockTxGasTipCap.Name)) @@ -114,11 +97,15 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { } return &Config{ - L1Endpoint: c.String(flags.L1WSEndpoint.Name), - L2Endpoint: c.String(flags.L2HTTPEndpoint.Name), - TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)), - TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)), - TaikoTokenAddress: common.HexToAddress(c.String(flags.TaikoTokenAddress.Name)), + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: c.String(flags.L1WSEndpoint.Name), + L2Endpoint: c.String(flags.L2HTTPEndpoint.Name), + TaikoL1Address: common.HexToAddress(c.String(flags.TaikoL1Address.Name)), + TaikoL2Address: common.HexToAddress(c.String(flags.TaikoL2Address.Name)), + TaikoTokenAddress: common.HexToAddress(c.String(flags.TaikoTokenAddress.Name)), + RetryInterval: c.Duration(flags.BackOffRetryInterval.Name), + Timeout: c.Duration(flags.RPCTimeout.Name), + }, AssignmentHookAddress: common.HexToAddress(c.String(flags.ProposerAssignmentHookAddress.Name)), L1ProposerPrivKey: l1ProposerPrivKey, ExtraData: c.String(flags.ExtraData.Name), @@ -127,10 +114,8 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { LocalAddressesOnly: c.Bool(flags.TxPoolLocalsOnly.Name), ProposeEmptyBlocksInterval: proposeEmptyBlocksInterval, MaxProposedTxListsPerEpoch: c.Uint64(flags.MaxProposedTxListsPerEpoch.Name), - ProposeBlockTxGasLimit: proposeBlockTxGasLimit, - BackOffRetryInterval: c.Duration(flags.BackOffRetryInterval.Name), + ProposeBlockTxGasLimit: c.Uint64(flags.ProposeBlockTxGasLimit.Name), ProposeBlockTxReplacementMultiplier: proposeBlockTxReplacementMultiplier, - RPCTimeout: timeout, WaitReceiptTimeout: c.Duration(flags.WaitReceiptTimeout.Name), ProposeBlockTxGasTipCap: proposeBlockTxGasTipCap, ProverEndpoints: proverEndpoints, diff --git a/proposer/config_test.go b/proposer/config_test.go index 62136eaa8..7951afd66 100644 --- a/proposer/config_test.go +++ b/proposer/config_test.go @@ -48,7 +48,7 @@ func (s *ProposerTestSuite) TestNewConfigFromCliContext() { s.Equal(1, len(c.LocalAddresses)) s.Equal(goldenTouchAddress, c.LocalAddresses[0]) s.Equal(uint64(5), c.ProposeBlockTxReplacementMultiplier) - s.Equal(5*time.Second, *c.RPCTimeout) + s.Equal(5*time.Second, c.Timeout) s.Equal(10*time.Second, c.WaitReceiptTimeout) s.Equal(uint64(tierFee), c.OptimisticTierFee.Uint64()) s.Equal(uint64(tierFee), c.SgxTierFee.Uint64()) diff --git a/proposer/proposer.go b/proposer/proposer.go index 5a7499842..6255a9edb 100644 --- a/proposer/proposer.go +++ b/proposer/proposer.go @@ -44,22 +44,14 @@ type Proposer struct { // RPC clients rpc *rpc.Client + *Config // Private keys and account addresses - proposerPrivKey *ecdsa.PrivateKey proposerAddress common.Address - // Proposing configurations - proposingInterval *time.Duration - proposeEmptyBlocksInterval *time.Duration - proposingTimer *time.Timer - locals []common.Address - localsOnly bool - maxProposedTxListsPerEpoch uint64 - proposeBlockTxGasLimit *uint64 - txReplacementTipMultiplier uint64 - proposeBlockTxGasTipCap *big.Int - tiers []*rpc.TierProviderTierWithID - tierFees []encoding.TierFee + proposingTimer *time.Timer + + tiers []*rpc.TierProviderTierWithID + tierFees []encoding.TierFee // Prover selector proverSelector selector.ProverSelector @@ -73,10 +65,6 @@ type Proposer struct { ctx context.Context wg sync.WaitGroup - - waitReceiptTimeout time.Duration - - cfg *Config } // InitFromCli New initializes the given proposer instance based on the command line flags. @@ -86,36 +74,18 @@ func (p *Proposer) InitFromCli(ctx context.Context, c *cli.Context) error { return err } - return InitFromConfig(ctx, p, cfg) + return p.InitFromConfig(ctx, cfg) } // InitFromConfig initializes the proposer instance based on the given configurations. -func InitFromConfig(ctx context.Context, p *Proposer, cfg *Config) (err error) { - p.proposerPrivKey = cfg.L1ProposerPrivKey +func (p *Proposer) InitFromConfig(ctx context.Context, cfg *Config) (err error) { p.proposerAddress = crypto.PubkeyToAddress(cfg.L1ProposerPrivKey.PublicKey) - p.proposingInterval = cfg.ProposeInterval - p.proposeEmptyBlocksInterval = cfg.ProposeEmptyBlocksInterval - p.proposeBlockTxGasLimit = cfg.ProposeBlockTxGasLimit p.wg = sync.WaitGroup{} - p.locals = cfg.LocalAddresses - p.localsOnly = cfg.LocalAddressesOnly - p.maxProposedTxListsPerEpoch = cfg.MaxProposedTxListsPerEpoch - p.txReplacementTipMultiplier = cfg.ProposeBlockTxReplacementMultiplier - p.proposeBlockTxGasTipCap = cfg.ProposeBlockTxGasTipCap p.ctx = ctx - p.waitReceiptTimeout = cfg.WaitReceiptTimeout - p.cfg = cfg + p.Config = cfg // RPC clients - if p.rpc, err = rpc.NewClient(p.ctx, &rpc.ClientConfig{ - L1Endpoint: cfg.L1Endpoint, - L2Endpoint: cfg.L2Endpoint, - TaikoL1Address: cfg.TaikoL1Address, - TaikoL2Address: cfg.TaikoL2Address, - TaikoTokenAddress: cfg.TaikoTokenAddress, - RetryInterval: cfg.BackOffRetryInterval, - Timeout: cfg.RPCTimeout, - }); err != nil { + if p.rpc, err = rpc.NewClient(p.ctx, cfg.ClientConfig); err != nil { return fmt.Errorf("initialize rpc clients error: %w", err) } @@ -184,8 +154,8 @@ func (p *Proposer) eventLoop() { continue } // if no new transactions and empty block interval has passed, propose an empty block - if p.proposeEmptyBlocksInterval != nil { - if time.Now().Before(lastNonEmptyBlockProposedAt.Add(*p.proposeEmptyBlocksInterval)) { + if p.ProposeEmptyBlocksInterval != nil { + if time.Now().Before(lastNonEmptyBlockProposedAt.Add(*p.ProposeEmptyBlocksInterval)) { continue } @@ -246,14 +216,14 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { baseFee, p.protocolConfigs.BlockMaxGasLimit, p.protocolConfigs.BlockMaxTxListBytes.Uint64(), - p.locals, - p.maxProposedTxListsPerEpoch, + p.LocalAddresses, + p.MaxProposedTxListsPerEpoch, ) if err != nil { return fmt.Errorf("failed to fetch transaction pool content: %w", err) } - if p.localsOnly { + if p.LocalAddressesOnly { var ( localTxsLists []types.Transactions signer = types.LatestSignerForChainID(p.rpc.L2ChainID) @@ -266,7 +236,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { return err } - for _, localAddress := range p.locals { + for _, localAddress := range p.LocalAddresses { if sender == localAddress { filtered = append(filtered, tx) } @@ -292,7 +262,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { } nonce, err := p.rpc.L1.NonceAt( ctx, - crypto.PubkeyToAddress(p.proposerPrivKey.PublicKey), + crypto.PubkeyToAddress(p.L1ProposerPrivKey.PublicKey), new(big.Int).SetUint64(head), ) if err != nil { @@ -305,7 +275,7 @@ func (p *Proposer) ProposeOp(ctx context.Context) error { for i, txs := range txLists { func(i int, txs types.Transactions) { g.Go(func() error { - if i >= int(p.maxProposedTxListsPerEpoch) { + if i >= int(p.MaxProposedTxListsPerEpoch) { return nil } @@ -348,31 +318,29 @@ func (p *Proposer) sendProposeBlockTx( isReplacement bool, ) (*types.Transaction, error) { // Propose the transactions list - opts, err := getTxOpts(ctx, p.rpc.L1, p.proposerPrivKey, p.rpc.L1ChainID, maxFee) + opts, err := getTxOpts(ctx, p.rpc.L1, p.L1ProposerPrivKey, p.rpc.L1ChainID, maxFee) if err != nil { return nil, err } if nonce != nil { opts.Nonce = new(big.Int).SetUint64(*nonce) } - if p.proposeBlockTxGasLimit != nil { - opts.GasLimit = *p.proposeBlockTxGasLimit - } + opts.GasLimit = p.ProposeBlockTxGasLimit if isReplacement { if opts, err = rpc.IncreaseGasTipCap( ctx, p.rpc, opts, p.proposerAddress, - new(big.Int).SetUint64(p.txReplacementTipMultiplier), - p.proposeBlockTxGasTipCap, + new(big.Int).SetUint64(p.ProposeBlockTxReplacementMultiplier), + p.ProposeBlockTxGasTipCap, ); err != nil { return nil, err } } var parentMetaHash = [32]byte{} - if p.cfg.IncludeParentMetaHash { + if p.IncludeParentMetaHash { state, err := p.rpc.TaikoL1.State(&bind.CallOpts{Context: ctx}) if err != nil { return nil, err @@ -399,13 +367,13 @@ func (p *Proposer) sendProposeBlockTx( } hookCalls = append(hookCalls, encoding.HookCall{ - Hook: p.cfg.AssignmentHookAddress, + Hook: p.AssignmentHookAddress, Data: hookInputData, }) encodedParams, err := encoding.EncodeBlockParams(&encoding.BlockParams{ AssignedProver: assignedProver, - ExtraData: rpc.StringToBytes32(p.cfg.ExtraData), + ExtraData: rpc.StringToBytes32(p.ExtraData), TxListByteOffset: common.Big0, TxListByteSize: common.Big0, BlobHash: [32]byte{}, @@ -491,7 +459,7 @@ func (p *Proposer) ProposeTxList( return err } - ctxWithTimeout, cancel := context.WithTimeout(ctx, p.waitReceiptTimeout) + ctxWithTimeout, cancel := context.WithTimeout(ctx, p.WaitReceiptTimeout) defer cancel() if _, err := rpc.WaitReceipt(ctxWithTimeout, p.rpc.L1, tx); err != nil { @@ -522,8 +490,8 @@ func (p *Proposer) updateProposingTicker() { } var duration time.Duration - if p.proposingInterval != nil { - duration = *p.proposingInterval + if p.ProposeInterval != nil { + duration = *p.ProposeInterval } else { // Random number between 12 - 120 randomSeconds := rand.Intn(120-11) + 12 // nolint: gosec @@ -553,13 +521,13 @@ func (p *Proposer) initTierFees() error { switch tier.ID { case encoding.TierOptimisticID: - p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.cfg.OptimisticTierFee}) + p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.OptimisticTierFee}) case encoding.TierSgxID: - p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.cfg.SgxTierFee}) + p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.SgxTierFee}) case encoding.TierPseZkevmID: - p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.cfg.PseZkevmTierFee}) + p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.PseZkevmTierFee}) case encoding.TierSgxAndPseZkevmID: - p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.cfg.SgxAndPseZkevmTierFee}) + p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: p.SgxAndPseZkevmTierFee}) case encoding.TierGuardianID: // Guardian prover should not charge any fee. p.tierFees = append(p.tierFees, encoding.TierFee{Tier: tier.ID, Fee: common.Big0}) diff --git a/proposer/proposer_test.go b/proposer/proposer_test.go index 8303e36db..2bbf8af9e 100644 --- a/proposer/proposer_test.go +++ b/proposer/proposer_test.go @@ -15,6 +15,7 @@ import ( "github.com/taikoxyz/taiko-client/bindings" "github.com/taikoxyz/taiko-client/internal/testutils" + "github.com/taikoxyz/taiko-client/pkg/rpc" ) type ProposerTestSuite struct { @@ -34,12 +35,14 @@ func (s *ProposerTestSuite) SetupTest() { ctx, cancel := context.WithCancel(context.Background()) proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests - s.Nil(InitFromConfig(ctx, p, &Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + s.Nil(p.InitFromConfig(ctx, &Config{ + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_HTTP_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + }, AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), L1ProposerPrivKey: l1ProposerPrivKey, ProposeInterval: &proposeInterval, @@ -115,8 +118,8 @@ func (s *ProposerTestSuite) TestProposeOp() { } func (s *ProposerTestSuite) TestProposeOpLocalsOnly() { - s.p.locals = []common.Address{common.BytesToAddress(testutils.RandomBytes(20))} - s.p.localsOnly = true + s.p.LocalAddresses = []common.Address{common.BytesToAddress(testutils.RandomBytes(20))} + s.p.LocalAddressesOnly = true // Propose txs in L2 execution engine's mempool sink := make(chan *bindings.TaikoL1ClientBlockProposed) @@ -152,7 +155,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() { opts, err := getTxOpts( context.Background(), s.p.rpc.L1, - s.p.proposerPrivKey, + s.p.L1ProposerPrivKey, s.RPCClient.L1ChainID, fee, ) @@ -174,7 +177,7 @@ func (s *ProposerTestSuite) TestSendProposeBlockTx() { s.SetL1Automine(false) defer s.SetL1Automine(true) - signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(s.RPCClient.L1ChainID), s.p.proposerPrivKey) + signedTx, err := types.SignTx(tx, types.LatestSignerForChainID(s.RPCClient.L1ChainID), s.p.L1ProposerPrivKey) s.Nil(err) s.Nil(s.RPCClient.L1.SendTransaction(context.Background(), signedTx)) @@ -209,15 +212,15 @@ func (s *ProposerTestSuite) TestAssignProverSuccessFirstRound() { _, _, fee, err := s.p.proverSelector.AssignProver(context.Background(), s.p.tierFees, testutils.RandomHash()) s.Nil(err) - s.Equal(fee.Uint64(), s.p.cfg.OptimisticTierFee.Uint64()) + s.Equal(fee.Uint64(), s.p.OptimisticTierFee.Uint64()) } func (s *ProposerTestSuite) TestUpdateProposingTicker() { oneHour := 1 * time.Hour - s.p.proposingInterval = &oneHour + s.p.ProposeInterval = &oneHour s.NotPanics(s.p.updateProposingTicker) - s.p.proposingInterval = nil + s.p.ProposeInterval = nil s.NotPanics(s.p.updateProposingTicker) } diff --git a/prover/config.go b/prover/config.go index a7fac7eb0..828ffaefa 100644 --- a/prover/config.go +++ b/prover/config.go @@ -37,7 +37,7 @@ type Config struct { BackOffRetryInterval time.Duration ProveUnassignedBlocks bool ContesterMode bool - RPCTimeout *time.Duration + RPCTimeout time.Duration WaitReceiptTimeout time.Duration ProveBlockGasLimit *uint64 ProveBlockTxReplacementMultiplier uint64 @@ -70,12 +70,6 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { startingBlockID = new(big.Int).SetUint64(c.Uint64(flags.StartingBlockID.Name)) } - var timeout *time.Duration - if c.IsSet(flags.RPCTimeout.Name) { - duration := c.Duration(flags.RPCTimeout.Name) - timeout = &duration - } - var proveBlockTxGasLimit *uint64 if c.IsSet(flags.ProveBlockTxGasLimit.Name) { gasLimit := c.Uint64(flags.ProveBlockTxGasLimit.Name) @@ -152,7 +146,7 @@ func NewConfigFromCliContext(c *cli.Context) (*Config, error) { BackOffRetryInterval: c.Duration(flags.BackOffRetryInterval.Name), ProveUnassignedBlocks: c.Bool(flags.ProveUnassignedBlocks.Name), ContesterMode: c.Bool(flags.ContesterMode.Name), - RPCTimeout: timeout, + RPCTimeout: c.Duration(flags.RPCTimeout.Name), WaitReceiptTimeout: c.Duration(flags.WaitReceiptTimeout.Name), ProveBlockGasLimit: proveBlockTxGasLimit, Capacity: c.Uint64(flags.ProverCapacity.Name), diff --git a/prover/config_test.go b/prover/config_test.go index 5ed2e833f..1c1732d8b 100644 --- a/prover/config_test.go +++ b/prover/config_test.go @@ -43,7 +43,7 @@ func (s *ProverTestSuite) TestNewConfigFromCliContextGuardianProver() { s.Equal("", c.Graffiti) s.True(c.ProveUnassignedBlocks) s.True(c.ContesterMode) - s.Equal(rpcTimeout, *c.RPCTimeout) + s.Equal(rpcTimeout, c.RPCTimeout) s.Equal(uint64(8), c.Capacity) s.Equal(uint64(minTierFee), c.MinOptimisticTierFee.Uint64()) s.Equal(uint64(minTierFee), c.MinSgxTierFee.Uint64()) diff --git a/prover/proof_submitter/proof_submitter_test.go b/prover/proof_submitter/proof_submitter_test.go index e8a5a763e..e33807be0 100644 --- a/prover/proof_submitter/proof_submitter_test.go +++ b/prover/proof_submitter/proof_submitter_test.go @@ -18,6 +18,7 @@ import ( "github.com/taikoxyz/taiko-client/driver/chain_syncer/calldata" "github.com/taikoxyz/taiko-client/driver/state" "github.com/taikoxyz/taiko-client/internal/testutils" + "github.com/taikoxyz/taiko-client/pkg/rpc" "github.com/taikoxyz/taiko-client/proposer" producer "github.com/taikoxyz/taiko-client/prover/proof_producer" ) @@ -88,12 +89,14 @@ func (s *ProofSubmitterTestSuite) SetupTest() { s.Nil(err) proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests - s.Nil(proposer.InitFromConfig(context.Background(), prop, (&proposer.Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{ + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + }, AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), L1ProposerPrivKey: l1ProposerPrivKey, @@ -107,7 +110,7 @@ func (s *ProofSubmitterTestSuite) SetupTest() { SgxAndPseZkevmTierFee: common.Big256, MaxTierFeePriceBumps: 3, TierFeePriceBump: common.Big2, - }))) + })) s.proposer = prop } diff --git a/prover/prover.go b/prover/prover.go index 915adba0a..3d692c64c 100644 --- a/prover/prover.go +++ b/prover/prover.go @@ -109,7 +109,7 @@ func InitFromConfig(ctx context.Context, p *Prover, cfg *Config) (err error) { GuardianProverAddress: cfg.GuardianProverAddress, RetryInterval: cfg.BackOffRetryInterval, Timeout: cfg.RPCTimeout, - BackOffMaxRetrys: new(big.Int).SetUint64(p.cfg.BackOffMaxRetrys), + BackOffMaxRetries: cfg.BackOffMaxRetrys, }); err != nil { return err } diff --git a/prover/prover_test.go b/prover/prover_test.go index 7ddd89bd7..909744017 100644 --- a/prover/prover_test.go +++ b/prover/prover_test.go @@ -99,13 +99,15 @@ func (s *ProverTestSuite) SetupTest() { s.NotEmpty(jwtSecret) d := new(driver.Driver) - s.Nil(driver.InitFromConfig(context.Background(), d, &driver.Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), - L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - JwtSecret: string(jwtSecret), + s.Nil(d.InitFromConfig(context.Background(), &driver.Config{ + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), + L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + JwtSecret: string(jwtSecret), + }, })) s.d = d @@ -116,12 +118,14 @@ func (s *ProverTestSuite) SetupTest() { prop := new(proposer.Proposer) proposeInterval := 1024 * time.Hour // No need to periodically propose transactions list in unit tests - s.Nil(proposer.InitFromConfig(context.Background(), prop, (&proposer.Config{ - L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), - L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), - TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), - TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), - TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + s.Nil(prop.InitFromConfig(context.Background(), &proposer.Config{ + ClientConfig: &rpc.ClientConfig{ + L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), + L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), + TaikoL1Address: common.HexToAddress(os.Getenv("TAIKO_L1_ADDRESS")), + TaikoL2Address: common.HexToAddress(os.Getenv("TAIKO_L2_ADDRESS")), + TaikoTokenAddress: common.HexToAddress(os.Getenv("TAIKO_TOKEN_ADDRESS")), + }, AssignmentHookAddress: common.HexToAddress(os.Getenv("ASSIGNMENT_HOOK_ADDRESS")), L1ProposerPrivKey: l1ProposerPrivKey, ProposeInterval: &proposeInterval, @@ -134,7 +138,7 @@ func (s *ProverTestSuite) SetupTest() { SgxAndPseZkevmTierFee: common.Big256, MaxTierFeePriceBumps: 3, TierFeePriceBump: common.Big2, - }))) + })) s.proposer = prop } @@ -151,7 +155,7 @@ func (s *ProverTestSuite) TestInitError() { p := new(Prover) // Error should be "context canceled", instead is "Dial ethclient error:" - s.ErrorContains(InitFromConfig(ctx, p, (&Config{ + s.ErrorContains(InitFromConfig(ctx, p, &Config{ L1WsEndpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), L1HttpEndpoint: os.Getenv("L1_NODE_HTTP_ENDPOINT"), L2WsEndpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), @@ -164,7 +168,7 @@ func (s *ProverTestSuite) TestInitError() { Dummy: true, ProveUnassignedBlocks: true, ProveBlockTxReplacementMultiplier: 2, - })), "dial tcp:") + }), "dial tcp:") } func (s *ProverTestSuite) TestOnBlockProposed() { diff --git a/prover/server/server_test.go b/prover/server/server_test.go index fd2f94ce2..c36946dcc 100644 --- a/prover/server/server_test.go +++ b/prover/server/server_test.go @@ -31,7 +31,6 @@ func (s *ProverServerTestSuite) SetupTest() { l1ProverPrivKey, err := crypto.ToECDSA(common.FromHex(os.Getenv("L1_PROVER_PRIVATE_KEY"))) s.Nil(err) - timeout := 5 * time.Second rpcClient, err := rpc.NewClient(context.Background(), &rpc.ClientConfig{ L1Endpoint: os.Getenv("L1_NODE_WS_ENDPOINT"), L2Endpoint: os.Getenv("L2_EXECUTION_ENGINE_WS_ENDPOINT"), @@ -41,7 +40,7 @@ func (s *ProverServerTestSuite) SetupTest() { L2EngineEndpoint: os.Getenv("L2_EXECUTION_ENGINE_AUTH_ENDPOINT"), JwtSecret: os.Getenv("JWT_SECRET"), RetryInterval: backoff.DefaultMaxInterval, - Timeout: &timeout, + Timeout: 5 * time.Second, }) s.Nil(err)