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

[5/5]: lnwallet: extensions to aux leaf store to integrate custom channels #8641

Open
wants to merge 12 commits into
base: aux-leaf-signing
Choose a base branch
from

Conversation

Copy link

coderabbitai bot commented Apr 11, 2024

Important

Review Skipped

Auto reviews are disabled on this repository.

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>.
    • 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 generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @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.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration 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.

Copy link

Pull reviewers stats

Stats of the last 30 days for lnd:

User Total reviews Time to review Total comments
guggero
🥇
24
▀▀▀
2d 13h 46m
52
▀▀▀
ellemouton
🥈
12
5d 14h 33m
21
bhandras
🥉
9
30m
0
Roasbeef
7
7d 8h 43m
20
yyforyongyu
6
3h 18m
0
ziggie1984
5
3d 1h 5m
14
ProofOfKeags
4
4d 6h 3m
42
▀▀
GeorgeTsagk
4
2d 20h 31m
10
bitromortac
2
13d 3h 49m
6
saubyk
2
5h 24m
0
Chinwendu20
2
18d 5h 38m
▀▀
9
positiveblue
1
4d 21h 57m
0
AndySchroder
1
17d 9h 5m
▀▀
4
ffranr
1
14h 10m
4
Crypt-iQ
1
7d 14h 36m
4
dstadulis
1
1d 22h 10m
4
morehouse
1
2d 2h 39m
1
carlaKC
1
12h 2m
0
mohamedawnallah
1
1d 4h 44m
0

