Skip to content

Commit 8cb5016

Browse files
author
Ifeanyichukwu
committed
chore: extend activity_name to all activity relevant logging
1 parent 1cc36a7 commit 8cb5016

File tree

4 files changed

+120
-76
lines changed

4 files changed

+120
-76
lines changed

README.md

Lines changed: 72 additions & 53 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,31 +127,32 @@ 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, amount for payments that you'd like
140-
to execute and an optional name for each `activity` description that is used
141-
as the logging prefix to relate logs to their corresponding activity description
142-
(The index of each `activity` description will be used if a name is not
143-
provided for the `activity` description). Note that `source` nodes *must* be contained in `nodes`,
144-
but destination nodes can be any public node in the network (though
145-
this may result in liquidity draining over time).
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
153+
this may result in liquidity draining over time). You can also add an optional name for each `activity` description that is
154+
used as the logging prefix to relate logs to their corresponding activity
155+
description (The index of each `activity` description will be used if a name is not provided for the `activity` description).
146156

147157
Required fields:
148158
```
@@ -169,6 +179,13 @@ The example simulation file below sets up the following simulation:
169179
* Dispatch 140000 msat payments from `Bob` to `Alice` every 50 seconds.
170180
* Dispatch 1000 msat payments from `Bob` to `Dave` every 2 seconds.
171181
* Dispatch 10 payments (5000 msat each) from `Erin` to `Frank` at 2 second intervals, starting 20 seconds into the sim.
182+
183+
- Connect to `Alice` running LND to generate activity.
184+
- Connect to `Bob` running CLN to generate activity.
185+
- Dispatch 2000 msat payments from `Alice` to `Carol` every 1 seconds.
186+
- Dispatch 140000 msat payments from `Bob` to `Alice` every 50 seconds.
187+
- Dispatch 1000 msat payments from `Bob` to `Dave` every 2 seconds.
188+
172189
```
173190
{
174191
"nodes": [
@@ -232,10 +249,10 @@ The example simulation file below sets up the following simulation:
232249

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

235-
Nodes can be identified by their public key or an id string (as
236-
described above). Activity sources and destinations may reference the
237-
`id` defined in `nodes`, but destinations that are not listed in `nodes`
238-
*must* provide a valid public key.
252+
Nodes can be identified by their public key or an id string (as
253+
described above). Activity sources and destinations may reference the
254+
`id` defined in `nodes`, but destinations that are not listed in `nodes`
255+
_must_ provide a valid public key.
239256

240257
### Simulation Output
241258

@@ -246,10 +263,12 @@ Run `sim-cli -h` for details on data directory (`--data-dir`) and other options
246263
which affect how simulation outputs are persisted
247264

248265
## Lightning Environments
266+
249267
If you're looking to get started with local lightning development, we
250-
recommend [polar](https://lightningpolar.com/). For larger deployments,
251-
see the [Scaling Lightning](https://github.com/scaling-lightning/scaling-lightning)
268+
recommend [polar](https://lightningpolar.com/). For larger deployments,
269+
see the [Scaling Lightning](https://github.com/scaling-lightning/scaling-lightning)
252270
project.
253271

254272
## Docker
273+
255274
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: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ async fn main() -> anyhow::Result<()> {
132132
alias_node_map.insert(node_info.alias.clone(), node_info);
133133
}
134134

135-
let mut validated_activities = vec![];
135+
let mut validated_activities: Vec<ActivityDefinition> = vec![];
136136
// Make all the activities identifiable by PK internally
137137
for act in activity.into_iter() {
138138
// We can only map aliases to nodes we control, so if either the source or destination alias
@@ -182,6 +182,14 @@ async fn main() -> anyhow::Result<()> {
182182
},
183183
};
184184

185+
for validated_activity in &validated_activities {
186+
if validated_activity.activity_name == act.activity_name {
187+
anyhow::bail!(LightningError::ValidationError(
188+
"Duplicate activity name is not allowed".to_string(),
189+
));
190+
}
191+
}
192+
185193
validated_activities.push(ActivityDefinition {
186194
source,
187195
destination,

sim-lib/src/defined_activity.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ pub struct DefinedPaymentActivity {
99
count: Option<u64>,
1010
wait: Duration,
1111
amount: u64,
12+
activity_name: String,
1213
}
1314

1415
impl DefinedPaymentActivity {
@@ -18,13 +19,14 @@ impl DefinedPaymentActivity {
1819
count: Option<u64>,
1920
wait: Duration,
2021
amount: u64,
21-
) -> Self {
22+
activity_name: String) -> Self {
2223
DefinedPaymentActivity {
2324
destination,
2425
start,
2526
count,
2627
wait,
2728
amount,
29+
activity_name,
2830
}
2931
}
3032
}
@@ -33,8 +35,8 @@ impl fmt::Display for DefinedPaymentActivity {
3335
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3436
write!(
3537
f,
36-
"static payment of {} to {} every {:?}",
37-
self.amount, self.destination, self.wait
38+
"{} activity: static payment of {} to {} every {:?}",
39+
self.activity_name, self.amount, self.destination, self.wait
3840
)
3941
}
4042
}
@@ -86,6 +88,7 @@ mod tests {
8688

8789
let source = get_random_keypair();
8890
let payment_amt = 50;
91+
let activity_name = String::from("Coffee Purchase");
8992

9093
let generator = DefinedPaymentActivity::new(
9194
node.clone(),
@@ -94,6 +97,12 @@ mod tests {
9497
Duration::from_secs(60),
9598
payment_amt,
9699
);
100+
let generator = DefinedPaymentActivity::new(
101+
node.clone(),
102+
Duration::from_secs(60),
103+
payment_amt,
104+
activity_name,
105+
);
97106

98107
let (dest, dest_capacity) = generator.choose_destination(source.1);
99108
assert_eq!(node.pubkey, dest.pubkey);

0 commit comments

Comments
 (0)