Skip to content
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

Asset metadata overwrite fix #370

Merged
merged 2 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions itest/addrs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ func testAddresses(t *harnessTest) {

// Make sure we have imported and finalized all proofs.
assertNonInteractiveRecvComplete(t, secondTapd, idx+1)

// Make sure the asset meta is also fetched correctly.
assetResp, err := secondTapd.FetchAssetMeta(
ctxt, &taprpc.FetchAssetMetaRequest{
Asset: &taprpc.FetchAssetMetaRequest_AssetId{
AssetId: a.AssetGenesis.AssetId,
},
},
)
require.NoError(t.t, err)
require.Equal(t.t, a.AssetGenesis.MetaHash, assetResp.MetaHash)
}

// Now sanity check that we can actually list the transfer.
Expand Down
7 changes: 4 additions & 3 deletions tapdb/sqlc/assets.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tapdb/sqlc/mssmt.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions tapdb/sqlc/queries/assets.sql
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ INSERT INTO asset_proofs (
) VALUES (
(SELECT asset_id FROM target_asset), @proof_file
) ON CONFLICT (asset_id)
-- This is not a NOP, update the proof file in case it wasn't set before.
-- This is not a NOP, we always overwrite the proof with the new one.
DO UPDATE SET proof_file = EXCLUDED.proof_file;

-- name: FetchAssetProofs :many
Expand Down Expand Up @@ -718,8 +718,9 @@ INSERT INTO assets_meta (
-- In this case, we may be inserting the data+type for an existing blob. So
-- we'll set both of those values. At this layer we assume the meta hash
-- has been validated elsewhere.
DO UPDATE SET meta_data_blob = EXCLUDED.meta_data_blob,
meta_data_type = EXCLUDED.meta_data_type
DO UPDATE SET meta_data_blob = COALESCE(EXCLUDED.meta_data_blob, assets_meta.meta_data_blob),
meta_data_type = COALESCE(EXCLUDED.meta_data_type, assets_meta.meta_data_type)

RETURNING meta_id;

-- name: FetchAssetMeta :one
Expand Down
1 change: 1 addition & 0 deletions tapdb/sqlc/queries/mssmt.sql
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ INSERT INTO mssmt_roots (
) VALUES (
$1, $2
) ON CONFLICT (namespace)
-- Not a NOP, we always overwrite the root hash.
DO UPDATE SET root_hash = EXCLUDED.root_hash;

-- name: FetchAllNodes :many
Expand Down