6

How do baking rewards appear on the chain when they are credited to the baker? Is it a 'transaction' operation? How do I go about identifying them?

5

The rewards happen as part of the protocol and it's all on chain. But they are not a "transaction" in the normal sense of the word, as usually a transaction requires some user intervention. But there is fundamental movements of funds from the "freezer" to the delegates. Conceptually, the freezer temporarily holds all the bonds and rewards for baking and endorsing.

To find this information on chain, we have to look at the very last block of the cycle we'd expect the reward.

blockNumForRewards = (rewardedCycleNum + 6) * numOfBlocksInCycle

For example, for cycle 93, the rewards for cycle 93 gets unlocked at the last block of cycle 98, so we need to look at block number (93 + 6) * 4096 = 405,504.

After we knowing the block number, We can query for the block with our node by getting the hash from a block explorer like tzscan. In this case, BLdha4dMeWYxYkuP46eCgYwsgBYiKPNFLvgiu5NqgdxPLhkgzUf is our block hash:

/chains/main/blocks/BLdha4dMeWYxYkuP46eCgYwsgBYiKPNFLvgiu5NqgdxPLhkgzUf

Obviously there is a lot of information in here, but let's focus on the path that handles the balance changes, specifically metadata > balance_updates. Example:

{
  "protocol": "PsddFKi32cMJ2qPjf43Qv5GDWLDPZb3T3bF6fLKiF5HtvHNU7aP",
  "chain_id": "NetXdQprcVkpaWU",
  "hash": "BLdha4dMeWYxYkuP46eCgYwsgBYiKPNFLvgiu5NqgdxPLhkgzUf",
  "metadata": {
    ...
    "balance_updates": [
      // this is what we care about
    ]
  }
  ...
}

This portion of the block is the balance updates that retains to what the protocol needs to apply regardless of the user interventions. In a lot of the blocks, this portion will just include the current block baker with its locked rewards and bonds. In the last block of the cycle, balance_updates also includes all the rewards and bonds unlocks for every baker that participated in cycle 93.

Anyhow, let's dig into the specifics of one baker to understand further. For illustration, I've filtered out transactions for one particular baker tz1ivoFE...TD.

    "balance_updates": [
      ...
      {
        "kind": "freezer",
        "category": "deposits",
        "delegate": "tz1ivoFEvbfbUNav5FwLvmxzMGcNXWxY9qTD",
        "level": 93,
        "change": "-10368000000"
      },
      {
        "kind": "freezer",
        "category": "fees",
        "delegate": "tz1ivoFEvbfbUNav5FwLvmxzMGcNXWxY9qTD",
        "level": 93,
        "change": "-9362"
      },
      {
        "kind": "freezer",
        "category": "rewards",
        "delegate": "tz1ivoFEvbfbUNav5FwLvmxzMGcNXWxY9qTD",
        "level": 93,
        "change": "-321000000"
      },
      {
        "kind": "contract",
        "contract": "tz1ivoFEvbfbUNav5FwLvmxzMGcNXWxY9qTD",
        "change": "10689009362"
      },
      ...

Inside of balance_updates array, it will include every "transaction" that needs to be adjusted for all these addresses including the "freezer". Each transaction also gives some clues on what they are for.

The above is pretty typical what we'll see per baker. There are 3 "freezer" related transactions and one "contract". The "freezer" transaction are different by their category (deposits, fees and rewards). The categories are pretty self explanatory. Just in case you are wonder, deposits and rewards will include both baking and endorsements bonds and rewards. Notice that those freezer operations are negative values and they imply that these balances are subtracted from freezer.

The "contract" transaction is what changes the balance to the baker in question. This is pretty similar to a user initiated transaction. If we add up the 3 freezer category's balances, they would add up to the change balance for the baker.

  • 1
    This is the correct answer. My answer answered the question of how baker credit/reward their delegators, not how a baker is rewarded via the protocol itself. To remove any confusion, I've deleted my answer. – lostdorje Apr 23 at 4:29
0

The "short version" answer is that this is accomplished through consensus, which is an extremely important concept in blockchains that are used for cryptocurrency. Unfortunately many people just dont really understand it; in this aspect essentially the term "consensus" boils down to:

(and this really is a very simplified description here, not taking into account freezing rewards or deposits, etc) The code for the Tezos protocol dictates that when an account bakes a block, that account's balance simply goes up by ꜩ16. Since everyone is running the same protocol, everyone agrees that when an account bakes a block, that account's balance goes up by ꜩ16. Thats consensus.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.