From eba548091aff7a08a5257ff2dcbd70073cd771b1 Mon Sep 17 00:00:00 2001 From: James Date: Tue, 17 Mar 2026 12:25:22 -0400 Subject: [PATCH] refactor: preparatory generics for host context adapter --- Cargo.toml | 36 +++++++++++----------- crates/blobber/src/blobs/cache.rs | 11 +++---- crates/blobber/src/lib.rs | 2 +- crates/blobber/src/shim.rs | 14 +++++---- crates/block-processor/src/alias.rs | 7 +++-- crates/block-processor/src/v1/processor.rs | 14 ++++----- crates/node/src/alias.rs | 18 ++++++++--- 7 files changed, 57 insertions(+), 45 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 37398d8..1d01544 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -44,15 +44,15 @@ signet-rpc = { version = "0.16.0-rc.7", path = "crates/rpc" } init4-bin-base = { version = "0.18.0-rc.8", features = ["alloy"] } -signet-bundle = "0.16.0-rc.11" -signet-constants = "0.16.0-rc.11" -signet-evm = "0.16.0-rc.11" -signet-extract = "0.16.0-rc.11" -signet-test-utils = "0.16.0-rc.11" -signet-tx-cache = "0.16.0-rc.11" -signet-types = "0.16.0-rc.11" -signet-zenith = "0.16.0-rc.11" -signet-journal = "0.16.0-rc.11" +signet-bundle = "0.16.0-rc.14" +signet-constants = "0.16.0-rc.14" +signet-evm = "0.16.0-rc.14" +signet-extract = "0.16.0-rc.14" +signet-test-utils = "0.16.0-rc.14" +signet-tx-cache = "0.16.0-rc.14" +signet-types = "0.16.0-rc.14" +signet-zenith = "0.16.0-rc.14" +signet-journal = "0.16.0-rc.14" signet-storage = "0.6.5" signet-cold = "0.6.5" signet-hot = "0.6.5" @@ -114,14 +114,14 @@ url = "2.5.4" tempfile = "3.17.0" [patch.crates-io] -# signet-bundle = { path = "../sdk/crates/bundle"} -# signet-constants = { path = "../sdk/crates/constants"} -# signet-evm = { path = "../sdk/crates/evm"} -# signet-extract = { path = "../sdk/crates/extract"} -# signet-journal = { path = "../sdk/crates/journal"} -# signet-test-utils = { path = "../sdk/crates/test-utils"} -# signet-tx-cache = { path = "../sdk/crates/tx-cache"} -# signet-types = { path = "../sdk/crates/types"} -# signet-zenith = { path = "../sdk/crates/zenith"} +signet-bundle = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} +signet-constants = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} +signet-evm = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} +signet-extract = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} +signet-journal = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} +signet-test-utils = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} +signet-tx-cache = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} +signet-types = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} +signet-zenith = { git = "https://github.com/init4tech/signet-sdk.git", branch = "feat/extractable-metadata"} # init4-bin-base = { path = "../shared" } diff --git a/crates/blobber/src/blobs/cache.rs b/crates/blobber/src/blobs/cache.rs index 81c67f9..96b9e96 100644 --- a/crates/blobber/src/blobs/cache.rs +++ b/crates/blobber/src/blobs/cache.rs @@ -4,8 +4,7 @@ use alloy::eips::eip7691::MAX_BLOBS_PER_BLOCK_ELECTRA; use alloy::eips::merge::EPOCH_SLOTS; use alloy::primitives::{B256, Bytes, keccak256}; use core::fmt; -use reth::transaction_pool::TransactionPool; -use reth::{network::cache::LruMap, primitives::Receipt}; +use reth::{network::cache::LruMap, transaction_pool::TransactionPool}; use signet_extract::ExtractedEvent; use signet_zenith::Zenith::BlockSubmitted; use signet_zenith::ZenithBlock; @@ -75,10 +74,10 @@ impl CacheHandle { /// Fetch the blobs using [`Self::fetch_blobs`] and decode them to get the /// Zenith block data using the provided coder. - pub async fn fetch_and_decode( + pub async fn fetch_and_decode( &self, slot: usize, - extract: &ExtractedEvent<'_, Receipt, BlockSubmitted>, + extract: &ExtractedEvent<'_, R, BlockSubmitted>, ) -> BlobberResult where Coder: SidecarCoder + Default, @@ -116,11 +115,11 @@ impl CacheHandle { /// decoded (e.g., due to a malformatted blob). /// - `Err(FetchError)` if there was an unrecoverable error fetching the /// blobs. - pub async fn signet_block( + pub async fn signet_block( &self, host_block_number: u64, slot: usize, - extract: &ExtractedEvent<'_, Receipt, BlockSubmitted>, + extract: &ExtractedEvent<'_, R, BlockSubmitted>, ) -> FetchResult where Coder: SidecarCoder + Default, diff --git a/crates/blobber/src/lib.rs b/crates/blobber/src/lib.rs index ef6dcca..511d4ff 100644 --- a/crates/blobber/src/lib.rs +++ b/crates/blobber/src/lib.rs @@ -24,7 +24,7 @@ mod error; pub use error::{BlobberError, BlobberResult}; mod shim; -pub use shim::ExtractableChainShim; +pub use shim::{ExtractableChainShim, RecoveredBlockShim}; #[cfg(test)] mod test { diff --git a/crates/blobber/src/shim.rs b/crates/blobber/src/shim.rs index a7ac340..084ce9f 100644 --- a/crates/blobber/src/shim.rs +++ b/crates/blobber/src/shim.rs @@ -2,7 +2,7 @@ use alloy::consensus::Block; use reth::providers::Chain; -use signet_extract::{Extractable, HasTxns}; +use signet_extract::{BlockAndReceipts, Extractable, HasTxns}; use signet_types::primitives::TransactionSigned; /// A type alias for Reth's recovered block with a signed transaction. @@ -32,14 +32,16 @@ impl<'a> Extractable for ExtractableChainShim<'a> { type Block = RecoveredBlockShim; type Receipt = reth::primitives::Receipt; - fn blocks_and_receipts(&self) -> impl Iterator)> { + fn blocks_and_receipts( + &self, + ) -> impl Iterator> { self.chain.blocks_and_receipts().map(|(block, receipts)| { - // SAFETY: because the shim is repr(transparent), the memory layout - // of `RecoveredBlockShim` is the same as `RethRecovered`, so we - // can safely transmute the reference. + // SAFETY: `RecoveredBlockShim` is `#[repr(transparent)]` over a + // single `RethRecovered` field, guaranteeing identical memory + // layout. This makes the reference transmute sound. let block = unsafe { std::mem::transmute::<&'a RethRecovered, &RecoveredBlockShim>(block) }; - (block, receipts) + BlockAndReceipts { block, receipts } }) } } diff --git a/crates/block-processor/src/alias.rs b/crates/block-processor/src/alias.rs index 04e79cd..a0f84b2 100644 --- a/crates/block-processor/src/alias.rs +++ b/crates/block-processor/src/alias.rs @@ -1,15 +1,16 @@ use alloy::primitives::{Address, map::HashSet}; +use core::future::{self, Future}; use std::sync::{Arc, Mutex}; /// Simple trait to allow checking if an address should be aliased. pub trait AliasOracle { /// Returns true if the given address is an alias. - fn should_alias(&self, address: Address) -> eyre::Result; + fn should_alias(&self, address: Address) -> impl Future> + Send; } impl AliasOracle for HashSet
{ - fn should_alias(&self, address: Address) -> eyre::Result { - Ok(self.contains(&address)) + fn should_alias(&self, address: Address) -> impl Future> + Send { + future::ready(Ok(self.contains(&address))) } } diff --git a/crates/block-processor/src/v1/processor.rs b/crates/block-processor/src/v1/processor.rs index 294afdc..bbf374c 100644 --- a/crates/block-processor/src/v1/processor.rs +++ b/crates/block-processor/src/v1/processor.rs @@ -6,10 +6,10 @@ use alloy::{ use core::fmt; use eyre::{ContextCompat, WrapErr}; use init4_bin_base::utils::calc::SlotCalculator; -use signet_blobber::{CacheHandle, ExtractableChainShim}; +use signet_blobber::CacheHandle; use signet_constants::SignetSystemConstants; use signet_evm::{BlockResult, EthereumHardfork, EvmNeedsCfg, SignetDriver}; -use signet_extract::Extracts; +use signet_extract::{Extractable, Extracts}; use signet_hot::{ db::HotDbRead, model::{HotKv, HotKvRead, RevmRead}, @@ -114,9 +114,9 @@ where host_height = block_extracts.host_block.number(), has_ru_block = block_extracts.submitted.is_some(), ))] - pub async fn process_block( + pub async fn process_block( &self, - block_extracts: &Extracts<'_, ExtractableChainShim<'_>>, + block_extracts: &Extracts<'_, C>, ) -> eyre::Result { metrics::record_extracts(block_extracts); self.run_evm(block_extracts).await @@ -142,9 +142,9 @@ where /// Run the EVM for a single block extraction, returning the fully /// assembled [`ExecutedBlock`]. #[instrument(skip_all)] - async fn run_evm( + async fn run_evm( &self, - block_extracts: &Extracts<'_, ExtractableChainShim<'_>>, + block_extracts: &Extracts<'_, C>, ) -> eyre::Result { let start_time = std::time::Instant::now(); let spec_id = self.hardforks.spec_id(); @@ -186,7 +186,7 @@ where let mut to_alias: HashSet
= Default::default(); for transact in block_extracts.transacts() { let addr = transact.host_sender(); - if !to_alias.contains(&addr) && oracle.should_alias(addr)? { + if !to_alias.contains(&addr) && oracle.should_alias(addr).await? { to_alias.insert(addr); } } diff --git a/crates/node/src/alias.rs b/crates/node/src/alias.rs index 8cb1853..c682c87 100644 --- a/crates/node/src/alias.rs +++ b/crates/node/src/alias.rs @@ -1,5 +1,8 @@ use alloy::{consensus::constants::KECCAK_EMPTY, primitives::Address}; -use core::fmt; +use core::{ + fmt, + future::{self, Future}, +}; use eyre::OptionExt; use reth::providers::{StateProviderBox, StateProviderFactory}; use signet_block_processor::{AliasOracle, AliasOracleFactory}; @@ -16,9 +19,9 @@ impl fmt::Debug for RethAliasOracle { } } -impl AliasOracle for RethAliasOracle { - fn should_alias(&self, address: Address) -> eyre::Result { - // No account at this address. +impl RethAliasOracle { + /// Synchronously check whether the given address should be aliased. + fn check_alias(&self, address: Address) -> eyre::Result { let Some(acct) = self.0.basic_account(&address)? else { return Ok(false) }; // Get the bytecode hash for this account. let bch = match acct.bytecode_hash { @@ -41,6 +44,13 @@ impl AliasOracle for RethAliasOracle { } } +impl AliasOracle for RethAliasOracle { + fn should_alias(&self, address: Address) -> impl Future> + Send { + let result = self.check_alias(address); + future::ready(result) + } +} + /// An [`AliasOracleFactory`] backed by a `Box`. /// /// Creates [`RethAliasOracle`] instances from the latest host chain state.