LiskArchive / lisk-sdk

🔩 Lisk software development kit
https://lisk.com
Apache License 2.0
2.72k stars 456 forks source link

Wrong block reward calculation #8502

Closed przemerr closed 1 year ago

przemerr commented 1 year ago

Expected behavior

The block rewards should be calculated correctly for every validator

Actual behavior

Currently on betanet the amount of validators is below 103, I believe because of that reason, the dynamic reward module is miscalculating the block rewards for every delegate, it assigns the expected ~500 LSK per round proportionally to the validators, but since there is less than 103 validator, they mint the blocks multiple times in a round, making the inflation higher than expected

Steps to reproduce

Check the current block rewards on the betanet and the inflation.

Which version(s) does this affect? (Environment, OS, etc...)

SDK 6.0-beta

przemerr commented 1 year ago

at the time of writing the comment, the behavior changed, every validator gets the same amount of LSK no matter the vote weight (which is also incorrect)

shuse2 commented 1 year ago

Getting 500 LSK per round is correct

Currently on betanet the amount of validators is below 103, I believe because of that reason, the dynamic reward module is miscalculating the block rewards for every delegate

if there is less than 103 validators in betanet, for example, only 2 validators. The length of the round will become 2. Therefore, each validators getting approximately 250 LSK per block is the correct behavior.

przemerr commented 1 year ago

@shuse2 So, you're saying that the inflation rate on a chain is not constant and is higher when the number of active validators is lower?

shuse2 commented 1 year ago

if there is lower than 103 in the lisk mainchain case, the inflation rate will be higher corresponding to the real time. The reward per round is the same, but the round will become shorter

shuse2 commented 1 year ago

Looking at the current situation, it looks like most of the validators is getting 23 LSK, with 22 validators so it's about right. The weight seems more or less equal for all the validators. That's why the most of the validators get the same reward, but im checking staked amount => bft weight conversion is correct

