mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
chore: use alloy nodeinfo (#7512)
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
use jsonrpsee::{core::RpcResult, proc_macros::rpc};
|
||||
use reth_primitives::{AnyNode, NodeRecord};
|
||||
use reth_rpc_types::{NodeInfo, PeerInfo};
|
||||
use reth_rpc_types::{admin::NodeInfo, PeerInfo};
|
||||
|
||||
/// Admin namespace rpc interface that gives access to several non-standard RPC methods.
|
||||
#[cfg_attr(not(feature = "client"), rpc(server, namespace = "admin"))]
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
use crate::transaction::from_recovered_with_block_context;
|
||||
use alloy_rlp::Encodable;
|
||||
use reth_primitives::{
|
||||
Block as PrimitiveBlock, BlockWithSenders, Header as PrimitiveHeader, B256, U256, U64,
|
||||
Block as PrimitiveBlock, BlockWithSenders, Header as PrimitiveHeader, B256, U256,
|
||||
};
|
||||
use reth_rpc_types::{Block, BlockError, BlockTransactions, BlockTransactionsKind, Header};
|
||||
|
||||
@ -127,18 +127,18 @@ pub fn from_primitive_with_hash(primitive_header: reth_primitives::SealedHeader)
|
||||
transactions_root,
|
||||
receipts_root,
|
||||
withdrawals_root,
|
||||
number: Some(U256::from(number)),
|
||||
gas_used: U256::from(gas_used),
|
||||
gas_limit: U256::from(gas_limit),
|
||||
number: Some(number),
|
||||
gas_used: gas_used as u128,
|
||||
gas_limit: gas_limit as u128,
|
||||
extra_data,
|
||||
logs_bloom,
|
||||
timestamp: U256::from(timestamp),
|
||||
timestamp,
|
||||
difficulty,
|
||||
mix_hash: Some(mix_hash),
|
||||
nonce: Some(nonce.to_be_bytes().into()),
|
||||
base_fee_per_gas: base_fee_per_gas.map(U256::from),
|
||||
blob_gas_used: blob_gas_used.map(U64::from),
|
||||
excess_blob_gas: excess_blob_gas.map(U64::from),
|
||||
base_fee_per_gas: base_fee_per_gas.map(u128::from),
|
||||
blob_gas_used: blob_gas_used.map(u128::from),
|
||||
excess_blob_gas: excess_blob_gas.map(u128::from),
|
||||
parent_beacon_block_root,
|
||||
total_difficulty: None,
|
||||
}
|
||||
|
||||
@ -8,9 +8,7 @@
|
||||
issue_tracker_base_url = "https://github.com/paradigmxyz/reth/issues/"
|
||||
)]
|
||||
#![cfg_attr(docsrs, feature(doc_cfg, doc_auto_cfg))]
|
||||
#![allow(hidden_glob_reexports)] // TODO rm in followup PR
|
||||
|
||||
mod admin;
|
||||
pub mod beacon;
|
||||
mod eth;
|
||||
mod mev;
|
||||
@ -38,7 +36,6 @@ pub use eth::{
|
||||
transaction::{self, TransactionKind, TransactionRequest, TypedTransactionRequest},
|
||||
};
|
||||
|
||||
pub use admin::*;
|
||||
pub use mev::*;
|
||||
pub use net::*;
|
||||
pub use peer::*;
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
use crate::{pk_to_id, PeerId};
|
||||
use alloy_rlp::{RlpDecodable, RlpEncodable};
|
||||
use alloy_rpc_types::admin::EthProtocolInfo;
|
||||
use enr::Enr;
|
||||
use secp256k1::{SecretKey, SECP256K1};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serde_with::{DeserializeFromStr, SerializeDisplay};
|
||||
use std::{
|
||||
fmt,
|
||||
@ -13,6 +15,17 @@ use std::{
|
||||
use thiserror::Error;
|
||||
use url::{Host, Url};
|
||||
|
||||
/// The status of the network being ran by the local node.
|
||||
#[derive(Clone, Debug, Serialize, Deserialize)]
|
||||
pub struct NetworkStatus {
|
||||
/// The local node client version.
|
||||
pub client_version: String,
|
||||
/// The current ethereum protocol version
|
||||
pub protocol_version: u64,
|
||||
/// Information about the Ethereum Wire Protocol.
|
||||
pub eth_protocol_info: EthProtocolInfo,
|
||||
}
|
||||
|
||||
/// Represents a ENR in discovery.
|
||||
///
|
||||
/// Note: this is only an excerpt of the [`NodeRecord`] data structure.
|
||||
|
||||
@ -1,10 +1,14 @@
|
||||
use crate::result::ToRpcResult;
|
||||
use alloy_primitives::B256;
|
||||
use async_trait::async_trait;
|
||||
use jsonrpsee::core::RpcResult;
|
||||
use reth_network_api::{NetworkInfo, PeerKind, Peers};
|
||||
use reth_primitives::{AnyNode, ChainSpec, NodeRecord};
|
||||
use reth_rpc_api::AdminApiServer;
|
||||
use reth_rpc_types::{NodeInfo, PeerEthProtocolInfo, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo};
|
||||
use reth_rpc_types::{
|
||||
admin::{EthProtocolInfo, NodeInfo, Ports, ProtocolInfo},
|
||||
PeerEthProtocolInfo, PeerInfo, PeerNetworkInfo, PeerProtocolsInfo,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
/// `admin` API implementation.
|
||||
@ -87,11 +91,31 @@ where
|
||||
|
||||
/// Handler for `admin_nodeInfo`
|
||||
async fn node_info(&self) -> RpcResult<NodeInfo> {
|
||||
let enr = self.network.local_node_record();
|
||||
let enode = 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, config))
|
||||
let node_info = NodeInfo {
|
||||
id: B256::from_slice(&enode.id.as_slice()[..32]),
|
||||
name: status.client_version,
|
||||
enode: enode.to_string(),
|
||||
enr: "".to_string(),
|
||||
ip: enode.address,
|
||||
ports: Ports { discovery: enode.udp_port, listener: enode.tcp_port },
|
||||
listen_addr: enode.tcp_addr(),
|
||||
protocols: ProtocolInfo {
|
||||
eth: Some(EthProtocolInfo {
|
||||
network: status.eth_protocol_info.network,
|
||||
difficulty: status.eth_protocol_info.difficulty,
|
||||
genesis: status.eth_protocol_info.genesis,
|
||||
config,
|
||||
head: status.eth_protocol_info.head,
|
||||
}),
|
||||
snap: None,
|
||||
},
|
||||
};
|
||||
|
||||
Ok(node_info)
|
||||
}
|
||||
|
||||
/// Handler for `admin_peerEvents`
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
//! Optimism helpers.
|
||||
|
||||
use reth_primitives::U256;
|
||||
use revm::L1BlockInfo;
|
||||
|
||||
/// Optimism Transaction Metadata
|
||||
@ -15,17 +14,17 @@ pub(crate) struct OptimismTxMeta {
|
||||
/// The L1 block info.
|
||||
pub(crate) l1_block_info: Option<L1BlockInfo>,
|
||||
/// The L1 fee for the block.
|
||||
pub(crate) l1_fee: Option<U256>,
|
||||
pub(crate) l1_fee: Option<u128>,
|
||||
/// The L1 data gas for the block.
|
||||
pub(crate) l1_data_gas: Option<U256>,
|
||||
pub(crate) l1_data_gas: Option<u128>,
|
||||
}
|
||||
|
||||
impl OptimismTxMeta {
|
||||
/// Creates a new [OptimismTxMeta].
|
||||
pub(crate) fn new(
|
||||
l1_block_info: Option<L1BlockInfo>,
|
||||
l1_fee: Option<U256>,
|
||||
l1_data_gas: Option<U256>,
|
||||
l1_fee: Option<u128>,
|
||||
l1_data_gas: Option<u128>,
|
||||
) -> Self {
|
||||
Self { l1_block_info, l1_fee, l1_data_gas }
|
||||
}
|
||||
|
||||
@ -1280,7 +1280,7 @@ where
|
||||
let block_hash = block.hash();
|
||||
|
||||
let block_number = block_env.number.saturating_to::<u64>();
|
||||
let base_fee = block_env.basefee.saturating_to::<u64>();
|
||||
let base_fee = block_env.basefee.saturating_to::<u128>();
|
||||
|
||||
// prepare transactions, we do everything upfront to reduce time spent with open state
|
||||
let max_transactions = highest_index.map_or(block.body.len(), |highest| {
|
||||
@ -1501,7 +1501,10 @@ where
|
||||
let inner_l1_data_gas = l1_block_info
|
||||
.l1_data_gas(&self.inner.provider.chain_spec(), block_timestamp, &envelope_buf)
|
||||
.map_err(|_| OptimismEthApiError::L1BlockGasError)?;
|
||||
(Some(inner_l1_fee), Some(inner_l1_data_gas))
|
||||
(
|
||||
Some(inner_l1_fee.saturating_to::<u128>()),
|
||||
Some(inner_l1_data_gas.saturating_to::<u128>()),
|
||||
)
|
||||
} else {
|
||||
(None, None)
|
||||
};
|
||||
@ -1629,7 +1632,7 @@ impl TransactionSource {
|
||||
index: Some(index),
|
||||
block_hash: Some(block_hash),
|
||||
block_number: Some(block_number),
|
||||
base_fee,
|
||||
base_fee: base_fee.map(u128::from),
|
||||
},
|
||||
)
|
||||
}
|
||||
@ -1718,7 +1721,7 @@ pub(crate) fn build_transaction_receipt_with_block_receipts(
|
||||
|
||||
let rpc_receipt = reth_rpc_types::Receipt {
|
||||
status: receipt.success,
|
||||
cumulative_gas_used: receipt.cumulative_gas_used,
|
||||
cumulative_gas_used: receipt.cumulative_gas_used as u128,
|
||||
logs,
|
||||
};
|
||||
|
||||
@ -1734,14 +1737,14 @@ pub(crate) fn build_transaction_receipt_with_block_receipts(
|
||||
block_number: Some(meta.block_number),
|
||||
from,
|
||||
to: None,
|
||||
gas_used: Some(gas_used),
|
||||
gas_used: gas_used as u128,
|
||||
contract_address: None,
|
||||
effective_gas_price: transaction.effective_gas_price(meta.base_fee) as u64,
|
||||
effective_gas_price: transaction.effective_gas_price(meta.base_fee),
|
||||
// TODO pre-byzantium receipts have a post-transaction state root
|
||||
state_root: None,
|
||||
// EIP-4844 fields
|
||||
blob_gas_price: blob_gas_price.map(|gas| gas as u64),
|
||||
blob_gas_used,
|
||||
blob_gas_price,
|
||||
blob_gas_used: blob_gas_used.map(u128::from),
|
||||
};
|
||||
let mut res_receipt = WithOtherFields::new(res_receipt);
|
||||
|
||||
@ -1755,12 +1758,12 @@ pub(crate) fn build_transaction_receipt_with_block_receipts(
|
||||
receipt.deposit_receipt_version.map(reth_primitives::U64::from);
|
||||
} else if let Some(l1_block_info) = optimism_tx_meta.l1_block_info {
|
||||
op_fields.l1_fee = optimism_tx_meta.l1_fee;
|
||||
op_fields.l1_gas_used = optimism_tx_meta
|
||||
.l1_data_gas
|
||||
.map(|dg| dg + l1_block_info.l1_fee_overhead.unwrap_or_default());
|
||||
op_fields.l1_gas_used = optimism_tx_meta.l1_data_gas.map(|dg| {
|
||||
dg + l1_block_info.l1_fee_overhead.unwrap_or_default().saturating_to::<u128>()
|
||||
});
|
||||
op_fields.l1_fee_scalar =
|
||||
Some(f64::from(l1_block_info.l1_base_fee_scalar) / 1_000_000.0);
|
||||
op_fields.l1_gas_price = Some(l1_block_info.l1_base_fee);
|
||||
op_fields.l1_gas_price = Some(l1_block_info.l1_base_fee.saturating_to());
|
||||
}
|
||||
|
||||
res_receipt.other = op_fields.into();
|
||||
|
||||
@ -158,13 +158,13 @@ where
|
||||
}
|
||||
|
||||
// Crop receipts and transform them into OtsTransactionReceipt
|
||||
let timestamp = Some(u64::try_from(block.header.timestamp).unwrap_or(u64::MAX));
|
||||
let timestamp = Some(block.header.timestamp);
|
||||
let receipts = receipts
|
||||
.drain(page_start..page_end)
|
||||
.map(|receipt| {
|
||||
let receipt = receipt.inner.map_inner(|receipt| OtsReceipt {
|
||||
status: receipt.inner.receipt.status,
|
||||
cumulative_gas_used: receipt.inner.receipt.cumulative_gas_used,
|
||||
cumulative_gas_used: receipt.inner.receipt.cumulative_gas_used as u64,
|
||||
logs: None,
|
||||
logs_bloom: None,
|
||||
r#type: receipt.r#type,
|
||||
|
||||
Reference in New Issue
Block a user