lib/machine/src/fault/types.zig

daab053ee43316e1809a84551d573ddd1e5bf3d2

 1 const os = @import("os");
 2 
 3 /// The version number a fault record is written under, its encoding version. A reader
 4 /// checks this before trusting a stored fault record. The reader rejects a record
 5 /// written under a version it does not speak. One version exists today: `deterministic_fault_v1`.
 6 pub const Dialect = enum(u16) {
 7     deterministic_fault_v1 = 1,
 8 };
 9 
10 /// The eleven fault families a point can name, its fault kind: a machine crash,
11 /// a process crash, an I/O error, packet loss, packet delay, packet reorder, a partition,
12 /// a clock jump, an entropy choice, capacity exhaustion, and a host service failure.
13 /// A caller picks one of these to say what sort of failure a point stands for.
14 pub const Kind = enum(u8) {
15     machine_crash = 1,
16     process_crash = 2,
17     io_error = 3,
18     packet_loss = 4,
19     packet_delay = 5,
20     packet_reorder = 6,
21     partition = 7,
22     clock_jump = 8,
23     entropy_choice = 9,
24     capacity_exhaustion = 10,
25     host_service_failure = 11,
26 };
27 
28 /// The outcome recorded at one fault point, its choice. A caller sets this to take
29 /// one of the two branches at that point. Bypass leaves execution untouched, and
30 /// inject applies the fault effect.
31 pub const Choice = enum(u8) {
32     bypass = 1,
33     inject = 2,
34 };
35 
36 /// The named place where a fault can be injected, a fault point. A caller builds
37 /// one of these to name the place a decision will be taken. The basis digest names
38 /// the authenticated state the point came out of. The subject digest identifies
39 /// what the fault acts on, a packet or a node for example. The id commits every
40 /// field, so two points agree only when their state, kind, and target all agree.
41 pub const Point = struct {
42     id: os.abi.Digest,
43     dialect: Dialect,
44     basis: os.abi.Digest,
45     kind: Kind,
46     subject: os.abi.Digest,
47 };
48 
49 /// A point together with the choice made at it, a fault decision. A caller stores
50 /// one of these per fault point as the record of what was chosen there. The digest
51 /// commits the pair, and `advance` folds it into the fault chain.
52 pub const Decision = struct {
53     point: Point,
54     choice: Choice,
55     digest: os.abi.Digest,
56 };