Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: update gas parameters for a parachain, units, and miscellaneous fixes and cleanups #6

Merged
merged 8 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
537 changes: 249 additions & 288 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ futures = "0.3.30"
serde_json = "1.0.114"

# Local
parachain-template-runtime = { path = "./runtime" }
frontier-parachain-runtime = { path = "./runtime" }

# Build
substrate-wasm-builder = { git = "https://github.com/paritytech/polkadot-sdk", branch = "release-polkadot-v1.9.0", default-features = false }
Expand Down Expand Up @@ -130,7 +130,7 @@ fc-mapping-sync = {git = "https://github.com/polkadot-evm/frontier", features =
fc-rpc = {git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0", features = ["rpc-binary-search-estimate", "txpool"], default-features = false }
fc-rpc-core = {git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0" }
fc-storage = {git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0" }
fp-dynamic-fee = {git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0", default-features = false }
fp-dynamic-fee = {git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0"}
fp-evm = {git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0", default-features = false }
fp-rpc = {git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0", default-features = false }
fp-self-contained = { git = "https://github.com/polkadot-evm/frontier", branch = "polkadot-v1.9.0", features = ["serde"], default-features = false }
Expand Down
7 changes: 4 additions & 3 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ jsonrpsee = { workspace = true }
futures = { workspace = true }
serde_json = { workspace = true }
color-print = { workspace = true }
hex-literal = "0.4.1"

# Local
parachain-template-runtime = {path = "../runtime"}
frontier-parachain-runtime = {path = "../runtime"}

# Substrate
frame-benchmarking = { workspace = true }
Expand Down Expand Up @@ -95,14 +96,14 @@ runtime-benchmarks = [
"cumulus-primitives-core/runtime-benchmarks",
"frame-benchmarking-cli/runtime-benchmarks",
"frame-benchmarking/runtime-benchmarks",
"parachain-template-runtime/runtime-benchmarks",
"frontier-parachain-runtime/runtime-benchmarks",
"polkadot-cli/runtime-benchmarks",
"polkadot-primitives/runtime-benchmarks",
"sc-service/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
try-runtime = [
"parachain-template-runtime/try-runtime",
"frontier-parachain-runtime/try-runtime",
"polkadot-cli/try-runtime",
"sp-runtime/try-runtime",
]
11 changes: 7 additions & 4 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use cumulus_primitives_core::ParaId;
use parachain_template_runtime as runtime;
use frontier_parachain_runtime as runtime;
use hex_literal::hex;
use runtime::{AccountId, AuraId, Signature, EXISTENTIAL_DEPOSIT};
use sc_chain_spec::{ChainSpecExtension, ChainSpecGroup};
use sc_service::ChainType;
Expand Down Expand Up @@ -66,7 +67,7 @@ pub fn development_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("tokenDecimals".into(), 18.into());
properties.insert("ss58Format".into(), 42.into());

ChainSpec::builder(
Expand Down Expand Up @@ -116,7 +117,7 @@ pub fn local_testnet_config() -> ChainSpec {
// Give your base currency a unit name and decimal places
let mut properties = sc_chain_spec::Properties::new();
properties.insert("tokenSymbol".into(), "UNIT".into());
properties.insert("tokenDecimals".into(), 12.into());
properties.insert("tokenDecimals".into(), 18.into());
properties.insert("ss58Format".into(), 42.into());

#[allow(deprecated)]
Expand Down Expand Up @@ -156,6 +157,8 @@ pub fn local_testnet_config() -> ChainSpec {
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
//prefunded EVM account
hex!["e1ad20aae239ccbb609aa537d515dc9d53c5936ea67d8acc9fe0618925279f7d"].into(),
],
get_account_id_from_seed::<sr25519::Public>("Alice"),
2000.into(),
Expand Down Expand Up @@ -216,7 +219,7 @@ fn testnet_genesis(
};
serde_json::json!({
"balances": {
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u64 << 60)).collect::<Vec<_>>(),
"balances": endowed_accounts.iter().cloned().map(|k| (k, 1u128 << 80)).collect::<Vec<_>>(),
},
"parachainInfo": {
"parachainId": id,
Expand Down
2 changes: 1 addition & 1 deletion node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ use std::net::SocketAddr;
use cumulus_client_service::storage_proof_size::HostFunctions as ReclaimHostFunctions;
use cumulus_primitives_core::ParaId;
use frame_benchmarking_cli::{BenchmarkCmd, SUBSTRATE_REFERENCE_HARDWARE};
use frontier_parachain_runtime::Block;
use log::info;
use parachain_template_runtime::Block;
use sc_cli::{
ChainSpec, CliConfiguration, DefaultConfigurationValues, ImportParams, KeystoreParams,
NetworkParams, Result, SharedParams, SubstrateCli,
Expand Down
2 changes: 1 addition & 1 deletion node/src/eth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use fc_mapping_sync::{kv::MappingSyncWorker, SyncStrategy};
use fc_rpc::{EthTask, OverrideHandle};
pub use fc_rpc_core::types::{FeeHistoryCache, FeeHistoryCacheLimit, FilterPool};
// Local
use parachain_template_runtime::opaque::Block;
use frontier_parachain_runtime::opaque::Block;

/// Frontier DB backend type.
pub type FrontierBackend = fc_db::Backend<Block>;
Expand Down
2 changes: 1 addition & 1 deletion node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use std::sync::Arc;

use parachain_template_runtime::{opaque::Block, AccountId, Balance, Nonce};
use frontier_parachain_runtime::{opaque::Block, AccountId, Balance, Nonce};

use sc_client_api::{
backend::{AuxStore, Backend, StorageProvider},
Expand Down
12 changes: 6 additions & 6 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::{path::Path, sync::Arc, time::Duration};

use cumulus_client_cli::CollatorOptions;
// Local Runtime Types
use parachain_template_runtime::{
use frontier_parachain_runtime::{
opaque::{Block, Hash},
RuntimeApi, TransactionConverter,
};
Expand Down Expand Up @@ -57,11 +57,11 @@ impl sc_executor::NativeExecutionDispatch for ParachainNativeExecutor {
);

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
parachain_template_runtime::api::dispatch(method, data)
frontier_parachain_runtime::api::dispatch(method, data)
}

fn native_version() -> sc_executor::NativeVersion {
parachain_template_runtime::native_version()
frontier_parachain_runtime::native_version()
}
}

Expand Down Expand Up @@ -231,7 +231,7 @@ async fn start_node_impl(
import_queue,
keystore_container,
transaction_pool,
other: (block_import, mut telemetry, telemetry_worker_handle, frontier_backend, _overrides),
other: (block_import, mut telemetry, telemetry_worker_handle, frontier_backend, overrides),
..
} = new_partial(&parachain_config, &eth_config)?;

Expand Down Expand Up @@ -307,7 +307,6 @@ async fn start_node_impl(

// for ethereum-compatibility rpc.
parachain_config.rpc_id_provider = Some(Box::new(fc_rpc::EthereumSubIdProvider));
let overrides = crate::rpc::overrides_handle(client.clone());
let eth_rpc_params = crate::rpc::EthDeps {
client: client.clone(),
pool: transaction_pool.clone(),
Expand Down Expand Up @@ -397,7 +396,8 @@ async fn start_node_impl(
fee_history_cache_limit,
sync_service.clone(),
pubsub_notification_sinks,
);
)
.await;

if let Some(hwbench) = hwbench {
sc_sysinfo::print_hwbench(&hwbench);
Expand Down
5 changes: 1 addition & 4 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = "parachain-template-runtime"
name = "frontier-parachain-runtime"
version = "0.1.0"
authors.workspace = true
description = "Parachain runtime template"
Expand Down Expand Up @@ -81,7 +81,6 @@ fp-self-contained = { workspace = true }

# Frontier FRAME
pallet-base-fee = { workspace = true }
pallet-dynamic-fee = { workspace = true }
pallet-ethereum = { workspace = true }
pallet-evm = { workspace = true }
pallet-evm-chain-id = { workspace = true }
Expand Down Expand Up @@ -147,7 +146,6 @@ std = [
"fp-self-contained/std",
# Frontier FRAME
"pallet-base-fee/std",
"pallet-dynamic-fee/std",
"pallet-ethereum/std",
"pallet-evm/std",
"pallet-evm-chain-id/std",
Expand Down Expand Up @@ -210,7 +208,6 @@ try-runtime = [
"pallet-evm-chain-id/try-runtime",
"pallet-ethereum/try-runtime",
"pallet-base-fee/try-runtime",
"pallet-dynamic-fee/try-runtime",
]

experimental = ["pallet-aura/experimental"]
57 changes: 33 additions & 24 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ use sp_std::{marker::PhantomData, prelude::*};
use sp_version::NativeVersion;
use sp_version::RuntimeVersion;

use cumulus_primitives_core::{relay_chain::MAX_POV_SIZE, AggregateMessageOrigin, ParaId};
use cumulus_primitives_core::{AggregateMessageOrigin, ParaId};
use frame_support::{
construct_runtime, derive_impl,
dispatch::DispatchClass,
Expand Down Expand Up @@ -70,7 +70,6 @@ use weights::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight};
use xcm::latest::prelude::{AssetId, BodyId};

// Frontier
use fp_evm::weight_per_gas;
use fp_rpc::TransactionStatus;
use pallet_ethereum::{
Call::transact, PostLogContent, Transaction as EthereumTransaction, TransactionAction,
Expand Down Expand Up @@ -132,7 +131,11 @@ pub type SignedExtra = (

/// Unchecked extrinsic type as expected by this runtime.
pub type UncheckedExtrinsic =
generic::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;
fp_self_contained::UncheckedExtrinsic<Address, RuntimeCall, Signature, SignedExtra>;

/// Extrinsic type that has already been checked.
pub type CheckedExtrinsic =
fp_self_contained::CheckedExtrinsic<AccountId, RuntimeCall, SignedExtra, H160>;

/// Executive: handles dispatch to the various modules.
pub type Executive = frame_executive::Executive<
Expand Down Expand Up @@ -200,8 +203,8 @@ impl_opaque_keys! {

#[sp_version::runtime_version]
pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("parachain-template-runtime"),
impl_name: create_runtime_str!("parachain-template-runtime"),
spec_name: create_runtime_str!("frontier-parachain-runtime"),
impl_name: create_runtime_str!("frontier-parachain-runtime"),
authoring_version: 1,
spec_version: 1,
impl_version: 0,
Expand All @@ -228,10 +231,10 @@ pub const HOURS: BlockNumber = MINUTES * 60;
pub const DAYS: BlockNumber = HOURS * 24;

// Unit = the base number of indivisible units for balances
pub const UNIT: Balance = 1_000_000_000_000;
pub const CENTIUNIT: Balance = 10_000_000_000;
pub const MILLIUNIT: Balance = 1_000_000_000;
pub const MICROUNIT: Balance = 1_000_000;
pub const MICROUNIT: Balance = 1_000_000_000_000;
pub const MILLIUNIT: Balance = 1_000 * MICROUNIT;
pub const CENTIUNIT: Balance = 10 * MILLIUNIT;
pub const UNIT: Balance = 100 * MILLIUNIT;

/// The existential deposit. Set to 1/10 of the Connected Relay Chain.
pub const EXISTENTIAL_DEPOSIT: Balance = MILLIUNIT;
Expand Down Expand Up @@ -359,16 +362,30 @@ impl<F: FindAuthor<u32>> FindAuthor<H160> for FindAuthorTruncated<F> {
}
}

const BLOCK_GAS_LIMIT: u64 = 75_000_000;
/// Current approximation of the gas/s consumption considering
/// EVM execution over compiled WASM (on 4.4Ghz CPU).
/// Given the 500ms Weight, from which 75% only are used for transactions,
AlexD10S marked this conversation as resolved.
Show resolved Hide resolved
/// the total EVM execution gas limit is: GAS_PER_SECOND * 0.500 * 0.75 ~= 15_000_000.
/// src: https://github.com/moonbeam-foundation/moonbeam/blob/master/runtime/moonbeam/src/lib.rs#L378
/// Note: this is a conservative estimate considering async backing is enabled.
pub const GAS_PER_SECOND: u64 = 40_000_000;
/// Approximate ratio of the amount of Weight per Gas.
/// u64 works for approximations because Weight is a very small unit compared to gas.
pub const WEIGHT_PER_GAS: u64 = WEIGHT_REF_TIME_PER_SECOND / GAS_PER_SECOND;

parameter_types! {
pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT);
pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE as u64);
pub BlockGasLimit: U256 = U256::from(NORMAL_DISPATCH_RATIO * MAXIMUM_BLOCK_WEIGHT.ref_time() / WEIGHT_PER_GAS);
/// The amount of gas per pov. A ratio of 4 if we convert ref_time to gas and we compare
/// it with the pov_size for a block. E.g.
/// ceil(
/// (max_extrinsic.ref_time() / max_extrinsic.proof_size()) / WEIGHT_REF_TIME_PER_GAS
/// )
/// https://github.com/moonbeam-foundation/moonbeam/blob/master/runtime/moonbeam/src/lib.rs#L414
pub GasLimitPovSizeRatio: u64 = 4;
pub PrecompilesValue: FrontierPrecompiles<Runtime> = FrontierPrecompiles::<_>::new();
pub WeightPerGas: Weight = Weight::from_parts(weight_per_gas(BLOCK_GAS_LIMIT, NORMAL_DISPATCH_RATIO, WEIGHT_MILLISECS_PER_BLOCK), 0);
pub WeightPerGas: Weight = Weight::from_parts(WEIGHT_PER_GAS, 0);
pub SuicideQuickClearLimit: u32 = 0;
}

impl pallet_evm::Config for Runtime {
type FeeCalculator = BaseFee;
type GasWeightMapping = pallet_evm::FixedGasWeightMapping<Self>;
Expand Down Expand Up @@ -403,13 +420,6 @@ impl pallet_ethereum::Config for Runtime {
type PostLogContent = PostBlockAndTxnHashes;
type ExtraDataLength = ConstU32<30>;
}
parameter_types! {
pub BoundDivision: U256 = U256::from(1024);
}

impl pallet_dynamic_fee::Config for Runtime {
type MinGasPriceBoundDivisor = BoundDivision;
}

parameter_types! {
pub DefaultBaseFeePerGas: U256 = U256::from(1_000_000_000);
Expand Down Expand Up @@ -659,8 +669,7 @@ construct_runtime!(
Ethereum: pallet_ethereum = 40,
EVM: pallet_evm = 41,
EVMChainId: pallet_evm_chain_id = 42,
DynamicFee: pallet_dynamic_fee = 43,
BaseFee: pallet_base_fee = 44,
BaseFee: pallet_base_fee = 43,
}
);

Expand Down Expand Up @@ -1017,7 +1026,7 @@ impl_runtime_apis! {
fn extrinsic_filter(
xts: Vec<<Block as BlockT>::Extrinsic>,
) -> Vec<EthereumTransaction> {
xts.into_iter().filter_map(|xt| match xt.function {
xts.into_iter().filter_map(|xt| match xt.0.function {
RuntimeCall::Ethereum(transact { transaction }) => Some(transaction),
_ => None
}).collect::<Vec<EthereumTransaction>>()
Expand Down
Loading