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 into 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, as part of creating
18    /// it: the journal appears complete with its genesis or not at all,
19    /// so a first boot that fails or crashes never leaves a history that
20    /// lacks it, and a replica can only copy one that has it. A node that
21    /// recovers an existing journal or restores a snapshot, or follows a
22    /// primary, already has them in its history, and journals nothing
23    /// from this field — changing it after the first boot changes
24    /// nothing.
25    ///
26    /// The exception is a journal with no entry at all and no recorded
27    /// genesis length — left by an earlier release's refused first boot,
28    /// or a replica's copy of one restarted on a primary's flags: nothing
29    /// was ever served from it, so it gets this genesis.
30    pub genesis: Vec<E>,
31    /// Journaled every time a node becomes primary — after `genesis` on a
32    /// new journal, on recovering an existing journal as primary, and
33    /// right after the epoch bump on promotion.
34    ///
35    /// Operator configuration the application enforces (rate limits,
36    /// caps) belongs here. The values in force are then always those of
37    /// the node serving clients, recorded in the history they govern:
38    /// replicas apply the primary's values, not their own, and replay
39    /// makes the decisions the values made the first time. A node's own
40    /// values take effect only once it is primary. Re-applying a value
41    /// already in force should leave the state unchanged.
42    pub on_primary: Vec<E>,
43}
44
45impl<E> StartupEvents<E> {
46    /// No startup events: an application whose history starts empty and
47    /// which takes no operator configuration.
48    pub fn none() -> Self {
49        Self {
50            genesis: Vec::new(),
51            on_primary: Vec::new(),
52        }
53    }
54}