1
1
pub ( crate ) mod blob;
2
2
pub ( crate ) mod message;
3
3
4
- use crate :: { beacon_client :: OnlineBeaconClient , l1:: message:: L1MessageProvider , L1BlobProvider } ;
4
+ use crate :: { beacon :: BeaconProvider , l1:: message:: L1MessageProvider , L1BlobProvider } ;
5
5
use std:: { num:: NonZeroUsize , sync:: Arc } ;
6
6
7
7
use alloy_eips:: eip4844:: { Blob , BlobTransactionSidecarItem } ;
@@ -18,9 +18,9 @@ impl<T> L1Provider for T where T: L1BlobProvider + L1MessageProvider {}
18
18
/// An error occurring at the [`L1Provider`].
19
19
#[ derive( Debug , thiserror:: Error ) ]
20
20
pub 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 ) ,
24
24
/// Invalid timestamp for slot.
25
25
#[ error( "invalid block timestamp: genesis {0}, provided {1}" ) ]
26
26
InvalidBlockTimestamp ( u64 , u64 ) ,
@@ -34,37 +34,40 @@ pub enum L1ProviderError {
34
34
35
35
/// An online implementation of the [`L1Provider`] trait.
36
36
#[ 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 ,
40
40
/// The cache for blobs from similar blocks.
41
41
cache : Arc < Mutex < LruCache < B256 , Arc < Blob > > > > ,
42
42
/// The L1 message provider
43
- l1_message_provider : P ,
43
+ l1_message_provider : L1P ,
44
44
/// The genesis timestamp for the Beacon chain.
45
45
genesis_timestamp : u64 ,
46
46
/// The slot interval for the Beacon chain.
47
47
slot_interval : u64 ,
48
48
}
49
49
50
- impl < P > OnlineL1Provider < P > {
50
+ impl < L1P , BP > OnlineL1Provider < L1P , BP >
51
+ where
52
+ BP : BeaconProvider ,
53
+ {
51
54
/// Returns a new [`OnlineBeaconClient`] from the provided [`OnlineBeaconClient`], blob capacity
52
55
/// 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 {
58
57
let cache = Arc :: new ( Mutex :: new ( LruCache :: new (
59
58
NonZeroUsize :: new ( blob_capacity) . expect ( "cache requires non-zero capacity" ) ,
60
59
) ) ) ;
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" ) ;
65
68
66
69
Self {
67
- beacon_client : client ,
70
+ beacon_provider ,
68
71
cache,
69
72
l1_message_provider,
70
73
genesis_timestamp : genesis. data . genesis_time ,
@@ -85,7 +88,7 @@ impl<P> OnlineL1Provider<P> {
85
88
}
86
89
87
90
#[ async_trait:: async_trait]
88
- impl < P : Sync > L1BlobProvider for OnlineL1Provider < P > {
91
+ impl < L1P : Sync , BP : BeaconProvider + Sync > L1BlobProvider for OnlineL1Provider < L1P , BP > {
89
92
/// Returns the requested blob corresponding to the passed hash.
90
93
async fn blob (
91
94
& self ,
@@ -103,9 +106,10 @@ impl<P: Sync> L1BlobProvider for OnlineL1Provider<P> {
103
106
// query the blobs with the client, return target blob and store all others in cache.
104
107
let slot = self . slot ( block_timestamp) ?;
105
108
let mut blobs = self
106
- . beacon_client
109
+ . beacon_provider
107
110
. blobs ( slot)
108
- . await ?
111
+ . await
112
+ . map_err ( Into :: into) ?
109
113
. into_iter ( )
110
114
. map ( |blob| BlobTransactionSidecarItem {
111
115
index : blob. index ,
@@ -134,8 +138,8 @@ impl<P: Sync> L1BlobProvider for OnlineL1Provider<P> {
134
138
}
135
139
136
140
#[ 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 ;
139
143
140
144
async fn next_l1_message ( & self ) -> Result < Option < TxL1Message > , Self :: Error > {
141
145
self . l1_message_provider . next_l1_message ( ) . await
0 commit comments