Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove SVM's dependency on vote crate #3671

Merged
merged 9 commits into from
Nov 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion program-runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ solana-metrics = { workspace = true }
solana-sdk = { workspace = true }
solana-timings = { workspace = true }
solana-type-overrides = { workspace = true }
solana-vote = { workspace = true }
solana_rbpf = { workspace = true }
thiserror = { workspace = true }

Expand Down
25 changes: 13 additions & 12 deletions program-runtime/src/invoke_context.rs
pgarg66 marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ use {
},
solana_timings::{ExecuteDetailsTimings, ExecuteTimings},
solana_type_overrides::sync::{atomic::Ordering, Arc},
solana_vote::vote_account::VoteAccountsHashMap,
std::{
alloc::Layout,
cell::RefCell,
Expand Down Expand Up @@ -151,25 +150,25 @@ impl BpfAllocator {
pub struct EnvironmentConfig<'a> {
pub blockhash: Hash,
pub blockhash_lamports_per_signature: u64,
epoch_total_stake: Option<u64>,
epoch_vote_accounts: Option<&'a VoteAccountsHashMap>,
epoch_total_stake: u64,
get_epoch_vote_account_stake_callback: &'a dyn Fn(&'a Pubkey) -> u64,
pub feature_set: Arc<FeatureSet>,
sysvar_cache: &'a SysvarCache,
}
impl<'a> EnvironmentConfig<'a> {
pub fn new(
blockhash: Hash,
blockhash_lamports_per_signature: u64,
epoch_total_stake: Option<u64>,
epoch_vote_accounts: Option<&'a VoteAccountsHashMap>,
epoch_total_stake: u64,
get_epoch_vote_account_stake_callback: &'a dyn Fn(&'a Pubkey) -> u64,
feature_set: Arc<FeatureSet>,
sysvar_cache: &'a SysvarCache,
) -> Self {
Self {
blockhash,
blockhash_lamports_per_signature,
epoch_total_stake,
epoch_vote_accounts,
get_epoch_vote_account_stake_callback,
feature_set,
sysvar_cache,
}
Expand Down Expand Up @@ -658,13 +657,15 @@ impl<'a> InvokeContext<'a> {
}

/// Get cached epoch total stake.
pub fn get_epoch_total_stake(&self) -> Option<u64> {
pub fn get_epoch_total_stake(&self) -> 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
/// Get cached stake for the epoch vote account.
pub fn get_epoch_vote_account_stake(&self, pubkey: &'a Pubkey) -> u64 {
(self
.environment_config
.get_epoch_vote_account_stake_callback)(pubkey)
}

// Should alignment be enforced during user pointer translation
Expand Down Expand Up @@ -765,8 +766,8 @@ macro_rules! with_mock_invoke_context {
let environment_config = EnvironmentConfig::new(
Hash::default(),
0,
None,
None,
0,
&|_| 0,
Arc::new(FeatureSet::all_enabled()),
&sysvar_cache,
);
Expand Down
1 change: 0 additions & 1 deletion programs/bpf_loader/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ assert_matches = { workspace = true }
memoffset = { workspace = true }
rand = { workspace = true }
solana-sdk = { workspace = true, features = ["dev-context-only-utils"] }
solana-vote = { workspace = true, features = ["dev-context-only-utils"] }
test-case = { workspace = true }

[lib]
Expand Down
37 changes: 14 additions & 23 deletions programs/bpf_loader/src/syscalls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2071,7 +2071,7 @@ declare_builtin_function!(
// - Compute budget is exceeded.
// - Otherwise, the syscall returns a `u64` integer representing the total active
// stake on the cluster for the current epoch.
Ok(invoke_context.get_epoch_total_stake().unwrap_or(0))
Ok(invoke_context.get_epoch_total_stake())
} else {
// As specified by SIMD-0133: If `var_addr` is _not_ a null pointer:
//
Expand Down Expand Up @@ -2103,16 +2103,7 @@ declare_builtin_function!(
let check_aligned = invoke_context.get_check_aligned();
let vote_address = translate_type::<Pubkey>(memory_mapping, var_addr, check_aligned)?;

Ok(
if let Some(vote_accounts) = invoke_context.get_epoch_vote_accounts() {
vote_accounts
.get(vote_address)
.map(|(stake, _)| *stake)
.unwrap_or(0)
} else {
0
},
)
Ok(invoke_context.get_epoch_vote_account_stake(vote_address))
}
}
);
Expand Down Expand Up @@ -2147,8 +2138,7 @@ mod tests {
last_restart_slot::LastRestartSlot,
},
},
solana_vote::vote_account::VoteAccount,
buffalojoec marked this conversation as resolved.
Show resolved Hide resolved
std::{collections::HashMap, mem, str::FromStr},
std::{mem, str::FromStr},
test_case::test_case,
};

