Skip to content

Support group keys on HTLC Interceptor & Invoice HTLC Modifier #1416

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

Closed

Conversation

GeorgeTsagk
Copy link
Member

Description

With this PR we extend the rfq.OrderHandler and tapchannel.AuxInvoiceManager sub systems to be able to read groupkey specifiers and handle HTLCs with multiple asset balances.

Based on #1382

@GeorgeTsagk GeorgeTsagk self-assigned this Feb 27, 2025
@coveralls
Copy link

coveralls commented Feb 27, 2025

Pull Request Test Coverage Report for Build 13656341913

Details

  • 45 of 60 (75.0%) changed or added relevant lines in 4 files are covered.
  • 55 unchanged lines in 14 files lost coverage.
  • Overall coverage increased (+0.01%) to 54.577%

Changes Missing Coverage Covered Lines Changed/Added Lines %
tapchannel/aux_invoice_manager.go 18 19 94.74%
rfqmsg/records.go 10 12 83.33%
rfq/order.go 12 24 50.0%
Files with Coverage Reduction New Missed Lines %
commitment/tap.go 2 84.77%
mssmt/compacted_tree.go 2 83.27%
tapchannel/aux_invoice_manager.go 2 91.5%
tapchannel/aux_leaf_signer.go 2 43.08%
tapdb/mssmt.go 2 88.64%
tapdb/universe.go 2 81.76%
universe/base.go 2 79.53%
asset/asset.go 3 80.65%
asset/mock.go 3 72.45%
rfqmsg/records.go 3 72.05%
Totals Coverage Status
Change from base Build 13655815117: 0.01%
Covered Lines: 49004
Relevant Lines: 89788

💛 - Coveralls

@GeorgeTsagk GeorgeTsagk moved this from 🆕 New to 🏗 In progress in Taproot-Assets Project Board Feb 27, 2025
@GeorgeTsagk GeorgeTsagk force-pushed the rfq-negotiation-groupkey branch from 269ad4b to 7c660bd Compare March 4, 2025 14:23
@GeorgeTsagk GeorgeTsagk force-pushed the group-htlc-interceptor-acceptor branch from b1ee2ba to 43afd50 Compare March 4, 2025 14:26
We add a new interface to the HTLC SumAssetBalance method, which helps
check the identifier of the asset against a specifier. This allows for
checking asset inclusion in a group, which is a bit involved and not the
responsibility of the HTLC model.
We extend the interface of the rfq Policy in order to allow the
specifier checker to be involved. This extends certain checks, and
allows us to use asset specifiers that only have a group key.
We add the specifier checker interface to the AuxInvoiceManager too, as
it is needed to validate incoming HTLCs which may use asset IDs that
belong to a group, while the RFQ is based on a group key.
Adds some coverage to the invoice manager unit tests, which involve an
RFQ quote over a group key, plus an HTLC with multiple asset balances,
which may belong or not to the group.
@GeorgeTsagk GeorgeTsagk force-pushed the group-htlc-interceptor-acceptor branch from 43afd50 to e3be2a0 Compare March 4, 2025 14:49
// AssetMatchesSpecifier checks whether the passed specifier and asset
// ID match. If the specifier contains a group key, it will check
// whether the asset belongs to that group.
AssetMatchesSpecifier(ctx context.Context,
Copy link
Member

Choose a reason for hiding this comment

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

I think we should remove the other version of this interface added (in rfqmsg) and just keep this one.

Copy link
Member Author

Choose a reason for hiding this comment

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

importing this in rfqmsg causes import cycle

// we just need to provide a dummy value as the asset ID. The
// real asset IDs will be carefully picked in a later step in
// the process. What really matters now is the total amount.
assetID = sha256.Sum256(groupKey.SerializeCompressed())
Copy link
Member

Choose a reason for hiding this comment

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

Why isn't the asset ID relevant here? It looks like it's used to pass along which custom records to use for the outgoing HTLC transformation.

IIUC, we need to select the asset ID amongst the set of active channels the outgoing link has that may all be diff, but have the same asset group.

Copy link
Member Author

Choose a reason for hiding this comment

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

We don't know of specific asset IDs on this level, and we don't need do. What we want to do here is signal the amount that needs to be sent to the other side.

Channel selection was already taken care of when the receiver negotiated & embedded a quote in the invoice. At this point in the code, we're only intercepting the HTLC which has a predetermined outgoing channel.

// AssetMatchesSpecifier checks if the provided asset satisfies the
// provided specifier. If the specifier includes a group key, we will
// check if the asset belongs to that group.
AssetMatchesSpecifier(ctx context.Context, specifier asset.Specifier,
Copy link
Member

Choose a reason for hiding this comment

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

Seems the rfq package is already imported here, so we can embed that interface. Mainly a question re style.

Copy link
Member Author

Choose a reason for hiding this comment

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

I usually stick with the interface approach, which also serves as a hint w.r.t what parts of rfq manager we'll be using.


switch {
case specifier.HasGroupPubKey():
return true, nil
Copy link
Member

Choose a reason for hiding this comment

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

Why do we just return true for group keys? We should expand the unit tests here and earlier in the PR to make sure to matches properly re same group key but diff asset IDs.

Copy link
Member Author

Choose a reason for hiding this comment

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

this was a placeholder just for the commit to compile. In a later commit this transforms to

	case specifier.HasGroupPubKey():
		if id == groupAssetID_1 || id == groupAssetID_2 {
			return true, nil
		}

		return false, nil

@github-project-automation github-project-automation bot moved this from 🏗 In progress to 👀 In review in Taproot-Assets Project Board Mar 5, 2025
@GeorgeTsagk
Copy link
Member Author

Thanks for the early review @Roasbeef

I will close this PR in favor of #1423, which broadens the scope just a little bit to make group keys effective e2e

I did address some of your comments, and will keep looking here in case you reply to the threads above.

@GeorgeTsagk GeorgeTsagk closed this Mar 5, 2025
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Taproot-Assets Project Board Mar 5, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

3 participants