mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
Integrate Config into admin_nodeInfo response (#7206)
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -6539,6 +6539,7 @@ dependencies = [
|
||||
name = "reth-rpc-types"
|
||||
version = "0.2.0-beta.3"
|
||||
dependencies = [
|
||||
"alloy-genesis",
|
||||
"alloy-primitives",
|
||||
"alloy-rlp",
|
||||
"alloy-rpc-engine-types",
|
||||
|
||||
@ -32,9 +32,10 @@ impl NetworkInfo for NoopNetwork {
|
||||
protocol_version: ProtocolVersion::V5 as u64,
|
||||
eth_protocol_info: EthProtocolInfo {
|
||||
difficulty: Default::default(),
|
||||
head: Default::default(),
|
||||
network: 1,
|
||||
genesis: Default::default(),
|
||||
config: Default::default(),
|
||||
head: Default::default(),
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
@ -359,6 +359,7 @@ where
|
||||
head: status.blockhash,
|
||||
network: status.chain.id(),
|
||||
genesis: status.genesis,
|
||||
config: Default::default(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -154,36 +154,22 @@
|
||||
#![cfg_attr(not(test), warn(unused_crate_dependencies))]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fmt,
|
||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
str::FromStr,
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
|
||||
use hyper::{header::AUTHORIZATION, HeaderMap};
|
||||
pub use jsonrpsee::server::ServerBuilder;
|
||||
use jsonrpsee::{
|
||||
server::{IdProvider, Server, ServerHandle},
|
||||
Methods, RpcModule,
|
||||
};
|
||||
use reth_node_api::{ConfigureEvmEnv, EngineTypes};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use strum::{AsRefStr, EnumIter, IntoStaticStr, ParseError, VariantArray, VariantNames};
|
||||
use tower::layer::util::{Identity, Stack};
|
||||
use tower_http::cors::CorsLayer;
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
use crate::{
|
||||
auth::AuthRpcModule, error::WsHttpSamePortError, metrics::RpcServerMetrics,
|
||||
RpcModuleSelection::Selection,
|
||||
};
|
||||
use constants::*;
|
||||
use error::{RpcError, ServerKind};
|
||||
use hyper::{header::AUTHORIZATION, HeaderMap};
|
||||
pub use jsonrpsee::server::ServerBuilder;
|
||||
use jsonrpsee::{
|
||||
server::{IdProvider, Server, ServerHandle},
|
||||
Methods, RpcModule,
|
||||
};
|
||||
use reth_ipc::server::IpcServer;
|
||||
pub use reth_ipc::server::{Builder as IpcServerBuilder, Endpoint};
|
||||
use reth_network_api::{noop::NoopNetwork, NetworkInfo, Peers};
|
||||
use reth_node_api::{ConfigureEvmEnv, EngineTypes};
|
||||
use reth_provider::{
|
||||
AccountReader, BlockReader, BlockReaderIdExt, CanonStateSubscriptions, ChainSpecProvider,
|
||||
ChangeSetReader, EvmEnvProvider, StateProviderFactory,
|
||||
@ -205,6 +191,19 @@ use reth_tasks::{
|
||||
TaskSpawner, TokioTaskExecutor,
|
||||
};
|
||||
use reth_transaction_pool::{noop::NoopTransactionPool, TransactionPool};
|
||||
use serde::{Deserialize, Serialize, Serializer};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
fmt,
|
||||
net::{Ipv4Addr, SocketAddr, SocketAddrV4},
|
||||
str::FromStr,
|
||||
time::{Duration, SystemTime, UNIX_EPOCH},
|
||||
};
|
||||
use strum::{AsRefStr, EnumIter, IntoStaticStr, ParseError, VariantArray, VariantNames};
|
||||
use tower::layer::util::{Identity, Stack};
|
||||
use tower_http::cors::CorsLayer;
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
// re-export for convenience
|
||||
pub use crate::eth::{EthConfig, EthHandlers};
|
||||
|
||||
@ -1015,14 +1014,14 @@ impl<Provider, Pool, Network, Tasks, Events, EvmConfig>
|
||||
}
|
||||
}
|
||||
|
||||
impl<Provider, Pool, Network, Tasks, Events, EvmConfig>
|
||||
impl<Provider: ChainSpecProvider, Pool, Network, Tasks, Events, EvmConfig>
|
||||
RethModuleRegistry<Provider, Pool, Network, Tasks, Events, EvmConfig>
|
||||
where
|
||||
Network: NetworkInfo + Peers + Clone + 'static,
|
||||
{
|
||||
/// Instantiates AdminApi
|
||||
pub fn admin_api(&mut self) -> AdminApi<Network> {
|
||||
AdminApi::new(self.network.clone())
|
||||
AdminApi::new(self.network.clone(), self.provider.chain_spec())
|
||||
}
|
||||
|
||||
/// Instantiates Web3Api
|
||||
@ -1203,7 +1202,9 @@ where
|
||||
.entry(namespace)
|
||||
.or_insert_with(|| match namespace {
|
||||
RethRpcModule::Admin => {
|
||||
AdminApi::new(self.network.clone()).into_rpc().into()
|
||||
AdminApi::new(self.network.clone(), self.provider.chain_spec())
|
||||
.into_rpc()
|
||||
.into()
|
||||
}
|
||||
RethRpcModule::Debug => DebugApi::new(
|
||||
self.provider.clone(),
|
||||
|
||||
@ -20,6 +20,7 @@ alloy-rpc-trace-types.workspace = true
|
||||
alloy-rpc-engine-types = { workspace = true, features = ["jsonrpsee-types"] }
|
||||
ethereum_ssz_derive = { version = "0.5", optional = true }
|
||||
ethereum_ssz = { version = "0.5", optional = true }
|
||||
alloy-genesis.workspace = true
|
||||
|
||||
# misc
|
||||
thiserror.workspace = true
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
use crate::{NodeRecord, PeerId};
|
||||
use alloy_genesis::ChainConfig;
|
||||
use alloy_primitives::{B256, U256};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::{
|
||||
@ -32,7 +33,7 @@ pub struct NodeInfo {
|
||||
|
||||
impl NodeInfo {
|
||||
/// Creates a new instance of `NodeInfo`.
|
||||
pub fn new(enr: NodeRecord, status: NetworkStatus) -> NodeInfo {
|
||||
pub fn new(enr: NodeRecord, status: NetworkStatus, config: ChainConfig) -> NodeInfo {
|
||||
NodeInfo {
|
||||
enode: enr,
|
||||
id: enr.id,
|
||||
@ -40,7 +41,10 @@ impl NodeInfo {
|
||||
listen_addr: enr.tcp_addr(),
|
||||
ports: Ports { discovery: enr.udp_port, listener: enr.tcp_port },
|
||||
name: status.client_version,
|
||||
protocols: Protocols { eth: status.eth_protocol_info, other: Default::default() },
|
||||
protocols: Protocols {
|
||||
eth: EthProtocolInfo::new(status.eth_protocol_info, config),
|
||||
other: Default::default(),
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -87,6 +91,21 @@ pub struct EthProtocolInfo {
|
||||
pub network: u64,
|
||||
/// Genesis block of the current chain.
|
||||
pub genesis: B256,
|
||||
/// Configuration of the chain.
|
||||
pub config: ChainConfig,
|
||||
}
|
||||
|
||||
impl EthProtocolInfo {
|
||||
/// Creates a new instance of `EthProtocolInfo`.
|
||||
pub fn new(info: EthProtocolInfo, config: ChainConfig) -> EthProtocolInfo {
|
||||
EthProtocolInfo {
|
||||
difficulty: info.difficulty,
|
||||
head: info.head,
|
||||
network: info.network,
|
||||
genesis: info.genesis,
|
||||
config,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
@ -95,7 +114,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_parse_node_info_roundtrip() {
|
||||
let sample = r#"{"enode":"enode://44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d@[::]:30303","id":"44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d","ip":"::","listenAddr":"[::]:30303","name":"reth","ports":{"discovery":30303,"listener":30303},"protocols":{"eth":{"difficulty":17334254859343145000,"genesis":"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3","head":"0xb83f73fbe6220c111136aefd27b160bf4a34085c65ba89f24246b3162257c36a","network":1}}}"#;
|
||||
let sample = r#"{"enode":"enode://44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d@[::]:30303","id":"44826a5d6a55f88a18298bca4773fca5749cdc3a5c9f308aa7d810e9b31123f3e7c5fba0b1d70aac5308426f47df2a128a6747040a3815cc7dd7167d03be320d","ip":"::","listenAddr":"[::]:30303","name":"reth","ports":{"discovery":30303,"listener":30303},"protocols":{"eth":{"difficulty":17334254859343145000,"genesis":"0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3","head":"0xb83f73fbe6220c111136aefd27b160bf4a34085c65ba89f24246b3162257c36a","network":1, "config": {"chainId": 17000,"homesteadBlock": 0,"daoForkSupport": true,"eip150Block": 0,"eip155Block": 0,"eip158Block": 0,"byzantiumBlock": 0,"constantinopleBlock": 0,"petersburgBlock": 0,"istanbulBlock": 0,"berlinBlock": 0,"londonBlock": 0,"shanghaiTime": 1696000704,"cancunTime": 1707305664,"terminalTotalDifficulty": 0,"terminalTotalDifficultyPassed": true,"ethash": {}}}}}"#;
|
||||
|
||||
let info: NodeInfo = serde_json::from_str(sample).unwrap();
|
||||
let serialized = serde_json::to_string_pretty(&info).unwrap();
|
||||
|
||||
@ -2,9 +2,10 @@ use crate::result::ToRpcResult;
|
||||
use async_trait::async_trait;
|
||||
use jsonrpsee::core::RpcResult;
|
||||
use reth_network_api::{NetworkInfo, PeerKind, Peers};
|
||||
use reth_primitives::NodeRecord;
|
||||
use reth_primitives::{ChainSpec, NodeRecord};
|
||||
use reth_rpc_api::AdminApiServer;
|
||||
use reth_rpc_types::{NodeInfo, PeerEthProtocolInfo, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// `admin` API implementation.
|
||||
///
|
||||
@ -12,12 +13,14 @@ use reth_rpc_types::{NodeInfo, PeerEthProtocolInfo, PeerInfo, PeerNetworkInfo, P
|
||||
pub struct AdminApi<N> {
|
||||
/// An interface to interact with the network
|
||||
network: N,
|
||||
/// The specification of the blockchain's configuration.
|
||||
chain_spec: Arc<ChainSpec>,
|
||||
}
|
||||
|
||||
impl<N> AdminApi<N> {
|
||||
/// Creates a new instance of `AdminApi`.
|
||||
pub fn new(network: N) -> Self {
|
||||
AdminApi { network }
|
||||
pub fn new(network: N, chain_spec: Arc<ChainSpec>) -> Self {
|
||||
AdminApi { network, chain_spec }
|
||||
}
|
||||
}
|
||||
|
||||
@ -83,8 +86,9 @@ where
|
||||
async fn node_info(&self) -> RpcResult<NodeInfo> {
|
||||
let enr = self.network.local_node_record();
|
||||
let status = self.network.network_status().await.to_rpc_result()?;
|
||||
let config = self.chain_spec.genesis().config.clone();
|
||||
|
||||
Ok(NodeInfo::new(enr, status))
|
||||
Ok(NodeInfo::new(enr, status, config))
|
||||
}
|
||||
|
||||
/// Handler for `admin_peerEvents`
|
||||
|
||||
Reference in New Issue
Block a user