Skip to content
This repository has been archived by the owner on Feb 6, 2025. It is now read-only.

Commit

Permalink
reslove dirty cache issue
Browse files Browse the repository at this point in the history
  • Loading branch information
forcodedancing committed Aug 21, 2024
1 parent acd701c commit 36bcfd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
5 changes: 1 addition & 4 deletions crates/blockchain-tree/src/blockchain_tree.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Implementation of [`BlockchainTree`]
use crate::{
canonical_cache::{apply_bundle_state, clear_accounts_and_storages},
canonical_cache::apply_bundle_state,
metrics::{MakeCanonicalAction, MakeCanonicalDurationsRecorder, TreeMetrics},
state::{BlockchainId, TreeState},
AppendableChain, BlockIndices, BlockchainTreeConfig, ExecutionData, TreeExternals,
Expand Down Expand Up @@ -1344,9 +1344,6 @@ where

provider_rw.commit()?;

// clear global canonical cache
clear_accounts_and_storages();

if blocks_and_execution.is_empty() {
Ok(None)
} else {
Expand Down
11 changes: 10 additions & 1 deletion crates/blockchain-tree/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
//! blocks, as well as a list of the blocks the chain is composed of.
use super::externals::TreeExternals;
use crate::{canonical_cache::CachedBundleStateProvider, BundleStateDataRef};
use crate::{
canonical_cache::{clear_accounts_and_storages, CachedBundleStateProvider},
BundleStateDataRef,
};
use reth_blockchain_tree_api::{
error::{BlockchainTreeError, InsertBlockErrorKind},
BlockAttachment, BlockValidationKind,
Expand Down Expand Up @@ -81,6 +84,12 @@ impl AppendableChain {
let execution_outcome = ExecutionOutcome::default();
let empty = BTreeMap::new();

if block_attachment == BlockAttachment::HistoricalFork {
// The fork is a historical fork, the global canonical cache could be dirty.
// The case should be rare for bsc & op.
clear_accounts_and_storages();
}

let state_provider = BundleStateDataRef {
execution_outcome: &execution_outcome,
sidechain_block_hashes: &empty,
Expand Down

0 comments on commit 36bcfd1

Please sign in to comment.