Skip to content

Commit

Permalink
Add dynamic issuance migration and fix clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
nazar-pc committed Feb 12, 2024
1 parent 50535cf commit 3e94c9e
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 9 deletions.
8 changes: 4 additions & 4 deletions crates/pallet-rewards/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unsafe_code)]
#![warn(rust_2018_idioms, missing_debug_implementations)]
#![warn(rust_2018_idioms)]
#![feature(try_blocks)]

#[cfg(feature = "runtime-benchmarks")]
Expand Down Expand Up @@ -162,16 +162,16 @@ mod pallet {

/// Tokens left to issue to farmers at any given time
#[pallet::storage]
pub(super) type RemainingIssuance<T> = StorageValue<_, BalanceOf<T>, ValueQuery>;
pub type RemainingIssuance<T> = StorageValue<_, BalanceOf<T>, ValueQuery>;

/// Block proposer subsidy parameters
#[pallet::storage]
pub(super) type ProposerSubsidyParams<T> =
pub type ProposerSubsidyParams<T> =
StorageValue<_, IssuanceComponentParams<BlockNumberFor<T>, BalanceOf<T>>, OptionQuery>;

/// Voter subsidy parameters
#[pallet::storage]
pub(super) type VoterSubsidyParams<T> =
pub type VoterSubsidyParams<T> =
StorageValue<_, IssuanceComponentParams<BlockNumberFor<T>, BalanceOf<T>>, OptionQuery>;

/// `pallet-rewards` events
Expand Down
6 changes: 3 additions & 3 deletions crates/pallet-rewards/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fn correct_block_reward() {

{
let params = IssuanceComponentParams {
initial_subsidy: 1 * SSC,
initial_subsidy: SSC,
max_component_issuance: 1_000_000 * SSC,
initial_subsidy_start_block: 10,
initial_subsidy_duration: 10,
Expand Down Expand Up @@ -71,7 +71,7 @@ fn correct_block_reward() {

{
let params = IssuanceComponentParams {
initial_subsidy: 1 * SSC,
initial_subsidy: SSC,
max_component_issuance: 0,
initial_subsidy_start_block: 10,
initial_subsidy_duration: 10,
Expand All @@ -89,7 +89,7 @@ fn correct_vote_reward() {
assert_eq!(Pallet::vote_reward(None, 0), 0);

let params = IssuanceComponentParams {
initial_subsidy: 1 * SSC,
initial_subsidy: SSC,
max_component_issuance: 1_000_000 * SSC,
initial_subsidy_start_block: 10,
initial_subsidy_duration: 10,
Expand Down
40 changes: 38 additions & 2 deletions crates/subspace-runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ use domain_runtime_primitives::{
};
use frame_support::inherent::ProvideInherent;
use frame_support::traits::{
ConstU16, ConstU32, ConstU64, ConstU8, Currency, Everything, Get, VariantCount,
ConstU16, ConstU32, ConstU64, ConstU8, Currency, Everything, Get, OnRuntimeUpgrade,
VariantCount,
};
use frame_support::weights::constants::{ParityDbWeight, WEIGHT_REF_TIME_PER_SECOND};
use frame_support::weights::{ConstantMultiplier, IdentityFee, Weight};
Expand Down Expand Up @@ -111,7 +112,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("subspace"),
impl_name: create_runtime_str!("subspace"),
authoring_version: 0,
spec_version: 0,
spec_version: 1,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 0,
Expand Down Expand Up @@ -736,13 +737,48 @@ pub type SignedExtra = (
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

pub struct InitializeDynamicIssuance;
impl OnRuntimeUpgrade for InitializeDynamicIssuance {
fn on_runtime_upgrade() -> Weight {
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;
pallet_rewards::RemainingIssuance::<Runtime>::put(remaining_issuance);

let base_reward = SSC;
let proposer_share = 1;
let voters_share = Balance::from(EXPECTED_VOTES_PER_BLOCK);
let total_shares = proposer_share + voters_share;
pallet_rewards::ProposerSubsidyParams::<Runtime>::put(IssuanceComponentParams {
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,
});
pallet_rewards::VoterSubsidyParams::<Runtime>::put(IssuanceComponentParams {
initial_subsidy: voters_share * base_reward
/ total_shares
/ Balance::from(EXPECTED_VOTES_PER_BLOCK),
max_component_issuance: remaining_issuance * voters_share
/ total_shares
/ Balance::from(EXPECTED_VOTES_PER_BLOCK),
initial_subsidy_start_block: System::block_number(),
initial_subsidy_duration: 10_512_000,
});

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

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Runtime,
Block,
frame_system::ChainContext<Runtime>,
Runtime,
AllPalletsWithSystem,
InitializeDynamicIssuance,
>;

fn extract_segment_headers(ext: &UncheckedExtrinsic) -> Option<Vec<SegmentHeader>> {
Expand Down

0 comments on commit 3e94c9e

Please sign in to comment.