Skip to main content

melin_server_runtime/
startup.rs

1//! Application events the runtime journals on a node's own behalf.
2
3/// Events the runtime journals as a node takes up the primary role,
4/// before it serves its first client.
5///
6/// They go through the journal like any client event, and that is the
7/// point: replicas receive them in the stream, and every replay — from
8/// genesis, from a snapshot, on a promoted replica — applies them again,
9/// in order. Nothing the application's state depends on bypasses the
10/// journal, so recovery can only reproduce the state the node had.
11///
12/// `Vec` rather than an iterator: both sets are built once at startup
13/// from operator configuration and consumed once, off any hot path.
14pub struct StartupEvents<E> {
15    /// The first events of the history: what every node's state starts
16    /// from (reference data, initial balances, ...). Journaled once, by
17    /// the node that creates the journal as primary. A node that recovers
18    /// an existing journal, or follows a primary, already has them in its
19    /// history.
20    pub genesis: Vec<E>,
21    /// Journaled every time a node becomes primary — after `genesis` on a
22    /// new journal, on recovering an existing journal as primary, and
23    /// right after the epoch bump on promotion.
24    ///
25    /// Operator configuration the application enforces (rate limits,
26    /// caps) belongs here. The values in force are then always those of
27    /// the node serving clients, recorded in the history they govern:
28    /// replicas apply the primary's values, not their own, and replay
29    /// makes the decisions the values made the first time. A node's own
30    /// values take effect only once it is primary. Re-applying a value
31    /// already in force should leave the state unchanged.
32    pub on_primary: Vec<E>,
33}
34
35impl<E> StartupEvents<E> {
36    /// No startup events: an application whose history starts empty and
37    /// which takes no operator configuration.
38    pub fn none() -> Self {
39        Self {
40            genesis: Vec::new(),
41            on_primary: Vec::new(),
42        }
43    }
44}