Skip to content

Commit

Permalink
generate transactions JIT
Browse files Browse the repository at this point in the history
  • Loading branch information
rob-maron committed Sep 28, 2023
1 parent e29b67f commit 77b28b6
Showing 1 changed file with 12 additions and 22 deletions.
34 changes: 12 additions & 22 deletions crates/hotshot/examples/infra/modDA.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ use libp2p_networking::{
network::{MeshParams, NetworkNodeConfigBuilder, NetworkNodeType},
reexport::Multiaddr,
};
use rand::rngs::StdRng;
use rand::SeedableRng;
use std::{collections::BTreeSet, sync::Arc};
use std::{num::NonZeroUsize, str::FromStr};
// use libp2p::{
Expand All @@ -59,9 +61,9 @@ use std::{num::NonZeroUsize, str::FromStr};
// };
use libp2p_identity::PeerId;
// use libp2p_networking::network::{MeshParams, NetworkNodeConfigBuilder, NetworkNodeType};
use std::{fmt::Debug, net::Ipv4Addr};
use std::{
//collections::{BTreeSet, VecDeque},
collections::VecDeque,
//fs,
mem,
net::IpAddr,
Expand All @@ -71,7 +73,6 @@ use std::{
//time::{Duration, Instant},
time::Instant,
};
use std::{fmt::Debug, net::Ipv4Addr};
//use surf_disco::error::ClientError;
//use surf_disco::Client;
use tracing::{debug, error, info, warn};
Expand Down Expand Up @@ -267,26 +268,10 @@ pub trait RunDA<
} = self.get_config();

let size = mem::size_of::<TYPES::Transaction>();
let adjusted_padding = if padding < size { 0 } else { padding - size };
let mut txns: VecDeque<TYPES::Transaction> = VecDeque::new();

// TODO ED: In the future we should have each node generate transactions every round to simulate a more realistic network
let tx_to_gen = transactions_per_round * rounds * 3;
{
let mut txn_rng = rand::thread_rng();
for _ in 0..tx_to_gen {
let txn =
<<TYPES as NodeType>::StateType as TestableState>::create_random_transaction(
None,
&mut txn_rng,
padding as u64,
);
txns.push_back(txn);
}
}
debug!("Generated {} transactions", tx_to_gen);
let padding = padding.saturating_sub(size);
let mut txn_rng = StdRng::seed_from_u64(node_index);

debug!("Adjusted padding size is {:?} bytes", adjusted_padding);
debug!("Adjusted padding size is {:?} bytes", padding);

let mut total_transactions_committed = 0;
let mut total_transactions_sent = 0;
Expand Down Expand Up @@ -330,7 +315,12 @@ pub trait RunDA<

// send transactions
for _ in 0..transactions_to_send_per_round {
let txn = txns.pop_front().unwrap();
let txn =
<<TYPES as NodeType>::StateType as TestableState>::create_random_transaction(
None,
&mut txn_rng,
padding as u64,
);
_ = context.submit_transaction(txn).await.unwrap();
total_transactions_sent += 1;
}
Expand Down

0 comments on commit 77b28b6

Please sign in to comment.