Skip to content

Commit 3e57981

Browse files
authored
Implement cached reads (#75)
* Initial implementation with dashmaps * Rework to use CachedStateProvider * fmt * clippy * clippy * remove deadcode * fix clippy * fmt * info! * info! * Preload caches * Clean up test
1 parent f4abbf1 commit 3e57981

File tree

6 files changed

+624
-7
lines changed

6 files changed

+624
-7
lines changed

src/payload/block.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ impl<P: Platform> BlockContext<P> {
6969
attribs: types::PayloadBuilderAttributes<P>,
7070
base_state: StateProviderBox,
7171
chainspec: Arc<types::ChainSpec<P>>,
72+
cached: Option<ExecutionCache>,
7273
) -> Result<Self, Error<P>> {
7374
let block_env = P::next_block_environment_context::<P>(
7475
&chainspec,
@@ -81,8 +82,11 @@ impl<P: Platform> BlockContext<P> {
8182
.next_evm_env(&parent, &block_env)
8283
.map_err(Error::EvmEnv)?;
8384

85+
let execution_cached = cached.unwrap_or_default();
86+
let provider =
87+
CachedStateProvider::new_with_caches(base_state, execution_cached);
8488
let mut base_state = State::builder()
85-
.with_database(StateProviderDatabase(base_state))
89+
.with_database(StateProviderDatabase(provider))
8690
.with_bundle_update()
8791
.build();
8892

@@ -202,7 +206,8 @@ struct BlockContextInner<P: Platform> {
202206
///
203207
/// This state has no changes made to it during the payload building process
204208
/// through any of the created checkpoints.
205-
base_state: State<StateProviderDatabase<StateProviderBox>>,
209+
base_state:
210+
State<StateProviderDatabase<CachedStateProvider<StateProviderBox>>>,
206211

207212
/// The EVM factory configured for the environment in which we are building
208213
/// the payload. This type is used to create individual EVM instances that

0 commit comments

Comments
 (0)