Skip to content

get-sysvar: extract from solana-sysvar#770

Open
grod220 wants to merge 1 commit into
anza-xyz:masterfrom
grod220:get-sysvar-crate
Open

get-sysvar: extract from solana-sysvar#770
grod220 wants to merge 1 commit into
anza-xyz:masterfrom
grod220:get-sysvar-crate

Conversation

@grod220

@grod220 grod220 commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

Inspired from #766 (comment)

We want to lighten solana-sysvar and let each sysvar's accessor live in its own type crate rather than all of them sitting in solana-sysvar. The blocker is get_sysvar which needs to be shared across crates. This PR extracts it into a low-level solana-get-sysvar crate that type crates can depend on directly.

Changes

  • new solana-get-sysvar crate
    • get_sysvar / get_sysvar_unchecked copied over
    • new GetSysvarStub trait
    • no-std support (adds default no-std feature)
  • solana-sysvar (no public API change)
    • Test helpers repointed to set_get_sysvar_stub

@github-actions

Copy link
Copy Markdown
Contributor

If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client @solana/sysvars (example)
Thank you for keeping the JavaScript clients in sync with the Rust clients.

@grod220 grod220 force-pushed the get-sysvar-crate branch from 24dc25d to 200beee Compare June 15, 2026 11:59
@github-actions

Copy link
Copy Markdown
Contributor

If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client @solana/sysvars (example)
Thank you for keeping the JavaScript clients in sync with the Rust clients.

@grod220 grod220 force-pushed the get-sysvar-crate branch from 200beee to 5215d04 Compare June 15, 2026 12:02
@github-actions

Copy link
Copy Markdown
Contributor

If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client @solana/sysvars (example)
Thank you for keeping the JavaScript clients in sync with the Rust clients.

Comment thread get-sysvar/src/lib.rs
Comment on lines +20 to +23
/// Syscall success code.
//
// Defined in solana-program-entrypoint as [`SUCCESS`](https://github.com/anza-xyz/solana-sdk/blob/program-entrypoint@v2.2.1/program-entrypoint/src/lib.rs#L35).
const SUCCESS: u64 = 0;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Locally defined to avoid std import (program-entrypoint)

Comment thread get-sysvar/src/lib.rs
Comment on lines +96 to +101
// Off-chain no-std builds have neither runtime syscalls nor host stubs.
#[cfg(all(not(target_os = "solana"), not(feature = "std")))]
{
let _ = (sysvar_id, var_addr, offset, length);
solana_program_error::UNSUPPORTED_SYSVAR
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given the no-std feature, we need an explicit host + no-std fallback that raises

Comment thread get-sysvar/src/lib.rs
@@ -0,0 +1,102 @@
//! Access to the `sol_get_sysvar` syscall, used to fetch sysvar data from the runtime.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality copied over from sysvar/src/lib.rs but with some modifications

  • sol_get_sysvar() for better re-use
  • fix code comments referencing agave master branch w/ broken links
  • using new stub

Comment thread get-sysvar/src/stubs.rs
@@ -0,0 +1,46 @@
use std::sync::{Arc, RwLock};

/// Off-chain stub implementation of the `sol_get_sysvar` syscall.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is meant to be a simple replacement for the use of program_stubs.rs which seems to be on its way out. Added as there still seems to be need to run tests and inject mocks offchain (sysvar crates own tests & program-test crate).

Comment on lines -145 to -156
#[allow(dead_code)]
pub(crate) fn sol_get_sysvar(
sysvar_id_addr: *const u8,
var_addr: *mut u8,
offset: u64,
length: u64,
) -> u64 {
SYSCALL_STUBS
.read()
.unwrap()
.sol_get_sysvar(sysvar_id_addr, var_addr, offset, length)
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that get_sysvar reads solana-get-sysvar's registry instead of SYSCALL_STUBS, the mocks have to install there instead.

Anyone mocking sysvars (agave's program-test) must install a GetSysvarStub via set_get_sysvar_stub instead. This is an important follow up.

@grod220 grod220 force-pushed the get-sysvar-crate branch from 5215d04 to 2127efd Compare June 15, 2026 12:54
@github-actions

Copy link
Copy Markdown
Contributor

If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client @solana/sysvars (example)
Thank you for keeping the JavaScript clients in sync with the Rust clients.

@grod220 grod220 requested review from buffalojoec and joncinque June 15, 2026 13:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant