Skip to content

Commit

Permalink
da: try fallback to blobdata else try calldata
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed Jun 7, 2024
1 parent 4c64973 commit 2572809
Showing 1 changed file with 24 additions and 17 deletions.
41 changes: 24 additions & 17 deletions op-batcher/batcher/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,10 +515,17 @@ func (l *BatchSubmitter) sendTransaction(ctx context.Context, txdata txData, que
// signal plasma commitment tx with TxDataVersion1
data = comm.TxData()
}
candidate, err = l.calldataTxCandidate(data)
candidate, err = l.celestiaTxCandidate(data)
if err != nil {
l.recordFailedTx(txdata.ID(), err)
return nil
if l.DAClient.EthFallbackDisabled {
return fmt.Errorf("celestia: blob submission failed; eth fallback disabled: %w", err)
}
l.Log.Info("celestia: blob submission failed; using 4844 fallback", "err", err)
candidate, err = l.blobTxCandidate(txdata)
if err != nil {
l.Log.Info("celestia: building blob tx failed; using calldata fallback", "err", err)
candidate = l.calldataTxCandidate(data)
}
}
}

Expand Down Expand Up @@ -550,25 +557,25 @@ func (l *BatchSubmitter) blobTxCandidate(data txData) (*txmgr.TxCandidate, error
}, nil
}

func (l *BatchSubmitter) calldataTxCandidate(data []byte) (*txmgr.TxCandidate, error) {
func (l *BatchSubmitter) calldataTxCandidate(data []byte) *txmgr.TxCandidate {
l.Log.Info("building Calldata transaction candidate", "size", len(data))
return &txmgr.TxCandidate{
To: &l.RollupConfig.BatchInboxAddress,
TxData: data,
}
}

func (l *BatchSubmitter) celestiaTxCandidate(data []byte) (*txmgr.TxCandidate, error) {
l.Log.Info("building Celestia 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)
cancel()
if err == nil && len(ids) == 1 {
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)
if err != nil {
return nil, err
}
return &txmgr.TxCandidate{
To: &l.RollupConfig.BatchInboxAddress,
TxData: data,
}, nil
l.Log.Info("celestia: blob successfully submitted", "id", hex.EncodeToString(ids[0]))
data = append([]byte{celestia.DerivationVersionCelestia}, ids[0]...)
return l.calldataTxCandidate(data), nil
}

func (l *BatchSubmitter) handleReceipt(r txmgr.TxReceipt[txID]) {
Expand Down

0 comments on commit 2572809

Please sign in to comment.