Clean up demote program write lock feature (#21949)
* Clean up demote program write lock feature * fix test
This commit is contained in:
parent
a5769c029f
commit
6ff0be6a82
|
@ -139,7 +139,7 @@ fn format_account_mode(message: &Message, index: usize) -> String {
|
||||||
} else {
|
} else {
|
||||||
"-"
|
"-"
|
||||||
},
|
},
|
||||||
if message.is_writable(index, /*demote_program_write_locks=*/ true) {
|
if message.is_writable(index) {
|
||||||
"w" // comment for consistent rust fmt (no joking; lol)
|
"w" // comment for consistent rust fmt (no joking; lol)
|
||||||
} else {
|
} else {
|
||||||
"-"
|
"-"
|
||||||
|
|
|
@ -935,8 +935,7 @@ impl BankingStage {
|
||||||
gossip_vote_sender: &ReplayVoteSender,
|
gossip_vote_sender: &ReplayVoteSender,
|
||||||
qos_service: &Arc<QosService>,
|
qos_service: &Arc<QosService>,
|
||||||
) -> (Result<usize, PohRecorderError>, Vec<usize>) {
|
) -> (Result<usize, PohRecorderError>, Vec<usize>) {
|
||||||
let tx_costs =
|
let tx_costs = qos_service.compute_transaction_costs(txs.iter());
|
||||||
qos_service.compute_transaction_costs(txs.iter(), bank.demote_program_write_locks());
|
|
||||||
|
|
||||||
let transactions_qos_results =
|
let transactions_qos_results =
|
||||||
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.iter(), bank);
|
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.iter(), bank);
|
||||||
|
|
|
@ -78,13 +78,12 @@ impl QosService {
|
||||||
pub fn compute_transaction_costs<'a>(
|
pub fn compute_transaction_costs<'a>(
|
||||||
&self,
|
&self,
|
||||||
transactions: impl Iterator<Item = &'a SanitizedTransaction>,
|
transactions: impl Iterator<Item = &'a SanitizedTransaction>,
|
||||||
demote_program_write_locks: bool,
|
|
||||||
) -> Vec<TransactionCost> {
|
) -> Vec<TransactionCost> {
|
||||||
let mut compute_cost_time = Measure::start("compute_cost_time");
|
let mut compute_cost_time = Measure::start("compute_cost_time");
|
||||||
let cost_model = self.cost_model.read().unwrap();
|
let cost_model = self.cost_model.read().unwrap();
|
||||||
let txs_costs: Vec<_> = transactions
|
let txs_costs: Vec<_> = transactions
|
||||||
.map(|tx| {
|
.map(|tx| {
|
||||||
let cost = cost_model.calculate_cost(tx, demote_program_write_locks);
|
let cost = cost_model.calculate_cost(tx);
|
||||||
debug!(
|
debug!(
|
||||||
"transaction {:?}, cost {:?}, cost sum {}",
|
"transaction {:?}, cost {:?}, cost sum {}",
|
||||||
tx,
|
tx,
|
||||||
|
@ -261,7 +260,7 @@ mod tests {
|
||||||
|
|
||||||
let cost_model = Arc::new(RwLock::new(CostModel::default()));
|
let cost_model = Arc::new(RwLock::new(CostModel::default()));
|
||||||
let qos_service = QosService::new(cost_model.clone());
|
let qos_service = QosService::new(cost_model.clone());
|
||||||
let txs_costs = qos_service.compute_transaction_costs(txs.iter(), false);
|
let txs_costs = qos_service.compute_transaction_costs(txs.iter());
|
||||||
|
|
||||||
// verify the size of txs_costs and its contents
|
// verify the size of txs_costs and its contents
|
||||||
assert_eq!(txs_costs.len(), txs.len());
|
assert_eq!(txs_costs.len(), txs.len());
|
||||||
|
@ -271,11 +270,7 @@ mod tests {
|
||||||
.map(|(index, cost)| {
|
.map(|(index, cost)| {
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
cost.sum(),
|
cost.sum(),
|
||||||
cost_model
|
cost_model.read().unwrap().calculate_cost(&txs[index]).sum()
|
||||||
.read()
|
|
||||||
.unwrap()
|
|
||||||
.calculate_cost(&txs[index], false)
|
|
||||||
.sum()
|
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
.collect_vec();
|
.collect_vec();
|
||||||
|
@ -306,14 +301,14 @@ mod tests {
|
||||||
let transfer_tx_cost = cost_model
|
let transfer_tx_cost = cost_model
|
||||||
.read()
|
.read()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.calculate_cost(&transfer_tx, false)
|
.calculate_cost(&transfer_tx)
|
||||||
.sum();
|
.sum();
|
||||||
|
|
||||||
// make a vec of txs
|
// make a vec of txs
|
||||||
let txs = vec![transfer_tx.clone(), vote_tx.clone(), transfer_tx, vote_tx];
|
let txs = vec![transfer_tx.clone(), vote_tx.clone(), transfer_tx, vote_tx];
|
||||||
|
|
||||||
let qos_service = QosService::new(cost_model);
|
let qos_service = QosService::new(cost_model);
|
||||||
let txs_costs = qos_service.compute_transaction_costs(txs.iter(), false);
|
let txs_costs = qos_service.compute_transaction_costs(txs.iter());
|
||||||
|
|
||||||
// set cost tracker limit to fit 1 transfer tx, vote tx bypasses limit check
|
// set cost tracker limit to fit 1 transfer tx, vote tx bypasses limit check
|
||||||
let cost_limit = transfer_tx_cost;
|
let cost_limit = transfer_tx_cost;
|
||||||
|
@ -359,7 +354,7 @@ mod tests {
|
||||||
.name("test-producer-1".to_string())
|
.name("test-producer-1".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
debug!("thread 1 starts with {} txs", txs_1.len());
|
debug!("thread 1 starts with {} txs", txs_1.len());
|
||||||
let tx_costs = qos_service_1.compute_transaction_costs(txs_1.iter(), false);
|
let tx_costs = qos_service_1.compute_transaction_costs(txs_1.iter());
|
||||||
assert_eq!(txs_count, tx_costs.len());
|
assert_eq!(txs_count, tx_costs.len());
|
||||||
debug!(
|
debug!(
|
||||||
"thread 1 done, generated {} count, see service count as {}",
|
"thread 1 done, generated {} count, see service count as {}",
|
||||||
|
@ -376,7 +371,7 @@ mod tests {
|
||||||
.name("test-producer-2".to_string())
|
.name("test-producer-2".to_string())
|
||||||
.spawn(move || {
|
.spawn(move || {
|
||||||
debug!("thread 2 starts with {} txs", txs_2.len());
|
debug!("thread 2 starts with {} txs", txs_2.len());
|
||||||
let tx_costs = qos_service_2.compute_transaction_costs(txs_2.iter(), false);
|
let tx_costs = qos_service_2.compute_transaction_costs(txs_2.iter());
|
||||||
assert_eq!(txs_count, tx_costs.len());
|
assert_eq!(txs_count, tx_costs.len());
|
||||||
debug!(
|
debug!(
|
||||||
"thread 2 done, generated {} count, see service count as {}",
|
"thread 2 done, generated {} count, see service count as {}",
|
||||||
|
|
|
@ -800,10 +800,7 @@ fn compute_slot_cost(blockstore: &Blockstore, slot: Slot) -> Result<(), String>
|
||||||
.for_each(|transaction| {
|
.for_each(|transaction| {
|
||||||
num_programs += transaction.message().instructions().len();
|
num_programs += transaction.message().instructions().len();
|
||||||
|
|
||||||
let tx_cost = cost_model.calculate_cost(
|
let tx_cost = cost_model.calculate_cost(&transaction);
|
||||||
&transaction,
|
|
||||||
true, // demote_program_write_locks
|
|
||||||
);
|
|
||||||
let result = cost_tracker.try_add(&transaction, &tx_cost);
|
let result = cost_tracker.try_add(&transaction, &tx_cost);
|
||||||
if result.is_err() {
|
if result.is_err() {
|
||||||
println!(
|
println!(
|
||||||
|
|
|
@ -10,9 +10,8 @@ use {
|
||||||
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
|
||||||
compute_budget::ComputeBudget,
|
compute_budget::ComputeBudget,
|
||||||
feature_set::{
|
feature_set::{
|
||||||
demote_program_write_locks, do_support_realloc, neon_evm_compute_budget,
|
do_support_realloc, neon_evm_compute_budget, reject_empty_instruction_without_program,
|
||||||
reject_empty_instruction_without_program, remove_native_loader, requestable_heap_size,
|
remove_native_loader, requestable_heap_size, tx_wide_compute_cap, FeatureSet,
|
||||||
tx_wide_compute_cap, FeatureSet,
|
|
||||||
},
|
},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
instruction::{AccountMeta, CompiledInstruction, Instruction, InstructionError},
|
||||||
|
@ -282,9 +281,6 @@ impl<'a> InvokeContext<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the KeyedAccounts that will be passed to the program
|
// Create the KeyedAccounts that will be passed to the program
|
||||||
let demote_program_write_locks = self
|
|
||||||
.feature_set
|
|
||||||
.is_active(&demote_program_write_locks::id());
|
|
||||||
let keyed_accounts = program_indices
|
let keyed_accounts = program_indices
|
||||||
.iter()
|
.iter()
|
||||||
.map(|account_index| {
|
.map(|account_index| {
|
||||||
|
@ -304,7 +300,7 @@ impl<'a> InvokeContext<'a> {
|
||||||
};
|
};
|
||||||
(
|
(
|
||||||
message.is_signer(index_in_instruction),
|
message.is_signer(index_in_instruction),
|
||||||
message.is_writable(index_in_instruction, demote_program_write_locks),
|
message.is_writable(index_in_instruction),
|
||||||
&self.accounts[account_index].0,
|
&self.accounts[account_index].0,
|
||||||
&self.accounts[account_index].1 as &RefCell<AccountSharedData>,
|
&self.accounts[account_index].1 as &RefCell<AccountSharedData>,
|
||||||
)
|
)
|
||||||
|
@ -336,9 +332,6 @@ impl<'a> InvokeContext<'a> {
|
||||||
program_indices: &[usize],
|
program_indices: &[usize],
|
||||||
) -> Result<(), InstructionError> {
|
) -> Result<(), InstructionError> {
|
||||||
let program_id = instruction.program_id(&message.account_keys);
|
let program_id = instruction.program_id(&message.account_keys);
|
||||||
let demote_program_write_locks = self
|
|
||||||
.feature_set
|
|
||||||
.is_active(&demote_program_write_locks::id());
|
|
||||||
let do_support_realloc = self.feature_set.is_active(&do_support_realloc::id());
|
let do_support_realloc = self.feature_set.is_active(&do_support_realloc::id());
|
||||||
|
|
||||||
// Verify all executable accounts have zero outstanding refs
|
// Verify all executable accounts have zero outstanding refs
|
||||||
|
@ -364,7 +357,7 @@ impl<'a> InvokeContext<'a> {
|
||||||
pre_account
|
pre_account
|
||||||
.verify(
|
.verify(
|
||||||
program_id,
|
program_id,
|
||||||
message.is_writable(account_index, demote_program_write_locks),
|
message.is_writable(account_index),
|
||||||
&self.rent,
|
&self.rent,
|
||||||
&account,
|
&account,
|
||||||
&mut self.timings,
|
&mut self.timings,
|
||||||
|
@ -669,11 +662,8 @@ impl<'a> InvokeContext<'a> {
|
||||||
if is_lowest_invocation_level {
|
if is_lowest_invocation_level {
|
||||||
self.verify(message, instruction, program_indices)?;
|
self.verify(message, instruction, program_indices)?;
|
||||||
} else {
|
} else {
|
||||||
let demote_program_write_locks = self
|
|
||||||
.feature_set
|
|
||||||
.is_active(&demote_program_write_locks::id());
|
|
||||||
let write_privileges: Vec<bool> = (0..message.account_keys.len())
|
let write_privileges: Vec<bool> = (0..message.account_keys.len())
|
||||||
.map(|i| message.is_writable(i, demote_program_write_locks))
|
.map(|i| message.is_writable(i))
|
||||||
.collect();
|
.collect();
|
||||||
self.verify_and_update(instruction, account_indices, &write_privileges)?;
|
self.verify_and_update(instruction, account_indices, &write_privileges)?;
|
||||||
}
|
}
|
||||||
|
@ -1147,7 +1137,7 @@ mod tests {
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
let write_privileges: Vec<bool> = (0..message.account_keys.len())
|
let write_privileges: Vec<bool> = (0..message.account_keys.len())
|
||||||
.map(|i| message.is_writable(i, /*demote_program_write_locks=*/ true))
|
.map(|i| message.is_writable(i))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
// modify account owned by the program
|
// modify account owned by the program
|
||||||
|
@ -1269,14 +1259,11 @@ mod tests {
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
// not owned account modified by the caller (before the invoke)
|
// not owned account modified by the caller (before the invoke)
|
||||||
let demote_program_write_locks = invoke_context
|
|
||||||
.feature_set
|
|
||||||
.is_active(&demote_program_write_locks::id());
|
|
||||||
let caller_write_privileges = message
|
let caller_write_privileges = message
|
||||||
.account_keys
|
.account_keys
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, _)| message.is_writable(i, demote_program_write_locks))
|
.map(|(i, _)| message.is_writable(i))
|
||||||
.collect::<Vec<bool>>();
|
.collect::<Vec<bool>>();
|
||||||
accounts[0].1.borrow_mut().data_as_mut_slice()[0] = 1;
|
accounts[0].1.borrow_mut().data_as_mut_slice()[0] = 1;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -1330,7 +1317,7 @@ mod tests {
|
||||||
.account_keys
|
.account_keys
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, _)| message.is_writable(i, demote_program_write_locks))
|
.map(|(i, _)| message.is_writable(i))
|
||||||
.collect::<Vec<bool>>();
|
.collect::<Vec<bool>>();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
invoke_context.process_instruction(
|
invoke_context.process_instruction(
|
||||||
|
|
|
@ -26,7 +26,6 @@ use {
|
||||||
compute_budget::ComputeBudget,
|
compute_budget::ComputeBudget,
|
||||||
entrypoint::{ProgramResult, SUCCESS},
|
entrypoint::{ProgramResult, SUCCESS},
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
feature_set::demote_program_write_locks,
|
|
||||||
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
fee_calculator::{FeeCalculator, FeeRateGovernor},
|
||||||
genesis_config::{ClusterType, GenesisConfig},
|
genesis_config::{ClusterType, GenesisConfig},
|
||||||
hash::Hash,
|
hash::Hash,
|
||||||
|
@ -244,15 +243,12 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
|
||||||
let message = Message::new(&[instruction.clone()], None);
|
let message = Message::new(&[instruction.clone()], None);
|
||||||
let program_id_index = message.instructions[0].program_id_index as usize;
|
let program_id_index = message.instructions[0].program_id_index as usize;
|
||||||
let program_id = message.account_keys[program_id_index];
|
let program_id = message.account_keys[program_id_index];
|
||||||
let demote_program_write_locks = invoke_context
|
|
||||||
.feature_set
|
|
||||||
.is_active(&demote_program_write_locks::id());
|
|
||||||
// TODO don't have the caller's keyed_accounts so can't validate writer or signer escalation or deescalation yet
|
// TODO don't have the caller's keyed_accounts so can't validate writer or signer escalation or deescalation yet
|
||||||
let caller_privileges = message
|
let caller_privileges = message
|
||||||
.account_keys
|
.account_keys
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.enumerate()
|
||||||
.map(|(i, _)| message.is_writable(i, demote_program_write_locks))
|
.map(|(i, _)| message.is_writable(i))
|
||||||
.collect::<Vec<bool>>();
|
.collect::<Vec<bool>>();
|
||||||
|
|
||||||
stable_log::program_invoke(&log_collector, &program_id, invoke_context.invoke_depth());
|
stable_log::program_invoke(&log_collector, &program_id, invoke_context.invoke_depth());
|
||||||
|
@ -280,7 +276,7 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
|
||||||
account.set_executable(account_info.executable);
|
account.set_executable(account_info.executable);
|
||||||
account.set_rent_epoch(account_info.rent_epoch);
|
account.set_rent_epoch(account_info.rent_epoch);
|
||||||
}
|
}
|
||||||
let account_info = if message.is_writable(i, demote_program_write_locks) {
|
let account_info = if message.is_writable(i) {
|
||||||
Some(account_info)
|
Some(account_info)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
|
|
@ -24,11 +24,10 @@ use {
|
||||||
entrypoint::{BPF_ALIGN_OF_U128, MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
entrypoint::{BPF_ALIGN_OF_U128, MAX_PERMITTED_DATA_INCREASE, SUCCESS},
|
||||||
epoch_schedule::EpochSchedule,
|
epoch_schedule::EpochSchedule,
|
||||||
feature_set::{
|
feature_set::{
|
||||||
blake3_syscall_enabled, demote_program_write_locks, disable_fees_sysvar,
|
blake3_syscall_enabled, disable_fees_sysvar, do_support_realloc,
|
||||||
do_support_realloc, fixed_memcpy_nonoverlapping_check,
|
fixed_memcpy_nonoverlapping_check, libsecp256k1_0_5_upgrade_enabled,
|
||||||
libsecp256k1_0_5_upgrade_enabled, prevent_calling_precompiles_as_programs,
|
prevent_calling_precompiles_as_programs, return_data_syscall_enabled,
|
||||||
return_data_syscall_enabled, secp256k1_recover_syscall_enabled,
|
secp256k1_recover_syscall_enabled, sol_log_data_syscall_enabled,
|
||||||
sol_log_data_syscall_enabled,
|
|
||||||
},
|
},
|
||||||
hash::{Hasher, HASH_BYTES},
|
hash::{Hasher, HASH_BYTES},
|
||||||
instruction::{AccountMeta, Instruction, InstructionError},
|
instruction::{AccountMeta, Instruction, InstructionError},
|
||||||
|
@ -2198,9 +2197,6 @@ fn get_translated_accounts<'a, T, F>(
|
||||||
where
|
where
|
||||||
F: Fn(&T, &InvokeContext) -> Result<CallerAccount<'a>, EbpfError<BpfError>>,
|
F: Fn(&T, &InvokeContext) -> Result<CallerAccount<'a>, EbpfError<BpfError>>,
|
||||||
{
|
{
|
||||||
let demote_program_write_locks = invoke_context
|
|
||||||
.feature_set
|
|
||||||
.is_active(&demote_program_write_locks::id());
|
|
||||||
let keyed_accounts = invoke_context
|
let keyed_accounts = invoke_context
|
||||||
.get_instruction_keyed_accounts()
|
.get_instruction_keyed_accounts()
|
||||||
.map_err(SyscallError::InstructionError)?;
|
.map_err(SyscallError::InstructionError)?;
|
||||||
|
@ -2229,7 +2225,7 @@ where
|
||||||
account.set_executable(caller_account.executable);
|
account.set_executable(caller_account.executable);
|
||||||
account.set_rent_epoch(caller_account.rent_epoch);
|
account.set_rent_epoch(caller_account.rent_epoch);
|
||||||
}
|
}
|
||||||
let caller_account = if message.is_writable(i, demote_program_write_locks) {
|
let caller_account = if message.is_writable(i) {
|
||||||
if let Some(orig_data_len_index) = keyed_accounts
|
if let Some(orig_data_len_index) = keyed_accounts
|
||||||
.iter()
|
.iter()
|
||||||
.position(|keyed_account| keyed_account.unsigned_key() == account_key)
|
.position(|keyed_account| keyed_account.unsigned_key() == account_key)
|
||||||
|
|
|
@ -123,8 +123,7 @@ impl TransactionStatusService {
|
||||||
transaction.message(),
|
transaction.message(),
|
||||||
lamports_per_signature,
|
lamports_per_signature,
|
||||||
);
|
);
|
||||||
let tx_account_locks =
|
let tx_account_locks = transaction.get_account_locks();
|
||||||
transaction.get_account_locks(bank.demote_program_write_locks());
|
|
||||||
|
|
||||||
let inner_instructions = inner_instructions.map(|inner_instructions| {
|
let inner_instructions = inner_instructions.map(|inner_instructions| {
|
||||||
inner_instructions
|
inner_instructions
|
||||||
|
|
|
@ -209,9 +209,8 @@ impl Accounts {
|
||||||
fn construct_instructions_account(
|
fn construct_instructions_account(
|
||||||
message: &SanitizedMessage,
|
message: &SanitizedMessage,
|
||||||
is_owned_by_sysvar: bool,
|
is_owned_by_sysvar: bool,
|
||||||
demote_program_write_locks: bool,
|
|
||||||
) -> AccountSharedData {
|
) -> AccountSharedData {
|
||||||
let data = construct_instructions_data(message, demote_program_write_locks);
|
let data = construct_instructions_data(message);
|
||||||
let owner = if is_owned_by_sysvar {
|
let owner = if is_owned_by_sysvar {
|
||||||
sysvar::id()
|
sysvar::id()
|
||||||
} else {
|
} else {
|
||||||
|
@ -247,9 +246,6 @@ impl Accounts {
|
||||||
let mut account_deps = Vec::with_capacity(message.account_keys_len());
|
let mut account_deps = Vec::with_capacity(message.account_keys_len());
|
||||||
let mut rent_debits = RentDebits::default();
|
let mut rent_debits = RentDebits::default();
|
||||||
let rent_for_sysvars = feature_set.is_active(&feature_set::rent_for_sysvars::id());
|
let rent_for_sysvars = feature_set.is_active(&feature_set::rent_for_sysvars::id());
|
||||||
let demote_program_write_locks =
|
|
||||||
feature_set.is_active(&feature_set::demote_program_write_locks::id());
|
|
||||||
|
|
||||||
for (i, key) in message.account_keys_iter().enumerate() {
|
for (i, key) in message.account_keys_iter().enumerate() {
|
||||||
let account = if !message.is_non_loader_key(i) {
|
let account = if !message.is_non_loader_key(i) {
|
||||||
// Fill in an empty account for the program slots.
|
// Fill in an empty account for the program slots.
|
||||||
|
@ -264,14 +260,13 @@ impl Accounts {
|
||||||
message,
|
message,
|
||||||
feature_set
|
feature_set
|
||||||
.is_active(&feature_set::instructions_sysvar_owned_by_sysvar::id()),
|
.is_active(&feature_set::instructions_sysvar_owned_by_sysvar::id()),
|
||||||
demote_program_write_locks,
|
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
let (account, rent) = self
|
let (account, rent) = self
|
||||||
.accounts_db
|
.accounts_db
|
||||||
.load_with_fixed_root(ancestors, key)
|
.load_with_fixed_root(ancestors, key)
|
||||||
.map(|(mut account, _)| {
|
.map(|(mut account, _)| {
|
||||||
if message.is_writable(i, demote_program_write_locks) {
|
if message.is_writable(i) {
|
||||||
let rent_due = rent_collector.collect_from_existing_account(
|
let rent_due = rent_collector.collect_from_existing_account(
|
||||||
key,
|
key,
|
||||||
&mut account,
|
&mut account,
|
||||||
|
@ -286,10 +281,7 @@ impl Accounts {
|
||||||
.unwrap_or_default();
|
.unwrap_or_default();
|
||||||
|
|
||||||
if bpf_loader_upgradeable::check_id(account.owner()) {
|
if bpf_loader_upgradeable::check_id(account.owner()) {
|
||||||
if demote_program_write_locks
|
if message.is_writable(i) && !message.is_upgradeable_loader_present() {
|
||||||
&& message.is_writable(i, demote_program_write_locks)
|
|
||||||
&& !message.is_upgradeable_loader_present()
|
|
||||||
{
|
|
||||||
error_counters.invalid_writable_account += 1;
|
error_counters.invalid_writable_account += 1;
|
||||||
return Err(TransactionError::InvalidWritableAccount);
|
return Err(TransactionError::InvalidWritableAccount);
|
||||||
}
|
}
|
||||||
|
@ -315,10 +307,7 @@ impl Accounts {
|
||||||
return Err(TransactionError::InvalidProgramForExecution);
|
return Err(TransactionError::InvalidProgramForExecution);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if account.executable()
|
} else if account.executable() && message.is_writable(i) {
|
||||||
&& demote_program_write_locks
|
|
||||||
&& message.is_writable(i, demote_program_write_locks)
|
|
||||||
{
|
|
||||||
error_counters.invalid_writable_account += 1;
|
error_counters.invalid_writable_account += 1;
|
||||||
return Err(TransactionError::InvalidWritableAccount);
|
return Err(TransactionError::InvalidWritableAccount);
|
||||||
}
|
}
|
||||||
|
@ -985,11 +974,8 @@ impl Accounts {
|
||||||
pub fn lock_accounts<'a>(
|
pub fn lock_accounts<'a>(
|
||||||
&self,
|
&self,
|
||||||
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
||||||
demote_program_write_locks: bool,
|
|
||||||
) -> Vec<Result<()>> {
|
) -> Vec<Result<()>> {
|
||||||
let keys: Vec<_> = txs
|
let keys: Vec<_> = txs.map(|tx| tx.get_account_locks()).collect();
|
||||||
.map(|tx| tx.get_account_locks(demote_program_write_locks))
|
|
||||||
.collect();
|
|
||||||
let account_locks = &mut self.account_locks.lock().unwrap();
|
let account_locks = &mut self.account_locks.lock().unwrap();
|
||||||
keys.into_iter()
|
keys.into_iter()
|
||||||
.map(|keys| self.lock_account(account_locks, keys.writable, keys.readonly))
|
.map(|keys| self.lock_account(account_locks, keys.writable, keys.readonly))
|
||||||
|
@ -1002,12 +988,11 @@ impl Accounts {
|
||||||
&self,
|
&self,
|
||||||
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
||||||
results: impl Iterator<Item = Result<()>>,
|
results: impl Iterator<Item = Result<()>>,
|
||||||
demote_program_write_locks: bool,
|
|
||||||
) -> Vec<Result<()>> {
|
) -> Vec<Result<()>> {
|
||||||
let key_results: Vec<_> = txs
|
let key_results: Vec<_> = txs
|
||||||
.zip(results)
|
.zip(results)
|
||||||
.map(|(tx, result)| match result {
|
.map(|(tx, result)| match result {
|
||||||
Ok(()) => Ok(tx.get_account_locks(demote_program_write_locks)),
|
Ok(()) => Ok(tx.get_account_locks()),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
@ -1027,7 +1012,6 @@ impl Accounts {
|
||||||
&self,
|
&self,
|
||||||
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
||||||
results: &[Result<()>],
|
results: &[Result<()>],
|
||||||
demote_program_write_locks: bool,
|
|
||||||
) {
|
) {
|
||||||
let keys: Vec<_> = txs
|
let keys: Vec<_> = txs
|
||||||
.zip(results)
|
.zip(results)
|
||||||
|
@ -1038,7 +1022,7 @@ impl Accounts {
|
||||||
| Err(TransactionError::WouldExceedMaxBlockCostLimit)
|
| Err(TransactionError::WouldExceedMaxBlockCostLimit)
|
||||||
| Err(TransactionError::WouldExceedMaxAccountCostLimit)
|
| Err(TransactionError::WouldExceedMaxAccountCostLimit)
|
||||||
| Err(TransactionError::WouldExceedMaxAccountDataCostLimit) => None,
|
| Err(TransactionError::WouldExceedMaxAccountDataCostLimit) => None,
|
||||||
_ => Some(tx.get_account_locks(demote_program_write_locks)),
|
_ => Some(tx.get_account_locks()),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
let mut account_locks = self.account_locks.lock().unwrap();
|
let mut account_locks = self.account_locks.lock().unwrap();
|
||||||
|
@ -1061,7 +1045,6 @@ impl Accounts {
|
||||||
blockhash: &Hash,
|
blockhash: &Hash,
|
||||||
lamports_per_signature: u64,
|
lamports_per_signature: u64,
|
||||||
rent_for_sysvars: bool,
|
rent_for_sysvars: bool,
|
||||||
demote_program_write_locks: bool,
|
|
||||||
leave_nonce_on_success: bool,
|
leave_nonce_on_success: bool,
|
||||||
) {
|
) {
|
||||||
let accounts_to_store = self.collect_accounts_to_store(
|
let accounts_to_store = self.collect_accounts_to_store(
|
||||||
|
@ -1072,7 +1055,6 @@ impl Accounts {
|
||||||
blockhash,
|
blockhash,
|
||||||
lamports_per_signature,
|
lamports_per_signature,
|
||||||
rent_for_sysvars,
|
rent_for_sysvars,
|
||||||
demote_program_write_locks,
|
|
||||||
leave_nonce_on_success,
|
leave_nonce_on_success,
|
||||||
);
|
);
|
||||||
self.accounts_db.store_cached(slot, &accounts_to_store);
|
self.accounts_db.store_cached(slot, &accounts_to_store);
|
||||||
|
@ -1100,7 +1082,6 @@ impl Accounts {
|
||||||
blockhash: &Hash,
|
blockhash: &Hash,
|
||||||
lamports_per_signature: u64,
|
lamports_per_signature: u64,
|
||||||
rent_for_sysvars: bool,
|
rent_for_sysvars: bool,
|
||||||
demote_program_write_locks: bool,
|
|
||||||
leave_nonce_on_success: bool,
|
leave_nonce_on_success: bool,
|
||||||
) -> Vec<(&'a Pubkey, &'a AccountSharedData)> {
|
) -> Vec<(&'a Pubkey, &'a AccountSharedData)> {
|
||||||
let mut accounts = Vec::with_capacity(load_results.len());
|
let mut accounts = Vec::with_capacity(load_results.len());
|
||||||
|
@ -1137,7 +1118,7 @@ impl Accounts {
|
||||||
fee_payer_index = Some(i);
|
fee_payer_index = Some(i);
|
||||||
}
|
}
|
||||||
let is_fee_payer = Some(i) == fee_payer_index;
|
let is_fee_payer = Some(i) == fee_payer_index;
|
||||||
if message.is_writable(i, demote_program_write_locks) {
|
if message.is_writable(i) {
|
||||||
let is_nonce_account = prepare_if_nonce_account(
|
let is_nonce_account = prepare_if_nonce_account(
|
||||||
address,
|
address,
|
||||||
account,
|
account,
|
||||||
|
@ -2171,8 +2152,6 @@ mod tests {
|
||||||
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
|
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
|
||||||
accounts.store_slow_uncached(0, &keypair3.pubkey(), &account3);
|
accounts.store_slow_uncached(0, &keypair3.pubkey(), &account3);
|
||||||
|
|
||||||
let demote_program_write_locks = true;
|
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
||||||
let message = Message::new_with_compiled_instructions(
|
let message = Message::new_with_compiled_instructions(
|
||||||
1,
|
1,
|
||||||
|
@ -2183,7 +2162,7 @@ mod tests {
|
||||||
instructions,
|
instructions,
|
||||||
);
|
);
|
||||||
let tx = new_sanitized_tx(&[&keypair0], message, Hash::default());
|
let tx = new_sanitized_tx(&[&keypair0], message, Hash::default());
|
||||||
let results0 = accounts.lock_accounts([tx.clone()].iter(), demote_program_write_locks);
|
let results0 = accounts.lock_accounts([tx.clone()].iter());
|
||||||
|
|
||||||
assert!(results0[0].is_ok());
|
assert!(results0[0].is_ok());
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
|
@ -2218,7 +2197,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
let tx1 = new_sanitized_tx(&[&keypair1], message, Hash::default());
|
let tx1 = new_sanitized_tx(&[&keypair1], message, Hash::default());
|
||||||
let txs = vec![tx0, tx1];
|
let txs = vec![tx0, tx1];
|
||||||
let results1 = accounts.lock_accounts(txs.iter(), demote_program_write_locks);
|
let results1 = accounts.lock_accounts(txs.iter());
|
||||||
|
|
||||||
assert!(results1[0].is_ok()); // Read-only account (keypair1) can be referenced multiple times
|
assert!(results1[0].is_ok()); // Read-only account (keypair1) can be referenced multiple times
|
||||||
assert!(results1[1].is_err()); // Read-only account (keypair1) cannot also be locked as writable
|
assert!(results1[1].is_err()); // Read-only account (keypair1) cannot also be locked as writable
|
||||||
|
@ -2233,8 +2212,8 @@ mod tests {
|
||||||
2
|
2
|
||||||
);
|
);
|
||||||
|
|
||||||
accounts.unlock_accounts([tx].iter(), &results0, demote_program_write_locks);
|
accounts.unlock_accounts([tx].iter(), &results0);
|
||||||
accounts.unlock_accounts(txs.iter(), &results1, demote_program_write_locks);
|
accounts.unlock_accounts(txs.iter(), &results1);
|
||||||
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
||||||
let message = Message::new_with_compiled_instructions(
|
let message = Message::new_with_compiled_instructions(
|
||||||
1,
|
1,
|
||||||
|
@ -2245,7 +2224,7 @@ mod tests {
|
||||||
instructions,
|
instructions,
|
||||||
);
|
);
|
||||||
let tx = new_sanitized_tx(&[&keypair1], message, Hash::default());
|
let tx = new_sanitized_tx(&[&keypair1], message, Hash::default());
|
||||||
let results2 = accounts.lock_accounts([tx].iter(), demote_program_write_locks);
|
let results2 = accounts.lock_accounts([tx].iter());
|
||||||
assert!(results2[0].is_ok()); // Now keypair1 account can be locked as writable
|
assert!(results2[0].is_ok()); // Now keypair1 account can be locked as writable
|
||||||
|
|
||||||
// Check that read-only lock with zero references is deleted
|
// Check that read-only lock with zero references is deleted
|
||||||
|
@ -2282,8 +2261,6 @@ mod tests {
|
||||||
accounts.store_slow_uncached(0, &keypair1.pubkey(), &account1);
|
accounts.store_slow_uncached(0, &keypair1.pubkey(), &account1);
|
||||||
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
|
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
|
||||||
|
|
||||||
let demote_program_write_locks = true;
|
|
||||||
|
|
||||||
let accounts_arc = Arc::new(accounts);
|
let accounts_arc = Arc::new(accounts);
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
||||||
|
@ -2316,15 +2293,13 @@ mod tests {
|
||||||
let exit_clone = exit_clone.clone();
|
let exit_clone = exit_clone.clone();
|
||||||
loop {
|
loop {
|
||||||
let txs = vec![writable_tx.clone()];
|
let txs = vec![writable_tx.clone()];
|
||||||
let results = accounts_clone
|
let results = accounts_clone.clone().lock_accounts(txs.iter());
|
||||||
.clone()
|
|
||||||
.lock_accounts(txs.iter(), demote_program_write_locks);
|
|
||||||
for result in results.iter() {
|
for result in results.iter() {
|
||||||
if result.is_ok() {
|
if result.is_ok() {
|
||||||
counter_clone.clone().fetch_add(1, Ordering::SeqCst);
|
counter_clone.clone().fetch_add(1, Ordering::SeqCst);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
accounts_clone.unlock_accounts(txs.iter(), &results, demote_program_write_locks);
|
accounts_clone.unlock_accounts(txs.iter(), &results);
|
||||||
if exit_clone.clone().load(Ordering::Relaxed) {
|
if exit_clone.clone().load(Ordering::Relaxed) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -2333,15 +2308,13 @@ mod tests {
|
||||||
let counter_clone = counter;
|
let counter_clone = counter;
|
||||||
for _ in 0..5 {
|
for _ in 0..5 {
|
||||||
let txs = vec![readonly_tx.clone()];
|
let txs = vec![readonly_tx.clone()];
|
||||||
let results = accounts_arc
|
let results = accounts_arc.clone().lock_accounts(txs.iter());
|
||||||
.clone()
|
|
||||||
.lock_accounts(txs.iter(), demote_program_write_locks);
|
|
||||||
if results[0].is_ok() {
|
if results[0].is_ok() {
|
||||||
let counter_value = counter_clone.clone().load(Ordering::SeqCst);
|
let counter_value = counter_clone.clone().load(Ordering::SeqCst);
|
||||||
thread::sleep(time::Duration::from_millis(50));
|
thread::sleep(time::Duration::from_millis(50));
|
||||||
assert_eq!(counter_value, counter_clone.clone().load(Ordering::SeqCst));
|
assert_eq!(counter_value, counter_clone.clone().load(Ordering::SeqCst));
|
||||||
}
|
}
|
||||||
accounts_arc.unlock_accounts(txs.iter(), &results, demote_program_write_locks);
|
accounts_arc.unlock_accounts(txs.iter(), &results);
|
||||||
thread::sleep(time::Duration::from_millis(50));
|
thread::sleep(time::Duration::from_millis(50));
|
||||||
}
|
}
|
||||||
exit.store(true, Ordering::Relaxed);
|
exit.store(true, Ordering::Relaxed);
|
||||||
|
@ -2371,8 +2344,6 @@ mod tests {
|
||||||
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
|
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
|
||||||
accounts.store_slow_uncached(0, &keypair3.pubkey(), &account3);
|
accounts.store_slow_uncached(0, &keypair3.pubkey(), &account3);
|
||||||
|
|
||||||
let demote_program_write_locks = true;
|
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
||||||
let message = Message::new_with_compiled_instructions(
|
let message = Message::new_with_compiled_instructions(
|
||||||
1,
|
1,
|
||||||
|
@ -2383,7 +2354,7 @@ mod tests {
|
||||||
instructions,
|
instructions,
|
||||||
);
|
);
|
||||||
let tx = new_sanitized_tx(&[&keypair0], message, Hash::default());
|
let tx = new_sanitized_tx(&[&keypair0], message, Hash::default());
|
||||||
let results0 = accounts.lock_accounts([tx].iter(), demote_program_write_locks);
|
let results0 = accounts.lock_accounts([tx].iter());
|
||||||
|
|
||||||
assert!(results0[0].is_ok());
|
assert!(results0[0].is_ok());
|
||||||
// Instruction program-id account demoted to readonly
|
// Instruction program-id account demoted to readonly
|
||||||
|
@ -2436,8 +2407,6 @@ mod tests {
|
||||||
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
|
accounts.store_slow_uncached(0, &keypair2.pubkey(), &account2);
|
||||||
accounts.store_slow_uncached(0, &keypair3.pubkey(), &account3);
|
accounts.store_slow_uncached(0, &keypair3.pubkey(), &account3);
|
||||||
|
|
||||||
let demote_program_write_locks = true;
|
|
||||||
|
|
||||||
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
let instructions = vec![CompiledInstruction::new(2, &(), vec![0, 1])];
|
||||||
let message = Message::new_with_compiled_instructions(
|
let message = Message::new_with_compiled_instructions(
|
||||||
1,
|
1,
|
||||||
|
@ -2476,11 +2445,7 @@ mod tests {
|
||||||
Ok(()),
|
Ok(()),
|
||||||
];
|
];
|
||||||
|
|
||||||
let results = accounts.lock_accounts_with_results(
|
let results = accounts.lock_accounts_with_results(txs.iter(), qos_results.into_iter());
|
||||||
txs.iter(),
|
|
||||||
qos_results.into_iter(),
|
|
||||||
demote_program_write_locks,
|
|
||||||
);
|
|
||||||
|
|
||||||
assert!(results[0].is_ok()); // Read-only account (keypair0) can be referenced multiple times
|
assert!(results[0].is_ok()); // Read-only account (keypair0) can be referenced multiple times
|
||||||
assert!(results[1].is_err()); // is not locked due to !qos_results[1].is_ok()
|
assert!(results[1].is_err()); // is not locked due to !qos_results[1].is_ok()
|
||||||
|
@ -2506,7 +2471,7 @@ mod tests {
|
||||||
.get(&keypair2.pubkey())
|
.get(&keypair2.pubkey())
|
||||||
.is_none());
|
.is_none());
|
||||||
|
|
||||||
accounts.unlock_accounts(txs.iter(), &results, demote_program_write_locks);
|
accounts.unlock_accounts(txs.iter(), &results);
|
||||||
|
|
||||||
// check all locks to be removed
|
// check all locks to be removed
|
||||||
assert!(accounts
|
assert!(accounts
|
||||||
|
@ -2610,7 +2575,6 @@ mod tests {
|
||||||
&Hash::default(),
|
&Hash::default(),
|
||||||
0,
|
0,
|
||||||
true,
|
true,
|
||||||
true, // demote_program_write_locks
|
|
||||||
true, // leave_nonce_on_success
|
true, // leave_nonce_on_success
|
||||||
);
|
);
|
||||||
assert_eq!(collected_accounts.len(), 2);
|
assert_eq!(collected_accounts.len(), 2);
|
||||||
|
@ -3040,7 +3004,6 @@ mod tests {
|
||||||
&next_blockhash,
|
&next_blockhash,
|
||||||
0,
|
0,
|
||||||
true,
|
true,
|
||||||
true, // demote_program_write_locks
|
|
||||||
true, // leave_nonce_on_success
|
true, // leave_nonce_on_success
|
||||||
);
|
);
|
||||||
assert_eq!(collected_accounts.len(), 2);
|
assert_eq!(collected_accounts.len(), 2);
|
||||||
|
@ -3151,7 +3114,6 @@ mod tests {
|
||||||
&next_blockhash,
|
&next_blockhash,
|
||||||
0,
|
0,
|
||||||
true,
|
true,
|
||||||
true, // demote_program_write_locks
|
|
||||||
true, // leave_nonce_on_success
|
true, // leave_nonce_on_success
|
||||||
);
|
);
|
||||||
assert_eq!(collected_accounts.len(), 1);
|
assert_eq!(collected_accounts.len(), 1);
|
||||||
|
|
|
@ -3068,10 +3068,7 @@ impl Bank {
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(SanitizedTransaction::from_transaction_for_tests)
|
.map(SanitizedTransaction::from_transaction_for_tests)
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let lock_results = self
|
let lock_results = self.rc.accounts.lock_accounts(sanitized_txs.iter());
|
||||||
.rc
|
|
||||||
.accounts
|
|
||||||
.lock_accounts(sanitized_txs.iter(), self.demote_program_write_locks());
|
|
||||||
TransactionBatch::new(lock_results, self, Cow::Owned(sanitized_txs))
|
TransactionBatch::new(lock_results, self, Cow::Owned(sanitized_txs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3087,10 +3084,7 @@ impl Bank {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
.collect::<Result<Vec<_>>>()?;
|
.collect::<Result<Vec<_>>>()?;
|
||||||
let lock_results = self
|
let lock_results = self.rc.accounts.lock_accounts(sanitized_txs.iter());
|
||||||
.rc
|
|
||||||
.accounts
|
|
||||||
.lock_accounts(sanitized_txs.iter(), self.demote_program_write_locks());
|
|
||||||
Ok(TransactionBatch::new(
|
Ok(TransactionBatch::new(
|
||||||
lock_results,
|
lock_results,
|
||||||
self,
|
self,
|
||||||
|
@ -3103,10 +3097,7 @@ impl Bank {
|
||||||
&'a self,
|
&'a self,
|
||||||
txs: &'b [SanitizedTransaction],
|
txs: &'b [SanitizedTransaction],
|
||||||
) -> TransactionBatch<'a, 'b> {
|
) -> TransactionBatch<'a, 'b> {
|
||||||
let lock_results = self
|
let lock_results = self.rc.accounts.lock_accounts(txs.iter());
|
||||||
.rc
|
|
||||||
.accounts
|
|
||||||
.lock_accounts(txs.iter(), self.demote_program_write_locks());
|
|
||||||
TransactionBatch::new(lock_results, self, Cow::Borrowed(txs))
|
TransactionBatch::new(lock_results, self, Cow::Borrowed(txs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3118,11 +3109,10 @@ impl Bank {
|
||||||
transaction_results: impl Iterator<Item = Result<()>>,
|
transaction_results: impl Iterator<Item = Result<()>>,
|
||||||
) -> TransactionBatch<'a, 'b> {
|
) -> TransactionBatch<'a, 'b> {
|
||||||
// this lock_results could be: Ok, AccountInUse, WouldExceedBlockMaxLimit or WouldExceedAccountMaxLimit
|
// this lock_results could be: Ok, AccountInUse, WouldExceedBlockMaxLimit or WouldExceedAccountMaxLimit
|
||||||
let lock_results = self.rc.accounts.lock_accounts_with_results(
|
let lock_results = self
|
||||||
transactions.iter(),
|
.rc
|
||||||
transaction_results,
|
.accounts
|
||||||
self.demote_program_write_locks(),
|
.lock_accounts_with_results(transactions.iter(), transaction_results);
|
||||||
);
|
|
||||||
TransactionBatch::new(lock_results, self, Cow::Borrowed(transactions))
|
TransactionBatch::new(lock_results, self, Cow::Borrowed(transactions))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3204,11 +3194,9 @@ impl Bank {
|
||||||
pub fn unlock_accounts(&self, batch: &mut TransactionBatch) {
|
pub fn unlock_accounts(&self, batch: &mut TransactionBatch) {
|
||||||
if batch.needs_unlock {
|
if batch.needs_unlock {
|
||||||
batch.needs_unlock = false;
|
batch.needs_unlock = false;
|
||||||
self.rc.accounts.unlock_accounts(
|
self.rc
|
||||||
batch.sanitized_transactions().iter(),
|
.accounts
|
||||||
batch.lock_results(),
|
.unlock_accounts(batch.sanitized_transactions().iter(), batch.lock_results())
|
||||||
self.demote_program_write_locks(),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3921,7 +3909,6 @@ impl Bank {
|
||||||
&blockhash,
|
&blockhash,
|
||||||
lamports_per_signature,
|
lamports_per_signature,
|
||||||
self.rent_for_sysvars(),
|
self.rent_for_sysvars(),
|
||||||
self.demote_program_write_locks(),
|
|
||||||
self.leave_nonce_on_success(),
|
self.leave_nonce_on_success(),
|
||||||
);
|
);
|
||||||
let rent_debits = self.collect_rent(executed_results, loaded_txs);
|
let rent_debits = self.collect_rent(executed_results, loaded_txs);
|
||||||
|
@ -5768,11 +5755,6 @@ impl Bank {
|
||||||
.is_active(&feature_set::stake_program_advance_activating_credits_observed::id())
|
.is_active(&feature_set::stake_program_advance_activating_credits_observed::id())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn demote_program_write_locks(&self) -> bool {
|
|
||||||
self.feature_set
|
|
||||||
.is_active(&feature_set::demote_program_write_locks::id())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn leave_nonce_on_success(&self) -> bool {
|
pub fn leave_nonce_on_success(&self) -> bool {
|
||||||
self.feature_set
|
self.feature_set
|
||||||
.is_active(&feature_set::leave_nonce_on_success::id())
|
.is_active(&feature_set::leave_nonce_on_success::id())
|
||||||
|
@ -7271,10 +7253,7 @@ pub(crate) mod tests {
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
bank.process_transaction(&tx),
|
bank.process_transaction(&tx),
|
||||||
Err(TransactionError::InstructionError(
|
Err(TransactionError::InvalidWritableAccount)
|
||||||
0,
|
|
||||||
InstructionError::ExecutableLamportChange
|
|
||||||
))
|
|
||||||
);
|
);
|
||||||
assert_eq!(bank.get_balance(&account_pubkey), account_balance);
|
assert_eq!(bank.get_balance(&account_pubkey), account_balance);
|
||||||
}
|
}
|
||||||
|
|
|
@ -111,15 +111,11 @@ impl CostModel {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn calculate_cost(
|
pub fn calculate_cost(&self, transaction: &SanitizedTransaction) -> TransactionCost {
|
||||||
&self,
|
|
||||||
transaction: &SanitizedTransaction,
|
|
||||||
demote_program_write_locks: bool,
|
|
||||||
) -> TransactionCost {
|
|
||||||
let mut tx_cost = TransactionCost::new_with_capacity(MAX_WRITABLE_ACCOUNTS);
|
let mut tx_cost = TransactionCost::new_with_capacity(MAX_WRITABLE_ACCOUNTS);
|
||||||
|
|
||||||
tx_cost.signature_cost = self.get_signature_cost(transaction);
|
tx_cost.signature_cost = self.get_signature_cost(transaction);
|
||||||
self.get_write_lock_cost(&mut tx_cost, transaction, demote_program_write_locks);
|
self.get_write_lock_cost(&mut tx_cost, transaction);
|
||||||
tx_cost.data_bytes_cost = self.get_data_bytes_cost(transaction);
|
tx_cost.data_bytes_cost = self.get_data_bytes_cost(transaction);
|
||||||
tx_cost.execution_cost = self.get_transaction_cost(transaction);
|
tx_cost.execution_cost = self.get_transaction_cost(transaction);
|
||||||
tx_cost.cost_weight = self.calculate_cost_weight(transaction);
|
tx_cost.cost_weight = self.calculate_cost_weight(transaction);
|
||||||
|
@ -154,11 +150,10 @@ impl CostModel {
|
||||||
&self,
|
&self,
|
||||||
tx_cost: &mut TransactionCost,
|
tx_cost: &mut TransactionCost,
|
||||||
transaction: &SanitizedTransaction,
|
transaction: &SanitizedTransaction,
|
||||||
demote_program_write_locks: bool,
|
|
||||||
) {
|
) {
|
||||||
let message = transaction.message();
|
let message = transaction.message();
|
||||||
message.account_keys_iter().enumerate().for_each(|(i, k)| {
|
message.account_keys_iter().enumerate().for_each(|(i, k)| {
|
||||||
let is_writable = message.is_writable(i, demote_program_write_locks);
|
let is_writable = message.is_writable(i);
|
||||||
|
|
||||||
if is_writable {
|
if is_writable {
|
||||||
tx_cost.writable_accounts.push(*k);
|
tx_cost.writable_accounts.push(*k);
|
||||||
|
@ -487,7 +482,7 @@ mod tests {
|
||||||
);
|
);
|
||||||
|
|
||||||
let cost_model = CostModel::default();
|
let cost_model = CostModel::default();
|
||||||
let tx_cost = cost_model.calculate_cost(&tx, /*demote_program_write_locks=*/ true);
|
let tx_cost = cost_model.calculate_cost(&tx);
|
||||||
assert_eq!(2 + 2, tx_cost.writable_accounts.len());
|
assert_eq!(2 + 2, tx_cost.writable_accounts.len());
|
||||||
assert_eq!(signer1.pubkey(), tx_cost.writable_accounts[0]);
|
assert_eq!(signer1.pubkey(), tx_cost.writable_accounts[0]);
|
||||||
assert_eq!(signer2.pubkey(), tx_cost.writable_accounts[1]);
|
assert_eq!(signer2.pubkey(), tx_cost.writable_accounts[1]);
|
||||||
|
@ -531,7 +526,7 @@ mod tests {
|
||||||
cost_model
|
cost_model
|
||||||
.upsert_instruction_cost(&system_program::id(), expected_execution_cost)
|
.upsert_instruction_cost(&system_program::id(), expected_execution_cost)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let tx_cost = cost_model.calculate_cost(&tx, /*demote_program_write_locks=*/ true);
|
let tx_cost = cost_model.calculate_cost(&tx);
|
||||||
assert_eq!(expected_account_cost, tx_cost.write_lock_cost);
|
assert_eq!(expected_account_cost, tx_cost.write_lock_cost);
|
||||||
assert_eq!(expected_execution_cost, tx_cost.execution_cost);
|
assert_eq!(expected_execution_cost, tx_cost.execution_cost);
|
||||||
assert_eq!(2, tx_cost.writable_accounts.len());
|
assert_eq!(2, tx_cost.writable_accounts.len());
|
||||||
|
@ -600,8 +595,7 @@ mod tests {
|
||||||
} else {
|
} else {
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
let cost_model = cost_model.write().unwrap();
|
let cost_model = cost_model.write().unwrap();
|
||||||
let tx_cost = cost_model
|
let tx_cost = cost_model.calculate_cost(&tx);
|
||||||
.calculate_cost(&tx, /*demote_program_write_locks=*/ true);
|
|
||||||
assert_eq!(3, tx_cost.writable_accounts.len());
|
assert_eq!(3, tx_cost.writable_accounts.len());
|
||||||
assert_eq!(expected_account_cost, tx_cost.write_lock_cost);
|
assert_eq!(expected_account_cost, tx_cost.write_lock_cost);
|
||||||
})
|
})
|
||||||
|
|
|
@ -19,8 +19,6 @@ fn make_instructions() -> Vec<Instruction> {
|
||||||
vec![inst; 4]
|
vec![inst; 4]
|
||||||
}
|
}
|
||||||
|
|
||||||
const DEMOTE_PROGRAM_WRITE_LOCKS: bool = true;
|
|
||||||
|
|
||||||
#[bench]
|
#[bench]
|
||||||
fn bench_bincode_instruction_serialize(b: &mut Bencher) {
|
fn bench_bincode_instruction_serialize(b: &mut Bencher) {
|
||||||
let instructions = make_instructions();
|
let instructions = make_instructions();
|
||||||
|
@ -36,7 +34,7 @@ fn bench_manual_instruction_serialize(b: &mut Bencher) {
|
||||||
SanitizedMessage::try_from(Message::new(&instructions, Some(&Pubkey::new_unique())))
|
SanitizedMessage::try_from(Message::new(&instructions, Some(&Pubkey::new_unique())))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
test::black_box(message.serialize_instructions(DEMOTE_PROGRAM_WRITE_LOCKS));
|
test::black_box(message.serialize_instructions());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +53,7 @@ fn bench_manual_instruction_deserialize(b: &mut Bencher) {
|
||||||
let message =
|
let message =
|
||||||
SanitizedMessage::try_from(Message::new(&instructions, Some(&Pubkey::new_unique())))
|
SanitizedMessage::try_from(Message::new(&instructions, Some(&Pubkey::new_unique())))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let serialized = message.serialize_instructions(DEMOTE_PROGRAM_WRITE_LOCKS);
|
let serialized = message.serialize_instructions();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
for i in 0..instructions.len() {
|
for i in 0..instructions.len() {
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
|
@ -70,7 +68,7 @@ fn bench_manual_instruction_deserialize_single(b: &mut Bencher) {
|
||||||
let message =
|
let message =
|
||||||
SanitizedMessage::try_from(Message::new(&instructions, Some(&Pubkey::new_unique())))
|
SanitizedMessage::try_from(Message::new(&instructions, Some(&Pubkey::new_unique())))
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let serialized = message.serialize_instructions(DEMOTE_PROGRAM_WRITE_LOCKS);
|
let serialized = message.serialize_instructions();
|
||||||
b.iter(|| {
|
b.iter(|| {
|
||||||
#[allow(deprecated)]
|
#[allow(deprecated)]
|
||||||
test::black_box(instructions::load_instruction_at(3, &serialized).unwrap());
|
test::black_box(instructions::load_instruction_at(3, &serialized).unwrap());
|
||||||
|
|
|
@ -367,10 +367,9 @@ impl Message {
|
||||||
self.program_position(i).is_some()
|
self.program_position(i).is_some()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_writable(&self, i: usize, demote_program_write_locks: bool) -> bool {
|
pub fn is_writable(&self, i: usize) -> bool {
|
||||||
let demote_program_id = demote_program_write_locks
|
let demote_program_id =
|
||||||
&& self.is_key_called_as_program(i)
|
self.is_key_called_as_program(i) && !self.is_upgradeable_loader_present();
|
||||||
&& !self.is_upgradeable_loader_present();
|
|
||||||
(i < (self.header.num_required_signatures - self.header.num_readonly_signed_accounts)
|
(i < (self.header.num_required_signatures - self.header.num_readonly_signed_accounts)
|
||||||
as usize
|
as usize
|
||||||
|| (i >= self.header.num_required_signatures as usize
|
|| (i >= self.header.num_required_signatures as usize
|
||||||
|
@ -392,7 +391,7 @@ impl Message {
|
||||||
let mut writable_keys = vec![];
|
let mut writable_keys = vec![];
|
||||||
let mut readonly_keys = vec![];
|
let mut readonly_keys = vec![];
|
||||||
for (i, key) in self.account_keys.iter().enumerate() {
|
for (i, key) in self.account_keys.iter().enumerate() {
|
||||||
if self.is_writable(i, /*demote_program_write_locks=*/ true) {
|
if self.is_writable(i) {
|
||||||
writable_keys.push(key);
|
writable_keys.push(key);
|
||||||
} else {
|
} else {
|
||||||
readonly_keys.push(key);
|
readonly_keys.push(key);
|
||||||
|
@ -430,8 +429,7 @@ impl Message {
|
||||||
for account_index in &instruction.accounts {
|
for account_index in &instruction.accounts {
|
||||||
let account_index = *account_index as usize;
|
let account_index = *account_index as usize;
|
||||||
let is_signer = self.is_signer(account_index);
|
let is_signer = self.is_signer(account_index);
|
||||||
let is_writable =
|
let is_writable = self.is_writable(account_index);
|
||||||
self.is_writable(account_index, /*demote_program_write_locks=*/ true);
|
|
||||||
let mut meta_byte = 0;
|
let mut meta_byte = 0;
|
||||||
if is_signer {
|
if is_signer {
|
||||||
meta_byte |= 1 << Self::IS_SIGNER_BIT;
|
meta_byte |= 1 << Self::IS_SIGNER_BIT;
|
||||||
|
@ -894,13 +892,12 @@ mod tests {
|
||||||
recent_blockhash: Hash::default(),
|
recent_blockhash: Hash::default(),
|
||||||
instructions: vec![],
|
instructions: vec![],
|
||||||
};
|
};
|
||||||
let demote_program_write_locks = true;
|
assert!(message.is_writable(0));
|
||||||
assert!(message.is_writable(0, demote_program_write_locks));
|
assert!(!message.is_writable(1));
|
||||||
assert!(!message.is_writable(1, demote_program_write_locks));
|
assert!(!message.is_writable(2));
|
||||||
assert!(!message.is_writable(2, demote_program_write_locks));
|
assert!(message.is_writable(3));
|
||||||
assert!(message.is_writable(3, demote_program_write_locks));
|
assert!(message.is_writable(4));
|
||||||
assert!(message.is_writable(4, demote_program_write_locks));
|
assert!(!message.is_writable(5));
|
||||||
assert!(!message.is_writable(5, demote_program_write_locks));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -187,10 +187,10 @@ impl SanitizedMessage {
|
||||||
|
|
||||||
/// Returns true if the account at the specified index is writable by the
|
/// Returns true if the account at the specified index is writable by the
|
||||||
/// instructions in this message.
|
/// instructions in this message.
|
||||||
pub fn is_writable(&self, index: usize, demote_program_write_locks: bool) -> bool {
|
pub fn is_writable(&self, index: usize) -> bool {
|
||||||
match self {
|
match self {
|
||||||
Self::Legacy(message) => message.is_writable(index, demote_program_write_locks),
|
Self::Legacy(message) => message.is_writable(index),
|
||||||
Self::V0(message) => message.is_writable(index, demote_program_write_locks),
|
Self::V0(message) => message.is_writable(index),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,7 +214,7 @@ impl SanitizedMessage {
|
||||||
// 67..69 - data len - u16
|
// 67..69 - data len - u16
|
||||||
// 69..data_len - data
|
// 69..data_len - data
|
||||||
#[allow(clippy::integer_arithmetic)]
|
#[allow(clippy::integer_arithmetic)]
|
||||||
pub fn serialize_instructions(&self, demote_program_write_locks: bool) -> Vec<u8> {
|
pub fn serialize_instructions(&self) -> Vec<u8> {
|
||||||
// 64 bytes is a reasonable guess, calculating exactly is slower in benchmarks
|
// 64 bytes is a reasonable guess, calculating exactly is slower in benchmarks
|
||||||
let mut data = Vec::with_capacity(self.instructions().len() * (32 * 2));
|
let mut data = Vec::with_capacity(self.instructions().len() * (32 * 2));
|
||||||
append_u16(&mut data, self.instructions().len() as u16);
|
append_u16(&mut data, self.instructions().len() as u16);
|
||||||
|
@ -229,7 +229,7 @@ impl SanitizedMessage {
|
||||||
for account_index in &instruction.accounts {
|
for account_index in &instruction.accounts {
|
||||||
let account_index = *account_index as usize;
|
let account_index = *account_index as usize;
|
||||||
let is_signer = self.is_signer(account_index);
|
let is_signer = self.is_signer(account_index);
|
||||||
let is_writable = self.is_writable(account_index, demote_program_write_locks);
|
let is_writable = self.is_writable(account_index);
|
||||||
let mut account_meta = InstructionsSysvarAccountMeta::NONE;
|
let mut account_meta = InstructionsSysvarAccountMeta::NONE;
|
||||||
if is_signer {
|
if is_signer {
|
||||||
account_meta |= InstructionsSysvarAccountMeta::IS_SIGNER;
|
account_meta |= InstructionsSysvarAccountMeta::IS_SIGNER;
|
||||||
|
@ -426,10 +426,9 @@ mod tests {
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
let demote_program_write_locks = true;
|
|
||||||
let message = LegacyMessage::new(&instructions, Some(&id1));
|
let message = LegacyMessage::new(&instructions, Some(&id1));
|
||||||
let sanitized_message = SanitizedMessage::try_from(message.clone()).unwrap();
|
let sanitized_message = SanitizedMessage::try_from(message.clone()).unwrap();
|
||||||
let serialized = sanitized_message.serialize_instructions(demote_program_write_locks);
|
let serialized = sanitized_message.serialize_instructions();
|
||||||
|
|
||||||
// assert that SanitizedMessage::serialize_instructions has the same behavior as the
|
// assert that SanitizedMessage::serialize_instructions has the same behavior as the
|
||||||
// deprecated Message::serialize_instructions method
|
// deprecated Message::serialize_instructions method
|
||||||
|
|
|
@ -104,11 +104,10 @@ impl LoadedMessage {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if the account at the specified index was loaded as writable
|
/// Returns true if the account at the specified index was loaded as writable
|
||||||
pub fn is_writable(&self, key_index: usize, demote_program_write_locks: bool) -> bool {
|
pub fn is_writable(&self, key_index: usize) -> bool {
|
||||||
if self.is_writable_index(key_index) {
|
if self.is_writable_index(key_index) {
|
||||||
if let Some(key) = self.get_account_key(key_index) {
|
if let Some(key) = self.get_account_key(key_index) {
|
||||||
let demote_program_id = demote_program_write_locks
|
let demote_program_id = self.is_key_called_as_program(key_index)
|
||||||
&& self.is_key_called_as_program(key_index)
|
|
||||||
&& !self.is_upgradeable_loader_present();
|
&& !self.is_upgradeable_loader_present();
|
||||||
return !(sysvar::is_sysvar_id(key)
|
return !(sysvar::is_sysvar_id(key)
|
||||||
|| BUILTIN_PROGRAMS_KEYS.contains(key)
|
|| BUILTIN_PROGRAMS_KEYS.contains(key)
|
||||||
|
@ -269,11 +268,11 @@ mod tests {
|
||||||
|
|
||||||
message.message.account_keys[0] = sysvar::clock::id();
|
message.message.account_keys[0] = sysvar::clock::id();
|
||||||
assert!(message.is_writable_index(0));
|
assert!(message.is_writable_index(0));
|
||||||
assert!(!message.is_writable(0, /*demote_program_write_locks=*/ true));
|
assert!(!message.is_writable(0));
|
||||||
|
|
||||||
message.message.account_keys[0] = system_program::id();
|
message.message.account_keys[0] = system_program::id();
|
||||||
assert!(message.is_writable_index(0));
|
assert!(message.is_writable_index(0));
|
||||||
assert!(!message.is_writable(0, /*demote_program_write_locks=*/ true));
|
assert!(!message.is_writable(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -303,6 +302,6 @@ mod tests {
|
||||||
};
|
};
|
||||||
|
|
||||||
assert!(message.is_writable_index(2));
|
assert!(message.is_writable_index(2));
|
||||||
assert!(!message.is_writable(2, /*demote_program_write_locks=*/ true));
|
assert!(!message.is_writable(2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,11 +13,8 @@ crate::declare_sysvar_id!("Sysvar1nstructions1111111111111111111111111", Instruc
|
||||||
|
|
||||||
// Construct the account data for the Instruction sSysvar
|
// Construct the account data for the Instruction sSysvar
|
||||||
#[cfg(not(target_arch = "bpf"))]
|
#[cfg(not(target_arch = "bpf"))]
|
||||||
pub fn construct_instructions_data(
|
pub fn construct_instructions_data(message: &crate::message::SanitizedMessage) -> Vec<u8> {
|
||||||
message: &crate::message::SanitizedMessage,
|
let mut data = message.serialize_instructions();
|
||||||
demote_program_write_locks: bool,
|
|
||||||
) -> Vec<u8> {
|
|
||||||
let mut data = message.serialize_instructions(demote_program_write_locks);
|
|
||||||
// add room for current instruction index.
|
// add room for current instruction index.
|
||||||
data.resize(data.len() + 2, 0);
|
data.resize(data.len() + 2, 0);
|
||||||
|
|
||||||
|
@ -154,7 +151,7 @@ mod tests {
|
||||||
|
|
||||||
let key = id();
|
let key = id();
|
||||||
let mut lamports = 0;
|
let mut lamports = 0;
|
||||||
let mut data = construct_instructions_data(&sanitized_message, true);
|
let mut data = construct_instructions_data(&sanitized_message);
|
||||||
let owner = crate::sysvar::id();
|
let owner = crate::sysvar::id();
|
||||||
let mut account_info = AccountInfo::new(
|
let mut account_info = AccountInfo::new(
|
||||||
&key,
|
&key,
|
||||||
|
@ -208,7 +205,7 @@ mod tests {
|
||||||
|
|
||||||
let key = id();
|
let key = id();
|
||||||
let mut lamports = 0;
|
let mut lamports = 0;
|
||||||
let mut data = construct_instructions_data(&sanitized_message, true);
|
let mut data = construct_instructions_data(&sanitized_message);
|
||||||
store_current_index(&mut data, 1);
|
store_current_index(&mut data, 1);
|
||||||
let owner = crate::sysvar::id();
|
let owner = crate::sysvar::id();
|
||||||
let mut account_info = AccountInfo::new(
|
let mut account_info = AccountInfo::new(
|
||||||
|
@ -266,7 +263,7 @@ mod tests {
|
||||||
|
|
||||||
let key = id();
|
let key = id();
|
||||||
let mut lamports = 0;
|
let mut lamports = 0;
|
||||||
let mut data = construct_instructions_data(&sanitized_message, true);
|
let mut data = construct_instructions_data(&sanitized_message);
|
||||||
store_current_index(&mut data, 1);
|
store_current_index(&mut data, 1);
|
||||||
let owner = crate::sysvar::id();
|
let owner = crate::sysvar::id();
|
||||||
let mut account_info = AccountInfo::new(
|
let mut account_info = AccountInfo::new(
|
||||||
|
|
|
@ -410,7 +410,7 @@ pub fn uses_durable_nonce(tx: &Transaction) -> Option<&CompiledInstruction> {
|
||||||
// Nonce account is writable
|
// Nonce account is writable
|
||||||
&& matches!(
|
&& matches!(
|
||||||
instruction.accounts.get(0),
|
instruction.accounts.get(0),
|
||||||
Some(index) if message.is_writable(*index as usize, true)
|
Some(index) if message.is_writable(*index as usize)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -140,7 +140,7 @@ impl SanitizedTransaction {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Return the list of accounts that must be locked during processing this transaction.
|
/// Return the list of accounts that must be locked during processing this transaction.
|
||||||
pub fn get_account_locks(&self, demote_program_write_locks: bool) -> TransactionAccountLocks {
|
pub fn get_account_locks(&self) -> TransactionAccountLocks {
|
||||||
let message = &self.message;
|
let message = &self.message;
|
||||||
let num_readonly_accounts = message.num_readonly_accounts();
|
let num_readonly_accounts = message.num_readonly_accounts();
|
||||||
let num_writable_accounts = message
|
let num_writable_accounts = message
|
||||||
|
@ -153,7 +153,7 @@ impl SanitizedTransaction {
|
||||||
};
|
};
|
||||||
|
|
||||||
for (i, key) in message.account_keys_iter().enumerate() {
|
for (i, key) in message.account_keys_iter().enumerate() {
|
||||||
if message.is_writable(i, demote_program_write_locks) {
|
if message.is_writable(i) {
|
||||||
account_locks.writable.push(key);
|
account_locks.writable.push(key);
|
||||||
} else {
|
} else {
|
||||||
account_locks.readonly.push(key);
|
account_locks.readonly.push(key);
|
||||||
|
@ -183,7 +183,7 @@ impl SanitizedTransaction {
|
||||||
.and_then(|ix| {
|
.and_then(|ix| {
|
||||||
ix.accounts.get(0).and_then(|idx| {
|
ix.accounts.get(0).and_then(|idx| {
|
||||||
let idx = *idx as usize;
|
let idx = *idx as usize;
|
||||||
if nonce_must_be_writable && !self.message.is_writable(idx, true) {
|
if nonce_must_be_writable && !self.message.is_writable(idx) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
self.message.get_account_key(idx)
|
self.message.get_account_key(idx)
|
||||||
|
|
|
@ -13,7 +13,7 @@ pub fn parse_accounts(message: &Message) -> Vec<ParsedAccount> {
|
||||||
for (i, account_key) in message.account_keys.iter().enumerate() {
|
for (i, account_key) in message.account_keys.iter().enumerate() {
|
||||||
accounts.push(ParsedAccount {
|
accounts.push(ParsedAccount {
|
||||||
pubkey: account_key.to_string(),
|
pubkey: account_key.to_string(),
|
||||||
writable: message.is_writable(i, /*demote_program_write_locks=*/ true),
|
writable: message.is_writable(i),
|
||||||
signer: message.is_signer(i),
|
signer: message.is_signer(i),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue