Skip to content

Commit

Permalink
Update evm module runtime name (#293)
Browse files Browse the repository at this point in the history
* Fix evm runtime name

* Format toml

* Add migration

* Fix state processor

* Use latest polkadot-v0.9.37 commit

* Fix tests
  • Loading branch information
boundless-forest authored Feb 22, 2023
1 parent c46aa63 commit f24def2
Show file tree
Hide file tree
Showing 24 changed files with 440 additions and 419 deletions.
407 changes: 219 additions & 188 deletions Cargo.lock

Large diffs are not rendered by default.

346 changes: 173 additions & 173 deletions Cargo.toml

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions node/src/chain_spec/crab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn genesis_config() -> ChainSpec {

// EVM stuff.
ethereum: Default::default(),
evm: EvmConfig {
evm: EVMConfig {
accounts: {
BTreeMap::from_iter(
CrabPrecompiles::<Runtime>::used_addresses().iter().map(|p| {
Expand Down Expand Up @@ -308,7 +308,7 @@ fn testnet_genesis(

// EVM stuff.
ethereum: Default::default(),
evm: EvmConfig {
evm: EVMConfig {
accounts: {
BTreeMap::from_iter(
CrabPrecompiles::<Runtime>::used_addresses()
Expand Down
4 changes: 2 additions & 2 deletions node/src/chain_spec/darwinia.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ pub fn genesis_config() -> ChainSpec {

// EVM stuff.
ethereum: Default::default(),
evm: EvmConfig {
evm: EVMConfig {
accounts: {
BTreeMap::from_iter(
DarwiniaPrecompiles::<Runtime>::used_addresses().iter().map(|p| {
Expand Down Expand Up @@ -308,7 +308,7 @@ fn testnet_genesis(

// EVM stuff.
ethereum: Default::default(),
evm: EvmConfig {
evm: EVMConfig {
accounts: {
BTreeMap::from_iter(
DarwiniaPrecompiles::<Runtime>::used_addresses()
Expand Down
4 changes: 2 additions & 2 deletions node/src/chain_spec/pangolin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn genesis_config() -> ChainSpec {

// EVM stuff.
ethereum: Default::default(),
evm: EvmConfig {
evm: EVMConfig {
accounts: {
BTreeMap::from_iter(
PangolinPrecompiles::<Runtime>::used_addresses().iter().map(|p| {
Expand Down Expand Up @@ -333,7 +333,7 @@ fn testnet_genesis(

// EVM stuff.
ethereum: Default::default(),
evm: EvmConfig {
evm: EVMConfig {
accounts: {
BTreeMap::from_iter(
PangolinPrecompiles::<Runtime>::used_addresses()
Expand Down
4 changes: 2 additions & 2 deletions node/src/chain_spec/pangoro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ pub fn genesis_config() -> ChainSpec {

// EVM stuff.
ethereum: Default::default(),
evm: EvmConfig {
evm: EVMConfig {
accounts: {
BTreeMap::from_iter(
PangoroPrecompiles::<Runtime>::used_addresses().iter().map(|p| {
Expand Down Expand Up @@ -333,7 +333,7 @@ fn testnet_genesis(

// EVM stuff.
ethereum: Default::default(),
evm: EvmConfig {
evm: EVMConfig {
accounts: {
BTreeMap::from_iter(
PangoroPrecompiles::<Runtime>::used_addresses()
Expand Down
2 changes: 1 addition & 1 deletion pallet/message-gadget/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ frame_support::construct_runtime! {
System: frame_system,
Timestamp: pallet_timestamp,
Balances: pallet_balances,
Evm: pallet_evm,
EVM: pallet_evm,
MessageGadget: darwinia_message_gadget,
}
}
Expand Down
6 changes: 3 additions & 3 deletions pallet/message-transact/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ pub mod pallet {

#[pallet::error]
pub enum Error<T> {
/// Evm validation errors.
/// EVM validation errors.
MessageTransactError(EvmTxErrorWrapper),
}

Expand Down Expand Up @@ -192,9 +192,9 @@ impl From<InvalidEvmTransactionError> for EvmTxErrorWrapper {
}
}

/// Calculates the fee for a relayer to submit an LCMP Evm transaction.
/// Calculates the fee for a relayer to submit an LCMP EVM transaction.
///
/// The gas_price of an LCMP Evm transaction is always the min_gas_price(), which is a fixed value.
/// The gas_price of an LCMP EVM transaction is always the min_gas_price(), which is a fixed value.
/// Therefore, only the gas_limit and value of the transaction should be considered in the
/// calculation of the fee, and the gas_price of the transaction itself can be ignored.
pub fn total_payment<T: pallet_evm::Config>(tx_data: TransactionData) -> U256 {
Expand Down
2 changes: 1 addition & 1 deletion pallet/message-transact/src/tests/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ fn test_dispatch_eip1559_transaction_weight_mismatch() {
pallet_bridge_dispatch::Event::MessageWeightMismatch(
SOURCE_CHAIN_ID,
mock_message_id,
Weight::from_ref_time(1249901046000),
Weight::from_ref_time(1249900180000),
Weight::from_ref_time(1000000000000),
),
));
Expand Down
2 changes: 1 addition & 1 deletion pallet/message-transact/src/tests/eip2930.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ fn test_dispatch_eip2930_transaction_weight_mismatch() {
pallet_bridge_dispatch::Event::MessageWeightMismatch(
SOURCE_CHAIN_ID,
mock_message_id,
Weight::from_ref_time(1249901046000),
Weight::from_ref_time(1249900180000),
Weight::from_ref_time(1000000000000),
),
));
Expand Down
2 changes: 1 addition & 1 deletion pallet/message-transact/src/tests/legacy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ fn test_dispatch_legacy_transaction_weight_mismatch() {
pallet_bridge_dispatch::Event::MessageWeightMismatch(
SOURCE_CHAIN_ID,
mock_message_id,
Weight::from_ref_time(1249901046000),
Weight::from_ref_time(1249900180000),
Weight::from_ref_time(1000000000000),
),
));
Expand Down
2 changes: 1 addition & 1 deletion precompile/state-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,6 @@ where
pub struct StateStorageFilter;
impl StorageFilterT for StateStorageFilter {
fn allow(prefix: &[u8]) -> bool {
prefix != Twox128::hash(b"Evm")
prefix != Twox128::hash(b"EVM")
}
}
2 changes: 1 addition & 1 deletion precompile/state-storage/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ frame_support::construct_runtime! {
System: frame_system,
Timestamp: pallet_timestamp,
Balances: pallet_balances,
Evm: pallet_evm,
EVM: pallet_evm,
}
}

Expand Down
8 changes: 4 additions & 4 deletions runtime/crab/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ frame_support::construct_runtime! {

// EVM stuff.
Ethereum: pallet_ethereum = 36,
Evm: pallet_evm = 37,
EVM: pallet_evm = 37,
MessageTransact: darwinia_message_transact = 38,

// Crab <> Darwinia
Expand Down Expand Up @@ -317,7 +317,7 @@ sp_api::impl_runtime_apis! {
}

fn account_basic(address: sp_core::H160) -> pallet_evm::Account {
let (account, _) = Evm::account_basic(&address);
let (account, _) = EVM::account_basic(&address);

account
}
Expand All @@ -332,7 +332,7 @@ sp_api::impl_runtime_apis! {
}

fn account_code_at(address: sp_core::H160) -> Vec<u8> {
Evm::account_codes(address)
EVM::account_codes(address)
}

fn author() -> sp_core::H160 {
Expand All @@ -344,7 +344,7 @@ sp_api::impl_runtime_apis! {

index.to_big_endian(&mut tmp);

Evm::account_storages(address, sp_core::H256::from_slice(&tmp[..]))
EVM::account_storages(address, sp_core::H256::from_slice(&tmp[..]))
}

fn call(
Expand Down
8 changes: 4 additions & 4 deletions runtime/darwinia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ frame_support::construct_runtime! {

// EVM stuff.
Ethereum: pallet_ethereum = 36,
Evm: pallet_evm = 37,
EVM: pallet_evm = 37,
MessageTransact: darwinia_message_transact = 38,

// Darwinia <> Crab
Expand Down Expand Up @@ -317,7 +317,7 @@ sp_api::impl_runtime_apis! {
}

fn account_basic(address: sp_core::H160) -> pallet_evm::Account {
let (account, _) = Evm::account_basic(&address);
let (account, _) = EVM::account_basic(&address);

account
}
Expand All @@ -332,7 +332,7 @@ sp_api::impl_runtime_apis! {
}

fn account_code_at(address: sp_core::H160) -> Vec<u8> {
Evm::account_codes(address)
EVM::account_codes(address)
}

fn author() -> sp_core::H160 {
Expand All @@ -344,7 +344,7 @@ sp_api::impl_runtime_apis! {

index.to_big_endian(&mut tmp);

Evm::account_storages(address, sp_core::H256::from_slice(&tmp[..]))
EVM::account_storages(address, sp_core::H256::from_slice(&tmp[..]))
}

fn call(
Expand Down
1 change: 0 additions & 1 deletion runtime/darwinia/src/pallets/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ where
}
}


pub struct DarwiniaPrecompiles<R>(sp_std::marker::PhantomData<R>);
impl<R> DarwiniaPrecompiles<R>
where
Expand Down
8 changes: 4 additions & 4 deletions runtime/pangolin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ frame_support::construct_runtime! {

// EVM stuff.
Ethereum: pallet_ethereum = 36,
Evm: pallet_evm = 37,
EVM: pallet_evm = 37,
MessageTransact: darwinia_message_transact = 38,

// Pangolin <> Pangoro
Expand Down Expand Up @@ -319,7 +319,7 @@ sp_api::impl_runtime_apis! {
}

fn account_basic(address: sp_core::H160) -> pallet_evm::Account {
let (account, _) = Evm::account_basic(&address);
let (account, _) = EVM::account_basic(&address);

account
}
Expand All @@ -334,7 +334,7 @@ sp_api::impl_runtime_apis! {
}

fn account_code_at(address: sp_core::H160) -> Vec<u8> {
Evm::account_codes(address)
EVM::account_codes(address)
}

fn author() -> sp_core::H160 {
Expand All @@ -346,7 +346,7 @@ sp_api::impl_runtime_apis! {

index.to_big_endian(&mut tmp);

Evm::account_storages(address, sp_core::H256::from_slice(&tmp[..]))
EVM::account_storages(address, sp_core::H256::from_slice(&tmp[..]))
}

fn call(
Expand Down
3 changes: 1 addition & 2 deletions runtime/pangolin/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ impl frame_support::traits::OnRuntimeUpgrade for CustomOnRuntimeUpgrade {
}

fn migrate() -> frame_support::weights::Weight {
<pallet_assets::migration::v1::MigrateToV1<Runtime> as frame_support::traits::OnRuntimeUpgrade>::on_runtime_upgrade();
frame_support::migration::move_pallet(b"Staking", b"DarwiniaStaking");
frame_support::migration::move_pallet(b"Evm", b"EVM");

// frame_support::weights::Weight::zero()
RuntimeBlockWeights::get().max_block
Expand Down
8 changes: 4 additions & 4 deletions runtime/pangoro/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ frame_support::construct_runtime! {

// EVM stuff.
Ethereum: pallet_ethereum = 36,
Evm: pallet_evm = 37,
EVM: pallet_evm = 37,
MessageTransact: darwinia_message_transact = 38,

// Pangoro <> Pangolin
Expand Down Expand Up @@ -319,7 +319,7 @@ sp_api::impl_runtime_apis! {
}

fn account_basic(address: sp_core::H160) -> pallet_evm::Account {
let (account, _) = Evm::account_basic(&address);
let (account, _) = EVM::account_basic(&address);

account
}
Expand All @@ -334,7 +334,7 @@ sp_api::impl_runtime_apis! {
}

fn account_code_at(address: sp_core::H160) -> Vec<u8> {
Evm::account_codes(address)
EVM::account_codes(address)
}

fn author() -> sp_core::H160 {
Expand All @@ -346,7 +346,7 @@ sp_api::impl_runtime_apis! {

index.to_big_endian(&mut tmp);

Evm::account_storages(address, sp_core::H256::from_slice(&tmp[..]))
EVM::account_storages(address, sp_core::H256::from_slice(&tmp[..]))
}

fn call(
Expand Down
2 changes: 1 addition & 1 deletion tests/ethereum/test-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe("Test contract", () => {
}).timeout(60000);

step("Get contract code", async function () {
expect(await web3.eth.getCode(inc.options.address), incrementerInfo.bytecode);
expect(await web3.eth.getCode(inc.options.address)).not.to.be.null;
});

step("Get default number", async function () {
Expand Down
2 changes: 1 addition & 1 deletion tool/state-processor/src/evm/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Process steps
- set `PALLET_ETHEREUM_SCHEMA`
- take solo `EVM::AccountCodes` and `EVM::AccountStorages`
- set `Evm::AccountCodes` and `Evm::AccountStorages`
- set `EVM::AccountCodes` and `EVM::AccountStorages`
22 changes: 9 additions & 13 deletions tool/state-processor/src/evm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,18 @@ impl<S> Processor<S> {

// Storage items.
// https://github.dev/darwinia-network/frontier/blob/darwinia-v0.12.5/frame/evm/src/lib.rs#L407
let mut account_codes = Map::default();
let mut account_storages = Map::default();
let mut codes = Map::default();
let mut storages = Map::default();

log::info!("take `EVM::AccountCodes` and `EVM::AccountStorages`");
self.solo_state
.take_raw_map(&item_key(b"EVM", b"AccountCodes"), &mut account_codes, |key, from| {
replace_first_match(key, from, &item_key(b"Evm", b"AccountCodes"))
})
.take_raw_map(
&item_key(b"EVM", b"AccountStorages"),
&mut account_storages,
|key, from| replace_first_match(key, from, &item_key(b"Evm", b"AccountStorages")),
);

log::info!("set `Evm::AccountCodes` and `Evm::AccountStorages`");
self.shell_state.insert_raw_key_map(account_codes).insert_raw_key_map(account_storages);
.take_raw_map(&item_key(b"EVM", b"AccountCodes"), &mut codes, |k, _| k.to_owned())
.take_raw_map(&item_key(b"EVM", b"AccountStorages"), &mut storages, |k, _| {
k.to_owned()
});

log::info!("set `EVM::AccountCodes` and `EVM::AccountStorages`");
self.shell_state.insert_raw_key_map(codes).insert_raw_key_map(storages);

self
}
Expand Down
6 changes: 3 additions & 3 deletions tool/state-processor/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Tester {
get_last_64_key,
)
.take_map(b"AccountMigration", b"Accounts", &mut migration_accounts, get_last_64_key)
.take_map(b"Evm", b"AccountCodes", &mut shell_evm_codes, get_last_40);
.take_map(b"EVM", b"AccountCodes", &mut shell_evm_codes, get_last_40);

Self {
solo_accounts,
Expand Down Expand Up @@ -621,7 +621,7 @@ fn evm_contract_account_storage() {

let migrated_storage_item_len = tester.shell_state.map.iter().fold(0u32, |sum, (k, _)| {
if k.starts_with(&full_key(
b"Evm",
b"EVM",
b"AccountStorages",
&blake2_128_concat_to_string(addr.encode()),
)) {
Expand All @@ -634,7 +634,7 @@ fn evm_contract_account_storage() {

let mut migrated_storage_value = H256::zero();
tester.shell_state.get_value(
b"Evm",
b"EVM",
b"AccountStorages",
&format!(
"{}{}",
Expand Down
4 changes: 0 additions & 4 deletions tool/state-processor/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,6 @@ pub fn get_last_64(key: &str) -> String {
format!("0x{}", &key[key.len() - 64..])
}

pub fn replace_first_match(key: &str, from: &str, to: &str) -> String {
key.replacen(from, to, 1)
}

pub fn blake2_128_concat_to_string<D>(data: D) -> String
where
D: AsRef<[u8]>,
Expand Down

0 comments on commit f24def2

Please sign in to comment.