@@ -1412,9 +1412,15 @@ pub async fn get_blocks_v3(
14121412 let skip_randao_verification = query_params. skip_randao_verification . unwrap_or ( false ) ;
14131413 let builder_boost_factor = query_params. builder_boost_factor . unwrap_or ( 100 ) ;
14141414
1415- let mut state = db. get_latest_state ( ) . map_err ( |err| {
1416- ApiError :: InternalError ( format ! ( "Unable to fetch the latest state: {err}" ) )
1417- } ) ?;
1415+ let store = Store :: new ( db. get_ref ( ) . clone ( ) , operation_pool. get_ref ( ) . clone ( ) , None ) ;
1416+ let head_root = store
1417+ . get_head ( )
1418+ . map_err ( |err| ApiError :: InternalError ( format ! ( "Failed to get head root: {err:?}" ) ) ) ?;
1419+ let mut state = db
1420+ . state_provider ( )
1421+ . get ( head_root)
1422+ . map_err ( |err| ApiError :: InternalError ( format ! ( "Failed to get state, error: {err:?}" ) ) ) ?
1423+ . ok_or_else ( || ApiError :: NotFound ( format ! ( "Failed to find state for root {head_root}" ) ) ) ?;
14181424
14191425 let current_slot = state. slot ;
14201426
@@ -1424,6 +1430,11 @@ pub async fn get_blocks_v3(
14241430 ) ) ;
14251431 }
14261432
1433+ // Process slots to get state at the requested slot.
1434+ state
1435+ . process_slots ( slot)
1436+ . map_err ( |err| ApiError :: InternalError ( format ! ( "Failed to process slots: {err}" ) ) ) ?;
1437+
14271438 let proposer_index = state. get_beacon_proposer_index ( Some ( slot) ) . map_err ( |err| {
14281439 ApiError :: InternalError ( format ! (
14291440 "Failed to get the proposer index for slot {slot}: {err}" ,
@@ -1446,11 +1457,6 @@ pub async fn get_blocks_v3(
14461457 & proposer_public_key,
14471458 ) ?;
14481459
1449- // Process slots to get state at the requested slot
1450- state
1451- . process_slots ( slot)
1452- . map_err ( |err| ApiError :: InternalError ( format ! ( "Failed to process slots: {err}" ) ) ) ?;
1453-
14541460 let fee_recipient = operation_pool
14551461 . get_proposer_preparation ( proposer_index)
14561462 . unwrap_or ( Address :: ZERO ) ;
0 commit comments