Skip to content
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
8 changes: 4 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

110 changes: 55 additions & 55 deletions frame/evm/src/runner/stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -768,61 +768,6 @@ where
}
}

fn record_external_operation(&mut self, op: evm::ExternalOperation) -> Result<(), ExitError> {
let size_limit: u64 = self
.metadata()
.gasometer()
.config()
.create_contract_limit
.unwrap_or_default() as u64;

let (weight_info, recorded) = self.info_mut();

if let Some(weight_info) = weight_info {
match op {
evm::ExternalOperation::AccountBasicRead => {
weight_info.try_record_proof_size_or_fail(ACCOUNT_BASIC_PROOF_SIZE)?
}
evm::ExternalOperation::AddressCodeRead(address) => {
let maybe_record = !recorded.account_codes.contains(&address);
// Skip if the address has been already recorded this block
if maybe_record {
// First we record account emptiness check.
// Transfers to EOAs with standard 21_000 gas limit are able to
// pay for this pov size.
weight_info.try_record_proof_size_or_fail(IS_EMPTY_CHECK_PROOF_SIZE)?;

if <AccountCodes<T>>::decode_len(address).unwrap_or(0) == 0 {
return Ok(());
}
// Try to record fixed sized `AccountCodesMetadata` read
// Tentatively 16 + 20 + 40
weight_info
.try_record_proof_size_or_fail(ACCOUNT_CODES_METADATA_PROOF_SIZE)?;
if let Some(meta) = <AccountCodesMetadata<T>>::get(address) {
weight_info.try_record_proof_size_or_fail(meta.size)?;
} else {
// If it does not exist, try to record `create_contract_limit` first.
weight_info.try_record_proof_size_or_fail(size_limit)?;
let meta = Pallet::<T>::account_code_metadata(address);
let actual_size = meta.size;
// Refund if applies
weight_info.refund_proof_size(size_limit.saturating_sub(actual_size));
}
recorded.account_codes.push(address);
}
}
evm::ExternalOperation::IsEmpty => {
weight_info.try_record_proof_size_or_fail(IS_EMPTY_CHECK_PROOF_SIZE)?
}
evm::ExternalOperation::Write => {
weight_info.try_record_proof_size_or_fail(WRITE_PROOF_SIZE)?
}
};
}
Ok(())
}

fn code(&self, address: H160) -> Vec<u8> {
<AccountCodes<T>>::get(address)
}
Expand Down Expand Up @@ -994,6 +939,61 @@ where
<Pallet<T>>::account_code_metadata(address).hash
}

fn record_external_operation(&mut self, op: evm::ExternalOperation) -> Result<(), ExitError> {
let size_limit: u64 = self
.metadata()
.gasometer()
.config()
.create_contract_limit
.unwrap_or_default() as u64;

let (weight_info, recorded) = self.info_mut();

if let Some(weight_info) = weight_info {
match op {
evm::ExternalOperation::AccountBasicRead => {
weight_info.try_record_proof_size_or_fail(ACCOUNT_BASIC_PROOF_SIZE)?
}
evm::ExternalOperation::AddressCodeRead(address) => {
let maybe_record = !recorded.account_codes.contains(&address);
// Skip if the address has been already recorded this block
if maybe_record {
// First we record account emptiness check.
// Transfers to EOAs with standard 21_000 gas limit are able to
// pay for this pov size.
weight_info.try_record_proof_size_or_fail(IS_EMPTY_CHECK_PROOF_SIZE)?;

if <AccountCodes<T>>::decode_len(address).unwrap_or(0) == 0 {
return Ok(());
}
// Try to record fixed sized `AccountCodesMetadata` read
// Tentatively 16 + 20 + 40
weight_info
.try_record_proof_size_or_fail(ACCOUNT_CODES_METADATA_PROOF_SIZE)?;
if let Some(meta) = <AccountCodesMetadata<T>>::get(address) {
weight_info.try_record_proof_size_or_fail(meta.size)?;
} else {
// If it does not exist, try to record `create_contract_limit` first.
weight_info.try_record_proof_size_or_fail(size_limit)?;
let meta = Pallet::<T>::account_code_metadata(address);
let actual_size = meta.size;
// Refund if applies
weight_info.refund_proof_size(size_limit.saturating_sub(actual_size));
}
recorded.account_codes.push(address);
}
}
evm::ExternalOperation::IsEmpty => {
weight_info.try_record_proof_size_or_fail(IS_EMPTY_CHECK_PROOF_SIZE)?
}
evm::ExternalOperation::Write => {
weight_info.try_record_proof_size_or_fail(WRITE_PROOF_SIZE)?
}
};
}
Ok(())
}

fn record_external_dynamic_opcode_cost(
&mut self,
opcode: Opcode,
Expand Down