Access to special accounts with dynamically-updated data.
Sysvars are special accounts that contain dynamically-updated data about the
network cluster, the blockchain history, and the executing transaction. Each
sysvar is defined in its own submodule within this module. The [clock],
[epoch_schedule], and [rent] sysvars are most useful to on-chain
programs.
Simple sysvars implement the [Sysvar::get] method, which loads a sysvar
directly from the runtime, as in this example that logs the clock sysvar:
use AccountInfo;
use msg;
use Sysvar;
use ProgramResult;
use Pubkey;
Since Solana sysvars are accounts, if the AccountInfo is provided to the
program, then the program can deserialize the sysvar with wincode to access
its data, as in this example that again logs the [clock] sysvar.
use ;
use Clock;
use msg;
use ;
use Pubkey;
use clock;
When possible, programs should prefer to call Sysvar::get instead of
deserializing with wincode, as the latter imposes extra
overhead of deserialization while also requiring the sysvar account address
be passed to the program, wasting the limited space available to
transactions. Deserializing sysvars that can instead be retrieved with
Sysvar::get should be only be considered for compatibility with older
programs that pass around sysvar accounts.
Some sysvars are too large to deserialize within a program, and
deserializing them may exhaust the program's compute budget. Some sysvars do
not implement Sysvar::get and return an error. Some sysvars have custom deserializers
that do not implement the Sysvar trait. These cases are documented in the
modules for individual sysvars.
All sysvar accounts are owned by the account identified by sysvar::ID.
For more details see the Solana documentation on sysvars.