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: Allows amount and interval ranges in manual activity definition #153

Merged
merged 1 commit into from
May 20, 2024

Conversation

sr-gi
Copy link
Member

@sr-gi sr-gi commented Oct 25, 2023

Values in activities can now be fixed values (e.g. 1000) or ranges (e.g. [500, 1000]).

If a range is provided, the value will be sampled uniformly at random from it.

Close #43

@carlaKC
Copy link
Contributor

carlaKC commented Oct 26, 2023

I think that we should get some refactoring in before we make this type of change.

produce_events and produce_random events should really just be one function that takes a NetworkGenerator and PaymentGenerator. I've started on that refactor, and we're going to have some significant churn if we do this piece first. Since this isn't very high prio I'd like to hold off till that's in if it's okay.

@sr-gi
Copy link
Member Author

sr-gi commented Oct 26, 2023

Sure, no rush on my end

@sr-gi
Copy link
Member Author

sr-gi commented Mar 27, 2024

@carlaKC I saw you tagged #43 for the V3 release. I'm happy to rework this if you find it useful

@carlaKC
Copy link
Contributor

carlaKC commented Mar 27, 2024

@carlaKC I saw you tagged #43 for the V3 release. I'm happy to rework this if you find it useful

That would be great!

@@ -37,7 +39,11 @@ impl DestinationGenerator for DefinedPaymentActivity {

impl PaymentGenerator for DefinedPaymentActivity {
fn next_payment_wait(&self) -> Duration {
self.wait
let wait = Duration::from_secs(self.wait.value() as u64);
Copy link
Member Author

@sr-gi sr-gi Mar 28, 2024

Choose a reason for hiding this comment

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

This is the only bit I'm not super happy about, given we'll be building a Duration object every time we call next_payment_wait, even for fixed wait payments. However, changing this would imply changing the generic for ValueOrRange, and I think potentially more code bolilerplate.

I don't think this is too bad, but I'm open to change it if you find it is.

Copy link
Contributor

Choose a reason for hiding this comment

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

We could have a RangePaymentActivity impl of PaymentGenerator which deals exclusively with the range case?

We can stil parse everything as-is here, but then create either RangePaymentActivity or DefinedPaymentActivity when we switch over from ActiviyParser -> ActivityDefinition. Might cause a little bit of trait object agony in main, but we should be mostly okay in lib 🤞

That might also be quite boiler-platey, but could be worth considering!

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if that would be even more complex.

We have two fields that can be either a range or a value (but only one of them has the initialization issue), how do we deal with the combination of these?

DefinedPaymentActivity would need to have wait: Duration, amount: ValueOrRange<u64> while RangePaymentActivity would have wait: ValueOrRange<u16>, amount: ValueOrRange<u64>. That's really counterintuitive. The alternative would be to only allow either both or none to be ranges, but that's limiting the functionality.

None of the solutions I've been trying to come up with have been satisfying for one reason or another (nor even having a two-argument generic, since deserialization becomes a mess). I've been checking the constructor of Duration and, honestly, it doesn't look that bad (specially considering that we are constructing with nanos=0): https://doc.rust-lang.org/src/core/time.rs.html#199-207

So I would bite the bullet with this one, but I'm happy to be convinced of an alternative solution if you could find something I'm missing

Copy link
Contributor

Choose a reason for hiding this comment

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

Managed to completely miss this comment - sorry!!

DefinedPaymentActivity would need to have wait: Duration, amount: ValueOrRange while RangePaymentActivity would have wait: ValueOrRange, amount: ValueOrRange. That's really counterintuitive. The alternative would be to only allow either both or none to be ranges, but that's limiting the functionality.

Good point, didn't think about the inbetween case where we only want a range for one of them! Agreed, let's just go ahead w/ what we have here.

Copy link
Member Author

Choose a reason for hiding this comment

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

np, I'll update it with the most recent comments

@sr-gi sr-gi requested a review from carlaKC March 28, 2024 12:07
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

Thanks for picking this one back up!

sim-lib/src/defined_activity.rs Outdated Show resolved Hide resolved
@@ -37,7 +39,11 @@ impl DestinationGenerator for DefinedPaymentActivity {

impl PaymentGenerator for DefinedPaymentActivity {
fn next_payment_wait(&self) -> Duration {
self.wait
let wait = Duration::from_secs(self.wait.value() as u64);
Copy link
Contributor

Choose a reason for hiding this comment

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

We could have a RangePaymentActivity impl of PaymentGenerator which deals exclusively with the range case?

We can stil parse everything as-is here, but then create either RangePaymentActivity or DefinedPaymentActivity when we switch over from ActiviyParser -> ActivityDefinition. Might cause a little bit of trait object agony in main, but we should be mostly okay in lib 🤞

That might also be quite boiler-platey, but could be worth considering!

Copy link
Contributor

@bjohnson5 bjohnson5 left a comment

Choose a reason for hiding this comment

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

@sr-gi Hello! I am a new contributor trying to learn my way around sim-ln. Helping out with reviews right now and @carlaKC mentioned this one would be good to look at. I tested out using ranges and it works great, this will be a very useful feature. Left a few small comments.

sim-lib/src/lib.rs Show resolved Hide resolved
sim-lib/src/serializers.rs Show resolved Hide resolved
sim-lib/src/lib.rs Outdated Show resolved Hide resolved
@sr-gi
Copy link
Member Author

sr-gi commented May 7, 2024

CI failure is unrelated

@carlaKC
Copy link
Contributor

carlaKC commented May 15, 2024

CI failure is unrelated

Fixed in #186. Also is this ready for a look?

Amounts and intervals in activities can now be fixed values (e.g. 1000) or ranges (e.g.
[500, 1000]). If a range is provided, the value will be sampled uniformly at
random from it.
@sr-gi
Copy link
Member Author

sr-gi commented May 16, 2024

Rebased to make CI green again.

This should be review-ready.

Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

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

tACK, such a nice feature to add 😻

Comment on lines 79 to +80
use super::DefinedPaymentActivity;
use super::*;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: can remove DefinedPaymentActivity if we're using *

@carlaKC carlaKC requested a review from bjohnson5 May 20, 2024 15:28
@carlaKC carlaKC merged commit a9aba5d into bitcoin-dev-project:main May 20, 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.

Feature: Make the input file format allow ranges in the frequency (interval) and amounts
3 participants