@@ -13,6 +13,7 @@ use signet_node_types::Pnt;
1313use signet_tx_cache:: client:: TxCache ;
1414use signet_types:: constants:: SignetSystemConstants ;
1515use std:: sync:: Arc ;
16+ use tokio:: sync:: { AcquireError , OwnedSemaphorePermit , Semaphore } ;
1617use trevm:: helpers:: Ctx ;
1718
1819/// State location when instantiating an EVM instance.
@@ -126,6 +127,12 @@ where
126127 }
127128}
128129
130+ /// Shared context between all RPC handlers.
131+ #[ derive( Debug ) ]
132+ struct SharedContext {
133+ tracing_semaphores : Arc < Semaphore > ,
134+ }
135+
129136/// Inner context for [`RpcCtx`].
130137#[ derive( Debug ) ]
131138pub struct RpcCtxInner < Host , Signet >
@@ -135,6 +142,8 @@ where
135142{
136143 host : Host ,
137144 signet : SignetCtx < Signet > ,
145+
146+ shared : SharedContext ,
138147}
139148
140149impl < Host , Signet > RpcCtxInner < Host , Signet >
@@ -154,8 +163,18 @@ where
154163 where
155164 Tasks : TaskSpawner + Clone + ' static ,
156165 {
157- SignetCtx :: new ( constants, factory, eth_config, tx_cache, spawner)
158- . map ( |signet| Self { host, signet } )
166+ SignetCtx :: new ( constants, factory, eth_config, tx_cache, spawner) . map ( |signet| Self {
167+ host,
168+ signet,
169+ shared : SharedContext {
170+ tracing_semaphores : Semaphore :: new ( eth_config. max_tracing_requests ) . into ( ) ,
171+ } ,
172+ } )
173+ }
174+
175+ /// Acquire a permit for tracing.
176+ pub async fn acquire_tracing_permit ( & self ) -> Result < OwnedSemaphorePermit , AcquireError > {
177+ self . shared . tracing_semaphores . clone ( ) . acquire_owned ( ) . await
159178 }
160179
161180 pub const fn host ( & self ) -> & Host {
0 commit comments