-
Notifications
You must be signed in to change notification settings - Fork 79
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
[EI-468] Create v1 migration views #385
Conversation
57447fb
to
4eeb4f5
Compare
rust/processor/migrations/2024-05-22-200847_add_v1_migration_views/up.sql
Outdated
Show resolved
Hide resolved
rust/processor/migrations/2024-05-22-200847_add_v1_migration_views/up.sql
Outdated
Show resolved
Hide resolved
rust/processor/migrations/2024-05-22-200847_add_v1_migration_views/up.sql
Show resolved
Hide resolved
TRUE AS maximum_mutable, | ||
TRUE AS uri_mutable, | ||
TRUE AS description_mutable, | ||
TRUE AS properties_mutable, | ||
TRUE AS royalty_mutable, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not always TRUE
SELECT
maximum_mutable,
uri_mutable,
description_mutable,
properties_mutable,
royalty_mutable,
COUNT(1)
FROM current_token_datas
GROUP BY 1,2,3,4,5
ORDER BY 1,2,3,4,5
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bowenyang007 validated that most of these are true, so it's fine to hardcode it to avoid having to migrate the v1 logic over to the v2 processor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are supposed to be used by marketplaces to indicate which fields are non modifiable. however basically everyone just used one minting contract that sets all of these to true so majority of these ended up being true. and nobody seems to care about these.
my thought is that we can remove them and nothing would happen since I haven’t seen any UI that exposes these. If someone ends up wanting them we could create a new table altogether (similar to royalty and other metadata that aren’t critical).
Field is not nullable, previously these could have different bool values
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So 2 options here:
- make these nullable and set to null. this changes the schema and could cause some compatibility issues
- keep as is.
@ying-w do you prefer one or the other?
rust/processor/migrations/2024-05-22-200847_add_v1_migration_views/up.sql
Outdated
Show resolved
Hide resolved
rust/processor/migrations/2024-05-22-200847_add_v1_migration_views/up.sql
Outdated
Show resolved
Hide resolved
rust/processor/migrations/2024-05-22-200847_add_v1_migration_views/up.sql
Outdated
Show resolved
Hide resolved
rust/processor/migrations/2024-05-22-200847_add_v1_migration_views/up.sql
Outdated
Show resolved
Hide resolved
transaction_version, | ||
owner_address, | ||
-- this is mainly for hashing the coin type for primary key | ||
encode(sha256(asset_type::bytea), 'hex') as coin_type_hash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we actually have sha256 support enabled in alloy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the intention to use this as a join? Because if so need to add this as an index on the underlying table
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I ran this in dbeaver and it worked so it seems like it's supported. Also I forgot to add a migration view for coin_infos, which is the only table this could join with. Yes we should add indexes on the underlying tables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
a few small concerns, but otherwise lgtm
Need to add coin_infos |
amount, | ||
table_type_v1 AS table_type, | ||
tov.inserted_at, | ||
tdv.collection_id AS collection_data_id_hash, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
values are different, collection_id != collection_data_id_hash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you give an example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
similar to coins, logic would be encode( sha256( (collection_creator_address || '::' || token_name)::bytea ), 'hex')
from here
hash(f"{standardize_address(self.creator)}::{self.name}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The processing code does the hash already for v1 collections and tokens
aptos-indexer-processors/rust/processor/src/models/token_v2_models/v2_collections.rs
Line 264 in 48d7794
let collection_id = collection_id_struct.to_id(); |
So basically everything that's v1 in tdv
is already hashed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just realized that, so just need ltrim
JOIN collections_v2 cv | ||
ON tdv.collection_id = cv.collection_id AND tdv.transaction_version = cv.transaction_version |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i dont think this works, token_activities_v2 has new entries when tokens have activities whereas collections_v2 has new entries when collection properties change
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i guess the best we can do is joining on the current_ tables
royalty_points_numerator, | ||
royalty_points_denominator, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to join on new royalty tables
CREATE OR REPLACE VIEW legacy_migration_v1.coin_activities AS | ||
SElECT | ||
transaction_version, | ||
owner_address as event_account_address, | ||
-- these two below are mildly concerning | ||
0 as event_creation_number, | ||
0 as event_sequence_number, | ||
owner_address, | ||
asset_type AS coin_type, | ||
amount, | ||
"type" AS activity_type, | ||
is_gas_fee, | ||
is_transaction_success, | ||
entry_function_id_str, | ||
block_height, | ||
transaction_timestamp, | ||
inserted_at, | ||
event_index, | ||
gas_fee_payer_address, | ||
storage_refund_amount, | ||
FROM public.fungible_asset_activities | ||
WHERE token_standard = 'v1' | ||
; | ||
CREATE INDEX lm1_ca_ct_a_index ON public.fungible_asset_activities USING btree (asset_type, amount) | ||
CREATE INDEX lm1_ca_ct_at_a_index ON public.fungible_asset_activities USING btree (asset_type, "type", amount) | ||
CREATE INDEX lm1_ca_oa_ct_at_index ON public.fungible_asset_activities USING btree (owner_address, asset_type, "type", amount) | ||
CREATE INDEX lm1_ca_oa_igf_index ON public.fungible_asset_activities USING btree (owner_address, is_gas_fee) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
have we tested any of this in terms of performance?
CREATE INDEX lm1_ca_ct_a_index ON public.fungible_asset_activities USING btree (asset_type, amount) | ||
CREATE INDEX lm1_ca_ct_at_a_index ON public.fungible_asset_activities USING btree (asset_type, "type", amount) | ||
CREATE INDEX lm1_ca_oa_ct_at_index ON public.fungible_asset_activities USING btree (owner_address, asset_type, "type", amount) | ||
CREATE INDEX lm1_ca_oa_igf_index ON public.fungible_asset_activities USING btree (owner_address, is_gas_fee) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@bowenyang007 this is where it's failing
1ec4f70
to
30c9263
Compare
8b38773
to
bbea445
Compare
27564c8
to
f595aba
Compare
@@ -52,11 +50,26 @@ SELECT transaction_version, | |||
inserted_at | |||
FROM public.fungible_asset_balances | |||
WHERE token_standard = 'v1'; | |||
-- replace `coin_infos` with `fungible_asset_metadata` | |||
CREATE OR REPLACE VIEW legacy_migration_v1.coin_infos AS | |||
SELECT encode(sha256(asset_type::bytea), 'hex'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need to rename this? as coin_type_hash
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes! Good catch.
cd00178
to
445628a
Compare
Description
As part of the v1 table deprecation, replace the v1 tables with views using the v2 tables. This will give the ecosystem a migration window to migrate their queries to the v2 tables and reduces ecosystem impact.
Test plan
Ran the SQL locally