Skip to content

Instantly share code, notes, and snippets.

@0ex-d
Created December 13, 2024 00:36
Show Gist options
  • Save 0ex-d/6e80dd78d14f04a264783fcadc45dcb2 to your computer and use it in GitHub Desktop.
Save 0ex-d/6e80dd78d14f04a264783fcadc45dcb2 to your computer and use it in GitHub Desktop.
fn simulate_mempool_flood() {
let mut mempool: Vec<Transaction> = Vec::new();
let mut rng = rand::thread_rng();
for i in 0..10_000 {
let tx = Transaction {
id: format!("tx_{}", i),
fee: rng.gen_range(1..=10),
vin: if rng.gen_bool(0.9) {
vec![format!("utxo_{}", rng.gen_range(1..=1000))]
} else {
vec![format!("nonexistent_utxo_{}", rng.gen_range(1..=1000))]
},
vout: vec![format!("address_{}", rng.gen_range(1..=1000))],
};
mempool.push(tx);
}
println!("Mempool flooded with {} transactions", mempool.len());
let valid_transactions: Vec<_> = mempool
.iter()
.filter(|tx| !tx.vin.iter().any(|input| input.contains("nonexistent")))
.collect();
println!("Valid transactions count: {}", valid_transactions.len());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment