Skip to content

Commit

Permalink
sim-lib: ensures destination supports keysend for random payments
Browse files Browse the repository at this point in the history
  • Loading branch information
sr-gi committed Oct 5, 2023
1 parent e884245 commit 98c15d0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -819,32 +819,37 @@ async fn produce_random_events<N: NetworkGenerator, A: PaymentGenerator + Displa
// Wait until our time to next payment has elapsed then execute a random amount payment to a random
// destination.
_ = time::sleep(wait) => {
let destination = network_generator.lock().await.sample_node_by_capacity(source.pubkey);
let (destination, capacity) = network_generator.lock().await.sample_node_by_capacity(source.pubkey);

if !destination.features.supports_keysend() {
log::debug!("Destination does not support keysend, skipping payment: {source} -> {destination}");
continue;
};

// Only proceed with a payment if the amount is non-zero, otherwise skip this round. If we can't get
// a payment amount something has gone wrong (because we should have validated that we can always
// generate amounts), so we exit.
let amount = match node_generator.payment_amount(destination.1) {
let amount = match node_generator.payment_amount(capacity) {
Ok(amt) => {
if amt == 0 {
log::debug!("Skipping zero amount payment for {source} -> {}.", destination.0);
log::debug!("Skipping zero amount payment for {source} -> {destination}.");
continue;
}
amt
},
Err(e) => {
log::error!("Could not get amount for {source} -> {}: {e}. Please report a bug!", destination.0);
log::error!("Could not get amount for {source} -> {destination}: {e}. Please report a bug!");
break;
},
};

log::debug!("Generated random payment: {source} -> {}: {amount} msat.", destination.0);
log::debug!("Generated random payment: {source} -> {}: {amount} msat.", destination);

// Send the payment, exiting if we can no longer send to the consumer.
let event = SimulationEvent::SendPayment(destination.0.clone(), amount);
let event = SimulationEvent::SendPayment(destination.clone(), amount);
if let Err(e) = sender.send(event).await {
log::debug!(
"Stopped random producer for {amount}: {source} -> {}. Consumer error: {e}.", destination.0,
"Stopped random producer for {amount}: {source} -> {destination}. Consumer error: {e}.",
);
break;
}
Expand Down

0 comments on commit 98c15d0

Please sign in to comment.