wip: replay of trampoline forwards#4475
Draft
carlaKC wants to merge 8 commits intolightningdevkit:mainfrom
Draft
wip: replay of trampoline forwards#4475carlaKC wants to merge 8 commits intolightningdevkit:mainfrom
carlaKC wants to merge 8 commits intolightningdevkit:mainfrom
Conversation
|
👋 Hi! I see this is a draft PR. |
When we add handling for trampoline payments, we're going to need the full HTLCSource (with multiple prev_htlcs) to replay settles/claims. Here we update our existing logic to support tracking by source.
For trampoline, we have multiple outgoing HTLCs for our single source.
Taking the bluntest approach of storing all information for trampoline forwards as a first stab, can possibly reduce data later.
da5b766 to
625bb89
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR contains the most data-heavy / least-smart approach to handling replay of trampoline forwards. Opening this up as a basis for discussion, not intended for real review!
There's a lot of background written up here - for TLDR skip to ➡️section⬅️ which has the open question I'm unsure about.
Trampoline Background
Trampoline forwards may have multiple HTLCS incoming and outgoing, for example:
On our outbound channels (D/E), we represent these forwards using a
HTLCSourcewhich contains information about all of our inbound HTLCs and the part of the payment dispatched on that outgoing channel.In
D'spending_outbound_htlcs:In
E'spending_outbound_htlcs:Note: each outbound HTLC tracks all inbound, and they have a shared
payment_idbut differentsession_priv!Claims:
claim_funds_from_htlc_forward_hopfor eachprev_hopreported byHTLCSource.previous_hop_datato create ourPaymentForwardedevent.Fails:
payment_idinfail_htlc_backwards_internalto check whether it's appropriate to fail back at this time.prev_hopreported byHTLCSource.Replays
We populate
already_forwarded_htlcsfrom all of our inbound htlcs (inbound_forwarded_htlcs), and de-duplicate any HTLCs that still present on outbound channels (outbound_htlc_forwards). Anything that is remaining has a claim replayed when a preimage is present on the inbound monitor, and a fail otherwise. We track our inbound htlcs per-inbound channel, and keep a record of the outbound htlc that they are associated with inInboundUpdateAdd.In our multi-in, multi-out trampoline world there are a few things that we need to consider:
➡️ (1) Reconstructing multi-inbound ⬅️
Right now, we reconstruct the
HTLCSource::PreviousHopDatafromInboundUpdateAddand the channel monitor that our inbound htlc is on. We can't do this for trampoline because our source is spread across multiple inbound channels.Our options here are:
a) Store information about all inbound HTLCs in each
InboundUpdateAddso that we can reconstruct ourHTLCSourceb) Store information about only our channel's inbound HTLC in
InboundUpdateAdd, and post-process ouralready_forwarded_htlcsto collectHTLCSourcebypayment_idc) Store information about only our channel's inbound HTLC in
InboundUpdateAddand do not reconstruct multi-in `HTLCSource (this seems like a bad idea, but including it for completeness).This PR implements (a), which has the downside of being very data-heavy. The downside of (b) is that we could produce events with missing information when some of our inbound HTLCs have been cleared out, but it doesn't seem terrible.
❓ I think that it's worth taking a look at the complexity of (b) but would be interested in thoughts here!
(2) Multiple
OutboundHop(s)As we commit each of our outbound HTLCs, we'll report the
HTLCSources above forDandEincommitted_outbound_htlc_sourcesand use them toprune_persisted_inbound_htlc_onions. We track each uniquesession_priv'sOutboundHopso that we're able to get a full record of all the outbound HTLCs that our inbound is associated with. If any of our outbound HTLCs are still present, we'll appropriately prune the inbound fromalready_forwarded_htlcs.I don't think there are many different approaches to this - we could have a 1-in/2-out trampoline forward, so we need to track all outbound with our inbound. This means we'll have some duplication when we have multiple inbound HTLCs.