{
  "id": "1",
  "jsonrpc": "2.0",
  "result": {
    "validators": [
      {
        "address": "lsk6pbgwqdmba9ktyxy3k5rzjvyeknxp6wfwk36oa",
        "bftWeight": "7",
        "blsKey": "9593089b50ccfc38a330b10d6b65b8ded984e1dd46f5d0ed6093a9e63bc31e3e2053d40a3adaa1715ed4e28176f36e26"
      },
      {
        "address": "lsk3oe7hmf5k5e4f58zhmbouzx3t4v98sgsfuhwnw",
        "bftWeight": "7",
        "blsKey": "8ec8b6e8a539c00a25d810b5a3c9f091ebf052ffbaf2dcb39e0b3894a2ae827c5af6194951fd2155238d99632b96af8d"
      },
      {
        "address": "lskth9yqsevfc984gpe8euk9m85vtowqzv2ewwnmv",
        "bftWeight": "7",
        "blsKey": "9567064edb05efe17c05de56aebde07846ff42d7e1fb041b89c266aa04b5891ee7f0e3b207bd120f727122adcf90d11c"
      },
      {
        "address": "lskhf3gtj3wecxaxy7csqb5k8kszugghpscvat5b4",
        "bftWeight": "7",
        "blsKey": "8bef5fb7abe61237338cf9e8808d174ebeb7ffc62547c3ea03aff98b2a308d6bbd03f9c921ec5f020003332354ad39e8"
      },
      {
        "address": "lskxsddtvbc7ze98bqbawaq3ydj2f8387429633t9",
        "bftWeight": "5",
        "blsKey": "a7f0a161bfc193c96f6954a5c9bd5d53995e50af810824ac2f56477255302b2258900d1a3711a2c8ceb6ce418222ab24"
      },
      {
        "address": "lska7owayy5cgmko5gxxou9kgf6gjmharb94k34rv",
        "bftWeight": "7",
        "blsKey": "a0e33cff5ea655e11d5ffbadbf1e35090fa1a651c5f8e4836880514f5d234e26fadf02f8c813b399eed037c8a8b45392"
      },
      {
        "address": "lskmz22uzabdhhad2ddb2f6hqky9v9b4n926hggfg",
        "bftWeight": "7",
        "blsKey": "9185d09d2020588f91c0c63343b723d3bfecc56920702c3da70c31e3a47810430a7ca45c83696fa5e72c926d2e372872"
      },
      {
        "address": "lskmfoq8b2xjk9ttnfhhhjq33ukas4ndb7eckc3c3",
        "bftWeight": "7",
        "blsKey": "b921391b7ff32d6b3e4792dbb0961f30e35db7c332ab7453097cff23461a5d69e2efdb8e1d756b3fe61b78afd2ed0cb1"
      },
      {
        "address": "lskzytpy82c8xtkpopchzee3vydza4cvjvcsa4fv3",
        "bftWeight": "7",
        "blsKey": "81a0565891c920229a66ac458345bcb9884837b5b89b379d93b122c359487b8a75959d1d9f0e765c5cc58a0f397a9697"
      },
      {
        "address": "lskxbe5kzt6k69km6ruq9nx4b7kyyonp3bj5yhrcq",
        "bftWeight": "6",
        "blsKey": "b9016208815203e701e65b690353940ef2e02d90c269bdd6fc6b489247b9943e3c83136164bfc9bb6442e7ca4a3973cb"
      },
      {
        "address": "lsknnashp7msn4zwn7owe84xfn7brr9p66e7m9uzg",
        "bftWeight": "7",
        "blsKey": "acc1e8c3f349f5c2064ec7e157b9e073463b9080eff38abe6922af275c642d4e758598796c7cd6c091e2598cb27cf40a"
      },
      {
        "address": "lsk9p7zenqhs3avzy58vjavt98c9gmncvfemhayxt",
        "bftWeight": "7",
        "blsKey": "a69bc7bdc43be3a46e7c02a420953588ea64c7ad0eb2a84dc71d5cf06068678858df07c9fb9c4c30575a26952c73457f"
      },
      {
        "address": "lskeqhjv84465mtjqtmpthkzuucovd7nmrwa7y5r4",
        "bftWeight": "7",
        "blsKey": "91a6a6a2e687074a879dd82897a5fd0b888482d936f6cf00eab5f59c0d537575f47d9dca499017a5917b0d1c9d846c2f"
      },
      {
        "address": "lskhahpjmn86e3ahn4wpvtmjnwzqguz3zv9woqh8u",
        "bftWeight": "7",
        "blsKey": "853bad8f5b9267af7ce927d1547191e0eec5df05ae76da948b9e0bf7ec47b679ce3a7d4586bd306597222569854bb010"
      },
      {
        "address": "lskbm4p4sava9x75osfcw67jwv387m7zgwvz35mkw",
        "bftWeight": "7",
        "blsKey": "b4dd73412298d2cc27d3102402665f4c45424ab310986747a946a1f7c50378c54f1923e0204039f8023cbca823aca866"
      },
      {
        "address": "lsk5cbsc8y69shtgnmegoqt4yrfy5xe92db3kaqxb",
        "bftWeight": "7",
        "blsKey": "8fca3b10a0687879865da0bc79348a91376c9b6e4d88ae85e6e9f92c1f4ef751c426b0003861b48f13a4c3ceaaa81603"
      },
      {
        "address": "lskx9oc6auv2v38sorwbwgzhq9ovmjwbk5wpzmda7",
        "bftWeight": "3",
        "blsKey": "a25e3d61529229dd6a0e3ab8dc044c864829036b17d0849a37f16f587474990ae16f66f568069b8b5090a49668357356"
      },
      {
        "address": "lsk9xu5ohfvx5bzntyy5udqx59amoha6w55xwcn97",
        "bftWeight": "6",
        "blsKey": "93db6c705eb01c109198276aa2b212eca39911b6727922a369cc33d92fd61c26b8f319ae47b03233d855a53d5d313a56"
      },
      {
        "address": "lsk9xxaky96k6p3o7azt6brgasfye9yhumywwduyc",
        "bftWeight": "7",
        "blsKey": "84a5e99e66aae790b5ac25c78b92f3d7479b40b70cd11c56ee4e53d7fa40a06ce46db045a31b9e5e49d324801e499e50"
      },
      {
        "address": "lskyvov25nzg63c6k59hytnfhgd3vcsrztx3zux49",
        "bftWeight": "2",
        "blsKey": "b137d8a975ec500be7b43b8417ce9f0aa769375b3cfdf4c7d8f20e5eb7f7318491ae95b730d9f8df1b8442a694a72900"
      },
      {
        "address": "lskrbqgfofry4gqqzzakuyevvtcsn52m94pb5gf9b",
        "bftWeight": "7",
        "blsKey": "b9c0de0bc2f42dff077792153cf2dff3cc5bf77c262a3e1130e7d1398bee61c3f7c6ced0aa9463d9ed4b24073dc5592a"
      },
      {
        "address": "lskm7bcu9g5wz8vc4j2tfjmndnq2hsupsarcu7p8v",
        "bftWeight": "7",
        "blsKey": "af8c7e06a4c25a62b233ebc968d7d0e8db6fd8cac05d2ca68c352db0d4f94aa56e2117fec09398ef63c9f5e09b45622d"
      }
    ],
    "certificateThreshold": "95",
    "precommitThreshold": "95",
    "prevoteThreshold": "95",
    "validatorsHash": "2f0b84e94945d9eef89cd74cc7f0de6b54888711385e0b9e5f2c4105d35c15b0"
  }
}
shuse2 commented 1 year ago

Checking capping, it looks like capping is working as expected (the weight is capped with some configuration: currently 5%) so that the difference wont be too big within the active validators

przemerr commented 1 year ago

@shuse2 check this out https://betanet-service.liskscan.com/api/v3/blocks?generatorAddress=lskhf3gtj3wecxaxy7csqb5k8kszugghpscvat5b4&limit=10&offset=5365&sort=height:asc

especially at the "height":129073" comparing to "height":129045" there was a significant drop in the rewards almost 10 times, and there wasn't any big shift in voteweights

also are you sure the rounds get shorter? currently there are 22 validators, and the round is definitely 103 blocks long, delegates get reshuffled every 103 blocks

shuse2 commented 1 year ago

Round length is suppose to be shorter but we have this issue https://github.com/LiskHQ/lisk-sdk/issues/8562. So currently, the validators are snapshotted/shuffled every 103 blocks, but total reward depends on # of active validators. Which is bit complex than it should be.

For the shift between "height":129073" - "height":129045", im guessing there was less than or equal to 20 validators. with 5% BFT cap, until 20 validators, there is no capping, so there could be big differences in the reward between validators.

at the height 129045, it was 19 validators as below

{
    "validators": [
      {
        "address": "lskm7bcu9g5wz8vc4j2tfjmndnq2hsupsarcu7p8v",
        "bftWeight": "28",
        "blsKey": "af8c7e06a4c25a62b233ebc968d7d0e8db6fd8cac05d2ca68c352db0d4f94aa56e2117fec09398ef63c9f5e09b45622d"
      },
      {
        "address": "lskyvov25nzg63c6k59hytnfhgd3vcsrztx3zux49",
        "bftWeight": "2",
        "blsKey": "b137d8a975ec500be7b43b8417ce9f0aa769375b3cfdf4c7d8f20e5eb7f7318491ae95b730d9f8df1b8442a694a72900"
      },
      {
        "address": "lsk9xxaky96k6p3o7azt6brgasfye9yhumywwduyc",
        "bftWeight": "1",
        "blsKey": "84a5e99e66aae790b5ac25c78b92f3d7479b40b70cd11c56ee4e53d7fa40a06ce46db045a31b9e5e49d324801e499e50"
      },
      {
        "address": "lskxsddtvbc7ze98bqbawaq3ydj2f8387429633t9",
        "bftWeight": "5",
        "blsKey": "a7f0a161bfc193c96f6954a5c9bd5d53995e50af810824ac2f56477255302b2258900d1a3711a2c8ceb6ce418222ab24"
      },
      {
        "address": "lsk6pbgwqdmba9ktyxy3k5rzjvyeknxp6wfwk36oa",
        "bftWeight": "10",
        "blsKey": "9593089b50ccfc38a330b10d6b65b8ded984e1dd46f5d0ed6093a9e63bc31e3e2053d40a3adaa1715ed4e28176f36e26"
      },
      {
        "address": "lskeqhjv84465mtjqtmpthkzuucovd7nmrwa7y5r4",
        "bftWeight": "301",
        "blsKey": "91a6a6a2e687074a879dd82897a5fd0b888482d936f6cf00eab5f59c0d537575f47d9dca499017a5917b0d1c9d846c2f"
      },
      {
        "address": "lskzytpy82c8xtkpopchzee3vydza4cvjvcsa4fv3",
        "bftWeight": "10",
        "blsKey": "81a0565891c920229a66ac458345bcb9884837b5b89b379d93b122c359487b8a75959d1d9f0e765c5cc58a0f397a9697"
      },
      {
        "address": "lskrbqgfofry4gqqzzakuyevvtcsn52m94pb5gf9b",
        "bftWeight": "2",
        "blsKey": "b9c0de0bc2f42dff077792153cf2dff3cc5bf77c262a3e1130e7d1398bee61c3f7c6ced0aa9463d9ed4b24073dc5592a"
      },
      {
        "address": "lskmz22uzabdhhad2ddb2f6hqky9v9b4n926hggfg",
        "bftWeight": "52",
        "blsKey": "9185d09d2020588f91c0c63343b723d3bfecc56920702c3da70c31e3a47810430a7ca45c83696fa5e72c926d2e372872"
      },
      {
        "address": "lsk5cbsc8y69shtgnmegoqt4yrfy5xe92db3kaqxb",
        "bftWeight": "18",
        "blsKey": "8fca3b10a0687879865da0bc79348a91376c9b6e4d88ae85e6e9f92c1f4ef751c426b0003861b48f13a4c3ceaaa81603"
      },
      {
        "address": "lska7owayy5cgmko5gxxou9kgf6gjmharb94k34rv",
        "bftWeight": "261",
        "blsKey": "a0e33cff5ea655e11d5ffbadbf1e35090fa1a651c5f8e4836880514f5d234e26fadf02f8c813b399eed037c8a8b45392"
      },
      {
        "address": "lsk9xu5ohfvx5bzntyy5udqx59amoha6w55xwcn97",
        "bftWeight": "6",
        "blsKey": "93db6c705eb01c109198276aa2b212eca39911b6727922a369cc33d92fd61c26b8f319ae47b03233d855a53d5d313a56"
      },
      {
        "address": "lskth9yqsevfc984gpe8euk9m85vtowqzv2ewwnmv",
        "bftWeight": "12",
        "blsKey": "9567064edb05efe17c05de56aebde07846ff42d7e1fb041b89c266aa04b5891ee7f0e3b207bd120f727122adcf90d11c"
      },
      {
        "address": "lsk9p7zenqhs3avzy58vjavt98c9gmncvfemhayxt",
        "bftWeight": "303",
        "blsKey": "a69bc7bdc43be3a46e7c02a420953588ea64c7ad0eb2a84dc71d5cf06068678858df07c9fb9c4c30575a26952c73457f"
      },
      {
        "address": "lsk3oe7hmf5k5e4f58zhmbouzx3t4v98sgsfuhwnw",
        "bftWeight": "2",
        "blsKey": "8ec8b6e8a539c00a25d810b5a3c9f091ebf052ffbaf2dcb39e0b3894a2ae827c5af6194951fd2155238d99632b96af8d"
      },
      {
        "address": "lskmfoq8b2xjk9ttnfhhhjq33ukas4ndb7eckc3c3",
        "bftWeight": "46",
        "blsKey": "b921391b7ff32d6b3e4792dbb0961f30e35db7c332ab7453097cff23461a5d69e2efdb8e1d756b3fe61b78afd2ed0cb1"
      },
      {
        "address": "lskhahpjmn86e3ahn4wpvtmjnwzqguz3zv9woqh8u",
        "bftWeight": "12",
        "blsKey": "853bad8f5b9267af7ce927d1547191e0eec5df05ae76da948b9e0bf7ec47b679ce3a7d4586bd306597222569854bb010"
      },
      {
        "address": "lskbm4p4sava9x75osfcw67jwv387m7zgwvz35mkw",
        "bftWeight": "30",
        "blsKey": "b4dd73412298d2cc27d3102402665f4c45424ab310986747a946a1f7c50378c54f1923e0204039f8023cbca823aca866"
      },
      {
        "address": "lskhf3gtj3wecxaxy7csqb5k8kszugghpscvat5b4",
        "bftWeight": "990",
        "blsKey": "8bef5fb7abe61237338cf9e8808d174ebeb7ffc62547c3ea03aff98b2a308d6bbd03f9c921ec5f020003332354ad39e8"
      }
    ],
    "certificateThreshold": "1395",
    "precommitThreshold": "1395",
    "prevoteThreshold": "1395",
    "validatorsHash": "d75119a23df052a8a85147f30051944bda59acf1aa69839a7f20fc333ba697ce"
  }
przemerr commented 1 year ago

Thank you @shuse2 everything is more clear now, the round length, the cap switch at 20 validatora, got me all confused 👍

shuse2 commented 1 year ago

I'll close the issue as resolved 👍