get-sysvar: extract from solana-sysvar#770
Conversation
|
If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client |
24dc25d to
200beee
Compare
|
If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client |
200beee to
5215d04
Compare
|
If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client |
| /// 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; |
There was a problem hiding this comment.
Locally defined to avoid std import (program-entrypoint)
| // 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 | ||
| } |
There was a problem hiding this comment.
Given the no-std feature, we need an explicit host + no-std fallback that raises
| @@ -0,0 +1,102 @@ | |||
| //! Access to the `sol_get_sysvar` syscall, used to fetch sysvar data from the runtime. | |||
There was a problem hiding this comment.
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
| @@ -0,0 +1,46 @@ | |||
| use std::sync::{Arc, RwLock}; | |||
|
|
|||
| /// Off-chain stub implementation of the `sol_get_sysvar` syscall. | |||
There was a problem hiding this comment.
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).
| #[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) | ||
| } |
There was a problem hiding this comment.
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.
5215d04 to
2127efd
Compare
|
If this PR represents a change to the sysvar layout, please open a follow-up PR to update the JavaScript client |
Inspired from #766 (comment)
We want to lighten
solana-sysvarand let each sysvar's accessor live in its own type crate rather than all of them sitting insolana-sysvar. The blocker isget_sysvarwhich needs to be shared across crates. This PR extracts it into a low-levelsolana-get-sysvarcrate that type crates can depend on directly.Changes
solana-get-sysvarcrateget_sysvar/get_sysvar_uncheckedcopied overGetSysvarStubtraitsolana-sysvar(no public API change)set_get_sysvar_stub