From 0c4e3cebfb35886eae9fb0cf5efbbb6f77d925ec Mon Sep 17 00:00:00 2001 From: Brooks Prumo Date: Thu, 14 Jul 2022 13:25:47 -0500 Subject: [PATCH] Do not check accounts data size in InvokeContext --- program-runtime/src/accounts_data_meter.rs | 12 ++---------- program-runtime/src/invoke_context.rs | 22 +++++----------------- 2 files changed, 7 insertions(+), 27 deletions(-) diff --git a/program-runtime/src/accounts_data_meter.rs b/program-runtime/src/accounts_data_meter.rs index 244ce9b118ed97..fe8a75b29740b4 100644 --- a/program-runtime/src/accounts_data_meter.rs +++ b/program-runtime/src/accounts_data_meter.rs @@ -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) @@ -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; diff --git a/program-runtime/src/invoke_context.rs b/program-runtime/src/invoke_context.rs index 52c860bb63dcc7..fc38ef6171929c 100644 --- a/program-runtime/src/invoke_context.rs +++ b/program-runtime/src/invoke_context.rs @@ -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, @@ -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() @@ -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 @@ -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 @@ -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; }