@@ -77,7 +77,7 @@ use serde::{Deserialize, Serialize};
7777use std:: num:: NonZeroUsize ;
7878use std:: ops:: RangeInclusive ;
7979use std:: str:: FromStr ;
80- use std:: sync:: { Arc , LazyLock } ;
80+ use std:: sync:: { Arc , LazyLock , OnceLock } ;
8181use utils:: { decode_payload, lookup_eth_address} ;
8282
8383static FOREST_TRACE_FILTER_MAX_RESULT : LazyLock < u64 > =
@@ -764,17 +764,23 @@ impl RpcMethod<0> for Web3ClientVersion {
764764 const PERMISSION : Permission = Permission :: Read ;
765765
766766 type Params = ( ) ;
767- type Ok = String ;
767+ type Ok = Arc < str > ;
768768
769769 async fn handle (
770770 _: Ctx < impl Blockstore + Send + Sync + ' static > ,
771771 ( ) : Self :: Params ,
772772 _: & http:: Extensions ,
773773 ) -> Result < Self :: Ok , ServerError > {
774- Ok ( format ! (
775- "forest/{}" ,
776- * crate :: utils:: version:: FOREST_VERSION_STRING
777- ) )
774+ // Version string is baked in at build time; cache once.
775+ static CACHED : OnceLock < Arc < str > > = OnceLock :: new ( ) ;
776+ Ok ( CACHED
777+ . get_or_init ( || {
778+ Arc :: < str > :: from ( format ! (
779+ "forest/{}" ,
780+ * crate :: utils:: version:: FOREST_VERSION_STRING
781+ ) )
782+ } )
783+ . clone ( ) )
778784 }
779785}
780786
@@ -844,14 +850,18 @@ impl RpcMethod<0> for EthChainId {
844850 const PERMISSION : Permission = Permission :: Read ;
845851
846852 type Params = ( ) ;
847- type Ok = String ;
853+ type Ok = Arc < str > ;
848854
849855 async fn handle (
850856 ctx : Ctx < impl Blockstore + Send + Sync + ' static > ,
851857 ( ) : Self :: Params ,
852858 _: & http:: Extensions ,
853859 ) -> Result < Self :: Ok , ServerError > {
854- Ok ( format ! ( "{:#x}" , ctx. chain_config( ) . eth_chain_id) )
860+ // `eth_chain_id` is fixed for the process lifetime; cache the hex form.
861+ static CACHED : OnceLock < Arc < str > > = OnceLock :: new ( ) ;
862+ Ok ( CACHED
863+ . get_or_init ( || Arc :: < str > :: from ( format ! ( "{:#x}" , ctx. chain_config( ) . eth_chain_id) ) )
864+ . clone ( ) )
855865 }
856866}
857867
0 commit comments