Skip to content
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
170 changes: 156 additions & 14 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion sim-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ simple_logger = "4.2.0"
# The virtual-time feature is required for the --virtual-time flag, which runs simulations on a paused runtime.
simln-lib = { path = "../simln-lib", features = ["virtual-time"] }
tokio = { version = "1.26.0", features = ["full"] }
bitcoin = { version = "0.30.1" }
bitcoin = { version = "0.32" }
ctrlc = "3.4.0"
rand = "0.8.5"
hex = {version = "0.4.3"}
Expand Down
31 changes: 14 additions & 17 deletions sim-cli/src/parsing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ pub async fn create_simulation_with_network(
(
Simulation<SimulationClock>,
Vec<ActivityDefinition>,
HashMap<PublicKey, Arc<Mutex<SimNode<SimGraph, SimulationClock>>>>,
HashMap<PublicKey, Arc<SimNode<SimGraph, SimulationClock>>>,
),
anyhow::Error,
> {
Expand Down Expand Up @@ -322,9 +322,9 @@ pub async fn create_simulation_with_network(
// to a dyn trait and exclude any nodes that shouldn't be included in random activity
// generation.
let nodes = ln_node_from_graph(simulation_graph, routing_graph, clock.clone()).await?;
let mut nodes_dyn: HashMap<_, Arc<Mutex<dyn LightningNode>>> = nodes
let mut nodes_dyn: HashMap<_, Arc<dyn LightningNode>> = nodes
.iter()
.map(|(pk, node)| (*pk, Arc::clone(node) as Arc<Mutex<dyn LightningNode>>))
.map(|(pk, node)| (*pk, Arc::clone(node) as Arc<dyn LightningNode>))
.collect();
for pk in exclude {
nodes_dyn.remove(pk);
Expand Down Expand Up @@ -388,26 +388,25 @@ async fn get_clients(
nodes: Vec<NodeConnection>,
) -> Result<
(
HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>>,
HashMap<PublicKey, Arc<dyn LightningNode>>,
HashMap<PublicKey, NodeInfo>,
),
LightningError,
> {
let mut clients: HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>> = HashMap::new();
let mut clients: HashMap<PublicKey, Arc<dyn LightningNode>> = HashMap::new();
let mut clients_info: HashMap<PublicKey, NodeInfo> = 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>> = match connection {
NodeConnection::Lnd(c) => Arc::new(Mutex::new(LndNode::new(c).await?)),
NodeConnection::Cln(c) => Arc::new(Mutex::new(ClnNode::new(c).await?)),
NodeConnection::Eclair(c) => Arc::new(Mutex::new(EclairNode::new(c).await?)),
NodeConnection::LdkServer(c) => Arc::new(Mutex::new(LdkServerNode::new(c).await?)),
// We won't know the size of the dyn LightningNode at compile time, so the node is boxed into an Arc to
// store it in the clients map.
let node: Arc<dyn LightningNode> = match connection {
NodeConnection::Lnd(c) => Arc::new(LndNode::new(c).await?),
NodeConnection::Cln(c) => Arc::new(ClnNode::new(c).await?),
NodeConnection::Eclair(c) => Arc::new(EclairNode::new(c).await?),
NodeConnection::LdkServer(c) => Arc::new(LdkServerNode::new(c).await?),
};

let node_info = node.lock().await.get_info().clone();
let node_info = node.get_info().clone();

clients.insert(node_info.pubkey, node);
clients_info.insert(node_info.pubkey, node_info);
Expand Down Expand Up @@ -606,16 +605,14 @@ pub fn parse_sim_params(cli: &Cli) -> anyhow::Result<SimParams> {
}

pub async fn get_validated_activities(
clients: &HashMap<PublicKey, Arc<Mutex<dyn LightningNode>>>,
clients: &HashMap<PublicKey, Arc<dyn LightningNode>>,
nodes_info: HashMap<PublicKey, NodeInfo>,
activity: Vec<ActivityParser>,
) -> Result<Vec<ActivityDefinition>, LightningError> {
// We need to be able to look up destination nodes in the graph, because we allow defined activities to send to
// nodes that we do not control. To do this, we can just grab the first node in our map and perform the lookup.
let graph = match clients.values().next() {
Some(client) => client
.lock()
.await
.get_graph()
.await
.map_err(|e| LightningError::GetGraphError(format!("Error getting graph {:?}", e))),
Expand Down
4 changes: 2 additions & 2 deletions simln-lib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ cln-grpc = "0.1.3"
expanduser = "1.2.2"
serde = { version="1.0.183", features=["derive"] }
serde_json = "1.0.104"
bitcoin = { version = "0.30.1", features=["serde"] }
lightning = { version = "0.0.123" }
bitcoin = { version = "0.32", features=["serde"] }
lightning = { version = "0.2" }
tonic_lnd = { package="fedimint-tonic-lnd", version="0.1.2", features=["lightningrpc", "routerrpc"]}
tonic = { version = "0.8", features = ["tls", "transport"] }
async-trait = "0.1.73"
Expand Down
4 changes: 3 additions & 1 deletion simln-lib/src/batched_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ impl BatchedWriter {
let file = directory.join(file_name);

let writer = WriterBuilder::new()
.from_path(file)
.from_path(&file)
.map_err(SimulationError::CsvError)?;

log::info!("Writing simulation results to {}.", file.display());

Ok(BatchedWriter {
batch_size,
counter: 0,
Expand Down
Loading
Loading