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

FIP 0011 Consensus Fault Simplification #1190

Merged
merged 3 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions vm/actor/src/builtin/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2720,9 +2720,9 @@ impl Actor {

// The policy amounts we should burn and send to reporter
// These may differ from actual funds send when miner goes into fee debt
let fault_penalty =
consensus_fault_penalty(reward_stats.this_epoch_reward_smoothed.estimate());
let slasher_reward = reward_for_consensus_slash_report(fault_age, &fault_penalty);
let this_epoch_reward = reward_stats.this_epoch_reward_smoothed.estimate();
let fault_penalty = consensus_fault_penalty(this_epoch_reward.clone());
let slasher_reward = reward_for_consensus_slash_report(&this_epoch_reward);

let mut pledge_delta = TokenAmount::from(0);

Expand Down
52 changes: 7 additions & 45 deletions vm/actor/src/builtin/miner/policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ use fil_types::{
NetworkVersion, RegisteredPoStProof, RegisteredSealProof, SectorQuality, SectorSize,
StoragePower,
};
use num_bigint::BigUint;
use num_bigint::{BigInt, Integer};
use num_traits::Pow;
use std::cmp;
use vm::TokenAmount;

Expand Down Expand Up @@ -259,12 +257,6 @@ pub fn qa_power_for_sector(size: SectorSize, sector: &SectorOnChainInfo) -> Stor
pub fn sector_deals_max(size: SectorSize) -> u64 {
cmp::max(256, size as u64 / DEAL_LIMIT_DENOMINATOR)
}

struct BigFrac {
numerator: BigInt,
denominator: BigInt,
}

/// Specification for a linear vesting schedule.
pub struct VestSpec {
pub initial_delay: ChainEpoch, // Delay before any amount starts vesting.
Expand All @@ -280,44 +272,14 @@ pub const REWARD_VESTING_SPEC: VestSpec = VestSpec {
quantization: 12 * EPOCHS_IN_HOUR, // PARAM_FINISH
};

pub fn reward_for_consensus_slash_report(
elapsed_epoch: ChainEpoch,
collateral: &TokenAmount,
) -> TokenAmount {
// var growthRate = SLASHER_SHARE_GROWTH_RATE_NUM / SLASHER_SHARE_GROWTH_RATE_DENOM
// var multiplier = growthRate^elapsedEpoch
// var slasherProportion = min(INITIAL_SLASHER_SHARE * multiplier, 1.0)
// return collateral * slasherProportion
// BigInt Operation
// NUM = SLASHER_SHARE_GROWTH_RATE_NUM^elapsedEpoch * INITIAL_SLASHER_SHARE_NUM * collateral
// DENOM = SLASHER_SHARE_GROWTH_RATE_DENOM^elapsedEpoch * INITIAL_SLASHER_SHARE_DENOM
// slasher_amount = min(NUM/DENOM, collateral)
let consensus_fault_reporter_share_growth_rate = BigFrac {
numerator: BigInt::from(100_785_473_384u64),
denominator: BigInt::from(100_000_000_000u64),
};
let consensus_fault_reporter_initial_share = BigFrac {
numerator: BigInt::from(1),
denominator: BigInt::from(1000),
};
let max_reporter_share = BigFrac {
numerator: BigInt::from(1),
denominator: BigInt::from(20),
};
let elapsed = BigUint::from(elapsed_epoch as u64);
let slasher_share_numerator = consensus_fault_reporter_share_growth_rate
.numerator
.pow(&elapsed);
let slasher_share_denominator = consensus_fault_reporter_share_growth_rate
.denominator
.pow(&elapsed);
let num: BigInt =
(slasher_share_numerator * consensus_fault_reporter_initial_share.numerator) * collateral;
let denom = slasher_share_denominator * consensus_fault_reporter_initial_share.denominator;
// Default share of block reward allocated as reward to the consensus fault reporter.
// Applied as epochReward / (expectedLeadersPerEpoch * consensusFaultReporterDefaultShare)
pub const CONSENSUS_FAULT_REPORTER_DEFAULT_SHARE: i64 = 4;

cmp::min(
num.div_floor(&denom),
(collateral * max_reporter_share.numerator).div_floor(&max_reporter_share.denominator),
pub fn reward_for_consensus_slash_report(epoch_reward: &TokenAmount) -> TokenAmount {
epoch_reward.div_floor(
&(BigInt::from(EXPECTED_LEADERS_PER_EPOCH)
* BigInt::from(CONSENSUS_FAULT_REPORTER_DEFAULT_SHARE)),
)
}

Expand Down