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

Direct connect for OnionMessage sending #2723

Merged
merged 18 commits into from
Dec 8, 2023

Commits on Dec 6, 2023

  1. Use a message buffer abstraction in OnionMessenger

    Onion messages are buffered for sending to the next node. Since the
    network has limited adoption, connecting directly to a peer may be
    necessary. Add an OnionMessageBuffer abstraction that can differentiate
    between connected peers and those are pending a connection. This allows
    for buffering messages before a connection is established and applying
    different buffer policies for peers yet to be connected.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    79f212b View commit details
    Browse the repository at this point in the history
  2. Destination in OnionMessenger::send_onion_message

    OnionMessenger::send_onion_message takes an OnionMessagePath. This isn't
    very useful as it requires finding a path manually. Instead, have the
    method take a Destination and use OnionMessenger's MessageRouter to
    construct the path. Later, this will allow for buffering messages where
    the first node in the path isn't a direct connection.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    8412e83 View commit details
    Browse the repository at this point in the history
  3. Buffer onion messages requiring a connection

    MessageRouter::find_path returns a path to use when sending an onion
    message. If the first node on the path is not connected or does not
    support onion messages, sending will fail with InvalidFirstHop. Instead
    of failing outright, buffer the message for later sending once the first
    node is a connected peer.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    ddee928 View commit details
    Browse the repository at this point in the history
  4. Add NetworkGraph reference to DefaultMessageRouter

    When buffering onion messages for a node that is not connected as a
    peer, it's possible that the node does not exist. Include a NetworkGraph
    reference in DefaultMessageRouter so that it can be used to check if the
    node actually exists. Otherwise, an malicious node may send an onion
    message where the reply path's introduction node doesn't exist. This
    would result in buffering messages that may never be delivered.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    17af8d5 View commit details
    Browse the repository at this point in the history
  5. Add Option<Vec<SocketAddress>> to OnionMessagePath

    MessageRouter::find_path is given a Destination to reach via a set of
    peers. If a path cannot be found, it may return a partial path such that
    OnionMessenger can signal a direct connection to the first node in the
    path is needed. Include a list of socket addresses in the returned
    OnionMessagePath to allow OnionMessenger to know how to connect to the
    node.
    
    This allows DefaultMessageRouter to use its NetworkGraph to return
    socket addresses for gossiped nodes.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    1114c3c View commit details
    Browse the repository at this point in the history
  6. Return socket addresses from DefaultMessageRouter

    When there isn't a direct connection with the Destination of an
    OnionMessage, look up socket addresses from the NetworkGraph. This is
    used to signal to OnionMessenger that a direct connection is needed to
    send the message.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    b86f02a View commit details
    Browse the repository at this point in the history
  7. Add Event::ConnectionNeeded for onion messages

    A MessageRouter may be unable to find a complete path to an onion
    message's destination. This could because no such path exists or any
    needs on a potential path don't support onion messages. Add an event
    that indicates a connection with a node is needed in order to send the
    message.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    ba2a822 View commit details
    Browse the repository at this point in the history
  8. Make OnionMessageHandler extend EventsProvider

    An OnionMessageHandler may buffer messages that can't be sent because
    the recipient is not a peer. Have the trait extend EventsProvider so
    that implementation so that an Event::ConnectionNeeded can be generated
    for any nodes that fall into this category. Also, implement
    EventsProvider for OnionMessenger and IgnoringMessageHandler.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    06b05df View commit details
    Browse the repository at this point in the history
  9. Drop buffered messages for timed out nodes

    OnionMessenger buffers onion messages for nodes that are pending a
    connection. To prevent DoS concerns, add a timer_tick_occurred method to
    OnionMessageHandler so that buffered messages can be dropped. This will
    be called in lightning-background-processor every 10 seconds.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    cfaa7f3 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    ae98517 View commit details
    Browse the repository at this point in the history
  11. Re-wrap define_run_body macro parameters

    Some code hygiene before another parameter is added and rustfmt is
    eventually used.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    36ecc8e View commit details
    Browse the repository at this point in the history
  12. Re-order define_run_body macro parameters

    Simply to avoid excessive wrapping when possible.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    ce68f22 View commit details
    Browse the repository at this point in the history
  13. Process OnionMessageHandler events in background

    OnionMessageHandler implementations now also implement EventsProvider.
    Update lightning-background-processor to also process any events the
    PeerManager's OnionMessageHandler provides.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    6ca81ff View commit details
    Browse the repository at this point in the history
  14. Call OnionMessageHandler::timer_tick_occurred

    lightning-background-processor processes events provided by the
    PeerManager's OnionMessageHandler for when a connection is needed. If a
    connection is not established in a reasonable amount of time, drop any
    buffered onion messages by calling timer_tick_occurred.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    e25af3e View commit details
    Browse the repository at this point in the history
  15. Reuse MessengerNode in spec_test_vector

    Additional tests will be added needing a similar node struct, so
    consolidate its usage.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    210407e View commit details
    Browse the repository at this point in the history
  16. Test pending connection onion message buffering

    Add tests for onion message buffering checking that messages are cleared
    upon disconnection and timed out after MAX_TIMER_TICKS. Also, checks
    that ConnectionNeeded events are generated.
    jkczyz committed Dec 6, 2023
    Configuration menu
    Copy the full SHA
    89e630b View commit details
    Browse the repository at this point in the history
  17. Configuration menu
    Copy the full SHA
    d46519b View commit details
    Browse the repository at this point in the history
  18. Configuration menu
    Copy the full SHA
    0b83116 View commit details
    Browse the repository at this point in the history