Skip to content

Commit 0d163bb

Browse files
carlaKCclaude
andcommitted
simln-lib: read payment dispatch time from the clock
send_payment stamped each Payment's dispatch_time with SystemTime::now(), bypassing the simulation clock. Under discrete-event simulation the wall clock does not advance with virtual time, so this both broke virtual-time timestamps and made results non-reproducible. Stamp the dispatch time from the simulation clock once the inter-payment wait has elapsed, and thread it into send_payment as an argument. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 0405467 commit 0d163bb

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

simln-lib/src/lib.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,12 +1195,14 @@ async fn produce_payment_events<C: Clock>(
11951195
_ = pe_clock.sleep(wait_time) => {
11961196
generate_payment(&mut heap, source, &mut payments_tracker, clock.now()).await?;
11971197

1198+
// Stamp the dispatch time from the simulation clock now that the wait has elapsed.
1199+
let dispatch_time = pe_clock.now();
11981200
tasks.spawn(async move {
11991201
log::debug!("Generated payment: {source} -> {}: {amount} msat.", destination);
12001202

12011203
// Send the payment, exiting if we can no longer send to the consumer.
12021204
let event = SimulationEvent::SendPayment(destination.clone(), amount);
1203-
if let Err(e) = send_payment(node, pe_output_sender, event.clone()).await {
1205+
if let Err(e) = send_payment(node, pe_output_sender, event.clone(), dispatch_time).await {
12041206
pe_shutdown.trigger();
12051207
log::debug!("Not able to send event payment for {amount}: {source} -> {}. Exited with error {e}.", destination);
12061208
} else {
@@ -1275,6 +1277,7 @@ async fn send_payment(
12751277
node: Arc<Mutex<dyn LightningNode>>,
12761278
sender: Sender<SimulationOutput>,
12771279
simulation_event: SimulationEvent,
1280+
dispatch_time: SystemTime,
12781281
) -> Result<(), SimulationError> {
12791282
match simulation_event {
12801283
SimulationEvent::SendPayment(dest, amt_msat) => {
@@ -1285,7 +1288,9 @@ async fn send_payment(
12851288
hash: None,
12861289
amount_msat: amt_msat,
12871290
destination: dest.pubkey,
1288-
dispatch_time: SystemTime::now(),
1291+
// Take the dispatch time from the simulation clock rather than the wall clock, so that it advances with
1292+
// virtual time under discrete-event simulation and stays reproducible across runs.
1293+
dispatch_time,
12891294
};
12901295

12911296
let outcome = match node.send_payment(dest.pubkey, amt_msat).await {

0 commit comments

Comments
 (0)