Skip to content

Commit

Permalink
Merge pull request #113 from carlaKC/111-randomactivity
Browse files Browse the repository at this point in the history
Random Activity Generator
  • Loading branch information
sr-gi authored Oct 4, 2023
2 parents 7927465 + 46566b2 commit 843d797
Show file tree
Hide file tree
Showing 6 changed files with 546 additions and 38 deletions.
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
/// 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

0 comments on commit 843d797

Please sign in to comment.