Skip to content

feat: save and load partial blocks from a cache #227

Open
@bertmiller

Description

@bertmiller

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:

#[derive(Debug)]
pub struct PartialBlockStateCache {
    pub partial_block: Arc<PartialBlock<GasUsedSimulationTracer>>,
    pub state: Arc<CachedSimulationState>,
    pub execution_results: Vec<ExecutionResult>,
}

/// An inner cache of partial blocks, keyed by a vector of order IDs.
#[derive(Debug, Default)]
struct PartialBlockCache {
    inner_cache: DashMap<Vec<OrderId>, Arc<PartialBlockStateCache>>,
}

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-builderIssues related to the core block building protocol

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions