Skip to content

Commit

Permalink
op-node: gracefully retry da connection err
Browse files Browse the repository at this point in the history
  • Loading branch information
tuxcanfly committed May 15, 2023
1 parent b0519b4 commit d0280e1
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 14 deletions.
45 changes: 32 additions & 13 deletions op-node/rollup/derive/calldata_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,20 @@ func NewDataSource(ctx context.Context, log log.Logger, cfg *rollup.Config, daCf
batcherAddr: batcherAddr,
}
} else {
data, err := DataFromEVMTransactions(cfg, daCfg, batcherAddr, txs, log.New("origin", block))
if err != nil {
return &DataSource{
open: false,
id: block,
cfg: cfg,
fetcher: fetcher,
log: log,
batcherAddr: batcherAddr,
}
}
return &DataSource{
open: true,
data: DataFromEVMTransactions(cfg, daCfg, batcherAddr, txs, log.New("origin", block)),
data: data,
}
}
}
Expand All @@ -89,7 +100,10 @@ func (ds *DataSource) Next(ctx context.Context) (eth.Data, error) {
if !ds.open {
if _, txs, err := ds.fetcher.InfoAndTxsByHash(ctx, ds.id.Hash); err == nil {
ds.open = true
ds.data = DataFromEVMTransactions(ds.cfg, ds.daCfg, ds.batcherAddr, txs, log.New("origin", ds.id))
ds.data, err = DataFromEVMTransactions(ds.cfg, ds.daCfg, ds.batcherAddr, txs, log.New("origin", ds.id))
if err != nil {
return nil, NewTemporaryError(fmt.Errorf("failed to open calldata source: %w", err))
}
} else if errors.Is(err, ethereum.NotFound) {
return nil, NewResetError(fmt.Errorf("failed to open calldata source: %w", err))
} else {
Expand All @@ -108,7 +122,7 @@ func (ds *DataSource) Next(ctx context.Context) (eth.Data, error) {
// DataFromEVMTransactions filters all of the transactions and returns the calldata from transactions
// that are sent to the batch inbox address from the batch sender address.
// This will return an empty array if no valid transactions are found.
func DataFromEVMTransactions(config *rollup.Config, daCfg *rollup.DAConfig, batcherAddr common.Address, txs types.Transactions, log log.Logger) []eth.Data {
func DataFromEVMTransactions(config *rollup.Config, daCfg *rollup.DAConfig, batcherAddr common.Address, txs types.Transactions, log log.Logger) ([]eth.Data, error) {
var out []eth.Data
l1Signer := config.L1Signer()
for j, tx := range txs {
Expand All @@ -124,19 +138,24 @@ func DataFromEVMTransactions(config *rollup.Config, daCfg *rollup.DAConfig, batc
continue // not an authorized batch submitter, ignore
}

height, index, err := decodeETHData(tx.Data())
if err != nil {
log.Warn("unable to decode data pointer", "index", j, "err", err)
continue
}
data, err := daCfg.Client.NamespacedData(context.Background(), daCfg.NamespaceId, uint64(height))
if err != nil {
log.Warn("unable to retrieve data from da", "err", err)
if daCfg != nil {
height, index, err := decodeETHData(tx.Data())
if err != nil {
log.Warn("unable to decode data pointer", "index", j, "err", err)
continue
}
data, err := daCfg.Client.NamespacedData(context.Background(), daCfg.NamespaceId, uint64(height))
if err != nil {
log.Warn("unable to retrieve data from da", "err", err)
return nil, err
}
out = append(out, data[index])
} else {
out = append(out, tx.Data())
}
out = append(out, data[index])
}
}
return out
return out, nil
}

// decodeETHData will decode the data retrieved from the EVM, this data
Expand Down
3 changes: 2 additions & 1 deletion op-node/rollup/derive/calldata_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,9 @@ func TestDataFromEVMTransactions(t *testing.T) {
}
}

out := DataFromEVMTransactions(cfg, batcherAddr, txs, testlog.Logger(t, log.LvlCrit))
out, err := DataFromEVMTransactions(cfg, nil, batcherAddr, txs, testlog.Logger(t, log.LvlCrit))
require.ElementsMatch(t, expectedData, out)
require.NoError(t, err)
}

}

0 comments on commit d0280e1

Please sign in to comment.