Skip to content

Merge the per-peer daemons into a single peerd #4316

Open
@cdecker

Description

@cdecker

As the protocol becomes ever more complex the common parts that need
to be handled by the various per-peer daemons (openingd, channeld,
closingd, potentially even onchaind) forces us to duplicate
functionality quiet a bit. In addition, as the phases become less
well-separated, for dual-funding, RBF funding support, splicing, etc,
we need to move existing functionality between daemons (see #4293 and
#4271 for examples), leading to rather large overheads when adding
support for these.

One solution is to merge the per-peer daemons into a single peerd
that gets started when first connecting, and stopped when we lose the
connection (onchaind being the one exception that could be kept
separate).

Advantages

  • We maintain the separation between lightningd and anything that
    touches a user-connection (unless we merge connectd back into
    lightningd as well, in which case we'd be execveing peerd
    with the raw connection before exchanging any data).

  • peerd has full control of the crypto_state and the connection,
    which means lightningd never has to touch it, and we don't need
    to fd-pass the peer connection.

    • This in turn makes Windows support much easier, since the only
      FDs we now pass are from hsmd and gossipd which can be
      inherited from lightningd. New connections can be created in
      lightningd and muxed onto the single connection it now keeps
      with hsmd, removing the need for fd-passing altogether.
  • Simplifies debugging, since the daemons are longer lived and
    debuggers don't have to re-attach to new processes as we progress
    through the states.

Disadvantages

  • Daemons become more complex, and all have to switch to async
    communication

  • Breaks all pending changes during the refactoring period.

  • Weakens the hsmd capabilities system since all peer daemons share
    the same connection with a superset of all currently needed
    capabilities.

Bottom-up approach

We can extract common functionality into common/ and slowly start
converging to a common internal representation, then start migrating
individual daemons to peerd. This is the least disruptive, but also
the long approach.

Top-down approach

A quick and dirty approach to the problem: create peerd, rename
main from the various daemons to <daemon>_main, create links to
peerd from the old daemon name, then call <daemon>_main based on
the executable name. Then start merging everything.

Over time we start differentiating daemons via the first message they
receive (usually an init message of some kind), then add daemon
transitions without stopping and starting the daemon, and finally
integrate all io_loops into a single loop.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions