Skip to content

Commit 3dc2eb7

Browse files
authored
Merge pull request #248 from f3r10/feature_add_ability_to_run_with_mocked_ln_network
simln-lib/feature: Add ability to run with mocked ln network
2 parents 333f843 + 0c91cf7 commit 3dc2eb7

File tree

8 files changed

+359
-98
lines changed

8 files changed

+359
-98
lines changed

Cargo.lock

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

README.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,106 @@ project.
270270
## Docker
271271
If you want to run the cli in a containerized environment, see the docker set up docs [here](./docker/README.md)
272272

273+
## Advanced Usage - Network Simulation
274+
275+
If you are looking to simulate payments are large lightning networks
276+
without the resource consumption of setting up a large cluster of nodes,
277+
you may be interested in dispatching payments on a simulated network.
278+
279+
To run on a simulated network, you will need to provide the desired
280+
topology and channel policies for each edge in the graph. The nodes in
281+
the network will be inferred from the edges provided. Simulation of
282+
payments on both a mocked and real lightning network is not supported,
283+
so the `sim_network` field is mutually exclusive with the `nodes` section
284+
described above.
285+
286+
The example that follows will execute random payments on a network
287+
consisting of three nodes and two channels. You may specify defined
288+
activity to execute on the mocked network, though you must refer to
289+
nodes by their pubkey (aliases are not yet supported).
290+
291+
```
292+
{
293+
"sim_network": [
294+
{
295+
"scid": 1,
296+
"capacity_msat": 250000,
297+
"node_1": {
298+
"pubkey": "0344f37d544896dcc95a08ddd9bdfc2b756bf3f91b3f65bce588bd9d0228c24977",
299+
"max_htlc_count": 483,
300+
"max_in_flight_msat": 250000,
301+
"min_htlc_size_msat": 1,
302+
"max_htlc_size_msat": 100000,
303+
"cltv_expiry_delta": 40,
304+
"base_fee": 1000,
305+
"fee_rate_prop": 100
306+
},
307+
"node_2": {
308+
"pubkey": "020a30431ce58843eedf8051214dbfadb65b107cc598b8277f14bb9b33c9cd026f",
309+
"max_htlc_count": 15,
310+
"max_in_flight_msat": 100000,
311+
"min_htlc_size_msat": 1,
312+
"max_htlc_size_msat": 50000,
313+
"cltv_expiry_delta": 80,
314+
"base_fee": 2000,
315+
"fee_rate_prop": 500
316+
}
317+
},
318+
{
319+
"scid": 2,
320+
"capacity_msat": 100000,
321+
"node_1": {
322+
"pubkey": "020a30431ce58843eedf8051214dbfadb65b107cc598b8277f14bb9b33c9cd026f",
323+
"max_htlc_count": 200,
324+
"max_in_flight_msat": 100000,
325+
"min_htlc_size_msat": 1,
326+
"max_htlc_size_msat": 25000,
327+
"cltv_expiry_delta": 40,
328+
"base_fee": 1750,
329+
"fee_rate_prop": 100
330+
},
331+
"node_2": {
332+
"pubkey": "035c0b392725bb7298d56bf1bcb23634fc509d86a39a8141d435f9d4d6cd4b12eb",
333+
"max_htlc_count": 15,
334+
"max_in_flight_msat": 50000,
335+
"min_htlc_size_msat": 1,
336+
"max_htlc_size_msat": 50000,
337+
"cltv_expiry_delta": 80,
338+
"base_fee": 3000,
339+
"fee_rate_prop": 5
340+
}
341+
}
342+
]
343+
}
344+
```
345+
346+
Note that you need to provide forwarding policies in each direction,
347+
because each participant in the channel sets their own forwarding
348+
policy and restrictions on their counterparty.
349+
350+
### Inclusions and Limitations
351+
352+
The simulator will execute payments on the mocked out network as it
353+
would for a network of real nodes. See the inclusions and exclusions
354+
listed below for a description of the functionality covered by the
355+
simulated network.
356+
357+
Included:
358+
* Routing Policy Enforcement: mocked channels enforce fee and CLTV
359+
requirements.
360+
* Channel restrictions: mocked channels abide by the in-flight
361+
count and value limitations set on channel creation.
362+
* Liquidity checks: HTLCs are only forwarded if the node has sufficient
363+
liquidity in the mocked channel.
364+
365+
Not included:
366+
* Channel reserve: the required minimum reserve balance is not
367+
subtracted from a node's available balance.
368+
* On chain fees: the simulation does not subtract on chain fees from
369+
available liquidity.
370+
* Dust limits: the simulation node not account for restrictions on dust
371+
HTLCs.
372+
273373
## Developers
274374

275375
* [Developer documentation](docs/DEVELOPER.md)

sim-cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ anyhow = { version = "1.0.69", features = ["backtrace"] }
1414
clap = { version = "4.1.6", features = ["derive", "env", "std", "help", "usage", "error-context", "suggestions"], default-features = false }
1515
dialoguer = "0.11.0"
1616
log = "0.4.20"
17+
triggered = "0.1.2"
1718
serde = "1.0.183"
1819
serde_json = "1.0.104"
1920
simple_logger = "4.2.0"

sim-cli/src/main.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
use clap::Parser;
22
use log::LevelFilter;
3-
use sim_cli::parsing::{create_simulation, Cli};
3+
use sim_cli::parsing::{create_simulation, create_simulation_with_network, parse_sim_params, Cli};
44
use simple_logger::SimpleLogger;
5+
use tokio_util::task::TaskTracker;
56

67
#[tokio::main]
78
async fn main() -> anyhow::Result<()> {
@@ -12,6 +13,7 @@ async fn main() -> anyhow::Result<()> {
1213
}
1314

1415
let cli = Cli::parse();
16+
let sim_params = parse_sim_params(&cli).await?;
1517

1618
SimpleLogger::new()
1719
.with_level(LevelFilter::Warn)
@@ -20,15 +22,23 @@ async fn main() -> anyhow::Result<()> {
2022
.init()
2123
.unwrap();
2224

23-
let sim = create_simulation(&cli).await?;
25+
cli.validate(&sim_params)?;
26+
27+
let tasks = TaskTracker::new();
28+
29+
let (sim, validated_activities) = if sim_params.sim_network.is_empty() {
30+
create_simulation(&cli, &sim_params, tasks.clone()).await?
31+
} else {
32+
create_simulation_with_network(&cli, &sim_params, tasks.clone()).await?
33+
};
2434
let sim2 = sim.clone();
2535

2636
ctrlc::set_handler(move || {
2737
log::info!("Shutting down simulation.");
2838
sim2.shutdown();
2939
})?;
3040

31-
sim.run().await?;
41+
sim.run(&validated_activities).await?;
3242

3343
Ok(())
3444
}

0 commit comments

Comments
 (0)