Feature: TransactionContext, InstructionContext and BorrowedAccount (#21706)
* Adds TransactionContext, InstructionContext and BorrowedAccount. * Redirects the usage of accounts in InvokeContext through TransactionContext. Also use the types declared in transaction_context.rs everywhere. * Adjusts all affected tests.
This commit is contained in:
committed by
GitHub
parent
bb97c8fdcd
commit
a06646631c
@@ -37,6 +37,7 @@ use {
|
||||
system_program,
|
||||
sysvar::{self, instructions::construct_instructions_data},
|
||||
transaction::{Result, SanitizedTransaction, TransactionError},
|
||||
transaction_context::TransactionAccount,
|
||||
},
|
||||
std::{
|
||||
cmp::Reverse,
|
||||
@@ -105,12 +106,11 @@ pub struct Accounts {
|
||||
}
|
||||
|
||||
// for the load instructions
|
||||
pub type TransactionAccounts = Vec<(Pubkey, AccountSharedData)>;
|
||||
pub type TransactionRent = u64;
|
||||
pub type TransactionProgramIndices = Vec<Vec<usize>>;
|
||||
#[derive(PartialEq, Debug, Clone)]
|
||||
pub struct LoadedTransaction {
|
||||
pub accounts: TransactionAccounts,
|
||||
pub accounts: Vec<TransactionAccount>,
|
||||
pub program_indices: TransactionProgramIndices,
|
||||
pub rent: TransactionRent,
|
||||
pub rent_debits: RentDebits,
|
||||
@@ -385,7 +385,7 @@ impl Accounts {
|
||||
fn load_executable_accounts(
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
accounts: &mut Vec<(Pubkey, AccountSharedData)>,
|
||||
accounts: &mut Vec<TransactionAccount>,
|
||||
mut program_account_index: usize,
|
||||
error_counters: &mut ErrorCounters,
|
||||
) -> Result<Vec<usize>> {
|
||||
@@ -606,7 +606,7 @@ impl Accounts {
|
||||
&self,
|
||||
slot: Slot,
|
||||
program_id: Option<&Pubkey>,
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
) -> Vec<TransactionAccount> {
|
||||
self.scan_slot(slot, |stored_account| {
|
||||
let hit = match program_id {
|
||||
None => true,
|
||||
@@ -721,7 +721,7 @@ impl Accounts {
|
||||
}
|
||||
|
||||
fn load_while_filtering<F: Fn(&AccountSharedData) -> bool>(
|
||||
collector: &mut Vec<(Pubkey, AccountSharedData)>,
|
||||
collector: &mut Vec<TransactionAccount>,
|
||||
some_account_tuple: Option<(&Pubkey, AccountSharedData, Slot)>,
|
||||
filter: F,
|
||||
) {
|
||||
@@ -739,11 +739,11 @@ impl Accounts {
|
||||
bank_id: BankId,
|
||||
program_id: &Pubkey,
|
||||
config: &ScanConfig,
|
||||
) -> ScanResult<Vec<(Pubkey, AccountSharedData)>> {
|
||||
) -> ScanResult<Vec<TransactionAccount>> {
|
||||
self.accounts_db.scan_accounts(
|
||||
ancestors,
|
||||
bank_id,
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData)>, some_account_tuple| {
|
||||
|collector: &mut Vec<TransactionAccount>, some_account_tuple| {
|
||||
Self::load_while_filtering(collector, some_account_tuple, |account| {
|
||||
account.owner() == program_id
|
||||
})
|
||||
@@ -759,11 +759,11 @@ impl Accounts {
|
||||
program_id: &Pubkey,
|
||||
filter: F,
|
||||
config: &ScanConfig,
|
||||
) -> ScanResult<Vec<(Pubkey, AccountSharedData)>> {
|
||||
) -> ScanResult<Vec<TransactionAccount>> {
|
||||
self.accounts_db.scan_accounts(
|
||||
ancestors,
|
||||
bank_id,
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData)>, some_account_tuple| {
|
||||
|collector: &mut Vec<TransactionAccount>, some_account_tuple| {
|
||||
Self::load_while_filtering(collector, some_account_tuple, |account| {
|
||||
account.owner() == program_id && filter(account)
|
||||
})
|
||||
@@ -796,9 +796,9 @@ impl Accounts {
|
||||
}
|
||||
|
||||
fn maybe_abort_scan(
|
||||
result: ScanResult<Vec<(Pubkey, AccountSharedData)>>,
|
||||
result: ScanResult<Vec<TransactionAccount>>,
|
||||
config: &ScanConfig,
|
||||
) -> ScanResult<Vec<(Pubkey, AccountSharedData)>> {
|
||||
) -> ScanResult<Vec<TransactionAccount>> {
|
||||
if config.is_aborted() {
|
||||
ScanResult::Err(ScanError::Aborted(
|
||||
"The accumulated scan results exceeded the limit".to_string(),
|
||||
@@ -816,7 +816,7 @@ impl Accounts {
|
||||
filter: F,
|
||||
config: &ScanConfig,
|
||||
byte_limit_for_scan: Option<usize>,
|
||||
) -> ScanResult<Vec<(Pubkey, AccountSharedData)>> {
|
||||
) -> ScanResult<Vec<TransactionAccount>> {
|
||||
let sum = AtomicUsize::default();
|
||||
let config = config.recreate_with_abort();
|
||||
let result = self
|
||||
@@ -825,7 +825,7 @@ impl Accounts {
|
||||
ancestors,
|
||||
bank_id,
|
||||
*index_key,
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData)>, some_account_tuple| {
|
||||
|collector: &mut Vec<TransactionAccount>, some_account_tuple| {
|
||||
Self::load_while_filtering(collector, some_account_tuple, |account| {
|
||||
let use_account = filter(account);
|
||||
if use_account
|
||||
@@ -887,13 +887,13 @@ impl Accounts {
|
||||
&self,
|
||||
ancestors: &Ancestors,
|
||||
range: R,
|
||||
) -> Vec<(Pubkey, AccountSharedData)> {
|
||||
) -> Vec<TransactionAccount> {
|
||||
self.accounts_db.range_scan_accounts(
|
||||
"load_to_collect_rent_eagerly_scan_elapsed",
|
||||
ancestors,
|
||||
range,
|
||||
&ScanConfig::new(true),
|
||||
|collector: &mut Vec<(Pubkey, AccountSharedData)>, option| {
|
||||
|collector: &mut Vec<TransactionAccount>, option| {
|
||||
Self::load_while_filtering(collector, option, |_| true)
|
||||
},
|
||||
)
|
||||
@@ -1277,7 +1277,7 @@ mod tests {
|
||||
|
||||
fn load_accounts_with_fee_and_rent(
|
||||
tx: Transaction,
|
||||
ka: &[(Pubkey, AccountSharedData)],
|
||||
ka: &[TransactionAccount],
|
||||
lamports_per_signature: u64,
|
||||
rent_collector: &RentCollector,
|
||||
error_counters: &mut ErrorCounters,
|
||||
@@ -1310,7 +1310,7 @@ mod tests {
|
||||
|
||||
fn load_accounts_with_fee(
|
||||
tx: Transaction,
|
||||
ka: &[(Pubkey, AccountSharedData)],
|
||||
ka: &[TransactionAccount],
|
||||
lamports_per_signature: u64,
|
||||
error_counters: &mut ErrorCounters,
|
||||
) -> Vec<TransactionLoadResult> {
|
||||
@@ -1325,7 +1325,7 @@ mod tests {
|
||||
|
||||
fn load_accounts(
|
||||
tx: Transaction,
|
||||
ka: &[(Pubkey, AccountSharedData)],
|
||||
ka: &[TransactionAccount],
|
||||
error_counters: &mut ErrorCounters,
|
||||
) -> Vec<TransactionLoadResult> {
|
||||
load_accounts_with_fee(tx, ka, 0, error_counters)
|
||||
@@ -1390,7 +1390,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_no_account_0_exists() {
|
||||
let accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1416,7 +1416,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_unknown_program_id() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1450,7 +1450,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_insufficient_funds() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1486,7 +1486,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_invalid_account_for_fee() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1588,7 +1588,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_no_loaders() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1629,7 +1629,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_max_call_depth() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1695,7 +1695,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_bad_owner() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1730,7 +1730,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_not_executable() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1764,7 +1764,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_multiple_loaders() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1860,7 +1860,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_executable_with_write_lock() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -1916,7 +1916,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_upgradeable_with_write_lock() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
@@ -2013,7 +2013,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_load_accounts_programdata_with_write_lock() {
|
||||
let mut accounts: Vec<(Pubkey, AccountSharedData)> = Vec::new();
|
||||
let mut accounts: Vec<TransactionAccount> = Vec::new();
|
||||
let mut error_counters = ErrorCounters::default();
|
||||
|
||||
let keypair = Keypair::new();
|
||||
|
Reference in New Issue
Block a user