Skip to content

Commit

Permalink
Switch the "TimestampBundleInInbox" to BucketQueueView.
Browse files Browse the repository at this point in the history
  • Loading branch information
MathieuDutSik committed Dec 6, 2024
1 parent 5ff44e3 commit 0f9fdd9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
19 changes: 13 additions & 6 deletions linera-chain/src/chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ use linera_execution::{
use linera_views::{
context::Context,
log_view::LogView,
queue_view::QueueView,
bucket_queue_view::BucketQueueView,
reentrant_collection_view::ReentrantCollectionView,
register_view::RegisterView,
set_view::SetView,
Expand Down Expand Up @@ -179,6 +179,13 @@ impl BundleInInbox {
}
}

// The number of timestamp in a bucket
// The `TimestampedBundleInInbox` type contains 4 cryptohashes, 1 blockheight
// an index, two enums and the ChannelName. Only the ChannelName has an unbounded
// size but we can expect the size to be reasonably small, so a total size of 100
// seems reasonable for the storing of the data.
const TIMESTAMPBUNDLE_BUCKET_SIZE: usize = 100;

/// A view accessing the state of a chain.
#[derive(Debug, RootView, ClonableView, SimpleObject)]
#[graphql(cache_control(no_cache))]
Expand Down Expand Up @@ -208,7 +215,7 @@ where
/// Mailboxes used to receive messages indexed by their origin.
pub inboxes: ReentrantCollectionView<C, Origin, InboxStateView<C>>,
/// A queue of unskippable bundles, with the timestamp when we added them to the inbox.
pub unskippable_bundles: QueueView<C, TimestampedBundleInInbox>,
pub unskippable_bundles: BucketQueueView<C, TimestampedBundleInInbox, TIMESTAMPBUNDLE_BUCKET_SIZE>,
/// Unskippable bundles that have been removed but are still in the queue.
pub removed_unskippable_bundles: SetView<C, BundleInInbox>,
/// Mailboxes used to send messages, indexed by their target.
Expand Down Expand Up @@ -620,10 +627,10 @@ where
}
if !removed_unskippable.is_empty() {
// Delete all removed bundles from the front of the unskippable queue.
let maybe_front = self.unskippable_bundles.front().await?;
let maybe_front = self.unskippable_bundles.front();
if maybe_front.is_some_and(|ts_entry| removed_unskippable.remove(&ts_entry.entry)) {
self.unskippable_bundles.delete_front();
while let Some(ts_entry) = self.unskippable_bundles.front().await? {
self.unskippable_bundles.delete_front().await?;
while let Some(ts_entry) = self.unskippable_bundles.front() {
if !removed_unskippable.remove(&ts_entry.entry) {
if !self
.removed_unskippable_bundles
Expand All @@ -634,7 +641,7 @@ where
}
self.removed_unskippable_bundles.remove(&ts_entry.entry)?;
}
self.unskippable_bundles.delete_front();
self.unskippable_bundles.delete_front().await?;
}
}
for entry in removed_unskippable {
Expand Down
2 changes: 1 addition & 1 deletion linera-core/src/chain_worker/state/attempted_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ where
let chain = &mut self.state.chain;
if let (Some(epoch), Some(entry)) = (
chain.execution_state.system.epoch.get(),
chain.unskippable_bundles.front().await?,
chain.unskippable_bundles.front(),
) {
let ownership = chain.execution_state.system.ownership.get();
let elapsed = self
Expand Down
3 changes: 2 additions & 1 deletion linera-views/src/views/bucket_queue_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ impl Cursor {
}
}

#[derive(Clone)]
#[derive(Clone, Debug)]
enum Bucket<T> {
Loaded { data: Vec<T> },
NotLoaded { length: usize },
Expand Down Expand Up @@ -127,6 +127,7 @@ fn stored_indices<T>(stored_data: &VecDeque<(usize, Bucket<T>)>, position: usize
/// The size `N` has to be chosen by taking into account the size of the type `T`
/// and the basic size of a block. For example a total size of 100bytes to 10KB
/// seems adequate.
#[derive(Debug)]
pub struct BucketQueueView<C, T, const N: usize> {
context: C,
/// The buckets of stored data. If missing, then it has not been loaded. The first index is always loaded.
Expand Down

0 comments on commit 0f9fdd9

Please sign in to comment.