Skip to content

Commit

Permalink
20 more errors fixed 10 to go primitives evm
Browse files Browse the repository at this point in the history
  • Loading branch information
4meta5 committed Jan 8, 2025
1 parent cf60a49 commit 6b39b5d
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions primitives/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ use sp_core::{H160, H256, U256};
use sp_runtime::Perbill;

pub use evm::{
interpreter::{error::ExitReason, machine::Machine, opcode::Opcode, runtime::Log},
interpreter::{machine::Machine, opcode::Opcode},
standard::Config,
};

pub use self::{
account_provider::AccountProvider,
precompile::{
Context, ExitError, ExitException, ExitResult, ExitSucceed, LinearCostPrecompile,
PrecompileSet, PurePrecompile,
Context, ExitException, ExitResult, ExitSucceed, LinearCostPrecompile, PrecompileSet,
PurePrecompile,
},
validation::{
Account, CheckEvmTransaction, CheckEvmTransactionConfig, CheckEvmTransactionInput,
Expand Down Expand Up @@ -123,34 +123,34 @@ impl WeightInfo {
})
}

fn try_consume(&self, cost: u64, limit: u64, usage: u64) -> Result<u64, ExitError> {
let usage = usage.checked_add(cost).ok_or(ExitError::OutOfGas)?;
fn try_consume(&self, cost: u64, limit: u64, usage: u64) -> Result<u64, ExitException> {
let usage = usage.checked_add(cost).ok_or(ExitException::OutOfGas)?;
if usage > limit {
return Err(ExitError::OutOfGas);
return Err(ExitException::OutOfGas);
}
Ok(usage)
}

pub fn try_record_ref_time_or_fail(&mut self, cost: u64) -> Result<(), ExitError> {
pub fn try_record_ref_time_or_fail(&mut self, cost: u64) -> Result<(), ExitException> {
if let (Some(ref_time_usage), Some(ref_time_limit)) =
(self.ref_time_usage, self.ref_time_limit)
{
let ref_time_usage = self.try_consume(cost, ref_time_limit, ref_time_usage)?;
if ref_time_usage > ref_time_limit {
return Err(ExitError::OutOfGas);
return Err(ExitException::OutOfGas);
}
self.ref_time_usage = Some(ref_time_usage);
}
Ok(())
}

pub fn try_record_proof_size_or_fail(&mut self, cost: u64) -> Result<(), ExitError> {
pub fn try_record_proof_size_or_fail(&mut self, cost: u64) -> Result<(), ExitException> {
if let (Some(proof_size_usage), Some(proof_size_limit)) =
(self.proof_size_usage, self.proof_size_limit)
{
let proof_size_usage = self.try_consume(cost, proof_size_limit, proof_size_usage)?;
if proof_size_usage > proof_size_limit {
return Err(ExitError::OutOfGas);
return Err(ExitException::OutOfGas);
}
self.proof_size_usage = Some(proof_size_usage);
}
Expand Down Expand Up @@ -199,10 +199,19 @@ pub struct UsedGas {
pub effective: U256,
}

/// Log
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Log {
pub address: H160,
pub topics: Vec<H256>,
pub data: Vec<u8>,
}

#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode, TypeInfo)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ExecutionInfoV2<T> {
pub exit_reason: ExitReason,
pub exit_reason: ExitResult,
pub value: T,
pub used_gas: UsedGas,
pub weight_info: Option<WeightInfo>,
Expand All @@ -222,7 +231,7 @@ pub enum CallOrCreateInfo {
#[derive(Clone, Eq, PartialEq, Debug, Encode, Decode)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
pub struct ExecutionInfo<T> {
pub exit_reason: ExitReason,
pub exit_reason: ExitResult,
pub value: T,
pub used_gas: U256,
pub logs: Vec<Log>,
Expand Down

0 comments on commit 6b39b5d

Please sign in to comment.