Skip to content

Commit cd50f8c

Browse files
authored
Merge pull request #280 from elnosh/exclude-random
exclude nodes from random activity
2 parents fefbfc7 + 11ac7d1 commit cd50f8c

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

sim-cli/src/parsing.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,21 @@ impl Cli {
123123
));
124124
}
125125

126+
if !sim_params.exclude.is_empty() {
127+
if sim_params.sim_network.is_empty() {
128+
return Err(anyhow!(
129+
"List of nodes to exclude from sending/receiving
130+
in random activity is only allowed on a simulated network"
131+
));
132+
}
133+
134+
if !sim_params.activity.is_empty() {
135+
return Err(anyhow!(
136+
"List of nodes to exclude from sending/receiving is only allowed on random activity"
137+
));
138+
}
139+
}
140+
126141
Ok(())
127142
}
128143
}
@@ -135,6 +150,8 @@ pub struct SimParams {
135150
pub sim_network: Vec<NetworkParser>,
136151
#[serde(default)]
137152
pub activity: Vec<ActivityParser>,
153+
#[serde(default)]
154+
pub exclude: Vec<PublicKey>,
138155
}
139156

140157
#[derive(Serialize, Deserialize, Debug, Clone)]
@@ -236,6 +253,7 @@ pub async fn create_simulation_with_network(
236253
nodes: _,
237254
sim_network,
238255
activity: _activity,
256+
exclude,
239257
} = sim_params;
240258

241259
// Convert nodes representation for parsing to SimulatedChannel
@@ -276,7 +294,11 @@ pub async fn create_simulation_with_network(
276294
.map_err(|e| SimulationError::SimulatedNetworkError(format!("{:?}", e)))?,
277295
);
278296

279-
let nodes = ln_node_from_graph(simulation_graph.clone(), routing_graph).await;
297+
let mut nodes = ln_node_from_graph(simulation_graph.clone(), routing_graph).await;
298+
for pk in exclude {
299+
nodes.remove(pk);
300+
}
301+
280302
let validated_activities =
281303
get_validated_activities(&nodes, nodes_info, sim_params.activity.clone()).await?;
282304

@@ -305,6 +327,7 @@ pub async fn create_simulation(
305327
nodes,
306328
sim_network: _sim_network,
307329
activity: _activity,
330+
exclude: _,
308331
} = sim_params;
309332

310333
let (clients, clients_info) = get_clients(nodes.to_vec()).await?;

0 commit comments

Comments
 (0)