Problem: (CRO-503) Slashing rate is not proportional to number of failing validators#506
Problem: (CRO-503) Slashing rate is not proportional to number of failing validators#506devashishdxt wants to merge 1 commit intocrypto-com:masterfrom devashishdxt:proportional-slashing
Conversation
…ailing validators Solution: Made slashing rates = (((3 * number of failing validators) / total vaildators) ^ 2) * slash rate
| total_validators: usize, | ||
| ) -> SlashRatio { | ||
| let millis = | ||
| (((3.0 * failing_validators as f64) / total_validators as f64).powi(2) * 1000.0) as u64; |
There was a problem hiding this comment.
3.0 can be constant if we need to adjust
There was a problem hiding this comment.
3 comes from the fact that it can tolerate up to 1/3 of faulting nodes
|
|
||
| #[inline] | ||
| fn mul(self, rhs: SlashRatio) -> Self::Output { | ||
| SlashRatio::new(self.0 * rhs.0) |
There was a problem hiding this comment.
I think having expect is similar to having runtime assertion. And in this case, we cannot have a compile time assertion.
tomtau
left a comment
There was a problem hiding this comment.
ideally fixed point operations.
also, the formula for unresponsiveness and byzantine faults may be different -- e.g. https://research.web3.foundation/en/latest/polkadot/slashing/amounts/#unresponsiveness
the formula is `(3*(number of failing validators - 1) / total validators) * slash rate
The idea there is that it's 0 for one isolated case and goes up to the full rate if 1/3 are unresponsive.
| (((3.0 * failing_validators as f64) / total_validators as f64).powi(2) * 1000.0) as u64; | ||
| SlashRatio::new(Milli::from_millis(std::cmp::min(millis, 1000))).unwrap() * self |
There was a problem hiding this comment.
this should use / preserve fixed-point operations rather than casting to floating points, otherwise it may not be deterministic (e.g. different rustc/llvm versions may optimizing floating point operations differently).
x.powi(2) can be rewritten as x*x
Codecov Report
@@ Coverage Diff @@
## master #506 +/- ##
==========================================
+ Coverage 67.22% 67.24% +0.02%
==========================================
Files 120 120
Lines 14114 14127 +13
==========================================
+ Hits 9488 9500 +12
- Misses 4626 4627 +1
|
|
I guess this PR is currently blocked by: #507 |
That is correct. I'm closing this pull request for now and will reopen it once all the changes are done. |
Solution: Made slashing rates =
(((3 * number of failing validators) / total vaildators) ^ 2) * slash rate