Skip to content

Commit 3a8b6de

Browse files
committed
sim-cli: exclude nodes from simulation but not from returned map
When we want to exclude nodes from random activity generation, we may still want to include them in our map of network nodes so that the caller can use any node in the network.
1 parent c4059cd commit 3a8b6de

1 file changed

Lines changed: 19 additions & 6 deletions

File tree

sim-cli/src/parsing.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,16 @@ struct NodeMapping {
241241
alias_node_map: HashMap<String, NodeInfo>,
242242
}
243243

244+
/// Creates a simulation that will run on an entirely-simulated network defined in `sim_params`,
245+
/// returning the simulation, a validated vector of any defined activities that were specified and
246+
/// a map of all the simulated nodes in the network. Note that if `sim_params::exclude` was set,
247+
/// the nodes will be excluded from the set of nodes actively sending/receiving random payments,
248+
/// but they will be included in the map so that they are available for use outside of the
249+
/// simulation.
250+
///
251+
/// This network can be customized by providing `interceptors` that will act on every HTLC that is
252+
/// forwarded by the network, and setting `custom_records` which will be set as the default TLV
253+
/// records set by the original sender of payments in their simulated `update_add_htlc`.
244254
pub async fn create_simulation_with_network(
245255
cfg: SimulationCfg,
246256
sim_params: &SimParams,
@@ -299,15 +309,18 @@ pub async fn create_simulation_with_network(
299309
.map_err(|e| SimulationError::SimulatedNetworkError(format!("{:?}", e)))?,
300310
);
301311

302-
let mut nodes = ln_node_from_graph(simulation_graph.clone(), routing_graph).await;
303-
for pk in exclude {
304-
nodes.remove(pk);
305-
}
306-
307-
let nodes_dyn: HashMap<_, Arc<Mutex<dyn LightningNode>>> = nodes
312+
// We want the full set of nodes in our graph to return to the caller so that they can take
313+
// custom actions on the simulated network. For the nodes we'll pass our simulation, cast them
314+
// to a dyn trait and exclude any nodes that shouldn't be included in random activity
315+
// generation.
316+
let nodes = ln_node_from_graph(simulation_graph.clone(), routing_graph).await;
317+
let mut nodes_dyn: HashMap<_, Arc<Mutex<dyn LightningNode>>> = nodes
308318
.iter()
309319
.map(|(pk, node)| (*pk, Arc::clone(node) as Arc<Mutex<dyn LightningNode>>))
310320
.collect();
321+
for pk in exclude {
322+
nodes_dyn.remove(pk);
323+
}
311324

312325
let validated_activities =
313326
get_validated_activities(&nodes_dyn, nodes_info, sim_params.activity.clone()).await?;

0 commit comments

Comments
 (0)