Skip to content

Commit 1270a16

Browse files
authored
Merge pull request #152 from sr-gi/20231025_improve_json_parsing
sim-lib: Get rid of nested json for node definition
2 parents f9d8541 + 8ad307b commit 1270a16

File tree

4 files changed

+54
-39
lines changed

4 files changed

+54
-39
lines changed

README.md

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,33 @@ sim-cli sim.json
5050
The simulator requires access details for a set of `nodes` that you
5151
have permission to execute commands on. Note that the current version
5252
of the simulator uses keysend to execute payments, which must be
53-
enabled in LND using `--accept-keysend`.
53+
enabled in LND using `--accept-keysend` (for CLN node it is enabled by default).
54+
55+
The required access details will depend on the node implementation. For LND, the following
56+
information is required:
57+
58+
```
59+
{
60+
"id": <node_id>,
61+
"address": https://<ip:port or domain:port>,
62+
"macaroon": <path_to_selected_macaroon>,
63+
"cert": <path_to_tls_cert>
64+
}
65+
```
66+
67+
Whereas for CLN nodes, the following information is required:
68+
69+
```
70+
{
71+
"id": <node_id>,
72+
"address": https://<ip:port or domain:port>,
73+
"ca_cert": <path_to_ca_cert>,
74+
"client_cert": <path_to_client_cert>,
75+
"client_key": <path_to_client_key>
76+
}
77+
```
78+
79+
**Note that node addresses must be declare with HTTPS transport, i.e. <https://ip-or-domain:port>**
5480

5581
Payment activity can be simulated in two different ways:
5682
* Random activity: generate random activity on the `nodes` provided,
@@ -70,28 +96,22 @@ not "drain" from the simulation.
7096
{
7197
"nodes": [
7298
{
73-
"LND": {
74-
"id": "Alice",
75-
"address": "https://127.0.0.1:10011",
76-
"macaroon": "/path/admin.macaroon",
77-
"cert": "/path/tls.cert"
78-
}
99+
"id": "Alice",
100+
"address": "https://127.0.0.1:10011",
101+
"macaroon": "/path/admin.macaroon",
102+
"cert": "/path/tls.cert"
79103
},
80-
{
81-
"CLN": {
82-
"id": "0230a16a05c5ca120136b3a770a2adfdad88a68d526e63448a9eef88bddd6a30d8",
83-
"address": "https://localhost:10013",
84-
"ca_cert": "/path/ca.pem",
85-
"client_cert": "/path/client.pem",
86-
"client_key": "/path/client-key.pem"
87-
}
104+
{
105+
"id": "0230a16a05c5ca120136b3a770a2adfdad88a68d526e63448a9eef88bddd6a30d8",
106+
"address": "https://localhost:10013",
107+
"ca_cert": "/path/ca.pem",
108+
"client_cert": "/path/client.pem",
109+
"client_key": "/path/client-key.pem"
88110
}
89111
]
90112
}
91113
```
92114

93-
**Note that node addresses must be declare with HTTPS transport, i.e. <https://ip-or-domain>**
94-
95115
Nodes can be identified by an arbitrary string ("Alice", "CLN1", etc) or
96116
by their node public key. If a valid public key is provided it *must*
97117
match the public key reported by the node.
@@ -126,21 +146,17 @@ The example simulation file below sets up the following simulation:
126146
{
127147
"nodes": [
128148
{
129-
"LND": {
130-
"id": "Alice",
131-
"address": "https://localhost:10011",
132-
"macaroon": "/path/admin.macaroon",
133-
"cert": "/path/tls.cert"
134-
}
149+
"id": "Alice",
150+
"address": "https://localhost:10011",
151+
"macaroon": "/path/admin.macaroon",
152+
"cert": "/path/tls.cert"
135153
},
136154
{
137-
"CLN": {
138-
"id": "0230a16a05c5ca120136b3a770a2adfdad88a68d526e63448a9eef88bddd6a30d8",
139-
"address": "https://127.0.0.1:10013",
140-
"ca_cert": "/path/ca.pem",
141-
"client_cert": "/path/client.pem",
142-
"client_key": "/path/client-key.pem"
143-
}
155+
"id": "0230a16a05c5ca120136b3a770a2adfdad88a68d526e63448a9eef88bddd6a30d8",
156+
"address": "https://127.0.0.1:10013",
157+
"ca_cert": "/path/ca.pem",
158+
"client_cert": "/path/client.pem",
159+
"client_key": "/path/client-key.pem"
144160
}
145161
],
146162
"activity": [

docker/README.md

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,10 @@ For instance, in your configuration:
5151

5252
```json
5353
{
54-
"LND": {
55-
"id": "022579561f6f0ea86e330df2f9e7b2be3e0a53f8552f9d5293b80dfc1038f2f66d",
56-
"address": "https://host.docker.internal:10002",
57-
"macaroon": "/path/in/container/lnd/bob/data/chain/bitcoin/regtest/admin.macaroon",
58-
"cert": "/path/in/container/lnd/bob/tls.cert"
59-
}
54+
"id": "022579561f6f0ea86e330df2f9e7b2be3e0a53f8552f9d5293b80dfc1038f2f66d",
55+
"address": "https://host.docker.internal:10002",
56+
"macaroon": "/path/in/container/lnd/bob/data/chain/bitcoin/regtest/admin.macaroon",
57+
"cert": "/path/in/container/lnd/bob/tls.cert"
6058
}
6159
```
6260

sim-cli/src/main.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::PathBuf;
44
use std::sync::Arc;
55
use tokio::sync::Mutex;
66

7+
use anyhow::anyhow;
78
use clap::Parser;
89
use log::LevelFilter;
910
use sim_lib::{
@@ -60,7 +61,8 @@ async fn main() -> anyhow::Result<()> {
6061
.unwrap();
6162

6263
let SimParams { nodes, activity } =
63-
serde_json::from_str(&std::fs::read_to_string(cli.sim_file)?)?;
64+
serde_json::from_str(&std::fs::read_to_string(cli.sim_file)?)
65+
.map_err(|e| anyhow!("Could not deserialize node connection data or activity description from simulation file (line {}, col {}).", e.line(), e.column()))?;
6466

6567
let mut clients: HashMap<PublicKey, Arc<Mutex<dyn LightningNode + Send>>> = HashMap::new();
6668
let mut pk_node_map = HashMap::new();

sim-lib/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ mod random_activity;
2525
mod serializers;
2626

2727
#[derive(Serialize, Deserialize, Debug, Clone)]
28+
#[serde(untagged)]
2829
pub enum NodeConnection {
29-
#[serde(alias = "lnd", alias = "Lnd")]
3030
LND(lnd::LndConnection),
31-
#[serde(alias = "cln", alias = "Cln")]
3231
CLN(cln::ClnConnection),
3332
}
3433

0 commit comments

Comments
 (0)