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
30 changes: 15 additions & 15 deletions crates/node-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
#![deny(unused_must_use, rust_2018_idioms)]
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]

mod utils;
pub use utils::{NodeTypesDbTrait, Pnt};

use reth::{
primitives::EthPrimitives,
providers::{
Expand Down Expand Up @@ -96,21 +99,6 @@ where
type DB = Db;
}

/// Convenience trait to aggregate the DB requirements
pub trait NodeTypesDbTrait:
reth_db::database::Database + reth_db::database_metrics::DatabaseMetrics + Clone + Unpin + 'static
{
}

impl<T> NodeTypesDbTrait for T where
T: reth_db::database::Database
+ reth_db::database_metrics::DatabaseMetrics
+ Clone
+ Unpin
+ 'static
{
}

/// Shim to impl [`CanonStateSubscriptions`]
#[derive(Debug, Clone)]
pub struct SharedCanonState<Db> {
Expand Down Expand Up @@ -172,3 +160,15 @@ where
self.sender.subscribe()
}
}

#[cfg(test)]
mod test {
use super::*;

#[allow(dead_code)]
fn compile_check() {
fn inner<P: Pnt>() {}

inner::<SignetNodeTypes<std::sync::Arc<reth_db::mdbx::DatabaseEnv>>>();
}
}
36 changes: 36 additions & 0 deletions crates/node-types/src/utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use reth::{primitives::EthPrimitives, providers::providers::ProviderNodeTypes};
use reth_chainspec::ChainSpec;
use reth_db::mdbx;
use std::sync::Arc;

/// Convenience trait for specifying the [`ProviderNodeTypes`] implementation
/// required for Signet functionality. This is used to condense many trait
/// bounds.
pub trait Pnt:
ProviderNodeTypes<ChainSpec = ChainSpec, Primitives = EthPrimitives, DB = Arc<mdbx::DatabaseEnv>>
{
}

impl<T> Pnt for T where
T: ProviderNodeTypes<
ChainSpec = ChainSpec,
Primitives = EthPrimitives,
DB = Arc<mdbx::DatabaseEnv>,
>
{
}

/// Convenience trait to aggregate the DB requirements
pub trait NodeTypesDbTrait:
reth_db::database::Database + reth_db::database_metrics::DatabaseMetrics + Clone + Unpin + 'static
{
}

impl<T> NodeTypesDbTrait for T where
T: reth_db::database::Database
+ reth_db::database_metrics::DatabaseMetrics
+ Clone
+ Unpin
+ 'static
{
}
7 changes: 6 additions & 1 deletion crates/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ homepage.workspace = true
repository.workspace = true

[dependencies]
signet-node-types.workspace = true

signet-bundle.workspace = true
signet-evm.workspace = true
signet-types.workspace = true
signet-tx-cache.workspace = true
signet-types.workspace = true

ajj.workspace = true
trevm.workspace = true

alloy.workspace = true
reth.workspace = true
reth-chainspec.workspace = true
reth-db.workspace = true
reth-db-common.workspace = true
reth-evm-ethereum.workspace = true
reth-node-api.workspace = true
reth-rpc-eth-api.workspace = true
Expand All @@ -35,6 +39,7 @@ tokio = { workspace = true, features = ["macros"] }
tokio-util = "0.7.13"
tower-http = { version = "0.6.2", features = ["cors"] }
tracing.workspace = true
serde_json.workspace = true

[dev-dependencies]
signet-zenith.workspace = true
Expand Down
3 changes: 1 addition & 2 deletions crates/rpc/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::utils::{serve_axum, serve_ipc, serve_ws};
use ajj::{Router, pubsub::ServerShutdown};
use reth::{args::RpcServerArgs, tasks::TaskExecutor};
use std::net::SocketAddr;
use tokio::task::JoinHandle;

use crate::util::{serve_axum, serve_ipc, serve_ws};

