@@ -7,7 +7,7 @@ use crate::{
77use alloy_primitives:: { keccak256, Address , Bytes , B256 , U256 } ;
88use alloy_provider:: {
99 network:: { AnyNetwork , AnyRpcBlock , AnyRpcTransaction } ,
10- Provider ,
10+ DynProvider , Provider ,
1111} ;
1212use alloy_rpc_types:: BlockId ;
1313use eyre:: WrapErr ;
@@ -155,8 +155,8 @@ enum BackendRequest {
155155/// This handler will remain active as long as it is reachable (request channel still open) and
156156/// requests are in progress.
157157#[ must_use = "futures do nothing unless polled" ]
158- pub struct BackendHandler < P > {
159- provider : P ,
158+ pub struct BackendHandler {
159+ provider : DynProvider < AnyNetwork > ,
160160 /// Stores all the data.
161161 db : BlockchainDb ,
162162 /// Requests currently in progress
@@ -178,12 +178,9 @@ pub struct BackendHandler<P> {
178178 account_fetch_mode : Arc < AtomicU8 > ,
179179}
180180
181- impl < P > BackendHandler < P >
182- where
183- P : Provider < AnyNetwork > + Clone + Unpin + ' static ,
184- {
181+ impl BackendHandler {
185182 fn new (
186- provider : P ,
183+ provider : DynProvider < AnyNetwork > ,
187184 db : BlockchainDb ,
188185 rx : UnboundedReceiver < BackendRequest > ,
189186 block_id : Option < BlockId > ,
@@ -474,10 +471,7 @@ where
474471 }
475472}
476473
477- impl < P > Future for BackendHandler < P >
478- where
479- P : Provider < AnyNetwork > + Clone + Unpin + ' static ,
480- {
474+ impl Future for BackendHandler {
481475 type Output = ( ) ;
482476
483477 fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
@@ -737,12 +731,11 @@ impl SharedBackend {
737731 ///
738732 /// The spawned `BackendHandler` finishes once the last `SharedBackend` connected to it is
739733 /// dropped.
740- ///
741- /// NOTE: this should be called with `Arc<Provider>`
742- pub async fn spawn_backend < P > ( provider : P , db : BlockchainDb , pin_block : Option < BlockId > ) -> Self
743- where
744- P : Provider < AnyNetwork > + Unpin + ' static + Clone ,
745- {
734+ pub async fn spawn_backend < P : Provider < AnyNetwork > + ' static > (
735+ provider : P ,
736+ db : BlockchainDb ,
737+ pin_block : Option < BlockId > ,
738+ ) -> Self {
746739 let ( shared, handler) = Self :: new ( provider, db, pin_block) ;
747740 // spawn the provider handler to a task
748741 trace ! ( target: "backendhandler" , "spawning Backendhandler task" ) ;
@@ -752,14 +745,11 @@ impl SharedBackend {
752745
753746 /// Same as `Self::spawn_backend` but spawns the `BackendHandler` on a separate `std::thread` in
754747 /// its own `tokio::Runtime`
755- pub fn spawn_backend_thread < P > (
748+ pub fn spawn_backend_thread < P : Provider < AnyNetwork > + ' static > (
756749 provider : P ,
757750 db : BlockchainDb ,
758751 pin_block : Option < BlockId > ,
759- ) -> Self
760- where
761- P : Provider < AnyNetwork > + Unpin + ' static + Clone ,
762- {
752+ ) -> Self {
763753 let ( shared, handler) = Self :: new ( provider, db, pin_block) ;
764754
765755 // spawn a light-weight thread with a thread-local async runtime just for
@@ -781,17 +771,14 @@ impl SharedBackend {
781771 }
782772
783773 /// Returns a new `SharedBackend` and the `BackendHandler`
784- pub fn new < P > (
774+ pub fn new < P : Provider < AnyNetwork > + ' static > (
785775 provider : P ,
786776 db : BlockchainDb ,
787777 pin_block : Option < BlockId > ,
788- ) -> ( Self , BackendHandler < P > )
789- where
790- P : Provider < AnyNetwork > + Unpin + ' static + Clone ,
791- {
778+ ) -> ( Self , BackendHandler ) {
792779 let ( backend, backend_rx) = unbounded ( ) ;
793780 let cache = Arc :: new ( FlushJsonBlockCacheDB ( Arc :: clone ( db. cache ( ) ) ) ) ;
794- let handler = BackendHandler :: new ( provider, db, backend_rx, pin_block) ;
781+ let handler = BackendHandler :: new ( provider. erased ( ) , db, backend_rx, pin_block) ;
795782 ( Self { backend, cache, blocking_mode : Default :: default ( ) } , handler)
796783 }
797784
0 commit comments