Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

extract poh-config crate #3855

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ members = [
"sdk/package-metadata",
"sdk/package-metadata-macro",
"sdk/packet",
"sdk/poh-config",
"sdk/precompile-error",
"sdk/precompiles",
"sdk/presigner",
Expand Down Expand Up @@ -502,6 +503,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" }
Expand Down
9 changes: 9 additions & 0 deletions programs/sbf/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,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",
Expand Down Expand Up @@ -140,6 +141,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 }
Expand Down
39 changes: 39 additions & 0 deletions sdk/poh-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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
53 changes: 53 additions & 0 deletions sdk/poh-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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<u64>,

/// 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<u64>,
}

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))
}
}
2 changes: 1 addition & 1 deletion sdk/src/genesis_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 3 additions & 2 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,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;
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -218,7 +219,7 @@ macro_rules! saturating_add_assign {
}};
}

#[macro_use]
#[cfg_attr(not(target_os = "solana"), macro_use)]
extern crate serde_derive;
pub extern crate bs58;
extern crate log as logger;
Expand Down
40 changes: 0 additions & 40 deletions sdk/src/poh_config.rs

This file was deleted.

9 changes: 9 additions & 0 deletions svm/examples/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading