Description
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 mergeconnectd
back into
lightningd
as well, in which case we'd beexecve
ingpeerd
with the raw connection before exchanging any data). -
peerd
has full control of thecrypto_state
and the connection,
which meanslightningd
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 fromhsmd
andgossipd
which can be
inherited fromlightningd
. New connections can be created in
lightningd
and muxed onto the single connection it now keeps
withhsmd
, removing the need for fd-passing altogether.
- This in turn makes Windows support much easier, since the only
-
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_loop
s into a single loop.