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 (instruments, accounts, ...). Journaled once, by the node that
17 /// creates the journal as primary. A node that recovers an existing
18 /// journal, or follows a primary, already has them in its history.
19 pub genesis: Vec<E>,
20 /// Journaled every time a node becomes primary — after `genesis` on a
21 /// new journal, on recovering an existing journal as primary, and
22 /// right after the epoch bump on promotion.
23 ///
24 /// Operator configuration the application enforces (rate limits,
25 /// caps) belongs here. The values in force are then always those of
26 /// the node serving clients, recorded in the history they govern:
27 /// replicas apply the primary's values, not their own, and replay
28 /// makes the decisions the values made the first time. A node's own
29 /// values take effect only once it is primary. Re-applying a value
30 /// already in force should leave the state unchanged.
31 pub on_primary: Vec<E>,
32}
33
34impl<E> StartupEvents<E> {
35 /// No startup events: an application whose history starts empty and
36 /// which takes no operator configuration.
37 pub fn none() -> Self {
38 Self {
39 genesis: Vec::new(),
40 on_primary: Vec::new(),
41 }
42 }
43}