perf: remove unnecessary state clone (#4763)

This commit is contained in:
Roman Krasiuk
2023-09-25 16:48:48 +03:00
committed by GitHub
parent 1b17453261
commit 0f9def08c0
12 changed files with 15 additions and 15 deletions

View File

@ -210,7 +210,7 @@ impl AppendableChain {
// check state root if the block extends the canonical chain.
if block_kind.extends_canonical_head() {
// check state root
let state_root = provider.state_root(bundle_state.clone())?;
let state_root = provider.state_root(&bundle_state)?;
if block.state_root != state_root {
return Err(ConsensusError::BodyStateRootDiff {
got: state_root,

View File

@ -353,7 +353,7 @@ impl StorageInner {
let state_root = client
.latest()
.map_err(|_| BlockExecutionError::ProviderError)?
.state_root(bundle_state.clone())
.state_root(bundle_state)
.unwrap();
header.state_root = state_root;
Ok(header)

View File

@ -793,7 +793,7 @@ where
let logs_bloom = bundle.block_logs_bloom(block_number).expect("Number is in range");
// calculate the state root
let state_root = state_provider.state_root(bundle)?;
let state_root = state_provider.state_root(&bundle)?;
// create the block header
let transactions_root = proofs::calculate_transaction_root(&executed_txs);
@ -909,7 +909,7 @@ where
// calculate the state root
let bundle_state = BundleStateWithReceipts::new(db.take_bundle(), vec![], block_number);
let state_root = state.state_root(bundle_state)?;
let state_root = state.state_root(&bundle_state)?;
let header = Header {
parent_hash: parent_block.hash,

View File

@ -623,7 +623,7 @@ mod tests {
}
impl StateRootProvider for StateProviderTest {
fn state_root(&self, _bundle_state: BundleStateWithReceipts) -> RethResult<H256> {
fn state_root(&self, _bundle_state: &BundleStateWithReceipts) -> RethResult<H256> {
todo!()
}
}

View File

@ -193,7 +193,7 @@ impl PendingBlockEnv {
let logs_bloom = bundle.block_logs_bloom(block_number).expect("Block is present");
// calculate the state root
let state_root = state_provider.state_root(bundle)?;
let state_root = state_provider.state_root(&bundle)?;
// create the block header
let transactions_root = proofs::calculate_transaction_root(&executed_txs);

View File

@ -58,10 +58,10 @@ impl<SP: StateProvider, BSDP: BundleStateDataProvider> AccountReader
impl<SP: StateProvider, BSDP: BundleStateDataProvider> StateRootProvider
for BundleStateProvider<SP, BSDP>
{
fn state_root(&self, post_state: BundleStateWithReceipts) -> RethResult<H256> {
fn state_root(&self, post_state: &BundleStateWithReceipts) -> RethResult<H256> {
let mut state = self.post_state_data_provider.state().clone();
state.extend(post_state);
self.state_provider.state_root(state)
state.extend(post_state.clone());
self.state_provider.state_root(&state)
}
}

View File

@ -205,7 +205,7 @@ impl<'a, 'b, TX: DbTx<'a>> BlockHashReader for HistoricalStateProviderRef<'a, 'b
}
impl<'a, 'b, TX: DbTx<'a>> StateRootProvider for HistoricalStateProviderRef<'a, 'b, TX> {
fn state_root(&self, _post_state: BundleStateWithReceipts) -> RethResult<H256> {
fn state_root(&self, _post_state: &BundleStateWithReceipts) -> RethResult<H256> {
Err(ProviderError::StateRootNotAvailableForHistoricalBlock.into())
}
}

View File

@ -60,7 +60,7 @@ impl<'a, 'b, TX: DbTx<'a>> BlockHashReader for LatestStateProviderRef<'a, 'b, TX
}
impl<'a, 'b, TX: DbTx<'a>> StateRootProvider for LatestStateProviderRef<'a, 'b, TX> {
fn state_root(&self, bundle_state: BundleStateWithReceipts) -> RethResult<H256> {
fn state_root(&self, bundle_state: &BundleStateWithReceipts) -> RethResult<H256> {
bundle_state.state_root_slow(self.db).map_err(|err| RethError::Database(err.into()))
}
}

View File

@ -31,7 +31,7 @@ macro_rules! delegate_provider_impls {
$crate::providers::state::macros::delegate_impls_to_as_ref!(
for $target =>
StateRootProvider $(where [$($generics)*])? {
fn state_root(&self, state: crate::BundleStateWithReceipts) -> reth_interfaces::RethResult<reth_primitives::H256>;
fn state_root(&self, state: &crate::BundleStateWithReceipts) -> reth_interfaces::RethResult<reth_primitives::H256>;
}
AccountReader $(where [$($generics)*])? {
fn basic_account(&self, address: reth_primitives::Address) -> reth_interfaces::RethResult<Option<reth_primitives::Account>>;

View File

@ -476,7 +476,7 @@ impl AccountReader for MockEthProvider {
}
impl StateRootProvider for MockEthProvider {
fn state_root(&self, _state: BundleStateWithReceipts) -> RethResult<H256> {
fn state_root(&self, _state: &BundleStateWithReceipts) -> RethResult<H256> {
todo!()
}
}

View File

@ -253,7 +253,7 @@ impl ChangeSetReader for NoopProvider {
}
impl StateRootProvider for NoopProvider {
fn state_root(&self, _state: BundleStateWithReceipts) -> RethResult<H256> {
fn state_root(&self, _state: &BundleStateWithReceipts) -> RethResult<H256> {
todo!()
}
}

View File

@ -234,5 +234,5 @@ pub trait BundleStateDataProvider: Send + Sync {
#[auto_impl[Box,&, Arc]]
pub trait StateRootProvider: Send + Sync {
/// Returns the state root of the BundleState on top of the current state.
fn state_root(&self, post_state: BundleStateWithReceipts) -> RethResult<H256>;
fn state_root(&self, post_state: &BundleStateWithReceipts) -> RethResult<H256>;
}