mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 10:59:55 +00:00
feat: extend BlockBodyIndicesProvider with block_body_indices_range (#13829)
This commit is contained in:
@ -112,8 +112,7 @@ impl<D: BodyDownloader> BodyStage<D> {
|
||||
// fix the inconsistency right away.
|
||||
if let Some(unwind_to) = unwind_block {
|
||||
let next_tx_num_after_unwind = provider
|
||||
.tx_ref()
|
||||
.get::<tables::BlockBodyIndices>(unwind_to)?
|
||||
.block_body_indices(unwind_to)?
|
||||
.map(|b| b.next_tx_num())
|
||||
.ok_or(ProviderError::BlockBodyIndicesNotFound(unwind_to))?;
|
||||
|
||||
|
||||
@ -5,7 +5,6 @@ use alloy_primitives::BlockNumber;
|
||||
use num_traits::Zero;
|
||||
use reth_config::config::ExecutionConfig;
|
||||
use reth_db::{static_file::HeaderMask, tables};
|
||||
use reth_db_api::{cursor::DbCursorRO, transaction::DbTx};
|
||||
use reth_evm::{
|
||||
execute::{BatchExecutor, BlockExecutorProvider},
|
||||
metrics::ExecutorMetrics,
|
||||
@ -203,12 +202,8 @@ where
|
||||
}
|
||||
|
||||
// Get next expected receipt number
|
||||
let tx = provider.tx_ref();
|
||||
let next_receipt_num = tx
|
||||
.cursor_read::<tables::BlockBodyIndices>()?
|
||||
.seek_exact(checkpoint)?
|
||||
.map(|(_, value)| value.next_tx_num())
|
||||
.unwrap_or(0);
|
||||
let next_receipt_num =
|
||||
provider.block_body_indices(checkpoint)?.map(|b| b.next_tx_num()).unwrap_or(0);
|
||||
|
||||
let static_file_provider = provider.static_file_provider();
|
||||
|
||||
@ -237,8 +232,7 @@ where
|
||||
// fix the inconsistency right away.
|
||||
if let Some(unwind_to) = unwind_to {
|
||||
let next_receipt_num_after_unwind = provider
|
||||
.tx_ref()
|
||||
.get::<tables::BlockBodyIndices>(unwind_to)?
|
||||
.block_body_indices(unwind_to)?
|
||||
.map(|b| b.next_tx_num())
|
||||
.ok_or(ProviderError::BlockBodyIndicesNotFound(unwind_to))?;
|
||||
|
||||
@ -645,6 +639,7 @@ mod tests {
|
||||
use alloy_rlp::Decodable;
|
||||
use assert_matches::assert_matches;
|
||||
use reth_chainspec::ChainSpecBuilder;
|
||||
use reth_db::transaction::DbTx;
|
||||
use reth_db_api::{models::AccountBeforeTx, transaction::DbTxMut};
|
||||
use reth_evm::execute::BasicBlockExecutorProvider;
|
||||
use reth_evm_ethereum::execute::EthExecutionStrategyFactory;
|
||||
|
||||
@ -5,7 +5,7 @@ use reth_config::config::{EtlConfig, TransactionLookupConfig};
|
||||
use reth_db::{table::Value, tables, RawKey, RawValue};
|
||||
use reth_db_api::{
|
||||
cursor::{DbCursorRO, DbCursorRW},
|
||||
transaction::{DbTx, DbTxMut},
|
||||
transaction::DbTxMut,
|
||||
};
|
||||
use reth_etl::Collector;
|
||||
use reth_primitives::NodePrimitives;
|
||||
@ -195,12 +195,16 @@ where
|
||||
let tx = provider.tx_ref();
|
||||
let (range, unwind_to, _) = input.unwind_block_range_with_threshold(self.chunk_size);
|
||||
|
||||
// Cursors to unwind tx hash to number
|
||||
let mut body_cursor = tx.cursor_read::<tables::BlockBodyIndices>()?;
|
||||
// Cursor to unwind tx hash to number
|
||||
let mut tx_hash_number_cursor = tx.cursor_write::<tables::TransactionHashNumbers>()?;
|
||||
let static_file_provider = provider.static_file_provider();
|
||||
let mut rev_walker = body_cursor.walk_back(Some(*range.end()))?;
|
||||
while let Some((number, body)) = rev_walker.next().transpose()? {
|
||||
let rev_walker = provider
|
||||
.block_body_indices_range(range.clone())?
|
||||
.into_iter()
|
||||
.zip(range.collect::<Vec<_>>())
|
||||
.rev();
|
||||
|
||||
for (body, number) in rev_walker {
|
||||
if number <= unwind_to {
|
||||
break;
|
||||
}
|
||||
@ -255,6 +259,7 @@ mod tests {
|
||||
};
|
||||
use alloy_primitives::{BlockNumber, B256};
|
||||
use assert_matches::assert_matches;
|
||||
use reth_db::transaction::DbTx;
|
||||
use reth_primitives::SealedBlock;
|
||||
use reth_provider::{
|
||||
providers::StaticFileWriter, BlockBodyIndicesProvider, DatabaseProviderFactory,
|
||||
|
||||
Reference in New Issue
Block a user