-
Notifications
You must be signed in to change notification settings - Fork 37
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: add simulated clock to speed up simulations #242
base: main
Are you sure you want to change the base?
Conversation
Note to self - will update in the next push: Right now, SimLN is calling |
This looks good to me:) I had a question about how this would be used in the wild. If the purpose is to only speed up transactions, I think this works great! I was wondering if you may run into issues with clock skew because of how |
The plan would be to use this alongside #248 to run sped-up transactions on a simulated network. When it comes time to surface this option, we'll only make it available if running with a fake network - trying to speed up transactions on real nodes that are running with regular clock time would indeed be a mess (if that's what you want, just setup your simulation to have more transactions).
I think that provided we always rely on the simulation clock we should be ok? Eg with a 10x speed up, if we have a sleep for 10 minutes we should just tell EDIT: is this the sort of thing you're concerned about? Where the clock "runs away from us" and calling libraries need to be aware of the underlying impl. Sadly I don't have any good ideas here :( |
LGTM!! |
9b2da47
to
e468a4d
Compare
simln-lib/src/lib.rs
Outdated
@@ -511,12 +514,13 @@ struct ExecutorKit { | |||
payment_generator: Box<dyn PaymentGenerator>, | |||
} | |||
|
|||
impl Simulation { | |||
impl <C: Clock + 'static> Simulation <C>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TODO(carla): can this be replaced with a lifetime?
2fe7cd4
to
8468d51
Compare
Force pushed to:
Will start with fixups once this is in real review (needs to be rebased on #248 first, waiting till that approach has stabilized). |
approach looks good to me (: ran some simulations using |
I think I misunderstood how |
Add a trait to mock time so that when we get to using simulation time, we don't need to refactor. At present, this is just a wrapper over system time.
Allows us to keep the API for our clock a little simpler.
As is, channels were all imported with different timestamps. There's no use for this, and it runs the risk of exceeding LDK's 24h limit if we're using a very sped up clock. Using a single value fixes this.
8468d51
to
8bb2b6e
Compare
Given that this is being used quite extensively in simulations and working well, I think that we can go ahead with review even though there isn't a way to test this and then base #248 on top of it (instead of the other way around)? Adding it just requires a cli flag and some validation so it shouldn't be much of a lift. |
This PR adds a
Clock
trait and makesSimulation
generic over this trait so that we have the ability to mock time, as described in #81. The default implementation of this trait just thinly wraps a system clock.For the version where we want to speed things up, we track the instant that we started our clock and apply a multiplier to speed up time passed. For example, if we're running with a multiplier of 10:
When dealing with durations, we can simply multiply/divide to move between simulation and real time periods.
When dealing with timestamps, we use the elapsed duration since start to figure out a sped up clock time.
This PR doesn't surface the implementation anywhere, because it doesn't really make sense to run this speed up on real nodes - things get messy when you're using different clocks; if you want things faster on your real node network, just set the activity to fire more often or the random activity to send more payments.
It is, however, very useful once we've implemented #215, because we can speed up our sim-node network.