Skip to content

Commit 1f29207

Browse files
author
Ifeanyichukwu
committed
feat: add optional name for activity descriptions
1 parent dc544fa commit 1f29207

File tree

3 files changed

+123
-70
lines changed

3 files changed

+123
-70
lines changed

README.md

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,49 @@
11
# SimLN
22

3-
SimLN is a simulation tool that can be used to generate realistic
4-
payment activity on any lightning network topology. It is intentionally
5-
environment-agnostic so that it can be used across many environments -
6-
from integration tests to public signets.
3+
SimLN is a simulation tool that can be used to generate realistic
4+
payment activity on any lightning network topology. It is intentionally
5+
environment-agnostic so that it can be used across many environments -
6+
from integration tests to public signets.
77

8-
This tool is intended to serve developers who are familiar with
8+
This tool is intended to serve developers who are familiar with
99
lightning network development. It may be useful to you if you are:
10-
* A protocol developer looking to test proposals.
11-
* An application developer load-testing your application.
12-
* A signet operator interested in a hands-off way to run an active node.
13-
* A researcher generating synthetic data for a target topology.
10+
11+
- A protocol developer looking to test proposals.
12+
- An application developer load-testing your application.
13+
- A signet operator interested in a hands-off way to run an active node.
14+
- A researcher generating synthetic data for a target topology.
1415

