@@ -12,6 +12,7 @@ use signet_node_types::Pnt;
1212use signet_tx_cache:: client:: TxCache ;
1313use signet_types:: constants:: SignetSystemConstants ;
1414use std:: sync:: Arc ;
15+ use tokio:: sync:: { AcquireError , OwnedSemaphorePermit , Semaphore } ;
1516use trevm:: { helpers:: Ctx , revm:: Inspector } ;
1617
1718/// State location when instantiating an EVM instance.
@@ -137,6 +138,12 @@ where
137138 }
138139}
139140
141+ /// Shared context between all RPC handlers.
142+ #[ derive( Debug ) ]
143+ struct SharedContext {
144+ tracing_semaphores : Arc < Semaphore > ,
145+ }
146+
140147/// Inner context for [`RpcCtx`].
141148#[ derive( Debug ) ]
142149pub struct RpcCtxInner < Host , Signet >
@@ -146,6 +153,8 @@ where
146153{
147154 host : Host ,
148155 signet : SignetCtx < Signet > ,
156+
157+ shared : SharedContext ,
149158}
150159
151160impl < Host , Signet > RpcCtxInner < Host , Signet >
@@ -177,8 +186,20 @@ where
177186 where
178187 Tasks : TaskSpawner + Clone + ' static ,
179188 {
180- SignetCtx :: new ( constants, factory, provider, eth_config, tx_cache, spawner)
181- . map ( |signet| Self { host, signet } )
189+ SignetCtx :: new ( constants, factory, provider, eth_config, tx_cache, spawner) . map ( |signet| {
190+ Self {
191+ host,
192+ signet,
193+ shared : SharedContext {
194+ tracing_semaphores : Semaphore :: new ( eth_config. max_tracing_requests ) . into ( ) ,
195+ } ,
196+ }
197+ } )
198+ }
199+
200+ /// Acquire a permit for tracing.
201+ pub async fn acquire_tracing_permit ( & self ) -> Result < OwnedSemaphorePermit , AcquireError > {
202+ self . shared . tracing_semaphores . clone ( ) . acquire_owned ( ) . await
182203 }
183204
184205 pub const fn host ( & self ) -> & Host {
0 commit comments