Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: preload cachedreads with tip state #5804

Merged
merged 23 commits into from
Jan 9, 2024

Conversation

allnil
Copy link
Contributor

@allnil allnil commented Dec 17, 2023

draft PR for cache reads preload

Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great start so far!

we likely need more changes in the BasicPayloadGenerator which now needs a CachedReads and needs to use that to the instantiate a job if the parent_hash matches

bin/reth/src/cli/ext.rs Outdated Show resolved Hide resolved
crates/payload/builder/src/service.rs Show resolved Hide resolved
@rkrasiuk rkrasiuk added C-perf A change motivated by improving speed, memory usage or disk footprint A-block-building Related to block building labels Dec 18, 2023
crates/payload/builder/src/service.rs Outdated Show resolved Hide resolved
@allnil allnil requested a review from mattsse December 22, 2023 18:26
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

functionality wise this is exactly what we want!

this just needs a few more changes

crates/payload/builder/src/service.rs Outdated Show resolved Hide resolved
crates/payload/builder/src/traits.rs Outdated Show resolved Hide resolved
crates/payload/basic/src/lib.rs Outdated Show resolved Hide resolved
@mattsse
Copy link
Collaborator

mattsse commented Dec 29, 2023

sorry about the conflicts -.-

@mattsse mattsse changed the title Feat/preload cached reads feat: preload cachedreads with tip state Jan 9, 2024
@mattsse mattsse marked this pull request as ready for review January 9, 2024 12:52
@mattsse mattsse requested a review from Rjected as a code owner January 9, 2024 12:52
Comment on lines 207 to 226
fn on_new_state(&mut self, new_state: CanonStateNotification) {
if let Some(committed) = new_state.committed() {
let mut cached = CachedReads::default();

// extract the state from the notification and put it into the cache
let new_state = committed.state();
for (addr, acc) in new_state.accounts_iter() {
if let Some(acc) = acc {
let storage = if let Some(acc) = new_state.state().account(&addr) {
acc.storage.iter().map(|(key, slot)| (*key, slot.present_value)).collect()
} else {
Default::default()
};
cached.insert_account(addr, acc.clone(), storage);
}
}

self.pre_cached = Some(PrecachedState { block: committed.tip().hash, cached });
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rakita @rkrasiuk could you please take a closer look here.

It's not really obvious to me how I can get the plain state (account, accountstorage) from the Bundlestate

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general this is okay, but would add helper function to BundleStateWithReceipts to make it more obvious, maybe something like fn bundle_account_iter().

To point out, the bundle state contains only written accounts, not the reads, but it is still better than nothing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattsse you can create a new method accounts_with_storage_iter to make it easier. @rakita made good point that these are only writes, but that's better than nothing

Copy link
Member

@rkrasiuk rkrasiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mattsse mattsse added this pull request to the merge queue Jan 9, 2024
Merged via the queue into paradigmxyz:main with commit 514750f Jan 9, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-block-building Related to block building C-perf A change motivated by improving speed, memory usage or disk footprint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants