Skip to content

minting: fix re-issuing into existing group with external key #1517

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

Merged
merged 3 commits into from
May 9, 2025

Conversation

guggero
Copy link
Member

@guggero guggero commented May 6, 2025

Fixes #1515.
Fixes #1516.

@ZZiigguurraatt
Copy link

so this is ready to test?

@guggero
Copy link
Member Author

guggero commented May 6, 2025

so this is ready to test?

Yes.

@coveralls
Copy link

coveralls commented May 6, 2025

Pull Request Test Coverage Report for Build 14902741297

Details

  • 6 of 47 (12.77%) changed or added relevant lines in 4 files are covered.
  • 17 unchanged lines in 8 files lost coverage.
  • Overall coverage decreased (-0.01%) to 36.918%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapgarden/planter.go 6 8 75.0%
tapgarden/batch.go 0 4 0.0%
rpcserver.go 0 11 0.0%
tapgarden/seedling.go 0 24 0.0%
Files with Coverage Reduction New Missed Lines %
commitment/tap.go 1 72.05%
tapgarden/batch.go 1 71.88%
asset/asset.go 2 49.17%
asset/mock.go 2 65.45%
internal/test/helpers.go 2 86.95%
tappsbt/create.go 2 26.74%
rpcserver.go 3 0.0%
tapgarden/caretaker.go 4 68.68%
Totals Coverage Status
Change from base Build 14895618326: -0.01%
Covered Lines: 26530
Relevant Lines: 71862

💛 - Coveralls

@ZZiigguurraatt
Copy link

are you able to put these commits on top of #1498 as that is what I'm currently testing with ?

is that going to work okay as long as you merge #1498 first?

@levmi levmi requested review from Roasbeef and ffranr May 6, 2025 18:41
@guggero guggero force-pushed the re-issuance-external-group-key branch from 1805148 to d88ec8a Compare May 7, 2025 10:49
@guggero guggero requested a review from ZZiigguurraatt May 7, 2025 10:49
@ZZiigguurraatt
Copy link

ZZiigguurraatt commented May 7, 2025

I'm able to get this PR to work.

One additional thing I've now tested is the group_anchor option. Does that only work to mint two tranches in the same batch (without having a group_key first)? I'm trying to use it in a second batch, but I get

unable to mint asset: batch empty, group anchor Asset1 invalid

If it is only for minting two tranches in the same batch, why do we need to do that? Seems to me like if someone is going to be minting the same asset in the same batch, they would never need two tranches? I'm just wondering if this option should be removed if that is its only purpose. If it should not be removed, I think we should change the description from

The name of the asset in the batch that will anchor a new asset group.
This asset will be minted with the same group key as the anchor asset.

to

The name of a new asset in the same batch that will anchor a new asset group.
This asset will be minted with the same group key as the anchor asset.
This option cannot be used to anchor to an asset that has already been finalized in a previous batch.

If it is supposed to work from a second batch, I think we should fix it.

@guggero
Copy link
Member Author

guggero commented May 7, 2025

Does that only work to mint two tranches in the same batch (without having a group_key first)?

Yes, the group anchor (string) argument is only for tranches in the same batch.
I know we need to improve the documentation in this area. But basically the flags/fields work this way:

  • new_grouped_asset: I want to create a new group and this asset starts the group.
  • grouped_asset: This asset belongs to a group and I'll specify what group that is with other params (can either be group_anchororgroup_key`)
  • group_internal_key: When starting a new group, instruct lnd to use this specific key from the keychain to sign for the group (only works with new_grouped_asset).
  • external_group_key: Don't use a group internal key that is owned by lnd, use the externally owned key specified in this struct. This is required for both starting a group as well as re-issuing into an existing group that uses the external group (these are basically signing instructions).
  • group_anchor: Another asset in the current batch started the group, this asset should be put in the same group as the one in the batch with the name given (use case: multiple collectibles that belong to the same group but are minted in the same transaction). Reason for this being a string: In the case where the user doesn't want to define what group key they want to assign, one is created automatically. But this is done when sealing the batch, so we can't reference it as an actual public key here. That's why we specify the group anchor by its name (string).
  • group_key: Another asset in another batch/transaction started the group. This asset should join the group that has this group public key.

Feel free to use this in any way to update the docs...

@ZZiigguurraatt
Copy link

Does that only work to mint two tranches in the same batch (without having a group_key first)?

Yes, the group anchor (string) argument is only for tranches in the same batch. I know we need to improve the documentation in this area. But basically the flags/fields work this way:

* `new_grouped_asset`: I want to create a new group and this asset starts the group.

* grouped_asset`: This asset belongs to a group and I'll specify what group that is with other params (can either be `group_anchor`or`group_key`)

* `group_internal_key`: When starting a new group, instruct `lnd` to use this specific key from the keychain to sign for the group (only works with `new_grouped_asset`).

* `external_group_key`: Don't use a group internal key that is owned by `lnd`, use the externally owned key specified in this struct. This is required for both starting a group as well as re-issuing into an existing group that uses the external group (these are basically signing instructions).

* `group_anchor`: Another asset in the current batch started the group, _this_ asset should be put in the same group as the one in the batch with the name given (use case: multiple collectibles that belong to the same group but are minted in the same transaction). Reason for this being a string: In the case where the user doesn't want to define what group key they want to assign, one is created automatically. But this is done when sealing the batch, so we can't reference it as an actual public key here. That's why we specify the group anchor by its name (string).

* `group_key`: Another asset in another batch/transaction started the group. This asset should join the group that has this group public key.

Feel free to use this in any way to update the docs...

This helps a lot. Linking to this comment in #1519 so that we can deal with it there.

if !group.GroupKey.IsLocal() {
groupKeyBytes := c.GroupInfo.GroupPubKey.SerializeCompressed()
return fmt.Errorf("can't sign with group key %x", groupKeyBytes)
switch {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of this switch you can just return early with:

if c.ExternalKey.IsNone() && !group.GroupKey.IsLocal() {
	groupPubKey := c.GroupInfo.GroupPubKey
	groupKeyBytes := groupPubKey.SerializeCompressed()
	return fmt.Errorf("can't sign with group key %x",
		groupKeyBytes)
}

And you don't need to wrap the fn.MapOptionZ call in case c.ExternalKey.IsSome():. Because fn.MapOptionZ will just return err == nil if c.ExternalKey.IsNone(). Maybe we can save on indentation like that.

Copy link
Member Author

@guggero guggero May 8, 2025

Choose a reason for hiding this comment

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

Ah nice, that's actually much cleaner. Updated, thanks.

Comment on lines +580 to +582
mintReq2.Asset.GroupedAsset = true
mintReq2.Asset.NewGroupedAsset = false
mintReq2.Asset.GroupKey = batchAssets[0].AssetGroup.TweakedGroupKey
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is mintReq2.Asset.GroupedAsset = true necessary here? I would have expected setting mintReq2.Asset.ExternalGroupKey to imply group asset sufficiently.

Is setting these fields necessary or are we just covering all possibilities 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.

The RPC (and by extension the CLI) interface for the minting call is not optimal and quite confusing. See #1517 (comment)

So you need to set at least one of the GroupedAsset or NewGroupedAsset to true if you want to start or issue into a group, independent of the other fields.

guggero added 3 commits May 8, 2025 11:00
This commit fixes two checks that prevented us to re-issue more assets
into an existing group using an external group key.
Turns out we didn't really set up the group minting request properly to
mint into an existing group. Before this change we'd simply mint a
completely new group, using the same external key.
We renamed the RPC-level flag to NewGroupedAsset to make its use more
clear. This commit adjusts some of the left-over error messages to align
with the rename.
@guggero guggero force-pushed the re-issuance-external-group-key branch from d88ec8a to 8863f04 Compare May 8, 2025 09:01
@guggero guggero requested a review from ffranr May 8, 2025 09:39
Copy link
Contributor

@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.

thanks for the fix

@levmi levmi added the P0 label May 8, 2025
@levmi levmi moved this from 🆕 New to 👀 In review in Taproot-Assets Project Board May 8, 2025
@guggero guggero requested review from GeorgeTsagk and removed request for Roasbeef May 9, 2025 15:47
Copy link
Member

@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.

Looks good! 🌴

@GeorgeTsagk GeorgeTsagk added this pull request to the merge queue May 9, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 9, 2025
@guggero guggero merged commit 70b62f2 into main May 9, 2025
18 checks passed
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board May 9, 2025
@guggero guggero deleted the re-issuance-external-group-key branch May 9, 2025 16:39
@ZZiigguurraatt
Copy link

I have been having good results with this one. Thanks for the quick fix and so much feedback. Glad to see it merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: ✅ Done
6 participants