Skip to content

Commit

Permalink
[NO MERGE]: example of passing in topology for simulation
Browse files Browse the repository at this point in the history
  • Loading branch information
carlaKC committed Feb 1, 2024
1 parent 3aac16c commit 67de925
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 3 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sim-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ sim-lib = { path = "../sim-lib" }
tokio = { version = "1.26.0", features = ["full"] }
bitcoin = { version = "0.30.1" }
ctrlc = "3.4.0"
triggered = "0.1.2"
77 changes: 74 additions & 3 deletions sim-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
use bitcoin::secp256k1::PublicKey;
use sim_lib::sim_node::{
ln_node_from_graph, populate_network_graph, ChannelPolicy, SimGraph, SimulatedChannel,
};
use std::collections::HashMap;
use std::path::PathBuf;
use std::str::FromStr;
use std::sync::Arc;
use tokio::sync::Mutex;

Expand All @@ -10,7 +14,7 @@ use clap::Parser;
use log::LevelFilter;
use sim_lib::{
cln::ClnNode, lnd::LndNode, ActivityDefinition, LightningError, LightningNode, NodeConnection,
NodeId, SimParams, Simulation, WriteResults,
NodeId, SimParams, Simulation,WriteResults,
};
use simple_logger::SimpleLogger;

Expand Down Expand Up @@ -189,7 +193,6 @@ async fn main() -> anyhow::Result<()> {
amount_msat: act.amount_msat,
});
}

let write_results = if !cli.no_results {
Some(WriteResults {
results_dir: mkdir(cli.data_dir.join("results")).await?,
Expand All @@ -199,8 +202,76 @@ async fn main() -> anyhow::Result<()> {
None
};

let capacity = 300000000;
let pubkey_1 =
PublicKey::from_str("039ae6b91fbec1b400adffcd7f7132e81efbb5aaeeeb061903695a919652aee761")?;
let alice_to_bob = ChannelPolicy {
pubkey: pubkey_1,
max_htlc_count: 483,
max_in_flight_msat: capacity / 2,
min_htlc_size_msat: 1,
max_htlc_size_msat: capacity / 2,
cltv_expiry_delta: 40,
base_fee: 1000,
fee_rate_prop: 3500,
};

let pubkey_2 =
PublicKey::from_str("0275ade20b15f2a309d8db2d7ea4f5004129204b83d2307433292f183bdbe5df2e")?;
let bob_to_alice = ChannelPolicy {
pubkey: pubkey_2,
max_htlc_count: 483,
max_in_flight_msat: capacity / 2,
min_htlc_size_msat: 1,
max_htlc_size_msat: capacity / 2,
cltv_expiry_delta: 40,
base_fee: 2000,
fee_rate_prop: 1,
};

let bob_to_carol = ChannelPolicy {
pubkey: pubkey_2,
max_htlc_count: 483,
max_in_flight_msat: capacity / 2,
min_htlc_size_msat: 1,
max_htlc_size_msat: capacity / 2,
cltv_expiry_delta: 40,
base_fee: 1000,
fee_rate_prop: 1000,
};

let pubkey_3 =
PublicKey::from_str("028a4929f8c7fe3ce735f86d35e716efe406956dfe6ff1e1f88ea11207976a720b")?;
let carol_to_bob = ChannelPolicy {
pubkey: pubkey_3,
max_htlc_count: 483,
max_in_flight_msat: capacity / 2,
min_htlc_size_msat: 1,
max_htlc_size_msat: capacity / 2,
cltv_expiry_delta: 15,
base_fee: 2000,
fee_rate_prop: 1,
};

let chan_alice_bob = SimulatedChannel::new(capacity, 123, alice_to_bob, bob_to_alice);

let chan_bob_carol = SimulatedChannel::new(capacity, 456, bob_to_carol, carol_to_bob);

// TODO: use the shutdown trigger and listener across simulator and graph.
let (shutdown_trigger, shutdown_listener) = triggered::trigger();
let channels = vec![chan_alice_bob, chan_bob_carol];
let graph = match SimGraph::new(channels.clone(), shutdown_trigger, shutdown_listener) {
Ok(graph) => Arc::new(Mutex::new(graph)),
Err(e) => anyhow::bail!("failed: {:?}", e),
};

let routing_graph = match populate_network_graph(channels) {
Ok(r) => r,
Err(e) => anyhow::bail!("failed: {:?}", e),
};

let sim = Simulation::new(
clients,
ln_node_from_graph(graph, Arc::new(routing_graph)).await,
validated_activities,
cli.total_time,
cli.expected_pmt_amt,
Expand Down

0 comments on commit 67de925

Please sign in to comment.