From b7a79a419545e150055e9813d1a9329c8c186478 Mon Sep 17 00:00:00 2001 From: aloknerurkar Date: Tue, 10 Dec 2024 14:07:08 +0530 Subject: [PATCH] feat: use multiple RPCs for relayer (#527) --- bridge/standard/cmd/relayer/main.go | 12 ++++++------ bridge/standard/pkg/node/node.go | 14 +++++++------- .../templates/jobs/mev-commit-bridge.nomad.j2 | 2 +- .../nomad/playbooks/variables/profiles.yml | 2 +- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bridge/standard/cmd/relayer/main.go b/bridge/standard/cmd/relayer/main.go index 2cfa78df3..3e4580144 100644 --- a/bridge/standard/cmd/relayer/main.go +++ b/bridge/standard/cmd/relayer/main.go @@ -85,10 +85,10 @@ var ( }, }) - optionL1RPCUrl = altsrc.NewStringFlag(&cli.StringFlag{ - Name: "l1-rpc-url", - Usage: "URL for L1 RPC", - EnvVars: []string{"STANDARD_BRIDGE_RELAYER_L1_RPC_URL"}, + optionL1RPCUrls = altsrc.NewStringSliceFlag(&cli.StringSliceFlag{ + Name: "l1-rpc-urls", + Usage: "URLs for L1 RPC", + EnvVars: []string{"STANDARD_BRIDGE_RELAYER_L1_RPC_URLS"}, Required: true, }) @@ -158,7 +158,7 @@ func main() { optionLogFmt, optionLogLevel, optionLogTags, - optionL1RPCUrl, + optionL1RPCUrls, optionSettlementRPCUrl, optionL1ContractAddr, optionSettlementContractAddr, @@ -219,7 +219,7 @@ func start(c *cli.Context) error { Logger: logger, HTTPPort: c.Int(optionHTTPPort.Name), Signer: signer, - L1RPCURL: c.String(optionL1RPCUrl.Name), + L1RPCURLs: c.StringSlice(optionL1RPCUrls.Name), L1GatewayContractAddr: common.HexToAddress(c.String(optionL1ContractAddr.Name)), SettlementRPCURL: c.String(optionSettlementRPCUrl.Name), SettlementContractAddr: common.HexToAddress(c.String(optionSettlementContractAddr.Name)), diff --git a/bridge/standard/pkg/node/node.go b/bridge/standard/pkg/node/node.go index 75315cbb8..60e77d570 100644 --- a/bridge/standard/pkg/node/node.go +++ b/bridge/standard/pkg/node/node.go @@ -37,7 +37,7 @@ type Options struct { Logger *slog.Logger HTTPPort int Signer keysigner.KeySigner - L1RPCURL string + L1RPCURLs []string L1GatewayContractAddr common.Address SettlementRPCURL string SettlementContractAddr common.Address @@ -100,7 +100,7 @@ func NewNode(opts *Options) (*Node, error) { ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) defer cancel() - client, err := ethclient.DialContext(ctx, opts.L1RPCURL) + client, err := ethclient.DialContext(ctx, opts.L1RPCURLs[0]) if err != nil { return nil, fmt.Errorf("failed to connect to the Ethereum node: %w", err) } @@ -125,7 +125,7 @@ func NewNode(opts *Options) (*Node, error) { ctx, "l1", opts.Logger, - opts.L1RPCURL, + opts.L1RPCURLs, opts.Signer, opts.L1GatewayContractAddr, l1Store, @@ -139,7 +139,7 @@ func NewNode(opts *Options) (*Node, error) { ctx, "settlement", opts.Logger, - opts.SettlementRPCURL, + []string{opts.SettlementRPCURL}, opts.Signer, opts.SettlementContractAddr, settlementStore, @@ -243,12 +243,12 @@ func (n *Node) createGatewayContract( ctx context.Context, component string, logger *slog.Logger, - rpcURL string, + rpcURLs []string, signer keysigner.KeySigner, contractAddr common.Address, st *store.Store, ) error { - client, err := ethclient.Dial(rpcURL) + client, err := ethclient.Dial(rpcURLs[0]) if err != nil { return fmt.Errorf("failed to connect to the Ethereum node: %w", err) } @@ -288,7 +288,7 @@ func (n *Node) createGatewayContract( wrappedClient, err := ethwrapper.NewClient( logger.With("component", fmt.Sprintf("%s/ethwrapper", component)), - []string{rpcURL}, + rpcURLs, opts..., ) if err != nil { diff --git a/infrastructure/nomad/playbooks/templates/jobs/mev-commit-bridge.nomad.j2 b/infrastructure/nomad/playbooks/templates/jobs/mev-commit-bridge.nomad.j2 index 7f00e6db2..df021fe02 100644 --- a/infrastructure/nomad/playbooks/templates/jobs/mev-commit-bridge.nomad.j2 +++ b/infrastructure/nomad/playbooks/templates/jobs/mev-commit-bridge.nomad.j2 @@ -225,7 +225,7 @@ job "{{ job.name }}" { {{- end }} {{- end }} {% endraw %} - STANDARD_BRIDGE_RELAYER_L1_RPC_URL="{{ job.env['l1_rpc_url'] }}" + STANDARD_BRIDGE_RELAYER_L1_RPC_URLS="{{ job.env['l1_rpc_urls'] }}" L1_CHAIN_ID="{{ job.env['l1_chain_id'] }}" CONTRACTS_PATH="local/contracts" ARTIFACT_OUT_PATH="local" diff --git a/infrastructure/nomad/playbooks/variables/profiles.yml b/infrastructure/nomad/playbooks/variables/profiles.yml index 2c0213974..2dd19cf56 100644 --- a/infrastructure/nomad/playbooks/variables/profiles.yml +++ b/infrastructure/nomad/playbooks/variables/profiles.yml @@ -604,7 +604,7 @@ jobs: to: 5433 env: l1_chain_id: "{{ environments[env].chain_id }}" - l1_rpc_url: "{{ resolved_l1_rpc_urls.split(',')[0] }}" + l1_rpc_urls: "{{ resolved_l1_rpc_urls }}" mev_commit_faucet: &mev_commit_faucet_job name: mev-commit-faucet