Add storage point tracking and tie in storage rewards to economics (#4824)

* Add storage point tracking and tie in storage rewards to epochs and economics

* Prevent validators from updating their validations for a segment

* Fix test

* Retain syscall scoping for readability

* Update Credits to own epoch tracking
This commit is contained in:
Sagar Dhawan
2019-06-26 10:40:03 -07:00
committed by GitHub
parent 8a64e1ddc3
commit df1c473341
9 changed files with 318 additions and 123 deletions

View File

@ -22,8 +22,8 @@ pub struct Inflation {
/// Duration of grant pool inflation, in years
pub grant_term: f64,
/// Percentage of total inflation allocated to replicator rewards
pub replicator: f64,
/// Percentage of total inflation allocated to storage rewards
pub storage: f64,
}
const DEFAULT_INITIAL: f64 = 0.15;
@ -32,7 +32,7 @@ const DEFAULT_TAPER: f64 = 0.15;
const DEFAULT_FOUNDATION: f64 = 0.05;
const DEFAULT_GRANT: f64 = 0.05;
const DEFAULT_FOUNDATION_GRANT_TERM: f64 = 7.0;
const DEFAULT_REPLICATOR: f64 = 0.10;
const DEFAULT_STORAGE: f64 = 0.10;
impl Default for Inflation {
fn default() -> Self {
@ -44,7 +44,7 @@ impl Default for Inflation {
foundation_term: DEFAULT_FOUNDATION_GRANT_TERM,
grant: DEFAULT_GRANT,
grant_term: DEFAULT_FOUNDATION_GRANT_TERM,
replicator: DEFAULT_REPLICATOR,
storage: DEFAULT_STORAGE,
}
}
}
@ -63,12 +63,12 @@ impl Inflation {
/// portion of total that goes to validators
pub fn validator(&self, year: f64) -> f64 {
self.total(year) - self.replicator(year) - self.grant(year) - self.foundation(year)
self.total(year) - self.storage(year) - self.grant(year) - self.foundation(year)
}
/// portion of total that goes to replicators
pub fn replicator(&self, year: f64) -> f64 {
self.total(year) * self.replicator
/// portion of total that goes to storage mining
pub fn storage(&self, year: f64) -> f64 {
self.total(year) * self.storage
}
/// portion of total that goes to grant pools
@ -105,7 +105,7 @@ mod tests {
assert_eq!(
total,
inflation.validator(*year)
+ inflation.replicator(*year)
+ inflation.storage(*year)
+ inflation.grant(*year)
+ inflation.foundation(*year)
);

View File

@ -16,7 +16,7 @@ crate::solana_name_id!(ID, "Sysca11Rewards11111111111111111111111111111");
#[derive(Serialize, Deserialize, Debug, Default, PartialEq)]
pub struct Rewards {
pub validator_point_value: f64,
pub replicator_point_value: f64,
pub storage_point_value: f64,
}
impl Rewards {
@ -34,13 +34,13 @@ impl Rewards {
pub fn create_account(
lamports: u64,
validator_point_value: f64,
replicator_point_value: f64,
storage_point_value: f64,
) -> Account {
Account::new_data(
lamports,
&Rewards {
validator_point_value,
replicator_point_value,
storage_point_value,
},
&syscall::id(),
)