Expand Down Expand Up @@ -4801,8 +4791,8 @@ mod tests {
invoke_context.environment_config = EnvironmentConfig::new(
Hash::default(),
0,
Some(expected_total_stake),
None, // Vote accounts are not needed for this test.
expected_total_stake,
&|_| 0, // Vote accounts are not needed for this test.
Arc::<FeatureSet>::default(),
&sysvar_cache,
);
Expand Down Expand Up @@ -4845,18 +4835,19 @@ mod tests {
compute_budget.compute_unit_limit = expected_cus;

let vote_address = Pubkey::new_unique();
let mut vote_accounts_map = HashMap::new();
vote_accounts_map.insert(
vote_address,
(expected_epoch_stake, VoteAccount::new_random()),
);

with_mock_invoke_context!(invoke_context, transaction_context, vec![]);
let callback = |pubkey: &Pubkey| {
if *pubkey == vote_address {
expected_epoch_stake
} else {
0
}
};
invoke_context.environment_config = EnvironmentConfig::new(
Hash::default(),
0,
None, // Total stake is not needed for this test.
Some(&vote_accounts_map),
0, // Total stake is not needed for this test.
&callback,
Arc::<FeatureSet>::default(),
&sysvar_cache,
);
Expand Down
2 changes: 0 additions & 2 deletions programs/sbf/Cargo.lock

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

11 changes: 9 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,7 @@ impl Bank {
.unwrap()
.stats
.reset();

new
}

Expand Down Expand Up @@ -3767,8 +3768,7 @@ impl Bank {
let processing_environment = TransactionProcessingEnvironment {
blockhash,
blockhash_lamports_per_signature,
epoch_total_stake: Some(self.get_current_epoch_total_stake()),
epoch_vote_accounts: Some(self.get_current_epoch_vote_accounts()),
epoch_total_stake: self.get_current_epoch_total_stake(),
feature_set: Arc::clone(&self.feature_set),
fee_lamports_per_signature: self.fee_structure.lamports_per_signature,
rent_collector: Some(&rent_collector_with_metrics),
Expand Down Expand Up @@ -7129,6 +7129,13 @@ impl TransactionProcessingCallback for Bank {
self.inspect_account_for_accounts_lt_hash(address, &account_state, is_writable);
}
}

fn get_current_epoch_vote_account_stake(&self, vote_address: &Pubkey) -> u64 {
self.get_current_epoch_vote_accounts()
.get(vote_address)
.map(|(stake, _)| (*stake))
.unwrap_or(0)
}
}

#[cfg(feature = "dev-context-only-utils")]
Expand Down
4 changes: 2 additions & 2 deletions runtime/src/bank/builtins/core_bpf_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ impl Bank {
EnvironmentConfig::new(
Hash::default(),
0,
None,
None,
0,
&|_| 0,
self.feature_set.clone(),
&sysvar_cache,
),
Expand Down
1 change: 0 additions & 1 deletion svm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ solana-svm-transaction = { workspace = true }
solana-system-program = { workspace = true }
solana-timings = { workspace = true }
solana-type-overrides = { workspace = true }
solana-vote = { workspace = true }
thiserror = { workspace = true }

[lib]
Expand Down
5 changes: 3 additions & 2 deletions svm/doc/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ pub trait TransactionProcessingCallback {
fn get_account_shared_data(&self, pubkey: &Pubkey) -> Option<AccountSharedData>;

fn add_builtin_account(&self, _name: &str, _program_id: &Pubkey) {}

fn get_current_epoch_vote_account_stake(&self, _vote_address: &Pubkey) -> u64;
}
```

Expand Down Expand Up @@ -171,9 +173,8 @@ The transaction processor requires consumers to provide values describing
the runtime environment to use for processing transactions.

- `blockhash`: The blockhash to use for the transaction batch.
- `epoch_total_stake`: The total stake for the current epoch.
- `epoch_vote_accounts`: The vote accounts for the current epoch.
- `feature_set`: Runtime feature set to use for the transaction batch.
- `epoch_total_stake`: The total stake for the current epoch.
- `fee_structure`: Fee structure to use for assessing transaction fees.
- `lamports_per_signature`: Lamports per signature to charge per transaction.
- `rent_collector`: Rent collector to use for the transaction batch.
Expand Down
3 changes: 0 additions & 3 deletions svm/examples/Cargo.lock

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

1 change: 0 additions & 1 deletion svm/examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ solana-sdk = { path = "../../sdk/" }
solana-svm = { path = "../" }
solana-system-program = { path = "../../programs/system" }
solana-version = { path = "../../version" }
solana-vote = { path = "../../vote" }
solana-test-validator = { path = "../../test-validator" }
solana-transaction-status = { path = "../../transaction-status" }
spl-associated-token-account = "=6.0.0"
Expand Down
1 change: 0 additions & 1 deletion svm/examples/json-rpc/server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ solana-svm = { workspace = true }
solana-system-program = { workspace = true }
solana-transaction-status = { workspace = true }
solana-version = { workspace = true }
solana-vote = { workspace = true }
spl-token-2022 = { workspace = true, features = ["no-entrypoint"] }
tokio = { workspace = true, features = ["full"] }
tokio-util = { workspace = true, features = ["codec", "compat"] }
Expand Down
14 changes: 2 additions & 12 deletions svm/examples/json-rpc/server/src/rpc_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use {
},
solana_sdk::{
account::{from_account, Account, AccountSharedData, ReadableAccount},
clock::{Epoch, Slot, MAX_PROCESSING_AGE, MAX_TRANSACTION_FORWARDING_DELAY},
clock::{Slot, MAX_PROCESSING_AGE, MAX_TRANSACTION_FORWARDING_DELAY},
commitment_config::CommitmentConfig,
exit::Exit,
hash::Hash,
Expand Down Expand Up @@ -61,7 +61,6 @@ use {
map_inner_instructions, parse_ui_inner_instructions, TransactionBinaryEncoding,
UiTransactionEncoding,
},
solana_vote::vote_account::VoteAccountsHashMap,
spl_token_2022::{
extension::{
interest_bearing_mint::InterestBearingConfig, BaseStateWithExtensions,
Expand Down Expand Up @@ -435,14 +434,6 @@ impl JsonRpcRequestProcessor {
.unwrap_or_default()
}

fn epoch_total_stake(&self, _epoch: Epoch) -> Option<u64> {
Some(u64::default())
}

fn epoch_vote_accounts(&self, _epoch: Epoch) -> Option<&VoteAccountsHashMap> {
None
}

fn get_account(&self, pubkey: &Pubkey) -> Option<AccountSharedData> {
let account_map: HashMap<Pubkey, AccountSharedData> =
HashMap::from_iter(self.account_map.clone());
Expand Down Expand Up @@ -547,8 +538,7 @@ impl JsonRpcRequestProcessor {
let processing_environment = TransactionProcessingEnvironment {
blockhash,
blockhash_lamports_per_signature: lamports_per_signature,
epoch_total_stake: self.epoch_total_stake(Epoch::default()),
epoch_vote_accounts: self.epoch_vote_accounts(Epoch::default()),
epoch_total_stake: 0,
feature_set: Arc::clone(&bank.feature_set),
fee_lamports_per_signature: lamports_per_signature,
rent_collector: None,
Expand Down
3 changes: 1 addition & 2 deletions svm/examples/paytube/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,7 @@ impl PayTubeChannel {
let processing_environment = TransactionProcessingEnvironment {
blockhash: Hash::default(),
blockhash_lamports_per_signature: fee_structure.lamports_per_signature,
epoch_total_stake: None,
epoch_vote_accounts: None,
epoch_total_stake: 0,
feature_set: Arc::new(feature_set),
fee_lamports_per_signature: fee_structure.lamports_per_signature,
rent_collector: Some(&rent_collector),
Expand Down
Loading
Loading