Skip to content

Commit

Permalink
Changes another entry in the queue.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik committed Dec 6, 2024
1 parent 0f9fdd9 commit be71395
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
14 changes: 10 additions & 4 deletions linera-chain/src/outbox.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand All @@ -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.
Expand All @@ -31,7 +37,7 @@ where
pub next_height_to_schedule: RegisterView<C, BlockHeight>,
/// Keep sending these certified blocks of ours until they are acknowledged by
/// receivers.
pub queue: QueueView<C, BlockHeight>,
pub queue: BucketQueueView<C, BlockHeight, BLOCKHEIGHT_BUCKET_SIZE>,
}

impl<C> OutboxStateView<C>
Expand Down Expand Up @@ -59,11 +65,11 @@ where
height: BlockHeight,
) -> Result<Vec<BlockHeight>, 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)
Expand Down
4 changes: 2 additions & 2 deletions linera-core/src/chain_worker/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit be71395

Please sign in to comment.