diff --git a/node/src/frontier_service.rs b/node/src/frontier_service.rs index b507f2657..75601a4f3 100644 --- a/node/src/frontier_service.rs +++ b/node/src/frontier_service.rs @@ -19,12 +19,16 @@ //! Service and service factory implementation. Specialized wrapper over substrate service. // std -use std::{path::PathBuf, sync::Arc, time::Duration}; +use std::{ + path::{Path, PathBuf}, + sync::Arc, + time::Duration, +}; // crates.io use futures::{future, StreamExt}; use tokio::sync::Semaphore; // darwinia -use crate::cli::{EthRpcConfig, TracingApi}; +use crate::cli::{EthRpcConfig, FrontierBackendType, TracingApi}; use dc_primitives::{BlockNumber, Hash, Hashing}; // frontier use fc_mapping_sync::{EthereumBlockNotification, EthereumBlockNotificationSinks}; @@ -203,3 +207,48 @@ where pub(crate) fn db_config_dir(config: &Configuration) -> PathBuf { config.base_path.config_dir(config.chain_spec.id()) } + +/// Create a Frontier backend. +pub(crate) fn frontier_backend( + client: Arc, + config: &sc_service::Configuration, + eth_rpc_config: EthRpcConfig, +) -> Result, String> +where + B: 'static + sp_runtime::traits::Block, + BE: 'static + sc_client_api::backend::Backend, + C: 'static + + sp_api::ProvideRuntimeApi + + sp_blockchain::HeaderBackend + + sc_client_api::backend::StorageProvider, + C::Api: fp_rpc::EthereumRuntimeRPCApi, +{ + let db_config_dir = db_config_dir(config); + let overrides = fc_storage::overrides_handle(client.clone()); + match eth_rpc_config.frontier_backend_type { + FrontierBackendType::KeyValue => Ok(fc_db::Backend::::KeyValue( + fc_db::kv::Backend::open(Arc::clone(&client), &config.database, &db_config_dir)?, + )), + FrontierBackendType::Sql => { + let db_path = db_config_dir.join("sql"); + std::fs::create_dir_all(&db_path).expect("failed creating sql db directory"); + let backend = futures::executor::block_on(fc_db::sql::Backend::new( + fc_db::sql::BackendConfig::Sqlite(fc_db::sql::SqliteBackendConfig { + path: Path::new("sqlite:///") + .join(db_path) + .join("frontier.db3") + .to_str() + .unwrap(), + create_if_missing: true, + thread_count: eth_rpc_config.frontier_sql_backend_thread_count, + cache_size: eth_rpc_config.frontier_sql_backend_cache_size, + }), + eth_rpc_config.frontier_sql_backend_pool_size, + std::num::NonZeroU32::new(eth_rpc_config.frontier_sql_backend_num_ops_timeout), + overrides, + )) + .unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err)); + Ok(fc_db::Backend::::Sql(backend)) + }, + } +} diff --git a/node/src/service/mod.rs b/node/src/service/mod.rs index 805398796..b6572b5fc 100644 --- a/node/src/service/mod.rs +++ b/node/src/service/mod.rs @@ -35,7 +35,6 @@ pub use pangoro_runtime::RuntimeApi as PangoroRuntimeApi; // std use std::{ collections::BTreeMap, - path::Path, sync::{Arc, Mutex}, time::Duration, }; @@ -47,8 +46,6 @@ use sc_network::NetworkBlock; /// Full client backend type. type FullBackend = sc_service::TFullBackend; -/// Frontier backend type. -type FrontierBackend = fc_db::Backend; /// Full client type. type FullClient = sc_service::TFullClient>; @@ -216,34 +213,8 @@ where &task_manager, )?; // Frontier stuffs. - let overrides = fc_storage::overrides_handle(client.clone()); - let db_config_dir = crate::frontier_service::db_config_dir(config); - let frontier_backend = match eth_rpc_config.frontier_backend_type { - crate::cli::FrontierBackendType::KeyValue => FrontierBackend::KeyValue( - fc_db::kv::Backend::open(Arc::clone(&client), &config.database, &db_config_dir)?, - ), - crate::cli::FrontierBackendType::Sql => { - let db_path = db_config_dir.join("sql"); - std::fs::create_dir_all(&db_path).expect("failed creating sql db directory"); - let backend = futures::executor::block_on(fc_db::sql::Backend::new( - fc_db::sql::BackendConfig::Sqlite(fc_db::sql::SqliteBackendConfig { - path: Path::new("sqlite:///") - .join(db_path) - .join("frontier.db3") - .to_str() - .unwrap(), - create_if_missing: true, - thread_count: eth_rpc_config.frontier_sql_backend_thread_count, - cache_size: eth_rpc_config.frontier_sql_backend_cache_size, - }), - eth_rpc_config.frontier_sql_backend_pool_size, - std::num::NonZeroU32::new(eth_rpc_config.frontier_sql_backend_num_ops_timeout), - overrides, - )) - .unwrap_or_else(|err| panic!("failed creating sql backend: {:?}", err)); - FrontierBackend::Sql(backend) - }, - }; + let frontier_backend = + crate::frontier_service::frontier_backend(client.clone(), config, eth_rpc_config.clone())?; let filter_pool = Some(Arc::new(Mutex::new(BTreeMap::new()))); let fee_history_cache = Arc::new(Mutex::new(BTreeMap::new())); let fee_history_cache_limit = eth_rpc_config.fee_history_limit; diff --git a/pallet/message-gadget/src/lib.rs b/pallet/message-gadget/src/lib.rs index 7a7cb5aa9..05a1a67aa 100644 --- a/pallet/message-gadget/src/lib.rs +++ b/pallet/message-gadget/src/lib.rs @@ -95,7 +95,6 @@ where Vec::new(), false, false, - // TODO: FIX ME None, None, ::config(), diff --git a/pallet/message-gadget/src/tests.rs b/pallet/message-gadget/src/tests.rs index ecfb71ae0..da8a2e80e 100644 --- a/pallet/message-gadget/src/tests.rs +++ b/pallet/message-gadget/src/tests.rs @@ -139,14 +139,11 @@ fn message_root_getter_should_work() { array_bytes::hex2bytes_unchecked(CONTRACT_CODE), U256::zero(), U256::from(300_000_000).low_u64(), - // TODO: not sure Some(::FeeCalculator::min_gas_price().0), None, Some(U256::from(1)), vec![], - // TODO: not sure true, - // TODO: not sure false, None, None, diff --git a/pallet/message-transact/src/lib.rs b/pallet/message-transact/src/lib.rs index 9bdae40b5..c36930dc2 100644 --- a/pallet/message-transact/src/lib.rs +++ b/pallet/message-transact/src/lib.rs @@ -148,6 +148,16 @@ pub mod pallet { }; let transaction_data: TransactionData = (&*transaction).into(); + let (weight_limit, proof_size_base_cost) = + match ::GasWeightMapping::gas_to_weight( + transaction_data.gas_limit.unique_saturated_into(), + true, + ) { + weight_limit if weight_limit.proof_size() > 0 => + (Some(weight_limit), Some(proof_size_base_cost(&transaction))), + _ => (None, None), + }; + let _ = CheckEvmTransaction::::new( CheckEvmTransactionConfig { evm_config: T::config(), @@ -157,9 +167,8 @@ pub mod pallet { is_transactional: true, }, transaction_data.into(), - // TODO: FIX ME - None, - None, + weight_limit, + proof_size_base_cost, ) .validate_in_block_for(&who) .and_then(|v| v.with_chain_id()) @@ -213,3 +222,14 @@ pub fn total_payment(tx_data: TransactionData) -> U256 { tx_data.value.saturating_add(fee) } + +// TODO: Reuse the frontier implementation +fn proof_size_base_cost(transaction: &Transaction) -> u64 { + transaction + .encode() + .len() + // pallet index + .saturating_add(1) + // call index + .saturating_add(1) as u64 +} diff --git a/pallet/message-transact/src/tests/eip1559.rs b/pallet/message-transact/src/tests/eip1559.rs index 3845dd58b..28f311ebc 100644 --- a/pallet/message-transact/src/tests/eip1559.rs +++ b/pallet/message-transact/src/tests/eip1559.rs @@ -109,12 +109,11 @@ fn test_dispatch_eip1559_transaction_weight_mismatch() { ); assert!(!result.dispatch_result); - System::assert_has_event(RuntimeEvent::Dispatch( pallet_bridge_dispatch::Event::MessageWeightMismatch( SOURCE_CHAIN_ID, mock_message_id, - Weight::from_parts(1249900180000, 0), + Weight::from_parts(1249886382000, 0), Weight::from_parts(1000000000000, 0), ), )); diff --git a/pallet/message-transact/src/tests/eip2930.rs b/pallet/message-transact/src/tests/eip2930.rs index eca8a5042..751d20048 100644 --- a/pallet/message-transact/src/tests/eip2930.rs +++ b/pallet/message-transact/src/tests/eip2930.rs @@ -112,7 +112,7 @@ fn test_dispatch_eip2930_transaction_weight_mismatch() { pallet_bridge_dispatch::Event::MessageWeightMismatch( SOURCE_CHAIN_ID, mock_message_id, - Weight::from_parts(1249900180000, 0), + Weight::from_parts(1249886382000, 0), Weight::from_parts(1000000000000, 0), ), )); diff --git a/pallet/message-transact/src/tests/legacy.rs b/pallet/message-transact/src/tests/legacy.rs index dfab94824..107008877 100644 --- a/pallet/message-transact/src/tests/legacy.rs +++ b/pallet/message-transact/src/tests/legacy.rs @@ -109,7 +109,7 @@ fn test_dispatch_legacy_transaction_weight_mismatch() { pallet_bridge_dispatch::Event::MessageWeightMismatch( SOURCE_CHAIN_ID, mock_message_id, - Weight::from_parts(1249900180000, 0), + Weight::from_parts(1249886382000, 0), Weight::from_parts(1000000000000, 0), ), )); diff --git a/runtime/common/src/test.rs b/runtime/common/src/test.rs index f5698f274..e0d36d3e5 100644 --- a/runtime/common/src/test.rs +++ b/runtime/common/src/test.rs @@ -623,77 +623,76 @@ macro_rules! impl_fee_tests { TransactionPaymentGasPrice::min_gas_price().0 }; - // TODO: FIX ME - // assert_eq!( - // sim(Perbill::from_percent(0), 1), - // U256::from(18_779_695_954_322u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(25), 1), - // U256::from(18_779_695_954_322u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(50), 1), - // U256::from(18_780_048_076_923u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(100), 1), - // U256::from(18_781_104_484_337u128), - // ); - - // // 1 "real" hour (at 12-second blocks) - // assert_eq!( - // sim(Perbill::from_percent(0), 300), - // U256::from(18_675_757_338_238u128) - // ); - // assert_eq!( - // sim(Perbill::from_percent(25), 300), - // U256::from(18_675_757_338_238u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(50), 300), - // U256::from(18_781_104_484_337u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(100), 300), - // U256::from(19_100_724_834_341u128), - // ); - - // // 1 "real" day (at 12-second blocks) - // assert_eq!( - // sim(Perbill::from_percent(0), 7200), - // U256::from(16_688_607_212_670u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(25), 7200), - // U256::from(16_688_607_212_670u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(50), 7200), - // U256::from(19_100_724_834_341u128) - // ); - // assert_eq!( - // sim(Perbill::from_percent(100), 7200), - // U256::from(28_637_764_490_907u128), - // ); - - // // 7 "real" day (at 12-second blocks) - // assert_eq!( - // sim(Perbill::from_percent(0), 50400), - // U256::from(11_130_914_014_528u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(25), 50400), - // U256::from(11_130_914_014_528u128), - // ); - // assert_eq!( - // sim(Perbill::from_percent(50), 50400), - // U256::from(28_637_764_490_907u128) - // ); - // assert_eq!( - // sim(Perbill::from_percent(100), 50400), - // U256::from(487_712_592_259_520u128), - // ); + assert_eq!( + sim(Perbill::from_percent(0), 1), + U256::from(16_499_453_035_776u128), + ); + assert_eq!( + sim(Perbill::from_percent(25), 1), + U256::from(16_499_453_035_776u128), + ); + assert_eq!( + sim(Perbill::from_percent(50), 1), + U256::from(16_499_762_403_421u128), + ); + assert_eq!( + sim(Perbill::from_percent(100), 1), + U256::from(165_00_690_541_159u128), + ); + + // 1 "real" hour (at 12-second blocks) + assert_eq!( + sim(Perbill::from_percent(0), 300), + U256::from(16_408_134_714_177u128) + ); + assert_eq!( + sim(Perbill::from_percent(25), 300), + U256::from(16_408_134_714_177u128), + ); + assert_eq!( + sim(Perbill::from_percent(50), 300), + U256::from(16_500_690_541_159u128), + ); + assert_eq!( + sim(Perbill::from_percent(100), 300), + U256::from(16_781_502_380_018u128), + ); + + // 1 "real" day (at 12-second blocks) + assert_eq!( + sim(Perbill::from_percent(0), 7200), + U256::from(14_662_265_651_569u128), + ); + assert_eq!( + sim(Perbill::from_percent(25), 7200), + U256::from(14_662_265_651_569u128), + ); + assert_eq!( + sim(Perbill::from_percent(50), 7200), + U256::from(16_781_502_380_018u128) + ); + assert_eq!( + sim(Perbill::from_percent(100), 7200), + U256::from(25_160_548_467_697u128), + ); + + // 7 "real" day (at 12-second blocks) + assert_eq!( + sim(Perbill::from_percent(0), 50400), + U256::from(9_779_391_182_619u128), + ); + assert_eq!( + sim(Perbill::from_percent(25), 50400), + U256::from(9_779_391_182_619u128), + ); + assert_eq!( + sim(Perbill::from_percent(50), 50400), + U256::from(25_160_548_467_697u128) + ); + assert_eq!( + sim(Perbill::from_percent(100), 50400), + U256::from(428_494_211_541_821u128), + ); }) } } diff --git a/runtime/crab/build.rs b/runtime/crab/build.rs index b8c47c4a1..7d51a42f2 100644 --- a/runtime/crab/build.rs +++ b/runtime/crab/build.rs @@ -16,13 +16,13 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . -// crates.io -#[cfg(feature = "std")] -use substrate_wasm_builder::WasmBuilder; - #[cfg(feature = "std")] fn main() { - WasmBuilder::new().with_current_project().export_heap_base().import_memory().build() + substrate_wasm_builder::WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build() } #[cfg(not(feature = "std"))] diff --git a/runtime/darwinia/build.rs b/runtime/darwinia/build.rs index b8c47c4a1..7d51a42f2 100644 --- a/runtime/darwinia/build.rs +++ b/runtime/darwinia/build.rs @@ -16,13 +16,13 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . -// crates.io -#[cfg(feature = "std")] -use substrate_wasm_builder::WasmBuilder; - #[cfg(feature = "std")] fn main() { - WasmBuilder::new().with_current_project().export_heap_base().import_memory().build() + substrate_wasm_builder::WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build() } #[cfg(not(feature = "std"))] diff --git a/runtime/pangolin/build.rs b/runtime/pangolin/build.rs index b8c47c4a1..7d51a42f2 100644 --- a/runtime/pangolin/build.rs +++ b/runtime/pangolin/build.rs @@ -16,13 +16,13 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . -// crates.io -#[cfg(feature = "std")] -use substrate_wasm_builder::WasmBuilder; - #[cfg(feature = "std")] fn main() { - WasmBuilder::new().with_current_project().export_heap_base().import_memory().build() + substrate_wasm_builder::WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build() } #[cfg(not(feature = "std"))] diff --git a/runtime/pangoro/build.rs b/runtime/pangoro/build.rs index b8c47c4a1..7d51a42f2 100644 --- a/runtime/pangoro/build.rs +++ b/runtime/pangoro/build.rs @@ -16,13 +16,13 @@ // You should have received a copy of the GNU General Public License // along with Darwinia. If not, see . -// crates.io -#[cfg(feature = "std")] -use substrate_wasm_builder::WasmBuilder; - #[cfg(feature = "std")] fn main() { - WasmBuilder::new().with_current_project().export_heap_base().import_memory().build() + substrate_wasm_builder::WasmBuilder::new() + .with_current_project() + .export_heap_base() + .import_memory() + .build() } #[cfg(not(feature = "std"))] diff --git a/tests/ethereum/test-tracing.ts b/tests/ethereum/test-tracing.ts index 0282f68fa..7ebe0d4d6 100644 --- a/tests/ethereum/test-tracing.ts +++ b/tests/ethereum/test-tracing.ts @@ -43,10 +43,9 @@ describe("Test EVM tracing", () => { step("RPC debug_traceTransaction should work", async function () { let trace_result = await customRequest(web3, "debug_traceTransaction", [transact_hash]); - - expect(trace_result.result.stepLogs.length).to.be.equal(198); - expect(trace_result.result.stepLogs[0].depth).to.be.equal(1); - expect(trace_result.result.stepLogs[0].pc).to.be.equal(0); + expect(trace_result.result.structLogs.length).to.be.equal(198); + expect(trace_result.result.structLogs[0].depth).to.be.equal(1); + expect(trace_result.result.structLogs[0].pc).to.be.equal(0); }).timeout(60000); step("RPC debug_traceBlockByNumber should work", async function () {