/// Guard to shutdown the RPC servers. When dropped, this will shutdown all
/// running servers
#[derive(Default)]
Expand Down
47 changes: 27 additions & 20 deletions crates/rpc/src/ctx.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
use crate::{
Pnt,
eth::EthError,
interest::{ActiveFilter, FilterManager, FilterOutput, SubscriptionManager},
receipts::build_signet_receipt,
util::BlockRangeInclusiveIter,
utils::BlockRangeInclusiveIter,
};
use alloy::{
consensus::{BlockHeader, Header, Signed, Transaction, TxEnvelope},
Expand All @@ -14,12 +13,11 @@ use alloy::{
};
use reth::{
core::primitives::SignerRecoverable,
primitives::{Block, EthPrimitives, Receipt, Recovered, RecoveredBlock, TransactionSigned},
primitives::{Block, Receipt, Recovered, RecoveredBlock, TransactionSigned},
providers::{
BlockHashReader, BlockIdReader, BlockNumReader, CanonStateSubscriptions, HeaderProvider,
ProviderBlock, ProviderError, ProviderReceipt, ReceiptProvider, StateProviderFactory,
TransactionsProvider,
providers::{BlockchainProvider, ProviderNodeTypes},
ProviderBlock, ProviderError, ProviderFactory, ProviderReceipt, ProviderResult,
ReceiptProvider, StateProviderFactory, TransactionsProvider, providers::BlockchainProvider,
},
revm::{database::StateProviderDatabase, primitives::hardfork::SpecId},
rpc::{
Expand All @@ -40,6 +38,7 @@ use reth_chainspec::{BaseFeeParams, ChainSpec, ChainSpecProvider};
use reth_node_api::{BlockBody, FullNodeComponents};
use reth_rpc_eth_api::{RpcBlock, RpcConvert, RpcReceipt, RpcTransaction};
use signet_evm::EvmNeedsTx;
use signet_node_types::Pnt;
use signet_tx_cache::client::TxCache;
use signet_types::{MagicSig, constants::SignetSystemConstants};
use std::{marker::PhantomData, sync::Arc};
Expand Down Expand Up @@ -80,17 +79,16 @@ where
pub fn new<Tasks>(
host: Host,
constants: SignetSystemConstants,
provider: BlockchainProvider<Signet>,
factory: ProviderFactory<Signet>,
eth_config: EthConfig,
tx_cache: Option<TxCache>,
spawner: Tasks,
) -> Self
) -> ProviderResult<Self>
where
Tasks: TaskSpawner + Clone + 'static,
{
let inner = RpcCtxInner::new(host, constants, provider, eth_config, tx_cache, spawner);

Self { inner: Arc::new(inner) }
RpcCtxInner::new(host, constants, factory, eth_config, tx_cache, spawner)
.map(|inner| Self { inner: Arc::new(inner) })
}
}

Expand Down Expand Up @@ -136,16 +134,16 @@ where
pub fn new<Tasks>(
host: Host,
constants: SignetSystemConstants,
provider: BlockchainProvider<Signet>,
factory: ProviderFactory<Signet>,
eth_config: EthConfig,
tx_cache: Option<TxCache>,
spawner: Tasks,
) -> Self
) -> ProviderResult<Self>
where
Tasks: TaskSpawner + Clone + 'static,
{
let signet = SignetCtx::new(constants, provider, eth_config, tx_cache, spawner);
Self { host, signet }
SignetCtx::new(constants, factory, eth_config, tx_cache, spawner)
.map(|signet| Self { host, signet })
}

pub const fn host(&self) -> &Host {
Expand Down Expand Up @@ -194,6 +192,7 @@ where
eth_config: EthConfig,

// State stuff
factory: ProviderFactory<Inner>,
provider: BlockchainProvider<Inner>,
cache: EthStateCache<
ProviderBlock<BlockchainProvider<Inner>>,
Expand All @@ -217,20 +216,22 @@ where

impl<Inner> SignetCtx<Inner>
where
Inner: ProviderNodeTypes<ChainSpec = ChainSpec, Primitives = EthPrimitives>,
Inner: Pnt,
{
/// Instantiate a new `SignetCtx`, spawning necessary tasks to keep the
/// relevant caches up to date.
pub fn new<Tasks>(
constants: SignetSystemConstants,
provider: BlockchainProvider<Inner>,
factory: ProviderFactory<Inner>,
eth_config: EthConfig,
tx_cache: Option<TxCache>,
spawner: Tasks,
) -> Self
) -> ProviderResult<Self>
where
Tasks: TaskSpawner + Clone + 'static,
{
let provider = BlockchainProvider::new(factory.clone())?;

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());
Expand All @@ -249,8 +250,9 @@ where

let subs = SubscriptionManager::new(provider.clone(), eth_config.stale_filter_ttl);

Self {
Ok(Self {
constants,
factory,
provider,
eth_config,
cache,
Expand All @@ -260,14 +262,19 @@ where
filters,
subs,
_pd: PhantomData,
}
})
}

/// Access the signet constants
pub const fn constants(&self) -> &SignetSystemConstants {
&self.constants
}

/// Access the signet [`ProviderFactory`].
pub const fn factory(&self) -> &ProviderFactory<Inner> {
&self.factory
}

/// Access the signet DB
pub const fn provider(&self) -> &BlockchainProvider<Inner> {
&self.provider
Expand Down
4 changes: 2 additions & 2 deletions crates/rpc/src/eth/endpoints.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::{
Pnt,
ctx::RpcCtx,
eth::{CallErrorData, EthError},
interest::{FilterOutput, InterestKind},
receipts::build_signet_receipt,
util::{await_jh_option, await_jh_option_response, response_tri},
utils::{await_jh_option, await_jh_option_response, response_tri},
};
use ajj::{HandlerCtx, ResponsePayload};
use alloy::{
Expand All @@ -28,6 +27,7 @@ use reth_node_api::FullNodeComponents;
use reth_rpc_eth_api::{RpcBlock, RpcHeader, RpcReceipt, RpcTransaction};
use serde::Deserialize;
use signet_evm::EvmErrored;
use signet_node_types::Pnt;
use std::borrow::Cow;
use tracing::{Instrument, debug, trace_span};
use trevm::revm::context::result::ExecutionResult;
Expand Down
3 changes: 2 additions & 1 deletion crates/rpc/src/eth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ pub use error::EthError;
mod helpers;
pub use helpers::CallErrorData;

use crate::{Pnt, ctx::RpcCtx};
use crate::ctx::RpcCtx;
use alloy::{eips::BlockNumberOrTag, primitives::B256};
use reth_node_api::FullNodeComponents;
use signet_node_types::Pnt;

/// Instantiate the `eth` API router.
pub fn eth<Host, Signet>() -> ajj::Router<RpcCtx<Host, Signet>>
Expand Down
Loading
Loading