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 token owners to RPC and archive db #10989

Merged
merged 4 commits into from
May 17, 2022
Merged

Conversation

psteckler
Copy link
Member

@psteckler psteckler commented May 17, 2022

Add a field tokens_used to the Breadcrumb_added RPC message, a list of token id, owner pairs. Add the same field to precomputed blocks and extensional blocks.

The data in that list is used to populate a table of token owners in the archive processor, which is consulted when adding a token id to the archive db.

This change required additional code in extract_blocks to find the tokens used in each block. Tested by extracting the blocks from an archive db created with a local testnet, and then running archive_blocks on the resulting blocks.

(Note: added an empty token list to the precomputed block sample, in the expectation that these will be regenerated.)

Closes #10772
Closes #10793

@psteckler psteckler requested review from a team as code owners May 17, 2022 00:23
@psteckler psteckler added the ci-build-me Add this label to trigger a circle+buildkite build for this branch label May 17, 2022
Copy link
Member

@deepthiskumar deepthiskumar left a comment

Choose a reason for hiding this comment

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

Could you add a zkapp transaction with non-default tokens to the database used in the replayer test?

@@ -51,6 +51,18 @@ module Public_key = struct
public_key
end

module Token_owners = struct
(* hash table of token owners, updated for each block *)
let owner_tbl : Account_id.t Token_id.Table.t = Token_id.Table.create ()
Copy link
Member

Choose a reason for hiding this comment

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

How would this work when the archive process restarts? Should we initialize the table with the tokens from the database?

Copy link
Member Author

@psteckler psteckler May 17, 2022

Choose a reason for hiding this comment

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

You're only adding tokens to the db when there's a transaction in a block that mentions them. In that case, those tokens will be in the tokens_used list, and hence, in this table.

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually, tokens section in zkapps integration test should be sufficient, right? since it exercises the replayer flow now

We have to add that, right?

let open Deferred.Result.Let_syntax in
let value = Token_id.(to_string token_id) in
match owner with
match Token_owners.find_owner token_id with
Copy link
Member

Choose a reason for hiding this comment

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

Not finding an owner doesn't mean this is default token, right? (See the comment in Token_owners module definition)

Copy link
Member Author

@psteckler psteckler May 17, 2022

Choose a reason for hiding this comment

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

There should not be any tokens other than the default that have no owner, unless there's a bug, hence the asserts.

Copy link
Member Author

Choose a reason for hiding this comment

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

It might be safer to have the table contain options, so that a lookup should never fail.

let token_id = acct.token_id in
let owner = Mina_ledger.Ledger.token_owner ledger token_id in
(token_id, owner) )
|> List.dedup_and_sort
Copy link
Member

Choose a reason for hiding this comment

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

Nit: it will usually be more efficient to dedup_and_sort first, then look up the token_owner

Copy link
Member Author

@psteckler psteckler May 17, 2022

Choose a reason for hiding this comment

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

The accounts_accessed are all already distinct, but the tokens they use are not.

Just realized what you were trying to say here. I will push a commit with a fix.

Copy link
Member

Choose a reason for hiding this comment

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

Indeed, I meant

  • get the tokens from the account IDs
  • sort the tokens
  • hit the ledger to find out the token owners.

@psteckler
Copy link
Member Author

Could you add a zkapp transaction with non-default tokens to the database used in the replayer test?

Yes, I can do that, but I think it's for a separate PR.

@deepthiskumar
Copy link
Member

deepthiskumar commented May 17, 2022

Yes, I can do that, but I think it's for a separate PR.

a follow up PR? (so that this code change is tested before we make the next qa-net release)

@deepthiskumar
Copy link
Member

deepthiskumar commented May 17, 2022

Yes, I can do that, but I think it's for a separate PR.

a follow up PR? (so that this code change is tested before we make the next qa-net release)

Actually, tokens section in zkapps integration test should be sufficient, right? since it exercises the replayer flow now

@nholland94 nholland94 merged commit eae8d34 into develop May 17, 2022
@nholland94 nholland94 deleted the feature/token-owners-in-db branch May 17, 2022 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci-build-me Add this label to trigger a circle+buildkite build for this branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[zkApps Protocol] support tokens in archive node Add tokens_created to archive RPC and persisted blocks
5 participants