Skip to content
53 changes: 51 additions & 2 deletions node/src/frontier_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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<B, BE, C>(
client: Arc<C>,
config: &sc_service::Configuration,
eth_rpc_config: EthRpcConfig,
) -> Result<fc_db::Backend<B>, String>
where
B: 'static + sp_runtime::traits::Block<Hash = Hash>,
BE: 'static + sc_client_api::backend::Backend<B>,
C: 'static
+ sp_api::ProvideRuntimeApi<B>
+ sp_blockchain::HeaderBackend<B>
+ sc_client_api::backend::StorageProvider<B, BE>,
C::Api: fp_rpc::EthereumRuntimeRPCApi<B>,
{
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::<B>::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::<B>::Sql(backend))
},
}
}
33 changes: 2 additions & 31 deletions node/src/service/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ pub use pangoro_runtime::RuntimeApi as PangoroRuntimeApi;
// std
use std::{
collections::BTreeMap,
path::Path,
sync::{Arc, Mutex},
time::Duration,
};
Expand All @@ -47,8 +46,6 @@ use sc_network::NetworkBlock;

/// Full client backend type.
type FullBackend = sc_service::TFullBackend<Block>;
/// Frontier backend type.
type FrontierBackend = fc_db::Backend<Block>;
/// Full client type.
type FullClient<RuntimeApi, Executor> =
sc_service::TFullClient<Block, RuntimeApi, sc_executor::NativeElseWasmExecutor<Executor>>;
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion pallet/message-gadget/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ where
Vec::new(),
false,
false,
// TODO: FIX ME
None,
None,
<T as pallet_evm::Config>::config(),
Expand Down
3 changes: 0 additions & 3 deletions pallet/message-gadget/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(<Runtime as pallet_evm::Config>::FeeCalculator::min_gas_price().0),
None,
Some(U256::from(1)),
vec![],
// TODO: not sure
true,
// TODO: not sure
false,
None,
None,
Expand Down
26 changes: 23 additions & 3 deletions pallet/message-transact/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,16 @@ pub mod pallet {
};

let transaction_data: TransactionData = (&*transaction).into();
let (weight_limit, proof_size_base_cost) =
match <T as pallet_evm::Config>::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::<EvmTxErrorWrapper>::new(
CheckEvmTransactionConfig {
evm_config: T::config(),
Expand All @@ -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())
Expand Down Expand Up @@ -213,3 +222,14 @@ pub fn total_payment<T: pallet_evm::Config>(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
}
3 changes: 1 addition & 2 deletions pallet/message-transact/src/tests/eip1559.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
),
));
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_parts(1249900180000, 0),
Weight::from_parts(1249886382000, 0),
Weight::from_parts(1000000000000, 0),
),
));
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_parts(1249900180000, 0),
Weight::from_parts(1249886382000, 0),
Weight::from_parts(1000000000000, 0),
),
));
Expand Down
141 changes: 70 additions & 71 deletions runtime/common/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
})
}
}
Expand Down
10 changes: 5 additions & 5 deletions runtime/crab/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
// You should have received a copy of the GNU General Public License
// along with Darwinia. If not, see <https://www.gnu.org/licenses/>.

// 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"))]
Expand Down
Loading