Skip to content

Commit

Permalink
tapdb: fix incorrect asset ID for grouped assets
Browse files Browse the repository at this point in the history
It doesn't make sense to have the asset ID set for grouped assets in the
multiverse or universe roots tables. The asset ID would only really
point to the very first asset.
  • Loading branch information
guggero committed Oct 25, 2023
1 parent 7932f29 commit 55bbfd9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions tapdb/sqlc/migrations/000010_multiverse_tree.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ WHERE EXISTS (
SELECT 1 FROM mssmt_roots WHERE namespace = 'multiverse-transfer'
);

-- Before we turn the existing universe_roots into multiverse_leaves, we need to
-- fix a bug in the data where the asset ID was set for grouped assets.
UPDATE universe_roots
SET asset_id = NULL
WHERE group_key IS NOT NULL;

-- And now we create the multiverse_leaves entries for the multiverse roots.
-- This is a no-op if the multiverse root doesn't exist yet.
INSERT INTO multiverse_leaves (
Expand Down
6 changes: 4 additions & 2 deletions tapdb/universe.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,11 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore,
return nil, nil, err
}

var groupKeyBytes []byte
var groupKeyBytes, assetIDBytes []byte
if id.GroupKey != nil {
groupKeyBytes = schnorr.SerializePubKey(id.GroupKey)
} else {
assetIDBytes = id.AssetID[:]
}

mintingPointBytes, err := encodeOutpoint(key.OutPoint)
Expand Down Expand Up @@ -405,7 +407,7 @@ func universeUpsertProofLeaf(ctx context.Context, dbTx BaseUniverseStore,
// root ID that we'll use to insert the universe leaf overlay.
universeRootID, err := dbTx.UpsertUniverseRoot(ctx, NewUniverseRoot{
NamespaceRoot: namespace,
AssetID: fn.ByteSlice(leaf.ID()),
AssetID: assetIDBytes,
GroupKey: groupKeyBytes,
ProofType: id.ProofType.String(),
})
Expand Down

0 comments on commit 55bbfd9

Please sign in to comment.