Skip to content

Commit

Permalink
Syscall: GetEpochStake (anza-xyz#1152)
Browse files Browse the repository at this point in the history
* SVM: add `get_vote_accounts` callback

* program-runtime: invoke context: add `vote_accounts`

* sdk: add feature gate for sol-get-epoch-stake

* syscall: get-epoch-stake

* syscall: get-epoch-stake: tests

* drop `get_compute_meter`

* refactor for total stake

* refactor API for total stake
  • Loading branch information
buffalojoec authored Jun 11, 2024
1 parent 362c605 commit b150801
Show file tree
Hide file tree
Showing 21 changed files with 427 additions and 4 deletions.
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions program-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ solana-frozen-abi-macro = { workspace = true, optional = true }
solana-measure = { workspace = true }
solana-metrics = { workspace = true }
solana-sdk = { workspace = true }
solana-vote = { workspace = true }
solana_rbpf = { workspace = true }
thiserror = { workspace = true }

Expand Down
19 changes: 19 additions & 0 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ use {
IndexOfAccount, InstructionAccount, TransactionAccount, TransactionContext,
},
},
solana_vote::vote_account::VoteAccountsHashMap,
std::{
alloc::Layout,
cell::RefCell,
Expand Down Expand Up @@ -146,19 +147,25 @@ impl BpfAllocator {

pub struct EnvironmentConfig<'a> {
pub blockhash: Hash,
epoch_total_stake: Option<u64>,
epoch_vote_accounts: Option<&'a VoteAccountsHashMap>,
pub feature_set: Arc<FeatureSet>,
pub lamports_per_signature: u64,
sysvar_cache: &'a SysvarCache,
}
impl<'a> EnvironmentConfig<'a> {
pub fn new(
blockhash: Hash,
epoch_total_stake: Option<u64>,
epoch_vote_accounts: Option<&'a VoteAccountsHashMap>,
feature_set: Arc<FeatureSet>,
lamports_per_signature: u64,
sysvar_cache: &'a SysvarCache,
) -> Self {
Self {
blockhash,
epoch_total_stake,
epoch_vote_accounts,
feature_set,
lamports_per_signature,
sysvar_cache,
Expand Down Expand Up @@ -614,6 +621,16 @@ impl<'a> InvokeContext<'a> {
self.environment_config.sysvar_cache
}

/// Get cached epoch total stake.
pub fn get_epoch_total_stake(&self) -> Option<u64> {
self.environment_config.epoch_total_stake
}

/// Get cached epoch vote accounts.
pub fn get_epoch_vote_accounts(&self) -> Option<&VoteAccountsHashMap> {
self.environment_config.epoch_vote_accounts
}

// Should alignment be enforced during user pointer translation
pub fn get_check_aligned(&self) -> bool {
self.transaction_context
Expand Down Expand Up @@ -710,6 +727,8 @@ macro_rules! with_mock_invoke_context {
});
let environment_config = EnvironmentConfig::new(
Hash::default(),
None,
None,
Arc::new(FeatureSet::all_enabled()),
0,
&sysvar_cache,
Expand Down
1 change: 1 addition & 0 deletions programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ assert_matches = { workspace = true }
memoffset = { workspace = true }
rand = { workspace = true }
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
solana-vote = { workspace = true }
test-case = { workspace = true }

[lib]
Expand Down
Loading

0 comments on commit b150801

Please sign in to comment.