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

Limit the output following depth #7927

Open
cdecker opened this issue Dec 10, 2024 · 0 comments
Open

Limit the output following depth #7927

cdecker opened this issue Dec 10, 2024 · 0 comments

Comments

@cdecker
Copy link
Member

cdecker commented Dec 10, 2024

Status quo

onchaind adds a txowatch for the funding output of a channel when
the funding transaction is confirmed. This is so that lightningd can
inform onchaind and other channel-specific daemons about spends that
they are interested in.

The notification of spends is asynchronous, and so lightningd
implements an auto-follow logic: if an output we are watching is being
spent, then we add the spend transaction's outputs also to the set of
watch TX outputs. This allows for correct tracking despite onchaind
handling the notifications asynchronously.

This however also means that if onchaind is very slow, for example
because the signer is not present, and we're waiting on a signature,
then this adds new outputs to the watched set faster than we can
unsubscribe the not interesting ones.

We've seen at least one case in which a channel closing resulted in
50k UTXO spend notifications being queued up, and a similar number of
txowatch instances.

Solution

Channels have a predictable max depth of interesting transactions for
onchaind. For example the longest chain that I can think of at the
moment is:

  1. Funding output
  2. HTLC second stage output
  3. HTLC second stage sweep output
  4. HTLC second stage sweep anchor spend

So if we add a maxdepth field to the txowatch we can count that
down every time we create a descendant txowatch from a parent, and
if it hits 0 we do not follow further. By setting maxdepth to a
large(-ish) number (say 10) we still follow correctly, but no longer
risk picking up some mixer structure that fans our attention out to
thousands of outputs to follow.

Impact

The sheer number of UTXO spends being replayed during startup was
causing onchaind to fall further and further behind, all the while
the front of observed UTXOs was increasing rapidly.

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

No branches or pull requests

1 participant