-
Notifications
You must be signed in to change notification settings - Fork 220
Expand file tree
/
Copy pathaction.rs
More file actions
84 lines (71 loc) · 2.18 KB
/
action.rs
File metadata and controls
84 lines (71 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
//! Simulation action types for testing.
use commonware_cryptography::PublicKey;
use commonware_p2p::simulated::Link;
use commonware_runtime::deterministic;
use std::time::Duration;
/// Crash strategy for a simulation run.
#[derive(Clone)]
pub enum Crash<P: PublicKey> {
/// Periodically crash random validators and restart them after
/// a downtime period.
Random {
/// How often to trigger crashes.
frequency: Duration,
/// How long crashed validators stay offline.
downtime: Duration,
/// Number of validators to crash each time.
count: usize,
},
/// Delay some validators from starting until after N finalizations.
Delay {
/// Number of validators to delay.
count: usize,
/// Number of finalizations before starting delayed validators.
after: u64,
},
/// Time-indexed action schedule for precise control.
Schedule(Schedule<P>),
}
/// A time-ordered sequence of simulation actions.
#[derive(Clone)]
pub struct Schedule<P: PublicKey> {
/// Time-indexed actions.
pub events: Vec<(Duration, Action<P>)>,
}
impl<P: PublicKey> Schedule<P> {
/// Create an empty schedule.
pub const fn new() -> Self {
Self { events: vec![] }
}
/// Add an action at the given simulation time.
pub fn at(mut self, time: Duration, action: Action<P>) -> Self {
self.events.push((time, action));
self
}
}
impl<P: PublicKey> Default for Schedule<P> {
fn default() -> Self {
Self::new()
}
}
/// A single simulation action to apply at a specific time.
#[derive(Clone)]
pub enum Action<P: PublicKey> {
/// Update deterministic storage fault injection.
SetStorageFault(deterministic::FaultConfig),
/// Reset all directed links, restoring full connectivity with the given link.
Heal(Link),
/// Update a specific directed link by removing and re-adding it.
UpdateLink {
/// Source peer.
from: P,
/// Destination peer.
to: P,
/// New link configuration.
link: Link,
},
/// Crash a specific validator.
Crash(P),
/// Restart a previously crashed validator.
Restart(P),
}