-
Notifications
You must be signed in to change notification settings - Fork 132
tapgarden: list batches correctly after asset transfer #992
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
Conversation
I ran commit As a result
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
not sure if the CI error is a flake
I think we can just replace Instead, I think we can follow this chain: batch genesis asset ref -> genesis point ref -> chain txn. Then with the chain txn of the batch, we can join on the assets table to find the precise asset that was created in this instance. here's a version from Claude: -- name: FetchAssetsForBatch :many
WITH batch_info AS (
-- This CTE fetches the batch and its associated genesis point and anchor transaction
SELECT
batches.batch_id,
points.genesis_id,
points.anchor_tx_id
FROM asset_minting_batches batches
JOIN internal_keys keys ON batches.batch_id = keys.key_id
JOIN genesis_points points ON batches.genesis_id = points.genesis_id
WHERE keys.raw_key = $1
)
SELECT
assets.version,
script_keys.tweak,
script_keys.tweaked_script_key,
script_keys.declared_known AS script_key_declared_known,
internal_keys.raw_key AS script_key_raw,
internal_keys.key_family AS script_key_fam,
internal_keys.key_index AS script_key_index,
key_group_info_view.tapscript_root,
key_group_info_view.witness_stack,
key_group_info_view.tweaked_group_key,
key_group_info_view.raw_key AS group_key_raw,
key_group_info_view.key_family AS group_key_family,
key_group_info_view.key_index AS group_key_index,
assets.script_version,
assets.amount,
assets.lock_time,
assets.relative_lock_time,
assets.spent,
genesis_info_view.asset_id,
genesis_info_view.asset_tag,
genesis_info_view.meta_hash,
genesis_info_view.meta_type,
genesis_info_view.meta_blob,
genesis_info_view.output_index AS genesis_output_index,
genesis_info_view.asset_type,
genesis_info_view.prev_out AS genesis_prev_out
FROM assets
JOIN genesis_info_view ON assets.genesis_id = genesis_info_view.gen_asset_id
LEFT JOIN key_group_info_view ON assets.genesis_id = key_group_info_view.gen_asset_id
JOIN script_keys ON assets.script_key_id = script_keys.script_key_id
JOIN internal_keys ON script_keys.internal_key_id = internal_keys.key_id
JOIN managed_utxos ON assets.anchor_utxo_id = managed_utxos.utxo_id
JOIN batch_info ON genesis_info_view.gen_asset_id = batch_info.genesis_id
WHERE managed_utxos.txn_id = batch_info.anchor_tx_id; The last two lines there are most important: JOIN batch_info ON genesis_info_view.gen_asset_id = batch_info.genesis_id
WHERE managed_utxos.txn_id = batch_info.anchor_tx_id; We join with the batch info to line things up, then filter out for instances where the managed UTXO points to the same transaction as the one we made in the batch. |
e3ca693
to
e347419
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is looking real nice. Made some comments and asked some questions throughout.
The query looks decent but @guggero caught an issue that would pop up as a result of how we handle passive assets. At the end of the transfer logic, we re-anchor all passive assets: taproot-assets/tapdb/assets_store.go Line 2869 in aa3d671
Which involves updating the asset witness and the anchor UTXO:
So after a single reanchoring, if we filtered entries in the |
With the latest push, I can successfully list batches from this DB + set of proof files, with the earliest batch dating to October 2023. Reading assets from the proof files means that we don't get unserialized info like the group internal key or the tap tweak for the script key, so I'd like to add some logic to fetch that from the DB (we never delete entries in those tables, so that info should be present regardless of future transfers). The group anchor field is also unpopulated, but that should also be doable given the seedlings we're already fetching. |
Test timeout, will rerun:
|
e347419
to
a8c7639
Compare
In this commit, we change the batch marshalling behavior for finalized batches. We return the batch seedlings, as these are not mutated once an asset from a batch is spent. The next commit adds the means to fetch fully populated assets for a finalized batch.
In this commit, we add a new method to proof.Archiver to support querying for proofs with only the asset ID and anchor outpoint. This is useful when fetching issuance proofs in order to display genesis assets, as assets in the DB can be mutated if they are reanchored as passive assets (participate in a transfer as change). This is only implemented for the FileArchiver, as we can use proof file paths to efficiently fetch only the issuance proofs.
In this commit, we update listBatches to fetch assets from finalized batches via the proof file archiver instead of the DB. Given the batch seedlings, we fetch issuance proofs and decode the asset in its genesis state. We also verify that we can recompute the genesis output script with the fetched assets.
a8c7639
to
62b431e
Compare
Addressed all comments + added some extra querying to fill out the script key and group key info. No further changes planned. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 💃🏾
|
||
// TODO(jhb): Does funding guarantee that minting TXs always have | ||
// exactly two outputs? If not this func should be fallible. | ||
if genesisPkt.ChangeOutputIndex == 0 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using the current FundPSBT
call, yeah: we'll have the target output and a change output. Once we expose batch asset chan funding though, this'll change.
// If a proof cannot be found, then ErrProofNotFound should be returned. | ||
// | ||
// NOTE: This implements the Archiver interface. | ||
func (f *FileArchiver) FetchIssuanceProof(ctx context.Context, id asset.ID, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't this just use the universe archive only? The only thing you need to query for the issuance proof is the asset ID: https://github.com/lightninglabs/taproot-assets/blob/main/universe/interface.go#L329-L336
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed offline, and for maximal backwards compat, the file store may be the best option here as it existed before the universe store did.
Fixes #986 .
As detailed in #986, recent changes around how batches are created updated the way we store seedlings; specifically when we store script keys and group keys. Changes were made to how batches were displayed, and those changes broke the display of batches minted with tapd versions 0.3.3 or earlier.
Further investigation showed that the
ListBatches
RPC (and matching CLI command) displayed incorrect information once assets from a batch had been transferred.To fix this, we can re-read the assets minted in a batch from their issuance proofs that we stored on disk when finalizing the batch.