Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sim-lib: only use start delay if explicitly specified #190

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

carlaKC
Copy link
Contributor

@carlaKC carlaKC commented Jun 28, 2024

As is, we'll run with a 0 second start delay for:

  • Random activities
  • Defined activities with no start_secs specified

This very likely isn't the intent for defined activities (people should set start_secs=0 if they want their payments to fire immediately), and doesn't work for random activity because we just fire all payments on start.

Instead, we switch over to using our payment wait as the start delay in the absence of this field being set for defined activities and always for random activities.

Fixes #189

@carlaKC
Copy link
Contributor Author

carlaKC commented Jun 28, 2024

cc @bjohnson5 WDYT?

);
}
// On our first run, add a one-time start delay if set for our payment.
let opt_start = node_generator.payment_start();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: This line doesn't really need to happen every loop.

Calling payment_start() and assigning opt_start is only necessary on the first iteration. It might be worth moving that into the second condition so that if current_count == 0 fails it will short circuit and not execute the payment_start() call.

 let wait = if current_count == 0 && node_generator.payment_start().is_some() {
      let start = node_generator.payment_start().unwrap(); // Safe due to is_some check above.
      log::debug!(
          "Using a start delay. The first payment for {source} will be at {:?}.",
          start
      );

      start
  } else {
...

Still not ideal to call payment_start() twice but I could not think of a way to get the value into the if block otherwise.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still not ideal to call payment_start() twice but I could not think of a way to get the value into the if block otherwise.

Yeah, this was my original reasoning for creating op_start (+ learned that if let has more limited syntax than I thought). Agree that this is probably the best we can do - will add a note on the trait that it's expected to return the same value on every call.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually just went for a more verbose set of branches, I think it's nicer than adding an external expectation on payment_start's behavior (even if in practice it always is the same value) + added a comment explaining.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally agree, that looks really good now. It is also easier to read and understand what is happening.

@bjohnson5
Copy link
Collaborator

@carlaKC Untested ACK. I can test this change next week sometime, but don't let that be a blocker for merging.

@carlaKC carlaKC force-pushed the 189-paymentdelay branch 2 times, most recently from 3e63dd3 to 1231da8 Compare July 8, 2024 14:16
@carlaKC carlaKC marked this pull request as ready for review July 8, 2024 14:18
As is, we'll run with a 0 second start delay for:
- Random activities
- Defined activities with no `start_secs` specified

This very likely isn't the intent for defined activities (people should
set `start_secs=0` if they want their payments to fire immediately),
and doesn't work for random activity because we just fire all payments
on start.

Instead, we switch over to using our payment wait as the start delay in
the absence of this field being set for defined activities and always
for random activities.
@carlaKC
Copy link
Contributor Author

carlaKC commented Jul 8, 2024

Merging so that I can tag a patch with the fix (need the docker image elsewhere). Would be great to get post-merge review on this one anyway 🙏

@carlaKC carlaKC merged commit edb88e6 into bitcoin-dev-project:main Jul 8, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use payment delay for offset if no start_secs is specified
2 participants