Skip to content

Commit

Permalink
Use fraxda in BlobDataSource
Browse files Browse the repository at this point in the history
  • Loading branch information
0xalex88 committed Apr 17, 2024
1 parent 2091903 commit 1c01ee5
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
17 changes: 12 additions & 5 deletions op-node/rollup/derive/blob_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ func (ds *BlobDataSource) open(ctx context.Context) ([]blobOrCalldata, error) {
return nil, NewTemporaryError(fmt.Errorf("failed to open blob data source: %w", err))
}

data, hashes := dataAndHashesFromTxs(txs, &ds.dsCfg, ds.batcherAddr)
data, hashes, err := dataAndHashesFromTxs(txs, &ds.dsCfg, ds.batcherAddr)
if err != nil {
return nil, err
}

if len(hashes) == 0 {
// there are no blobs to fetch so we can return immediately
Expand Down Expand Up @@ -115,20 +118,24 @@ func (ds *BlobDataSource) open(ctx context.Context) ([]blobOrCalldata, error) {
// dataAndHashesFromTxs extracts calldata and datahashes from the input transactions and returns them. It
// creates a placeholder blobOrCalldata element for each returned blob hash that must be populated
// by fillBlobPointers after blob bodies are retrieved.
func dataAndHashesFromTxs(txs types.Transactions, config *DataSourceConfig, batcherAddr common.Address) ([]blobOrCalldata, []eth.IndexedBlobHash) {
func dataAndHashesFromTxs(txs types.Transactions, config *DataSourceConfig, batcherAddr common.Address) ([]blobOrCalldata, []eth.IndexedBlobHash, error) {
data := []blobOrCalldata{}
var hashes []eth.IndexedBlobHash
blobIndex := 0 // index of each blob in the block's blob sidecar
for _, tx := range txs {
logger := log.New("tx", tx.Hash())
// skip any non-batcher transactions
if !isValidBatchTx(tx, config.l1Signer, config.batchInboxAddress, batcherAddr) {
blobIndex += len(tx.BlobHashes())
continue
}
// handle non-blob batcher transactions by extracting their calldata
if tx.Type() != types.BlobTxType {
calldata := eth.Data(tx.Data())
data = append(data, blobOrCalldata{nil, &calldata})
calldata, err := DataFromEVMTransactions(*config, batcherAddr, types.Transactions{tx}, logger)
if err != nil {
return nil, nil, err
}
data = append(data, blobOrCalldata{nil, &calldata[0]})
continue
}
// handle blob batcher transactions by extracting their blob hashes, ignoring any calldata.
Expand All @@ -145,7 +152,7 @@ func dataAndHashesFromTxs(txs types.Transactions, config *DataSourceConfig, batc
blobIndex += 1
}
}
return data, hashes
return data, hashes, nil
}

// fillBlobPointers goes back through the data array and fills in the pointers to the fetched blob
Expand Down
15 changes: 10 additions & 5 deletions op-node/rollup/derive/blob_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ func TestDataAndHashesFromTxs(t *testing.T) {
}
calldataTx, _ := types.SignNewTx(privateKey, signer, txData)
txs := types.Transactions{calldataTx}
data, blobHashes := dataAndHashesFromTxs(txs, &config, batcherAddr)
data, blobHashes, err := dataAndHashesFromTxs(txs, &config, batcherAddr)
require.NoError(t, err)
require.Equal(t, 1, len(data))
require.Equal(t, 0, len(blobHashes))

Expand All @@ -57,22 +58,25 @@ func TestDataAndHashesFromTxs(t *testing.T) {
}
blobTx, _ := types.SignNewTx(privateKey, signer, blobTxData)
txs = types.Transactions{blobTx}
data, blobHashes = dataAndHashesFromTxs(txs, &config, batcherAddr)
data, blobHashes, err = dataAndHashesFromTxs(txs, &config, batcherAddr)
require.NoError(t, err)
require.Equal(t, 1, len(data))
require.Equal(t, 1, len(blobHashes))
require.Nil(t, data[0].calldata)

// try again with both the blob & calldata transactions and make sure both are picked up
txs = types.Transactions{blobTx, calldataTx}
data, blobHashes = dataAndHashesFromTxs(txs, &config, batcherAddr)
data, blobHashes, err = dataAndHashesFromTxs(txs, &config, batcherAddr)
require.NoError(t, err)
require.Equal(t, 2, len(data))
require.Equal(t, 1, len(blobHashes))
require.NotNil(t, data[1].calldata)

// make sure blob tx to the batch inbox is ignored if not signed by the batcher
blobTx, _ = types.SignNewTx(testutils.RandomKey(), signer, blobTxData)
txs = types.Transactions{blobTx}
data, blobHashes = dataAndHashesFromTxs(txs, &config, batcherAddr)
data, blobHashes, err = dataAndHashesFromTxs(txs, &config, batcherAddr)
require.NoError(t, err)
require.Equal(t, 0, len(data))
require.Equal(t, 0, len(blobHashes))

Expand All @@ -81,7 +85,8 @@ func TestDataAndHashesFromTxs(t *testing.T) {
blobTxData.To = testutils.RandomAddress(rng)
blobTx, _ = types.SignNewTx(privateKey, signer, blobTxData)
txs = types.Transactions{blobTx}
data, blobHashes = dataAndHashesFromTxs(txs, &config, batcherAddr)
data, blobHashes, err = dataAndHashesFromTxs(txs, &config, batcherAddr)
require.NoError(t, err)
require.Equal(t, 0, len(data))
require.Equal(t, 0, len(blobHashes))
}
Expand Down

0 comments on commit 1c01ee5

Please sign in to comment.