@@ -6,6 +6,7 @@ use jsonrpsee::core::RpcResult;
66use reth_chainspec:: ChainSpec ;
77use reth_network_api:: { NetworkInfo , PeerKind , Peers } ;
88use reth_network_peers:: { id2pk, AnyNode , NodeRecord } ;
9+ use reth_primitives:: EthereumHardfork ;
910use reth_rpc_api:: AdminApiServer ;
1011use reth_rpc_server_types:: ToRpcResult ;
1112use reth_rpc_types:: admin:: {
@@ -105,17 +106,56 @@ where
105106 async fn node_info ( & self ) -> RpcResult < NodeInfo > {
106107 let enode = self . network . local_node_record ( ) ;
107108 let status = self . network . network_status ( ) . await . to_rpc_result ( ) ?;
108- let config = ChainConfig {
109+ let mut config = ChainConfig {
109110 chain_id : self . chain_spec . chain . id ( ) ,
110111 terminal_total_difficulty_passed : self
111112 . chain_spec
112113 . get_final_paris_total_difficulty ( )
113114 . is_some ( ) ,
115+ terminal_total_difficulty : self
116+ . chain_spec
117+ . hardforks
118+ . fork ( EthereumHardfork :: Paris )
119+ . ttd ( ) ,
114120 ..self . chain_spec . genesis ( ) . config . clone ( )
115121 } ;
116122
117- let node_info = NodeInfo {
118- id : enode. id . to_string ( ) ,
123+ // helper macro to set the block or time for a hardfork if known
124+ macro_rules! set_block_or_time {
125+ ( $config: expr, [ $( $field: ident => $fork: ident, ) * ] ) => {
126+ $(
127+ // don't overwrite if already set
128+ if $config. $field. is_none( ) {
129+ $config. $field = self . chain_spec. hardforks. fork_block( EthereumHardfork :: $fork) ;
130+ }
131+ ) *
132+ } ;
133+ }
134+
135+ set_block_or_time ! ( config, [
136+ homestead_block => Homestead ,
137+ dao_fork_block => Dao ,
138+ eip150_block => Tangerine ,
139+ eip155_block => SpuriousDragon ,
140+ eip158_block => SpuriousDragon ,
141+ byzantium_block => Byzantium ,
142+ constantinople_block => Constantinople ,
143+ petersburg_block => Petersburg ,
144+ istanbul_block => Istanbul ,
145+ muir_glacier_block => MuirGlacier ,
146+ berlin_block => Berlin ,
147+ london_block => London ,
148+ arrow_glacier_block => ArrowGlacier ,
149+ gray_glacier_block => GrayGlacier ,
150+ shanghai_time => Shanghai ,
151+ cancun_time => Cancun ,
152+ prague_time => Prague ,
153+ ] ) ;
154+
155+ Ok ( NodeInfo {
156+ id : id2pk ( enode. id )
157+ . map ( |pk| pk. to_string ( ) )
158+ . unwrap_or_else ( |_| alloy_primitives:: hex:: encode ( enode. id . as_slice ( ) ) ) ,
119159 name : status. client_version ,
120160 enode : enode. to_string ( ) ,
121161 enr : self . network . local_enr ( ) . to_string ( ) ,
@@ -132,9 +172,7 @@ where
132172 } ) ,
133173 snap : None ,
134174 } ,
135- } ;
136-
137- Ok ( node_info)
175+ } )
138176 }
139177
140178 /// Handler for `admin_peerEvents`
0 commit comments