flashbots / flashbots/rbuilder

feat: save and load partial blocks from a cache

Open
#227 2 comments 0 reactions 0 assignees View on GitHub
A-builder
Dominant language
Rust
Stars
567
Forks
209
PR merge metrics
No merged PRs in 30d

Description

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](https://github.com/flashbots/rbuilder/blob/develop/crates/rbuilder/src/building/builders/parallel_builder/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>,
pub state: Arc,
pub execution_results: Vec,
}

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

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.