Skip to content

Commit 11a84a4

Browse files
sdk: evict genesis config (#4076)
* sdk: evict genesis_config * Update sdk/src/lib.rs Co-authored-by: Jon C <[email protected]> * Update sdk/src/lib.rs Co-authored-by: Jon C <[email protected]> * Update sdk/genesis-config/Cargo.toml Co-authored-by: Jon C <[email protected]> * sdk: drop unused deps * pubkey rand feature dev dep * remove serde feature * serde is back now * Update sdk/genesis-config/Cargo.toml Co-authored-by: Jon C <[email protected]> * Update sdk/genesis-config/src/lib.rs Co-authored-by: Jon C <[email protected]> * Update sdk/genesis-config/Cargo.toml Co-authored-by: Jon C <[email protected]> * update lockfile --------- Co-authored-by: Jon C <[email protected]>
1 parent b39a976 commit 11a84a4

File tree

8 files changed

+206
-38
lines changed

8 files changed

+206
-38
lines changed

Cargo.lock

Lines changed: 33 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ members = [
136136
"sdk/frozen-abi",
137137
"sdk/frozen-abi/macro",
138138
"sdk/gen-headers",
139+
"sdk/genesis-config",
139140
"sdk/hard-forks",
140141
"sdk/hash",
141142
"sdk/inflation",
@@ -499,6 +500,7 @@ solana-frozen-abi-macro = { path = "sdk/frozen-abi/macro", version = "=2.2.0" }
499500
solana-tps-client = { path = "tps-client", version = "=2.2.0" }
500501
solana-file-download = { path = "sdk/file-download", version = "=2.2.0" }
501502
solana-genesis = { path = "genesis", version = "=2.2.0" }
503+
solana-genesis-config = { path = "sdk/genesis-config", version = "=2.2.0" }
502504
solana-genesis-utils = { path = "genesis-utils", version = "=2.2.0" }
503505
agave-geyser-plugin-interface = { path = "geyser-plugin-interface", version = "=2.2.0" }
504506
solana-geyser-plugin-manager = { path = "geyser-plugin-manager", version = "=2.2.0" }

programs/sbf/Cargo.lock

Lines changed: 30 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sdk/Cargo.toml

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ default = [
2222
]
2323
full = [
2424
"byteorder",
25-
"chrono",
26-
"memmap2",
2725
"rand",
2826
"rand0-7",
2927
"serde_json",
@@ -39,6 +37,7 @@ full = [
3937
"dep:solana-cluster-type",
4038
"dep:solana-ed25519-program",
4139
"dep:solana-compute-budget-interface",
40+
"dep:solana-genesis-config",
4241
"dep:solana-hard-forks",
4342
"dep:solana-keypair",
4443
"dep:solana-offchain-message",
@@ -76,6 +75,7 @@ frozen-abi = [
7675
"solana-fee-structure/frozen-abi",
7776
"solana-account/frozen-abi",
7877
"solana-cluster-type/frozen-abi",
78+
"solana-genesis-config/frozen-abi",
7979
"solana-hard-forks/frozen-abi",
8080
"solana-inflation/frozen-abi",
8181
"solana-poh-config/frozen-abi",
@@ -97,15 +97,13 @@ bs58 = { workspace = true }
9797
bytemuck = { workspace = true }
9898
bytemuck_derive = { workspace = true }
9999
byteorder = { workspace = true, optional = true }
100-
chrono = { workspace = true, features = ["alloc"], optional = true }
101100
curve25519-dalek = { workspace = true, optional = true }
102101
digest = { workspace = true, optional = true }
103102
ed25519-dalek = { workspace = true, optional = true }
104103
itertools = { workspace = true }
105104
lazy_static = { workspace = true }
106105
libsecp256k1 = { workspace = true, optional = true, features = ["hmac"] }
107106
log = { workspace = true }
108-
memmap2 = { workspace = true, optional = true }
109107
num-derive = { workspace = true }
110108
num-traits = { workspace = true }
111109
qualifier_attr = { workspace = true, optional = true }
@@ -143,6 +141,9 @@ solana-frozen-abi = { workspace = true, optional = true, features = [
143141
solana-frozen-abi-macro = { workspace = true, optional = true, features = [
144142
"frozen-abi",
145143
] }
144+
solana-genesis-config = { workspace = true, features = [
145+
"serde"
146+
], optional = true }
146147
solana-hard-forks = { workspace = true, features = [
147148
"serde",
148149
], optional = true }

sdk/genesis-config/Cargo.toml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
[package]
2+
name = "solana-genesis-config"
3+
description = "A Solana network's genesis config."
4+
documentation = "https://docs.rs/solana-genesis-config"
5+
version = { workspace = true }
6+
authors = { workspace = true }
7+
repository = { workspace = true }
8+
homepage = { workspace = true }
9+
license = { workspace = true }
10+
edition = { workspace = true }
11+
12+
[dependencies]
13+
bincode = { workspace = true }
14+
chrono = { workspace = true, features = ["alloc"] }
15+
memmap2 = { workspace = true }
16+
serde = { workspace = true, optional = true }
17+
serde_derive = { workspace = true, optional = true }
18+
solana-account = { workspace = true }
19+
solana-clock = { workspace = true }
20+
solana-cluster-type = { workspace = true }
21+
solana-epoch-schedule = { workspace = true }
22+
solana-fee-calculator = { workspace = true }
23+
solana-frozen-abi = { workspace = true, optional = true }
24+
solana-frozen-abi-macro = { workspace = true, optional = true }
25+
solana-hash = { workspace = true }
26+
solana-inflation = { workspace = true }
27+
solana-keypair = { workspace = true }
28+
solana-logger = { workspace = true }
29+
solana-native-token = { workspace = true }
30+
solana-poh-config = { workspace = true }
31+
solana-pubkey = { workspace = true }
32+
solana-rent = { workspace = true }
33+
solana-sdk-ids = { workspace = true }
34+
solana-sha256-hasher = { workspace = true }
35+
solana-shred-version = { workspace = true }
36+
solana-signer = { workspace = true }
37+
solana-time-utils = { workspace = true }
38+
39+
[dev-dependencies]
40+
solana-genesis-config = { path = ".", features = ["serde"] }
41+
solana-pubkey = { workspace = true, features = ["rand"] }
42+
43+
[features]
44+
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"]
45+
serde = [
46+
"dep:serde",
47+
"dep:serde_derive",
48+
"solana-account/serde",
49+
"solana-clock/serde",
50+
"solana-cluster-type/serde",
51+
"solana-epoch-schedule/serde",
52+
"solana-fee-calculator/serde",
53+
"solana-inflation/serde",
54+
"solana-poh-config/serde",
55+
"solana-rent/serde",
56+
]
57+
58+
[package.metadata.docs.rs]
59+
targets = ["x86_64-unknown-linux-gnu"]
60+
all-features = true
61+
rustdoc-args = ["--cfg=docsrs"]
62+
63+
[lints]
64+
workspace = true

sdk/src/genesis_config.rs renamed to sdk/genesis-config/src/lib.rs

Lines changed: 39 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,45 @@
11
//! The chain's genesis config.
22
3-
#![cfg(feature = "full")]
4-
3+
#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]
4+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
55
#[deprecated(
66
since = "2.2.0",
77
note = "Use `solana_cluster_type::ClusterType` instead."
88
)]
99
pub use solana_cluster_type::ClusterType;
10+
#[cfg(feature = "frozen-abi")]
11+
use solana_frozen_abi_macro::{frozen_abi, AbiExample};
12+
#[cfg(feature = "serde")]
1013
use {
11-
crate::{
12-
clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT},
13-
epoch_schedule::EpochSchedule,
14-
fee_calculator::FeeRateGovernor,
15-
hash::{hash, Hash},
16-
inflation::Inflation,
17-
poh_config::PohConfig,
18-
pubkey::Pubkey,
19-
rent::Rent,
20-
shred_version::compute_shred_version,
21-
signature::{Keypair, Signer},
22-
system_program,
23-
timing::years_as_slots,
24-
},
2514
bincode::{deserialize, serialize},
2615
chrono::{TimeZone, Utc},
2716
memmap2::Mmap,
28-
solana_account::{Account, AccountSharedData},
17+
solana_hash::Hash,
2918
solana_native_token::lamports_to_sol,
19+
solana_sha256_hasher::hash,
20+
solana_shred_version::compute_shred_version,
3021
std::{
31-
collections::BTreeMap,
3222
fmt,
3323
fs::{File, OpenOptions},
3424
io::Write,
3525
path::{Path, PathBuf},
26+
},
27+
};
28+
use {
29+
solana_account::{Account, AccountSharedData},
30+
solana_clock::{UnixTimestamp, DEFAULT_TICKS_PER_SLOT},
31+
solana_epoch_schedule::EpochSchedule,
32+
solana_fee_calculator::FeeRateGovernor,
33+
solana_inflation::Inflation,
34+
solana_keypair::Keypair,
35+
solana_poh_config::PohConfig,
36+
solana_pubkey::Pubkey,
37+
solana_rent::Rent,
38+
solana_sdk_ids::system_program,
39+
solana_signer::Signer,
40+
solana_time_utils::years_as_slots,
41+
std::{
42+
collections::BTreeMap,
3643
time::{SystemTime, UNIX_EPOCH},
3744
},
3845
};
@@ -49,7 +56,11 @@ pub const UNUSED_DEFAULT: u64 = 1024;
4956
derive(AbiExample),
5057
frozen_abi(digest = "D9VFRSj4fodCuKFC9omQY2zY2Uw8wo6SzJFLeMJaVigm")
5158
)]
52-
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
59+
#[cfg_attr(
60+
feature = "serde",
61+
derive(serde_derive::Deserialize, serde_derive::Serialize)
62+
)]
63+
#[derive(Clone, Debug, PartialEq)]
5364
pub struct GenesisConfig {
5465
/// when the network (bootstrap validator) was started relative to the UNIX Epoch
5566
pub creation_time: UnixTimestamp,
@@ -132,15 +143,18 @@ impl GenesisConfig {
132143
}
133144
}
134145

146+
#[cfg(feature = "serde")]
135147
pub fn hash(&self) -> Hash {
136148
let serialized = serialize(&self).unwrap();
137149
hash(&serialized)
138150
}
139151

152+
#[cfg(feature = "serde")]
140153
fn genesis_filename(ledger_path: &Path) -> PathBuf {
141154
Path::new(ledger_path).join(DEFAULT_GENESIS_FILE)
142155
}
143156

157+
#[cfg(feature = "serde")]
144158
pub fn load(ledger_path: &Path) -> Result<Self, std::io::Error> {
145159
let filename = Self::genesis_filename(ledger_path);
146160
let file = OpenOptions::new()
@@ -170,6 +184,7 @@ impl GenesisConfig {
170184
Ok(genesis_config)
171185
}
172186

187+
#[cfg(feature = "serde")]
173188
pub fn write(&self, ledger_path: &Path) -> Result<(), std::io::Error> {
174189
let serialized = serialize(&self).map_err(|err| {
175190
std::io::Error::new(
@@ -216,6 +231,7 @@ impl GenesisConfig {
216231
}
217232
}
218233

234+
#[cfg(feature = "serde")]
219235
impl fmt::Display for GenesisConfig {
220236
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
221237
write!(
@@ -273,13 +289,9 @@ impl fmt::Display for GenesisConfig {
273289
}
274290
}
275291

276-
#[cfg(test)]
292+
#[cfg(all(feature = "serde", test))]
277293
mod tests {
278-
use {
279-
super::*,
280-
crate::signature::{Keypair, Signer},
281-
std::path::PathBuf,
282-
};
294+
use {super::*, solana_signer::Signer, std::path::PathBuf};
283295

284296
fn make_tmp_path(name: &str) -> PathBuf {
285297
let out_dir = std::env::var("FARF_DIR").unwrap_or_else(|_| "farf".to_string());
@@ -310,10 +322,10 @@ mod tests {
310322
AccountSharedData::new(10_000, 0, &Pubkey::default()),
311323
);
312324
config.add_account(
313-
solana_sdk::pubkey::new_rand(),
325+
solana_pubkey::new_rand(),
314326
AccountSharedData::new(1, 0, &Pubkey::default()),
315327
);
316-
config.add_native_instruction_processor("hi".to_string(), solana_sdk::pubkey::new_rand());
328+
config.add_native_instruction_processor("hi".to_string(), solana_pubkey::new_rand());
317329

318330
assert_eq!(config.accounts.len(), 2);
319331
assert!(config

0 commit comments

Comments
 (0)