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

lnwallet: add new NoopAdd payDesc entry type #9430

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

Roasbeef
Copy link
Member

In this commit, we add a new NoopAdd payDesc entry type. This type is meant to be used primarily by taproot overlay channels. When we go to settle this HTLC, rather than credit the settler for the funds, we just give the funds back to the sender. This results in an add that when settled, doesn't affect the balance in the channel.

This new HTLC type is intended to be used alongside a push amt, to ensure the remote party has a non-dust balance from the start. With that in place, then this new add type can be used for special overlay HTLCs.

In this commit, we add a new NoopAdd payDesc entry type. This type is
meant to be used primarily by taproot overlay channels. When we go to
settle this HTLC, rather than credit the settler for the funds, we just
give the funds back to the sender. This results in an add that when
settled, doesn't affect the balance in the channel.

This new HTLC type is intended to be used alongside a push amt, to
ensure the remote party has a non-dust balance from the start. With that
in place, then this new add type can be used for special overlay HTLCs.
Copy link
Contributor

coderabbitai bot commented Jan 21, 2025

Important

Review skipped

Auto reviews are limited to specific labels.

🏷️ Labels to auto review (1)
  • llm-review

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ZZiigguurraatt
Copy link

Okay, so we get an in flight HTLC for +354 sat, then when we settle with a new commitment transaction, HTLC is taken out of flight and we just update the new commitment to include the new taproot asset data anchored to the other outputs that are much larger. As long as each party has more than 354 sat in their balance, it's fine? Basically, on the sats side of the channel this isn't much different than canceling a HOLD invoice, except we add some new taproot assets data anchored to the updated commitment?

If the HTLC must go on chain, the sender just lost 354 sat as sort of an extra penalty, but the incentive for the receiver to go on chain is normally not going to motivate them to do that because they will have to pay much more than 354 sat to do a force close of an in flight HTLC?

@ZZiigguurraatt
Copy link

