Cleanup: InvokeContext accessors (#21574)
* Removes blockhash accessors from InvokeContext. * Removes lamports_per_signature accessors from InvokeContext. * Removes return_data accessors from InvokeContext. * Removes feature_set accessor from InvokeContext. * Removes instruction_recorders and instruction_index accessors from InvokeContext. * Moves get_sysvars() into InvokeContext. * Removes compute_meter parameter from InvokeContext::new(). * Removes InvokeContext::new_mock_with_sysvars_and_features(). * Removes InvokeContext::update_timing().
This commit is contained in:
committed by
GitHub
parent
dab0e8fdc7
commit
a9d5ef2055
@ -71,9 +71,7 @@ use solana_measure::measure::Measure;
|
||||
use solana_metrics::{inc_new_counter_debug, inc_new_counter_info};
|
||||
use solana_program_runtime::{
|
||||
instruction_recorder::InstructionRecorder,
|
||||
invoke_context::{
|
||||
BuiltinProgram, ComputeMeter, Executor, Executors, ProcessInstructionWithContext,
|
||||
},
|
||||
invoke_context::{BuiltinProgram, Executor, Executors, ProcessInstructionWithContext},
|
||||
log_collector::LogCollector,
|
||||
timings::ExecuteDetailsTimings,
|
||||
};
|
||||
@ -3871,8 +3869,6 @@ impl Bank {
|
||||
None
|
||||
};
|
||||
|
||||
let compute_meter = ComputeMeter::new_ref(compute_budget.max_units);
|
||||
|
||||
let (blockhash, lamports_per_signature) =
|
||||
self.last_blockhash_and_lamports_per_signature();
|
||||
|
||||
@ -3888,7 +3884,6 @@ impl Bank {
|
||||
instruction_recorders.as_deref(),
|
||||
feature_set,
|
||||
compute_budget,
|
||||
compute_meter,
|
||||
&mut timings.details,
|
||||
&*self.sysvar_cache.read().unwrap(),
|
||||
blockhash,
|
||||
|
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
||||
use solana_measure::measure::Measure;
|
||||
use solana_program_runtime::{
|
||||
instruction_recorder::InstructionRecorder,
|
||||
invoke_context::{BuiltinProgram, ComputeMeter, Executors, InvokeContext},
|
||||
invoke_context::{BuiltinProgram, Executors, InvokeContext},
|
||||
log_collector::LogCollector,
|
||||
timings::ExecuteDetailsTimings,
|
||||
};
|
||||
@ -50,7 +50,6 @@ impl MessageProcessor {
|
||||
instruction_recorders: Option<&[InstructionRecorder]>,
|
||||
feature_set: Arc<FeatureSet>,
|
||||
compute_budget: ComputeBudget,
|
||||
compute_meter: Rc<RefCell<ComputeMeter>>,
|
||||
timings: &mut ExecuteDetailsTimings,
|
||||
sysvars: &[(Pubkey, Vec<u8>)],
|
||||
blockhash: Hash,
|
||||
@ -63,9 +62,7 @@ impl MessageProcessor {
|
||||
sysvars,
|
||||
log_collector,
|
||||
compute_budget,
|
||||
compute_meter,
|
||||
executors,
|
||||
instruction_recorders,
|
||||
feature_set,
|
||||
blockhash,
|
||||
lamports_per_signature,
|
||||
@ -79,8 +76,10 @@ impl MessageProcessor {
|
||||
.enumerate()
|
||||
{
|
||||
let program_id = instruction.program_id(&message.account_keys);
|
||||
if invoke_context.is_feature_active(&prevent_calling_precompiles_as_programs::id())
|
||||
&& is_precompile(program_id, |id| invoke_context.is_feature_active(id))
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&prevent_calling_precompiles_as_programs::id())
|
||||
&& is_precompile(program_id, |id| invoke_context.feature_set.is_active(id))
|
||||
{
|
||||
// Precompiled programs don't have an instruction processor
|
||||
continue;
|
||||
@ -99,7 +98,10 @@ impl MessageProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
invoke_context.set_instruction_index(instruction_index);
|
||||
if let Some(instruction_recorders) = instruction_recorders {
|
||||
invoke_context.instruction_recorder =
|
||||
Some(&instruction_recorders[instruction_index]);
|
||||
}
|
||||
let result = invoke_context
|
||||
.push(message, instruction, program_indices, None)
|
||||
.and_then(|_| {
|
||||
@ -134,7 +136,6 @@ impl MessageProcessor {
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::rent_collector::RentCollector;
|
||||
use solana_program_runtime::invoke_context::ComputeMeter;
|
||||
use solana_sdk::{
|
||||
account::ReadableAccount,
|
||||
instruction::{AccountMeta, Instruction, InstructionError},
|
||||
@ -246,7 +247,6 @@ mod tests {
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
ComputeMeter::new_ref(std::i64::MAX as u64),
|
||||
&mut ExecuteDetailsTimings::default(),
|
||||
&[],
|
||||
Hash::default(),
|
||||
@ -276,7 +276,6 @@ mod tests {
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
ComputeMeter::new_ref(std::i64::MAX as u64),
|
||||
&mut ExecuteDetailsTimings::default(),
|
||||
&[],
|
||||
Hash::default(),
|
||||
@ -310,7 +309,6 @@ mod tests {
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
ComputeMeter::new_ref(std::i64::MAX as u64),
|
||||
&mut ExecuteDetailsTimings::default(),
|
||||
&[],
|
||||
Hash::default(),
|
||||
@ -455,7 +453,6 @@ mod tests {
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
ComputeMeter::new_ref(std::i64::MAX as u64),
|
||||
&mut ExecuteDetailsTimings::default(),
|
||||
&[],
|
||||
Hash::default(),
|
||||
@ -489,7 +486,6 @@ mod tests {
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
ComputeMeter::new_ref(std::i64::MAX as u64),
|
||||
&mut ExecuteDetailsTimings::default(),
|
||||
&[],
|
||||
Hash::default(),
|
||||
@ -520,7 +516,6 @@ mod tests {
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
ComputeMeter::new_ref(std::i64::MAX as u64),
|
||||
&mut ExecuteDetailsTimings::default(),
|
||||
&[],
|
||||
Hash::default(),
|
||||
@ -578,7 +573,6 @@ mod tests {
|
||||
None,
|
||||
Arc::new(FeatureSet::all_enabled()),
|
||||
ComputeBudget::new(),
|
||||
ComputeMeter::new_ref(std::i64::MAX as u64),
|
||||
&mut ExecuteDetailsTimings::default(),
|
||||
&[],
|
||||
Hash::default(),
|
||||
|
@ -47,9 +47,14 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
invoke_context: &InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let merge_nonce_error_into_system_error = invoke_context
|
||||
.is_feature_active(&feature_set::merge_nonce_error_into_system_error::id());
|
||||
.feature_set
|
||||
.is_active(&feature_set::merge_nonce_error_into_system_error::id());
|
||||
|
||||
if invoke_context.is_feature_active(&nonce_must_be_writable::id()) && !self.is_writable() {
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&nonce_must_be_writable::id())
|
||||
&& !self.is_writable()
|
||||
{
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Advance nonce account: Account {} must be writeable",
|
||||
@ -69,7 +74,7 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
);
|
||||
return Err(InstructionError::MissingRequiredSignature);
|
||||
}
|
||||
let recent_blockhash = *invoke_context.get_blockhash();
|
||||
let recent_blockhash = invoke_context.blockhash;
|
||||
if data.blockhash == recent_blockhash {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
@ -84,7 +89,7 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
let new_data = nonce::state::Data::new(
|
||||
data.authority,
|
||||
recent_blockhash,
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
self.set_state(&Versions::new_current(State::Initialized(new_data)))
|
||||
}
|
||||
@ -111,9 +116,14 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
invoke_context: &InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let merge_nonce_error_into_system_error = invoke_context
|
||||
.is_feature_active(&feature_set::merge_nonce_error_into_system_error::id());
|
||||
.feature_set
|
||||
.is_active(&feature_set::merge_nonce_error_into_system_error::id());
|
||||
|
||||
if invoke_context.is_feature_active(&nonce_must_be_writable::id()) && !self.is_writable() {
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&nonce_must_be_writable::id())
|
||||
&& !self.is_writable()
|
||||
{
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Withdraw nonce account: Account {} must be writeable",
|
||||
@ -137,7 +147,7 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
}
|
||||
State::Initialized(ref data) => {
|
||||
if lamports == self.lamports()? {
|
||||
if data.blockhash == *invoke_context.get_blockhash() {
|
||||
if data.blockhash == invoke_context.blockhash {
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Withdraw nonce account: nonce can only advance once per slot"
|
||||
@ -197,9 +207,14 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
invoke_context: &InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let merge_nonce_error_into_system_error = invoke_context
|
||||
.is_feature_active(&feature_set::merge_nonce_error_into_system_error::id());
|
||||
.feature_set
|
||||
.is_active(&feature_set::merge_nonce_error_into_system_error::id());
|
||||
|
||||
if invoke_context.is_feature_active(&nonce_must_be_writable::id()) && !self.is_writable() {
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&nonce_must_be_writable::id())
|
||||
&& !self.is_writable()
|
||||
{
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Initialize nonce account: Account {} must be writeable",
|
||||
@ -222,8 +237,8 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
}
|
||||
let data = nonce::state::Data::new(
|
||||
*nonce_authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
self.set_state(&Versions::new_current(State::Initialized(data)))
|
||||
}
|
||||
@ -248,9 +263,14 @@ impl<'a> NonceKeyedAccount for KeyedAccount<'a> {
|
||||
invoke_context: &InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
let merge_nonce_error_into_system_error = invoke_context
|
||||
.is_feature_active(&feature_set::merge_nonce_error_into_system_error::id());
|
||||
.feature_set
|
||||
.is_active(&feature_set::merge_nonce_error_into_system_error::id());
|
||||
|
||||
if invoke_context.is_feature_active(&nonce_must_be_writable::id()) && !self.is_writable() {
|
||||
if invoke_context
|
||||
.feature_set
|
||||
.is_active(&nonce_must_be_writable::id())
|
||||
&& !self.is_writable()
|
||||
{
|
||||
ic_msg!(
|
||||
invoke_context,
|
||||
"Authorize nonce account: Account {} must be writeable",
|
||||
@ -325,8 +345,8 @@ mod test {
|
||||
fn create_invoke_context_with_blockhash<'a>(seed: usize) -> InvokeContext<'a> {
|
||||
let mut invoke_context = InvokeContext::new_mock(&[], &[]);
|
||||
let (blockhash, lamports_per_signature) = create_test_blockhash(seed);
|
||||
invoke_context.set_blockhash(blockhash);
|
||||
invoke_context.set_lamports_per_signature(lamports_per_signature);
|
||||
invoke_context.blockhash = blockhash;
|
||||
invoke_context.lamports_per_signature = lamports_per_signature;
|
||||
invoke_context
|
||||
}
|
||||
|
||||
@ -364,8 +384,8 @@ mod test {
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data::new(
|
||||
data.authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
// First nonce instruction drives state from Uninitialized to Initialized
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
@ -378,8 +398,8 @@ mod test {
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data::new(
|
||||
data.authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
// Second nonce instruction consumes and replaces stored nonce
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
@ -392,8 +412,8 @@ mod test {
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data::new(
|
||||
data.authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
// Third nonce instruction for fun and profit
|
||||
assert_eq!(state, State::Initialized(data));
|
||||
@ -448,8 +468,8 @@ mod test {
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data::new(
|
||||
authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
assert_eq!(state, State::Initialized(data));
|
||||
let signers = HashSet::new();
|
||||
@ -726,8 +746,8 @@ mod test {
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data::new(
|
||||
authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
assert_eq!(state, State::Initialized(data.clone()));
|
||||
with_test_keyed_account(42, false, |to_keyed| {
|
||||
@ -749,8 +769,8 @@ mod test {
|
||||
.convert_to_current();
|
||||
let data = nonce::state::Data::new(
|
||||
data.authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
assert_eq!(state, State::Initialized(data));
|
||||
assert_eq!(
|
||||
@ -923,8 +943,8 @@ mod test {
|
||||
let result = keyed_account.initialize_nonce_account(&authority, &rent, &invoke_context);
|
||||
let data = nonce::state::Data::new(
|
||||
authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
assert_eq!(result, Ok(()));
|
||||
let state = AccountUtilsState::<Versions>::state(keyed_account)
|
||||
@ -988,8 +1008,8 @@ mod test {
|
||||
let authority = Pubkey::default();
|
||||
let data = nonce::state::Data::new(
|
||||
authority,
|
||||
*invoke_context.get_blockhash(),
|
||||
invoke_context.get_lamports_per_signature(),
|
||||
invoke_context.blockhash,
|
||||
invoke_context.lamports_per_signature,
|
||||
);
|
||||
let result = nonce_account.authorize_nonce_account(
|
||||
&Pubkey::default(),
|
||||
@ -1062,7 +1082,7 @@ mod test {
|
||||
.unwrap();
|
||||
assert!(verify_nonce_account(
|
||||
&nonce_account.account.borrow(),
|
||||
invoke_context.get_blockhash(),
|
||||
&invoke_context.blockhash,
|
||||
));
|
||||
});
|
||||
}
|
||||
@ -1093,7 +1113,7 @@ mod test {
|
||||
let invoke_context = create_invoke_context_with_blockhash(1);
|
||||
assert!(!verify_nonce_account(
|
||||
&nonce_account.account.borrow(),
|
||||
invoke_context.get_blockhash(),
|
||||
&invoke_context.blockhash,
|
||||
));
|
||||
});
|
||||
}
|
||||
|
@ -124,7 +124,9 @@ fn assign(
|
||||
// Thus, we're starting to remove this restriction from system instruction
|
||||
// processor for consistency and fewer special casing by piggybacking onto
|
||||
// the related feature gate..
|
||||
let rent_for_sysvars = invoke_context.is_feature_active(&feature_set::rent_for_sysvars::id());
|
||||
let rent_for_sysvars = invoke_context
|
||||
.feature_set
|
||||
.is_active(&feature_set::rent_for_sysvars::id());
|
||||
if !rent_for_sysvars && sysvar::check_id(owner) {
|
||||
// guard against sysvars being made
|
||||
ic_msg!(invoke_context, "Assign: cannot assign to sysvar, {}", owner);
|
||||
@ -205,7 +207,9 @@ fn transfer(
|
||||
lamports: u64,
|
||||
invoke_context: &InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
if !invoke_context.is_feature_active(&feature_set::system_transfer_zero_check::id())
|
||||
if !invoke_context
|
||||
.feature_set
|
||||
.is_active(&feature_set::system_transfer_zero_check::id())
|
||||
&& lamports == 0
|
||||
{
|
||||
return Ok(());
|
||||
@ -232,7 +236,9 @@ fn transfer_with_seed(
|
||||
lamports: u64,
|
||||
invoke_context: &InvokeContext,
|
||||
) -> Result<(), InstructionError> {
|
||||
if !invoke_context.is_feature_active(&feature_set::system_transfer_zero_check::id())
|
||||
if !invoke_context
|
||||
.feature_set
|
||||
.is_active(&feature_set::system_transfer_zero_check::id())
|
||||
&& lamports == 0
|
||||
{
|
||||
return Ok(());
|
||||
@ -944,8 +950,8 @@ mod tests {
|
||||
feature_set
|
||||
.inactive
|
||||
.insert(feature_set::rent_for_sysvars::id());
|
||||
let invoke_context =
|
||||
InvokeContext::new_mock_with_sysvars_and_features(&[], &[], &[], Arc::new(feature_set));
|
||||
let mut invoke_context = InvokeContext::new_mock(&[], &[]);
|
||||
invoke_context.feature_set = Arc::new(feature_set);
|
||||
// Attempt to create system account in account already owned by another program
|
||||
let from = Pubkey::new_unique();
|
||||
let from_account = AccountSharedData::new_ref(100, 0, &system_program::id());
|
||||
@ -1107,8 +1113,8 @@ mod tests {
|
||||
feature_set
|
||||
.inactive
|
||||
.insert(feature_set::rent_for_sysvars::id());
|
||||
let invoke_context =
|
||||
InvokeContext::new_mock_with_sysvars_and_features(&[], &[], &[], Arc::new(feature_set));
|
||||
let mut invoke_context = InvokeContext::new_mock(&[], &[]);
|
||||
invoke_context.feature_set = Arc::new(feature_set);
|
||||
let new_owner = sysvar::id();
|
||||
let from = Pubkey::new_unique();
|
||||
let mut from_account = AccountSharedData::new(100, 0, &system_program::id());
|
||||
@ -1575,7 +1581,7 @@ mod tests {
|
||||
|first_instruction_account: usize,
|
||||
instruction_data: &[u8],
|
||||
invoke_context: &mut InvokeContext| {
|
||||
invoke_context.set_blockhash(hash(&serialize(&0).unwrap()));
|
||||
invoke_context.blockhash = hash(&serialize(&0).unwrap());
|
||||
super::process_instruction(
|
||||
first_instruction_account,
|
||||
instruction_data,
|
||||
@ -1991,7 +1997,7 @@ mod tests {
|
||||
|first_instruction_account: usize,
|
||||
instruction_data: &[u8],
|
||||
invoke_context: &mut InvokeContext| {
|
||||
invoke_context.set_blockhash(hash(&serialize(&0).unwrap()));
|
||||
invoke_context.blockhash = hash(&serialize(&0).unwrap());
|
||||
super::process_instruction(
|
||||
first_instruction_account,
|
||||
instruction_data,
|
||||
|
Reference in New Issue
Block a user