Skip to content

Commit

Permalink
masp: implement remaining inflation logic
Browse files Browse the repository at this point in the history
Inflation logic that works with 256-bit Amounts was deferred until now.
We correct the implementation to adjust rewards for words above the
lowest. (Rewards are only awarded in the lowest denomination of NAM,
which is the only one used; if a reward exceeds i64::MAX, this is
certainly an error.)

For nonstandard (non-10^6) denominations, we must also perform an
adjustment in decimal places. This will apply to ETH in reality, and
our test ETH now.
  • Loading branch information
mariari authored and juped committed Jul 18, 2023
1 parent d92eb8f commit 9cab267
Show file tree
Hide file tree
Showing 12 changed files with 462 additions and 154 deletions.
20 changes: 11 additions & 9 deletions apps/src/lib/config/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use namada::types::key::dkg_session_keys::DkgPublicKey;
use namada::types::key::*;
use namada::types::time::{DateTimeUtc, DurationSecs};
use namada::types::token::Denomination;
use namada::types::uint::I256;
use namada::types::{storage, token};

/// Genesis configuration file format
Expand All @@ -38,6 +39,7 @@ pub mod genesis_config {
use namada::types::key::*;
use namada::types::time::Rfc3339String;
use namada::types::token::Denomination;
use namada::types::uint::I256;
use namada::types::{storage, token};
use serde::{Deserialize, Serialize};
use thiserror::Error;
Expand Down Expand Up @@ -395,8 +397,8 @@ pub mod genesis_config {
let token_vp_config = wasm.get(token_vp_name).unwrap();

TokenAccount {
last_locked_ratio: Decimal::ZERO,
last_inflation: 0,
last_locked_ratio: Dec::zero(),
last_inflation: I256::zero(),
parameters: config.parameters.as_ref().unwrap().to_owned(),
address: Address::decode(config.address.as_ref().unwrap()).unwrap(),
denom: config.denom,
Expand Down Expand Up @@ -816,9 +818,9 @@ pub struct TokenAccount {
/// Token parameters
pub parameters: token::parameters::Parameters,
/// Token inflation from the last epoch (read + write for every epoch)
pub last_inflation: u64,
pub last_inflation: I256,
/// Token shielded ratio from the last epoch (read + write for every epoch)
pub last_locked_ratio: Decimal,
pub last_locked_ratio: Dec,
}

#[derive(
Expand Down Expand Up @@ -1038,17 +1040,17 @@ pub fn genesis(num_validators: u64) -> Genesis {
balances.insert((&validator.account_key).into(), default_key_tokens);
}

let token_accounts = address::masp_rewards()
.into_keys()
.map(|address| TokenAccount {
let token_accounts = address::tokens()
.into_iter()
.map(|(address, (_, denom))| TokenAccount {
address,
denom,
vp_code_path: vp_token_path.into(),
vp_sha256: Default::default(),
balances: balances.clone(),
parameters: token::parameters::Parameters::default(),
last_inflation: 0,
last_locked_ratio: Decimal::ZERO,
last_inflation: I256::zero(),
last_locked_ratio: Dec::zero(),
})
.collect();
Genesis {
Expand Down
13 changes: 6 additions & 7 deletions core/src/ledger/inflation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
//! proof-of-stake, providing liquity to shielded asset pools, and public goods
//! funding.

use namada_core::types::dec::Dec;

use crate::ledger::storage_api::{self, StorageRead, StorageWrite};
use crate::types::address::Address;
use crate::types::dec::Dec;
use crate::types::token;

/// The domains of inflation
Expand Down Expand Up @@ -54,12 +53,12 @@ impl RewardsController {
pub fn new(
locked_tokens: token::Amount,
total_tokens: token::Amount,
locked_ratio_target: Decimal,
locked_ratio_last: Decimal,
max_reward_rate: Decimal,
locked_ratio_target: Dec,
locked_ratio_last: Dec,
max_reward_rate: Dec,
last_inflation_amount: token::Amount,
p_gain_nom: Decimal,
d_gain_nom: Decimal,
p_gain_nom: Dec,
d_gain_nom: Dec,
epochs_per_year: u64,
) -> Self {
Self {
Expand Down
Loading

0 comments on commit 9cab267

Please sign in to comment.