Skip to content

Commit

Permalink
modifying cap calc
Browse files Browse the repository at this point in the history
  • Loading branch information
EdHastingsCasperAssociation committed May 15, 2024
1 parent ff53398 commit 6bc7811
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion resources/local/chainspec.toml.in
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ refund_handling = { type = 'no_refund' }
# administrator accounts
# 'burn': fees are burned
fee_handling = { type = 'no_fee' }
# The proportion of baseline rewards going to reward finality signatures specifically.
# If a validator would recieve a validator credit, it cannot exceed this percentage of their total stake.
validator_credit_cap = [1, 5]
# Defines how pricing is handled.
#
Expand Down
2 changes: 1 addition & 1 deletion resources/production/chainspec.toml
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ refund_handling = { type = 'no_refund' }
# administrator accounts
# 'burn': fees are burned
fee_handling = { type = 'no_fee' }
# The proportion of baseline rewards going to reward finality signatures specifically.
# If a validator would recieve a validator credit, it cannot exceed this percentage of their total stake.
validator_credit_cap = [1, 5]
# Defines how pricing is handled.
#
Expand Down
14 changes: 10 additions & 4 deletions storage/src/system/auction/detail.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,14 @@ impl ValidatorBidsDetail {
&& !v.inactive()
}) {
let staked_amount = total_staked_amount(provider, bid)?;
let total = staked_amount.saturating_add(self.credit_amount(
let credit_amount = self.credit_amount(
validator_public_key,
era_ending,
staked_amount,
include_credits,
cap,
));
);
let total = staked_amount.saturating_add(credit_amount);
ret.insert(validator_public_key.clone(), total);
}

Expand All @@ -146,6 +148,7 @@ impl ValidatorBidsDetail {
&self,
validator_public_key: &PublicKey,
era_ending: EraId,
staked_amount: U512,
include_credit: bool,
cap: Ratio<U512>,
) -> U512 {
Expand All @@ -155,8 +158,11 @@ impl ValidatorBidsDetail {

if let Some(inner) = self.validator_credits.get(validator_public_key) {
if let Some(credit) = inner.get(&era_ending) {
let amount = Ratio::new_raw(credit.amount(), U512::one());
return amount.mul(cap).to_integer();
let capped = Ratio::new_raw(staked_amount, U512::one())
.mul(cap)
.to_integer();
let credit_amount = credit.amount();
return credit_amount.min(capped);
}
}

Expand Down

0 comments on commit 6bc7811

Please sign in to comment.