Skip to content

Commit a7635fe

Browse files
author
Ifeanyichukwu
committed
chore: resolve conflicts, clean up and improve code health
1 parent 8cb5016 commit a7635fe

File tree

4 files changed

+23
-38
lines changed

4 files changed

+23
-38
lines changed

README.md

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,7 @@ and destination nodes, you can provide `activity` descriptions of the
150150
source, destination, frequency and amount for payments that you'd like
151151
to execute. Note that `source` nodes _must_ be contained in `nodes`,
152152
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).
153+
this may result in liquidity draining over time).
156154

157155
Required fields:
158156
```
@@ -180,12 +178,6 @@ The example simulation file below sets up the following simulation:
180178
* Dispatch 1000 msat payments from `Bob` to `Dave` every 2 seconds.
181179
* Dispatch 10 payments (5000 msat each) from `Erin` to `Frank` at 2 second intervals, starting 20 seconds into the sim.
182180

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-
189181
```
190182
{
191183
"nodes": [

sim-cli/src/main.rs

Lines changed: 8 additions & 6 deletions
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.
@@ -182,14 +183,15 @@ async fn main() -> anyhow::Result<()> {
182183
},
183184
};
184185

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-
}
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+
),));
191191
}
192192

193+
activity_name_map.insert(act.activity_name.clone(), act.clone());
194+
193195
validated_activities.push(ActivityDefinition {
194196
source,
195197
destination,

sim-lib/src/defined_activity.rs

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

1514
impl DefinedPaymentActivity {
@@ -19,14 +18,13 @@ impl DefinedPaymentActivity {
1918
count: Option<u64>,
2019
wait: Duration,
2120
amount: u64,
22-
activity_name: String) -> Self {
21+
) -> Self {
2322
DefinedPaymentActivity {
2423
destination,
2524
start,
2625
count,
2726
wait,
2827
amount,
29-
activity_name,
3028
}
3129
}
3230
}
@@ -35,8 +33,8 @@ impl fmt::Display for DefinedPaymentActivity {
3533
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3634
write!(
3735
f,
38-
"{} activity: static payment of {} to {} every {:?}",
39-
self.activity_name, self.amount, self.destination, self.wait
36+
"static payment of {} to {} every {:?}",
37+
self.amount, self.destination, self.wait
4038
)
4139
}
4240
}
@@ -88,7 +86,6 @@ mod tests {
8886

8987
let source = get_random_keypair();
9088
let payment_amt = 50;
91-
let activity_name = String::from("Coffee Purchase");
9289

9390
let generator = DefinedPaymentActivity::new(
9491
node.clone(),
@@ -97,12 +94,6 @@ mod tests {
9794
Duration::from_secs(60),
9895
payment_amt,
9996
);
100-
let generator = DefinedPaymentActivity::new(
101-
node.clone(),
102-
Duration::from_secs(60),
103-
payment_amt,
104-
activity_name,
105-
);
10697

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

sim-lib/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ impl Simulation {
716716
description.count,
717717
Duration::from_secs(description.interval_secs.into()),
718718
description.amount_msat,
719-
activity_name.clone(),
720719
);
721720

722721
generators.push(ExecutorKit {
@@ -861,15 +860,16 @@ impl Simulation {
861860
let source = executor.source_info.clone();
862861

863862
log::info!(
864-
"Starting activity producer for {}: {}.",
863+
"Starting {} activity producer for {}: {}.",
864+
executor.activity_name,
865865
source,
866866
executor.payment_generator
867867
);
868868

869869
if let Err(e) = produce_events(
870870
executor.source_info,
871871
executor.activity_name,
872-
executor.network_generator,
872+
executor.network_generator,
873873
executor.payment_generator,
874874
pe_sender,
875875
pe_listener,
@@ -972,11 +972,6 @@ async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator +
972972
listener: Listener,
973973
) -> Result<(), SimulationError> {
974974
let mut current_count = 0;
975-
) {
976-
log::info!(
977-
"Started {activity_name} activity => activity producer for {source}: {node_generator}."
978-
);
979-
980975
loop {
981976
if let Some(c) = node_generator.payment_count() {
982977
if c == current_count {
@@ -1127,12 +1122,17 @@ impl PaymentResultLogger {
11271122
}
11281123
}
11291124

1125+
// TODO: Add activity name and handle the initial processing log with few LOC
11301126
impl Display for PaymentResultLogger {
11311127
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
11321128
let total_payments = self.success_payment + self.failed_payment;
1129+
1130+
// if self.activity_name
1131+
11331132
write!(
11341133
f,
1135-
"Processed {} payments sending {} msat total with {:.2}% success rate.",
1134+
"{} activity: Processed {} payments sending {} msat total with {:.2}% success rate.",
1135+
self.activity_name,
11361136
total_payments,
11371137
self.total_sent,
11381138
(self.success_payment as f64 / total_payments as f64) * 100.0
@@ -1201,7 +1201,7 @@ async fn produce_simulation_results(
12011201
}
12021202
},
12031203
SimulationOutput::SendPaymentFailure(payment, result) => {
1204-
if results.send((payment, result.clone())).await.is_err() {
1204+
if results.send((payment.clone(), result.clone())).await.is_err() {
12051205
return Err(SimulationError::MpscChannelError(
12061206
format!("Failed to send payment result: {result} for payment {:?} dispatched at {:?}.", payment.hash, payment.dispatch_time),
12071207
));
@@ -1272,7 +1272,7 @@ async fn track_payment_result(
12721272
_ = listener.clone() => {
12731273
log::debug!("Track payment result received a shutdown signal.");
12741274
},
1275-
send_payment_result = results.send((payment, res.clone())) => {
1275+
send_payment_result = results.send((payment.clone(), res.clone())) => {
12761276
if send_payment_result.is_err() {
12771277
return Err(SimulationError::MpscChannelError(format!("Failed to send payment result {res} for payment {payment}.")))
12781278
}

0 commit comments

Comments
 (0)