Skip to content

Commit b33b4e0

Browse files
committed
multi: add outpoint field to mint anchor uni commitment
This'll be useful to fix a bug in the next commit, where we weren't actually able to effectivley look up which pre commitment was being spent by a new supply commit.
1 parent 5c0182f commit b33b4e0

11 files changed

+62
-9
lines changed

tapdb/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const (
2424
// daemon.
2525
//
2626
// NOTE: This MUST be updated when a new migration is added.
27-
LatestMigrationVersion = 43
27+
LatestMigrationVersion = 44
2828
)
2929

3030
// DatabaseBackend is an interface that contains all methods our different

tapdb/sqlc/assets.sql.go

Lines changed: 7 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
-- Remove the outpoint column and its index
2+
DROP INDEX IF EXISTS mint_anchor_uni_commitments_outpoint_idx;
3+
ALTER TABLE mint_anchor_uni_commitments DROP COLUMN outpoint;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-- Add outpoint field to mint_anchor_uni_commitments to track the exact UTXO
2+
-- This allows precise marking of spent pre-commitments using the transaction inputs
3+
ALTER TABLE mint_anchor_uni_commitments
4+
ADD COLUMN outpoint BLOB;
5+
6+
-- Create an index for efficient lookups by outpoint
7+
CREATE INDEX mint_anchor_uni_commitments_outpoint_idx
8+
ON mint_anchor_uni_commitments(outpoint)
9+
WHERE outpoint IS NOT NULL;

tapdb/sqlc/models.go

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/sqlc/querier.go

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tapdb/sqlc/queries/assets.sql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1073,16 +1073,17 @@ WITH target_batch AS (
10731073
WHERE keys.raw_key = @batch_key
10741074
)
10751075
INSERT INTO mint_anchor_uni_commitments (
1076-
batch_id, tx_output_index, taproot_internal_key_id, group_key, spent_by
1076+
batch_id, tx_output_index, taproot_internal_key_id, group_key, spent_by, outpoint
10771077
)
10781078
VALUES (
10791079
(SELECT batch_id FROM target_batch), @tx_output_index,
1080-
@taproot_internal_key_id, @group_key, sqlc.narg('spent_by')
1080+
@taproot_internal_key_id, @group_key, sqlc.narg('spent_by'), sqlc.narg('outpoint')
10811081
)
10821082
ON CONFLICT(batch_id, tx_output_index) DO UPDATE SET
10831083
-- The following fields are updated if a conflict occurs.
10841084
taproot_internal_key_id = EXCLUDED.taproot_internal_key_id,
1085-
group_key = EXCLUDED.group_key
1085+
group_key = EXCLUDED.group_key,
1086+
outpoint = EXCLUDED.outpoint
10861087
RETURNING id;
10871088

10881089
-- name: FetchMintAnchorUniCommitment :many

tapdb/sqlc/queries/supply_commit.sql

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ WHERE
172172
mac.group_key = @group_key AND
173173
(mac.spent_by IS NULL OR commit_txn.block_hash IS NULL);
174174

175+
-- name: MarkPreCommitmentSpentByOutpoint :exec
176+
-- Mark a specific pre-commitment output as spent by its outpoint.
177+
UPDATE mint_anchor_uni_commitments
178+
SET spent_by = @spent_by_commit_id
179+
WHERE outpoint = @outpoint
180+
AND spent_by IS NULL;
181+
175182
-- name: FetchSupplyCommit :one
176183
SELECT
177184
sc.commit_id,

tapdb/sqlc/schemas/generated_schema.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,11 @@ CREATE TABLE mint_anchor_uni_commitments (
637637
group_key BLOB
638638
, taproot_internal_key_id
639639
BIGINT REFERENCES internal_keys(key_id)
640-
NOT NULL, spent_by BIGINT REFERENCES supply_commitments(commit_id));
640+
NOT NULL, spent_by BIGINT REFERENCES supply_commitments(commit_id), outpoint BLOB);
641+
642+
CREATE INDEX mint_anchor_uni_commitments_outpoint_idx
643+
ON mint_anchor_uni_commitments(outpoint)
644+
WHERE outpoint IS NOT NULL;
641645

642646
CREATE UNIQUE INDEX mint_anchor_uni_commitments_unique
643647
ON mint_anchor_uni_commitments (batch_id, tx_output_index);

tapdb/sqlc/supply_commit.sql.go

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)