From 5b256d28d09a282237775edfcdae1628e08bd2c1 Mon Sep 17 00:00:00 2001 From: kevinheavey Date: Sun, 29 Sep 2024 17:13:46 +0400 Subject: [PATCH] extract epoch-info crate --- Cargo.lock | 9 ++++++++ Cargo.toml | 4 +++- programs/sbf/Cargo.lock | 9 ++++++++ sdk/Cargo.toml | 1 + sdk/epoch-info/Cargo.toml | 23 +++++++++++++++++++ .../epoch_info.rs => epoch-info/src/lib.rs} | 14 ++++++----- sdk/src/lib.rs | 3 ++- 7 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 sdk/epoch-info/Cargo.toml rename sdk/{src/epoch_info.rs => epoch-info/src/lib.rs} (72%) diff --git a/Cargo.lock b/Cargo.lock index 2acd2130e695de..e3d1f7e6e93f34 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6620,6 +6620,14 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-epoch-info" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-epoch-schedule" version = "2.1.0" @@ -7919,6 +7927,7 @@ dependencies = [ "solana-bn254", "solana-decode-error", "solana-derivation-path", + "solana-epoch-info", "solana-feature-set", "solana-frozen-abi", "solana-frozen-abi-macro", diff --git a/Cargo.toml b/Cargo.toml index 03e897c488d865..08ac5810766b12 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -109,6 +109,7 @@ members = [ "sdk/clock", "sdk/decode-error", "sdk/derivation-path", + "sdk/epoch-info", "sdk/epoch-schedule", "sdk/feature-set", "sdk/gen-headers", @@ -410,7 +411,7 @@ solana-define-syscall = { path = "define-syscall", version = "=2.1.0" } solana-derivation-path = { path = "sdk/derivation-path", version = "=2.1.0" } solana-download-utils = { path = "download-utils", version = "=2.1.0" } solana-entry = { path = "entry", version = "=2.1.0" } -solana-program-entrypoint = { path = "sdk/program-entrypoint", version = "=2.1.0" } +solana-epoch-info = { path = "sdk/epoch-info", version = "=2.1.0" } solana-epoch-schedule = { path = "sdk/epoch-schedule", version = "=2.1.0" } solana-faucet = { path = "faucet", version = "=2.1.0" } solana-feature-set = { path = "sdk/feature-set", version = "=2.1.0" } @@ -447,6 +448,7 @@ solana-poh = { path = "poh", version = "=2.1.0" } solana-poseidon = { path = "poseidon", version = "=2.1.0" } solana-precompile-error = { path = "sdk/precompile-error", version = "=2.1.0" } solana-program = { path = "sdk/program", version = "=2.1.0", default-features = false } +solana-program-entrypoint = { path = "sdk/program-entrypoint", version = "=2.1.0" } solana-program-error = { path = "sdk/program-error", version = "=2.1.0" } solana-program-memory = { path = "sdk/program-memory", version = "=2.1.0" } solana-program-option = { path = "sdk/program-option", version = "=2.1.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index 7e987d12543ce6..c0b5694433a099 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5264,6 +5264,14 @@ dependencies = [ "solana-sdk", ] +[[package]] +name = "solana-epoch-info" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", +] + [[package]] name = "solana-epoch-schedule" version = "2.1.0" @@ -6682,6 +6690,7 @@ dependencies = [ "solana-bn254", "solana-decode-error", "solana-derivation-path", + "solana-epoch-info", "solana-feature-set", "solana-instruction", "solana-native-token", diff --git a/sdk/Cargo.toml b/sdk/Cargo.toml index 4872798563020d..40534dde5989dc 100644 --- a/sdk/Cargo.toml +++ b/sdk/Cargo.toml @@ -90,6 +90,7 @@ solana-account = { workspace = true, features = ["bincode"] } solana-bn254 = { workspace = true } solana-decode-error = { workspace = true } solana-derivation-path = { workspace = true } +solana-epoch-info = { workspace = true, features = ["serde"] } solana-feature-set = { workspace = true } solana-frozen-abi = { workspace = true, optional = true, features = [ "frozen-abi", diff --git a/sdk/epoch-info/Cargo.toml b/sdk/epoch-info/Cargo.toml new file mode 100644 index 00000000000000..4f20c53e43cbd7 --- /dev/null +++ b/sdk/epoch-info/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "solana-epoch-info" +description = "Information about the current Solana epoch." +documentation = "https://docs.rs/solana-epoch-info" +version = { workspace = true } +authors = { workspace = true } +repository = { workspace = true } +homepage = { workspace = true } +license = { workspace = true } +edition = { workspace = true } + +[dependencies] +serde = { workspace = true, optional = true } +serde_derive = { workspace = true, optional = true } + +[features] +serde = ["dep:serde", "dep:serde_derive"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] + +[lints] +workspace = true diff --git a/sdk/src/epoch_info.rs b/sdk/epoch-info/src/lib.rs similarity index 72% rename from sdk/src/epoch_info.rs rename to sdk/epoch-info/src/lib.rs index c324c38d8a1aa7..ccc46ae5e96426 100644 --- a/sdk/src/epoch_info.rs +++ b/sdk/epoch-info/src/lib.rs @@ -4,13 +4,15 @@ //! //! [`getEpochInfo`]: https://solana.com/docs/rpc/http/getepochinfo -use crate::clock::{Epoch, Slot}; - -#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)] -#[serde(rename_all = "camelCase")] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize), + serde(rename_all = "camelCase") +)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct EpochInfo { /// The current epoch - pub epoch: Epoch, + pub epoch: u64, /// The current slot, relative to the start of the current epoch pub slot_index: u64, @@ -19,7 +21,7 @@ pub struct EpochInfo { pub slots_in_epoch: u64, /// The absolute current slot - pub absolute_slot: Slot, + pub absolute_slot: u64, /// The current block height pub block_height: u64, diff --git a/sdk/src/lib.rs b/sdk/src/lib.rs index e1d9503a75de20..23489b8dec72dc 100644 --- a/sdk/src/lib.rs +++ b/sdk/src/lib.rs @@ -65,7 +65,6 @@ pub mod deserialize_utils; pub mod ed25519_instruction; pub mod entrypoint; pub mod entrypoint_deprecated; -pub mod epoch_info; pub mod epoch_rewards_hasher; pub mod example_mocks; pub mod exit; @@ -118,6 +117,8 @@ pub use solana_bn254 as alt_bn128; pub use solana_decode_error as decode_error; #[deprecated(since = "2.1.0", note = "Use `solana-derivation-path` crate instead")] pub use solana_derivation_path as derivation_path; +#[deprecated(since = "2.1.0", note = "Use `solana-epoch-info` crate instead")] +pub use solana_epoch_info as epoch_info; #[deprecated(since = "2.1.0", note = "Use `solana-feature-set` crate instead")] pub use solana_feature_set as feature_set; #[deprecated(since = "2.1.0", note = "Use `solana-program-memory` crate instead")]