@@ -25,7 +25,7 @@ use std::sync::Arc;
2525use thiserror:: Error ;
2626use tokio:: sync:: RwLock ;
2727use tokio:: sync:: mpsc;
28- use tracing:: { error, info} ;
28+ use tracing:: { debug , error, info} ;
2929
3030#[ derive( Debug , Error , PartialEq ) ]
3131pub enum FlashblocksError {
@@ -176,13 +176,15 @@ impl FlashblockBuilder {
176176pub struct FlashblocksService {
177177 client : RpcClient ,
178178
179- // Current payload ID we're processing (set from external notification)
180- current_payload_id : Arc < RwLock < PayloadId > > ,
179+ /// Current payload ID we're processing. Set from local payload calculation and updated from
180+ /// external source.
181+ /// None means rollup-boost has not served FCU with attributes yet.
182+ current_payload_id : Arc < RwLock < Option < PayloadId > > > ,
181183
182- // flashblocks payload being constructed
184+ /// The current Flashblock's payload being constructed.
183185 best_payload : Arc < RwLock < FlashblockBuilder > > ,
184186
185- // websocket publisher for sending valid preconfirmations to clients
187+ /// Websocket publisher for sending valid pre-confirmations to clients.
186188 ws_pub : Arc < WebSocketPublisher > ,
187189
188190 metrics : FlashblocksServiceMetrics ,
@@ -194,7 +196,7 @@ impl FlashblocksService {
194196
195197 Ok ( Self {
196198 client,
197- current_payload_id : Arc :: new ( RwLock :: new ( PayloadId :: default ( ) ) ) ,
199+ current_payload_id : Arc :: new ( RwLock :: new ( None ) ) ,
198200 best_payload : Arc :: new ( RwLock :: new ( FlashblockBuilder :: new ( ) ) ) ,
199201 ws_pub,
200202 metrics : Default :: default ( ) ,
@@ -207,7 +209,7 @@ impl FlashblocksService {
207209 payload_id : PayloadId ,
208210 ) -> Result < OpExecutionPayloadEnvelope , FlashblocksError > {
209211 // Check that we have flashblocks for correct payload
210- if * self . current_payload_id . read ( ) . await != payload_id {
212+ if * self . current_payload_id . read ( ) . await != Some ( payload_id) {
211213 // We have outdated `current_payload_id` so we should fallback to get_payload
212214 // Clearing best_payload in here would cause situation when old `get_payload` would clear
213215 // currently built correct flashblocks.
@@ -231,7 +233,7 @@ impl FlashblocksService {
231233
232234 pub async fn set_current_payload_id ( & self , payload_id : PayloadId ) {
233235 tracing:: debug!( message = "Setting current payload ID" , payload_id = %payload_id) ;
234- * self . current_payload_id . write ( ) . await = payload_id;
236+ * self . current_payload_id . write ( ) . await = Some ( payload_id) ;
235237 // Current state won't be useful anymore because chain progressed
236238 * self . best_payload . write ( ) . await = FlashblockBuilder :: new ( ) ;
237239 }
@@ -247,17 +249,30 @@ impl FlashblocksService {
247249 index = payload. index
248250 ) ;
249251
250- // make sure the payload id matches the current payload id
251- let local_payload_id = * self . current_payload_id . read ( ) . await ;
252- if local_payload_id != payload. payload_id {
253- self . metrics . current_payload_id_mismatch . increment ( 1 ) ;
254- error ! (
255- message = "Payload ID mismatch" ,
256- payload_id = %payload. payload_id,
257- %local_payload_id,
258- index = payload. index,
259- ) ;
260- return ;
252+ // Make sure the payload id matches the current payload id
253+ // If local payload id is non then boost is not service FCU with attributes
254+ match * self . current_payload_id . read ( ) . await {
255+ Some ( payload_id) => {
256+ if payload_id != payload. payload_id {
257+ self . metrics . current_payload_id_mismatch . increment ( 1 ) ;
258+ error ! (
259+ message = "Payload ID mismatch" ,
260+ payload_id = %payload. payload_id,
261+ local_payload_id = %payload_id,
262+ index = payload. index,
263+ ) ;
264+ return ;
265+ }
266+ }
267+ None => {
268+ // We haven't served FCU with attributes yet, just ignore flashblocks
269+ debug ! (
270+ message = "Received flashblocks, but no FCU with attributes was sent" ,
271+ payload_id = %payload. payload_id,
272+ index = payload. index,
273+ ) ;
274+ return ;
275+ }
261276 }
262277
263278 if let Err ( e) = self . best_payload . write ( ) . await . extend ( payload. clone ( ) ) {
@@ -311,11 +326,11 @@ impl EngineApiExt for FlashblocksService {
311326
312327 if let Some ( payload_id) = resp. payload_id {
313328 let current_payload = * self . current_payload_id . read ( ) . await ;
314- if current_payload != payload_id {
329+ if current_payload != Some ( payload_id) {
315330 tracing:: error!(
316331 message = "Payload id returned by builder differs from calculated. Using builder payload id" ,
317332 builder_payload_id = %payload_id,
318- calculated_payload_id = %current_payload,
333+ calculated_payload_id = %current_payload. unwrap_or_default ( ) ,
319334 ) ;
320335 self . set_current_payload_id ( payload_id) . await ;
321336 } else {
@@ -420,7 +435,7 @@ mod tests {
420435 FlashblocksService :: new ( builder_client, "127.0.0.1:8001" . parse ( ) . unwrap ( ) ) . unwrap ( ) ;
421436
422437 // Some "random" payload id
423- * service. current_payload_id . write ( ) . await = PayloadId :: new ( [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ) ;
438+ * service. current_payload_id . write ( ) . await = Some ( PayloadId :: new ( [ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 ] ) ) ;
424439
425440 // We ensure that request will skip rollup-boost and serve payload from backup if payload id
426441 // don't match
0 commit comments