From 10dff8fdbcfd81638c4ec9a2658e03cda532a9c8 Mon Sep 17 00:00:00 2001 From: Emiliano Bonassi Date: Thu, 2 May 2024 19:32:46 +0200 Subject: [PATCH] feat(op-batcher): support disable eth fallback --- op-batcher/batcher/driver.go | 14 +++++++++++--- op-batcher/batcher/service.go | 2 +- op-celestia/cli.go | 23 ++++++++++++++++------- op-celestia/da_client.go | 16 +++++++++------- op-node/rollup/driver/da.go | 2 +- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/op-batcher/batcher/driver.go b/op-batcher/batcher/driver.go index 09076374cdfb5..3af4d806404e2 100644 --- a/op-batcher/batcher/driver.go +++ b/op-batcher/batcher/driver.go @@ -510,7 +510,11 @@ func (l *BatchSubmitter) sendTransaction(ctx context.Context, txdata txData, que // signal plasma commitment tx with TxDataVersion1 data = comm.TxData() } - candidate = l.calldataTxCandidate(data) + candidate, err = l.calldataTxCandidate(data) + if err != nil { + l.recordFailedTx(txdata.ID(), err) + return nil + } } intrinsicGas, err := core.IntrinsicGas(candidate.TxData, nil, false, true, true, false) @@ -541,7 +545,7 @@ func (l *BatchSubmitter) blobTxCandidate(data txData) (*txmgr.TxCandidate, error }, nil } -func (l *BatchSubmitter) calldataTxCandidate(data []byte) *txmgr.TxCandidate { +func (l *BatchSubmitter) calldataTxCandidate(data []byte) (*txmgr.TxCandidate, error) { l.Log.Info("building Calldata transaction candidate", "size", len(data)) ctx, cancel := context.WithTimeout(context.Background(), 30*time.Duration(l.RollupConfig.BlockTime)*time.Second) ids, err := l.DAClient.Client.Submit(ctx, [][]byte{data}, -1, l.DAClient.Namespace) @@ -550,12 +554,16 @@ func (l *BatchSubmitter) calldataTxCandidate(data []byte) *txmgr.TxCandidate { l.Log.Info("celestia: blob successfully submitted", "id", hex.EncodeToString(ids[0])) data = append([]byte{celestia.DerivationVersionCelestia}, ids[0]...) } else { + if l.DAClient.EthFallbackDisabled { + return nil, fmt.Errorf("celestia: blob submission failed; eth fallback disabled: %w", err) + } + l.Log.Info("celestia: blob submission failed; falling back to eth", "err", err) } return &txmgr.TxCandidate{ To: &l.RollupConfig.BatchInboxAddress, TxData: data, - } + }, nil } func (l *BatchSubmitter) handleReceipt(r txmgr.TxReceipt[txID]) { diff --git a/op-batcher/batcher/service.go b/op-batcher/batcher/service.go index 164a5a6edc1f9..8ba8ab3423e67 100644 --- a/op-batcher/batcher/service.go +++ b/op-batcher/batcher/service.go @@ -347,7 +347,7 @@ func (bs *BatcherService) initPlasmaDA(cfg *CLIConfig) error { } func (bs *BatcherService) initDA(cfg *CLIConfig) error { - client, err := celestia.NewDAClient(cfg.DaConfig.Rpc, cfg.DaConfig.AuthToken, cfg.DaConfig.Namespace) + client, err := celestia.NewDAClient(cfg.DaConfig.Rpc, cfg.DaConfig.AuthToken, cfg.DaConfig.Namespace, cfg.DaConfig.EthFallbackDisabled) if err != nil { return err } diff --git a/op-celestia/cli.go b/op-celestia/cli.go index 4c2e19145d9da..40550ba5cf4ff 100644 --- a/op-celestia/cli.go +++ b/op-celestia/cli.go @@ -8,11 +8,13 @@ import ( const ( // RPCFlagName defines the flag for the rpc url - RPCFlagName = "da.rpc" + RPCFlagName = "da.rpc" // AuthTokenFlagName defines the flag for the auth token AuthTokenFlagName = "da.auth_token" // NamespaceFlagName defines the flag for the namespace NamespaceFlagName = "da.namespace" + // EthFallbackDisabledFlagName defines the flag for disabling eth fallback + EthFallbackDisabledFlagName = "da.eth_fallback_disabled" // NamespaceSize is the size of the hex encoded namespace string NamespaceSize = 58 @@ -39,13 +41,19 @@ func CLIFlags(envPrefix string) []cli.Flag { Usage: "namespace of the data availability client", EnvVars: opservice.PrefixEnvVar(envPrefix, "DA_NAMESPACE"), }, + &cli.BoolFlag{ + Name: EthFallbackDisabledFlagName, + Usage: "disable eth fallback", + EnvVars: opservice.PrefixEnvVar(envPrefix, "ETH_FALLBACK_DISABLED"), + }, } } type CLIConfig struct { - Rpc string - AuthToken string - Namespace string + Rpc string + AuthToken string + Namespace string + EthFallbackDisabled bool } func (c CLIConfig) Check() error { @@ -60,8 +68,9 @@ func NewCLIConfig() CLIConfig { func ReadCLIConfig(ctx *cli.Context) CLIConfig { return CLIConfig{ - Rpc: ctx.String(RPCFlagName), - AuthToken: ctx.String(AuthTokenFlagName), - Namespace: ctx.String(NamespaceFlagName), + Rpc: ctx.String(RPCFlagName), + AuthToken: ctx.String(AuthTokenFlagName), + Namespace: ctx.String(NamespaceFlagName), + EthFallbackDisabled: ctx.Bool(EthFallbackDisabledFlagName), } } diff --git a/op-celestia/da_client.go b/op-celestia/da_client.go index 8cf70df376444..d3d407a10b94a 100644 --- a/op-celestia/da_client.go +++ b/op-celestia/da_client.go @@ -9,12 +9,13 @@ import ( ) type DAClient struct { - Client da.DA - GetTimeout time.Duration - Namespace da.Namespace + Client da.DA + GetTimeout time.Duration + Namespace da.Namespace + EthFallbackDisabled bool } -func NewDAClient(rpc, token, namespace string) (*DAClient, error) { +func NewDAClient(rpc, token, namespace string, ethFallbackDisabled bool) (*DAClient, error) { client, err := proxy.NewClient(rpc, token) if err != nil { return nil, err @@ -24,8 +25,9 @@ func NewDAClient(rpc, token, namespace string) (*DAClient, error) { return nil, err } return &DAClient{ - Client: client, - GetTimeout: time.Minute, - Namespace: ns, + Client: client, + GetTimeout: time.Minute, + Namespace: ns, + EthFallbackDisabled: ethFallbackDisabled, }, nil } diff --git a/op-node/rollup/driver/da.go b/op-node/rollup/driver/da.go index dc5e5f3ceac0e..cacef1afd0c07 100644 --- a/op-node/rollup/driver/da.go +++ b/op-node/rollup/driver/da.go @@ -6,7 +6,7 @@ import ( ) func SetDAClient(cfg celestia.CLIConfig) error { - client, err := celestia.NewDAClient(cfg.Rpc, cfg.AuthToken, cfg.Namespace) + client, err := celestia.NewDAClient(cfg.Rpc, cfg.AuthToken, cfg.Namespace, false) if err != nil { return err }