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?

2 Answers 2

6

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.

4
  • 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, 2019 at 4:29
  • @Frank how to know that "tz1ivoFEvbfbUNav5FwLvmxzMGcNXWxY9qTD" is the baker ? 2. Why deposits , fees and rewards all are in negative. Could you please help me understand ?
    – Debasish22
    Feb 23, 2020 at 19:53
  • 1.That baker address is just an example, but this section only include bakers. 2. "Notice that those freezer operations are negative values and they imply that these balances are subtracted from freezer." Freezer is what the chain is storing, so we are making a negative balance change for the freezer and a positive balance change as the reward. It's zero sum.
    – Frank
    Feb 23, 2020 at 22:17
  • @Frank I am still confused with the freezer stuff. I have seen few samples where deposit is positive and reward is also positive. In which scenario this is possible for this blochHash we can find the deposit and reward as positive
    – Debasish22
    Feb 24, 2020 at 18:59
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 don't 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. That's consensus.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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