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

simln-lib/feature: Add ability to run with mocked ln network #248

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

f3r10
Copy link
Collaborator

@f3r10 f3r10 commented Mar 30, 2025

address #215

@f3r10 f3r10 force-pushed the feature_add_ability_to_run_with_mocked_ln_network branch from 6795897 to 3d2685b Compare March 30, 2025 15:48
@carlaKC
Copy link
Contributor

carlaKC commented Apr 2, 2025

Is this ready for a first review pass?

@f3r10
Copy link
Collaborator Author

f3r10 commented Apr 2, 2025

Sure, @carlaKC, it is ready for a first review pass. I have been thinking about how to add some tests

@f3r10 f3r10 force-pushed the feature_add_ability_to_run_with_mocked_ln_network branch from 3d2685b to 140f087 Compare April 2, 2025 18:07
Copy link
Contributor

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few big picture comments on how we're going to split this up, now that I've had some time to think about this (and live with these decisions on a downstream fork) I think we can cut it up a bit cleaner.

Also feel free to cherry pick carlaKC@d1afc33 for docs once this reaches the stage where you need then (removing the embarrassing rebase booger in there, kek).

@@ -96,6 +101,27 @@ enum NodeConnection {
Eclair(eclair::EclairConnection),
}

/// Data structure that is used to parse information from the simulation file, used to pair two node policies together
/// without the other internal state that is used in our simulated network.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym by "without the other internal state that is used in our simulated network?"

Without all the stuff in SimulatedChannel? I don't think the parsing module needs to worry too much about noting that - we have a few structs across modules that are quite duplicated but different for the sake of separation.

@@ -20,7 +20,7 @@ async fn main() -> anyhow::Result<()> {
.init()
.unwrap();

let sim = create_simulation(&cli).await?;
let (sim, sim_network) = create_simulation(&cli).await?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm torn about whether to have all the logic about our two different run "modes" here vs hidden in create_simulation (I know I did that in my branch, but I didn't love it).

WDYT of something like this which separates validation and has two dedicated functions that assumes we've done some validation on cli:

cli.validate()?; // does all the checks on nodes and sim_network
let tasks = TaskTracker::new();
let sim = if sim.network.is_none() {
    create_simulation(cli, tasks)
} else {
   create_simulation_with_network(cli, tasks);
}

sim.run()
tasks.wait

I don't like that we have some duplication in the different create network functions, but it is nice to clearly see the two cases and have more specialized functions.

(Related to comment about getting rid of new_with_sim_network)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree; it makes the code more concise

@@ -654,7 +655,7 @@ pub struct SimGraph {

/// track all tasks spawned to process payments in the graph. Note that handling the shutdown of tasks
/// in this tracker must be done externally.
tasks: TaskTracker,
pub tasks: TaskTracker,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're passing tasks into the constructor, we should have it available at our call site and then don't need to make it pub?

@@ -527,6 +528,42 @@ impl Simulation {
}
}

pub async fn new_with_sim_network(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second look, this seems like a bit of a layering violation to have Simulation be aware of SimGraph stuff - it should just care about getting some arbitrary set of lightning nodes.

If we have a dedicated create_simulation_with_network in the parsing module, we can just create the graph with SimGraph::new and then use ln_node_from_graph to get the nodes to pass into Simulation::new.

The nice side effect of passing tasks in is that we don't actually need the graph to wait on anymore, we can just tasks.wait at the end of the sim.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants