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

Add objects processor #215

Merged
merged 6 commits into from
Jan 17, 2024
Merged

Add objects processor #215

merged 6 commits into from
Jan 17, 2024

Conversation

rtso
Copy link
Collaborator

@rtso rtso commented Dec 8, 2023

Description

  • Move objects and current_objects parsing into its own objects processor
  • Add 2 new columns (is_token, is_fungible_asset) which will be used in token_v2_processor and fungible_asset_processor to check if an object is token or fungible asset

Backfill

Given this splits out the objects processor we need to start the new processor from when objects were created. No need to backfill default_processor though.

  • Testnet: 469526272
  • Mainnet: 144201952

Testing

object is token
Testnet version 528464455
Screenshot 2023-12-08 at 11 52 35 AM
Screenshot 2023-12-08 at 11 52 28 AM

object is fungible asset
Testnet version 802980551
Screenshot 2023-12-08 at 11 54 07 AM
Screenshot 2023-12-08 at 11 53 56 AM

object is both token and fungible asset
Testnet version 617679498
Screenshot 2023-12-08 at 11 55 29 AM
Screenshot 2023-12-08 at 11 55 18 AM

@rtso rtso force-pushed the rtso/object-processor branch from e65816e to 508cd45 Compare December 8, 2023 16:56
@rtso rtso requested review from banool, bowenyang007 and a team December 8, 2023 16:56
@rtso rtso marked this pull request as ready for review December 8, 2023 16:56
@rtso rtso force-pushed the rtso/object-processor branch 4 times, most recently from b6afe39 to 00f7a4f Compare December 8, 2023 17:37
Comment on lines 29 to 38
/// Tracks all object related metadata in a hashmap for quick access (keyed on address of the object)
pub type ObjectAggregatedDataMapping = HashMap<CurrentObjectPK, ObjectAggregatedData>;

/// This contains metadata for the object
#[derive(Serialize, Deserialize, Debug, Clone)]
pub struct ObjectAggregatedData {
pub fungible_asset_store: Option<FungibleAssetStore>,
pub token: Option<TokenV2>,
}

Copy link
Collaborator

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I think it's better to create a new struct specifically for objects. FungibleAssetAggregatedData expects non-null values which don't make sense with how objects are being parsed in objects processor. We also potentially want to add more things to ObjectAggregatedData in the future.

Copy link
Collaborator

Choose a reason for hiding this comment

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

FungibleAssetAggregatedData is designed to do what you're saying. Basically I realized that we need a lighter version than the token one so created that one. The only non null value there is the object itself which you definitely need for objects.

If you want to push for this as the minimum object metadata holder then I'd suggest rewriting the existing code to use what you're doing here. Not great to duplicate the same mechanism multiple times. We're already duplicating some of this across token and fungible assets.

Copy link
Collaborator

Choose a reason for hiding this comment

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

What could be also cleaner if you had guaranteed object core and persist that mapping across transactions. And then when you see object core again you don't even need to parse it. You can just grab it from the mapping.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

What if one of the struct gets deleted from the object. Can that happen?

@rtso rtso force-pushed the rtso/object-processor branch from a00fd21 to 6c5a9c6 Compare December 12, 2023 00:14
@rtso rtso requested a review from a team December 12, 2023 16:41
conn,
diesel::insert_into(schema::objects::table)
.values(&items_to_insert[start_ind..end_ind])
.on_conflict((transaction_version, write_set_change_index))
Copy link
Contributor

Choose a reason for hiding this comment

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

consider do_nothing for a transaction + event_indexer, this insertion is unlikely to change.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

for backfill i need do_update but after backfill we should change it back to do_nothing

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes but you don't need to change all the fields. Just the ones that you're backfilling.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Oh actually you also needt o change inserted_at time otherwise it doesn't update.

Copy link
Collaborator

@bowenyang007 bowenyang007 left a comment

Choose a reason for hiding this comment

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

Overall looking great! Thanks for refactoring. Just a couple of things to change.

@rtso rtso force-pushed the rtso/object-processor branch from 6c5a9c6 to 85f9946 Compare December 14, 2023 00:31
@rtso rtso force-pushed the rtso/object-processor branch from 85f9946 to 72460e9 Compare January 6, 2024 19:28
@bowenyang007 bowenyang007 force-pushed the rtso/object-processor branch from a6b854a to 8e32c3c Compare January 12, 2024 00:14
@bowenyang007 bowenyang007 changed the base branch from main to fix_payload_type January 12, 2024 00:15
Comment on lines 137 to 140
.set((
is_token.eq(excluded(is_token)),
is_fungible_asset.eq(excluded(is_fungible_asset)),
)),
Copy link
Collaborator

Choose a reason for hiding this comment

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

you do need to set all fields here.

@bowenyang007 bowenyang007 merged this pull request into fix_payload_type Jan 17, 2024
4 checks passed
@bowenyang007 bowenyang007 deleted the rtso/object-processor branch January 17, 2024 04:33
bowenyang007 added a commit that referenced this pull request Jan 17, 2024
* Add objects processor

* Use ObjectAggregatedDataMapping in fungible asset and token v2 processors

* Respond to comments

* Update is_address_fungible_token check since data mapping type changed

* rebase

* add proper on conflict set

---------

Co-authored-by: bowenyang007 <[email protected]>
bowenyang007 added a commit that referenced this pull request Jan 17, 2024
* Add payload type to default processor

* lint

* Add objects processor (#215)

* Add objects processor

* Use ObjectAggregatedDataMapping in fungible asset and token v2 processors

* Respond to comments

* Update is_address_fungible_token check since data mapping type changed

* rebase

* add proper on conflict set

---------

Co-authored-by: bowenyang007 <[email protected]>

---------

Co-authored-by: Renee Tso <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants