-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Remove the progress API from the derivation pipeline #3506
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
df9c2af
ab5d9c9
66c1b70
7d5dc38
7b59748
fe65b8a
80f2250
d33db24
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,7 +2,6 @@ package derive | |
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io" | ||
|
|
||
| "github.com/ethereum-optimism/optimism/op-node/eth" | ||
|
|
@@ -15,21 +14,60 @@ import ( | |
| // CalldataSource readers raw transactions from a given block & then filters for | ||
| // batch submitter transactions. | ||
| // This is not a stage in the pipeline, but a wrapper for another stage in the pipeline | ||
| // | ||
|
|
||
| type L1TransactionFetcher interface { | ||
| InfoAndTxsByHash(ctx context.Context, hash common.Hash) (eth.BlockInfo, types.Transactions, error) | ||
| } | ||
|
|
||
| type DataSlice []eth.Data | ||
| // CalldataSourceImpl is a fault tolerant approach to fetching data. | ||
| // The constructor will never fail & it will instead re-attempt the fetcher | ||
| // at a later point. | ||
| // This API greatly simplifies some calling code. | ||
| type CalldataSourceImpl struct { | ||
| // Internal state + data | ||
| open bool | ||
| data []eth.Data | ||
| // Required to re-attempt fetching | ||
| id eth.BlockID | ||
| cfg *rollup.Config // TODO: `DataFromEVMTransactions` should probably not take the full config | ||
| fetcher L1TransactionFetcher | ||
| log log.Logger | ||
| } | ||
|
|
||
| func (ds *DataSlice) Next(ctx context.Context) (eth.Data, error) { | ||
| if len(*ds) == 0 { | ||
| func NewCalldataSourceImpl(ctx context.Context, log log.Logger, cfg *rollup.Config, fetcher L1TransactionFetcher, block eth.BlockID) *CalldataSourceImpl { | ||
| _, txs, err := fetcher.InfoAndTxsByHash(ctx, block.Hash) | ||
| if err != nil { | ||
|
Comment on lines
+38
to
+39
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There should be a difference between temporary RPC errors and persistent not-found type of errors. Creating a calldata source with no data (if it doesn't error, but just returns nothing?) may result in accidental missed data, which could become a divergence. IMHO leaving the calldata as-is, and putting it in a separate PR or reducing changes is nice, since it's not quite the same as a derivation stage. |
||
| return &CalldataSourceImpl{ | ||
| open: false, | ||
| id: block, | ||
| cfg: cfg, | ||
| fetcher: fetcher, | ||
| log: log, | ||
| } | ||
| } else { | ||
| return &CalldataSourceImpl{ | ||
| open: true, | ||
| data: DataFromEVMTransactions(cfg, txs, log.New("origin", block)), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (cs *CalldataSourceImpl) Next(ctx context.Context) (eth.Data, error) { | ||
| if !cs.open { | ||
| if _, txs, err := cs.fetcher.InfoAndTxsByHash(ctx, cs.id.Hash); err == nil { | ||
| cs.open = true | ||
| cs.data = DataFromEVMTransactions(cs.cfg, txs, log.New("origin", cs.id)) | ||
| } else { | ||
| return nil, err | ||
| } | ||
| } | ||
| if len(cs.data) == 0 { | ||
| return nil, io.EOF | ||
| } else { | ||
| data := cs.data[0] | ||
| cs.data = cs.data[1:] | ||
| return data, nil | ||
| } | ||
| out := (*ds)[0] | ||
| *ds = (*ds)[1:] | ||
| return out, nil | ||
| } | ||
|
|
||
| type CalldataSource struct { | ||
|
|
@@ -42,13 +80,8 @@ func NewCalldataSource(log log.Logger, cfg *rollup.Config, fetcher L1Transaction | |
| return &CalldataSource{log: log, cfg: cfg, fetcher: fetcher} | ||
| } | ||
|
|
||
| func (cs *CalldataSource) OpenData(ctx context.Context, id eth.BlockID) (DataIter, error) { | ||
| _, txs, err := cs.fetcher.InfoAndTxsByHash(ctx, id.Hash) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to fetch transactions: %w", err) | ||
| } | ||
| data := DataFromEVMTransactions(cs.cfg, txs, cs.log.New("origin", id)) | ||
| return (*DataSlice)(&data), nil | ||
| func (cs *CalldataSource) OpenData(ctx context.Context, id eth.BlockID) *CalldataSourceImpl { | ||
| return NewCalldataSourceImpl(ctx, cs.log, cs.cfg, cs.fetcher, id) | ||
| } | ||
|
|
||
| func DataFromEVMTransactions(config *rollup.Config, txs types.Transactions, log log.Logger) []eth.Data { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't this get stuck in an infinite loop if the block hash doesn't exist? Perhaps want to check for
ethereum.NotFoundThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea, this can. This PR serves as an example of the structure rather than being ready to go, but this specific code will need to be beefed up before being merge.