Struct zksync_consensus_storage::BlockStore
source · pub struct BlockStore { /* private fields */ }
Expand description
A wrapper around a PersistentBlockStore which adds caching blocks in-memory and other useful utilities.
Implementations§
source§impl BlockStore
impl BlockStore
sourcepub async fn new(
ctx: &Ctx,
persistent: Box<dyn PersistentBlockStore>,
) -> Result<(Arc<Self>, BlockStoreRunner)>
pub async fn new( ctx: &Ctx, persistent: Box<dyn PersistentBlockStore>, ) -> Result<(Arc<Self>, BlockStoreRunner)>
Constructs a BlockStore. BlockStore takes ownership of the passed PersistentBlockStore, i.e. caller should modify the underlying persistent storage ONLY through the constructed BlockStore.
sourcepub fn queued(&self) -> BlockStoreState
pub fn queued(&self) -> BlockStoreState
Available blocks (in memory & persisted).
sourcepub async fn block(
&self,
ctx: &Ctx,
number: BlockNumber,
) -> Result<Option<FinalBlock>>
pub async fn block( &self, ctx: &Ctx, number: BlockNumber, ) -> Result<Option<FinalBlock>>
Fetches a block (from queue or persistent storage).
sourcepub async fn queue_block(&self, ctx: &Ctx, block: FinalBlock) -> Result<()>
pub async fn queue_block(&self, ctx: &Ctx, block: FinalBlock) -> Result<()>
Append block to a queue to be persisted eventually.
Since persisting a block may take a significant amount of time,
BlockStore contains a queue of blocks waiting to be persisted.
queue_block()
adds a block to the queue as soon as all intermediate
blocks are queued_state as well. Queue is unbounded, so it is caller’s
responsibility to manage the queue size.
sourcepub async fn wait_for_queued_change(
&self,
ctx: &Ctx,
old: &BlockStoreState,
) -> OrCanceled<BlockStoreState>
pub async fn wait_for_queued_change( &self, ctx: &Ctx, old: &BlockStoreState, ) -> OrCanceled<BlockStoreState>
Waits until the queued blocks range is different than old
.
sourcepub async fn wait_until_queued(
&self,
ctx: &Ctx,
number: BlockNumber,
) -> OrCanceled<BlockStoreState>
pub async fn wait_until_queued( &self, ctx: &Ctx, number: BlockNumber, ) -> OrCanceled<BlockStoreState>
Waits until the given block is queued (in memory, or persisted). Note that it doesn’t mean that the block is actually available, as old blocks might get pruned.
sourcepub async fn wait_until_persisted(
&self,
ctx: &Ctx,
number: BlockNumber,
) -> OrCanceled<BlockStoreState>
pub async fn wait_until_persisted( &self, ctx: &Ctx, number: BlockNumber, ) -> OrCanceled<BlockStoreState>
Waits until the given block is stored persistently. Note that it doesn’t mean that the block is actually available, as old blocks might get pruned.