Skip to content

Commit

Permalink
Apply review suggestions and fix remaining issuance in the migration
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Feb 28, 2024
1 parent 59366f4 commit 7be4396
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
16 changes: 8 additions & 8 deletions crates/pallet-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,16 +435,16 @@ impl<T: Config> Pallet<T> {
let is = params.initial_subsidy;
let mdi = max_decay_issuance;

let term1 = is * is * t / mdi;
let term2 = term1 * is * t / mdi;
let term3 = term2 * is * t / mdi;
let term4 = term3 * is * t / mdi;
let term5 = term4 * is * t / mdi;
let term1 = is * is / mdi * t;
let term2 = term1 * is / mdi * t;
let term3 = term2 * is / mdi * t;
let term4 = term3 * is / mdi * t;
let term5 = term4 * is / mdi * t;
let maybe_subsidy = try {
is.checked_sub(&term1)?
.checked_add(&(term2 / 2_u32.into()))?
.checked_sub(&(term3 / 6_u32.into()))?
is.checked_add(&(term2 / 2_u32.into()))?
.checked_sub(&term1)?
.checked_add(&(term4 / 24_u32.into()))?
.checked_sub(&(term3 / 6_u32.into()))?
.checked_sub(&(term5 / 120_u32.into()))?
};

Expand Down
8 changes: 8 additions & 0 deletions crates/pallet-rewards/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ fn correct_block_reward() {
assert!(
Pallet::block_reward(Some(params), 50, 100) < Pallet::block_reward(Some(params), 50, 0)
);

// Taylor series approximation underflows at a particular block
assert_ne!(Pallet::vote_reward(Some(params), 2_180_605), 0);
assert_eq!(Pallet::vote_reward(Some(params), 2_180_606), 0);
}

{
Expand Down Expand Up @@ -108,4 +112,8 @@ fn correct_vote_reward() {
// Vote reward goes down once initial subsidy ends
assert!(Pallet::vote_reward(Some(params), 10) > Pallet::vote_reward(Some(params), 21));
assert!(Pallet::vote_reward(Some(params), 21) > Pallet::vote_reward(Some(params), 50));

// Taylor series approximation underflows at a particular block
assert_ne!(Pallet::vote_reward(Some(params), 2_180_605), 0);
assert_eq!(Pallet::vote_reward(Some(params), 2_180_606), 0);
}
6 changes: 3 additions & 3 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ impl OnRuntimeUpgrade for InitializeDynamicIssuance {
if pallet_rewards::ProposerSubsidyParams::<Runtime>::get().is_some() {
return <Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 0);
}
let remaining_issuance = 1_000_000_000;
let remaining_issuance = 1_000_000_000 * SSC;
pallet_rewards::RemainingIssuance::<Runtime>::put(remaining_issuance);

let base_reward = SSC;
Expand All @@ -779,7 +779,7 @@ impl OnRuntimeUpgrade for InitializeDynamicIssuance {
initial_subsidy: proposer_share * base_reward / total_shares,
max_component_issuance: remaining_issuance * proposer_share / total_shares,
initial_subsidy_start_block: System::block_number(),
initial_subsidy_duration: 10_512_000,
initial_subsidy_duration: 302_400,
});
pallet_rewards::VoterSubsidyParams::<Runtime>::put(IssuanceComponentParams {
initial_subsidy: voters_share * base_reward
Expand All @@ -789,7 +789,7 @@ impl OnRuntimeUpgrade for InitializeDynamicIssuance {
/ total_shares
/ Balance::from(EXPECTED_VOTES_PER_BLOCK),
initial_subsidy_start_block: System::block_number(),
initial_subsidy_duration: 10_512_000,
initial_subsidy_duration: 302_400,
});

<Runtime as frame_system::Config>::DbWeight::get().reads_writes(1, 3)
Expand Down

0 comments on commit 7be4396

Please sign in to comment.