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

ResolvedTransactionView: array writable_cache #3775

Merged
Merged
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
10 changes: 6 additions & 4 deletions transaction-view/src/resolved_transaction_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ pub struct ResolvedTransactionView<D: TransactionData> {
/// The resolved address lookups.
resolved_addresses: Option<LoadedAddresses>,
/// A cache for whether an address is writable.
writable_cache: Vec<bool>, // TODO: should this be a vec, bitset, or array[256].
// Sanitized transactions are guaranteed to have a maximum of 256 keys,
// because account indexing is done with a u8.
writable_cache: [bool; 256],
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

plan to benchmark different approaches here;

  • bool array
  • bitset

however, just doing the simplest approach to remove the allocation-per-transaction for now, while getting code to use new tx-type into master. Easier to evaluate and compare approaches then once the allocation is gone.

}

impl<D: TransactionData> Deref for ResolvedTransactionView<D> {
Expand Down Expand Up @@ -91,12 +93,12 @@ impl<D: TransactionData> ResolvedTransactionView<D> {
view: &TransactionView<true, D>,
resolved_addresses: Option<&LoadedAddresses>,
reserved_account_keys: &HashSet<Pubkey>,
) -> Vec<bool> {
) -> [bool; 256] {
// Build account keys so that we can iterate over and check if
// an address is writable.
let account_keys = AccountKeys::new(view.static_account_keys(), resolved_addresses);

let mut is_writable_cache = Vec::with_capacity(account_keys.len());
let mut is_writable_cache = [false; 256];
let num_static_account_keys = usize::from(view.num_static_account_keys());
let num_writable_lookup_accounts = usize::from(view.total_writable_lookup_accounts());
let num_signed_accounts = usize::from(view.num_required_signatures());
Expand All @@ -120,7 +122,7 @@ impl<D: TransactionData> ResolvedTransactionView<D> {
};

// If the key is reserved it cannot be writable.
is_writable_cache.push(is_requested_write && !reserved_account_keys.contains(key));
is_writable_cache[index] = is_requested_write && !reserved_account_keys.contains(key);
apfitzge marked this conversation as resolved.
Show resolved Hide resolved
}

// If a program account is locked, it cannot be writable unless the
Expand Down
Loading