sim: Change a few things in the simulator

1. Simplify latency calculation to be more predictable, otherwise,
   setting a latency is not super useful.
2. Turn a hard error into a log. It's not worth fixing it now though, as
   it isn't a problem for the tests.
This commit is contained in:
cloudhead 2024-02-09 11:32:57 +01:00
parent d1f4161ee9
commit 4307bdaae4
No known key found for this signature in database
1 changed files with 5 additions and 22 deletions

View File

@ -259,25 +259,7 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
self.latencies
.get(&(from, to))
.cloned()
.map(|l| {
let mut rng = self.rng.borrow_mut();
if l <= MIN_LATENCY {
l
} else {
// Create variance in the latency. The resulting latency
// will be between half, and two times the base latency.
let millis = l.as_millis();
if rng.bool() {
// More latency.
LocalDuration::from_millis(millis + rng.u128(0..millis))
} else {
// Less latency.
LocalDuration::from_millis(millis - rng.u128(0..millis / 2))
}
}
})
.map(|l| if l < MIN_LATENCY { MIN_LATENCY } else { l })
.unwrap_or_else(|| MIN_LATENCY)
}
@ -409,9 +391,10 @@ impl<S: WriteStorage + 'static, G: Signer> Simulation<S, G> {
let attempt = self.attempts.remove(&conn);
let connection = self.connections.remove(&conn);
// Can't be both attempting and connected.
assert!(!(attempt && connection));
// FIXME: This shouldn't happen, but it does when latency is introduced.
if attempt && connection {
log::error!(target: "sim", "Connection is attempted and connected at the same time");
}
if attempt || connection {
p.disconnected(id, &reason);
}