taproot-assets icon indicating copy to clipboard operation
taproot-assets copied to clipboard

tapgarden: implement SealBatch

Open jharveyb opened this issue 10 months ago • 8 comments

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
  • [x] Update SealBatch to reject being called more than once
  • [x] Add itest that mints with custom asset group witnesses, custom script keys
  • [x] Add itest that spends an asset minted with a custom script key
  • [x] Update existing minting itests as needed
  • [x] Add itest that spends an anchor amount with a custom script instead of a signature

jharveyb avatar Apr 02 '24 18:04 jharveyb

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 avatar Apr 03 '24 20:04 jharveyb

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 avatar Apr 11 '24 15:04 jharveyb

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 avatar Apr 12 '24 22:04 jharveyb

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:

https://github.com/lightninglabs/taproot-assets/blob/761212d32a794666bfb09a7ac52aeefc02fc1078/itest/mint_fund_seal_test.go#L70

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 avatar Apr 15 '24 15:04 jharveyb

Remaining tasks:

  • [x] freeze batch at the end of SealBatch to prevent further calls to add seedlings, fund, or freeze
  • [x] 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:

https://github.com/lightninglabs/taproot-assets/issues/883#issuecomment-2059673703

jharveyb avatar Apr 16 '24 18:04 jharveyb

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 avatar Apr 23 '24 16:04 jharveyb

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 avatar May 01 '24 00:05 jharveyb

@georgetsagk: review reminder @guggero: review reminder

lightninglabs-deploy avatar May 08 '24 01:05 lightninglabs-deploy

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

jharveyb avatar May 16 '24 15:05 jharveyb