Skip to content

Commit aedd4fd

Browse files
authored
Sim rs 1.0 (#497)
* sim-rs: remove L_vote restriction in EB production * sim-rs: fix mempool behavior with EBs propagated before TXs * sim-rs: add version number to changelog * sim-rs: support selecting attackers with stake-fraction * sim-rs: bump version to 1.0.0
1 parent 74fcac8 commit aedd4fd

File tree

10 files changed

+152
-65
lines changed

10 files changed

+152
-65
lines changed

data/simulation/config.d.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,10 @@ export interface LateTXAttackConfig {
367367
"tx-generation-distribution": Distribution,
368368
}
369369

370-
export type NodeSelection = NodesNodeSelection;
370+
export type NodeSelection = NodesNodeSelection | StakeFractionNodeSelection;
371371
export interface NodesNodeSelection {
372372
"nodes": string[];
373+
}
374+
export interface StakeFractionNodeSelection {
375+
"stake-fraction": number,
373376
}

data/simulation/config.schema.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"description": "Configuration for a \"late EB\" attack,\nwhere nodes deliberately withhold EBs until near the end of the voting phase.",
8181
"properties": {
8282
"attackers": {
83-
"$ref": "#/definitions/NodesNodeSelection",
83+
"$ref": "#/definitions/NodeSelection",
8484
"description": "The set of stake pools which are participating in the attack."
8585
},
8686
"propagation-delay-ms": {
@@ -98,7 +98,7 @@
9898
"type": "number"
9999
},
100100
"attackers": {
101-
"$ref": "#/definitions/NodesNodeSelection",
101+
"$ref": "#/definitions/NodeSelection",
102102
"description": "The set of stake pools which are participating in the attack."
103103
},
104104
"tx-generation-distribution": {
@@ -138,6 +138,16 @@
138138
"enum": ["ordered-by-id", "random"],
139139
"type": "string"
140140
},
141+
"NodeSelection": {
142+
"anyOf": [
143+
{
144+
"$ref": "#/definitions/NodesNodeSelection"
145+
},
146+
{
147+
"$ref": "#/definitions/StakeFractionNodeSelection"
148+
}
149+
]
150+
},
141151
"NodesNodeSelection": {
142152
"properties": {
143153
"nodes": {
@@ -167,6 +177,14 @@
167177
"RelayStrategy": {
168178
"enum": ["request-from-all", "request-from-first"],
169179
"type": "string"
180+
},
181+
"StakeFractionNodeSelection": {
182+
"properties": {
183+
"stake-fraction": {
184+
"type": "number"
185+
}
186+
},
187+
"type": "object"
170188
}
171189
},
172190
"description": "A configuration for a Leios simulation.",

sim-rs/CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Changelog
2+
3+
## v1.0.0
4+
5+
### Linear Leios
6+
7+
- Allow RBs to include EB certificates produced at least `L_diff` slots ago, instead of `L_vote + L_diff` slots ago. When `L_diff` is 0, this removes any direct time factor from the decision to include an EB cert.
8+
- Add TXs to the mempool, even if they belong to an EB we've already seen.
9+
- Support choosing attackers by selecting a fraction of stake
10+
11+
### Other
12+
13+
- Add version number to the CLI tool's output.
14+
15+
## v0.1.0
16+
17+
This version was arbitrarily chosen as the point to start tracking major changes to the simulation.

sim-rs/Cargo.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sim-rs/implementations/LINEAR_LEIOS.md

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ When a node receives an RB body, it immediately removes all referenced/conflicti
7171

7272
A set of nodes can be configured to collude with each other, to distribute an EB close to the end of L_diff.
7373

74-
Example config:
74+
Example config (with explicit list of attackers):
7575
```yaml
7676
late-eb-attack:
7777
attackers:
@@ -85,15 +85,23 @@ late-eb-attack:
8585
propagation-delay-ms: 4500.0
8686
```
8787
88-
The `attackers` list controls which nodes are participating in the attack. (I will get around to letting you just choose a `stake` sometime soon). These nodes can communicate out of band, without taking latency or bandwidth into account.
88+
Example config (with fraction of stake):
89+
```yaml
90+
late-eb-attack:
91+
attackers:
92+
stake-fraction: 0.51
93+
propagation-delay-ms: 4500.0
94+
```
95+
96+
The `attackers` list controls which nodes are participating in the attack. These nodes can communicate out of band, without taking latency or bandwidth into account.
8997

9098
When one of the attackers generates an EB, it will instantly and instantaneously send that EB to all other attackers. The attackers will all wait for `propagation-delay-ms` to elapse, and _then_ announce the EB to all peers.
9199

92100
### TX Withholding
93101

94102
A set of nodes can be configured to "withhold" some number of TXs until the moment they generate an EB.
95103

96-
Example config:
104+
Example config (with explicit list of attackers):
97105
```yaml
98106
late-tx-attack:
99107
attackers:
@@ -110,7 +118,18 @@ late-tx-attack:
110118
value: 3
111119
```
112120

113-
The `attackers` list controls which nodes are participating in the attack. (I will get around to letting you just choose a `stake` sometime soon).
121+
Example config (with fraction of stake):
122+
```yaml
123+
late-tx-attack:
124+
attackers:
125+
stake-fraction: 0.51
126+
attack-probability: 1.0
127+
tx-generation-distribution:
128+
distribution: constant
129+
value: 3
130+
```
131+
132+
The `attackers` list controls which nodes are participating in the attack.
114133

115134
When an attacker generates an EB, with probability `attack-probability` they will also generate `tx-generation-distribution` brand-new transactions. Both the EB and the transactions will be immediately announced to peers as normal.
116135

sim-rs/sim-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sim-cli"
3-
version = "0.1.0"
3+
version = "1.0.0"
44
edition = "2024"
55
default-run = "sim-cli"
66
rust-version = "1.88"

sim-rs/sim-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ const DEFAULT_TOPOLOGY_PATHS: &[&str] = &[
3232
];
3333

3434
#[derive(Parser)]
35-
#[command(version = env!("VERGEN_GIT_SHA"))]
35+
#[command(version = concat!(env!("CARGO_PKG_VERSION"), "-", env!("VERGEN_GIT_SHA")))]
3636
struct Args {
3737
#[clap(default_value = None)]
3838
topology: Option<PathBuf>,

sim-rs/sim-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sim-core"
3-
version = "0.1.0"
3+
version = "1.0.0"
44
edition = "2024"
55
rust-version = "1.88"
66

sim-rs/sim-core/src/config.rs

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rand::Rng;
1010
use rand_chacha::ChaCha20Rng;
1111
use rand_distr::Distribution;
1212
use serde::{Deserialize, Serialize};
13+
use tracing::info;
1314

1415
use crate::{
1516
clock::Timestamp,
@@ -214,6 +215,7 @@ pub struct RawLateTXAttackConfig {
214215
#[serde(rename_all = "kebab-case")]
215216
pub enum NodeSelection {
216217
Nodes(HashSet<String>),
218+
StakeFraction(f64),
217219
}
218220

219221
#[derive(Debug, Serialize, Deserialize)]
@@ -305,10 +307,7 @@ impl Topology {
305307
Ok(())
306308
}
307309

308-
pub fn select(
309-
&mut self,
310-
selection: &NodeSelection,
311-
) -> impl Iterator<Item = &mut NodeConfiguration> {
310+
pub fn select(&mut self, selection: &NodeSelection) -> Vec<&mut NodeConfiguration> {
312311
let mut nodes = vec![];
313312
match selection {
314313
NodeSelection::Nodes(names) => {
@@ -318,8 +317,22 @@ impl Topology {
318317
.filter(|node| names.contains(&node.name)),
319318
);
320319
}
320+
NodeSelection::StakeFraction(fraction) => {
321+
let mut all_nodes = self.nodes.iter_mut().collect::<Vec<_>>();
322+
all_nodes.sort_by_key(|n| std::cmp::Reverse(n.stake));
323+
let total_stake = all_nodes.iter().map(|n| n.stake).sum::<u64>();
324+
let target_stake = ((total_stake as f64) * *fraction) as u64;
325+
let mut stake_so_far = 0;
326+
for node in all_nodes {
327+
if stake_so_far >= target_stake {
328+
break;
329+
}
330+
stake_so_far += node.stake;
331+
nodes.push(node);
332+
}
333+
}
321334
}
322-
nodes.into_iter()
335+
nodes
323336
}
324337
}
325338

@@ -632,10 +645,12 @@ pub(crate) struct LateEBAttackConfig {
632645

633646
impl LateEBAttackConfig {
634647
fn build(raw: &RawLateEBAttackConfig, topology: &mut Topology) -> Self {
635-
let attackers = topology
636-
.select(&raw.attackers)
637-
.map(|node| node.id)
638-
.collect();
648+
let all_attackers = topology.select(&raw.attackers);
649+
info!(
650+
"Late EB attackers: {:?}",
651+
all_attackers.iter().map(|n| &n.name).collect::<Vec<_>>()
652+
);
653+
let attackers = all_attackers.into_iter().map(|node| node.id).collect();
639654
Self {
640655
attackers,
641656
propagation_delay: duration_ms(raw.propagation_delay_ms),
@@ -653,7 +668,12 @@ pub(crate) struct LateTXAttackConfig {
653668

654669
impl LateTXAttackConfig {
655670
fn build(raw: &RawLateTXAttackConfig, topology: &mut Topology, params: &RawParameters) -> Self {
656-
for attacker in topology.select(&raw.attackers) {
671+
let all_attackers = topology.select(&raw.attackers);
672+
info!(
673+
"Late TX attackers: {:?}",
674+
all_attackers.iter().map(|n| &n.name).collect::<Vec<_>>()
675+
);
676+
for attacker in all_attackers {
657677
attacker.behaviours.withhold_txs = true;
658678
}
659679
Self {

0 commit comments

Comments
 (0)