Skip to content

Commit a00f1b5

Browse files
v2.1: sdk: Extract solana-sysvar-id crate (backport of #3309) (#3352)
sdk: Extract `solana-sysvar-id` crate (#3309) * sdk: Extract `solana-sysvar` crate #### Problem The sysvars in `solana-program` are tightly coupled with types that exist in `solana-program`. For example, all of the special sysvar getters like `Rent::get()` are implemented through a macro that falls back to using `program_stubs`. Because of this tight coupling, it's difficult to pull out bits for the sysvars. #### Summary of changes After numerous attempts, I've decided to keep it simple and only extract `SysvarId`, its helper macros, and `get_sysvar`. To go along with that, all of the separated sysvar crates now implement the sysvar ids themselves under a new `sysvar` feature. This new feature might be overkill, so let me know if we should just include the sysvar ids by default. I went with a feature to include an implementation using the `sol_get_sysvar` syscall in the future. It was really messy to include the `Sysvar` trait from `solana-program` because it falls back to using `bincode`, which we know performs poorly for on-chain programs. So the future idea is to create a new `Sysvar` trait in `solana-sysvar` which will require fewer bits to deserialize sysvars. Let me know what you think about this PR and the future idea! Note that I'll need to rebase this on top of #3249 and #3272 when they land. * Add solana-define-syscall for solana builds * Rename solana-sysvar -> solana-sysvar-id * Move back `get_sysvar` to solana-program * Update lockfile for v2.2 (cherry picked from commit 838c195) # Conflicts: # Cargo.toml Co-authored-by: Jon C <[email protected]>
1 parent 7b7e6bb commit a00f1b5

38 files changed

+251
-100
lines changed

Cargo.lock

Lines changed: 16 additions & 0 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
@@ -142,6 +142,7 @@ members = [
142142
"sdk/slot-hashes",
143143
"sdk/slot-history",
144144
"sdk/stable-layout",
145+
"sdk/sysvar-id",
145146
"sdk/transaction-error",
146147
"send-transaction-service",
147148
"short-vec",
@@ -505,6 +506,7 @@ solana-svm-example-paytube = { path = "svm/examples/paytube", version = "=2.1.1"
505506
solana-svm-rent-collector = { path = "svm-rent-collector", version = "=2.1.1" }
506507
solana-svm-transaction = { path = "svm-transaction", version = "=2.1.1" }
507508
solana-system-program = { path = "programs/system", version = "=2.1.1" }
509+
solana-sysvar-id = { path = "sdk/sysvar-id", version = "=2.1.1" }
508510
solana-test-validator = { path = "test-validator", version = "=2.1.1" }
509511
solana-thin-client = { path = "thin-client", version = "=2.1.1" }
510512
solana-transaction-error = { path = "sdk/transaction-error", version = "=2.1.1" }

programs/sbf/Cargo.lock

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

sdk/clock/Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,17 @@ edition = { workspace = true }
1313
serde = { workspace = true, optional = true }
1414
serde_derive = { workspace = true, optional = true }
1515
solana-sdk-macro = { workspace = true }
16+
solana-sysvar-id = { workspace = true, optional = true }
1617

1718
[dev-dependencies]
19+
solana-clock = { path = ".", features = ["sysvar"] }
1820
static_assertions = { workspace = true }
1921

2022
[features]
2123
serde = ["dep:serde", "dep:serde_derive"]
24+
sysvar = ["dep:solana-sysvar-id"]
2225

2326
[package.metadata.docs.rs]
2427
targets = ["x86_64-unknown-linux-gnu"]
28+
all-features = true
29+
rustdoc-args = ["--cfg=docsrs"]

sdk/clock/src/lib.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
//!
2121
//! [oracle]: https://docs.solanalabs.com/implemented-proposals/validator-timestamp-oracle
2222
#![no_std]
23+
#![cfg_attr(docsrs, feature(doc_auto_cfg))]
24+
25+
#[cfg(feature = "sysvar")]
26+
pub mod sysvar;
2327

2428
#[cfg(feature = "serde")]
2529
use serde_derive::{Deserialize, Serialize};

sdk/clock/src/sysvar.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use {crate::Clock, solana_sysvar_id::declare_sysvar_id};
2+
3+
declare_sysvar_id!("SysvarC1ock11111111111111111111111111111111", Clock);

sdk/epoch-schedule/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,20 @@ serde_derive = { workspace = true, optional = true }
1515
solana-frozen-abi = { workspace = true, optional = true }
1616
solana-frozen-abi-macro = { workspace = true, optional = true }
1717
solana-sdk-macro = { workspace = true }
18+
solana-sysvar-id = { workspace = true, optional = true }
1819

1920
[package.metadata.docs.rs]
2021
targets = ["x86_64-unknown-linux-gnu"]
2122

2223
[dev-dependencies]
2324
solana-clock = { workspace = true }
25+
solana-epoch-schedule = { path = ".", features = ["sysvar"] }
2426
static_assertions = { workspace = true }
2527

2628
[features]
2729
frozen-abi = ["dep:solana-frozen-abi", "dep:solana-frozen-abi-macro"]
2830
serde = ["dep:serde", "dep:serde_derive"]
31+
sysvar = ["dep:solana-sysvar-id"]
2932

3033
[lints]
3134
workspace = true

sdk/epoch-schedule/src/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@
1717
#[cfg(feature = "frozen-abi")]
1818
extern crate std;
1919

20+
#[cfg(feature = "sysvar")]
21+
pub mod sysvar;
22+
2023
#[cfg(feature = "serde")]
2124
use serde_derive::{Deserialize, Serialize};
2225
use solana_sdk_macro::CloneZeroed;

sdk/epoch-schedule/src/sysvar.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use {crate::EpochSchedule, solana_sysvar_id::declare_sysvar_id};
2+
3+
declare_sysvar_id!("SysvarEpochSchedu1e111111111111111111111111", EpochSchedule);

sdk/last-restart-slot/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@ edition = { workspace = true }
1313
serde = { workspace = true, optional = true }
1414
serde_derive = { workspace = true, optional = true }
1515
solana-sdk-macro = { workspace = true }
16+
solana-sysvar-id = { workspace = true, optional = true }
1617

1718
[features]
1819
serde = ["dep:serde", "dep:serde_derive"]
20+
sysvar = ["dep:solana-sysvar-id"]
1921

2022
[package.metadata.docs.rs]
2123
targets = ["x86_64-unknown-linux-gnu"]

0 commit comments

Comments
 (0)