From b903158543d4d9ce3906885fcf1140647448272a Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2020 03:36:47 +0000 Subject: [PATCH] getInflationRate now only supports the current epoch (#10887) (cherry picked from commit d53228e69dffc123ba20c5d9f84723181eb86b9e) Co-authored-by: Michael Vines --- core/src/rpc.rs | 63 +++++++++--------------------------- docs/src/apps/jsonrpc-api.md | 4 +-- 2 files changed, 17 insertions(+), 50 deletions(-) diff --git a/core/src/rpc.rs b/core/src/rpc.rs index 7f5f817788..3bdbfdc9c9 100644 --- a/core/src/rpc.rs +++ b/core/src/rpc.rs @@ -29,7 +29,7 @@ use solana_ledger::{ use solana_perf::packet::PACKET_DATA_SIZE; use solana_runtime::{accounts::AccountAddressFilter, bank::Bank, log_collector::LogCollector}; use solana_sdk::{ - clock::{Epoch, Slot, UnixTimestamp}, + clock::{Slot, UnixTimestamp}, commitment_config::{CommitmentConfig, CommitmentLevel}, epoch_info::EpochInfo, epoch_schedule::EpochSchedule, @@ -194,11 +194,10 @@ impl JsonRpcRequestProcessor { Ok(self.bank(commitment)?.inflation().into()) } - pub fn get_inflation_rate(&self, epoch: Option) -> Result { + pub fn get_inflation_rate(&self) -> Result { let bank = self.bank(None)?; - let operating_mode = bank.operating_mode(); - let epoch = epoch.unwrap_or_else(|| bank.epoch()); - let inflation = solana_genesis_programs::get_inflation_for_epoch(operating_mode, epoch); + let epoch = bank.epoch(); + let inflation = bank.inflation(); let year = (bank.epoch_schedule().get_last_slot_in_epoch(epoch)) as f64 / bank.slots_per_year(); @@ -796,11 +795,7 @@ pub trait RpcSol { ) -> Result; #[rpc(meta, name = "getInflationRate")] - fn get_inflation_rate( - &self, - meta: Self::Metadata, - epoch: Option, - ) -> Result; + fn get_inflation_rate(&self, meta: Self::Metadata) -> Result; #[rpc(meta, name = "getEpochSchedule")] fn get_epoch_schedule(&self, meta: Self::Metadata) -> Result; @@ -1065,13 +1060,9 @@ impl RpcSol for RpcSolImpl { meta.get_inflation_governor(commitment) } - fn get_inflation_rate( - &self, - meta: Self::Metadata, - epoch: Option, - ) -> Result { + fn get_inflation_rate(&self, meta: Self::Metadata) -> Result { debug!("get_inflation_rate rpc request received"); - meta.get_inflation_rate(epoch) + meta.get_inflation_rate() } fn get_epoch_schedule(&self, meta: Self::Metadata) -> Result { @@ -2074,35 +2065,7 @@ pub mod tests { let expected_inflation_governor: RpcInflationGovernor = bank.inflation().into(); assert_eq!(inflation_governor, expected_inflation_governor); - let req = r#"{"jsonrpc":"2.0","id":1,"method":"getInflationRate"}"#; // Queries current epoch by default - let rep = io.handle_request_sync(&req, meta.clone()); - let res: Response = serde_json::from_str(&rep.expect("actual response")) - .expect("actual response deserialization"); - let inflation_rate: RpcInflationRate = if let Response::Single(res) = res { - if let Output::Success(res) = res { - serde_json::from_value(res.result).unwrap() - } else { - panic!("Expected success"); - } - } else { - panic!("Expected single response"); - }; - let operating_mode = bank.operating_mode(); - let inflation = solana_genesis_programs::get_inflation_for_epoch(operating_mode, 0); - let year = (bank.epoch_schedule().get_last_slot_in_epoch(0)) as f64 / bank.slots_per_year(); - let expected_inflation_rate = RpcInflationRate { - total: inflation.total(year), - validator: inflation.validator(year), - foundation: inflation.foundation(year), - epoch: 0, - }; - assert_eq!(inflation_rate, expected_inflation_rate); - - let epoch = 40_000_000; // After default foundation term - let req = format!( - r#"{{"jsonrpc":"2.0","id":1,"method":"getInflationRate","params":[{}]}}"#, - epoch - ); // Queries current epoch by default + let req = r#"{"jsonrpc":"2.0","id":1,"method":"getInflationRate"}"#; // Queries current epoch let rep = io.handle_request_sync(&req, meta); let res: Response = serde_json::from_str(&rep.expect("actual response")) .expect("actual response deserialization"); @@ -2115,10 +2078,14 @@ pub mod tests { } else { panic!("Expected single response"); }; + let inflation = bank.inflation(); + let epoch = bank.epoch(); + let year = + (bank.epoch_schedule().get_last_slot_in_epoch(epoch)) as f64 / bank.slots_per_year(); let expected_inflation_rate = RpcInflationRate { - total: 0.015, - validator: 0.015, - foundation: 0.0, + total: inflation.total(year), + validator: inflation.validator(year), + foundation: inflation.foundation(year), epoch, }; assert_eq!(inflation_rate, expected_inflation_rate); diff --git a/docs/src/apps/jsonrpc-api.md b/docs/src/apps/jsonrpc-api.md index c7c4b45e5e..3a29911487 100644 --- a/docs/src/apps/jsonrpc-api.md +++ b/docs/src/apps/jsonrpc-api.md @@ -666,11 +666,11 @@ curl -X POST -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1, "m ### getInflationRate -Returns the specific inflation values for a particular epoch +Returns the specific inflation values for the current epoch #### Parameters: -* `` - (optional) Epoch, default is the current epoch +None #### Results: