Skip to content
This repository has been archived by the owner on Mar 13, 2023. It is now read-only.

Commit

Permalink
Update evm crate version (#394)
Browse files Browse the repository at this point in the history
* Companion for 230

* Format

* Remove original withdraw
  • Loading branch information
boundless-forest authored Dec 9, 2020
1 parent 3d96114 commit f225cd9
Show file tree
Hide file tree
Showing 14 changed files with 116 additions and 63 deletions.
16 changes: 8 additions & 8 deletions Cargo.lock

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

20 changes: 20 additions & 0 deletions bin/node/runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,16 @@ impl_runtime_apis! {
gas_limit: U256,
gas_price: Option<U256>,
nonce: Option<U256>,
estimate: bool,
) -> Result<darwinia_evm::CallInfo, sp_runtime::DispatchError> {
let config = if estimate {
let mut config = <Runtime as darwinia_evm::Trait>::config().clone();
config.estimate = true;
Some(config)
} else {
None
};

<Runtime as darwinia_evm::Trait>::Runner::call(
from,
to,
Expand All @@ -1482,6 +1491,7 @@ impl_runtime_apis! {
gas_limit.low_u32(),
gas_price,
nonce,
config.as_ref().unwrap_or(<Runtime as darwinia_evm::Trait>::config()),
).map_err(|err| err.into())
}

Expand All @@ -1492,14 +1502,24 @@ impl_runtime_apis! {
gas_limit: U256,
gas_price: Option<U256>,
nonce: Option<U256>,
estimate: bool,
) -> Result<darwinia_evm::CreateInfo, sp_runtime::DispatchError> {
let config = if estimate {
let mut config = <Runtime as darwinia_evm::Trait>::config().clone();
config.estimate = true;
Some(config)
} else {
None
};

<Runtime as darwinia_evm::Trait>::Runner::create(
from,
data,
value,
gas_limit.low_u32(),
gas_price,
nonce,
config.as_ref().unwrap_or(<Runtime as darwinia_evm::Trait>::config()),
).map_err(|err| err.into())
}

Expand Down
4 changes: 4 additions & 0 deletions client/dvm/rpc/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,7 @@ where
gas_limit,
gas_price,
nonce,
false,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
Expand All @@ -683,6 +684,7 @@ where
gas_limit,
gas_price,
nonce,
false,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
Expand Down Expand Up @@ -724,6 +726,7 @@ where
gas_limit,
gas_price,
nonce,
true,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
Expand All @@ -744,6 +747,7 @@ where
gas_limit,
gas_price,
nonce,
true,
)
.map_err(|err| internal_err(format!("runtime error: {:?}", err)))?
.map_err(|err| internal_err(format!("execution fatal: {:?}", err)))?;
Expand Down
2 changes: 1 addition & 1 deletion frame/dvm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ version = "1.2.2"
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false }
ethereum = { version = "0.5", default-features = false, features = ["with-codec"] }
ethereum-types = { version = "0.9", default-features = false }
evm = { version = "0.18.0", features = ["with-codec"], default-features = false }
evm = { version = "0.19.0", features = ["with-codec"], default-features = false }
libsecp256k1 = { version = "0.3", default-features = false }
rlp = { version = "0.4", default-features = false }
rustc-hex = { version = "2.1.0", default-features = false }
Expand Down
2 changes: 2 additions & 0 deletions frame/dvm/rpc/runtime-api/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ sp_api::decl_runtime_apis! {
gas_limit: U256,
gas_price: Option<U256>,
nonce: Option<U256>,
estimate: bool,
) -> Result<darwinia_evm_primitives::CallInfo, sp_runtime::DispatchError>;
/// Returns a frame_ethereum::create response.
fn create(
Expand All @@ -80,6 +81,7 @@ sp_api::decl_runtime_apis! {
gas_limit: U256,
gas_price: Option<U256>,
nonce: Option<U256>,
estimate: bool,
) -> Result<darwinia_evm_primitives::CreateInfo, sp_runtime::DispatchError>;
/// Return the current block.
fn current_block() -> Option<EthereumBlock>;
Expand Down
6 changes: 5 additions & 1 deletion frame/dvm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ decl_module! {
Some(transaction.gas_price),
Some(transaction.nonce),
transaction.action,
None,
)?;

let (reason, status, used_gas) = match info {
Expand Down Expand Up @@ -411,7 +412,7 @@ impl<T: Trait> Module<T> {
CurrentReceipts::get()
}

/// Execute an Ethereum transaction, ignoring transaction signatures.
/// Execute an Ethereum transaction
pub fn execute(
from: H160,
input: Vec<u8>,
Expand All @@ -420,6 +421,7 @@ impl<T: Trait> Module<T> {
gas_price: Option<U256>,
nonce: Option<U256>,
action: TransactionAction,
config: Option<evm::Config>,
) -> Result<(Option<H160>, CallOrCreateInfo), DispatchError> {
match action {
ethereum::TransactionAction::Call(target) => Ok((
Expand All @@ -433,6 +435,7 @@ impl<T: Trait> Module<T> {
gas_limit.low_u32(),
gas_price,
nonce,
config.as_ref().unwrap_or(T::config()),
)
.map_err(Into::into)?,
),
Expand All @@ -447,6 +450,7 @@ impl<T: Trait> Module<T> {
gas_limit.low_u32(),
gas_price,
nonce,
config.as_ref().unwrap_or(T::config()),
)
.map_err(Into::into)?,
),
Expand Down
8 changes: 8 additions & 0 deletions frame/dvm/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ fn transaction_should_increment_nonce() {
Some(t.gas_price),
Some(t.nonce),
t.action,
None,
));
assert_eq!(
<Test as darwinia_evm::Trait>::AccountBasicMapping::account_basic(&alice.address).nonce,
Expand Down Expand Up @@ -117,6 +118,7 @@ fn transaction_with_invalid_nonce_should_not_work() {
Some(t.gas_price),
Some(t.nonce),
t.action,
None,
));

transaction.nonce = U256::from(0);
Expand Down Expand Up @@ -147,6 +149,7 @@ fn contract_constructor_should_get_executed() {
Some(t.gas_price),
Some(t.nonce),
t.action,
None,
));
assert_eq!(
Evm::account_storages(erc20_address, alice_storage_address),
Expand Down Expand Up @@ -214,6 +217,7 @@ fn contract_should_be_created_at_given_address() {
Some(t.gas_price),
Some(t.nonce),
t.action,
None,
));
assert_ne!(Evm::account_codes(erc20_address).len(), 0);
});
Expand All @@ -236,6 +240,7 @@ fn transaction_should_generate_correct_gas_used() {
Some(t.gas_price),
Some(t.nonce),
t.action,
None,
)
.unwrap();

Expand Down Expand Up @@ -282,6 +287,7 @@ fn call_should_handle_errors() {
Some(t.gas_price),
Some(t.nonce),
t.action,
None,
));

let contract_address: Vec<u8> =
Expand All @@ -298,6 +304,7 @@ fn call_should_handle_errors() {
Some(U256::from(1)),
Some(U256::from(1)),
TransactionAction::Call(H160::from_slice(&contract_address)),
None,
)
.unwrap();
match info {
Expand All @@ -319,6 +326,7 @@ fn call_should_handle_errors() {
Some(U256::from(1)),
Some(U256::from(2)),
TransactionAction::Call(H160::from_slice(&contract_address)),
None,
)
.ok()
.unwrap();
Expand Down
6 changes: 3 additions & 3 deletions frame/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ version = "1.2.2"
[dependencies]
# crates
codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false }
evm = { version = "0.18", default-features = false, features = ["with-codec"] }
evm-gasometer = { version = "0.18", default-features = false }
evm-runtime = { version = "0.18", default-features = false }
evm = { version = "0.19.0", default-features = false, features = ["with-codec"] }
evm-gasometer = { version = "0.19.0", default-features = false }
evm-runtime = { version = "0.19.0", default-features = false }
impl-trait-for-tuples = { version = "0.1" }
primitive-types = { version = "0.7.0", default-features = false, features = ["rlp", "byteorder"] }
ripemd160 = { version = "0.9", default-features = false }
Expand Down
17 changes: 3 additions & 14 deletions frame/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,20 +357,6 @@ decl_module! {

fn deposit_event() = default;

/// Withdraw balance from EVM into currency/balances module.
#[weight = 0]
fn withdraw(origin, address: H160, value: BalanceOf<T>) {
let destination = T::WithdrawOrigin::ensure_address_origin(&address, origin)?;
let address_account_id = T::AddressMapping::into_account_id(address);

T::Currency::transfer(
&address_account_id,
&destination,
value,
ExistenceRequirement::AllowDeath
)?;
}

/// Issue an EVM call operation. This is similar to a message call transaction in Ethereum.
#[weight = T::GasToWeight::gas_to_weight(*gas_limit)]
fn call(
Expand All @@ -393,6 +379,7 @@ decl_module! {
gas_limit,
Some(gas_price),
nonce,
T::config(),
)?;

match info.exit_reason {
Expand Down Expand Up @@ -431,6 +418,7 @@ decl_module! {
gas_limit,
Some(gas_price),
nonce,
T::config(),
)?;
match info {
CreateInfo {
Expand Down Expand Up @@ -477,6 +465,7 @@ decl_module! {
gas_limit,
Some(gas_price),
nonce,
T::config(),
)?;
match info {
CreateInfo {
Expand Down
9 changes: 3 additions & 6 deletions frame/evm/src/runner/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ impl<T: Trait> RunnerT<T> for Runner<T> {
gas_limit: u32,
gas_price: Option<U256>,
nonce: Option<U256>,
config: &evm::Config,
) -> Result<CallInfo, Self::Error> {
let gas_price = match gas_price {
Some(gas_price) => {
Expand Down Expand Up @@ -85,8 +86,6 @@ impl<T: Trait> RunnerT<T> for Runner<T> {
origin: source,
};

let config = T::config();

let mut substate = Handler::<T>::new_with_precompile(
&vicinity,
gas_limit as usize,
Expand Down Expand Up @@ -125,6 +124,7 @@ impl<T: Trait> RunnerT<T> for Runner<T> {
gas_limit: u32,
gas_price: Option<U256>,
nonce: Option<U256>,
config: &evm::Config,
) -> Result<CreateInfo, Self::Error> {
let gas_price = match gas_price {
Some(gas_price) => {
Expand Down Expand Up @@ -153,8 +153,6 @@ impl<T: Trait> RunnerT<T> for Runner<T> {
origin: source,
};

let config = T::config();

let mut substate = Handler::<T>::new_with_precompile(
&vicinity,
gas_limit as usize,
Expand Down Expand Up @@ -203,6 +201,7 @@ impl<T: Trait> RunnerT<T> for Runner<T> {
gas_limit: u32,
gas_price: Option<U256>,
nonce: Option<U256>,
config: &evm::Config,
) -> Result<CreateInfo, Self::Error> {
let gas_price = match gas_price {
Some(gas_price) => {
Expand Down Expand Up @@ -231,8 +230,6 @@ impl<T: Trait> RunnerT<T> for Runner<T> {
origin: source,
};

let config = T::config();

let mut substate = Handler::<T>::new_with_precompile(
&vicinity,
gas_limit as usize,
Expand Down
3 changes: 3 additions & 0 deletions frame/evm/src/runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pub trait Runner<T: Trait> {
gas_limit: u32,
gas_price: Option<U256>,
nonce: Option<U256>,
config: &evm::Config,
) -> Result<CallInfo, Self::Error>;

fn create(
Expand All @@ -43,6 +44,7 @@ pub trait Runner<T: Trait> {
gas_limit: u32,
gas_price: Option<U256>,
nonce: Option<U256>,
config: &evm::Config,
) -> Result<CreateInfo, Self::Error>;

fn create2(
Expand All @@ -53,5 +55,6 @@ pub trait Runner<T: Trait> {
gas_limit: u32,
gas_price: Option<U256>,
nonce: Option<U256>,
config: &evm::Config,
) -> Result<CreateInfo, Self::Error>;
}
Loading

0 comments on commit f225cd9

Please sign in to comment.