Skip to content

Commit 5692374

Browse files
authored
Merge pull request #191 from enigbe/feat-run-simulator-with-fixed-seed
chore(rng): clean up documentation and RNG type
2 parents edb88e6 + 959507a commit 5692374

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,12 @@ of the random activity that is generated:
132132
capacity in a month.
133133
* `capacity-multiplier=0.5` means that each node sends half their
134134
capacity in a month.
135-
* `--fix-seed`: a `u64` value that allows you to generate random activities deterministically from the provided seed, albeit with some limitations. The simulations are not guaranteed to be perfectly deterministic because tasks complete in slightly different orders on each run of the simulator. With a fixed seed, we can guarantee that the order in which activities are dispatched will be deterministic.
135+
* `--fix-seed`: a `u64` value that allows you to generate random activities
136+
deterministically from the provided seed, albeit with some limitations.
137+
The simulations are not guaranteed to be perfectly deterministic because
138+
tasks complete in slightly different orders on each run of the simulator.
139+
With a fixed seed, we can guarantee that the order in which activities are
140+
dispatched will be deterministic.
136141

137142
### Setup - Defined Activity
138143
If you would like SimLN to generate a specific payments between source

sim-lib/src/lib.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,12 @@ enum SimulationOutput {
453453
///
454454
/// **Note**: `StdMutex`, i.e. (`std::sync::Mutex`), is used here to avoid making the traits
455455
/// `DestinationGenerator` and `PaymentGenerator` async.
456-
type MutRngType = Arc<StdMutex<Box<dyn RngCore + Send>>>;
456+
type MutRngType = Arc<StdMutex<dyn RngCore + Send>>;
457457

458458
/// Newtype for `MutRngType` to encapsulate and hide implementation details for
459459
/// creating new `MutRngType` types. Provides convenient API for the same purpose.
460460
#[derive(Clone)]
461-
struct MutRng(pub MutRngType);
461+
struct MutRng(MutRngType);
462462

463463
impl MutRng {
464464
/// Creates a new MutRng given an optional `u64` argument. If `seed_opt` is `Some`,
@@ -467,11 +467,9 @@ impl MutRng {
467467
/// non-deterministic source of entropy.
468468
pub fn new(seed_opt: Option<u64>) -> Self {
469469
if let Some(seed) = seed_opt {
470-
Self(Arc::new(StdMutex::new(
471-
Box::new(ChaCha8Rng::seed_from_u64(seed)) as Box<dyn RngCore + Send>,
472-
)))
470+
Self(Arc::new(StdMutex::new(ChaCha8Rng::seed_from_u64(seed))))
473471
} else {
474-
Self(Arc::new(StdMutex::new(Box::new(StdRng::from_entropy()))))
472+
Self(Arc::new(StdMutex::new(StdRng::from_entropy())))
475473
}
476474
}
477475
}

0 commit comments

Comments
 (0)