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

feat: Update slashing values for mainnet #4148

Merged
merged 11 commits into from Nov 1, 2023
Merged

feat: Update slashing values for mainnet #4148

merged 11 commits into from Nov 1, 2023

Conversation

marcellorigotti
Copy link
Contributor

@marcellorigotti marcellorigotti commented Oct 20, 2023

Pull Request

Closes: PRO-924

Checklist

Please conduct a thorough self-review before opening the PR.

  • I am confident that the code works.
  • I have updated documentation where appropriate.

Summary

Update slashing:

  • Validators who have a negative reputation for a whole day will be slashed 0.1% of their bond
  • Keygen failure penalties will be reduced to a fixed value of 1 FLIP
  • Added these values in the chainspec

@linear
Copy link

linear bot commented Oct 20, 2023

PRO-924 Constant value slashing

We currently slash validators based on a percentage of either the current bond, or their current total stake.

For mainnet release we want every slash to be a fixed notional 1FLIP penalty.

@codecov
Copy link

codecov bot commented Oct 20, 2023

Codecov Report

Merging #4148 (8e688cf) into main (d21557a) will decrease coverage by 0%.
The diff coverage is 51%.

@@          Coverage Diff          @@
##            main   #4148   +/-   ##
=====================================
- Coverage     72%     72%   -0%     
=====================================
  Files        379     380    +1     
  Lines      61792   61841   +49     
  Branches   61792   61841   +49     
=====================================
+ Hits       44353   44382   +29     
- Misses     15140   15153   +13     
- Partials    2299    2306    +7     
Files Coverage Δ
...ate-chain/cf-integration-tests/src/mock_runtime.rs 100% <100%> (ø)
state-chain/custom-rpc/src/lib.rs 23% <100%> (+<1%) ⬆️
state-chain/pallets/cf-emissions/src/mock.rs 84% <100%> (ø)
state-chain/pallets/cf-flip/src/mock.rs 99% <100%> (ø)
state-chain/pallets/cf-flip/src/tests.rs 93% <100%> (-<1%) ⬇️
state-chain/pallets/cf-funding/src/mock.rs 82% <100%> (ø)
...ain/pallets/cf-reputation/src/reporting_adapter.rs 92% <100%> (ø)
state-chain/primitives/src/lib.rs 63% <ø> (ø)
state-chain/traits/src/lib.rs 49% <ø> (ø)
...ate-chain/pallets/cf-validator/src/benchmarking.rs 0% <0%> (ø)
... and 7 more

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@marcellorigotti marcellorigotti changed the title Feature/pro 924 Feat: Update slashing values for mainnet Oct 20, 2023
@marcellorigotti marcellorigotti marked this pull request as ready for review October 20, 2023 14:46
@dandanlen dandanlen self-requested a review October 20, 2023 20:41
state-chain/node/src/chain_spec/common.rs Outdated Show resolved Hide resolved
Comment on lines 292 to 293
let attempted_slash: u128 = (*slashing_rate * *bond /
<mock::Test as pallet::Config>::BlocksPerDay::get() as u128)
Copy link
Contributor

Choose a reason for hiding this comment

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

This should probably be a function. We do this in the slash() function.

state-chain/pallets/cf-reputation/src/reporting_adapter.rs Outdated Show resolved Hide resolved
/// (2/3 must agree the node was an offender) on keygen failure.
#[pallet::storage]
pub(super) type KeygenSlashRate<T, I = ()> = StorageValue<_, Percent, ValueQuery>;
pub(super) type KeygenSlashAmount<T, I = ()> = StorageValue<_, FlipBalance, ValueQuery>;
Copy link
Collaborator

@dandanlen dandanlen Oct 23, 2023

Choose a reason for hiding this comment

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

This will require a storage migration. (LMK and I can show you how to do this)

state-chain/node/src/chain_spec/common.rs Outdated Show resolved Hide resolved
origin: OriginFor<T>,
percent_of_total_funds: Percent,
amount_to_slash: FlipBalance,
Copy link
Collaborator

Choose a reason for hiding this comment

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

FWIW this is a breaking change. In some cases we would want to change the call_index here - but since it's a governance extrinsic it's probably ok.

@@ -326,8 +327,8 @@ pub trait Slashing {
/// Slashes a validator for the equivalent of some number of blocks offline.
fn slash(validator_id: &Self::AccountId, blocks_offline: Self::BlockNumber);

/// Slahes a percentage of a validator's total balance.
fn slash_balance(account_id: &Self::AccountId, amount: Percent);
/// Slashes a validator for a fixed amount
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
/// Slashes a validator for a fixed amount
/// Slashes a validator by some fixed amount.

(nit)

/// Slahes a percentage of a validator's total balance.
fn slash_balance(account_id: &Self::AccountId, amount: Percent);
/// Slashes a validator for a fixed amount
fn slash_balance(account_id: &Self::AccountId, slash_rate: FlipBalance);
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fn slash_balance(account_id: &Self::AccountId, slash_rate: FlipBalance);
fn slash_balance(account_id: &Self::AccountId, slash_amount: FlipBalance);

@marcellorigotti marcellorigotti requested a review from a team as a code owner October 23, 2023 15:21
@marcellorigotti marcellorigotti requested review from zoheb391 and GabrielBuragev and removed request for a team October 23, 2023 15:21
@marcellorigotti
Copy link
Contributor Author

Regarding the breaking change and the storage migration we can check tomorrow in person @dandanlen, thanks!

Comment on lines 28 to 30
#[frame_support::storage_alias]
pub type KeygenSlashAmount<T: Config<I>, I: 'static> =
StorageValue<Pallet<T, I>, FlipBalance, ValueQuery>;
Copy link
Collaborator

Choose a reason for hiding this comment

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

You don't need this - you can just use the crate::KeygenSlashAmount that is defined in the new version of the pallet.

@dandanlen
Copy link
Collaborator

I'll resolve the conflicts and merge.

@dandanlen dandanlen changed the title Feat: Update slashing values for mainnet feat: Update slashing values for mainnet Oct 26, 2023
@kylezs
Copy link
Contributor

kylezs commented Nov 1, 2023

This waiting for anything?

@marcellorigotti
Copy link
Contributor Author

AFAIK it is ready to be merged, @dandanlen can you confirm?

@dandanlen
Copy link
Collaborator

No, sorry, I must have forgotten.

@dandanlen dandanlen enabled auto-merge (squash) November 1, 2023 14:11
@dandanlen dandanlen merged commit 3fafc45 into main Nov 1, 2023
41 checks passed
@dandanlen dandanlen deleted the feature/pro-924 branch November 1, 2023 14:55
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.

None yet

3 participants