Skip to content

Conversation

@jharveyb
Copy link
Contributor

@jharveyb jharveyb commented Apr 2, 2024

Addresses #722. Depends on #827.

Remaining TODOs:

  • Extend tapdb/asset_minting tests to cover new query params for script key, group key, etc.
  • Add tests for tapdb/asset_minting/CommitBatchTx, AddSeedlingGroups, FetchSeedlingGroups
  • Update SealBatch to reject being called more than once
  • Add itest that mints with custom asset group witnesses, custom script keys
  • Add itest that spends an asset minted with a custom script key
  • Update existing minting itests as needed
  • Add itest that spends an anchor amount with a custom script instead of a signature

@jharveyb jharveyb added this to the v0.4 milestone Apr 2, 2024
@jharveyb jharveyb self-assigned this Apr 2, 2024
@dstadulis dstadulis added enhancement New feature or request batching labels Apr 2, 2024
@jharveyb jharveyb force-pushed the mint_early_sprouting branch from c2e1cfd to 42b7bde Compare April 3, 2024 18:06
@jharveyb
Copy link
Contributor Author

jharveyb commented Apr 3, 2024

Have an external group witness working now in unit tests. Still looking at ways to prevent SealBatch from being called multiple times.

Right now IIUC we don't explicitly reject new seedling requests after a batch is frozen, so one option is to just freeze the batch at the end of SealBatch + disallow all calls except for FinalizeBatch on a frozen batch. So after calling SealBatch, the only other calls available would be finalize or cancel.

@jharveyb jharveyb force-pushed the mint_early_sprouting branch from 42b7bde to 132a2d0 Compare April 9, 2024 16:48
Base automatically changed from mint_early_sprouting to main April 9, 2024 17:19
@jharveyb jharveyb requested a review from guggero April 10, 2024 01:19
Copy link
Contributor

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

Looks pretty good to me! Looking forward to seeing it in action with an itest 🎉
Main request is to potentially remove some code duplication by moving some of the complexity of the seedlings further down, instead of having two almost identical batch structs.

@jharveyb jharveyb force-pushed the mint_seal_batch branch 2 times, most recently from 1f28703 to 434b33a Compare April 10, 2024 22:14
@jharveyb
Copy link
Contributor Author

Looks like a possible new flake in custodian event handling?

--- FAIL: TestTransactionConfirmedOnly (123.22s)
    test_postgres.go:11: Creating new Postgres DB for testing
    custodian_test.go:220: 
        	Error Trace:	/home/runner/work/taproot-assets/taproot-assets/tapgarden/custodian_test.go:220
        	            				/home/runner/work/taproot-assets/taproot-assets/tapgarden/custodian_test.go:740
        	            				/home/runner/work/taproot-assets/taproot-assets/tapgarden/custodian_test.go:669
        	Error:      	Received unexpected error:
        	            	method did not return within the timeout
        	Test:       	TestTransactionConfirmedOnly
FAIL
FAIL	github.com/lightninglabs/taproot-assets/tapgarden	156.362s
FAIL

@jharveyb
Copy link
Contributor Author

Posted some updates, mostly fixes where the group tapscript root wasn't being propogated correctly.

Also some changes in the MintAsset RPC to accomodate all the new fields.

Still working out some marshalling issues when generating group witnesses.

@jharveyb
Copy link
Contributor Author

jharveyb commented Apr 15, 2024

Posted my latest state. The issue with the version of the test I was working on before was internal keys not derived from the backing tapd node. Example for derivation here:

deriveRandomKey := func(lnd *node.HarnessNode) keychain.KeyDescriptor {

The posted version generates a sig for a siglock external to the planter, but I could not get a similar witness working if that key was derived from the backing lnd node, for both the Taproot Assets key family, or a random key family.

I'm at the last steps of the PSBT flow, which is very similar to the multisig test.

@jharveyb
Copy link
Contributor Author

jharveyb commented Apr 16, 2024

Remaining tasks:

  • freeze batch at the end of SealBatch to prevent further calls to add seedlings, fund, or freeze
  • Add CLI support

There's a path toward external key support in the itest via some changes in buildGroupReqs and how the key descriptor is set in the seedling:

#883 (comment)

@jharveyb
Copy link
Contributor Author

I have a branch that resolves #883 , but the better fix for that would be switching to SignPsbt for the VirtualTxSigner.

From offline discussion, I think for this PR we'll continue to accept a non-local group internal key without any constraints on the keyDescriptor / won't require mutual exclusion of the pubkey and keyLocator. I think having the family and index in the DB for a non-local internal key is useful in some cases, and shouldn't cause issues if it's for the group internal key.

@jharveyb jharveyb force-pushed the mint_seal_batch branch 2 times, most recently from 69b4b7e to c74bf0b Compare May 1, 2024 00:41
@jharveyb
Copy link
Contributor Author

jharveyb commented May 1, 2024

CLI commands are added, but they omit the fields with non-trivial formatting like KeyDescriptor or asset.ScriptKey. Similar to the commands we have for generating addresses, some functionality is only available via the RPCs directly.

@jharveyb jharveyb requested review from GeorgeTsagk and guggero May 1, 2024 00:43
@jharveyb jharveyb marked this pull request as ready for review May 1, 2024 00:43
@jharveyb jharveyb linked an issue May 1, 2024 that may be closed by this pull request
3 tasks
@lightninglabs-deploy
Copy link

@GeorgeTsagk: review reminder
@guggero: review reminder

Copy link
Contributor

@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 nice! tACK, LGTM 🎉

Mostly nits and nice-to-haves.

var sealBatchCommand = cli.Command{
Name: "seal",
Usage: "seal a batch",
Description: "Attempt to seal the pending batch.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this command really do anything on the command line other than sanity check that we can generate witnesses for all group keys in the batch? Not sure if we should hide (Hidden: true) the command and only keep it for debugging? Since it probably doesn't make sense to support submitting the actual witnesses through the CLI (only makes sense through RPC).

Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeh seems odd given that it doesn't have any acutal args in the proto.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I agree it doesn't have much use...

I suppose we want to still expose fund as we'll add other features to that later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update: added more to the descriptions and hid this cmd. In practice you could do fund + finalize from the CLI if we don't accept witness in seal.

// also want to reissue assets with a custom asset group witness, and spend
// an asset with a custom script key witness. An asset group with a tapscript
// root should also be imported into a new node correctly.
func testMintFundSealAssets(t *harnessTest) {
Copy link
Member

Choose a reason for hiding this comment

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

Great itest, but I think it would be easier to follow if some of the sub-components were split down into helper functions. So eg:

  • Making the tapscript root for the group key.
  • Making the root for the funding output tapscript leaf.
  • Signing on both levels,
  • The multi-sig sign and transfer at the end,

etc

var sealBatchCommand = cli.Command{
Name: "seal",
Usage: "seal a batch",
Description: "Attempt to seal the pending batch.",
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, yeh seems odd given that it doesn't have any acutal args in the proto.


func (r *rpcServer) SealBatch(ctx context.Context,
req *mintrpc.SealBatchRequest) (*mintrpc.SealBatchResponse, error) {

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this require that group witnesses re provided? Otherwise, how can you seal a batch w/o providing the witness?

Copy link
Contributor Author

@jharveyb jharveyb May 14, 2024

Choose a reason for hiding this comment

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

The check for all assets that need a witness, having a witness, is in the planter:

For all assets without an external witness, we try to derive the default witness. If we are unable to, DeriveGroupKey fails and no groups would be saved to disk.

So this call would fail if at least one external witness is needed. From the RPC layer, we can't really know if any external witnesses are needed.

jharveyb added 2 commits May 16, 2024 10:53
In this commit, we add an itest to exercise the FundBatch and
SealBatch RPCs. Specifically, we use asset script and group internal
keys derived outside of tapd, pass asset group witnesses via
SealBatch, and use a tweaked asset script key set during minting to
complete an asset transfer. We also use a tapscript sibling set
during minting to provide a script witness for anchoring an asset
transfer.
@jharveyb
Copy link
Contributor Author

Updated to address all comments, itest should be more readable now + other small fixes.

@jharveyb jharveyb requested review from Roasbeef and removed request for GeorgeTsagk May 16, 2024 15:38
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.

LGTM 🍵

@Roasbeef Roasbeef merged commit 057880e into main May 16, 2024
@guggero guggero deleted the mint_seal_batch branch May 17, 2024 06:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

batching enhancement New feature or request

Projects

Status: ✅ Done

Development

Successfully merging this pull request may close these issues.

[feature]: custom Group Key API for minting

6 participants