Which is related to the existing issue to add a single global notification
stream of all invoices, and some of the existing technical debt in that area
re the add/settle indexes...
Ideally with this issue
(
https://github.com/lightningnetwork/lnd/issues/6288), we can move to
implement a more future proofed event sourcing based notification system,
which also makes future changes like this easier.
Taking a look at that initial implementation you have, it would appear to
introduce another bucket of unbounded size (grows w/ the number of settled
invoices). Instead, what if we just stored this information within the
existing invoices? So things would first go to that "settle pending" state,
which is then ultimately finalized either: the HTLC times out
(reverts), or is fully settled.
In terms of an implementation path, every time we process a revocation from
the remote party (only after they revoke the state w/o that HTLC can it
actually be considered to be "settled"), we'll go to compact the logs
(remove adds that have a settled fully locked in, etc):
https://github.com/lightningnetwork/lnd/blob/08e4e665741c14854f3cf227ba3777a443bce932/lnwallet/channel.go#L1171.
At this point, we know that the HTLC is no longer present, and also that as
long as its present, on restart we'll re-run this routine. This is where the
logic to "up all" back to the invoice registry could live potentially (in
the form of extending what's returned to include the HTLCs that are fully
resolved at that height.
This would let us avoid the addition of yet-another-mega-bucket, and keeps
the state where it should be: in the invoice registry. This also means we
don't need to worry about more historical channel information, and if to
delete this state or note when a channel is abandoned.
For the on-chain resolution case, a similar upcall can be used back to the
invoice registry that the on-chain state is fully finalized.
-- Laolu