Skip to content

Commit 4269edf

Browse files
committed
feat: hazmat router
lint: clippy refactor: move PNT down
1 parent b7310f3 commit 4269edf

File tree

16 files changed

+328
-60
lines changed

16 files changed

+328
-60
lines changed

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ signet-tx-cache = { git = "https://github.com/init4tech/signet-sdk", tag = "v0.8
4949
signet-types = { git = "https://github.com/init4tech/signet-sdk", tag = "v0.8.4" }
5050
signet-zenith = { git = "https://github.com/init4tech/signet-sdk", tag = "v0.8.4" }
5151

52-
5352
# ajj
5453
ajj = { version = "0.3.4" }
5554

crates/node-types/src/lib.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
#![deny(unused_must_use, rust_2018_idioms)]
1212
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
1313

14+
mod utils;
15+
pub use utils::{NodeTypesDbTrait, Pnt};
16+
1417
use reth::{
1518
primitives::EthPrimitives,
1619
providers::{
@@ -96,21 +99,6 @@ where
9699
type DB = Db;
97100
}
98101

99-
/// Convenience trait to aggregate the DB requirements
100-
pub trait NodeTypesDbTrait:
101-
reth_db::database::Database + reth_db::database_metrics::DatabaseMetrics + Clone + Unpin + 'static
102-
{
103-
}
104-
105-
impl<T> NodeTypesDbTrait for T where
106-
T: reth_db::database::Database
107-
+ reth_db::database_metrics::DatabaseMetrics
108-
+ Clone
109-
+ Unpin
110-
+ 'static
111-
{
112-
}
113-
114102
/// Shim to impl [`CanonStateSubscriptions`]
115103
#[derive(Debug, Clone)]
116104
pub struct SharedCanonState<Db> {
@@ -172,3 +160,15 @@ where
172160
self.sender.subscribe()
173161
}
174162
}
163+
164+
#[cfg(test)]
165+
mod test {
166+
use super::*;
167+
168+
#[allow(dead_code)]
169+
fn compile_check() {
170+
fn inner<P: Pnt>() {}
171+
172+
inner::<SignetNodeTypes<std::sync::Arc<reth_db::mdbx::DatabaseEnv>>>();
173+
}
174+
}

crates/node-types/src/utils.rs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
use reth::{primitives::EthPrimitives, providers::providers::ProviderNodeTypes};
2+
use reth_chainspec::ChainSpec;
3+
use reth_db::mdbx;
4+
use std::sync::Arc;
5+
6+
/// Convenience trait for specifying the [`ProviderNodeTypes`] implementation
7+
/// required for Signet functionality. This is used to condense many trait
8+
/// bounds.
9+
pub trait Pnt:
10+
ProviderNodeTypes<ChainSpec = ChainSpec, Primitives = EthPrimitives, DB = Arc<mdbx::DatabaseEnv>>
11+
{
12+
}
13+
14+
impl<T> Pnt for T where
15+
T: ProviderNodeTypes<
16+
ChainSpec = ChainSpec,
17+
Primitives = EthPrimitives,
18+
DB = Arc<mdbx::DatabaseEnv>,
19+
>
20+
{
21+
}
22+
23+
/// Convenience trait to aggregate the DB requirements
24+
pub trait NodeTypesDbTrait:
25+
reth_db::database::Database + reth_db::database_metrics::DatabaseMetrics + Clone + Unpin + 'static
26+
{
27+
}
28+
29+
impl<T> NodeTypesDbTrait for T where
30+
T: reth_db::database::Database
31+
+ reth_db::database_metrics::DatabaseMetrics
32+
+ Clone
33+
+ Unpin
34+
+ 'static
35+
{
36+
}

crates/rpc/Cargo.toml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,21 @@ homepage.workspace = true
99
repository.workspace = true
1010

1111
[dependencies]
12+
signet-node-types.workspace = true
13+
1214
signet-bundle.workspace = true
1315
signet-evm.workspace = true
14-
signet-types.workspace = true
1516
signet-tx-cache.workspace = true
17+
signet-types.workspace = true
1618

1719
ajj.workspace = true
1820
trevm.workspace = true
1921

2022
alloy.workspace = true
2123
reth.workspace = true
2224
reth-chainspec.workspace = true
25+
reth-db.workspace = true
26+
reth-db-common.workspace = true
2327
reth-evm-ethereum.workspace = true
2428
reth-node-api.workspace = true
2529
reth-rpc-eth-api.workspace = true
@@ -35,6 +39,7 @@ tokio = { workspace = true, features = ["macros"] }
3539
tokio-util = "0.7.13"
3640
tower-http = { version = "0.6.2", features = ["cors"] }
3741
tracing.workspace = true
42+
serde_json.workspace = true
3843

3944
[dev-dependencies]
4045
signet-zenith.workspace = true

crates/rpc/src/config.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
use crate::utils::{serve_axum, serve_ipc, serve_ws};
12
use ajj::{Router, pubsub::ServerShutdown};
23
use reth::{args::RpcServerArgs, tasks::TaskExecutor};
34
use std::net::SocketAddr;
45
use tokio::task::JoinHandle;
56

6-
use crate::util::{serve_axum, serve_ipc, serve_ws};
7-
87
/// Guard to shutdown the RPC servers. When dropped, this will shutdown all
98
/// running servers
109
#[derive(Default)]

crates/rpc/src/ctx.rs

Lines changed: 27 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
use crate::{
2-
Pnt,
32
eth::EthError,
43
interest::{ActiveFilter, FilterManager, FilterOutput, SubscriptionManager},
54
receipts::build_signet_receipt,
6-
util::BlockRangeInclusiveIter,
5+
utils::BlockRangeInclusiveIter,
76
};
87
use alloy::{
98
consensus::{BlockHeader, Header, Signed, Transaction, TxEnvelope},
@@ -14,12 +13,11 @@ use alloy::{
1413
};
1514
use reth::{
1615
core::primitives::SignerRecoverable,
17-
primitives::{Block, EthPrimitives, Receipt, Recovered, RecoveredBlock, TransactionSigned},
16+
primitives::{Block, Receipt, Recovered, RecoveredBlock, TransactionSigned},
1817
providers::{
1918
BlockHashReader, BlockIdReader, BlockNumReader, CanonStateSubscriptions, HeaderProvider,
20-
ProviderBlock, ProviderError, ProviderReceipt, ReceiptProvider, StateProviderFactory,
21-
TransactionsProvider,
22-
providers::{BlockchainProvider, ProviderNodeTypes},
19+
ProviderBlock, ProviderError, ProviderFactory, ProviderReceipt, ProviderResult,
20+
ReceiptProvider, StateProviderFactory, TransactionsProvider, providers::BlockchainProvider,
2321
},
2422
revm::{database::StateProviderDatabase, primitives::hardfork::SpecId},
2523
rpc::{
@@ -40,6 +38,7 @@ use reth_chainspec::{BaseFeeParams, ChainSpec, ChainSpecProvider};
4038
use reth_node_api::{BlockBody, FullNodeComponents};
4139
use reth_rpc_eth_api::{RpcBlock, RpcConvert, RpcReceipt, RpcTransaction};
4240
use signet_evm::EvmNeedsTx;
41+
use signet_node_types::Pnt;
4342
use signet_tx_cache::client::TxCache;
4443
use signet_types::{MagicSig, constants::SignetSystemConstants};
4544
use std::{marker::PhantomData, sync::Arc};
@@ -80,17 +79,16 @@ where
8079
pub fn new<Tasks>(
8180
host: Host,
8281
constants: SignetSystemConstants,
83-
provider: BlockchainProvider<Signet>,
82+
factory: ProviderFactory<Signet>,
8483
eth_config: EthConfig,
8584
tx_cache: Option<TxCache>,
8685
spawner: Tasks,
87-
) -> Self
86+
) -> ProviderResult<Self>
8887
where
8988
Tasks: TaskSpawner + Clone + 'static,
9089
{
91-
let inner = RpcCtxInner::new(host, constants, provider, eth_config, tx_cache, spawner);
92-
93-
Self { inner: Arc::new(inner) }
90+
RpcCtxInner::new(host, constants, factory, eth_config, tx_cache, spawner)
91+
.map(|inner| Self { inner: Arc::new(inner) })
9492
}
9593
}
9694

@@ -136,16 +134,16 @@ where
136134
pub fn new<Tasks>(
137135
host: Host,
138136
constants: SignetSystemConstants,
139-
provider: BlockchainProvider<Signet>,
137+
factory: ProviderFactory<Signet>,
140138
eth_config: EthConfig,
141139
tx_cache: Option<TxCache>,
142140
spawner: Tasks,
143-
) -> Self
141+
) -> ProviderResult<Self>
144142
where
145143
Tasks: TaskSpawner + Clone + 'static,
146144
{
147-
let signet = SignetCtx::new(constants, provider, eth_config, tx_cache, spawner);
148-
Self { host, signet }
145+
SignetCtx::new(constants, factory, eth_config, tx_cache, spawner)
146+
.map(|signet| Self { host, signet })
149147
}
150148

151149
pub const fn host(&self) -> &Host {
@@ -194,6 +192,7 @@ where
194192
eth_config: EthConfig,
195193

196194
// State stuff
195+
factory: ProviderFactory<Inner>,
197196
provider: BlockchainProvider<Inner>,
198197
cache: EthStateCache<
199198
ProviderBlock<BlockchainProvider<Inner>>,
@@ -217,20 +216,22 @@ where
217216

218217
impl<Inner> SignetCtx<Inner>
219218
where
220-
Inner: ProviderNodeTypes<ChainSpec = ChainSpec, Primitives = EthPrimitives>,
219+
Inner: Pnt,
221220
{
222221
/// Instantiate a new `SignetCtx`, spawning necessary tasks to keep the
223222
/// relevant caches up to date.
224223
pub fn new<Tasks>(
225224
constants: SignetSystemConstants,
226-
provider: BlockchainProvider<Inner>,
225+
factory: ProviderFactory<Inner>,
227226
eth_config: EthConfig,
228227
tx_cache: Option<TxCache>,
229228
spawner: Tasks,
230-
) -> Self
229+
) -> ProviderResult<Self>
231230
where
232231
Tasks: TaskSpawner + Clone + 'static,
233232
{
233+
let provider = BlockchainProvider::new(factory.clone())?;
234+
234235
let cache = EthStateCache::spawn_with(provider.clone(), eth_config.cache, spawner.clone());
235236
let gas_oracle =
236237
GasPriceOracle::new(provider.clone(), eth_config.gas_oracle, cache.clone());
@@ -249,8 +250,9 @@ where
249250

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

252-
Self {
253+
Ok(Self {
253254
constants,
255+
factory,
254256
provider,
255257
eth_config,
256258
cache,
@@ -260,14 +262,19 @@ where
260262
filters,
261263
subs,
262264
_pd: PhantomData,
263-
}
265+
})
264266
}
265267

266268
/// Access the signet constants
267269
pub const fn constants(&self) -> &SignetSystemConstants {
268270
&self.constants
269271
}
270272

273+
/// Access the signet [`ProviderFactory`].
274+
pub const fn factory(&self) -> &ProviderFactory<Inner> {
275+
&self.factory
276+
}
277+
271278
/// Access the signet DB
272279
pub const fn provider(&self) -> &BlockchainProvider<Inner> {
273280
&self.provider

crates/rpc/src/eth/endpoints.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::{
2-
Pnt,
32
ctx::RpcCtx,
43
eth::{CallErrorData, EthError},
54
interest::{FilterOutput, InterestKind},
65
receipts::build_signet_receipt,
7-
util::{await_jh_option, await_jh_option_response, response_tri},
6+
utils::{await_jh_option, await_jh_option_response, response_tri},
87
};
98
use ajj::{HandlerCtx, ResponsePayload};
109
use alloy::{
@@ -28,6 +27,7 @@ use reth_node_api::FullNodeComponents;
2827
use reth_rpc_eth_api::{RpcBlock, RpcHeader, RpcReceipt, RpcTransaction};
2928
use serde::Deserialize;
3029
use signet_evm::EvmErrored;
30+
use signet_node_types::Pnt;
3131
use std::borrow::Cow;
3232
use tracing::{Instrument, debug, trace_span};
3333
use trevm::revm::context::result::ExecutionResult;

crates/rpc/src/eth/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ pub use error::EthError;
77
mod helpers;
88
pub use helpers::CallErrorData;
99

10-
use crate::{Pnt, ctx::RpcCtx};
10+
use crate::ctx::RpcCtx;
1111
use alloy::{eips::BlockNumberOrTag, primitives::B256};
1212
use reth_node_api::FullNodeComponents;
13+
use signet_node_types::Pnt;
1314

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

0 commit comments

Comments
 (0)