So this solution is more efficient than sending a matching 354 sat in the opposite direction (mentioned in lightninglabs/taproot-assets#888 (comment)), because it doesn't require an extra HTLC to be in flight and therefor results in lower on chain footprint in the event that the HTLC does need to go on chain?

@GeorgeTsagk GeorgeTsagk self-requested a review January 21, 2025 17:10
@Roasbeef
Copy link
Member Author

Okay, so we get an in flight HTLC for +354 sat, then when we settle with a new commitment transaction, HTLC is taken out of flight

Yep, or any amount really. An easy way to think about it is: we cancel the HTLC, while also revealing the preimage. This is the simplest solution I've thought of so far.

@ZZiigguurraatt
Copy link

What is the point of revealing the preimage? That isn't needed for the sats if you aren't changing the sats amount in the channel. I guess you need it to encourage updating of the commitment with the new taproot asset anchor? Otherwise they have no motivation to update the commitment with the new taproot assets anchor if they don't get the preimage?

Also, once the preimage is revealed, what prevents someone from wanting to settle a new commitment transaction with the channel state after the 354 sats were put into an HTLC (instead of before)? Is it the same incentive model if for dust with sats, if you start to disagree over this petty thing, then the other party will just close the channel because you are not worth doing business with anymore?

@Roasbeef
Copy link
Member Author

Updated to account for persistence.

@Roasbeef
Copy link
Member Author

Roasbeef commented Jan 23, 2025

What is the point of revealing the preimage?

You may still need to go on-chain to claim the HTLC. Also there might be an incoming HTLC, so you need to reveal that so the payment circuit can be closed (all HTLCs removed from all commitments).

Also, once the preimage is revealed, what prevents someone from wanting to settle a new commitment transaction with the channel state after the 354 sats were put into an HTLC

Can you elaborate on this?

@ZZiigguurraatt
Copy link

Also, once the preimage is revealed, what prevents someone from wanting to settle a new commitment transaction with the channel state after the 354 sats were put into an HTLC

Can you elaborate on this?

  1. HTLC inflight, +354 sat allocated to receiver
  2. preimage revealed
  3. receiver can go on chain and get the +354 sat
  4. sender wants to settle +0 sat with a new commitment and take the HTLC out of flight
  5. why does receiver want to settle an updated commitment transaction and take the HTLC out of flight if they loose 354 sat? is it just that they will need to pay more in on chain fees than 354 sat to do a force close so they have no incentive?

@Roasbeef
Copy link
Member Author

is it just that they will need to pay more in on chain fees than 354 sat to do a force close so they have no incentive?

Yep, exactly. Also if there's an outgoing HTLC (multi-hop), they may be able to secure an off-chain profit from the succesful HTLC forward.

Copy link
Collaborator

@GeorgeTsagk GeorgeTsagk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool stuff 🔥

@@ -6043,9 +6088,25 @@ func (lc *LightningChannel) MayAddOutgoingHtlc(amt lnwire.MilliSatoshi) error {
func (lc *LightningChannel) htlcAddDescriptor(htlc *lnwire.UpdateAddHTLC,
openKey *models.CircuitKey) *paymentDescriptor {

// TODO(roasbeef): can use push amt to simplify logic, not have to
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wdym in this todo: always push some sats amount on channel open, to make sure remote side can always anchor? if that's the case
a) this todo shouldn't be here, as lnd doesn't know anything about custom channel funding details
b) for custom channels with large btc capacity, it may be uneconomical to push enough sats to the other side to get them over the reserve

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it may be uneconomical to push enough sats to the other side to get them over the reserve

Would need to double check, but I think the starting value of a push_amt is actually exempt from the reserve constraints.

wdym in this todo: always push some sats amount on channel open, to make sure remote side can always anchor? if that's the case

Yes, so we'd have the APIs set up to always push an amount over to ensure they can anchor for as starting state.

Otherwise, we'll need to make sure that we only ever push for the "first" HTLC, which can be a bit tricky if you have many pending HTLCs in a new commitment transaction.


customRecords := htlc.CustomRecords.Copy()
if lc.channelState.ChanType.HasTapscriptRoot() {
entryType = NoopAdd
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a nice way to bootstrap things, but I think HasTapscriptRoot() is insufficient as the sole criteria here

We could be sending raw btc HTLCs over the channel, or we could be sending HTLCs carrying custom data and also carry a significant amount of btc. In both of the previous cases we definitely don't want to give the amount back to sender upon settlement

From the top of my head: we could also check for this HTLC's custom records, plus the actual amount of the btc delta and then decide whether we're in a NoopAdd case

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed. I think instead we may want to add a new aux interface, or re-use an existing one, to know when we should be using this or not.

// The NoopAdd HTLC is an internal construct, and isn't meant to show up
// on the wire. So we'll remove the special element from the set of
// custom records.
delete(customRecords, noopTLV)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IIUC this wouldn't really matter, as the receiver of the wire message would just ignore this unknown type, are we just saving wire space here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ended up doing this as we have some tests that assert what an HTLC should look like for transmission. If we continue to thread these over, then those start to fail.

On the other hand, maybe it makes sense to expose this, as then the receiver just accepts the noop if the sender does, vs the current logic of assuming that it's always noop when the tapscript bit is set.

balanceDeltas.ModifyForParty(
party.CounterParty(),
func(acc int64) int64 {
return acc + delta
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 So by default the custom aux blob is being updated / preserved in the background, so the only diff required is the one that pays back the sats, didn't expect this to be that lean 💯

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, was great how small it turned out to be in the end. This area of the code has been refactored a bit also, which served to simplify the addition of this new feature.

addEntry.EntryType == NoopAdd:

delta := int64(entry.Amount)
balanceDeltas.ModifyForParty(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also important to mention that parties could disagree here, with receiver potentially trying out malicious things (like going to chain, like @ZZiigguurraatt mentioned), and try to "grab" both the custom data and the btc amount

That's a good reason why I believe we should not convert the entry type to NoopAdd for HTLCs that carry a btc amount above a certain threshold, or let the user explicitly mark it somehow as noop

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I follow, but if they disagree, a force close occurs. Which doesn't benefit either party, as they need to pay for chain fees, and now the receiver will likely end up with nothing as it'll cost more to spend the output than it's actually worth.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mean that we should not allow significant btc amounts being carried by HTLCs of type NoopAdd

That breaks the incentive alignment and someone could actually want to misbehave and force-close/pay fees

@guggero guggero self-requested a review January 23, 2025 16:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants