Skip to content

Commit

Permalink
feat(derive): Use upstream alloy (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
clabby authored Apr 5, 2024
1 parent 2a4038c commit 9db7ac2
Show file tree
Hide file tree
Showing 42 changed files with 247 additions and 3,808 deletions.
147 changes: 137 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions crates/derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ homepage.workspace = true
anyhow.workspace = true

# External
alloy-primitives = { version = "0.6.3", default-features = false, features = ["rlp"] }
alloy-primitives = { version = "0.7.0", default-features = false, features = ["rlp"] }
alloy-rlp = { version = "0.3.4", default-features = false, features = ["derive"] }
alloy-sol-types = { version = "0.6.3", default-features = false }
alloy-sol-types = { version = "0.7.0", default-features = false }
alloy-consensus = { git = "https://github.com/clabby/alloy", branch = "cl/alloy-consensus-no-std", default-features = false }
alloy-eips = { git = "https://github.com/clabby/alloy", branch = "cl/alloy-consensus-no-std", default-features = false }
async-trait = "0.1.77"
hashbrown = "0.14.3"
unsigned-varint = "0.8.0"
Expand Down
77 changes: 40 additions & 37 deletions crates/derive/src/sources/blobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,17 @@
use crate::{
traits::{AsyncIterator, BlobProvider, ChainProvider},
types::{BlobData, BlockInfo, IndexedBlobHash, StageError, StageResult, TxEnvelope, TxType},
types::{BlobData, BlockInfo, IndexedBlobHash, StageError, StageResult},
};
use alloc::{boxed::Box, vec::Vec};
use alloy_consensus::TxEnvelope;
use alloy_primitives::{Address, Bytes};
use anyhow::Result;
use async_trait::async_trait;

/// A data iterator that reads from a blob.
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct BlobSource<F, B>
where
F: ChainProvider + Send,
Expand Down Expand Up @@ -56,42 +58,43 @@ where
}
}

fn extract_blob_data(&self, txs: Vec<TxEnvelope>) -> (Vec<BlobData>, Vec<IndexedBlobHash>) {
let mut index = 0;
let mut data = Vec::new();
let mut hashes = Vec::new();
for tx in txs {
if tx.to() != Some(self.batcher_address) {
index += tx.blob_hashes().map_or(0, |h| h.len());
continue;
}
if tx.from() != Some(self.signer) {
index += tx.blob_hashes().map_or(0, |h| h.len());
continue;
}
if tx.tx_type() != TxType::Eip4844 {
let calldata = tx.data().clone();
let blob_data = BlobData { data: None, calldata: Some(calldata) };
data.push(blob_data);
continue;
}
if !tx.data().is_empty() {
// TODO(refcell): Add a warning log here if the blob data is not empty
// https://github.com/ethereum-optimism/optimism/blob/develop/op-node/rollup/derive/blob_data_source.go#L136
}
let blob_hashes = if let Some(b) = tx.blob_hashes() {
b
} else {
continue;
};
for blob in blob_hashes {
let indexed = IndexedBlobHash { hash: blob, index };
hashes.push(indexed);
data.push(BlobData::default());
index += 1;
}
}
(data, hashes)
fn extract_blob_data(&self, _: Vec<TxEnvelope>) -> (Vec<BlobData>, Vec<IndexedBlobHash>) {
// let mut index = 0;
// let mut data = Vec::new();
// let mut hashes = Vec::new();
// for tx in txs {
// if tx.to() != Some(self.batcher_address) {
// index += tx.blob_hashes().map_or(0, |h| h.len());
// continue;
// }
// if tx.from() != Some(self.signer) {
// index += tx.blob_hashes().map_or(0, |h| h.len());
// continue;
// }
// if tx.tx_type() != TxType::Eip4844 {
// let calldata = tx.data().clone();
// let blob_data = BlobData { data: None, calldata: Some(calldata) };
// data.push(blob_data);
// continue;
// }
// if !tx.data().is_empty() {
// // TODO(refcell): Add a warning log here if the blob data is not empty
// // https://github.com/ethereum-optimism/optimism/blob/develop/op-node/rollup/derive/blob_data_source.go#L136
// }
// let blob_hashes = if let Some(b) = tx.blob_hashes() {
// b
// } else {
// continue;
// };
// for blob in blob_hashes {
// let indexed = IndexedBlobHash { hash: blob, index };
// hashes.push(indexed);
// data.push(BlobData::default());
// index += 1;
// }
// }
// (data, hashes)
todo!("Need ecrecover abstraction")
}

/// Loads blob data into the source if it is not open.
Expand Down
Loading

0 comments on commit 9db7ac2

Please sign in to comment.