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

Random Activity Generator #113

Merged
merged 7 commits into from
Oct 4, 2023
Merged
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
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sim-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ rand = "0.8.5"
hex = "0.4.3"
csv = "1.2.2"
serde_millis = "0.1.1"
rand_distr = "0.4.3"
40 changes: 38 additions & 2 deletions sim-lib/src/cln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use async_trait::async_trait;
use bitcoin::secp256k1::PublicKey;
use cln_grpc::pb::{
listpays_pays::ListpaysPaysStatus, node_client::NodeClient, Amount, GetinfoRequest,
GetinfoResponse, KeysendRequest, KeysendResponse, ListnodesRequest, ListpaysRequest,
ListpaysResponse,
GetinfoResponse, KeysendRequest, KeysendResponse, ListchannelsRequest, ListnodesRequest,
ListpaysRequest, ListpaysResponse,
};
use lightning::ln::features::NodeFeatures;
use lightning::ln::PaymentHash;
Expand Down Expand Up @@ -85,6 +85,36 @@ impl ClnNode {
},
})
}

/// Fetch channels belonging to the local node, initiated locally if is_source is true, and initiated remotely if
/// is_source is false. Introduced as a helper function because CLN doesn't have a single API to list all of our
carlaKC marked this conversation as resolved.
Show resolved Hide resolved
/// node's channels.
async fn node_channels(&mut self, is_source: bool) -> Result<Vec<u64>, LightningError> {
let req = if is_source {
ListchannelsRequest {
source: Some(self.info.pubkey.serialize().to_vec()),
..Default::default()
}
} else {
ListchannelsRequest {
destination: Some(self.info.pubkey.serialize().to_vec()),
..Default::default()
}
};

let resp = self
.client
.list_channels(req)
.await
.map_err(|err| LightningError::ListChannelsError(err.to_string()))?
.into_inner();

Ok(resp
.channels
.into_iter()
.map(|channel| channel.amount_msat.unwrap_or_default().msat)
.collect())
}
}

#[async_trait]
Expand Down Expand Up @@ -198,6 +228,12 @@ impl LightningNode for ClnNode {
))
}
}

async fn list_channels(&mut self) -> Result<Vec<u64>, LightningError> {
let mut node_channels = self.node_channels(true).await?;
node_channels.extend(self.node_channels(false).await?);
Ok(node_channels)
}
}

async fn reader(filename: &str) -> Result<Vec<u8>, Error> {
Expand Down
Loading