-
Notifications
You must be signed in to change notification settings - Fork 88
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: save and load partial blocks from a cache #227
Comments
If you take this one up, make sure to get buy in on designs from the team. |
Interested in taking this! I've taken your suggestion from the comments and landed on the following design, please let me know what you and the team think about this one @bertmiller :
#[derive(Default)]
pub struct PartialBlockCache {
index: HashMap<OrderId, usize>,
nodes: Vec<Node>,
cursor: Cursor,
}
struct Node {
children_index: HashMap<OrderId, usize>,
data: Box<PartialBlockStateCache>
}
#[derive(Debug)]
pub struct PartialBlockStateCache {
pub partial_block: PartialBlock<GasUsedSimulationTracer>,
pub state: CachedSimulationState,
pub execution_result: ExecutionResult,
}
Also, There's one more element to the suggested design: pub struct BBHFPWithCache<'a, P, DB>
where
DB: Database + Clone + 'static,
P: DatabaseProviderFactory<DB> + StateProviderFactory + Clone + 'static,
{
block_builder: BlockBuildingHelperFromProvider<P, DB>,
cache: &'a mut PartialBlockCache,
} (name is a work in progress, but it stands for Then the workflow is as follows:
A couple of main things about this design:
|
Often times in the process of building a block the top of the block will be the same as a previous block. In that case, we should be able to reload a previously built block's state instead of reconstructing it ourselves by reapplying however many orders. In turn, that will make the process of building faster - especially where we're just appending new transactions or something similar.
For an example of a cache, see simulation_cache.rs used in the parallel builder. We can use a similar idea, except we need to store the full partial block. A possible struct could be this:
Then we'd need to implement a new building helper to load/save from this cache.
In testing a design for this on the mempool I found a significant reduction in building times, from 11ms on average to just 2ms. The reason is that for many blocks we were just appending mempool txs at the end instead of rebuilding the whole thing. With loading from the cache that reduces the time to construct a new block with a new mempool tx to less than 1ms instead of 10+ms.
The text was updated successfully, but these errors were encountered: