Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include loaded accounts data size in TransactionResults #1525

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions accounts-db/src/accounts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,7 @@ mod tests {
nonce: None,
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let loaded1 = Ok(LoadedTransaction {
Expand All @@ -1588,6 +1589,7 @@ mod tests {
nonce: None,
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let mut loaded = vec![loaded0, loaded1];
Expand Down Expand Up @@ -1964,6 +1966,7 @@ mod tests {
nonce: nonce.clone(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let mut loaded = vec![loaded];
Expand Down Expand Up @@ -2068,6 +2071,7 @@ mod tests {
nonce: nonce.clone(),
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
});

let mut loaded = vec![loaded];
Expand Down
26 changes: 25 additions & 1 deletion runtime/src/bank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ use {
TransactionProcessingConfig,
},
transaction_results::{
TransactionExecutionDetails, TransactionExecutionResult, TransactionResults,
TransactionExecutionDetails, TransactionExecutionResult,
TransactionLoadedAccountsStats, TransactionResults,
},
},
solana_system_program::{get_system_account_kind, SystemAccountKind},
Expand Down Expand Up @@ -4193,13 +4194,36 @@ impl Bank {
update_transaction_statuses_time.as_us(),
);

let loaded_accounts_stats = Self::collect_loaded_accounts_stats(loaded_txs);
assert_eq!(
loaded_accounts_stats.len(),
execution_results.len(),
"loaded_account_stats and execution_results are not the same size"
);

TransactionResults {
fee_collection_results,
loaded_accounts_stats,
execution_results,
rent_debits,
}
}

fn collect_loaded_accounts_stats(
loaded_txs: &[TransactionLoadResult],
) -> Vec<Result<TransactionLoadedAccountsStats>> {
loaded_txs
.iter()
.map(|load_result| match load_result {
Ok(loaded_tx) => Ok(TransactionLoadedAccountsStats {
loaded_accounts_data_size: loaded_tx.loaded_accounts_data_size,
loaded_accounts_count: loaded_tx.accounts.len(),
}),
Err(err) => Err(err.clone()),
})
.collect()
}

fn collect_rent(
&self,
execution_results: &[TransactionExecutionResult],
Expand Down
17 changes: 12 additions & 5 deletions svm/src/account_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pub struct LoadedTransaction {
pub nonce: Option<NonceFull>,
pub rent: TransactionRent,
pub rent_debits: RentDebits,
pub loaded_accounts_data_size: usize,
}

impl LoadedTransaction {
Expand Down Expand Up @@ -388,6 +389,7 @@ fn load_transaction_accounts<CB: TransactionProcessingCallback>(
nonce,
rent: tx_rent,
rent_debits,
loaded_accounts_data_size: accumulated_accounts_data_size,
})
}

Expand Down Expand Up @@ -1519,7 +1521,8 @@ mod tests {
program_indices: vec![vec![]],
nonce: None,
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -1722,7 +1725,8 @@ mod tests {
nonce: None,
program_indices: vec![vec![1]],
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -1914,7 +1918,8 @@ mod tests {
program_indices: vec![vec![2, 1]],
nonce: None,
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -2006,7 +2011,8 @@ mod tests {
program_indices: vec![vec![3, 1], vec![3, 1]],
nonce: None,
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down Expand Up @@ -2168,7 +2174,8 @@ mod tests {
Some(mock_bank.accounts_map[&key2.pubkey()].clone())
)),
rent: 0,
rent_debits: RentDebits::default()
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
}
);
}
Expand Down
2 changes: 2 additions & 0 deletions svm/src/transaction_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,7 @@ mod tests {
nonce: None,
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 32,
};

let mut processing_config = TransactionProcessingConfig::default();
Expand Down Expand Up @@ -1124,6 +1125,7 @@ mod tests {
nonce: None,
rent: 0,
rent_debits: RentDebits::default(),
loaded_accounts_data_size: 0,
};

let processing_config = TransactionProcessingConfig {
Expand Down
7 changes: 7 additions & 0 deletions svm/src/transaction_results.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ use {

pub struct TransactionResults {
pub fee_collection_results: Vec<transaction::Result<()>>,
pub loaded_accounts_stats: Vec<transaction::Result<TransactionLoadedAccountsStats>>,
pub execution_results: Vec<TransactionExecutionResult>,
pub rent_debits: Vec<RentDebits>,
}

#[derive(Debug, Default, Clone)]
pub struct TransactionLoadedAccountsStats {
pub loaded_accounts_data_size: usize,
pub loaded_accounts_count: usize,
}

/// Type safe representation of a transaction execution attempt which
/// differentiates between a transaction that was executed (will be
/// committed to the ledger) and a transaction which wasn't executed
Expand Down
Loading