diff --git a/linera-chain/src/outbox.rs b/linera-chain/src/outbox.rs index 9043796301d..593f2c82075 100644 --- a/linera-chain/src/outbox.rs +++ b/linera-chain/src/outbox.rs @@ -6,7 +6,7 @@ use linera_base::data_types::{ArithmeticError, BlockHeight}; use linera_views::context::{create_test_memory_context, MemoryContext}; use linera_views::{ context::Context, - queue_view::QueueView, + bucket_queue_view::BucketQueueView, register_view::RegisterView, views::{ClonableView, View, ViewError}, }; @@ -15,6 +15,12 @@ use linera_views::{ #[path = "unit_tests/outbox_tests.rs"] mod outbox_tests; +// The number of block heights in a bucket +// The `BlockHeight` has just 8 bytes so the size is constant. +// This means that by choosing a size of 1000, we have a +// reasonable size that will not create any memory issues. +const BLOCKHEIGHT_BUCKET_SIZE: usize = 1000; + /// The state of an outbox /// * An outbox is used to send messages to another chain. /// * Internally, this is implemented as a FIFO queue of (increasing) block heights. @@ -31,7 +37,7 @@ where pub next_height_to_schedule: RegisterView, /// Keep sending these certified blocks of ours until they are acknowledged by /// receivers. - pub queue: QueueView, + pub queue: BucketQueueView, } impl OutboxStateView @@ -59,11 +65,11 @@ where height: BlockHeight, ) -> Result, ViewError> { let mut updates = Vec::new(); - while let Some(h) = self.queue.front().await? { + while let Some(h) = self.queue.front().cloned() { if h > height { break; } - self.queue.delete_front(); + self.queue.delete_front().await?; updates.push(h); } Ok(updates) diff --git a/linera-core/src/chain_worker/state/mod.rs b/linera-core/src/chain_worker/state/mod.rs index 7ba248ee712..de56d737c6f 100644 --- a/linera-core/src/chain_worker/state/mod.rs +++ b/linera-core/src/chain_worker/state/mod.rs @@ -530,8 +530,8 @@ where let outboxes = self.chain.outboxes.try_load_entries(&targets).await?; for outbox in outboxes { let outbox = outbox.expect("Only existing outboxes should be referenced by `indices`"); - let front = outbox.queue.front().await?; - if front.is_some_and(|key| key <= height) { + let front = outbox.queue.front(); + if front.is_some_and(|key| *key <= height) { return Ok(false); } }