Skip to content

Commit c404905

Browse files
committed
fixup! 19581f3
1 parent b3cb21d commit c404905

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

simln-lib/src/lib.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,6 @@ struct ExecutorKit {
628628
struct PaymentEvent {
629629
pubkey: PublicKey,
630630
absolute_time: SystemTime,
631-
wait_time: Duration,
632631
destination: NodeInfo,
633632
capacity: Option<u64>,
634633
}
@@ -1097,11 +1096,19 @@ impl<C: Clock + 'static> Simulation<C> {
10971096
match heap.pop() {
10981097
Some(Reverse(PaymentEvent {
10991098
pubkey,
1100-
absolute_time: _,
1101-
wait_time,
1099+
absolute_time,
11021100
destination,
11031101
capacity
11041102
})) => {
1103+
let internal_now = SystemTime::now();
1104+
let wait_time = match absolute_time.duration_since(internal_now) {
1105+
Ok(elapsed) => {
1106+
elapsed
1107+
},
1108+
Err(e) => {
1109+
e.duration()
1110+
}
1111+
};
11051112
let payload = payment_event_payloads.get(&pubkey).ok_or(SimulationError::PaymentGenerationError(
11061113
PaymentGenerationError(format!("executor {} not found", pubkey)),
11071114
))?;
@@ -1122,22 +1129,24 @@ impl<C: Clock + 'static> Simulation<C> {
11221129
// a payment amount something has gone wrong (because we should have validated that we can always
11231130
// generate amounts), so we exit.
11241131
let amount = payload.executor.payment_generator.payment_amount(capacity).map_err(SimulationError::PaymentGenerationError)?;
1125-
generate_payment(&mut heap, pubkey, payload.current_count + 1, &mut payment_event_payloads, SystemTime::now()).await?;
11261132
if amount == 0 {
11271133
log::debug!(
11281134
"Skipping zero amount payment for {source} -> {}.", destination
11291135
);
1136+
generate_payment(&mut heap, pubkey, payload.current_count, &mut payment_event_payloads, SystemTime::now()).await?;
11301137
continue;
11311138
}
11321139

11331140
// Wait until our time to next payment has elapsed then execute a random amount payment to a random
11341141
// destination.
1142+
let next_payment_count = payload.current_count + 1;
11351143
select! {
11361144
biased;
11371145
_ = listener.clone() => {
11381146
return Ok(())
11391147
},
11401148
_ = pe_clock.sleep(wait_time) => {
1149+
generate_payment(&mut heap, pubkey, next_payment_count, &mut payment_event_payloads, SystemTime::now()).await?;
11411150
task_clone.spawn(async move {
11421151
log::debug!("Generated payment: {source} -> {}: {amount} msat.", destination);
11431152

@@ -1533,7 +1542,6 @@ async fn generate_payment(
15331542
let payment_event = PaymentEvent {
15341543
pubkey,
15351544
absolute_time,
1536-
wait_time,
15371545
destination,
15381546
capacity,
15391547
};
@@ -2054,24 +2062,25 @@ mod tests {
20542062
let elapsed = start.elapsed();
20552063

20562064
let expected_payment_list = vec![
2057-
node_2.pubkey,
20582065
node_2.pubkey,
20592066
node_4.pubkey,
20602067
node_2.pubkey,
2061-
node_4.pubkey,
20622068
node_2.pubkey,
20632069
node_4.pubkey,
20642070
node_2.pubkey,
2071+
node_2.pubkey,
2072+
node_4.pubkey,
20652073
node_4.pubkey,
20662074
node_4.pubkey,
20672075
];
20682076

2069-
// Check that simulation ran 30 because
2077+
// Check that simulation ran 20ish seconds because
20702078
// from activity_1 there are 5 payments with a wait_time of 2s -> 10s
20712079
// from activity_2 there are 5 payments with a wait_time of 4s -> 20s
2080+
// but the wait time is interleave between the payments.
20722081
assert!(
2073-
elapsed >= Duration::from_secs(30),
2074-
"Simulation should have run at least for 30s, took {:?}",
2082+
elapsed <= Duration::from_secs(21),
2083+
"Simulation should have run no more than 21, took {:?}",
20752084
elapsed
20762085
);
20772086

0 commit comments

Comments
 (0)