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 6 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
2 changes: 0 additions & 2 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,10 +40,10 @@ use {
},
solana_timings::{ExecuteDetailsTimings, ExecuteTimings},
solana_type_overrides::sync::{atomic::Ordering, Arc},
solana_vote::vote_account::VoteAccountsHashMap,
std::{
alloc::Layout,
cell::RefCell,
collections::HashMap,
fmt::{self, Debug},
rc::Rc,
},
Expand Down Expand Up @@ -151,25 +151,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,
epoch_vote_stake: &'a HashMap<Pubkey, u64>,
pgarg66 marked this conversation as resolved.
Show resolved Hide resolved
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,
epoch_vote_stake: &'a HashMap<Pubkey, u64>,
feature_set: Arc<FeatureSet>,
sysvar_cache: &'a SysvarCache,
) -> Self {
Self {
blockhash,
blockhash_lamports_per_signature,
epoch_total_stake,
epoch_vote_accounts,
epoch_vote_stake,
feature_set,
sysvar_cache,
}
Expand Down Expand Up @@ -658,13 +658,13 @@ 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 epoch vote accounts.
pub fn get_epoch_vote_stake(&self) -> &HashMap<Pubkey, u64> {
self.environment_config.epoch_vote_stake
}

// Should alignment be enforced during user pointer translation
Expand Down Expand Up @@ -762,11 +762,12 @@ macro_rules! with_mock_invoke_context {
}
}
});
let epoch_vote_stake = HashMap::default();
let environment_config = EnvironmentConfig::new(
Hash::default(),
0,
None,
None,
0,
&epoch_vote_stake,
Arc::new(FeatureSet::all_enabled()),
&sysvar_cache,
);
Expand Down
2 changes: 1 addition & 1 deletion programs/bpf_loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ mod tests {
rent::Rent,
system_program, sysvar,
},
std::{fs::File, io::Read, ops::Range, sync::atomic::AtomicU64},
std::{collections::HashMap, fs::File, io::Read, ops::Range, sync::atomic::AtomicU64},
};

fn process_instruction(
Expand Down
1 change: 1 addition & 0 deletions programs/bpf_loader/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,7 @@ mod tests {
},
std::{
cell::RefCell,
collections::HashMap,
mem::transmute,
rc::Rc,
slice::{self, from_raw_parts, from_raw_parts_mut},
Expand Down
1 change: 1 addition & 0 deletions programs/bpf_loader/src/syscalls/cpi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,7 @@ mod tests {
},
std::{
cell::{Cell, RefCell},
collections::HashMap,
mem, ptr,
rc::Rc,
slice,
Expand Down
32 changes: 12 additions & 20 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,11 @@ 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_stake()
.get(vote_address)
.copied()
.unwrap_or(0))
pgarg66 marked this conversation as resolved.
Show resolved Hide resolved
}
}
);
Expand Down Expand Up @@ -2147,7 +2142,6 @@ 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},
test_case::test_case,
};
Expand Down Expand Up @@ -4798,11 +4792,12 @@ mod tests {
compute_budget.compute_unit_limit = expected_cus;

with_mock_invoke_context!(invoke_context, transaction_context, vec![]);
let epoch_vote_stake = HashMap::default();
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,
&epoch_vote_stake, // Vote accounts are not needed for this test.
Arc::<FeatureSet>::default(),
&sysvar_cache,
);
Expand Down Expand Up @@ -4846,17 +4841,14 @@ mod tests {

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()),
);
vote_accounts_map.insert(vote_address, expected_epoch_stake);

with_mock_invoke_context!(invoke_context, transaction_context, vec![]);
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.
&vote_accounts_map,
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.

2 changes: 1 addition & 1 deletion programs/sbf/benches/bpf_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use {
signature::Signer,
transaction_context::InstructionAccount,
},
std::{mem, sync::Arc},
std::{collections::HashMap, mem, sync::Arc},
test::Bencher,
};

Expand Down
1 change: 1 addition & 0 deletions programs/stake/src/stake_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,7 @@ mod tests {
stake::state::warmup_cooldown_rate,
sysvar::{epoch_schedule, SysvarId},
},
std::collections::HashMap,
test_case::test_case,
};

Expand Down
1 change: 1 addition & 0 deletions programs/system/src/system_instruction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ mod test {
system_program,
transaction_context::InstructionAccount,
},
std::collections::HashMap,
};

pub const NONCE_ACCOUNT_INDEX: IndexOfAccount = 0;
Expand Down
2 changes: 1 addition & 1 deletion programs/system/src/system_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -570,7 +570,7 @@ mod tests {
solana_program_runtime::{
invoke_context::mock_process_instruction, with_mock_invoke_context,
},
std::collections::BinaryHeap,
std::collections::{BinaryHeap, HashMap},
};

impl From<Pubkey> for Address {
Expand Down
22 changes: 20 additions & 2 deletions runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1463,6 +1463,14 @@ impl Bank {
.unwrap()
.stats
.reset();

if new.epoch != parent.epoch {
new.transaction_processor.set_epoch_stake_information(
new.get_current_epoch_total_stake(),
Arc::new(new.get_epoch_vote_stake()),
)
}

new
}

Expand Down Expand Up @@ -3767,8 +3775,6 @@ 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()),
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 @@ -5210,6 +5216,18 @@ impl Bank {
false, /* debugging_features */
))),
);

self.transaction_processor.set_epoch_stake_information(
self.get_current_epoch_total_stake(),
Arc::new(self.get_epoch_vote_stake()),
);
}

fn get_epoch_vote_stake(&self) -> HashMap<Pubkey, u64> {
self.get_current_epoch_vote_accounts()
.iter()
.map(|(address, (stake, _))| (*address, *stake))
.collect()
}

pub fn set_inflation(&self, inflation: Inflation) {
Expand Down
8 changes: 5 additions & 3 deletions runtime/src/bank/builtins/core_bpf_migration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use {
transaction_context::TransactionContext,
},
source_buffer::SourceBuffer,
std::{cmp::Ordering, sync::atomic::Ordering::Relaxed},
std::{cmp::Ordering, collections::HashMap, sync::atomic::Ordering::Relaxed},
target_builtin::TargetBuiltin,
target_core_bpf::TargetCoreBpf,
};
Expand Down Expand Up @@ -196,14 +196,16 @@ impl Bank {
compute_budget.max_instruction_trace_length,
);

let epoch_vote_stake: HashMap<Pubkey, u64> = HashMap::default();

let mut dummy_invoke_context = InvokeContext::new(
&mut dummy_transaction_context,
&mut program_cache_for_tx_batch,
EnvironmentConfig::new(
Hash::default(),
0,
None,
None,
0,
&epoch_vote_stake,
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
4 changes: 2 additions & 2 deletions svm/doc/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,8 @@ a `TransactionBatchProcessor` object the client need to specify the
- `program_cache: Arc<RwLock<ProgramCache<FG>>>` is a reference to
a ProgramCache instance. All on chain programs used in transaction
batch execution are loaded from the program cache.
- `epoch_total_stake`: The total stake for the current epoch.
- `epoch_vote_stake`: The stake for vote accounts for the current epoch.

In addition, `TransactionBatchProcessor` needs an instance of
`SysvarCache` and a set of pubkeys of builtin program IDs.
Expand Down Expand Up @@ -171,8 +173,6 @@ 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.
- `fee_structure`: Fee structure to use for assessing transaction fees.
- `lamports_per_signature`: Lamports per signature to charge per transaction.
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
Loading
Loading