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

feat(lightning): Add Lightning as transport #85

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Commits on Feb 6, 2023

  1. feat(lightning): add tower messages

    Add message (de)serilaization to teos-common
    This commit adds lightning messages and message (de)serialization using helper local modules (ser_utils, ser_macros) and LDK v0.0.108 instead of the attempted fork used before (https://github.com/meryacine/rust-lightning/tree/expose-tlv-macros)
    Most of the serialization macros and utils are copied from LDK's own serialization framework though. Also we might remove some of the locally implemented TLV stuff if they ever get exposed by LDK.
    
    But some of the macros have been edited and diverged from LDK's first
    implementation: for example, the `vec` arms for the macros were adjusted
    so that it works with `impl_writeable_msg` macro to send arrays as TLV (which is not the case
    for LDK ATM).
    Note that we could have had vectors(arrays) be inside `Option`s and put
    in a TLV, but this will waste extra two bytes for vector length
    annotation (we don't need the vector length annotated in the V(value) of
    the TLV since L(length) already embeds this information)
    
    We also now have another macro match arm `str_opt`, which
    indicates an optional string inside a TLV, this was created to avoid
    adding extra length field for strings just like `vec`.
    mariocynicys committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    20d9ad4 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    ceefb85 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    9f12f20 View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    23b87e4 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    195b325 View commit details
    Browse the repository at this point in the history
  6. Reviews from sr-gi 1

    mariocynicys committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    ab9699d View commit details
    Browse the repository at this point in the history
  7. Reviews from sr-gi 2

    mariocynicys committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    19ff970 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    3969d02 View commit details
    Browse the repository at this point in the history
  9. Adding the lightning server

    This commit adds the lightning server and its port configuration option.
    The peer manager in charge of the lightning server doesn't know about routing and lightning channels (yet?). It can only responde to the user custom messages defined in `teos_common::lightning::messages`.
    A \`block_in_place\` is used in \`handle_tower_message\` to synchronously block on grpc calls.
    mariocynicys committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    88bbb12 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    de3c7df View commit details
    Browse the repository at this point in the history
  11. Configuration menu
    Copy the full SHA
    697be71 View commit details
    Browse the repository at this point in the history
  12. tests: Add lightning tower handler tests

    These tests are analogous to tests in `http::tests_methods` and they test the tower message handler logic only (not the tower message handler when inside a peer manager)
    mariocynicys committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    1857e12 View commit details
    Browse the repository at this point in the history
  13. tests: Add test utils for peer manager testing

    These test utils include:
    - A test lightning client: this simulates a client's peer manager that is trying to connect to the tower and send/receive tower messages. For a real client, this should be part of a bigger application (say a lightning node) and the custom message handler adds the capabilities of speaking with the tower over Lightning.
    - Some utils to launch a Lightning server and connect one peer manager to another
    - A simple proof of concept test
    mariocynicys committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    a107335 View commit details
    Browse the repository at this point in the history
  14. Fix: Run lightning-net-tokio on a different runtime

    This fixes a deadlock issue that appears with too many concurrent requtests. This solution was taken from devrandom's issue: lightningdevkit/rust-lightning #1367
    Another solution that would probably work is that lightning net tokio wraps our sync calls with `tokio::task::spawn_blocking(|| sync_call()).await.unwarp()`, but not sure how would this affect performace of other users with no async code requirements.
    
    Note that peer_manager_tests now don't need to be anotated with `flavor = "multi_thread"`, that's because the runtime we block_on (inside lightning net tokio) is the artificial runtime created in `api::lightning::server` which is already "multi_thread"
    mariocynicys committed Feb 6, 2023
    Configuration menu
    Copy the full SHA
    5206d34 View commit details
    Browse the repository at this point in the history