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

Fix duplicate asset creation in itest #965

Merged
merged 7 commits into from
Jun 24, 2024
Merged

Conversation

guggero
Copy link
Member

@guggero guggero commented Jun 24, 2024

Fixes #691.

Depends on #954.

It turns out that in one of our itests (multi_address), because we do an address self-transfer, we sometimes created duplicate asset entries, if the timing was unfortunate.
Basically both the send logic (freighter) as well as the address receive logic (custodian) inserted the same asset (one materializing it from the transfer output, the other from the proof found in the DB).

@guggero guggero added this to the v0.4 milestone Jun 24, 2024
@guggero guggero requested review from gijswijs and jharveyb June 24, 2024 13:15
@guggero guggero self-assigned this Jun 24, 2024
@guggero guggero force-pushed the duplicate-asset-insert branch from bceae3b to dd8ba78 Compare June 24, 2024 14:08
Copy link
Contributor

@gijswijs gijswijs left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR touches ApplyPendingOutput which creates new assets. We still need to address Oli's comment about not reusing lock_time and relative_lock_time from the spent asset. See:

// TODO(guggero): This will need an update once we want
// to support full lock_time and relative_lock_time
// support.
templateID := spentAssetIDs[0]

Although not relevant for this specific PR, I wanted to raise it here for future reference.

tapdb/assets_common.go Outdated Show resolved Hide resolved
@guggero guggero force-pushed the duplicate-asset-insert branch from dd8ba78 to 16ae4dd Compare June 24, 2024 15:05
@guggero guggero requested a review from gijswijs June 24, 2024 15:17
@guggero guggero force-pushed the duplicate-asset-insert branch from 16ae4dd to 42a9d57 Compare June 24, 2024 15:41
@guggero guggero linked an issue Jun 24, 2024 that may be closed by this pull request
Base automatically changed from postgres-clobber to main June 24, 2024 15:53
@gijswijs
Copy link
Contributor

lgtm 🎉

Copy link
Contributor

@jharveyb jharveyb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, great catch 👍🏽

itest/addrs_test.go Show resolved Hide resolved
itest/psbt_test.go Show resolved Hide resolved
guggero added 7 commits June 24, 2024 20:58
Fixes #691 by adding a unique constraint that will actually work. The
assumption of the constraint is that there will never be an asset of the
same asset ID with the same script key in the same anchor transaction
output. This would be impossible anyway because the asset leaves would
collide within the asset-level MS-SMT tree.
So this unique key is safe to use as an upsert detection mechanism.
To make sure we don't insert duplicate assets, we turn all queries that
insert into the assets table into upserts.
The test that discovered the duplicate asset issue in the first place
would've shown the issue more clearly if we actually asserted the number
of asset UTXOs created.
We now add this assertion to make sure we only have the expected number
of assets in the asset table.
@guggero guggero force-pushed the duplicate-asset-insert branch from 42a9d57 to e6713c5 Compare June 24, 2024 19:01
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🦔

@Roasbeef Roasbeef merged commit b7117ea into main Jun 24, 2024
14 checks passed
@guggero guggero deleted the duplicate-asset-insert branch June 25, 2024 06:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

Fix assets SQL table unique constrinat
4 participants