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

fix: slashed fp and BTC rewards tracker #371

Merged
merged 14 commits into from
Dec 24, 2024

Conversation

RafilxTenfen
Copy link
Contributor

EventPowerDistUpdate_SlashedFp and RewardBTCStaking are called at different blocks.
The rewards are being called a few blocks behind and if the slashed fp is pruned in BTC reward tracker data, it fails to find and panics

On babylond-deployments an fp is being slashed at block height 46, the call of RewardBTCStaking happens at Babylon block 48 but is called to distribute rewards of voting power table from block 44 (which didn't had the FP slashed yet) which then checks for fp rewards for the FP that was pruned at the slashing processed event.

6:04PM INF finalizing commit of block hash=153E869F7B0056A9CD8208301F2019FFACA2BEFBBB35AEADF70DCA14C15F3972 height=47 module=consensus num_txs=2 root=62B5F025459DEEBE2EE6F5D869C5BCBE903299FF80825FB9DE62551E6B725D52
 ERR CONSENSUS FAILURE!!! err="failed to add fp rewards for btc delegation bbn1wwkaq6z3kdkekm7ltwxng4ftvzux8gzp2xjx8d at height 44: finality provider current rewards not found
$~ babylond q btcstaking finality-providers -o json | jq
...
    {
      "description": {
        "moniker": "Finality Provider 0",
        "identity": "",
        "website": "",
        "security_contact": "",
        "details": ""
      },
      "commission": "0.050000000000000000",
      "addr": "bbn1wwkaq6z3kdkekm7ltwxng4ftvzux8gzp2xjx8d",
      "btc_pk": "6ba387c315dc6105ec02b50684593505103a9f13452d3a597c16ac2f22b924dc",
      "pop": {
        "btc_sig_type": "BIP340",
        "btc_sig": "Q3PcfiKT0fwWOVx95rjV+mQvI/juTbYIV84Hfz2NAmQByiHRXz8OWnFbyugJgOrd/TrqR+6BOgtr10bZUFDFbA=="
      },
      "slashed_babylon_height": "46",
      "slashed_btc_height": 131,
      "height": "46",
      "jailed": false,
      "highest_voted_height": 45
    },

Basically, this means we are processing the rewards a few blocks down the road after the slash and then it is not possible to prune the data for reward tracker until that fp slashed height is processed.

The fix for the time being: do nothing at the btc reward tracker structures if some fp gets slashed just continue to store that data. In the future during the issue #362 we can properly handle the pruning of slashed finality provider data

Copy link
Collaborator

@KonradStaniec KonradStaniec left a comment

Choose a reason for hiding this comment

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

Fix looks good 👍

Added one comment about thing we are possibly missing.

x/finality/keeper/power_dist_change.go Show resolved Hide resolved
Copy link
Member

@gitferry gitferry left a comment

Choose a reason for hiding this comment

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

Maybe an alternative solution is to add a condition to break the loop if the fp.Slashed in https://github.com/babylonlabs-io/babylon/blob/main/x/finality/types/power_table.go#L77?

@RafilxTenfen
Copy link
Contributor Author

Maybe an alternative solution is to add a condition to break the loop if the fp.Slashed in https://github.com/babylonlabs-io/babylon/blob/main/x/finality/types/power_table.go#L77?

I totally agree

@KonradStaniec
Copy link
Collaborator

Maybe an alternative solution is to add a condition to break the loop if the fp.Slashed in https://github.com/babylonlabs-io/babylon/blob/main/x/finality/types/power_table.go#L77?

For it to make sense the above sorting https://github.com/babylonlabs-io/babylon/blob/main/x/finality/types/power_table.go#L71, should also take slashing into account no ?

@RafilxTenfen RafilxTenfen merged commit be9eb6b into main Dec 24, 2024
21 checks passed
@RafilxTenfen RafilxTenfen deleted the rafilx/fix-slashed-fp-vptable branch December 24, 2024 15:08
RafilxTenfen added a commit that referenced this pull request Dec 24, 2024
`EventPowerDistUpdate_SlashedFp` and
[`RewardBTCStaking`](https://github.com/babylonlabs-io/babylon/blob/b132d16483d2e12ac68be74a524a4b7121edac65/x/incentive/keeper/btc_staking_gauge.go#L19)
are called at different blocks.
The rewards are being called a few blocks behind and if the slashed fp
is pruned in BTC reward tracker data, it fails to find and panics

On babylond-deployments an fp is being slashed at block height 46, the
call of `RewardBTCStaking` happens at Babylon block 48 but is called to
distribute rewards of voting power table from block 44 (which didn't had
the FP slashed yet) which then checks for fp rewards for the FP that was
pruned at the slashing processed event.

```
6:04PM INF finalizing commit of block hash=153E869F7B0056A9CD8208301F2019FFACA2BEFBBB35AEADF70DCA14C15F3972 height=47 module=consensus num_txs=2 root=62B5F025459DEEBE2EE6F5D869C5BCBE903299FF80825FB9DE62551E6B725D52
 ERR CONSENSUS FAILURE!!! err="failed to add fp rewards for btc delegation bbn1wwkaq6z3kdkekm7ltwxng4ftvzux8gzp2xjx8d at height 44: finality provider current rewards not found
```

```shell
$~ babylond q btcstaking finality-providers -o json | jq
...
    {
      "description": {
        "moniker": "Finality Provider 0",
        "identity": "",
        "website": "",
        "security_contact": "",
        "details": ""
      },
      "commission": "0.050000000000000000",
      "addr": "bbn1wwkaq6z3kdkekm7ltwxng4ftvzux8gzp2xjx8d",
      "btc_pk": "6ba387c315dc6105ec02b50684593505103a9f13452d3a597c16ac2f22b924dc",
      "pop": {
        "btc_sig_type": "BIP340",
        "btc_sig": "Q3PcfiKT0fwWOVx95rjV+mQvI/juTbYIV84Hfz2NAmQByiHRXz8OWnFbyugJgOrd/TrqR+6BOgtr10bZUFDFbA=="
      },
      "slashed_babylon_height": "46",
      "slashed_btc_height": 131,
      "height": "46",
      "jailed": false,
      "highest_voted_height": 45
    },
```

Basically, this means we are processing the rewards a few blocks down
the road after the slash and then it is not possible to prune the data
for reward tracker until that fp slashed height is processed.

The fix for the time being: do nothing at the btc reward tracker
structures if some fp gets slashed just continue to store that data. In
the future during the issue
#362 we can properly
handle the pruning of slashed finality provider data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants