Skip to content

Commit

Permalink
Do not check accounts data size in InvokeContext
Browse files Browse the repository at this point in the history
  • Loading branch information
brooksprumo committed Jul 25, 2022
1 parent ffe7be9 commit 0c4e3ce
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 27 deletions.
12 changes: 2 additions & 10 deletions program-runtime/src/accounts_data_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ impl AccountsDataMeter {
/// Make a new AccountsDataMeter
#[must_use]
pub fn new(initial_accounts_data_len: u64) -> Self {
let accounts_data_meter = Self {
Self {
maximum: MAX_ACCOUNTS_DATA_LEN,
initial: initial_accounts_data_len,
delta: 0,
};
debug_assert!(accounts_data_meter.initial <= accounts_data_meter.maximum);
accounts_data_meter
}
}

/// Return the maximum amount of accounts data space that can be used (in bytes)
Expand Down Expand Up @@ -120,12 +118,6 @@ mod tests {
let _ = AccountsDataMeter::new(MAX_ACCOUNTS_DATA_LEN);
}

#[test]
#[should_panic]
fn test_new_panics_if_initial_len_too_big() {
let _ = AccountsDataMeter::new(MAX_ACCOUNTS_DATA_LEN + 1);
}

#[test]
fn test_remaining() {
let initial_accounts_data_len = 0;
Expand Down
22 changes: 5 additions & 17 deletions program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ use {
solana_sdk::{
account::{AccountSharedData, ReadableAccount},
bpf_loader_upgradeable::{self, UpgradeableLoaderState},
feature_set::{
cap_accounts_data_len, enable_early_verification_of_account_modifications, FeatureSet,
},
feature_set::{enable_early_verification_of_account_modifications, FeatureSet},
hash::Hash,
instruction::{AccountMeta, Instruction, InstructionError},
native_loader,
Expand Down Expand Up @@ -448,7 +446,6 @@ impl<'a> InvokeContext<'a> {
instruction_accounts: &[InstructionAccount],
program_indices: &[usize],
) -> Result<(), InstructionError> {
let cap_accounts_data_len = self.feature_set.is_active(&cap_accounts_data_len::id());
let instruction_context = self
.transaction_context
.get_current_instruction_context()
Expand Down Expand Up @@ -519,12 +516,8 @@ impl<'a> InvokeContext<'a> {
let pre_data_len = pre_account.data().len() as i64;
let post_data_len = account.data().len() as i64;
let data_len_delta = post_data_len.saturating_sub(pre_data_len);
if cap_accounts_data_len {
self.accounts_data_meter.adjust_delta(data_len_delta)?;
} else {
self.accounts_data_meter
.adjust_delta_unchecked(data_len_delta);
}
self.accounts_data_meter
.adjust_delta_unchecked(data_len_delta);
}

// Verify that the total sum of all the lamports did not change
Expand All @@ -543,7 +536,6 @@ impl<'a> InvokeContext<'a> {
instruction_accounts: &[InstructionAccount],
before_instruction_context_push: bool,
) -> Result<(), InstructionError> {
let cap_accounts_data_len = self.feature_set.is_active(&cap_accounts_data_len::id());
let transaction_context = &self.transaction_context;
let instruction_context = transaction_context.get_current_instruction_context()?;
let program_id = instruction_context
Expand Down Expand Up @@ -612,12 +604,8 @@ impl<'a> InvokeContext<'a> {
let pre_data_len = pre_account.data().len() as i64;
let post_data_len = account.data().len() as i64;
let data_len_delta = post_data_len.saturating_sub(pre_data_len);
if cap_accounts_data_len {
self.accounts_data_meter.adjust_delta(data_len_delta)?;
} else {
self.accounts_data_meter
.adjust_delta_unchecked(data_len_delta);
}
self.accounts_data_meter
.adjust_delta_unchecked(data_len_delta);

break;
}
Expand Down

0 comments on commit 0c4e3ce

Please sign in to comment.