1516
## Pre-Requisites
16-
SimLN requires you to "bring your own network" to generate activity
17+
18+
SimLN requires you to "bring your own network" to generate activity
1719
on. You will need:
18-
* A [lightning network](#lightning-environments) connected with any
20+
21+
- A [lightning network](#lightning-environments) connected with any
1922
topology of channels.
20-
* Access to execute commands on _at least_ one node in the network.
21-
* Rust compiler [installed](https://www.rust-lang.org/tools/install).
23+
- Access to execute commands on _at least_ one node in the network.
24+
- Rust compiler [installed](https://www.rust-lang.org/tools/install).
2225

2326
## LN Implementation Support
24-
* LND ✅
25-
* CLN ✅
26-
* Eclair 🏗️
27-
* LDK-node 🏗️
27+
28+
- LND ✅
29+
- CLN ✅
30+
- Eclair 🏗️
31+
- LDK-node 🏗️
2832

2933
See our [tracking issue](https://github.com/bitcoin-dev-project/sim-ln/issues/26)
3034
for updates on implementation support (contributions welcome!).
3135

3236
## Getting Started
33-
Clone the repo:
37+
38+
Clone the repo:
39+
3440
```
3541
git clone https://github.com/bitcoin-dev-project/sim-ln
3642
cd sim-ln
3743
```
3844

39-
Install the CLI:
45+
Install the CLI:
46+
4047
```
4148
cargo install --locked --path sim-cli/
4249
```
@@ -52,9 +59,10 @@ Run `sim-cli -h` for details on `--data-dir` and `--sim-file` options that allow
5259
Interested in contributing to the project? See [CONTRIBUTING](CONTRIBUTING.md) for more details.
5360

5461
### Simulation File Setup
55-
The simulator requires access details for a set of `nodes` that you
56-
have permission to execute commands on. Note that the current version
57-
of the simulator uses keysend to execute payments, which must be
62+
63+
The simulator requires access details for a set of `nodes` that you
64+
have permission to execute commands on. Note that the current version
65+
of the simulator uses keysend to execute payments, which must be
5866
enabled in LND using `--accept-keysend` (for CLN node it is enabled by default).
5967

6068
The required access details will depend on the node implementation. For LND, the following
@@ -72,7 +80,7 @@ information is required:
7280
Whereas for CLN nodes, the following information is required:
7381

7482
```
75-
{
83+
{
7684
"id": <node_id>,
7785
"address": https://<ip:port or domain:port>,
7886
"ca_cert": <path_to_ca_cert>,
@@ -84,17 +92,18 @@ Whereas for CLN nodes, the following information is required:
8492
**Note that node addresses must be declare with HTTPS transport, i.e. <https://ip-or-domain:port>**
8593

8694
Payment activity can be simulated in two different ways:
87-
* Random activity: generate random activity on the `nodes` provided,
95+
96+
- Random activity: generate random activity on the `nodes` provided,
8897
using the graph topology to determine payment frequency and size.
89-
* Defined activity: provide descriptions of specific payments that
98+
- Defined activity: provide descriptions of specific payments that
9099
you would like the generator to execute.
91100

92101
### Setup - Random Activity
93102

94-
To run the simulator with random activity generation, you just need to
95-
provide a set of nodes and the simulator will generate activity based
96-
on the topology of the underlying graph. Note that payments will only
97-
be sent between the `nodes` that are provided so that liquidity does
103+
To run the simulator with random activity generation, you just need to
104+
provide a set of nodes and the simulator will generate activity based
105+
on the topology of the underlying graph. Note that payments will only
106+
be sent between the `nodes` that are provided so that liquidity does
98107
not "drain" from the simulation.
99108

100109
```
@@ -106,7 +115,7 @@ not "drain" from the simulation.
106115
"macaroon": "/path/admin.macaroon",
107116
"cert": "/path/tls.cert"
108117
},
109-
{
118+
{
110119
"id": "0230a16a05c5ca120136b3a770a2adfdad88a68d526e63448a9eef88bddd6a30d8",
111120
"address": "https://localhost:10013",
112121
"ca_cert": "/path/ca.pem",
@@ -118,27 +127,29 @@ not "drain" from the simulation.
118127
```
119128

120129
Nodes can be identified by an arbitrary string ("Alice", "CLN1", etc) or
121-
by their node public key. If a valid public key is provided it *must*
130+
by their node public key. If a valid public key is provided it _must_
122131
match the public key reported by the node.
123132

124-
There are a few cli flags that can be used to toggle the characteristics
125-
of the random activity that is generated:
126-
* `--expected-payment-amount`: the approximate average amount that
133+
There are a few cli flags that can be used to toggle the characteristics
134+
of the random activity that is generated:
135+
136+
- `--expected-payment-amount`: the approximate average amount that
127137
will be sent by nodes, randomness will be introduced such that larger
128138
nodes send a wider variety of payment sizes around this expectation.
129-
* `--capacity-multiplier`: the number of times over that each node in
139+
- `--capacity-multiplier`: the number of times over that each node in
130140
the network sends their capacity in a calendar month, for example:
131-
* `capacity-multiplier=2` means that each node sends double their
132-
capacity in a month.
133-
* `capacity-multiplier=0.5` means that each node sends half their
141+
- `capacity-multiplier=2` means that each node sends double their
142+
capacity in a month.
143+
- `capacity-multiplier=0.5` means that each node sends half their
134144
capacity in a month.
135145

136146
### Setup - Defined Activity
137-
If you would like SimLN to generate a specific payments between source
138-
and destination nodes, you can provide `activity` descriptions of the
139-
source, destination, frequency and amount for payments that you'd like
140-
to execute. Note that `source` nodes *must* be contained in `nodes`,
141-
but destination nodes can be any public node in the network (though
147+
148+
If you would like SimLN to generate a specific payments between source
149+
and destination nodes, you can provide `activity` descriptions of the
150+
source, destination, frequency and amount for payments that you'd like
151+
to execute. Note that `source` nodes _must_ be contained in `nodes`,
152+
but destination nodes can be any public node in the network (though
142153
this may result in liquidity draining over time).
143154

144155
Required fields:
@@ -166,6 +177,7 @@ The example simulation file below sets up the following simulation:
166177
* Dispatch 140000 msat payments from `Bob` to `Alice` every 50 seconds.
167178
* Dispatch 1000 msat payments from `Bob` to `Dave` every 2 seconds.
168179
* Dispatch 10 payments (5000 msat each) from `Erin` to `Frank` at 2 second intervals, starting 20 seconds into the sim.
180+
169181
```
170182
{
171183
"nodes": [
@@ -200,7 +212,8 @@ The example simulation file below sets up the following simulation:
200212
"source": "Alice",
201213
"destination": "02d804ad31429c8cc29e20ec43b4129553eb97623801e534ab5a66cdcd2149dbed",
202214
"interval_secs": 1,
203-
"amount_msat": 2000
215+
"amount_msat": 2000,
216+
"activity_name": "Daily Contribution"
204217
},
205218
{
206219
"source": "0230a16a05c5ca120136b3a770a2adfdad88a68d526e63448a9eef88bddd6a30d8",
@@ -228,10 +241,10 @@ The example simulation file below sets up the following simulation:
228241

229242
**Note that node addresses must be declare with HTTPS transport, i.e <https://ip-or-domain>**
230243

231-
Nodes can be identified by their public key or an id string (as
232-
described above). Activity sources and destinations may reference the
233-
`id` defined in `nodes`, but destinations that are not listed in `nodes`
234-
*must* provide a valid public key.
244+
Nodes can be identified by their public key or an id string (as
245+
described above). Activity sources and destinations may reference the
246+
`id` defined in `nodes`, but destinations that are not listed in `nodes`
247+
_must_ provide a valid public key.
235248

236249
### Simulation Output
237250

@@ -242,10 +255,12 @@ Run `sim-cli -h` for details on data directory (`--data-dir`) and other options
242255
which affect how simulation outputs are persisted
243256

244257
## Lightning Environments
258+
245259
If you're looking to get started with local lightning development, we
246-
recommend [polar](https://lightningpolar.com/). For larger deployments,
247-
see the [Scaling Lightning](https://github.com/scaling-lightning/scaling-lightning)
260+
recommend [polar](https://lightningpolar.com/). For larger deployments,
261+
see the [Scaling Lightning](https://github.com/scaling-lightning/scaling-lightning)
248262
project.
249263

250264
## Docker
265+
251266
If you want to run the cli in a containerized environment, see the docker set up docs [here](./docker/README.md)

sim-cli/src/main.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ async fn main() -> anyhow::Result<()> {
9595
let mut clients: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>> = HashMap::new();
9696
let mut pk_node_map = HashMap::new();
9797
let mut alias_node_map = HashMap::new();
98+
let mut activity_name_map = HashMap::new();
9899

99100
for connection in nodes {
100101
// TODO: Feels like there should be a better way of doing this without having to Arc<Mutex<T>>> it at this time.
@@ -132,7 +133,7 @@ async fn main() -> anyhow::Result<()> {
132133
alias_node_map.insert(node_info.alias.clone(), node_info);
133134
}
134135

135-
let mut validated_activities = vec![];
136+
let mut validated_activities: Vec<ActivityDefinition> = vec![];
136137
// Make all the activities identifiable by PK internally
137138
for act in activity.into_iter() {
138139
// We can only map aliases to nodes we control, so if either the source or destination alias
@@ -182,13 +183,23 @@ async fn main() -> anyhow::Result<()> {
182183
},
183184
};
184185

186+
if activity_name_map.contains_key(&act.activity_name) {
187+
anyhow::bail!(LightningError::ValidationError(format!(
188+
"Duplicate activity name {:?} is not allowed.",
189+
act.activity_name.unwrap()
190+
),));
191+
}
192+
193+
activity_name_map.insert(act.activity_name.clone(), act.clone());
194+
185195
validated_activities.push(ActivityDefinition {
186196
source,
187197
destination,
188198
start_secs: act.start_secs,
189199
count: act.count,
190200
interval_secs: act.interval_secs,
191201
amount_msat: act.amount_msat,
202+
activity_name: act.activity_name,
192203
});
193204
}
194205

0 commit comments

Comments
 (0)