diff --git a/Cargo.lock b/Cargo.lock index ab5874283bc759..6bf406650b3988 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -7764,6 +7764,18 @@ dependencies = [ "solana-version", ] +[[package]] +name = "solana-poh-config" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", + "solana-clock", + "solana-frozen-abi", + "solana-frozen-abi-macro", + "static_assertions", +] + [[package]] name = "solana-poseidon" version = "2.2.0" @@ -8534,6 +8546,7 @@ dependencies = [ "solana-logger", "solana-native-token", "solana-packet", + "solana-poh-config", "solana-precompile-error", "solana-precompiles", "solana-presigner", diff --git a/Cargo.toml b/Cargo.toml index c62c59226c78d2..b9a4bc19b3cdb0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -142,6 +142,7 @@ members = [ "sdk/package-metadata", "sdk/package-metadata-macro", "sdk/packet", + "sdk/poh-config", "sdk/precompile-error", "sdk/precompiles", "sdk/presigner", @@ -508,6 +509,7 @@ solana-package-metadata-macro = { path = "sdk/package-metadata-macro", version = solana-packet = { path = "sdk/packet", version = "=2.2.0" } solana-perf = { path = "perf", version = "=2.2.0" } solana-poh = { path = "poh", version = "=2.2.0" } +solana-poh-config = { path = "sdk/poh-config", version = "=2.2.0" } solana-poseidon = { path = "poseidon", version = "=2.2.0" } solana-precompile-error = { path = "sdk/precompile-error", version = "=2.2.0" } solana-precompiles = { path = "sdk/precompiles", version = "=2.2.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 4aabc16f3c955e..8530c14c3e29bc 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -6090,6 +6090,14 @@ dependencies = [ "thiserror 2.0.4", ] +[[package]] +name = "solana-poh-config" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-poseidon" version = "2.2.0" @@ -7233,6 +7241,7 @@ dependencies = [ "solana-keypair", "solana-native-token", "solana-packet", + "solana-poh-config", "solana-precompile-error", "solana-precompiles", "solana-presigner", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index a704a315a420b8..32f60be7e24b20 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -72,6 +72,7 @@ frozen-abi = [ "solana-account/frozen-abi", "solana-cluster-type/frozen-abi", "solana-inflation/frozen-abi", + "solana-poh-config/frozen-abi", "solana-program/frozen-abi", "solana-reward-info/frozen-abi", "solana-short-vec/frozen-abi", @@ -143,6 +144,7 @@ solana-keypair = { workspace = true, optional = true, features = [ ] } solana-native-token = { workspace = true } solana-packet = { workspace = true, features = ["bincode", "serde"] } +solana-poh-config = { workspace = true, features = ["serde"] } solana-precompile-error = { workspace = true, optional = true } solana-precompiles = { workspace = true, optional = true } solana-presigner = { workspace = true, optional = true } diff --git a/sdk/poh-config/Cargo.toml b/sdk/poh-config/Cargo.toml new file mode 100644 index 00000000000000..e0e07976085aea --- /dev/null +++ b/sdk/poh-config/Cargo.toml @@ -0,0 +1,39 @@ +[package] +name = "solana-poh-config" +description = "Definitions of Solana's proof of history." +documentation = "https://docs.rs/solana-poh-config" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] + +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } +solana-frozen-abi = { workspace = true, optional = true, features = [ + "frozen-abi", +] } +solana-frozen-abi-macro = { workspace = true, optional = true, features = [ + "frozen-abi", +] } + +[dev-dependencies] +solana-clock = { workspace = true } +static_assertions = { workspace = true } + +[features] +frozen-abi = [ + "dep:solana-frozen-abi", + "dep:solana-frozen-abi-macro", +] +serde = ["dep:serde", "dep:serde_derive"] + +[lints] +workspace = true diff --git a/sdk/poh-config/src/lib.rs b/sdk/poh-config/src/lib.rs new file mode 100644 index 00000000000000..36cd5198ddbcca --- /dev/null +++ b/sdk/poh-config/src/lib.rs @@ -0,0 +1,53 @@ +//! Definitions of Solana's proof of history. +#![cfg_attr(docsrs, feature(doc_auto_cfg))] +#![cfg_attr(feature = "frozen-abi", feature(min_specialization))] + +use std::time::Duration; + +// inlined to avoid solana-clock dep +const DEFAULT_TICKS_PER_SECOND: u64 = 160; +#[cfg(test)] +static_assertions::const_assert_eq!( + DEFAULT_TICKS_PER_SECOND, + solana_clock::DEFAULT_TICKS_PER_SECOND +); + +#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(Clone, Debug, Eq, PartialEq)] +pub struct PohConfig { + /// The target tick rate of the cluster. + pub target_tick_duration: Duration, + + /// The target total tick count to be produced; used for testing only + pub target_tick_count: Option, + + /// How many hashes to roll before emitting the next tick entry. + /// None enables "Low power mode", which makes the validator sleep + /// for `target_tick_duration` instead of hashing + pub hashes_per_tick: Option, +} + +impl PohConfig { + pub fn new_sleep(target_tick_duration: Duration) -> Self { + Self { + target_tick_duration, + hashes_per_tick: None, + target_tick_count: None, + } + } +} + +// the !=0 check was previously done by the unchecked_div_by_const macro +#[cfg(test)] +static_assertions::const_assert!(DEFAULT_TICKS_PER_SECOND != 0); +const DEFAULT_SLEEP_MICROS: u64 = (1000 * 1000) / DEFAULT_TICKS_PER_SECOND; + +impl Default for PohConfig { + fn default() -> Self { + Self::new_sleep(Duration::from_micros(DEFAULT_SLEEP_MICROS)) + } +} diff --git a/sdk/src/genesis_config.rs b/sdk/src/genesis_config.rs index bd71cb09a6b47b..af86e8e3005659 100644 --- a/sdk/src/genesis_config.rs +++ b/sdk/src/genesis_config.rs @@ -47,7 +47,7 @@ pub const UNUSED_DEFAULT: u64 = 1024; #[cfg_attr( feature = "frozen-abi", derive(AbiExample), - frozen_abi(digest = "iDVgqt11gc2Fnu2mrkMsfsjfonDQ5mGX26vQwLivo7M") + frozen_abi(digest = "D9VFRSj4fodCuKFC9omQY2zY2Uw8wo6SzJFLeMJaVigm") )] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] pub struct GenesisConfig { diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index 752ad612a5c7b5..cee2da124fb030 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -78,7 +78,6 @@ pub mod native_loader; pub mod net; pub mod nonce_account; pub mod offchain_message; -pub mod poh_config; pub mod precompiles; pub mod program_utils; pub mod pubkey; @@ -132,6 +131,8 @@ pub use solana_fee_structure as fee; pub use solana_inflation as inflation; #[deprecated(since = "2.1.0", note = "Use `solana-packet` crate instead")] pub use solana_packet as packet; +#[deprecated(since = "2.2.0", note = "Use `solana-poh-config` crate instead")] +pub use solana_poh_config as poh_config; #[deprecated(since = "2.1.0", note = "Use `solana-program-memory` crate instead")] pub use solana_program_memory as program_memory; #[deprecated(since = "2.1.0", note = "Use `solana_pubkey::pubkey` instead")] @@ -224,10 +225,10 @@ macro_rules! saturating_add_assign { }}; } -#[macro_use] -extern crate serde_derive; pub extern crate bs58; extern crate log as logger; +#[cfg_attr(not(target_os = "solana"), macro_use)] +extern crate serde_derive; #[cfg_attr(feature = "frozen-abi", macro_use)] #[cfg(feature = "frozen-abi")] diff --git a/sdk/src/poh_config.rs b/sdk/src/poh_config.rs deleted file mode 100644 index 8e3d12719ef8a9..00000000000000 --- a/sdk/src/poh_config.rs +++ /dev/null @@ -1,40 +0,0 @@ -//! Definitions of Solana's proof of history. - -use { - crate::{clock::DEFAULT_TICKS_PER_SECOND, unchecked_div_by_const}, - std::time::Duration, -}; - -#[cfg_attr(feature = "frozen-abi", derive(AbiExample))] -#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] -pub struct PohConfig { - /// The target tick rate of the cluster. - pub target_tick_duration: Duration, - - /// The target total tick count to be produced; used for testing only - pub target_tick_count: Option, - - /// How many hashes to roll before emitting the next tick entry. - /// None enables "Low power mode", which makes the validator sleep - /// for `target_tick_duration` instead of hashing - pub hashes_per_tick: Option, -} - -impl PohConfig { - pub fn new_sleep(target_tick_duration: Duration) -> Self { - Self { - target_tick_duration, - hashes_per_tick: None, - target_tick_count: None, - } - } -} - -impl Default for PohConfig { - fn default() -> Self { - Self::new_sleep(Duration::from_micros(unchecked_div_by_const!( - 1000 * 1000, - DEFAULT_TICKS_PER_SECOND - ))) - } -} diff --git a/svm/examples/Cargo.lock b/svm/examples/Cargo.lock index 7bd58e61e953d3..54e71014bb9343 100644 --- a/svm/examples/Cargo.lock +++ b/svm/examples/Cargo.lock @@ -5910,6 +5910,14 @@ dependencies = [ "thiserror 2.0.4", ] +[[package]] +name = "solana-poh-config" +version = "2.2.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-poseidon" version = "2.2.0" @@ -6561,6 +6569,7 @@ dependencies = [ "solana-keypair", "solana-native-token", "solana-packet", + "solana-poh-config", "solana-precompile-error", "solana-precompiles", "solana-presigner",