@@ -654,25 +654,29 @@ type AuxLeafStore interface {
// FetchLeavesFromView attempts to fetch the auxiliary leaves that
// correspond to the passed aux blob, and pending fully evaluated HTLC
// view.
FetchLeavesFromView(prevBlob tlv.Blob, view *HtlcView,
FetchLeavesFromView(chanState *channeldb.OpenChannel, prevBlob tlv.Blob,
Copy link
Member

Choose a reason for hiding this comment

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

Alternatively could just be that special funding blob (the one in the open channel struct), we could also use a type alias here. Unsure though if we do need all that other information or not.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We need the local/remote channel config, custom blob, thaw height, initiator and channel type. So it's easiest to just pass in the whole channel state. Not sure what a type alias would give us? Other than perhaps being a bit shorter.

// of the pkScript and CLTV timeout, and the value is the index the
// output should be placed at. The CLTV timeout is encoded as a big
// endian before hashing and is assumed to be 0 for non-HTLC outputs.
// sha256(pkScript || bigEndian(cltvDelta)) -> outputIndex
Copy link
Member

Choose a reason for hiding this comment

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

IIUC, this also incudes the value as well.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah yes, good catch. Fixed.

// lets us skip sending the entire transaction over, instead we'll just
// send signatures.
if auxLeaves.IsSome() &&
auxLeaves.UnsafeFromSome().CustomOutputOrder != nil {
Copy link
Member

Choose a reason for hiding this comment

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

If we want to mask this a bit more, then we can have a functional option to pass in a new custom sorting interface/type. Default is the existing one, then we know to override it at the config level for these special channels.

Copy link
Collaborator Author

@guggero guggero Apr 12, 2024

Choose a reason for hiding this comment

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

Good point. I'm meeting you half way: Instead of passing in a function, we now require a sort function to be returned. But that way at least the sorting logic is not in the lnd code base anymore.

input/script_utils.go Show resolved Hide resolved
@@ -660,7 +660,8 @@ type AuxLeafStore interface {
// correspond to the passed aux blob, and pending original (unfiltered)
// HTLC view.
FetchLeavesFromView(chanState *channeldb.OpenChannel, prevBlob tlv.Blob,
unfilteredView *HtlcView,
unfilteredView *HtlcView, isOurCommit bool, ourBalance,
theirBalance lnwire.MilliSatoshi,
Copy link
Member

Choose a reason for hiding this comment

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

Balances needed for the new sorting algo?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, for sorting, making sure we have non-dust BTC amounts for any asset amounts and for determining whether we need commitment anchor outputs (which we need to create exclusion proofs for).

@guggero guggero force-pushed the custom-channels-integration branch 5 times, most recently from d288b6a to f7f875b Compare April 16, 2024 11:23
@guggero guggero changed the base branch from aux-leaf-fetcher to aux-leaf-signing April 16, 2024 11:23
@guggero guggero force-pushed the custom-channels-integration branch 7 times, most recently from cb514a1 to f35aead Compare April 23, 2024 20:19
@guggero guggero changed the base branch from aux-leaf-signing to 0-19-staging April 23, 2024 20:21
@guggero guggero force-pushed the custom-channels-integration branch from f35aead to cf965f0 Compare April 24, 2024 15:04
@guggero guggero changed the base branch from 0-19-staging to aux-leaf-signing April 24, 2024 15:07
@guggero guggero changed the title lnwallet: extensions to aux leaf store to integrate custom channels [5/?]: lnwallet: extensions to aux leaf store to integrate custom channels Apr 24, 2024
@guggero guggero force-pushed the custom-channels-integration branch from cf965f0 to 0e6a9dd Compare April 25, 2024 17:06
@guggero guggero marked this pull request as ready for review May 17, 2024 13:26
@guggero
Copy link
Collaborator Author

guggero commented May 17, 2024

This PR should now contain everything from the PoC branch and is ready for review.

@guggero guggero force-pushed the custom-channels-integration branch 2 times, most recently from 5a834c1 to 7b9e627 Compare May 20, 2024 18:07
@guggero guggero force-pushed the aux-leaf-signing branch 2 times, most recently from c0b5902 to 6123a1c Compare May 21, 2024 07:27
@guggero guggero force-pushed the custom-channels-integration branch 2 times, most recently from 3b45569 to 12d4694 Compare May 21, 2024 07:46
@guggero guggero force-pushed the custom-channels-integration branch from 12d4694 to 44fe836 Compare May 22, 2024 16:25
Copy link
Collaborator

@ffranr ffranr left a comment

Choose a reason for hiding this comment

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

I appreciate that each commit pretty much does one thing 👍

# Allow fmt.Printf() in lncli.
- path: cmd/lncli/*
# Allow fmt.Printf() in commands.
- path: cmd/commands/*
Copy link
Collaborator

Choose a reason for hiding this comment

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

This refactoring commit seems unnecessary in this PR. Would be simpler to do this sort of change once the saga is merged into master perhaps.

The commit body should explain why this change is necessary.

Comment on lines +388 to +402
// AddHeight returns a pointer to the height at which the HTLC was added to the
// commitment chain. The height is returned based on the chain the HTLC is
// being added to (local or remote chain).
func AddHeight(htlc *PaymentDescriptor, remoteChain bool) *uint64 {
if remoteChain {
return &htlc.addCommitHeightRemote
}

return &htlc.addCommitHeightLocal
}

// RemoveHeight returns a pointer to the height at which the HTLC was removed
// from the commitment chain. The height is returned based on the chain the HTLC
// is being removed from (local or remote chain).
func RemoveHeight(htlc *PaymentDescriptor, remoteChain bool) *uint64 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do these functions return pointer types?

Comment on lines +575 to +581
type AuxDataParser interface {
// InlineParseCustomData replaces any custom data binary blob in the
// given RPC message with its corresponding JSON formatted data. This
// transforms the binary (likely TLV encoded) data to a human-readable
// JSON representation (still as byte slice).
InlineParseCustomData(msg proto.Message) error
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

This commit adds an interface without an implementation. Was that intentional? I think we should clarify the commit message if it was intentional. Otherwise the implementation is unexpectedly missing.

Comment on lines +954 to +957
// When the HTLC was decoded from the wire, the ExtraData field was
// parsed and split into the BlindingPoint and CustomRecords. Which
// means we don't have to copy over the ExtraData itself into the
// PaymentDescriptor, just the encoded CustomRecords.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure if this comment is true. The ExtraData field still might contain data for a field which is lower in type than the custom records type range but not a defined field on the HTLC.

To avoid sorting issues with identical HTLCs (equal size, equal payment
hash, equal CLTV), we need to also use the HTLC index to be able to
distinguish between them.
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.

None yet

3 participants