Skip to content

Commit ccfa991

Browse files
committed
refactor: preparatory generics for host context adapter
1 parent feb895e commit ccfa991

16 files changed

Lines changed: 127 additions & 1068 deletions

File tree

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
.DS_Store
33
Cargo.lock
44
.idea/
5-
docs/superpowers/

Cargo.toml

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ signet-rpc = { version = "0.16.0-rc.7", path = "crates/rpc" }
4444

4545
init4-bin-base = { version = "0.18.0-rc.8", features = ["alloy"] }
4646

47-
signet-bundle = "0.16.0-rc.11"
48-
signet-constants = "0.16.0-rc.11"
49-
signet-evm = "0.16.0-rc.11"
50-
signet-extract = "0.16.0-rc.11"
51-
signet-test-utils = "0.16.0-rc.11"
52-
signet-tx-cache = "0.16.0-rc.11"
53-
signet-types = "0.16.0-rc.11"
54-
signet-zenith = "0.16.0-rc.11"
55-
signet-journal = "0.16.0-rc.11"
47+
signet-bundle = "0.16.0-rc.14"
48+
signet-constants = "0.16.0-rc.14"
49+
signet-evm = "0.16.0-rc.14"
50+
signet-extract = "0.16.0-rc.14"
51+
signet-test-utils = "0.16.0-rc.14"
52+
signet-tx-cache = "0.16.0-rc.14"
53+
signet-types = "0.16.0-rc.14"
54+
signet-zenith = "0.16.0-rc.14"
55+
signet-journal = "0.16.0-rc.14"
5656
signet-storage = "0.6.5"
5757
signet-cold = "0.6.5"
5858
signet-hot = "0.6.5"
@@ -114,14 +114,14 @@ url = "2.5.4"
114114
tempfile = "3.17.0"
115115

116116
[patch.crates-io]
117-
# signet-bundle = { path = "../sdk/crates/bundle"}
118-
# signet-constants = { path = "../sdk/crates/constants"}
119-
# signet-evm = { path = "../sdk/crates/evm"}
120-
# signet-extract = { path = "../sdk/crates/extract"}
121-
# signet-journal = { path = "../sdk/crates/journal"}
122-
# signet-test-utils = { path = "../sdk/crates/test-utils"}
123-
# signet-tx-cache = { path = "../sdk/crates/tx-cache"}
124-
# signet-types = { path = "../sdk/crates/types"}
125-
# signet-zenith = { path = "../sdk/crates/zenith"}
117+
signet-bundle = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
118+
signet-constants = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
119+
signet-evm = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
120+
signet-extract = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
121+
signet-journal = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
122+
signet-test-utils = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
123+
signet-tx-cache = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
124+
signet-types = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
125+
signet-zenith = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"}
126126

127127
# init4-bin-base = { path = "../shared" }

crates/blobber/src/blobs/cache.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use alloy::eips::eip7691::MAX_BLOBS_PER_BLOCK_ELECTRA;
44
use alloy::eips::merge::EPOCH_SLOTS;
55
use alloy::primitives::{B256, Bytes, keccak256};
66
use core::fmt;
7-
use reth::transaction_pool::TransactionPool;
8-
use reth::{network::cache::LruMap, primitives::Receipt};
7+
use reth::{network::cache::LruMap, transaction_pool::TransactionPool};
98
use signet_extract::ExtractedEvent;
109
use signet_zenith::Zenith::BlockSubmitted;
1110
use signet_zenith::ZenithBlock;
@@ -75,10 +74,10 @@ impl<Coder> CacheHandle<Coder> {
7574

7675
/// Fetch the blobs using [`Self::fetch_blobs`] and decode them to get the
7776
/// Zenith block data using the provided coder.
78-
pub async fn fetch_and_decode(
77+
pub async fn fetch_and_decode<R>(
7978
&self,
8079
slot: usize,
81-
extract: &ExtractedEvent<'_, Receipt, BlockSubmitted>,
80+
extract: &ExtractedEvent<'_, R, BlockSubmitted>,
8281
) -> BlobberResult<Bytes>
8382
where
8483
Coder: SidecarCoder + Default,
@@ -116,11 +115,11 @@ impl<Coder> CacheHandle<Coder> {
116115
/// decoded (e.g., due to a malformatted blob).
117116
/// - `Err(FetchError)` if there was an unrecoverable error fetching the
118117
/// blobs.
119-
pub async fn signet_block(
118+
pub async fn signet_block<R>(
120119
&self,
121120
host_block_number: u64,
122121
slot: usize,
123-
extract: &ExtractedEvent<'_, Receipt, BlockSubmitted>,
122+
extract: &ExtractedEvent<'_, R, BlockSubmitted>,
124123
) -> FetchResult<ZenithBlock>
125124
where
126125
Coder: SidecarCoder + Default,

crates/blobber/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ mod error;
2424
pub use error::{BlobberError, BlobberResult};
2525

2626
mod shim;
27-
pub use shim::ExtractableChainShim;
27+
pub use shim::{ExtractableChainShim, RecoveredBlockShim};
2828

2929
#[cfg(test)]
3030
mod test {

crates/blobber/src/shim.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use alloy::consensus::Block;
44
use reth::providers::Chain;
5-
use signet_extract::{Extractable, HasTxns};
5+
use signet_extract::{BlockAndReceipts, Extractable, HasTxns};
66
use signet_types::primitives::TransactionSigned;
77

88
/// A type alias for Reth's recovered block with a signed transaction.
@@ -32,14 +32,16 @@ impl<'a> Extractable for ExtractableChainShim<'a> {
3232
type Block = RecoveredBlockShim;
3333
type Receipt = reth::primitives::Receipt;
3434

35-
fn blocks_and_receipts(&self) -> impl Iterator<Item = (&Self::Block, &Vec<Self::Receipt>)> {
35+
fn blocks_and_receipts(
36+
&self,
37+
) -> impl Iterator<Item = BlockAndReceipts<'_, Self::Block, Self::Receipt>> {
3638
self.chain.blocks_and_receipts().map(|(block, receipts)| {
37-
// SAFETY: because the shim is repr(transparent), the memory layout
38-
// of `RecoveredBlockShim` is the same as `RethRecovered`, so we
39-
// can safely transmute the reference.
39+
// SAFETY: `RecoveredBlockShim` is `#[repr(transparent)]` over a
40+
// single `RethRecovered` field, guaranteeing identical memory
41+
// layout. This makes the reference transmute sound.
4042
let block =
4143
unsafe { std::mem::transmute::<&'a RethRecovered, &RecoveredBlockShim>(block) };
42-
(block, receipts)
44+
BlockAndReceipts { block, receipts }
4345
})
4446
}
4547
}

crates/block-processor/src/alias.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
use alloy::primitives::{Address, map::HashSet};
2+
use core::future::{self, Future};
23
use std::sync::{Arc, Mutex};
34

45
/// Simple trait to allow checking if an address should be aliased.
56
pub trait AliasOracle {
67
/// Returns true if the given address is an alias.
7-
fn should_alias(&self, address: Address) -> eyre::Result<bool>;
8+
fn should_alias(&self, address: Address) -> impl Future<Output = eyre::Result<bool>> + Send;
89
}
910

1011
impl AliasOracle for HashSet<Address> {
11-
fn should_alias(&self, address: Address) -> eyre::Result<bool> {
12-
Ok(self.contains(&address))
12+
fn should_alias(&self, address: Address) -> impl Future<Output = eyre::Result<bool>> + Send {
13+
future::ready(Ok(self.contains(&address)))
1314
}
1415
}
1516

crates/block-processor/src/v1/processor.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ use alloy::{
66
use core::fmt;
77
use eyre::{ContextCompat, WrapErr};
88
use init4_bin_base::utils::calc::SlotCalculator;
9-
use signet_blobber::{CacheHandle, ExtractableChainShim};
9+
use signet_blobber::CacheHandle;
1010
use signet_constants::SignetSystemConstants;
1111
use signet_evm::{BlockResult, EthereumHardfork, EvmNeedsCfg, SignetDriver};
12-
use signet_extract::Extracts;
12+
use signet_extract::{Extractable, Extracts};
1313
use signet_hot::{
1414
db::HotDbRead,
1515
model::{HotKv, HotKvRead, RevmRead},
@@ -114,9 +114,9 @@ where
114114
host_height = block_extracts.host_block.number(),
115115
has_ru_block = block_extracts.submitted.is_some(),
116116
))]
117-
pub async fn process_block(
117+
pub async fn process_block<C: Extractable>(
118118
&self,
119-
block_extracts: &Extracts<'_, ExtractableChainShim<'_>>,
119+
block_extracts: &Extracts<'_, C>,
120120
) -> eyre::Result<ExecutedBlock> {
121121
metrics::record_extracts(block_extracts);
122122
self.run_evm(block_extracts).await
@@ -142,9 +142,9 @@ where
142142
/// Run the EVM for a single block extraction, returning the fully
143143
/// assembled [`ExecutedBlock`].
144144
#[instrument(skip_all)]
145-
async fn run_evm(
145+
async fn run_evm<C: Extractable>(
146146
&self,
147-
block_extracts: &Extracts<'_, ExtractableChainShim<'_>>,
147+
block_extracts: &Extracts<'_, C>,
148148
) -> eyre::Result<ExecutedBlock> {
149149
let start_time = std::time::Instant::now();
150150
let spec_id = self.hardforks.spec_id();
@@ -186,7 +186,7 @@ where
186186
let mut to_alias: HashSet<Address> = Default::default();
187187
for transact in block_extracts.transacts() {
188188
let addr = transact.host_sender();
189-
if !to_alias.contains(&addr) && oracle.should_alias(addr)? {
189+
if !to_alias.contains(&addr) && oracle.should_alias(addr).await? {
190190
to_alias.insert(addr);
191191
}
192192
}

0 commit comments

Comments
 (0)