Marigold
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Write
        • Owners
        • Signed-in users
        • Everyone
        Owners Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Help
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Write
Owners
  • Owners
  • Signed-in users
  • Everyone
Owners Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- tags: protocol --- # Ticket Balance Transparency [toc] ## Milestone https://gitlab.com/tezos/tezos/-/milestones/118 ## Scope and Design The goal of this project is to provide more transparency for indexers with regards to ticket ownership. More specifically, we propose to: 1. Add ticket ownership updates to transaction receipts 2. Provide an RPC for retrieving ticket ownership for originated contracts 3. Provide an RPC for retrieving the ticket balance of a specific ticket-token and account/rollup address (1) makes it easier for indexers to scan blocks and traverse the transaction receipts in order to update their ticket balance tables. (2) can be used on *originated contracts* to retrieve the current ticket balance for an originated contract. (3) can be used for checking balances for a specific ticket type and contracts, and also works for implicit accounts and rollup addresses. Once we have (1) and (2) it would be possible for indexers to reconstruct a "global ticket table" that keeps track of all ticket ownership (Note: let us know if this is not the case). This can be done by: 1. Calling the API from (2) to retrieve the current ticket ownership of all contracts. - This is only needs to be done once to bootstrap the global ticket table. - We only need the balance for contracts (and not implicit accounts) since implicit accounts cannot own tickets at this point (until [milestone/92](https://gitlab.com/tezos/tezos/-/milestones/92#tab-issues) is implemented). 2. Scanning the ticket balance updates in the receipts (from (1)) of all transactions to update the global ticket table. (3) is meant to only be used as a double-check/validate ticket ownership. ## 1. Ticket ownership updates to transaction receipts The idea is to make changes to ticket ownership part of the transaction (and internal origination) receipts, similar to balance updates. Ticket updates consist of a list of ticket-tokens and account updates. A ticket-token is the combination of a *ticketer* (the creator of the ticket) and ticket content (a value of some comparable Michelson type). For each ticket-token, we provide a list of account and balance update pairs, which we call ***ticket balance updates***, as in: ``` Updated tickets: Ticketer: KT1WuPpnvefGFqKMDHWHEXz7FpnTc5JfYCB7 Content type: string Content: "blue" Account updates: KT1LPnsqkZnddGUWZWFE5GtGBFtq6bT6EB7Q ... +3 ``` Ticket balance updates represent increase/decrease of tickets in the storage. They are included in receipts whenever: - A new ticket is minted and added to the contract's storage. - A new ticket is sent from another account and stored in the contract's storage. - An existing ticket is deleted from a contract’s storage. ### Examples #### Example 1: Contract mints a ticket and stores it Suppose that: - `tz_a` calls `KT_A`. - `KT_A` mints a ticket and stores it in it's storage. ``` tz_a -> KT_A (mints one ticket and stores it to storage) ``` A single ticket should be added to `KT_A`'s storage, which is reflected in the receipt as: ``` Manager signed operations: ... Transaction: From: tz_a To: KT_A Parameter: 0 ... Ticket updates: Ticketer: KT_A Content: "blue" Content type: string Account updates: KT_A ... +1 ``` #### Example 2: Contract reads one ticket from storage and sends it to another contract Suppose: - `tz_a` calls `KT_A`. - `KT_A` reads one ticket from storage and sends it to `KT_B`. - `KT_B` stores the received ticket. ``` one ticket -> KT_B / (stores ticket) tz_a -> KT_A (read one ticket) ``` One ticket is removed from `KT_A`'s storage by the initial transaction and one ticket is added to `KT_B`'s storage by the internal transaction: ``` Manager signed operations: ... Transaction: From: tz_a To: KT_A ... Ticket updates: Ticketer: KT_T Content: "blue" Content type: string Account updates: KT_A ... -1 Internal Transaction: ... From: KT_A To: KT_B Parameter: (Pair T (Pair "blue" 1)) ... Ticket updates: Ticketer: KT_T Content: "blue" Content type: string Account updates: KT_B ... +1 ``` #### Example 3: Contract mints a ticket and sends it to another contract Suppose: - `tz_a` calls `KT_A`. - `KT_A` mints a ticket and sends it to `KT_B`. - `KT_B` stores the ticket it received. ``` one ticket -> KT_B / (stores ticket) tz_a -> KT_A (mints one ticket) ``` This transaction will not change the tickets in storage of `KT_A` and will increase the ticket in storage `KT_B` by one: ``` Manager signed operations: ... Transaction: From: tz_a To: KT_A ... Internal Transaction: ... From: KT_A To: KT_B Parameter: (Pair T (Pair "blue" 1)) ... Ticket updates: Ticketer: KT_T Content: "blue" Content type: string Account updates: KT_B ... +1 ``` #### Example 4: Contract receives ticket from implicit account and stores it Suppose: - `tz_a` calls `KT_A` with one ticket in the parameter - This will be possible once [milestone/92](https://gitlab.com/tezos/tezos/-/milestones/92#tab-issues) is done. - `KT_A` stores the received ticket. ``` tz_a -(one ticket)-> KT_A (stores ticket in storage) ``` A ticket is removed from `tz_a` and added to the storage of `KT_A` via subsequent internal operation: ``` Manager signed operations: ... Transfer Ticket: From: tz_a ... Ticket updates: Ticketer: KT_T Content: "blue" Content type: string Account updates: tz_a ... -1 Internal Transaction: ... From: tz_a To: KT_A Parameter: (Pair T (Pair "blue" 1)) ... Ticket updates: Ticketer: KT_T Content: "blue" Content type: string Account updates: KT_A ... +1 ``` #### Example 5: A more complex case Suppose: - `tz_a` sends one ticket to `KT_A` - `KT_A` reads one additional ticket from storage and sends one ticket each to `KT_B` and `KT_C`. - `KT_B` stores the ticket. - `KT_C` does not store the ticket (i.e. throws it away) ``` transfer blue ticket -> KT_B / (stores ticket in storage) tz_a -(one ticket)-> KT_A (read one ticket) \ transfer blue ticket -> KT_C (does not store ticket in storage) ``` The resulting receipt will look like: ``` Manager signed operations: ... Transaction: From: tz_a To: KT_A Parameter: 0 ... Ticket updates: Ticketer: KT_T Content: "blue" Content type: string Account updates: tz_a ... -1 KT_A ... -1 Internal operations: Internal Transaction: ... From: KT_A To: KT_B Parameter: (Pair KT_T (Pair "blue" 1)) Ticket updates: KT_B ... +1 Internal Transaction: ... From: KT_A To: KT_C Parameter: (Pair KT_T (Pair "blue" 1)) ... ...(no ticket updates)... ``` Note that you can get the net-ticket balance update of the a ticket for any transaction by adding up the corresponding `Ticket updates` in the receipts: ``` Account updates: tz_a ... -1 KT_A ... -1 KT_B ... +1 ``` For reference, here is what the full receipt would look like in JSON: ``` [ { "kind": "transaction", "source": tz_a, "destination": KT_A, .... "metadata": { "operation_result": { "status": "applied", "storage": [], "balance_updates": [...], "ticket_updates": [ { "ticketer": T "content": "blue", "content_type": "string", "account_updates": [ { "contract": tz_a "change": "-1" }, { "contract": KT_A "change": "-1" } ] } ], ... }, "internal_operation_results": [ { "kind": "transaction", "source": KT_A, "destination": KT_B, "parameters": { "entrypoint": "default", "value": { "prim": "Pair", "args": [ { "bytes": "01014fb3291ad73087c75cba9ed0885141c6412f7400" }, { "prim": "Pair", "args": [ { "string": "blue" }, { "int": "1" } ] } ] } }, "result": { "status": "applied", "balance_updates": [...], ... "ticket_updates": [{ "ticketer": T "content": "blue", "content_type": "string", "account_updates": [{ "contract": KT_B "change": "+1" }] }] } }, { "kind": "transaction", "source": A, "destination": C, "parameters": { "entrypoint": "default", "value": { "prim": "Pair", "args": [ { "bytes": "01014fb3291ad73087c75cba9ed0885141c6412f7400" }, { "prim": "Pair", "args": [ { "string": "blue" }, { "int": "1" } ] } ] } } } ] } } ] ``` ### Notes - No receipt is provided for the following scenarios: - A ticket is minted but not saved. - Two tickets existing in a contract’s storage are joined together and saved in the storage. - One ticket existing in a contract’s storage is split and both tickets are saved. - We will support receipts for all combinations of transactions between: - Implicit accounts - Originated accounts - Rollups (SCORU and TORU) ### Alternative solution An alternative way of displaying the ticket updates is to have a single net-balance update at the top level of the receipt. For the "Example 5" it would look like: ``` Manager signed operations: ... Ticket updates: Ticketer: KT_T Content: "blue" Content type: string Account updates: tz_a ... -1 KT_A ... -1 KT_B ... +1 Transaction: From: tz_a To: KT_A Parameter: 0 ... Internal operations: Internal Transaction: ... From: KT_A To: KT_B Parameter: (Pair KT_T (Pair "blue" 1)) ... Internal Transaction: ... From: KT_A To: KT_C Parameter: (Pair KT_T (Pair "blue" 1)) ... ``` ## 2. RPC for retrieving ticket ownership for originated contracts All tickets owned by originated contracts exist in the respective contract’s storage. We can provide an RPC that scans the contract storage for tickets and returns a list of ticket balances. The API will look like this: ``` tezos-client rpc get /chains/main/blocks/genesis/context/contracts/<contract_id>/ticket_balance ``` For example: ```ocaml tezos-client rpc get /chains/main/blocks/genesis/context/contracts/KT1WuPpnvefGFqKMDHWHEXz7FpnTc5JfYCB7/ticket_balance ``` Would return a breakdown of the tickets owned by `KT1WuPpnvefGFqKMDHWHEXz7FpnTc5JfYCB7` like this: ```json { "ticket_balance": [ { "ticketer": "KT1WuPpnvefGFqKMDHWHEXz7FpnTc5JfYCB7", "content": "blue", "content_type": "string", "balance": 7 }, { "ticketer": "KT1WvzYHCNBvDSdwafTHv7nJ1dWmZ8GCYuuC", "content": "red", "content_type": "string", "balance": 2 } ] } ``` ## 3. RPC for the ticket balance of a ticket-token and account Implicit accounts and rollup addresses may hold tickets but the tickets are not contained in any storage why it is not possible to retrieve them by using the RPC above. Ticket ownership is tracked by the protocol as a table that maps a triple of `owner x ticketer x content` to balance. However, the keys are hashed so it’s also not possible to iterate over the table and collect all ticket for a given contract. Instead what we can do is to provide an RPC that returns the balance of specific combination of `owner x ticketer x content`, by looking up the balance from the ticket balance table in the context. This RPC would need to receive four things: 1. The address of the contract or rollup that we target 2. The ticketer of the ticket-token we are interested in 3. The content of the ticket-token we are interested in 4. The type of the content we are interested in (that is beacuse The API will be a`POST` endpoint which can be called like: ```ocaml tezos-client rpc post /chains/main/blocks/genesis/context/contracts/tz1KqTpEZ7Yob7QbPE4Hy4Wo8fHG8LhKxZSx/ticket_balance_with/ ``` With a request body that looks like: ``` { "ticketer": "KT1WuPpnvefGFqKMDHWHEXz7FpnTc5JfYCB7", "content_type": "string", "content": "blue", } ``` And would return a single number representing the amount of ticket-tokens with the given ticketer and content held by the contract: ``` 3 ```

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully