11pub ( crate ) mod blob;
22pub ( crate ) mod message;
33
4- use crate :: { beacon_client :: OnlineBeaconClient , l1:: message:: L1MessageProvider , L1BlobProvider } ;
4+ use crate :: { beacon :: BeaconProvider , l1:: message:: L1MessageProvider , L1BlobProvider } ;
55use std:: { num:: NonZeroUsize , sync:: Arc } ;
66
77use alloy_eips:: eip4844:: { Blob , BlobTransactionSidecarItem } ;
@@ -18,9 +18,9 @@ impl<T> L1Provider for T where T: L1BlobProvider + L1MessageProvider {}
1818/// An error occurring at the [`L1Provider`].
1919#[ derive( Debug , thiserror:: Error ) ]
2020pub enum L1ProviderError {
21- /// Invalid timestamp for slot .
22- #[ error( "Beacon client error: {0}" ) ]
23- BeaconClient ( #[ from] reqwest:: Error ) ,
21+ /// Error at the beacon provider .
22+ #[ error( "Beacon provider error: {0}" ) ]
23+ BeaconProvider ( #[ from] reqwest:: Error ) ,
2424 /// Invalid timestamp for slot.
2525 #[ error( "invalid block timestamp: genesis {0}, provided {1}" ) ]
2626 InvalidBlockTimestamp ( u64 , u64 ) ,
@@ -34,37 +34,40 @@ pub enum L1ProviderError {
3434
3535/// An online implementation of the [`L1Provider`] trait.
3636#[ derive( Debug , Clone ) ]
37- pub struct OnlineL1Provider < P > {
38- /// The Beacon client .
39- beacon_client : OnlineBeaconClient ,
37+ pub struct OnlineL1Provider < L1P , BP > {
38+ /// The beacon provider .
39+ beacon_provider : BP ,
4040 /// The cache for blobs from similar blocks.
4141 cache : Arc < Mutex < LruCache < B256 , Arc < Blob > > > > ,
4242 /// The L1 message provider
43- l1_message_provider : P ,
43+ l1_message_provider : L1P ,
4444 /// The genesis timestamp for the Beacon chain.
4545 genesis_timestamp : u64 ,
4646 /// The slot interval for the Beacon chain.
4747 slot_interval : u64 ,
4848}
4949
50- impl < P > OnlineL1Provider < P > {
50+ impl < L1P , BP > OnlineL1Provider < L1P , BP >
51+ where
52+ BP : BeaconProvider ,
53+ {
5154 /// Returns a new [`OnlineBeaconClient`] from the provided [`OnlineBeaconClient`], blob capacity
5255 /// and [`L1MessageProvider`].
53- pub async fn new (
54- client : OnlineBeaconClient ,
55- blob_capacity : usize ,
56- l1_message_provider : P ,
57- ) -> Self {
56+ pub async fn new ( beacon_provider : BP , blob_capacity : usize , l1_message_provider : L1P ) -> Self {
5857 let cache = Arc :: new ( Mutex :: new ( LruCache :: new (
5958 NonZeroUsize :: new ( blob_capacity) . expect ( "cache requires non-zero capacity" ) ,
6059 ) ) ) ;
61- let config =
62- client. config_spec ( ) . await . expect ( "failed to fetch Beacon chain configuration" ) ;
63- let genesis =
64- client. beacon_genesis ( ) . await . expect ( "failed to fetch Beacon chain genesis info" ) ;
60+ let config = beacon_provider
61+ . config_spec ( )
62+ . await
63+ . expect ( "failed to fetch Beacon chain configuration" ) ;
64+ let genesis = beacon_provider
65+ . beacon_genesis ( )
66+ . await
67+ . expect ( "failed to fetch Beacon chain genesis info" ) ;
6568
6669 Self {
67- beacon_client : client ,
70+ beacon_provider ,
6871 cache,
6972 l1_message_provider,
7073 genesis_timestamp : genesis. data . genesis_time ,
@@ -85,7 +88,7 @@ impl<P> OnlineL1Provider<P> {
8588}
8689
8790#[ async_trait:: async_trait]
88- impl < P : Sync > L1BlobProvider for OnlineL1Provider < P > {
91+ impl < L1P : Sync , BP : BeaconProvider + Sync > L1BlobProvider for OnlineL1Provider < L1P , BP > {
8992 /// Returns the requested blob corresponding to the passed hash.
9093 async fn blob (
9194 & self ,
@@ -103,9 +106,10 @@ impl<P: Sync> L1BlobProvider for OnlineL1Provider<P> {
103106 // query the blobs with the client, return target blob and store all others in cache.
104107 let slot = self . slot ( block_timestamp) ?;
105108 let mut blobs = self
106- . beacon_client
109+ . beacon_provider
107110 . blobs ( slot)
108- . await ?
111+ . await
112+ . map_err ( Into :: into) ?
109113 . into_iter ( )
110114 . map ( |blob| BlobTransactionSidecarItem {
111115 index : blob. index ,
@@ -134,8 +138,8 @@ impl<P: Sync> L1BlobProvider for OnlineL1Provider<P> {
134138}
135139
136140#[ async_trait:: async_trait]
137- impl < P : L1MessageProvider + Sync > L1MessageProvider for OnlineL1Provider < P > {
138- type Error = <P >:: Error ;
141+ impl < L1P : L1MessageProvider + Sync , BP : Sync > L1MessageProvider for OnlineL1Provider < L1P , BP > {
142+ type Error = <L1P >:: Error ;
139143
140144 async fn next_l1_message ( & self ) -> Result < Option < TxL1Message > , Self :: Error > {
141145 self . l1_message_provider . next_l1_message ( ) . await
0 commit comments