From 884ff1c86ef91539f7cc53065bcec302dac5fc18 Mon Sep 17 00:00:00 2001 From: Sonic Date: Sun, 25 Jan 2026 23:54:38 +0200 Subject: [PATCH] feat: make solana-inflation crate no_std --- Cargo.lock | 8 ++++++++ inflation/Cargo.toml | 1 + inflation/src/lib.rs | 7 ++++++- scripts/check-no-std.sh | 1 + 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 15cb4e9b6..54157622a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1888,6 +1888,12 @@ version = "0.2.170" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "875b3680cb2f8f71bdcf9a30f38d48282f5d3c95cbf9b3fa57269bb5d5c06828" +[[package]] +name = "libm" +version = "0.2.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981" + [[package]] name = "light-poseidon" version = "0.2.0" @@ -2027,6 +2033,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", + "libm", ] [[package]] @@ -3434,6 +3441,7 @@ dependencies = [ name = "solana-inflation" version = "3.0.0" dependencies = [ + "num-traits", "serde", "serde_derive", "solana-frozen-abi", diff --git a/inflation/Cargo.toml b/inflation/Cargo.toml index d8b2b4191..70d4e75ea 100644 --- a/inflation/Cargo.toml +++ b/inflation/Cargo.toml @@ -17,6 +17,7 @@ frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"] serde = ["dep:serde", "dep:serde_derive"] [dependencies] +num-traits = { workspace = true, default-features = false, features = ["libm"] } serde = { workspace = true, optional = true } serde_derive = { workspace = true, optional = true } solana-frozen-abi = { workspace = true, optional = true } diff --git a/inflation/src/lib.rs b/inflation/src/lib.rs index 53bf0f294..957167ed6 100644 --- a/inflation/src/lib.rs +++ b/inflation/src/lib.rs @@ -1,9 +1,14 @@ //! configuration for network inflation +#![no_std] #![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(feature = "frozen-abi", feature(min_specialization))] #[cfg(feature = "serde")] use serde_derive::{Deserialize, Serialize}; +// The import is required for no_std compilation because .powf() which comes from the Float trait (not from std's inherent f64 methods). +#[allow(unused_imports)] +use num_traits::Float; + #[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] #[cfg_attr(feature = "serde", derive(Deserialize, Serialize))] #[derive(PartialEq, Clone, Debug, Copy)] @@ -89,7 +94,7 @@ impl Inflation { /// inflation rate at year pub fn total(&self, year: f64) -> f64 { assert!(year >= 0.0); - let tapered = self.initial * ((1.0 - self.taper).powf(year)); + let tapered = self.initial * (1.0 - self.taper).powf(year); if tapered > self.terminal { tapered diff --git a/scripts/check-no-std.sh b/scripts/check-no-std.sh index 24311114c..7346c75b3 100755 --- a/scripts/check-no-std.sh +++ b/scripts/check-no-std.sh @@ -21,6 +21,7 @@ no_std_crates=( -p solana-epoch-stake -p solana-fee-calculator -p solana-hash + -p solana-inflation -p solana-instruction-view -p solana-keccak-hasher -p solana-msg