From d1e6fb5dc8cb219ef6ba25e1d7b217337440fbe6 Mon Sep 17 00:00:00 2001 From: Oliver Gugger Date: Tue, 6 Feb 2024 17:06:22 +0100 Subject: [PATCH 1/2] tapdb: fix migration 15 We assumed nobody would have multiple witness entries at this point, as they could only be produced when using the vPSBT API. But a user reported problems when running the migration 15 which indicates they indeed had multiple witnesses per asset (possibly due to multiple imports of the same proof which would be a whole separate issue and likely needs to be fixed in their DB manually). This commit makes sure we insert a non-duplicate default value (we just pick the witness ID as we just care about the order not the actual value). --- .../migrations/000015_asset_witnesses.up.sql | 13 ++++++++--- .../migrations_test_00015_dummy_data.sql | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 tapdb/testdata/migrations_test_00015_dummy_data.sql diff --git a/tapdb/sqlc/migrations/000015_asset_witnesses.up.sql b/tapdb/sqlc/migrations/000015_asset_witnesses.up.sql index 4cb82f0c4..200987ecb 100644 --- a/tapdb/sqlc/migrations/000015_asset_witnesses.up.sql +++ b/tapdb/sqlc/migrations/000015_asset_witnesses.up.sql @@ -1,7 +1,14 @@ -- The witness index indicates the order of the witness in the list of witnesses --- for a given asset. We didn't really support more than one witness before, so --- the default value of 0 should be fine for all existing assets. -ALTER TABLE asset_witnesses ADD COLUMN witness_index INTEGER NOT NULL DEFAULT 0; +-- for a given asset. We'll be inserting an actual value in the next query, so +-- we just start with -1. +ALTER TABLE asset_witnesses ADD COLUMN witness_index INTEGER NOT NULL DEFAULT -1; + +-- Update the witness index to be the same as the witness id. We'll use the +-- witness_index for sorting only, so setting the default to the witness_id is +-- just to make sure we preserve the current order of witnesses while also +-- satisfying the unique constraint we add below. +UPDATE asset_witnesses SET witness_index = CAST(witness_id AS INTEGER) + WHERE witness_index = -1; -- We need to be able to upsert witnesses, so we need a unique constraint on -- (asset_id, witness_index). diff --git a/tapdb/testdata/migrations_test_00015_dummy_data.sql b/tapdb/testdata/migrations_test_00015_dummy_data.sql new file mode 100644 index 000000000..3eaae0960 --- /dev/null +++ b/tapdb/testdata/migrations_test_00015_dummy_data.sql @@ -0,0 +1,22 @@ +-- This dummy data inserts a single asset that has two witness entries so we can +-- test the migration 15 that adds the witness_index column to the +-- asset_witnesses table. +INSERT INTO chain_txns VALUES(1,X'a1594fc379308b2a209f6d0bdb8602e9f87cf71fc232c69032b9a5fed28f9331',1980,X'02000000000101022cd51ca4d850c5f71ceedf7c50a08ff82d66612b22f631eac95e6b52cbbd2d0000000000ffffffff02e80300000000000022512018ac5a65a0d12e7846c89d24705e2697b1da14627978ba8db24bdbce21fc2aa85cd5f5050000000022512030263d67b4275144b2b00921d220a1311b9a4465fa656ba7d5754b421cb4308402483045022100fa32af97cab8a765dc347c3ff57b14f9810b6dbfc4d02727fb099d1ed875660602204cb66f3bbd92925707158b4aa67338c50a9ffddceb023875eb82b78b3967e007012102eb9cd2a22fd11c40823cb7b0f0fba4156138af69cf73c0644be54f4d46ba480700000000',441,X'4295613d85ccbc455159eb4ddd1e266ca10041d3c75726286b7dfeb3132c9c4f',1); + +INSERT INTO genesis_points VALUES(1,X'022cd51ca4d850c5f71ceedf7c50a08ff82d66612b22f631eac95e6b52cbbd2d00000000',1); + +INSERT INTO assets_meta VALUES(1,X'2b990b7adb1faf51ccb9b1c73bc5e73926db39cdec8906d4fd3c6c423a3c9821',X'736f6d65206d65746164617461',0); + +INSERT INTO genesis_assets VALUES(1,X'add7d0d7cc37e58a7c0d8ad40b6904050d2baa25a1829f00689c4b27b524dd04','itestbuxx-collectible',1,0,1,1); + +INSERT INTO internal_keys VALUES(1,X'02827d74858d152da1fae12010ad8d3c46b595c2d4480512a6575925424617124f',212,0); +INSERT INTO internal_keys VALUES(2,X'03efbcf2878876bae81ca9a7f6476764d2da38d565b9fb2b691e7bb22fd99f9e5e',212,2); + +INSERT INTO managed_utxos VALUES(1,X'a1594fc379308b2a209f6d0bdb8602e9f87cf71fc232c69032b9a5fed28f933100000000',1000,1,X'1dd3e2cf0bbbee32832c4deb57bbae58779fa599be0b8eb1f61e8c624157e2fa',NULL,X'1dd3e2cf0bbbee32832c4deb57bbae58779fa599be0b8eb1f61e8c624157e2fa',1,NULL,NULL); + +INSERT INTO script_keys VALUES(1,2,X'029c571fffcac1a1a7cd3372bd202ad8562f28e48b90f8a4eb714eca062f576ee6',NULL); + +INSERT INTO assets VALUES(1,1,1,1,NULL,0,1,0,0,NULL,NULL,1,false); + +INSERT INTO asset_witnesses VALUES(1,1,X'a1594fc379308b2a209f6d0bdb8602e9f87cf71fc232c69032b9a5fed28f933100000000',X'add7d0d7cc37e58a7c0d8ad40b6904050d2baa25a1829f00689c4b27b524dd04',X'02827d74858d152da1fae12010ad8d3c46b595c2d4480512a6575925424617124f',X'0101aa',NULL); +INSERT INTO asset_witnesses VALUES(2,1,X'a1594fc379308b2a209f6d0bdb8602e9f87cf71fc232c69032b9a5fed28f933101000000',X'add7d0d7cc37e58a7c0d8ad40b6904050d2baa25a1829f00689c4b27b524dd04',X'02827d74858d152da1fae12010ad8d3c46b595c2d4480512a6575925424617124f',X'0101bb',NULL); From 0b7aade53ffd772ead3820a253c73eac561d2c61 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Tue, 6 Feb 2024 14:42:21 -0800 Subject: [PATCH 2/2] build: bump version to v0.3.3 rc3 --- version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version.go b/version.go index 1d8b3002c..bc2f0d6a5 100644 --- a/version.go +++ b/version.go @@ -49,7 +49,7 @@ const ( // AppPreRelease MUST only contain characters from semanticAlphabet // per the semantic versioning spec. - AppPreRelease = "alpha.rc2" + AppPreRelease = "alpha.rc3" // defaultAgentName is the default name of the software that is added as // the first part of the user agent string.