Skip to content

Commit

Permalink
multi: once off documentation comment sweep
Browse files Browse the repository at this point in the history
  • Loading branch information
carlaKC committed Jan 30, 2024
1 parent 0deb2cb commit f028342
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 32 deletions.
4 changes: 2 additions & 2 deletions sim-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ async fn main() -> anyhow::Result<()> {
serde_json::from_str(&std::fs::read_to_string(sim_path)?)
.map_err(|e| anyhow!("Could not deserialize node connection data or activity description from simulation file (line {}, col {}).", e.line(), e.column()))?;

let mut clients: HashMap<PublicKey, Arc<Mutex<dyn LightningNode + Send>>> = HashMap::new();
let mut clients: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>> = HashMap::new();
let mut pk_node_map = HashMap::new();
let mut alias_node_map = HashMap::new();

for connection in nodes {
// TODO: Feels like there should be a better way of doing this without having to Arc<Mutex<T>>> it at this time.
// Box sort of works, but we won't know the size of the dyn LightningNode at compile time so the compiler will
// scream at us when trying to create the Arc<Mutex>> later on while adding the node to the clients map
let node: Arc<Mutex<dyn LightningNode + Send>> = match connection {
let node: Arc<Mutex<dyn LightningNode>> = match connection {
NodeConnection::LND(c) => Arc::new(Mutex::new(LndNode::new(c).await?)),
NodeConnection::CLN(c) => Arc::new(Mutex::new(ClnNode::new(c).await?)),
};
Expand Down
53 changes: 26 additions & 27 deletions sim-lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,29 +95,29 @@ pub struct SimParams {
/// [NodeId], which enables the use of public keys and aliases in the simulation description.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ActivityParser {
// The source of the payment.
/// The source of the payment.
#[serde(with = "serializers::serde_node_id")]
pub source: NodeId,
// The destination of the payment.
/// The destination of the payment.
#[serde(with = "serializers::serde_node_id")]
pub destination: NodeId,
// The interval of the event, as in every how many seconds the payment is performed.
/// The interval of the event, as in every how many seconds the payment is performed.
pub interval_secs: u16,
// The amount of m_sat to used in this payment.
/// The amount of m_sat to used in this payment.
pub amount_msat: u64,
}

/// Data structure used internally by the simulator. Both source and destination are represented as [PublicKey] here.
/// This is constructed during activity validation and passed along to the [Simulation].
#[derive(Debug, Clone)]
pub struct ActivityDefinition {
// The source of the payment.
/// The source of the payment.
pub source: NodeInfo,
// The destination of the payment.
/// The destination of the payment.
pub destination: NodeInfo,
// The interval of the event, as in every how many seconds the payment is performed.
/// The interval of the event, as in every how many seconds the payment is performed.
pub interval_secs: u16,
// The amount of m_sat to used in this payment.
/// The amount of m_sat to used in this payment.
pub amount_msat: u64,
}

Expand All @@ -135,7 +135,6 @@ pub enum SimulationError {
RandomActivityError(RandomActivityError),
}

// Phase 2: Event Queue
#[derive(Debug, Error)]
pub enum LightningError {
#[error("Node connection error: {0}")]
Expand Down Expand Up @@ -204,8 +203,8 @@ pub trait LightningNode: Send {
}

pub trait DestinationGenerator: Send {
// choose_destination picks a destination node within the network, returning the node's information and its
// capacity (if available).
/// choose_destination picks a destination node within the network, returning the node's information and its
/// capacity (if available).
fn choose_destination(&self, source: PublicKey) -> (NodeInfo, Option<u64>);
}

Expand All @@ -214,10 +213,10 @@ pub trait DestinationGenerator: Send {
pub struct PaymentGenerationError(String);

pub trait PaymentGenerator: Display + Send {
// Returns the number of seconds that a node should wait until firing its next payment.
/// Returns the number of seconds that a node should wait until firing its next payment.
fn next_payment_wait(&self) -> time::Duration;

// Returns a payment amount based, with a destination capacity optionally provided to inform the amount picked.
/// Returns a payment amount based, with a destination capacity optionally provided to inform the amount picked.
fn payment_amount(
&self,
destination_capacity: Option<u64>,
Expand Down Expand Up @@ -324,14 +323,14 @@ enum SimulationOutput {

#[derive(Clone)]
pub struct Simulation {
// The lightning node that is being simulated.
/// The lightning node that is being simulated.
nodes: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>>,
// The activity that are to be executed on the node.
/// The activity that are to be executed on the node.
activity: Vec<ActivityDefinition>,
// High level triggers used to manage simulation tasks and shutdown.
/// High level triggers used to manage simulation tasks and shutdown.
shutdown_trigger: Trigger,
shutdown_listener: Listener,
// Total simulation time. The simulation will run forever if undefined.
/// Total simulation time. The simulation will run forever if undefined.
total_time: Option<time::Duration>,
/// The expected payment size for the network.
expected_payment_msat: u64,
Expand Down Expand Up @@ -425,7 +424,7 @@ impl Simulation {
Ok(())
}

// validates that the nodes are all on the same network and ensures that we're not running on mainnet.
/// validates that the nodes are all on the same network and ensures that we're not running on mainnet.
async fn validate_node_network(&self) -> Result<(), LightningError> {
if self.nodes.is_empty() {
return Err(LightningError::ValidationError(
Expand Down Expand Up @@ -531,8 +530,8 @@ impl Simulation {
self.shutdown_trigger.trigger()
}

// run_data_collection starts the tasks required for the simulation to report of the results of the activity that
// it generates. The simulation should report outputs via the receiver that is passed in.
/// run_data_collection starts the tasks required for the simulation to report of the results of the activity that
/// it generates. The simulation should report outputs via the receiver that is passed in.
fn run_data_collection(
&self,
output_receiver: Receiver<SimulationOutput>,
Expand Down Expand Up @@ -716,11 +715,11 @@ impl Simulation {
}
}

// consume_events processes events that are crated for a lightning node that we can execute events on. Any output
// that is generated from the event being executed is piped into a channel to handle the result of the event. If it
// exits, it will use the trigger provided to trigger shutdown in other threads. If an error occurs elsewhere, we
// expect the senders corresponding to our receiver to be dropped, which will cause the receiver to error out and
// exit.
/// events that are crated for a lightning node that we can execute events on. Any output that is generated from the
/// event being executed is piped into a channel to handle the result of the event. If it exits, it will use the
/// trigger provided to trigger shutdown in other threads. If an error occurs elsewhere, we expect the senders
/// corresponding to our receiver to be dropped, which will cause the receiver to error out and
/// exit.
async fn consume_events(
node: Arc<Mutex<dyn LightningNode>>,
mut receiver: Receiver<SimulationEvent>,
Expand Down Expand Up @@ -787,8 +786,8 @@ async fn consume_events(
}
}

// produce events generates events for the activity description provided. It accepts a shutdown listener so it can
// exit if other threads signal that they have errored out.
/// produce events generates events for the activity description provided. It accepts a shutdown listener so it can
/// exit if other threads signal that they have errored out.
async fn produce_events<N: DestinationGenerator + ?Sized, A: PaymentGenerator + ?Sized>(
source: NodeInfo,
network_generator: Arc<Mutex<N>>,
Expand Down
6 changes: 3 additions & 3 deletions sim-lib/src/random_activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ pub struct NetworkGraphView {
}

impl NetworkGraphView {
// Creates a network view for the map of node public keys to capacity (in millisatoshis) provided. Returns an error
// if any node's capacity is zero (the node cannot receive), or there are not at least two nodes (one node can't
// send to itself).
/// Creates a network view for the map of node public keys to capacity (in millisatoshis) provided. Returns an error
/// if any node's capacity is zero (the node cannot receive), or there are not at least two nodes (one node can't
/// send to itself).
pub fn new(nodes: Vec<(NodeInfo, u64)>) -> Result<Self, RandomActivityError> {
if nodes.len() < 2 {
return Err(RandomActivityError::ValueError(
Expand Down

0 comments on commit f028342

Please sign in to comment.