1
- use crate :: { BlobFetcherError , Blobs , FetchResult } ;
1
+ use crate :: { BlobberError , BlobberResult , Blobs , FetchResult } ;
2
2
use alloy:: consensus:: { SidecarCoder , SimpleCoder , Transaction as _} ;
3
3
use alloy:: eips:: eip7691:: MAX_BLOBS_PER_BLOCK_ELECTRA ;
4
4
use alloy:: eips:: merge:: EPOCH_SLOTS ;
@@ -13,7 +13,7 @@ use std::{
13
13
time:: Duration ,
14
14
} ;
15
15
use tokio:: sync:: { mpsc, oneshot} ;
16
- use tracing:: { Instrument , debug , error, info, instrument} ;
16
+ use tracing:: { Instrument , debug_span , error, info, instrument, trace } ;
17
17
18
18
const BLOB_CACHE_SIZE : u32 = ( MAX_BLOBS_PER_BLOCK_ELECTRA * EPOCH_SLOTS ) as u32 ;
19
19
const CACHE_REQUEST_CHANNEL_SIZE : usize = ( MAX_BLOBS_PER_BLOCK_ELECTRA * 2 ) as usize ;
@@ -54,7 +54,7 @@ impl CacheHandle {
54
54
slot : usize ,
55
55
tx_hash : B256 ,
56
56
version_hashes : Vec < B256 > ,
57
- ) -> FetchResult < Blobs > {
57
+ ) -> BlobberResult < Blobs > {
58
58
let ( resp, receiver) = oneshot:: channel ( ) ;
59
59
60
60
self . send ( CacheInst :: Retrieve {
@@ -66,7 +66,7 @@ impl CacheHandle {
66
66
} )
67
67
. await ;
68
68
69
- receiver. await . map_err ( |_| BlobFetcherError :: missing_sidecar ( tx_hash) )
69
+ receiver. await . map_err ( |_| BlobberError :: missing_sidecar ( tx_hash) )
70
70
}
71
71
72
72
/// Fetch the blobs using [`Self::fetch_blobs`] and decode them to get the
@@ -76,24 +76,24 @@ impl CacheHandle {
76
76
slot : usize ,
77
77
extract : & ExtractedEvent < ' _ , Receipt , BlockSubmitted > ,
78
78
mut coder : C ,
79
- ) -> FetchResult < Bytes > {
79
+ ) -> BlobberResult < Bytes > {
80
80
let tx_hash = extract. tx_hash ( ) ;
81
81
let versioned_hashes = extract
82
82
. tx
83
83
. as_eip4844 ( )
84
- . ok_or_else ( BlobFetcherError :: non_4844_transaction) ?
84
+ . ok_or_else ( BlobberError :: non_4844_transaction) ?
85
85
. blob_versioned_hashes ( )
86
86
. expect ( "tx is eip4844" ) ;
87
87
88
88
let blobs = self . fetch_blobs ( slot, tx_hash, versioned_hashes. to_owned ( ) ) . await ?;
89
89
90
90
coder
91
91
. decode_all ( blobs. as_ref ( ) )
92
- . ok_or_else ( BlobFetcherError :: blob_decode_error) ?
92
+ . ok_or_else ( BlobberError :: blob_decode_error) ?
93
93
. into_iter ( )
94
94
. find ( |data| keccak256 ( data) == extract. block_data_hash ( ) )
95
95
. map ( Into :: into)
96
- . ok_or_else ( || BlobFetcherError :: block_data_not_found ( tx_hash) )
96
+ . ok_or_else ( || BlobberError :: block_data_not_found ( tx_hash) )
97
97
}
98
98
99
99
/// Fetch the blobs using [`Self::fetch_blobs`] and decode them using
@@ -102,12 +102,21 @@ impl CacheHandle {
102
102
& self ,
103
103
slot : usize ,
104
104
extract : & ExtractedEvent < ' _ , Receipt , BlockSubmitted > ,
105
- ) -> FetchResult < Bytes > {
105
+ ) -> BlobberResult < Bytes > {
106
106
self . fetch_and_decode_with_coder ( slot, extract, SimpleCoder :: default ( ) ) . await
107
107
}
108
108
109
109
/// Fetch the blobs, decode them using the provided coder, and construct a
110
110
/// Zenith block from the header and data.
111
+ ///
112
+ /// # Returns
113
+ ///
114
+ /// - `Ok(ZenithBlock)` if the block was successfully fetched and
115
+ /// decoded.
116
+ /// - `Ok(ZenithBlock)` with an EMPTY BLOCK if the block_data could not be
117
+ /// decoded (e.g., due to a malformatted blob).
118
+ /// - `Err(FetchError)` if there was an unrecoverable error fetching the
119
+ /// blobs.
111
120
pub async fn signet_block_with_coder < C : SidecarCoder > (
112
121
& self ,
113
122
host_block_number : u64 ,
@@ -116,13 +125,28 @@ impl CacheHandle {
116
125
coder : C ,
117
126
) -> FetchResult < ZenithBlock > {
118
127
let header = extract. ru_header ( host_block_number) ;
119
- self . fetch_and_decode_with_coder ( slot, extract, coder)
120
- . await
121
- . map ( |buf| ZenithBlock :: from_header_and_data ( header, buf) )
128
+ let block_data = match self . fetch_and_decode_with_coder ( slot, extract, coder) . await {
129
+ Ok ( buf) => buf,
130
+ Err ( BlobberError :: Decode ( _) ) => {
131
+ trace ! ( "Failed to decode block data" ) ;
132
+ Bytes :: default ( )
133
+ }
134
+ Err ( BlobberError :: Fetch ( err) ) => return Err ( err) ,
135
+ } ;
136
+ Ok ( ZenithBlock :: from_header_and_data ( header, block_data) )
122
137
}
123
138
124
139
/// Fetch the blobs, decode them using [`SimpleCoder`], and construct a
125
140
/// Zenith block from the header and data.
141
+ ///
142
+ /// # Returns
143
+ ///
144
+ /// - `Ok(ZenithBlock)` if the block was successfully fetched and
145
+ /// decoded.
146
+ /// - `Ok(ZenithBlock)` with an EMPTY BLOCK if the block_data could not be
147
+ /// decoded (e.g., due to a malformatted blob).
148
+ /// - `Err(FetchError)` if there was an unrecoverable error fetching the
149
+ /// blobs.
126
150
pub async fn signet_block (
127
151
& self ,
128
152
host_block_number : u64 ,
@@ -159,7 +183,7 @@ impl<Pool: TransactionPool + 'static> BlobCacher<Pool> {
159
183
slot : usize ,
160
184
tx_hash : B256 ,
161
185
versioned_hashes : Vec < B256 > ,
162
- ) -> FetchResult < Blobs > {
186
+ ) -> BlobberResult < Blobs > {
163
187
// Cache hit
164
188
if let Some ( blobs) = self . cache . lock ( ) . unwrap ( ) . get ( & ( slot, tx_hash) ) {
165
189
info ! ( target: "signet_blobber::BlobCacher" , "Cache hit" ) ;
@@ -169,23 +193,21 @@ impl<Pool: TransactionPool + 'static> BlobCacher<Pool> {
169
193
// Cache miss, use the fetcher to retrieve blobs
170
194
// Retry fetching blobs up to `FETCH_RETRIES` times
171
195
for attempt in 1 ..=FETCH_RETRIES {
172
- let blobs = self . fetcher . fetch_blobs ( slot, tx_hash, & versioned_hashes) . await ;
173
-
174
- match blobs {
175
- Ok ( blobs) => {
176
- self . cache . lock ( ) . unwrap ( ) . insert ( ( slot, tx_hash) , blobs. clone ( ) ) ;
177
- return Ok ( blobs) ;
178
- }
179
- Err ( BlobFetcherError :: Ignorable ( e) ) => {
180
- debug ! ( target: "signet_blobber::BlobCacher" , attempt, %e, "Blob fetch attempt failed." ) ;
181
- tokio:: time:: sleep ( BETWEEN_RETRIES ) . await ;
182
- continue ;
183
- }
184
- Err ( e) => return Err ( e) , // unrecoverable error
185
- }
196
+ let Ok ( blobs) = self
197
+ . fetcher
198
+ . fetch_blobs ( slot, tx_hash, & versioned_hashes)
199
+ . instrument ( debug_span ! ( "fetch_blobs_loop" , attempt) )
200
+ . await
201
+ else {
202
+ tokio:: time:: sleep ( BETWEEN_RETRIES ) . await ;
203
+ continue ;
204
+ } ;
205
+
206
+ self . cache . lock ( ) . unwrap ( ) . insert ( ( slot, tx_hash) , blobs. clone ( ) ) ;
207
+ return Ok ( blobs) ;
186
208
}
187
209
error ! ( target: "signet_blobber::BlobCacher" , "All fetch attempts failed" ) ;
188
- Err ( BlobFetcherError :: missing_sidecar ( tx_hash) )
210
+ Err ( BlobberError :: missing_sidecar ( tx_hash) )
189
211
}
190
212
191
213
/// Processes the cache instructions.
0 commit comments