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

Add AltLeaf support to tapfreighter #1233

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open

Add AltLeaf support to tapfreighter #1233

wants to merge 17 commits into from

Conversation

jharveyb
Copy link
Contributor

@jharveyb jharveyb commented Dec 3, 2024

This continues the work from #1180 .

Specifically:

  • Adds the AltLeaves field to Proof.
  • Tests correct en/decode of a Proof with AltLeaves populated.
  • Propagates AltLeaves from vOutputs, to anchor outputs for a transfer, and the corresponding transition proof.
  • Fetches AltLeaves for asset inputs during coin selection, and uses these AltLeaves when verifying the input anchor pubkey.

Test-wise, the added unit tests cover the new validation methods around []AltLeaves, and the new funcs that act on Tap commitments. The changes in later commits in tapsend and tapfrieghter are mostly only exercised via the PSBT itest.

@jharveyb
Copy link
Contributor Author

jharveyb commented Dec 3, 2024

From some offline review, there are a few clear TODOs:

  • Convert the new funcs that operate on Tap commitments to methods
  • Convert new errors to named errors
  • Add some more altleaf generation in existing unit tests
  • Add new asserts for itests wrt. checking for alt leaves
  • Add test vectors for Proof

@jharveyb
Copy link
Contributor Author

jharveyb commented Dec 4, 2024

The test vectors for Proof also need to be updated.

@coveralls
Copy link

coveralls commented Dec 4, 2024

Pull Request Test Coverage Report for Build 12381816079

Details

  • 303 of 470 (64.47%) changed or added relevant lines in 17 files are covered.
  • 22 unchanged lines in 8 files lost coverage.
  • Overall coverage increased (+0.1%) to 40.826%

Changes Missing Coverage Covered Lines Changed/Added Lines %
proof/records.go 10 11 90.91%
proof/append.go 6 8 75.0%
asset/asset.go 34 39 87.18%
commitment/tap.go 54 66 81.82%
rpcserver.go 0 13 0.0%
tapdb/assets_store.go 43 57 75.44%
tapsend/send.go 52 68 76.47%
tappsbt/interface.go 9 26 34.62%
tapfreighter/wallet.go 0 42 0.0%
itest/assertions.go 0 45 0.0%
Files with Coverage Reduction New Missed Lines %
tapfreighter/wallet.go 1 0.52%
rpcserver.go 1 0.0%
tappsbt/create.go 2 53.22%
tapgarden/planter.go 2 74.12%
commitment/tap.go 2 84.49%
universe/interface.go 4 51.95%
tapdb/universe.go 4 80.91%
tapdb/multiverse.go 6 68.21%
Totals Coverage Status
Change from base Build 12379489363: 0.1%
Covered Lines: 26093
Relevant Lines: 63912

💛 - Coveralls

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

Very clean! Did a first pass but will want to take another one to take a closer look at backward compatibility, with some manual testing.

commitment/tap.go Outdated Show resolved Hide resolved
commitment/tap.go Show resolved Hide resolved
tapfreighter/wallet.go Show resolved Hide resolved
rpcserver.go Show resolved Hide resolved
rpcserver.go Outdated Show resolved Hide resolved
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

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

Nice work with this change! Lots of little nooks and crannies to identify+update. Will sit with it for a bit to try and identify any missing areas or deficiencies in the tests

tappsbt/interface.go Outdated Show resolved Hide resolved
tappsbt/interface.go Outdated Show resolved Hide resolved
commitment/tap.go Outdated Show resolved Hide resolved
proof/append.go Outdated Show resolved Hide resolved
tapfreighter/wallet.go Show resolved Hide resolved
tapfreighter/wallet.go Show resolved Hide resolved
rpcserver.go Show resolved Hide resolved
@jharveyb
Copy link
Contributor Author

jharveyb commented Dec 6, 2024

Added a new itest to check that the tapfreighter and the vPSBT RPCs are rejecting invalid combinations of AltLeaves correctly (which surfaced some small need tweaking). The new test also demonstates that AltLeaves are merged into the same anchor output correctly.

@guggero guggero force-pushed the proof_alt_leaves branch 2 times, most recently from a7e34d5 to f4b1bc0 Compare December 12, 2024 10:32
@guggero guggero requested a review from gijswijs December 12, 2024 17:01
@dstadulis dstadulis added this to the v0.5 milestone Dec 12, 2024
@lightninglabs-deploy
Copy link

@jharveyb, remember to re-request review from reviewers when ready

Copy link
Contributor

@gijswijs gijswijs left a comment

Choose a reason for hiding this comment

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

Why did we choose to trim alt leaves from passive vPkts? I tried to think of a scenario where we would want those alt leaves to persist. I couldn't really think of one, but I could see a future where we would find a use case for that.

proof/proof_test.go Show resolved Hide resolved
tappsbt/interface.go Show resolved Hide resolved
commitment/tap.go Show resolved Hide resolved
commitment/tap.go Outdated Show resolved Hide resolved
jharveyb and others added 10 commits December 17, 2024 20:00
By changing the generic signature of the AltLeaf type we can get rid of
some of the weirdness and helper methods surrounding the type.
In this commit, we add an AltLeaves field to Proof, and update Proof
en/decode to support this optional field. With a small test change, we
also check that Proof.Verify() functions for Proofs that accounted for
any present AltLeaves correctly.
In this commit, we add logic to handle adding and removing altLeaves
from a TapCommitment. Unlike normal Assets, we never want to update an
AltLeaf once inserted into the AltCommitment. This means we need to
assert that AltLeaves being added to a TapCommitment don't collide with
already committed AltLeaves.
In this commit, we update the passive asset handling to not consider
altLeaves as assets. Specifically, any altLeaf in an input Tap
commitment should be set in the vInput for a passive asset vPkt, but
should not have its own vPkt where it is an input. Overall, input
altLeaves do not need to be re-anchored.
@guggero
Copy link
Member

guggero commented Dec 17, 2024

Why did we choose to trim alt leaves from passive vPkts?

We don't trim the alt leaves from passive assets. The two places where we use the commitment.TrimAltLeaves() function is where we check if any assets remain after removing a certain asset from a commitment (e.g. the asset being burned or the active asset of a transfer). And for those checks the alt leaves would be counted as "normal" assets and give a wrong result. So just for those two checks we trim the alt leaves (but in the case of passive assets we add them back further below).

Copy link
Member

@guggero guggero left a comment

Choose a reason for hiding this comment

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

As far as I can tell this gives us everything we need to be forward compatible with alt leaves, so giving my LGTM.

@guggero guggero requested review from gijswijs and Roasbeef December 17, 2024 21:36
@gijswijs
Copy link
Contributor

LGTM 🎉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

7 participants