Skip to content

Commit

Permalink
feat(op-batcher): support disable eth fallback
Browse files Browse the repository at this point in the history
  • Loading branch information
emilianobonassi authored and tuxcanfly committed May 23, 2024
1 parent 07c3301 commit 10dff8f
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
14 changes: 11 additions & 3 deletions op-batcher/batcher/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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]) {
Expand Down
2 changes: 1 addition & 1 deletion op-batcher/batcher/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
23 changes: 16 additions & 7 deletions op-celestia/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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),
}
}
16 changes: 9 additions & 7 deletions op-celestia/da_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion op-node/rollup/driver/da.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 10dff8f

Please sign in to comment.