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

Use one RNG per Event Producer #192

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions sim-cli/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use bitcoin::secp256k1::PublicKey;
use sim_lib::SimulationCfg;
use std::collections::HashMap;
use std::path::PathBuf;
use std::sync::Arc;
Expand Down Expand Up @@ -205,13 +206,15 @@ async fn main() -> anyhow::Result<()> {
};

let sim = Simulation::new(
SimulationCfg::new(
cli.total_time,
cli.expected_pmt_amt,
cli.capacity_multiplier,
write_results,
cli.fix_seed,
),
clients,
validated_activities,
cli.total_time,
cli.expected_pmt_amt,
cli.capacity_multiplier,
write_results,
cli.fix_seed,
);
let sim2 = sim.clone();

Expand Down
18 changes: 12 additions & 6 deletions sim-lib/src/defined_activity.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::{
DestinationGenerationError, DestinationGenerator, NodeInfo, PaymentGenerationError,
PaymentGenerator, ValueOrRange,
PaymentGenerator, RngSend, ValueOrRange,
};
use std::fmt;
use tokio::time::Duration;
Expand Down Expand Up @@ -45,6 +45,7 @@ impl fmt::Display for DefinedPaymentActivity {
impl DestinationGenerator for DefinedPaymentActivity {
fn choose_destination(
&self,
_: &mut RngSend,
_: bitcoin::secp256k1::PublicKey,
) -> Result<(NodeInfo, Option<u64>), DestinationGenerationError> {
Ok((self.destination.clone(), None))
Expand All @@ -60,12 +61,13 @@ impl PaymentGenerator for DefinedPaymentActivity {
self.count
}

fn next_payment_wait(&self) -> Result<Duration, PaymentGenerationError> {
fn next_payment_wait(&self, _: &mut RngSend) -> Result<Duration, PaymentGenerationError> {
Ok(Duration::from_secs(self.wait.value() as u64))
}

fn payment_amount(
&self,
_: &mut RngSend,
destination_capacity: Option<u64>,
) -> Result<u64, crate::PaymentGenerationError> {
if destination_capacity.is_some() {
Expand All @@ -82,7 +84,7 @@ impl PaymentGenerator for DefinedPaymentActivity {
mod tests {
use super::DefinedPaymentActivity;
use crate::test_utils::{create_nodes, get_random_keypair};
use crate::{DestinationGenerator, PaymentGenerationError, PaymentGenerator};
use crate::{DestinationGenerator, PaymentGenerationError, PaymentGenerator, RngSend};

#[test]
fn test_defined_activity_generator() {
Expand All @@ -100,13 +102,17 @@ mod tests {
crate::ValueOrRange::Value(payment_amt),
);

let (dest, dest_capacity) = generator.choose_destination(source.1).unwrap();
let mut rng = RngSend::new(None, 0);
let (dest, dest_capacity) = generator.choose_destination(&mut rng, source.1).unwrap();
assert_eq!(node.pubkey, dest.pubkey);
assert!(dest_capacity.is_none());

assert_eq!(payment_amt, generator.payment_amount(None).unwrap());
assert_eq!(
payment_amt,
generator.payment_amount(&mut rng, None).unwrap()
);
assert!(matches!(
generator.payment_amount(Some(10)),
generator.payment_amount(&mut rng, Some(10)),
Err(PaymentGenerationError(..))
));
}
Expand Down
Loading