This reverts commit eaa8c67bde
.
This commit is contained in:
@ -25,7 +25,7 @@ use {
|
|||||||
TransactionExecutionResult,
|
TransactionExecutionResult,
|
||||||
},
|
},
|
||||||
bank_utils,
|
bank_utils,
|
||||||
cost_model::{CostModel, ExecutionCost},
|
cost_model::CostModel,
|
||||||
transaction_batch::TransactionBatch,
|
transaction_batch::TransactionBatch,
|
||||||
vote_sender_types::ReplayVoteSender,
|
vote_sender_types::ReplayVoteSender,
|
||||||
},
|
},
|
||||||
@ -974,20 +974,14 @@ impl BankingStage {
|
|||||||
let tx_costs = qos_service.compute_transaction_costs(txs.iter());
|
let tx_costs = qos_service.compute_transaction_costs(txs.iter());
|
||||||
|
|
||||||
let transactions_qos_results =
|
let transactions_qos_results =
|
||||||
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.into_iter(), bank);
|
qos_service.select_transactions_per_cost(txs.iter(), tx_costs.iter(), bank);
|
||||||
|
|
||||||
// Only lock accounts for those transactions are selected for the block;
|
// Only lock accounts for those transactions are selected for the block;
|
||||||
// Once accounts are locked, other threads cannot encode transactions that will modify the
|
// Once accounts are locked, other threads cannot encode transactions that will modify the
|
||||||
// same account state
|
// same account state
|
||||||
let mut lock_time = Measure::start("lock_time");
|
let mut lock_time = Measure::start("lock_time");
|
||||||
let batch = bank.prepare_sanitized_batch_with_results(
|
let batch =
|
||||||
txs,
|
bank.prepare_sanitized_batch_with_results(txs, transactions_qos_results.into_iter());
|
||||||
transactions_qos_results
|
|
||||||
.into_iter()
|
|
||||||
.map(|transaction_cost_result| {
|
|
||||||
transaction_cost_result.map(|transaction_cost| transaction_cost.execution_cost)
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
lock_time.stop();
|
lock_time.stop();
|
||||||
|
|
||||||
// retryable_txs includes AccountInUse, WouldExceedMaxBlockCostLimit
|
// retryable_txs includes AccountInUse, WouldExceedMaxBlockCostLimit
|
||||||
@ -1087,9 +1081,9 @@ impl BankingStage {
|
|||||||
fn prepare_filter_for_pending_transactions(
|
fn prepare_filter_for_pending_transactions(
|
||||||
transactions_len: usize,
|
transactions_len: usize,
|
||||||
pending_tx_indexes: &[usize],
|
pending_tx_indexes: &[usize],
|
||||||
) -> Vec<transaction::Result<ExecutionCost>> {
|
) -> Vec<transaction::Result<()>> {
|
||||||
let mut mask = vec![Err(TransactionError::BlockhashNotFound); transactions_len];
|
let mut mask = vec![Err(TransactionError::BlockhashNotFound); transactions_len];
|
||||||
pending_tx_indexes.iter().for_each(|x| mask[*x] = Ok(0));
|
pending_tx_indexes.iter().for_each(|x| mask[*x] = Ok(()));
|
||||||
mask
|
mask
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1180,7 +1174,7 @@ impl BankingStage {
|
|||||||
|
|
||||||
let results = bank.check_transactions(
|
let results = bank.check_transactions(
|
||||||
transactions,
|
transactions,
|
||||||
filter.into_iter(),
|
&filter,
|
||||||
(MAX_PROCESSING_AGE)
|
(MAX_PROCESSING_AGE)
|
||||||
.saturating_sub(max_tx_fwd_delay)
|
.saturating_sub(max_tx_fwd_delay)
|
||||||
.saturating_sub(FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET as usize),
|
.saturating_sub(FORWARD_TRANSACTIONS_TO_LEADER_AT_SLOT_OFFSET as usize),
|
||||||
@ -1985,20 +1979,20 @@ mod tests {
|
|||||||
vec![
|
vec![
|
||||||
Err(TransactionError::BlockhashNotFound),
|
Err(TransactionError::BlockhashNotFound),
|
||||||
Err(TransactionError::BlockhashNotFound),
|
Err(TransactionError::BlockhashNotFound),
|
||||||
Ok(0),
|
Ok(()),
|
||||||
Err(TransactionError::BlockhashNotFound),
|
Err(TransactionError::BlockhashNotFound),
|
||||||
Ok(0),
|
Ok(()),
|
||||||
Ok(0)
|
Ok(())
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
BankingStage::prepare_filter_for_pending_transactions(6, &[0, 2, 3]),
|
BankingStage::prepare_filter_for_pending_transactions(6, &[0, 2, 3]),
|
||||||
vec![
|
vec![
|
||||||
Ok(0),
|
Ok(()),
|
||||||
Err(TransactionError::BlockhashNotFound),
|
Err(TransactionError::BlockhashNotFound),
|
||||||
Ok(0),
|
Ok(()),
|
||||||
Ok(0),
|
Ok(()),
|
||||||
Err(TransactionError::BlockhashNotFound),
|
Err(TransactionError::BlockhashNotFound),
|
||||||
Err(TransactionError::BlockhashNotFound),
|
Err(TransactionError::BlockhashNotFound),
|
||||||
]
|
]
|
||||||
@ -2012,10 +2006,10 @@ mod tests {
|
|||||||
&[
|
&[
|
||||||
(Err(TransactionError::BlockhashNotFound), None),
|
(Err(TransactionError::BlockhashNotFound), None),
|
||||||
(Err(TransactionError::BlockhashNotFound), None),
|
(Err(TransactionError::BlockhashNotFound), None),
|
||||||
(Ok(0), None),
|
(Ok(()), None),
|
||||||
(Err(TransactionError::BlockhashNotFound), None),
|
(Err(TransactionError::BlockhashNotFound), None),
|
||||||
(Ok(0), None),
|
(Ok(()), None),
|
||||||
(Ok(0), None),
|
(Ok(()), None),
|
||||||
],
|
],
|
||||||
&[2, 4, 5, 9, 11, 13]
|
&[2, 4, 5, 9, 11, 13]
|
||||||
),
|
),
|
||||||
@ -2025,12 +2019,12 @@ mod tests {
|
|||||||
assert_eq!(
|
assert_eq!(
|
||||||
BankingStage::filter_valid_transaction_indexes(
|
BankingStage::filter_valid_transaction_indexes(
|
||||||
&[
|
&[
|
||||||
(Ok(0), None),
|
(Ok(()), None),
|
||||||
(Err(TransactionError::BlockhashNotFound), None),
|
(Err(TransactionError::BlockhashNotFound), None),
|
||||||
(Err(TransactionError::BlockhashNotFound), None),
|
(Err(TransactionError::BlockhashNotFound), None),
|
||||||
(Ok(0), None),
|
(Ok(()), None),
|
||||||
(Ok(0), None),
|
(Ok(()), None),
|
||||||
(Ok(0), None),
|
(Ok(()), None),
|
||||||
],
|
],
|
||||||
&[1, 6, 7, 9, 31, 43]
|
&[1, 6, 7, 9, 31, 43]
|
||||||
),
|
),
|
||||||
|
@ -246,7 +246,6 @@ mod tests {
|
|||||||
ProgramTiming {
|
ProgramTiming {
|
||||||
accumulated_us,
|
accumulated_us,
|
||||||
accumulated_units,
|
accumulated_units,
|
||||||
current_cost_model_estimated_units: 0,
|
|
||||||
count,
|
count,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
@ -282,7 +281,6 @@ mod tests {
|
|||||||
ProgramTiming {
|
ProgramTiming {
|
||||||
accumulated_us,
|
accumulated_us,
|
||||||
accumulated_units,
|
accumulated_units,
|
||||||
current_cost_model_estimated_units: 0,
|
|
||||||
count,
|
count,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -117,18 +117,18 @@ impl QosService {
|
|||||||
pub fn select_transactions_per_cost<'a>(
|
pub fn select_transactions_per_cost<'a>(
|
||||||
&self,
|
&self,
|
||||||
transactions: impl Iterator<Item = &'a SanitizedTransaction>,
|
transactions: impl Iterator<Item = &'a SanitizedTransaction>,
|
||||||
transactions_costs: impl Iterator<Item = TransactionCost>,
|
transactions_costs: impl Iterator<Item = &'a TransactionCost>,
|
||||||
bank: &Arc<Bank>,
|
bank: &Arc<Bank>,
|
||||||
) -> Vec<transaction::Result<TransactionCost>> {
|
) -> Vec<transaction::Result<()>> {
|
||||||
let mut cost_tracking_time = Measure::start("cost_tracking_time");
|
let mut cost_tracking_time = Measure::start("cost_tracking_time");
|
||||||
let mut cost_tracker = bank.write_cost_tracker().unwrap();
|
let mut cost_tracker = bank.write_cost_tracker().unwrap();
|
||||||
let select_results = transactions
|
let select_results = transactions
|
||||||
.zip(transactions_costs)
|
.zip(transactions_costs)
|
||||||
.map(|(tx, cost)| match cost_tracker.try_add(tx, &cost) {
|
.map(|(tx, cost)| match cost_tracker.try_add(tx, cost) {
|
||||||
Ok(current_block_cost) => {
|
Ok(current_block_cost) => {
|
||||||
debug!("slot {:?}, transaction {:?}, cost {:?}, fit into current block, current block cost {}", bank.slot(), tx, cost, current_block_cost);
|
debug!("slot {:?}, transaction {:?}, cost {:?}, fit into current block, current block cost {}", bank.slot(), tx, cost, current_block_cost);
|
||||||
self.metrics.selected_txs_count.fetch_add(1, Ordering::Relaxed);
|
self.metrics.selected_txs_count.fetch_add(1, Ordering::Relaxed);
|
||||||
Ok(cost)
|
Ok(())
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
debug!("slot {:?}, transaction {:?}, cost {:?}, not fit into current block, '{:?}'", bank.slot(), tx, cost, e);
|
debug!("slot {:?}, transaction {:?}, cost {:?}, not fit into current block, '{:?}'", bank.slot(), tx, cost, e);
|
||||||
@ -441,8 +441,7 @@ mod tests {
|
|||||||
bank.write_cost_tracker()
|
bank.write_cost_tracker()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.set_limits(cost_limit, cost_limit);
|
.set_limits(cost_limit, cost_limit);
|
||||||
let results =
|
let results = qos_service.select_transactions_per_cost(txs.iter(), txs_costs.iter(), &bank);
|
||||||
qos_service.select_transactions_per_cost(txs.iter(), txs_costs.into_iter(), &bank);
|
|
||||||
|
|
||||||
// verify that first transfer tx and all votes are allowed
|
// verify that first transfer tx and all votes are allowed
|
||||||
assert_eq!(results.len(), txs.len());
|
assert_eq!(results.len(), txs.len());
|
||||||
|
@ -102,10 +102,10 @@ thread_local!(static PAR_THREAD_POOL: RefCell<ThreadPool> = RefCell::new(rayon::
|
|||||||
.unwrap())
|
.unwrap())
|
||||||
);
|
);
|
||||||
|
|
||||||
fn first_err<T>(results: &[Result<T>]) -> Result<()> {
|
fn first_err(results: &[Result<()>]) -> Result<()> {
|
||||||
for r in results {
|
for r in results {
|
||||||
if let Err(e) = r {
|
if r.is_err() {
|
||||||
return Err(e.clone());
|
return r.clone();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -28,12 +28,6 @@ use {
|
|||||||
pub type ProcessInstructionWithContext =
|
pub type ProcessInstructionWithContext =
|
||||||
fn(usize, &[u8], &mut InvokeContext) -> Result<(), InstructionError>;
|
fn(usize, &[u8], &mut InvokeContext) -> Result<(), InstructionError>;
|
||||||
|
|
||||||
#[derive(Debug, PartialEq)]
|
|
||||||
pub struct ProcessInstructionResult {
|
|
||||||
pub compute_units_consumed: u64,
|
|
||||||
pub result: Result<(), InstructionError>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct BuiltinProgram {
|
pub struct BuiltinProgram {
|
||||||
pub program_id: Pubkey,
|
pub program_id: Pubkey,
|
||||||
@ -520,8 +514,7 @@ impl<'a> InvokeContext<'a> {
|
|||||||
&instruction_accounts,
|
&instruction_accounts,
|
||||||
Some(&caller_write_privileges),
|
Some(&caller_write_privileges),
|
||||||
&program_indices,
|
&program_indices,
|
||||||
)
|
)?;
|
||||||
.result?;
|
|
||||||
|
|
||||||
// Verify the called program has not misbehaved
|
// Verify the called program has not misbehaved
|
||||||
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());
|
||||||
@ -702,7 +695,7 @@ impl<'a> InvokeContext<'a> {
|
|||||||
instruction_accounts: &[InstructionAccount],
|
instruction_accounts: &[InstructionAccount],
|
||||||
caller_write_privileges: Option<&[bool]>,
|
caller_write_privileges: Option<&[bool]>,
|
||||||
program_indices: &[usize],
|
program_indices: &[usize],
|
||||||
) -> ProcessInstructionResult {
|
) -> Result<u64, InstructionError> {
|
||||||
let program_id = program_indices
|
let program_id = program_indices
|
||||||
.last()
|
.last()
|
||||||
.map(|index| *self.transaction_context.get_key_of_account_at_index(*index))
|
.map(|index| *self.transaction_context.get_key_of_account_at_index(*index))
|
||||||
@ -715,13 +708,8 @@ impl<'a> InvokeContext<'a> {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Verify the calling program hasn't misbehaved
|
// Verify the calling program hasn't misbehaved
|
||||||
let result = self.verify_and_update(instruction_accounts, caller_write_privileges);
|
self.verify_and_update(instruction_accounts, caller_write_privileges)?;
|
||||||
if result.is_err() {
|
|
||||||
return ProcessInstructionResult {
|
|
||||||
compute_units_consumed: 0,
|
|
||||||
result,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
// Record instruction
|
// Record instruction
|
||||||
if let Some(instruction_recorder) = &self.instruction_recorder {
|
if let Some(instruction_recorder) = &self.instruction_recorder {
|
||||||
let compiled_instruction = CompiledInstruction {
|
let compiled_instruction = CompiledInstruction {
|
||||||
@ -741,31 +729,27 @@ impl<'a> InvokeContext<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut compute_units_consumed = 0;
|
|
||||||
let result = self
|
let result = self
|
||||||
.push(instruction_accounts, program_indices)
|
.push(instruction_accounts, program_indices)
|
||||||
.and_then(|_| {
|
.and_then(|_| {
|
||||||
self.return_data = (program_id, Vec::new());
|
self.return_data = (program_id, Vec::new());
|
||||||
let pre_remaining_units = self.compute_meter.borrow().get_remaining();
|
let pre_remaining_units = self.compute_meter.borrow().get_remaining();
|
||||||
let execution_result = self.process_executable_chain(instruction_data);
|
self.process_executable_chain(instruction_data)?;
|
||||||
let post_remaining_units = self.compute_meter.borrow().get_remaining();
|
let post_remaining_units = self.compute_meter.borrow().get_remaining();
|
||||||
compute_units_consumed = pre_remaining_units.saturating_sub(post_remaining_units);
|
|
||||||
execution_result?;
|
|
||||||
|
|
||||||
// Verify the called program has not misbehaved
|
// Verify the called program has not misbehaved
|
||||||
if is_lowest_invocation_level {
|
if is_lowest_invocation_level {
|
||||||
self.verify(instruction_accounts, program_indices)
|
self.verify(instruction_accounts, program_indices)?;
|
||||||
} else {
|
} else {
|
||||||
self.verify_and_update(instruction_accounts, None)
|
self.verify_and_update(instruction_accounts, None)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(pre_remaining_units.saturating_sub(post_remaining_units))
|
||||||
});
|
});
|
||||||
|
|
||||||
// Pop the invoke_stack to restore previous state
|
// Pop the invoke_stack to restore previous state
|
||||||
self.pop();
|
self.pop();
|
||||||
ProcessInstructionResult {
|
result
|
||||||
compute_units_consumed,
|
|
||||||
result,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Calls the instruction's program entrypoint method
|
/// Calls the instruction's program entrypoint method
|
||||||
@ -1063,10 +1047,6 @@ mod tests {
|
|||||||
ModifyOwned,
|
ModifyOwned,
|
||||||
ModifyNotOwned,
|
ModifyNotOwned,
|
||||||
ModifyReadonly,
|
ModifyReadonly,
|
||||||
ConsumeComputeUnits {
|
|
||||||
compute_units_consumed: u64,
|
|
||||||
desired_result: Result<(), InstructionError>,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@ -1180,17 +1160,6 @@ mod tests {
|
|||||||
.try_account_ref_mut()?
|
.try_account_ref_mut()?
|
||||||
.data_as_mut_slice()[0] = 1
|
.data_as_mut_slice()[0] = 1
|
||||||
}
|
}
|
||||||
MockInstruction::ConsumeComputeUnits {
|
|
||||||
compute_units_consumed,
|
|
||||||
desired_result,
|
|
||||||
} => {
|
|
||||||
invoke_context
|
|
||||||
.get_compute_meter()
|
|
||||||
.borrow_mut()
|
|
||||||
.consume(compute_units_consumed)
|
|
||||||
.unwrap();
|
|
||||||
return desired_result;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return Err(InstructionError::InvalidInstructionData);
|
return Err(InstructionError::InvalidInstructionData);
|
||||||
@ -1372,14 +1341,12 @@ mod tests {
|
|||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.data_as_mut_slice()[0] = 1;
|
.data_as_mut_slice()[0] = 1;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
invoke_context
|
invoke_context.process_instruction(
|
||||||
.process_instruction(
|
&instruction.data,
|
||||||
&instruction.data,
|
&instruction_accounts,
|
||||||
&instruction_accounts,
|
None,
|
||||||
None,
|
&program_indices[1..],
|
||||||
&program_indices[1..],
|
),
|
||||||
)
|
|
||||||
.result,
|
|
||||||
Err(InstructionError::ExternalAccountDataModified)
|
Err(InstructionError::ExternalAccountDataModified)
|
||||||
);
|
);
|
||||||
transaction_context
|
transaction_context
|
||||||
@ -1393,14 +1360,12 @@ mod tests {
|
|||||||
.borrow_mut()
|
.borrow_mut()
|
||||||
.data_as_mut_slice()[0] = 1;
|
.data_as_mut_slice()[0] = 1;
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
invoke_context
|
invoke_context.process_instruction(
|
||||||
.process_instruction(
|
&instruction.data,
|
||||||
&instruction.data,
|
&instruction_accounts,
|
||||||
&instruction_accounts,
|
None,
|
||||||
None,
|
&program_indices[1..],
|
||||||
&program_indices[1..],
|
),
|
||||||
)
|
|
||||||
.result,
|
|
||||||
Err(InstructionError::ReadonlyDataModified)
|
Err(InstructionError::ReadonlyDataModified)
|
||||||
);
|
);
|
||||||
transaction_context
|
transaction_context
|
||||||
@ -1411,33 +1376,15 @@ mod tests {
|
|||||||
invoke_context.pop();
|
invoke_context.pop();
|
||||||
|
|
||||||
let cases = vec![
|
let cases = vec![
|
||||||
(
|
(MockInstruction::NoopSuccess, Ok(0)),
|
||||||
MockInstruction::NoopSuccess,
|
|
||||||
ProcessInstructionResult {
|
|
||||||
result: Ok(()),
|
|
||||||
compute_units_consumed: 0,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
(
|
(
|
||||||
MockInstruction::NoopFail,
|
MockInstruction::NoopFail,
|
||||||
ProcessInstructionResult {
|
Err(InstructionError::GenericError),
|
||||||
result: Err(InstructionError::GenericError),
|
|
||||||
compute_units_consumed: 0,
|
|
||||||
},
|
|
||||||
),
|
|
||||||
(
|
|
||||||
MockInstruction::ModifyOwned,
|
|
||||||
ProcessInstructionResult {
|
|
||||||
result: Ok(()),
|
|
||||||
compute_units_consumed: 0,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
|
(MockInstruction::ModifyOwned, Ok(0)),
|
||||||
(
|
(
|
||||||
MockInstruction::ModifyNotOwned,
|
MockInstruction::ModifyNotOwned,
|
||||||
ProcessInstructionResult {
|
Err(InstructionError::ExternalAccountDataModified),
|
||||||
result: Err(InstructionError::ExternalAccountDataModified),
|
|
||||||
compute_units_consumed: 0,
|
|
||||||
},
|
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
for case in cases {
|
for case in cases {
|
||||||
@ -1608,83 +1555,4 @@ mod tests {
|
|||||||
);
|
);
|
||||||
invoke_context.pop();
|
invoke_context.pop();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_process_instruction_compute_budget() {
|
|
||||||
let caller_program_id = solana_sdk::pubkey::new_rand();
|
|
||||||
let callee_program_id = solana_sdk::pubkey::new_rand();
|
|
||||||
let builtin_programs = &[BuiltinProgram {
|
|
||||||
program_id: callee_program_id,
|
|
||||||
process_instruction: mock_process_instruction,
|
|
||||||
}];
|
|
||||||
|
|
||||||
let owned_account = AccountSharedData::new(42, 1, &callee_program_id);
|
|
||||||
let not_owned_account = AccountSharedData::new(84, 1, &solana_sdk::pubkey::new_rand());
|
|
||||||
let readonly_account = AccountSharedData::new(168, 1, &solana_sdk::pubkey::new_rand());
|
|
||||||
let loader_account = AccountSharedData::new(0, 0, &native_loader::id());
|
|
||||||
let mut program_account = AccountSharedData::new(1, 0, &native_loader::id());
|
|
||||||
program_account.set_executable(true);
|
|
||||||
|
|
||||||
let accounts = vec![
|
|
||||||
(solana_sdk::pubkey::new_rand(), owned_account),
|
|
||||||
(solana_sdk::pubkey::new_rand(), not_owned_account),
|
|
||||||
(solana_sdk::pubkey::new_rand(), readonly_account),
|
|
||||||
(caller_program_id, loader_account),
|
|
||||||
(callee_program_id, program_account),
|
|
||||||
];
|
|
||||||
let program_indices = [3, 4];
|
|
||||||
|
|
||||||
let metas = vec![
|
|
||||||
AccountMeta::new(accounts[0].0, false),
|
|
||||||
AccountMeta::new(accounts[1].0, false),
|
|
||||||
AccountMeta::new_readonly(accounts[2].0, false),
|
|
||||||
];
|
|
||||||
let instruction_accounts = metas
|
|
||||||
.iter()
|
|
||||||
.enumerate()
|
|
||||||
.map(|(account_index, account_meta)| InstructionAccount {
|
|
||||||
index: account_index,
|
|
||||||
is_signer: account_meta.is_signer,
|
|
||||||
is_writable: account_meta.is_writable,
|
|
||||||
})
|
|
||||||
.collect::<Vec<_>>();
|
|
||||||
|
|
||||||
let transaction_context = TransactionContext::new(accounts, 1);
|
|
||||||
let mut invoke_context = InvokeContext::new_mock(&transaction_context, builtin_programs);
|
|
||||||
let compute_units_consumed = 10;
|
|
||||||
let desired_results = vec![Ok(()), Err(InstructionError::GenericError)];
|
|
||||||
|
|
||||||
for desired_result in desired_results {
|
|
||||||
let instruction = Instruction::new_with_bincode(
|
|
||||||
callee_program_id,
|
|
||||||
&MockInstruction::ConsumeComputeUnits {
|
|
||||||
compute_units_consumed,
|
|
||||||
desired_result: desired_result.clone(),
|
|
||||||
},
|
|
||||||
metas.clone(),
|
|
||||||
);
|
|
||||||
invoke_context
|
|
||||||
.push(&instruction_accounts, &program_indices[..1])
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let result = invoke_context.process_instruction(
|
|
||||||
&instruction.data,
|
|
||||||
&instruction_accounts,
|
|
||||||
None,
|
|
||||||
&program_indices[1..],
|
|
||||||
);
|
|
||||||
|
|
||||||
// Because the instruction had compute cost > 0, then regardless of the execution result,
|
|
||||||
// the number of compute units consumed should be a non-default which is something greater
|
|
||||||
// than zero.
|
|
||||||
assert!(result.compute_units_consumed > 0);
|
|
||||||
assert_eq!(
|
|
||||||
result,
|
|
||||||
ProcessInstructionResult {
|
|
||||||
compute_units_consumed,
|
|
||||||
result: desired_result,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ use {solana_sdk::pubkey::Pubkey, std::collections::HashMap};
|
|||||||
pub struct ProgramTiming {
|
pub struct ProgramTiming {
|
||||||
pub accumulated_us: u64,
|
pub accumulated_us: u64,
|
||||||
pub accumulated_units: u64,
|
pub accumulated_units: u64,
|
||||||
pub current_cost_model_estimated_units: u64,
|
|
||||||
pub count: u32,
|
pub count: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -47,24 +46,10 @@ impl ExecuteDetailsTimings {
|
|||||||
program_timing.count = program_timing.count.saturating_add(other.count);
|
program_timing.count = program_timing.count.saturating_add(other.count);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn accumulate_program(
|
pub fn accumulate_program(&mut self, program_id: &Pubkey, us: u64, units: u64) {
|
||||||
&mut self,
|
|
||||||
program_id: &Pubkey,
|
|
||||||
us: u64,
|
|
||||||
actual_compute_units_consumed: u64,
|
|
||||||
estimated_execution_cost: u64,
|
|
||||||
is_error: bool,
|
|
||||||
) {
|
|
||||||
let program_timing = self.per_program_timings.entry(*program_id).or_default();
|
let program_timing = self.per_program_timings.entry(*program_id).or_default();
|
||||||
program_timing.accumulated_us = program_timing.accumulated_us.saturating_add(us);
|
program_timing.accumulated_us = program_timing.accumulated_us.saturating_add(us);
|
||||||
let compute_units_update = if is_error {
|
program_timing.accumulated_units = program_timing.accumulated_units.saturating_add(units);
|
||||||
std::cmp::max(actual_compute_units_consumed, estimated_execution_cost)
|
|
||||||
} else {
|
|
||||||
actual_compute_units_consumed
|
|
||||||
};
|
|
||||||
program_timing.accumulated_units = program_timing
|
|
||||||
.accumulated_units
|
|
||||||
.saturating_add(compute_units_update);
|
|
||||||
program_timing.count = program_timing.count.saturating_add(1);
|
program_timing.count = program_timing.count.saturating_add(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -283,7 +283,6 @@ impl solana_sdk::program_stubs::SyscallStubs for SyscallStubs {
|
|||||||
Some(&caller_write_privileges),
|
Some(&caller_write_privileges),
|
||||||
&program_indices,
|
&program_indices,
|
||||||
)
|
)
|
||||||
.result
|
|
||||||
.map_err(|err| ProgramError::try_from(err).unwrap_or_else(|err| panic!("{}", err)))?;
|
.map_err(|err| ProgramError::try_from(err).unwrap_or_else(|err| panic!("{}", err)))?;
|
||||||
|
|
||||||
// Copy writeable account modifications back into the caller's AccountInfos
|
// Copy writeable account modifications back into the caller's AccountInfos
|
||||||
|
@ -2395,7 +2395,6 @@ fn call<'a, 'b: 'a>(
|
|||||||
Some(&caller_write_privileges),
|
Some(&caller_write_privileges),
|
||||||
&program_indices,
|
&program_indices,
|
||||||
)
|
)
|
||||||
.result
|
|
||||||
.map_err(SyscallError::InstructionError)?;
|
.map_err(SyscallError::InstructionError)?;
|
||||||
|
|
||||||
// Copy results back to caller
|
// Copy results back to caller
|
||||||
|
@ -13,7 +13,6 @@ use {
|
|||||||
TransactionExecutionResult,
|
TransactionExecutionResult,
|
||||||
},
|
},
|
||||||
blockhash_queue::BlockhashQueue,
|
blockhash_queue::BlockhashQueue,
|
||||||
cost_model::ExecutionCost,
|
|
||||||
rent_collector::RentCollector,
|
rent_collector::RentCollector,
|
||||||
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
|
system_instruction_processor::{get_system_account_kind, SystemAccountKind},
|
||||||
},
|
},
|
||||||
@ -115,7 +114,6 @@ pub struct LoadedTransaction {
|
|||||||
pub program_indices: TransactionProgramIndices,
|
pub program_indices: TransactionProgramIndices,
|
||||||
pub rent: TransactionRent,
|
pub rent: TransactionRent,
|
||||||
pub rent_debits: RentDebits,
|
pub rent_debits: RentDebits,
|
||||||
pub estimated_execution_cost: ExecutionCost,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type TransactionLoadResult = (Result<LoadedTransaction>, Option<NonceFull>);
|
pub type TransactionLoadResult = (Result<LoadedTransaction>, Option<NonceFull>);
|
||||||
@ -233,7 +231,6 @@ impl Accounts {
|
|||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
rent_collector: &RentCollector,
|
rent_collector: &RentCollector,
|
||||||
feature_set: &FeatureSet,
|
feature_set: &FeatureSet,
|
||||||
estimated_execution_cost: ExecutionCost,
|
|
||||||
) -> Result<LoadedTransaction> {
|
) -> Result<LoadedTransaction> {
|
||||||
// Copy all the accounts
|
// Copy all the accounts
|
||||||
let message = tx.message();
|
let message = tx.message();
|
||||||
@ -377,7 +374,6 @@ impl Accounts {
|
|||||||
program_indices,
|
program_indices,
|
||||||
rent: tx_rent,
|
rent: tx_rent,
|
||||||
rent_debits,
|
rent_debits,
|
||||||
estimated_execution_cost,
|
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
error_counters.account_not_found += 1;
|
error_counters.account_not_found += 1;
|
||||||
@ -471,7 +467,7 @@ impl Accounts {
|
|||||||
txs.iter()
|
txs.iter()
|
||||||
.zip(lock_results)
|
.zip(lock_results)
|
||||||
.map(|etx| match etx {
|
.map(|etx| match etx {
|
||||||
(tx, (Ok(execution_cost), nonce)) => {
|
(tx, (Ok(()), nonce)) => {
|
||||||
let lamports_per_signature = nonce
|
let lamports_per_signature = nonce
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|nonce| nonce.lamports_per_signature())
|
.map(|nonce| nonce.lamports_per_signature())
|
||||||
@ -491,7 +487,6 @@ impl Accounts {
|
|||||||
error_counters,
|
error_counters,
|
||||||
rent_collector,
|
rent_collector,
|
||||||
feature_set,
|
feature_set,
|
||||||
execution_cost,
|
|
||||||
) {
|
) {
|
||||||
Ok(loaded_transaction) => loaded_transaction,
|
Ok(loaded_transaction) => loaded_transaction,
|
||||||
Err(e) => return (Err(e), None),
|
Err(e) => return (Err(e), None),
|
||||||
@ -983,14 +978,11 @@ 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>,
|
||||||
) -> Vec<Result<ExecutionCost>> {
|
) -> Vec<Result<()>> {
|
||||||
let keys: Vec<_> = txs.map(|tx| tx.get_account_locks()).collect();
|
let keys: Vec<_> = txs.map(|tx| tx.get_account_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| {
|
.map(|keys| self.lock_account(account_locks, keys.writable, keys.readonly))
|
||||||
self.lock_account(account_locks, keys.writable, keys.readonly)
|
|
||||||
.map(|_| 0)
|
|
||||||
})
|
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -999,12 +991,12 @@ impl Accounts {
|
|||||||
pub fn lock_accounts_with_results<'a>(
|
pub fn lock_accounts_with_results<'a>(
|
||||||
&self,
|
&self,
|
||||||
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
||||||
results: impl Iterator<Item = Result<ExecutionCost>>,
|
results: impl Iterator<Item = Result<()>>,
|
||||||
) -> Vec<Result<ExecutionCost>> {
|
) -> 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(execution_cost) => Ok((tx.get_account_locks(), execution_cost)),
|
Ok(()) => Ok(tx.get_account_locks()),
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
@ -1012,9 +1004,7 @@ impl Accounts {
|
|||||||
key_results
|
key_results
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.map(|key_result| match key_result {
|
.map(|key_result| match key_result {
|
||||||
Ok((keys, execution_cost)) => self
|
Ok(keys) => self.lock_account(account_locks, keys.writable, keys.readonly),
|
||||||
.lock_account(account_locks, keys.writable, keys.readonly)
|
|
||||||
.map(|_| execution_cost),
|
|
||||||
Err(e) => Err(e),
|
Err(e) => Err(e),
|
||||||
})
|
})
|
||||||
.collect()
|
.collect()
|
||||||
@ -1025,7 +1015,7 @@ impl Accounts {
|
|||||||
pub fn unlock_accounts<'a>(
|
pub fn unlock_accounts<'a>(
|
||||||
&self,
|
&self,
|
||||||
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
||||||
results: &[Result<ExecutionCost>],
|
results: &[Result<()>],
|
||||||
) {
|
) {
|
||||||
let keys: Vec<_> = txs
|
let keys: Vec<_> = txs
|
||||||
.zip(results)
|
.zip(results)
|
||||||
@ -1310,7 +1300,7 @@ mod tests {
|
|||||||
accounts.load_accounts(
|
accounts.load_accounts(
|
||||||
&ancestors,
|
&ancestors,
|
||||||
&[sanitized_tx],
|
&[sanitized_tx],
|
||||||
vec![(Ok(0), None)],
|
vec![(Ok(()), None)],
|
||||||
&hash_queue,
|
&hash_queue,
|
||||||
error_counters,
|
error_counters,
|
||||||
rent_collector,
|
rent_collector,
|
||||||
@ -2458,9 +2448,9 @@ mod tests {
|
|||||||
let txs = vec![tx0, tx1, tx2];
|
let txs = vec![tx0, tx1, tx2];
|
||||||
|
|
||||||
let qos_results = vec![
|
let qos_results = vec![
|
||||||
Ok(0),
|
Ok(()),
|
||||||
Err(TransactionError::WouldExceedMaxBlockCostLimit),
|
Err(TransactionError::WouldExceedMaxBlockCostLimit),
|
||||||
Ok(0),
|
Ok(()),
|
||||||
];
|
];
|
||||||
|
|
||||||
let results = accounts.lock_accounts_with_results(txs.iter(), qos_results.into_iter());
|
let results = accounts.lock_accounts_with_results(txs.iter(), qos_results.into_iter());
|
||||||
@ -2553,7 +2543,6 @@ mod tests {
|
|||||||
program_indices: vec![],
|
program_indices: vec![],
|
||||||
rent: 0,
|
rent: 0,
|
||||||
rent_debits: RentDebits::default(),
|
rent_debits: RentDebits::default(),
|
||||||
estimated_execution_cost: 0,
|
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
@ -2564,7 +2553,6 @@ mod tests {
|
|||||||
program_indices: vec![],
|
program_indices: vec![],
|
||||||
rent: 0,
|
rent: 0,
|
||||||
rent_debits: RentDebits::default(),
|
rent_debits: RentDebits::default(),
|
||||||
estimated_execution_cost: 0,
|
|
||||||
}),
|
}),
|
||||||
None,
|
None,
|
||||||
);
|
);
|
||||||
@ -2658,7 +2646,7 @@ mod tests {
|
|||||||
accounts.load_accounts(
|
accounts.load_accounts(
|
||||||
&ancestors,
|
&ancestors,
|
||||||
&[tx],
|
&[tx],
|
||||||
vec![(Ok(0), None)],
|
vec![(Ok(()), None)],
|
||||||
&hash_queue,
|
&hash_queue,
|
||||||
&mut error_counters,
|
&mut error_counters,
|
||||||
&rent_collector,
|
&rent_collector,
|
||||||
@ -2994,7 +2982,6 @@ mod tests {
|
|||||||
program_indices: vec![],
|
program_indices: vec![],
|
||||||
rent: 0,
|
rent: 0,
|
||||||
rent_debits: RentDebits::default(),
|
rent_debits: RentDebits::default(),
|
||||||
estimated_execution_cost: 0,
|
|
||||||
}),
|
}),
|
||||||
nonce.clone(),
|
nonce.clone(),
|
||||||
);
|
);
|
||||||
@ -3105,7 +3092,6 @@ mod tests {
|
|||||||
program_indices: vec![],
|
program_indices: vec![],
|
||||||
rent: 0,
|
rent: 0,
|
||||||
rent_debits: RentDebits::default(),
|
rent_debits: RentDebits::default(),
|
||||||
estimated_execution_cost: 0,
|
|
||||||
}),
|
}),
|
||||||
nonce.clone(),
|
nonce.clone(),
|
||||||
);
|
);
|
||||||
|
@ -47,7 +47,6 @@ use {
|
|||||||
ancestors::{Ancestors, AncestorsForSerialization},
|
ancestors::{Ancestors, AncestorsForSerialization},
|
||||||
blockhash_queue::BlockhashQueue,
|
blockhash_queue::BlockhashQueue,
|
||||||
builtins::{self, ActivationType, Builtin, Builtins},
|
builtins::{self, ActivationType, Builtin, Builtins},
|
||||||
cost_model::ExecutionCost,
|
|
||||||
cost_tracker::CostTracker,
|
cost_tracker::CostTracker,
|
||||||
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
epoch_stakes::{EpochStakes, NodeVoteAccounts},
|
||||||
inline_spl_token,
|
inline_spl_token,
|
||||||
@ -504,7 +503,7 @@ impl StatusCacheRc {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub type TransactionCheckResult<'a> = (Result<ExecutionCost>, Option<NoncePartial>);
|
pub type TransactionCheckResult = (Result<()>, Option<NoncePartial>);
|
||||||
pub type TransactionExecutionResult = (Result<()>, Option<NonceFull>);
|
pub type TransactionExecutionResult = (Result<()>, Option<NonceFull>);
|
||||||
pub struct TransactionResults {
|
pub struct TransactionResults {
|
||||||
pub fee_collection_results: Vec<Result<()>>,
|
pub fee_collection_results: Vec<Result<()>>,
|
||||||
@ -3108,7 +3107,7 @@ impl Bank {
|
|||||||
pub fn prepare_sanitized_batch_with_results<'a, 'b>(
|
pub fn prepare_sanitized_batch_with_results<'a, 'b>(
|
||||||
&'a self,
|
&'a self,
|
||||||
transactions: &'b [SanitizedTransaction],
|
transactions: &'b [SanitizedTransaction],
|
||||||
transaction_results: impl Iterator<Item = Result<ExecutionCost>>,
|
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
|
let lock_results = self
|
||||||
@ -3123,7 +3122,7 @@ impl Bank {
|
|||||||
&'a self,
|
&'a self,
|
||||||
transaction: SanitizedTransaction,
|
transaction: SanitizedTransaction,
|
||||||
) -> TransactionBatch<'a, '_> {
|
) -> TransactionBatch<'a, '_> {
|
||||||
let mut batch = TransactionBatch::new(vec![Ok(0)], self, Cow::Owned(vec![transaction]));
|
let mut batch = TransactionBatch::new(vec![Ok(())], self, Cow::Owned(vec![transaction]));
|
||||||
batch.needs_unlock = false;
|
batch.needs_unlock = false;
|
||||||
batch
|
batch
|
||||||
}
|
}
|
||||||
@ -3219,29 +3218,23 @@ impl Bank {
|
|||||||
self.rc.accounts.accounts_db.set_shrink_paths(paths);
|
self.rc.accounts.accounts_db.set_shrink_paths(paths);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_age<'a, T>(
|
fn check_age<'a>(
|
||||||
&self,
|
&self,
|
||||||
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
txs: impl Iterator<Item = &'a SanitizedTransaction>,
|
||||||
lock_results: impl Iterator<Item = T>,
|
lock_results: &[Result<()>],
|
||||||
max_age: usize,
|
max_age: usize,
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
) -> Vec<TransactionCheckResult>
|
) -> Vec<TransactionCheckResult> {
|
||||||
where
|
|
||||||
T: std::borrow::Borrow<Result<ExecutionCost>>,
|
|
||||||
{
|
|
||||||
let hash_queue = self.blockhash_queue.read().unwrap();
|
let hash_queue = self.blockhash_queue.read().unwrap();
|
||||||
txs.zip(lock_results)
|
txs.zip(lock_results)
|
||||||
.map(|(tx, lock_res)| match lock_res.borrow() {
|
.map(|(tx, lock_res)| match lock_res {
|
||||||
Ok(execution_cost) => {
|
Ok(()) => {
|
||||||
let recent_blockhash = tx.message().recent_blockhash();
|
let recent_blockhash = tx.message().recent_blockhash();
|
||||||
let hash_age = hash_queue.check_hash_age(recent_blockhash, max_age);
|
let hash_age = hash_queue.check_hash_age(recent_blockhash, max_age);
|
||||||
if hash_age == Some(true) {
|
if hash_age == Some(true) {
|
||||||
(Ok(*execution_cost), None)
|
(Ok(()), None)
|
||||||
} else if let Some((address, account)) = self.check_transaction_for_nonce(tx) {
|
} else if let Some((address, account)) = self.check_transaction_for_nonce(tx) {
|
||||||
(
|
(Ok(()), Some(NoncePartial::new(address, account)))
|
||||||
Ok(*execution_cost),
|
|
||||||
Some(NoncePartial::new(address, account)),
|
|
||||||
)
|
|
||||||
} else if hash_age == Some(false) {
|
} else if hash_age == Some(false) {
|
||||||
error_counters.blockhash_too_old += 1;
|
error_counters.blockhash_too_old += 1;
|
||||||
(Err(TransactionError::BlockhashNotFound), None)
|
(Err(TransactionError::BlockhashNotFound), None)
|
||||||
@ -3311,16 +3304,13 @@ impl Bank {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn check_transactions<T>(
|
pub fn check_transactions(
|
||||||
&self,
|
&self,
|
||||||
sanitized_txs: &[SanitizedTransaction],
|
sanitized_txs: &[SanitizedTransaction],
|
||||||
lock_results: impl Iterator<Item = T>,
|
lock_results: &[Result<()>],
|
||||||
max_age: usize,
|
max_age: usize,
|
||||||
error_counters: &mut ErrorCounters,
|
error_counters: &mut ErrorCounters,
|
||||||
) -> Vec<TransactionCheckResult>
|
) -> Vec<TransactionCheckResult> {
|
||||||
where
|
|
||||||
T: std::borrow::Borrow<Result<ExecutionCost>>,
|
|
||||||
{
|
|
||||||
let age_results =
|
let age_results =
|
||||||
self.check_age(sanitized_txs.iter(), lock_results, max_age, error_counters);
|
self.check_age(sanitized_txs.iter(), lock_results, max_age, error_counters);
|
||||||
self.check_status_cache(sanitized_txs, age_results, error_counters)
|
self.check_status_cache(sanitized_txs, age_results, error_counters)
|
||||||
@ -3516,7 +3506,7 @@ impl Bank {
|
|||||||
let mut check_time = Measure::start("check_transactions");
|
let mut check_time = Measure::start("check_transactions");
|
||||||
let check_results = self.check_transactions(
|
let check_results = self.check_transactions(
|
||||||
sanitized_txs,
|
sanitized_txs,
|
||||||
batch.lock_results().iter(),
|
batch.lock_results(),
|
||||||
max_age,
|
max_age,
|
||||||
&mut error_counters,
|
&mut error_counters,
|
||||||
);
|
);
|
||||||
@ -3598,7 +3588,6 @@ impl Bank {
|
|||||||
&self.builtin_programs.vec,
|
&self.builtin_programs.vec,
|
||||||
legacy_message,
|
legacy_message,
|
||||||
&loaded_transaction.program_indices,
|
&loaded_transaction.program_indices,
|
||||||
loaded_transaction.estimated_execution_cost,
|
|
||||||
&transaction_context,
|
&transaction_context,
|
||||||
self.rent_collector.rent,
|
self.rent_collector.rent,
|
||||||
log_collector.clone(),
|
log_collector.clone(),
|
||||||
|
@ -18,7 +18,6 @@ use {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const MAX_WRITABLE_ACCOUNTS: usize = 256;
|
const MAX_WRITABLE_ACCOUNTS: usize = 256;
|
||||||
pub type ExecutionCost = u64;
|
|
||||||
|
|
||||||
// costs are stored in number of 'compute unit's
|
// costs are stored in number of 'compute unit's
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -27,7 +26,7 @@ pub struct TransactionCost {
|
|||||||
pub signature_cost: u64,
|
pub signature_cost: u64,
|
||||||
pub write_lock_cost: u64,
|
pub write_lock_cost: u64,
|
||||||
pub data_bytes_cost: u64,
|
pub data_bytes_cost: u64,
|
||||||
pub execution_cost: ExecutionCost,
|
pub execution_cost: u64,
|
||||||
// `cost_weight` is a multiplier could be applied to transaction cost,
|
// `cost_weight` is a multiplier could be applied to transaction cost,
|
||||||
// if set to zero allows the transaction to bypass cost limit check.
|
// if set to zero allows the transaction to bypass cost limit check.
|
||||||
pub cost_weight: u32,
|
pub cost_weight: u32,
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
use {
|
use {
|
||||||
crate::cost_model::ExecutionCost,
|
|
||||||
serde::{Deserialize, Serialize},
|
serde::{Deserialize, Serialize},
|
||||||
solana_measure::measure::Measure,
|
solana_measure::measure::Measure,
|
||||||
solana_program_runtime::{
|
solana_program_runtime::{
|
||||||
instruction_recorder::InstructionRecorder,
|
instruction_recorder::InstructionRecorder,
|
||||||
invoke_context::{BuiltinProgram, Executors, InvokeContext, ProcessInstructionResult},
|
invoke_context::{BuiltinProgram, Executors, InvokeContext},
|
||||||
log_collector::LogCollector,
|
log_collector::LogCollector,
|
||||||
timings::ExecuteDetailsTimings,
|
timings::ExecuteDetailsTimings,
|
||||||
},
|
},
|
||||||
@ -54,7 +53,6 @@ impl MessageProcessor {
|
|||||||
builtin_programs: &[BuiltinProgram],
|
builtin_programs: &[BuiltinProgram],
|
||||||
message: &Message,
|
message: &Message,
|
||||||
program_indices: &[Vec<usize>],
|
program_indices: &[Vec<usize>],
|
||||||
estimated_execution_cost: ExecutionCost,
|
|
||||||
transaction_context: &TransactionContext,
|
transaction_context: &TransactionContext,
|
||||||
rent: Rent,
|
rent: Rent,
|
||||||
log_collector: Option<Rc<RefCell<LogCollector>>>,
|
log_collector: Option<Rc<RefCell<LogCollector>>>,
|
||||||
@ -129,26 +127,21 @@ impl MessageProcessor {
|
|||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
let mut time = Measure::start("execute_instruction");
|
let mut time = Measure::start("execute_instruction");
|
||||||
let ProcessInstructionResult {
|
let compute_meter_consumption = invoke_context
|
||||||
compute_units_consumed,
|
.process_instruction(
|
||||||
result,
|
&instruction.data,
|
||||||
} = invoke_context.process_instruction(
|
&instruction_accounts,
|
||||||
&instruction.data,
|
None,
|
||||||
&instruction_accounts,
|
program_indices,
|
||||||
None,
|
)
|
||||||
program_indices,
|
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
||||||
);
|
|
||||||
time.stop();
|
time.stop();
|
||||||
timings.accumulate_program(
|
timings.accumulate_program(
|
||||||
instruction.program_id(&message.account_keys),
|
instruction.program_id(&message.account_keys),
|
||||||
time.as_us(),
|
time.as_us(),
|
||||||
compute_units_consumed,
|
compute_meter_consumption,
|
||||||
estimated_execution_cost,
|
|
||||||
result.is_err(),
|
|
||||||
);
|
);
|
||||||
timings.accumulate(&invoke_context.timings);
|
timings.accumulate(&invoke_context.timings);
|
||||||
result
|
|
||||||
.map_err(|err| TransactionError::InstructionError(instruction_index as u8, err))?;
|
|
||||||
}
|
}
|
||||||
Ok(ProcessedMessageInfo {
|
Ok(ProcessedMessageInfo {
|
||||||
accounts_data_len: invoke_context.get_accounts_data_meter().current(),
|
accounts_data_len: invoke_context.get_accounts_data_meter().current(),
|
||||||
@ -265,7 +258,6 @@ mod tests {
|
|||||||
builtin_programs,
|
builtin_programs,
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices,
|
||||||
0,
|
|
||||||
&transaction_context,
|
&transaction_context,
|
||||||
rent_collector.rent,
|
rent_collector.rent,
|
||||||
None,
|
None,
|
||||||
@ -307,7 +299,6 @@ mod tests {
|
|||||||
builtin_programs,
|
builtin_programs,
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices,
|
||||||
0,
|
|
||||||
&transaction_context,
|
&transaction_context,
|
||||||
rent_collector.rent,
|
rent_collector.rent,
|
||||||
None,
|
None,
|
||||||
@ -341,7 +332,6 @@ mod tests {
|
|||||||
builtin_programs,
|
builtin_programs,
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices,
|
||||||
0,
|
|
||||||
&transaction_context,
|
&transaction_context,
|
||||||
rent_collector.rent,
|
rent_collector.rent,
|
||||||
None,
|
None,
|
||||||
@ -486,7 +476,6 @@ mod tests {
|
|||||||
builtin_programs,
|
builtin_programs,
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices,
|
||||||
0,
|
|
||||||
&transaction_context,
|
&transaction_context,
|
||||||
rent_collector.rent,
|
rent_collector.rent,
|
||||||
None,
|
None,
|
||||||
@ -521,7 +510,6 @@ mod tests {
|
|||||||
builtin_programs,
|
builtin_programs,
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices,
|
||||||
0,
|
|
||||||
&transaction_context,
|
&transaction_context,
|
||||||
rent_collector.rent,
|
rent_collector.rent,
|
||||||
None,
|
None,
|
||||||
@ -553,7 +541,6 @@ mod tests {
|
|||||||
builtin_programs,
|
builtin_programs,
|
||||||
&message,
|
&message,
|
||||||
&program_indices,
|
&program_indices,
|
||||||
0,
|
|
||||||
&transaction_context,
|
&transaction_context,
|
||||||
rent_collector.rent,
|
rent_collector.rent,
|
||||||
None,
|
None,
|
||||||
@ -627,7 +614,6 @@ mod tests {
|
|||||||
builtin_programs,
|
builtin_programs,
|
||||||
&message,
|
&message,
|
||||||
&[vec![0], vec![1]],
|
&[vec![0], vec![1]],
|
||||||
0,
|
|
||||||
&transaction_context,
|
&transaction_context,
|
||||||
RentCollector::default().rent,
|
RentCollector::default().rent,
|
||||||
None,
|
None,
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
use {
|
use {
|
||||||
crate::{bank::Bank, cost_model::ExecutionCost},
|
crate::bank::Bank,
|
||||||
solana_sdk::transaction::{Result, SanitizedTransaction},
|
solana_sdk::transaction::{Result, SanitizedTransaction},
|
||||||
std::borrow::Cow,
|
std::borrow::Cow,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Represents the results of trying to lock a set of accounts
|
// Represents the results of trying to lock a set of accounts
|
||||||
pub struct TransactionBatch<'a, 'b> {
|
pub struct TransactionBatch<'a, 'b> {
|
||||||
lock_results: Vec<Result<ExecutionCost>>,
|
lock_results: Vec<Result<()>>,
|
||||||
bank: &'a Bank,
|
bank: &'a Bank,
|
||||||
sanitized_txs: Cow<'b, [SanitizedTransaction]>,
|
sanitized_txs: Cow<'b, [SanitizedTransaction]>,
|
||||||
pub(crate) needs_unlock: bool,
|
pub(crate) needs_unlock: bool,
|
||||||
@ -14,7 +14,7 @@ pub struct TransactionBatch<'a, 'b> {
|
|||||||
|
|
||||||
impl<'a, 'b> TransactionBatch<'a, 'b> {
|
impl<'a, 'b> TransactionBatch<'a, 'b> {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
lock_results: Vec<Result<ExecutionCost>>,
|
lock_results: Vec<Result<()>>,
|
||||||
bank: &'a Bank,
|
bank: &'a Bank,
|
||||||
sanitized_txs: Cow<'b, [SanitizedTransaction]>,
|
sanitized_txs: Cow<'b, [SanitizedTransaction]>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
@ -27,7 +27,7 @@ impl<'a, 'b> TransactionBatch<'a, 'b> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn lock_results(&self) -> &Vec<Result<ExecutionCost>> {
|
pub fn lock_results(&self) -> &Vec<Result<()>> {
|
||||||
&self.lock_results
|
&self.lock_results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user