* Refactor: move sysvar cache to new module
(cherry picked from commit 7171c95bdd
)
# Conflicts:
# Cargo.lock
# program-runtime/Cargo.toml
# program-runtime/src/invoke_context.rs
# programs/bpf/Cargo.lock
# programs/bpf_loader/src/syscalls.rs
# programs/stake/src/stake_instruction.rs
# programs/vote/src/vote_instruction.rs
# runtime/src/message_processor.rs
* resolve conflicts
Co-authored-by: Justin Starry <justin@solana.com>
This commit is contained in:
2
programs/bpf/Cargo.lock
generated
2
programs/bpf/Cargo.lock
generated
@ -3282,6 +3282,8 @@ dependencies = [
|
||||
"num-traits",
|
||||
"rustc_version 0.4.0",
|
||||
"serde",
|
||||
"solana-frozen-abi 1.9.5",
|
||||
"solana-frozen-abi-macro 1.9.5",
|
||||
"solana-logger 1.9.5",
|
||||
"solana-measure",
|
||||
"solana-sdk",
|
||||
|
@ -2647,12 +2647,12 @@ impl<'a, 'b> SyscallObject<BpfError> for SyscallLogData<'a, 'b> {
|
||||
mod tests {
|
||||
use {
|
||||
super::*,
|
||||
solana_program_runtime::invoke_context::InvokeContext,
|
||||
solana_program_runtime::{invoke_context::InvokeContext, sysvar_cache::SysvarCache},
|
||||
solana_rbpf::{
|
||||
ebpf::HOST_ALIGN, memory_region::MemoryRegion, user_error::UserError, vm::Config,
|
||||
},
|
||||
solana_sdk::{bpf_loader, fee_calculator::FeeCalculator, hash::hashv},
|
||||
std::str::FromStr,
|
||||
std::{borrow::Cow, str::FromStr},
|
||||
};
|
||||
|
||||
macro_rules! assert_access_violation {
|
||||
@ -3559,11 +3559,10 @@ mod tests {
|
||||
leader_schedule_epoch: 4,
|
||||
unix_timestamp: 5,
|
||||
};
|
||||
let mut data = vec![];
|
||||
bincode::serialize_into(&mut data, &src_clock).unwrap();
|
||||
let mut sysvar_cache = SysvarCache::default();
|
||||
sysvar_cache.push_entry(sysvar::clock::id(), bincode::serialize(&src_clock).unwrap());
|
||||
let mut invoke_context = InvokeContext::new_mock(&accounts, &[]);
|
||||
let sysvars = [(sysvar::clock::id(), data)];
|
||||
invoke_context.sysvars = &sysvars;
|
||||
invoke_context.sysvar_cache = Cow::Owned(sysvar_cache);
|
||||
invoke_context
|
||||
.push(&message, &message.instructions()[0], &[0], &[])
|
||||
.unwrap();
|
||||
@ -3604,11 +3603,13 @@ mod tests {
|
||||
first_normal_epoch: 3,
|
||||
first_normal_slot: 4,
|
||||
};
|
||||
let mut data = vec![];
|
||||
bincode::serialize_into(&mut data, &src_epochschedule).unwrap();
|
||||
let mut sysvar_cache = SysvarCache::default();
|
||||
sysvar_cache.push_entry(
|
||||
sysvar::epoch_schedule::id(),
|
||||
bincode::serialize(&src_epochschedule).unwrap(),
|
||||
);
|
||||
let mut invoke_context = InvokeContext::new_mock(&accounts, &[]);
|
||||
let sysvars = [(sysvar::epoch_schedule::id(), data)];
|
||||
invoke_context.sysvars = &sysvars;
|
||||
invoke_context.sysvar_cache = Cow::Owned(sysvar_cache);
|
||||
invoke_context
|
||||
.push(&message, &message.instructions()[0], &[0], &[])
|
||||
.unwrap();
|
||||
@ -3656,11 +3657,10 @@ mod tests {
|
||||
lamports_per_signature: 1,
|
||||
},
|
||||
};
|
||||
let mut data = vec![];
|
||||
bincode::serialize_into(&mut data, &src_fees).unwrap();
|
||||
let mut sysvar_cache = SysvarCache::default();
|
||||
sysvar_cache.push_entry(sysvar::fees::id(), bincode::serialize(&src_fees).unwrap());
|
||||
let mut invoke_context = InvokeContext::new_mock(&accounts, &[]);
|
||||
let sysvars = [(sysvar::fees::id(), data)];
|
||||
invoke_context.sysvars = &sysvars;
|
||||
invoke_context.sysvar_cache = Cow::Owned(sysvar_cache);
|
||||
invoke_context
|
||||
.push(&message, &message.instructions()[0], &[0], &[])
|
||||
.unwrap();
|
||||
@ -3699,11 +3699,10 @@ mod tests {
|
||||
exemption_threshold: 2.0,
|
||||
burn_percent: 3,
|
||||
};
|
||||
let mut data = vec![];
|
||||
bincode::serialize_into(&mut data, &src_rent).unwrap();
|
||||
let mut sysvar_cache = SysvarCache::default();
|
||||
sysvar_cache.push_entry(sysvar::rent::id(), bincode::serialize(&src_rent).unwrap());
|
||||
let mut invoke_context = InvokeContext::new_mock(&accounts, &[]);
|
||||
let sysvars = [(sysvar::rent::id(), data)];
|
||||
invoke_context.sysvars = &sysvars;
|
||||
invoke_context.sysvar_cache = Cow::Owned(sysvar_cache);
|
||||
invoke_context
|
||||
.push(&message, &message.instructions()[0], &[0], &[])
|
||||
.unwrap();
|
||||
|
@ -341,8 +341,11 @@ mod tests {
|
||||
super::*,
|
||||
crate::stake_state::{Meta, StakeState},
|
||||
bincode::serialize,
|
||||
solana_program_runtime::invoke_context::{
|
||||
mock_process_instruction, prepare_mock_invoke_context, InvokeContext,
|
||||
solana_program_runtime::{
|
||||
invoke_context::{
|
||||
mock_process_instruction, prepare_mock_invoke_context, InvokeContext,
|
||||
},
|
||||
sysvar_cache::SysvarCache,
|
||||
},
|
||||
solana_sdk::{
|
||||
account::{self, AccountSharedData},
|
||||
@ -354,9 +357,9 @@ mod tests {
|
||||
instruction::{self, LockupArgs},
|
||||
state::{Authorized, Lockup, StakeAuthorize},
|
||||
},
|
||||
sysvar::{stake_history::StakeHistory, Sysvar},
|
||||
sysvar::stake_history::StakeHistory,
|
||||
},
|
||||
std::{cell::RefCell, rc::Rc, str::FromStr},
|
||||
std::{borrow::Cow, cell::RefCell, rc::Rc, str::FromStr},
|
||||
};
|
||||
|
||||
fn create_default_account() -> Rc<RefCell<AccountSharedData>> {
|
||||
@ -428,11 +431,13 @@ mod tests {
|
||||
let processor_account = AccountSharedData::new_ref(0, 0, &solana_sdk::native_loader::id());
|
||||
let program_indices = vec![preparation.accounts.len()];
|
||||
preparation.accounts.push((id(), processor_account));
|
||||
let mut data = Vec::with_capacity(sysvar::clock::Clock::size_of());
|
||||
bincode::serialize_into(&mut data, &sysvar::clock::Clock::default()).unwrap();
|
||||
let mut invoke_context = InvokeContext::new_mock(&preparation.accounts, &[]);
|
||||
let sysvars = [(sysvar::clock::id(), data)];
|
||||
invoke_context.sysvars = &sysvars;
|
||||
let mut sysvar_cache = SysvarCache::default();
|
||||
sysvar_cache.push_entry(
|
||||
sysvar::clock::id(),
|
||||
bincode::serialize(&Clock::default()).unwrap(),
|
||||
);
|
||||
invoke_context.sysvar_cache = Cow::Owned(sysvar_cache);
|
||||
invoke_context.push(
|
||||
&preparation.message,
|
||||
&preparation.message.instructions()[0],
|
||||
@ -1074,11 +1079,13 @@ mod tests {
|
||||
let processor_account = AccountSharedData::new_ref(0, 0, &solana_sdk::native_loader::id());
|
||||
let program_indices = vec![preparation.accounts.len()];
|
||||
preparation.accounts.push((id(), processor_account));
|
||||
let mut data = Vec::with_capacity(sysvar::clock::Clock::size_of());
|
||||
bincode::serialize_into(&mut data, &sysvar::clock::Clock::default()).unwrap();
|
||||
let mut invoke_context = InvokeContext::new_mock(&preparation.accounts, &[]);
|
||||
let sysvars = [(sysvar::clock::id(), data)];
|
||||
invoke_context.sysvars = &sysvars;
|
||||
let mut sysvar_cache = SysvarCache::default();
|
||||
sysvar_cache.push_entry(
|
||||
sysvar::clock::id(),
|
||||
bincode::serialize(&Clock::default()).unwrap(),
|
||||
);
|
||||
invoke_context.sysvar_cache = Cow::Owned(sysvar_cache);
|
||||
invoke_context
|
||||
.push(
|
||||
&preparation.message,
|
||||
|
@ -449,7 +449,9 @@ mod tests {
|
||||
use {
|
||||
super::*,
|
||||
bincode::serialize,
|
||||
solana_program_runtime::invoke_context::mock_process_instruction,
|
||||
solana_program_runtime::{
|
||||
invoke_context::mock_process_instruction, sysvar_cache::SysvarCache,
|
||||
},
|
||||
solana_sdk::{
|
||||
account::{self, Account, AccountSharedData},
|
||||
rent::Rent,
|
||||
@ -509,14 +511,15 @@ mod tests {
|
||||
.map(|(meta, account)| (meta.is_signer, meta.is_writable, meta.pubkey, account))
|
||||
.collect();
|
||||
|
||||
let mut sysvar_cache = SysvarCache::default();
|
||||
let rent = Rent::default();
|
||||
let rent_sysvar = (sysvar::rent::id(), bincode::serialize(&rent).unwrap());
|
||||
sysvar_cache.push_entry(sysvar::rent::id(), bincode::serialize(&rent).unwrap());
|
||||
solana_program_runtime::invoke_context::mock_process_instruction_with_sysvars(
|
||||
&id(),
|
||||
Vec::new(),
|
||||
&instruction.data,
|
||||
&keyed_accounts,
|
||||
&[rent_sysvar],
|
||||
&sysvar_cache,
|
||||
super::process_instruction,
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user