Skip to content

Commit

Permalink
cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
pompon0 committed Oct 8, 2024
1 parent 4f5f35c commit 0ddd54f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
12 changes: 7 additions & 5 deletions node/libs/storage/src/block_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,16 +176,16 @@ impl Inner {

/// If cache size has been exceeded, remove entries which were already persisted.
fn truncate_cache(&mut self) {
while self.cache.len() > CACHE_CAPACITY
&& self.persisted.next() > self.cache[0].number()
{
while self.cache.len() > CACHE_CAPACITY && self.persisted.next() > self.cache[0].number() {
self.cache.pop_front();
}
}

fn block(&self, n: validator::BlockNumber) -> Option<validator::Block> {
let first = self.cache.front()?;
self.cache.get(n.0.checked_sub(first.number().0)? as usize).cloned()
self.cache
.get(n.0.checked_sub(first.number().0)? as usize)
.cloned()
}
}

Expand Down Expand Up @@ -357,7 +357,9 @@ impl BlockStore {
/// blocks are queued_state as well. Queue is unbounded, so it is caller's
/// responsibility to manage the queue size.
pub async fn queue_block(&self, ctx: &ctx::Ctx, block: validator::Block) -> ctx::Result<()> {
self.verify_block(ctx, &block).await.wrap("verify_block")?;
self.verify_block(ctx, &block)
.await
.with_wrap(|| format!("verify_block({})", block.number()))?;
sync::wait_for(ctx, &mut self.inner.subscribe(), |inner| {
inner.queued.next() >= block.number()
})
Expand Down
20 changes: 17 additions & 3 deletions node/libs/storage/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,25 @@ async fn test_get_not_cached_block() {
for block in &setup.blocks {
store.blocks.queue_block(ctx, block.clone()).await.unwrap();
}
store.blocks.wait_until_persisted(ctx, setup.blocks.last().as_ref().unwrap().number()).await.unwrap();
store
.blocks
.wait_until_persisted(ctx, setup.blocks.last().as_ref().unwrap().number())
.await
.unwrap();
// Request the first block (not in cache).
assert_eq!(setup.blocks[0], store.blocks.block(ctx, setup.blocks[0].number()).await.unwrap().unwrap());
assert_eq!(
setup.blocks[0],
store
.blocks
.block(ctx, setup.blocks[0].number())
.await
.unwrap()
.unwrap()
);
Ok(())
}).await.unwrap();
})
.await
.unwrap();
}

#[tokio::test]
Expand Down

0 comments on commit 0ddd54f

Please sign in to comment.