Przeglądaj źródła

Allow setting custom fixed inflation rate to solana-test-validator (#6661)

* Add inflation parameter to TestValidatorGenesis.
Add --inflation-fixed <RATE> option to solana-test-validator.

* Reject negative and NaN inflation rate values.

* Update the other Cargo.lock files.

* Use PartialOrd::partial_cmp() because clippy.
Kristofer Peterson 4 miesięcy temu
rodzic
commit
bb5f9dc9dc

+ 2 - 0
Cargo.lock

@@ -446,6 +446,7 @@ dependencies = [
  "solana-geyser-plugin-manager",
  "solana-gossip",
  "solana-hash",
+ "solana-inflation",
  "solana-keypair",
  "solana-ledger",
  "solana-logger",
@@ -11012,6 +11013,7 @@ dependencies = [
  "solana-fee-calculator",
  "solana-geyser-plugin-manager",
  "solana-gossip",
+ "solana-inflation",
  "solana-instruction",
  "solana-keypair",
  "solana-ledger",

+ 2 - 0
programs/sbf/Cargo.lock

@@ -193,6 +193,7 @@ dependencies = [
  "solana-geyser-plugin-manager",
  "solana-gossip",
  "solana-hash",
+ "solana-inflation",
  "solana-keypair",
  "solana-ledger",
  "solana-logger",
@@ -9295,6 +9296,7 @@ dependencies = [
  "solana-fee-calculator",
  "solana-geyser-plugin-manager",
  "solana-gossip",
+ "solana-inflation",
  "solana-instruction",
  "solana-keypair",
  "solana-ledger",

+ 1 - 0
svm/examples/Cargo.lock

@@ -8395,6 +8395,7 @@ dependencies = [
  "solana-fee-calculator",
  "solana-geyser-plugin-manager",
  "solana-gossip",
+ "solana-inflation",
  "solana-instruction",
  "solana-keypair",
  "solana-ledger",

+ 1 - 0
test-validator/Cargo.toml

@@ -33,6 +33,7 @@ solana-feature-gate-interface = { workspace = true }
 solana-fee-calculator = { workspace = true }
 solana-geyser-plugin-manager = { workspace = true }
 solana-gossip = { workspace = true }
+solana-inflation = { workspace = true }
 solana-instruction = { workspace = true }
 solana-keypair = { workspace = true }
 solana-ledger = { workspace = true }

+ 12 - 0
test-validator/src/lib.rs

@@ -28,6 +28,7 @@ use {
         cluster_info::{BindIpAddrs, ClusterInfo, Node, NodeConfig},
         contact_info::Protocol,
     },
+    solana_inflation::Inflation,
     solana_instruction::{AccountMeta, Instruction},
     solana_keypair::{read_keypair_file, write_keypair_file, Keypair},
     solana_ledger::{
@@ -121,6 +122,7 @@ pub struct TestValidatorGenesis {
     upgradeable_programs: Vec<UpgradeableProgramInfo>,
     ticks_per_slot: Option<u64>,
     epoch_schedule: Option<EpochSchedule>,
+    inflation: Option<Inflation>,
     node_config: TestValidatorNodeConfig,
     pub validator_exit: Arc<RwLock<Exit>>,
     pub start_progress: Arc<RwLock<ValidatorStartProgress>>,
@@ -153,6 +155,7 @@ impl Default for TestValidatorGenesis {
             upgradeable_programs: Vec::<UpgradeableProgramInfo>::default(),
             ticks_per_slot: Option::<u64>::default(),
             epoch_schedule: Option::<EpochSchedule>::default(),
+            inflation: Option::<Inflation>::default(),
             node_config: TestValidatorNodeConfig::default(),
             validator_exit: Arc::<RwLock<Exit>>::default(),
             start_progress: Arc::<RwLock<ValidatorStartProgress>>::default(),
@@ -252,6 +255,11 @@ impl TestValidatorGenesis {
         self
     }
 
+    pub fn inflation(&mut self, inflation: Inflation) -> &mut Self {
+        self.inflation = Some(inflation);
+        self
+    }
+
     pub fn rent(&mut self, rent: Rent) -> &mut Self {
         self.rent = rent;
         self
@@ -945,6 +953,10 @@ impl TestValidator {
             genesis_config.ticks_per_slot = ticks_per_slot;
         }
 
+        if let Some(inflation) = config.inflation {
+            genesis_config.inflation = inflation;
+        }
+
         for feature in feature_set {
             genesis_utils::activate_feature(&mut genesis_config, feature);
         }

+ 1 - 0
validator/Cargo.toml

@@ -51,6 +51,7 @@ solana-genesis-utils = { workspace = true }
 solana-geyser-plugin-manager = { workspace = true }
 solana-gossip = { workspace = true }
 solana-hash = { workspace = true }
+solana-inflation = { workspace = true }
 solana-keypair = { workspace = true }
 solana-ledger = { workspace = true }
 solana-logger = "=2.3.1"

+ 7 - 0
validator/src/bin/solana-test-validator.rs

@@ -17,6 +17,7 @@ use {
     solana_core::consensus::tower_storage::FileTowerStorage,
     solana_epoch_schedule::EpochSchedule,
     solana_faucet::faucet::run_local_faucet_with_port,
+    solana_inflation::Inflation,
     solana_keypair::{read_keypair_file, write_keypair_file, Keypair},
     solana_logger::redirect_stderr_to_file,
     solana_native_token::sol_to_lamports,
@@ -158,6 +159,7 @@ fn main() {
     let faucet_port = value_t_or_exit!(matches, "faucet_port", u16);
     let ticks_per_slot = value_t!(matches, "ticks_per_slot", u64).ok();
     let slots_per_epoch = value_t!(matches, "slots_per_epoch", Slot).ok();
+    let inflation_fixed = value_t!(matches, "inflation_fixed", f64).ok();
     let gossip_host = matches.value_of("gossip_host").map(|gossip_host| {
         warn!("--gossip-host is deprecated. Use --bind-address instead.");
         solana_net_utils::parse_host(gossip_host).unwrap_or_else(|err| {
@@ -380,6 +382,7 @@ fn main() {
             ("mint_address", "--mint"),
             ("ticks_per_slot", "--ticks-per-slot"),
             ("slots_per_epoch", "--slots-per-epoch"),
+            ("inflation_fixed", "--inflation-fixed"),
             ("faucet_sol", "--faucet-sol"),
             ("deactivate_feature", "--deactivate-feature"),
         ] {
@@ -569,6 +572,10 @@ fn main() {
         genesis.rent = Rent::with_slots_per_epoch(slots_per_epoch);
     }
 
+    if let Some(inflation_fixed) = inflation_fixed {
+        genesis.inflation(Inflation::new_fixed(inflation_fixed));
+    }
+
     genesis.gossip_host(advertised_ip);
 
     if let Some(gossip_port) = gossip_port {

+ 21 - 1
validator/src/cli.rs

@@ -37,7 +37,7 @@ use {
         DEFAULT_MAX_UNSTAKED_CONNECTIONS, DEFAULT_QUIC_ENDPOINTS,
     },
     solana_tpu_client::tpu_client::{DEFAULT_TPU_CONNECTION_POOL_SIZE, DEFAULT_VOTE_USE_QUIC},
-    std::{path::PathBuf, str::FromStr},
+    std::{cmp::Ordering, path::PathBuf, str::FromStr},
 };
 
 pub mod thread_args;
@@ -638,6 +638,26 @@ pub fn test_app<'a>(version: &'a str, default_args: &'a DefaultTestArgs) -> App<
                      this parameter is silently ignored",
                 ),
         )
+        .arg(
+            Arg::with_name("inflation_fixed")
+                .long("inflation-fixed")
+                .value_name("RATE")
+                .validator(|value| {
+                    value
+                        .parse::<f64>()
+                        .map_err(|err| format!("error parsing '{value}': {err}"))
+                        .and_then(|rate| match rate.partial_cmp(&0.0) {
+			    Some(Ordering::Greater) | Some(Ordering::Equal) => Ok(()),
+			    Some(Ordering::Less) | None => Err(String::from("value must be >= 0")),
+                        })
+                })
+                .takes_value(true)
+                .allow_hyphen_values(true)
+                .help(
+                    "Override default inflation with fixed rate. If the ledger already exists then \
+                     this parameter is silently ignored",
+                ),
+        )
         .arg(
             Arg::with_name("gossip_port")
                 .long("gossip-port")