Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ tokio-util = "0.7.13"
tower-http = { version = "0.6.2", features = ["cors"] }
tracing.workspace = true
serde_json.workspace = true
futures-util = "0.3.31"

[dev-dependencies]
signet-zenith.workspace = true
Expand Down
55 changes: 55 additions & 0 deletions crates/rpc/src/ctx/fee_hist.rs
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
use reth::{
core::primitives::SealedBlock,
primitives::{Block, RecoveredBlock},
providers::{CanonStateNotification, Chain},
};
use signet_types::MagicSig;
use std::sync::Arc;

/// Removes Signet system transactions from the block.
fn strip_block(block: RecoveredBlock<Block>) -> RecoveredBlock<Block> {
let (sealed, senders) = block.split_sealed();
let (header, mut body) = sealed.split_sealed_header_body();

// This is the index of the first transaction that has a system magic
// signature.
let sys_index = body
.transactions
.partition_point(|tx| MagicSig::try_from_signature(tx.signature()).is_some());

body.transactions.truncate(sys_index);

let sealed = SealedBlock::from_sealed_parts(header, body);
RecoveredBlock::new_sealed(sealed, senders)
}

/// Removes Signet system transactions from the chain. This function uses
/// `Arc::make_mut` to clone the contents of the Arc and modify the new
/// instance.
fn strip_chain(chain: &mut Arc<Chain>) {
let chain = Arc::make_mut(chain);

let (blocks, outcome, trie) = std::mem::take(chain).into_inner();
let blocks = blocks.into_blocks().map(strip_block);

*chain = Chain::new(blocks, outcome, trie);
}

/// Strips Signet system transactions from the `CanonStateNotification`.
pub(crate) fn strip_signet_system_txns(notif: CanonStateNotification) -> CanonStateNotification {
// Cloning here ensures that the `make_mut` invocations in
// `strip_chain` do not ever modify the original `notif` object.
let _c = notif.clone();

match notif {
CanonStateNotification::Commit { mut new } => {
strip_chain(&mut new);
CanonStateNotification::Commit { new }
}
CanonStateNotification::Reorg { mut old, mut new } => {
strip_chain(&mut old);
strip_chain(&mut new);

CanonStateNotification::Reorg { old, new }
}
}
}
1 change: 1 addition & 0 deletions crates/rpc/src/ctx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ mod full;
pub use full::RpcCtx;

mod fee_hist;
pub(crate) use fee_hist::strip_signet_system_txns;

/// Type alias for EVMs using a [`StateProviderBox`] as the `DB` type for
/// trevm.
Expand Down
7 changes: 6 additions & 1 deletion crates/rpc/src/ctx/signet.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{
RuRevmState,
ctx::strip_signet_system_txns,
eth::EthError,
interest::{ActiveFilter, FilterManager, FilterOutput, SubscriptionManager},
receipts::build_signet_receipt,
Expand All @@ -12,6 +13,7 @@ use alloy::{
primitives::{B256, U64},
rpc::types::{FeeHistory, Filter, Log},
};
use futures_util::StreamExt;
use reth::{
core::primitives::SignerRecoverable,
primitives::{Block, Receipt, Recovered, RecoveredBlock, TransactionSigned},
Expand Down Expand Up @@ -106,11 +108,14 @@ where
let cache = EthStateCache::spawn_with(provider.clone(), eth_config.cache, spawner.clone());
let gas_oracle =
GasPriceOracle::new(provider.clone(), eth_config.gas_oracle, cache.clone());

let fee_history = FeeHistoryCache::new(eth_config.fee_history_cache);

// The fee task pre-calculates and caches common percentiles for the
// `eth_feeHistory` RPC method.
let fee_task = fee_history_cache_new_blocks_task(
fee_history.clone(),
provider.canonical_state_stream(),
provider.canonical_state_stream().map(strip_signet_system_txns),
provider.clone(),
cache.clone(),
);
Expand Down