mirror of
https://github.com/hl-archive-node/nanoreth.git
synced 2025-12-06 19:09:54 +00:00
chore(storage): use chain spec from provider field (#7723)
This commit is contained in:
@ -285,7 +285,7 @@ impl Command {
|
||||
{
|
||||
provider_factory
|
||||
.provider_rw()?
|
||||
.take_block_and_execution_range(&self.chain, next_block..=target_block)?;
|
||||
.take_block_and_execution_range(next_block..=target_block)?;
|
||||
}
|
||||
|
||||
// Update latest block
|
||||
|
||||
@ -126,7 +126,7 @@ impl Command {
|
||||
let provider = provider_factory.provider_rw()?;
|
||||
|
||||
let _ = provider
|
||||
.take_block_and_execution_range(&self.chain, range.clone())
|
||||
.take_block_and_execution_range(range.clone())
|
||||
.map_err(|err| eyre::eyre!("Transaction error on unwind: {err}"))?;
|
||||
|
||||
provider.commit()?;
|
||||
|
||||
@ -1213,10 +1213,7 @@ where
|
||||
info!(target: "blockchain_tree", "REORG: revert canonical from database by unwinding chain blocks {:?}", revert_range);
|
||||
// read block and execution result from database. and remove traces of block from tables.
|
||||
let blocks_and_execution = provider_rw
|
||||
.take_block_and_execution_range(
|
||||
self.externals.provider_factory.chain_spec().as_ref(),
|
||||
revert_range,
|
||||
)
|
||||
.take_block_and_execution_range(revert_range)
|
||||
.map_err(|e| CanonicalError::CanonicalRevert(e.to_string()))?;
|
||||
|
||||
provider_rw.commit()?;
|
||||
|
||||
@ -709,7 +709,6 @@ impl<TX: DbTxMut + DbTx> DatabaseProvider<TX> {
|
||||
/// Return range of blocks and its execution result
|
||||
fn get_take_block_range<const TAKE: bool>(
|
||||
&self,
|
||||
chain_spec: &ChainSpec,
|
||||
range: impl RangeBounds<BlockNumber> + Clone,
|
||||
) -> ProviderResult<Vec<SealedBlockWithSenders>> {
|
||||
// For block we need Headers, Bodies, Uncles, withdrawals, Transactions, Signers
|
||||
@ -768,7 +767,8 @@ impl<TX: DbTxMut + DbTx> DatabaseProvider<TX> {
|
||||
};
|
||||
|
||||
// withdrawal can be missing
|
||||
let shanghai_is_active = chain_spec.is_shanghai_active_at_timestamp(header.timestamp);
|
||||
let shanghai_is_active =
|
||||
self.chain_spec.is_shanghai_active_at_timestamp(header.timestamp);
|
||||
let mut withdrawals = Some(Withdrawals::default());
|
||||
if shanghai_is_active {
|
||||
if let Some((block_number, _)) = block_withdrawals.as_ref() {
|
||||
@ -2376,7 +2376,6 @@ impl<TX: DbTxMut + DbTx> BlockExecutionWriter for DatabaseProvider<TX> {
|
||||
/// Return range of blocks and its execution result
|
||||
fn get_or_take_block_and_execution_range<const TAKE: bool>(
|
||||
&self,
|
||||
chain_spec: &ChainSpec,
|
||||
range: RangeInclusive<BlockNumber>,
|
||||
) -> ProviderResult<Chain> {
|
||||
if TAKE {
|
||||
@ -2447,7 +2446,7 @@ impl<TX: DbTxMut + DbTx> BlockExecutionWriter for DatabaseProvider<TX> {
|
||||
}
|
||||
|
||||
// get blocks
|
||||
let blocks = self.get_take_block_range::<TAKE>(chain_spec, range.clone())?;
|
||||
let blocks = self.get_take_block_range::<TAKE>(range.clone())?;
|
||||
let unwind_to = blocks.first().map(|b| b.number.saturating_sub(1));
|
||||
// get execution res
|
||||
let execution_state = self.unwind_or_peek_state::<TAKE>(range.clone())?;
|
||||
|
||||
@ -6,8 +6,8 @@ use auto_impl::auto_impl;
|
||||
use reth_db::models::StoredBlockBodyIndices;
|
||||
use reth_interfaces::provider::ProviderResult;
|
||||
use reth_primitives::{
|
||||
Block, BlockHashOrNumber, BlockId, BlockNumber, BlockNumberOrTag, BlockWithSenders, ChainSpec,
|
||||
Header, PruneModes, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader, B256,
|
||||
Block, BlockHashOrNumber, BlockId, BlockNumber, BlockNumberOrTag, BlockWithSenders, Header,
|
||||
PruneModes, Receipt, SealedBlock, SealedBlockWithSenders, SealedHeader, B256,
|
||||
};
|
||||
use reth_trie::{updates::TrieUpdates, HashedPostState};
|
||||
use std::ops::RangeInclusive;
|
||||
@ -268,25 +268,22 @@ pub trait BlockExecutionWriter: BlockWriter + BlockReader + Send + Sync {
|
||||
/// Get range of blocks and its execution result
|
||||
fn get_block_and_execution_range(
|
||||
&self,
|
||||
chain_spec: &ChainSpec,
|
||||
range: RangeInclusive<BlockNumber>,
|
||||
) -> ProviderResult<Chain> {
|
||||
self.get_or_take_block_and_execution_range::<false>(chain_spec, range)
|
||||
self.get_or_take_block_and_execution_range::<false>(range)
|
||||
}
|
||||
|
||||
/// Take range of blocks and its execution result
|
||||
fn take_block_and_execution_range(
|
||||
&self,
|
||||
chain_spec: &ChainSpec,
|
||||
range: RangeInclusive<BlockNumber>,
|
||||
) -> ProviderResult<Chain> {
|
||||
self.get_or_take_block_and_execution_range::<true>(chain_spec, range)
|
||||
self.get_or_take_block_and_execution_range::<true>(range)
|
||||
}
|
||||
|
||||
/// Return range of blocks and its execution result
|
||||
fn get_or_take_block_and_execution_range<const TAKE: bool>(
|
||||
&self,
|
||||
chain_spec: &ChainSpec,
|
||||
range: RangeInclusive<BlockNumber>,
|
||||
) -> ProviderResult<Chain>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user