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

Add Ability to Run as Full Simulator #2

Open
wants to merge 7 commits into
base: bitcoin-dev-project-fresheyes-staging-main-165
Choose a base branch
from

Conversation

adamjonas
Copy link
Owner

This PR is a WIP that adds the ability to run SimLN without any real lightning nodes, instead providing "simulated nodes" that copy the the routing policies and liquidity constraints of real nodes. The last commit hard-codes a graph to run this "full simulation" on as an example, whereas in reality we'd load from a json description of the desired topology/policies.

High Level Overview

Lightning implementations in SimLN are abstracted using the LightningNode: (https://github.com/bitcoin-dev-project/sim-ln/blob/main/sim-lib/src/lib.rs#L180) trait. The steps that we follow to support a simulated implementation of this trait (SimNode) are as follows:

  • Run the simulator with a –from_graph option, which allows starting the simulator with a graph file (format tbd) that provides channel policies and topology (not included in this PR).
  • Use a single, top-level SimGraph struct to manage:
    • A hashmap of simulated channels available
    • Propagation of payments through the simulated channels
  • Implement LightningNode: (https://github.com/bitcoin-dev-project/sim-ln/blob/main/sim-lib/src/lib.rs#L180) on a SimNode struct which:
    • Handles implementation of send/tracking functionality
    • Points to the coordinating SimGraph struct to manage payment dispatch.

Graph Abstraction

Management of payments through the simulated network is separated managed with the following layers:

  • SimGraph: high level coordinator that keeps a hashmap of each simulated channel (see below) in the network, along with their forwarding policies. Responsible for coordinating addition/removal of HTLCs as they propagate through the network.
  • SimNode: implementation of the LightningNode trait which rely on the SimGraph to propagate payments on their behalf.

Screenshot 2024-01-30 at 4 43 35 PM`

These structs are primarily used to provide send/track payment APIs, receiving updates on the state of their payments from SimGraph.

Channel State Machine

Implementation of channel state is broken down into three layers:

  • Channel Policy: representation of the directional policy of a participant (fees etc)
  • Channel State: tracks the “live” state of the outgoing state of the channel
  • Simulated Channel: tracks state for each direction of the channel, and high level information

Screenshot 2024-01-30 at 4 19 13 PM`

Each channel state is responsible for handling tracking of liquidity and HTLC limits in one direction, and the simulated channel is responsible for enforcing sanity checks across the channel (eg, that we don’t exceed our capacity).

An example state machine update is provided in the table below:

Step Alice Channel State Bob Channel State
Channel Opened by Alice Local_balance: 100_000 / In_Flight: nil Local_balance: 0 / In_Flight: Nil
Alice sends 100 sats to Bob Local_balance: 999_000 / In_Flight: 100 sats Local_balance: 0 / In_Flight: Nil
Alice payment succeeds Local_balance: 999_000 / In_Flight: nil Local_balance: 100 / In_Flight: Nil
Bob sends 50 sats to Alice Local_balance: 999_000 / In_Flight: nil Local_balance: 50 / In_Flight: 50
Bob payment fails Local_balance: 999_000 / In_Flight: nil Local_balance: 100 / In_Flight: nil

tl;dr

Screenshot 2024-01-30 at 4 01 34 PM`

carlaKC added 7 commits March 8, 2024 11:21
This commit adds a ChannelState struct which is used to track the
policy and state of a channel in the *outgoing* direction. This will
be used to check forwards against the node's advertised policy and
track the movement of outgoing HTLCs through the channel.

Note that we choose to implement this state *unidirectionally*, so a
single channel will be represented by two ChannelState structs (one in
each direction).
Add a single representation of a simulated lightning channel which
uses our state representation to add and remove htlcs. For simplicity,
each side of the channel is represented as a separate state, with the
only interaction between the two through the changes to local balance
that happen when we settle htlcs.
Add an implementation of the LightningNode trait that represents
the underlying lightning node. This implementation is intentionally
kept simple, depending on some SimNetwork trait to handle the mechanics
of actually simulating the flow of payments through a simulated graph.
We want to be able to distinguish between expected and critical payment
errors in our simulated payments. An expected error occurs due to a
lightning-related failure (such as running out of liquidity), and a
critical one happens because something has gone wrong with our
simulator (for example, an assertion failure about balances).

This commit adds an some utilities to ForwardingError to make this
distinction and display errors properly.
Add an implementation of our SimNetwork trait that will do the heavy
lifting of propagating htlcs through a simulated network.
Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1871600658 at 2024/02/09, 03:20:28 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1871601468 at 2024/02/09, 03:22:07 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1871604036 at 2024/02/09, 03:27:37 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1871606322 at 2024/02/09, 03:32:26 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1871611910 at 2024/02/09, 03:43:42 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1935408809 at 2024/02/09, 06:39:37 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1873037211 at 2024/02/09, 19:08:54 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1873084330 at 2024/02/09, 19:40:56 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1873125603 at 2024/02/09, 20:09:38 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1936656477 at 2024/02/09, 21:55:26 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1948784941 at 2024/02/16, 16:18:26 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1881017094 at 2024/02/16, 19:52:41 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1898527379 at 2024/02/27, 13:48:49 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1966604549 at 2024/02/27, 13:55:25 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1966612479 at 2024/02/27, 13:59:10 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1909512674 at 2024/02/29, 17:48:06 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1909521258 at 2024/02/29, 17:52:50 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1909551436 at 2024/02/29, 18:09:13 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1909580044 at 2024/02/29, 18:25:45 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1909608725 at 2024/02/29, 18:43:21 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1909670677 at 2024/02/29, 19:03:41 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1909674915 at 2024/02/29, 19:06:14 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1909723293 at 2024/02/29, 22:00:29 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1925235915 at 2024/03/08, 16:13:25 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1925238302 at 2024/03/08, 16:14:30 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1929143410 at 2024/03/11, 20:19:59 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1989399253 at 2024/03/11, 20:37:03 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1992413443 at 2024/03/12, 19:44:16 UTC.

Copy link

@fresheyes-staging-bot fresheyes-staging-bot bot left a comment

Choose a reason for hiding this comment

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

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#pullrequestreview-1932635987 at 2024/03/12, 21:13:29 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1994507732 at 2024/03/13, 14:15:41 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1994516619 at 2024/03/13, 14:20:09 UTC.

Copy link

An author commented here with:

  • comment link https://github.com/bitcoin-dev-project/sim-ln/pull/165#issuecomment-1994548803 at 2024/03/13, 14:36:28 UTC.

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