From 4bb87935f52222e48047e076b313af9f71cb21fb Mon Sep 17 00:00:00 2001 From: Jon C Date: Mon, 28 Oct 2024 13:17:01 +0100 Subject: [PATCH] sdk: Extract last-restart-slot crate (#3272) * sdk: Extract last-restart-slot crate #### Problem Just about all of the sysvars have been extract in some way from solana-program, but the last restart slot sysvar has not. #### Summary of changes Following most of the other crates that have done this, move it out. * Remove last_restart_slot.rs --- Cargo.lock | 10 ++++++++++ Cargo.toml | 1 + programs/sbf/Cargo.lock | 10 ++++++++++ sdk/last-restart-slot/Cargo.toml | 23 +++++++++++++++++++++++ sdk/last-restart-slot/src/lib.rs | 15 +++++++++++++++ sdk/program/Cargo.toml | 1 + sdk/program/src/last_restart_slot.rs | 10 ---------- sdk/program/src/lib.rs | 3 ++- 8 files changed, 62 insertions(+), 11 deletions(-) create mode 100644 sdk/last-restart-slot/Cargo.toml create mode 100644 sdk/last-restart-slot/src/lib.rs delete mode 100644 sdk/program/src/last_restart_slot.rs diff --git a/Cargo.lock b/Cargo.lock index ea925fbfcbb2f9..efa8b74c85b856 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -6956,6 +6956,15 @@ dependencies = [ "tiny-bip39", ] +[[package]] +name = "solana-last-restart-slot" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-macro", +] + [[package]] name = "solana-lattice-hash" version = "2.1.0" @@ -7416,6 +7425,7 @@ dependencies = [ "solana-frozen-abi-macro", "solana-hash", "solana-instruction", + "solana-last-restart-slot", "solana-logger", "solana-msg", "solana-native-token", diff --git a/Cargo.toml b/Cargo.toml index 3b3ed11f0c7166..6e80d68cf73e5e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -435,6 +435,7 @@ solana-gossip = { path = "gossip", version = "=2.1.0" } solana-hash = { path = "sdk/hash", version = "=2.1.0", default-features = false } solana-inline-spl = { path = "inline-spl", version = "=2.1.0" } solana-instruction = { path = "sdk/instruction", version = "=2.1.0", default-features = false } +solana-last-restart-slot = { path = "sdk/last-restart-slot", version = "=2.1.0" } solana-lattice-hash = { path = "lattice-hash", version = "=2.1.0" } solana-ledger = { path = "ledger", version = "=2.1.0" } solana-loader-v4-program = { path = "programs/loader-v4", version = "=2.1.0" } diff --git a/programs/sbf/Cargo.lock b/programs/sbf/Cargo.lock index ca9f8ec5720ecd..0e897cb60a2d14 100644 --- a/programs/sbf/Cargo.lock +++ b/programs/sbf/Cargo.lock @@ -5498,6 +5498,15 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "solana-last-restart-slot" +version = "2.1.0" +dependencies = [ + "serde", + "serde_derive", + "solana-sdk-macro", +] + [[package]] name = "solana-lattice-hash" version = "2.1.0" @@ -5786,6 +5795,7 @@ dependencies = [ "solana-fee-calculator", "solana-hash", "solana-instruction", + "solana-last-restart-slot", "solana-msg", "solana-native-token", "solana-program-entrypoint", diff --git a/sdk/last-restart-slot/Cargo.toml b/sdk/last-restart-slot/Cargo.toml new file mode 100644 index 00000000000000..7091a13dfd6a16 --- /dev/null +++ b/sdk/last-restart-slot/Cargo.toml @@ -0,0 +1,23 @@ +[package] +name = "solana-last-restart-slot" +description = "Types and utilities for the Solana LastRestartSlot sysvar." +documentation = "https://docs.rs/solana-last-restart-slot" +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 } +solana-sdk-macro = { workspace = true } + +[features] +serde = ["dep:serde", "dep:serde_derive"] + +[package.metadata.docs.rs] +targets = ["x86_64-unknown-linux-gnu"] +all-features = true +rustdoc-args = ["--cfg=docsrs"] diff --git a/sdk/last-restart-slot/src/lib.rs b/sdk/last-restart-slot/src/lib.rs new file mode 100644 index 00000000000000..0ab962f147b98c --- /dev/null +++ b/sdk/last-restart-slot/src/lib.rs @@ -0,0 +1,15 @@ +//! Information about the last restart slot (hard fork). +#![cfg_attr(docsrs, feature(doc_auto_cfg))] + +use solana_sdk_macro::CloneZeroed; + +#[repr(C)] +#[cfg_attr( + feature = "serde", + derive(serde_derive::Deserialize, serde_derive::Serialize) +)] +#[derive(Debug, CloneZeroed, PartialEq, Eq, Default)] +pub struct LastRestartSlot { + /// The last restart `Slot`. + pub last_restart_slot: u64, +} diff --git a/sdk/program/Cargo.toml b/sdk/program/Cargo.toml index 6eab63fe4e5f97..5d9c062098dbf0 100644 --- a/sdk/program/Cargo.toml +++ b/sdk/program/Cargo.toml @@ -53,6 +53,7 @@ solana-instruction = { workspace = true, default-features = false, features = [ "serde", "std", ] } +solana-last-restart-slot = { workspace = true, features = ["serde"] } solana-msg = { workspace = true } solana-native-token = { workspace = true } solana-program-entrypoint = { workspace = true } diff --git a/sdk/program/src/last_restart_slot.rs b/sdk/program/src/last_restart_slot.rs deleted file mode 100644 index 880685a096b5b1..00000000000000 --- a/sdk/program/src/last_restart_slot.rs +++ /dev/null @@ -1,10 +0,0 @@ -//! Information about the last restart slot (hard fork). - -use {solana_clock::Slot, solana_sdk_macro::CloneZeroed}; - -#[repr(C)] -#[derive(Serialize, Deserialize, Debug, CloneZeroed, PartialEq, Eq, Default)] -pub struct LastRestartSlot { - /// The last restart `Slot`. - pub last_restart_slot: Slot, -} diff --git a/sdk/program/src/lib.rs b/sdk/program/src/lib.rs index 9b47d19a261b18..26df24aeeae252 100644 --- a/sdk/program/src/lib.rs +++ b/sdk/program/src/lib.rs @@ -487,7 +487,6 @@ pub mod incinerator; pub mod instruction; pub mod keccak; pub mod lamports; -pub mod last_restart_slot; pub mod loader_instruction; pub mod loader_upgradeable_instruction; pub mod loader_v4; @@ -522,6 +521,8 @@ pub use solana_borsh::v0_10 as borsh0_10; pub use solana_borsh::v1 as borsh1; #[deprecated(since = "2.1.0", note = "Use `solana-fee-calculator` crate instead")] pub use solana_fee_calculator as fee_calculator; +#[deprecated(since = "2.1.0", note = "Use `solana-last-restart-slot` crate instead")] +pub use solana_last_restart_slot as last_restart_slot; #[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-program-pack` crate instead")]