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

[#3992][Events] Extract amount field from coins into TransferObject event #4328

Merged
merged 5 commits into from
Sep 2, 2022

Conversation

velvia
Copy link
Contributor

@velvia velvia commented Aug 26, 2022

Sui implementation for #3992

This adds an amount field to the TransferObject event plus implementation in the EventStore and relevant data structures. It is currently stored in the JSON field alongside transfer type and object version.

Currently (in the PR) there are three paths for the creation of a TransferObject event:

  1. For TransferObject transactions, in execution_engine::transfer_object(), at the end we call log_event to create the event
  2. For TransferSui transactions, I added a log_event() call at the end of execution_engine::transfer_sui() with the amount
  3. For MoveCall transactions, in adapter.rs log_event() is called for various kinds of transfers, as well as new object creations.

This PR will deserialize the Move object for paths 1 and 3 to get the amount. Thus, any coin that is transferred will have the amount recorded in the TransferObject event now.

@velvia
Copy link
Contributor Author

velvia commented Aug 29, 2022

@666lcz @longbowlu @patrickkuo I have now added amounts to events for transfers of any coins.

version: object.version(),
type_: TransferType::Coin, // Should this be a separate type, like SuiCoin?
amount: transferred,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

The PR description says you're just adding a field, but it looks like you're logging a whole new event. Is it correct that this was never emitted before?

This comment is a bit beyond the scope of this PR, but I also have some concerns about the format of this event - most of this data is redundant with existing transaction data, yet we are adding it all to the core data store for what may be one of the most common types of events. Can't we synthesize this data later, not on the validators, when we are emitting events?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated the PR title. Yes an event was not emitted before for TransferSui transactions, that was an oversight.

most of this data is redundant with existing transaction data, yet we are adding it all to the core data store for what may be one of the most common types of events

So a couple of things here.... there were a bunch of discussions about the best place for this to go, some of it might be in the issue linked in the description, but the consensus was that we would put it in an event. Yes, the object version is elsewhere in the effects, but not the transfer type and the amount. The transfer type cannot be deduced from effects for Move transactions, for example, and the amount is hidden in the Coin object layout itself. The destination of the transfer also is not directly derivable, though you could get it out of looking up the new object owner.

I agree that some of this data is redundant, and could be derived later, but this is really a larger discussion. One consideration is that it is really important that events be part of the historical data record -- partners and users will want to look up events, especially this amount field -- and if the effects from the validator do not include the full events, then we have a discrepancy between the state of the validator and full nodes. This discrepancy makes coming up with a full set of data for a checkpoint much more complicated.

I would not worry too much about redundant data and data storage costs right now. The long term data storage will probably look nothing like it does today.

@velvia velvia changed the title [#3992][Events] Add amount field to TransferObject event [#3992][Events] Extract amount field from coins into TransferObject event Aug 30, 2022
Copy link
Contributor

@patrickkuo patrickkuo left a comment

Choose a reason for hiding this comment

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

LGTM!

cc @666lcz , do we need changes in TS-SDK?

recipient: Owner::AddressOwner(recipient),
object_id: object.id(),
version: object.version(),
type_: TransferType::Coin, // Should this be a separate type, like SuiCoin?
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you resolve this comment? Not sure if I understand this question correctly, but this event is emitted for non-sui coins(e.g., coin::Coin) right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh. Maybe it's a good question for you. I can just remove the comment, the question was whether we need a different transfer type for Sui coins vs non-Sui coins. That code is in transfer_sui() which is I believe only for Sui coins?
So the question is do we need a separate transfer type for Sui coins vs non Sui 'coin::Coin` types. For now I just leave it the same.

Copy link
Contributor

@666lcz 666lcz left a comment

Choose a reason for hiding this comment

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

cc @666lcz , do we need changes in TS-SDK?

This is not a breaking change, so please feel free to land as it. The change on the ts side is just add a one-line changeamount: number | null to

type: string; // TODO - better type
. @velvia feel free to include this change in this PR, otherwise I am also happy to make the change in a separate PR.

@velvia
Copy link
Contributor Author

velvia commented Sep 1, 2022

@666lcz thanks, I'll try including that one line change while I'm fixing some other tests.

Copy link
Contributor

@lxfind lxfind left a comment

Choose a reason for hiding this comment

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

Thanks!

@velvia velvia merged commit 32b96ec into MystenLabs:main Sep 2, 2022
@velvia velvia deleted the ec/add-event-transfer-amount branch September 2, 2022 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants