queue.rs

Overview

The queue.rs file defines and implements the ExternalMessagesQueue struct, which manages a collection of external messages associated with unique stamps. The queue supports operations such as adding new messages, removing processed messages, and retrieving unprocessed messages grouped by account address. This functionality is critical for systems that handle ordered processing of external messages, ensuring messages are tracked by a timestamped index and organized per destination account.

Structs and Types

ExternalMessagesQueue

A data structure that holds external messages in an ordered map indexed by a Stamp. Each entry associates a Stamp with a tuple containing the destination account address and the wrapped message.

Public Methods

empty() -> ExternalMessagesQueue

Creates and returns a new empty ExternalMessagesQueue.


erase_processed(&mut self, processed: &[Stamp])

Removes messages from the queue that have been processed, identified by their Stamps.


push_external_messages(&mut self, messages: &[WrappedMessage], timestamp: DateTime<Utc>)

Adds a batch of external messages to the queue, assigning sequential stamps with the provided timestamp.


unprocessed_messages(&self) -> HashMap<AccountAddress, VecDeque<(Stamp, Message)>>

Retrieves all unprocessed messages grouped by their destination account addresses.

Important Implementation Details

Interactions with Other Parts of the System

Visual Diagram

classDiagram
class ExternalMessagesQueue {
-messages: BTreeMap<Stamp, (AccountAddress, WrappedMessage)>
-last_index: u64
+empty()
+erase_processed(processed: &[Stamp])
+push_external_messages(messages: &[WrappedMessage], timestamp: DateTime<Utc>)
+unprocessed_messages() HashMap<AccountAddress, VecDeque<(Stamp, Message)>>
}

The diagram shows the ExternalMessagesQueue struct with its private fields and public methods, illustrating its core responsibility as a container and manager of timestamped external messages keyed by stamps and grouped by account addresses.