linera-protocol
linera-protocol copied to clipboard
Cache staged executions of the next block
Motivation:
- Most validators executing a certified block have already voted on the proposal.
- Similarly, clients call
handle_block_proposallocally at the beginning of block creation and callhandle_certificateat the end. - On top of that, clients might stage the execution of a block even before calling
handle_block_proposallocally (for a final verification).
Concretely, we could cache the value of ChainStateView just before it is rolled back in handle_block_proposal.
I will add a single cache to WorkerState, next to the block cache, for now.
(Both caches would work equally well if they were split up into one cache per chain, of course. This would prevent one chain evicting another chain's entries, but it would make it harder to control the total cache size.)
Minor issue: ValueCache requires V: Clone. ExecutionStateView isn't Clone, because ClonableView::clone_unchecked can fail. This is due to the ReentrantByteCollectionView, which tries locking an async RwLock.
So I'm going to remove the V: Clone requirement from ValueCache, and move it to only the get method. (Needed because the actual LruCache is inside a mutex.) I'll add a new take method that removes the value. In the case of a block proposal, I'll just re-insert it. In the case of a confirmed block, we want to remove it anyway.