@@ -1416,51 +1416,53 @@ impl<TX: DbTx> BlockReader for DatabaseProvider<TX> {
1416
1416
let len = range. end ( ) . saturating_sub ( * range. start ( ) ) as usize ;
1417
1417
let mut blocks = Vec :: with_capacity ( len) ;
1418
1418
1419
- let mut headers_cursor = self . tx . cursor_read :: < tables :: Headers > ( ) ?;
1419
+ let headers = self . headers_range ( range ) ?;
1420
1420
let mut ommers_cursor = self . tx . cursor_read :: < tables:: BlockOmmers > ( ) ?;
1421
1421
let mut withdrawals_cursor = self . tx . cursor_read :: < tables:: BlockWithdrawals > ( ) ?;
1422
1422
let mut block_body_cursor = self . tx . cursor_read :: < tables:: BlockBodyIndices > ( ) ?;
1423
1423
let mut tx_cursor = self . tx . cursor_read :: < tables:: Transactions > ( ) ?;
1424
1424
1425
- for num in range {
1426
- if let Some ( ( _, header) ) = headers_cursor. seek_exact ( num) ? {
1427
- // If the body indices are not found, this means that the transactions either do
1428
- // not exist in the database yet, or they do exit but are
1429
- // not indexed. If they exist but are not indexed, we don't
1430
- // have enough information to return the block anyways, so
1431
- // we skip the block.
1432
- if let Some ( ( _, block_body_indices) ) = block_body_cursor. seek_exact ( num) ? {
1433
- let tx_range = block_body_indices. tx_num_range ( ) ;
1434
- let body = if tx_range. is_empty ( ) {
1435
- Vec :: new ( )
1425
+ for header in headers {
1426
+ // If the body indices are not found, this means that the transactions either do
1427
+ // not exist in the database yet, or they do exit but are
1428
+ // not indexed. If they exist but are not indexed, we don't
1429
+ // have enough information to return the block anyways, so
1430
+ // we skip the block.
1431
+ if let Some ( ( _, block_body_indices) ) = block_body_cursor. seek_exact ( header. number ) ? {
1432
+ let tx_range = block_body_indices. tx_num_range ( ) ;
1433
+ let body = if tx_range. is_empty ( ) {
1434
+ Vec :: new ( )
1435
+ } else {
1436
+ self . transactions_by_tx_range_with_cursor ( tx_range, & mut tx_cursor) ?
1437
+ . into_iter ( )
1438
+ . map ( Into :: into)
1439
+ . collect ( )
1440
+ } ;
1441
+
1442
+ // If we are past shanghai, then all blocks should have a withdrawal list,
1443
+ // even if empty
1444
+ let withdrawals =
1445
+ if self . chain_spec . is_shanghai_active_at_timestamp ( header. timestamp ) {
1446
+ Some (
1447
+ withdrawals_cursor
1448
+ . seek_exact ( header. number ) ?
1449
+ . map ( |( _, w) | w. withdrawals )
1450
+ . unwrap_or_default ( ) ,
1451
+ )
1436
1452
} else {
1437
- self . transactions_by_tx_range_with_cursor ( tx_range, & mut tx_cursor) ?
1438
- . into_iter ( )
1439
- . map ( Into :: into)
1440
- . collect ( )
1453
+ None
1441
1454
} ;
1442
-
1443
- // If we are past shanghai, then all blocks should have a withdrawal list,
1444
- // even if empty
1445
- let withdrawals =
1446
- if self . chain_spec . is_shanghai_active_at_timestamp ( header. timestamp ) {
1447
- Some (
1448
- withdrawals_cursor
1449
- . seek_exact ( num) ?
1450
- . map ( |( _, w) | w. withdrawals )
1451
- . unwrap_or_default ( ) ,
1452
- )
1453
- } else {
1454
- None
1455
- } ;
1456
- let ommers = if self . chain_spec . final_paris_total_difficulty ( num) . is_some ( ) {
1455
+ let ommers =
1456
+ if self . chain_spec . final_paris_total_difficulty ( header. number ) . is_some ( ) {
1457
1457
Vec :: new ( )
1458
1458
} else {
1459
- ommers_cursor. seek_exact ( num) ?. map ( |( _, o) | o. ommers ) . unwrap_or_default ( )
1459
+ ommers_cursor
1460
+ . seek_exact ( header. number ) ?
1461
+ . map ( |( _, o) | o. ommers )
1462
+ . unwrap_or_default ( )
1460
1463
} ;
1461
1464
1462
- blocks. push ( Block { header, body, ommers, withdrawals } ) ;
1463
- }
1465
+ blocks. push ( Block { header, body, ommers, withdrawals } ) ;
1464
1466
}
1465
1467
}
1466
1468
Ok ( blocks)
0 commit comments