diff --git a/node/Cargo.toml b/node/Cargo.toml index 127046e6..8fafcbc7 100644 --- a/node/Cargo.toml +++ b/node/Cargo.toml @@ -105,5 +105,6 @@ runtime-benchmarks = [ "sc-service/runtime-benchmarks", "node-subspace-runtime/runtime-benchmarks", ] +testnet = ["node-subspace-runtime/testnet"] try-runtime = ["node-subspace-runtime/try-runtime"] testnet-faucet = ["node-subspace-runtime/testnet-faucet"] diff --git a/node/src/command.rs b/node/src/command.rs index 75561703..f87fc3b4 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -134,6 +134,7 @@ pub fn run() -> sc_cli::Result<()> { runner.sync_run(|config| { // Remove Frontier offchain db let db_config_dir = db_config_dir(&config); + #[cfg(feature = "testnet")] match cli.eth.frontier_backend_type { crate::eth::BackendType::KeyValue => { let frontier_database_config = match config.database { @@ -154,6 +155,7 @@ pub fn run() -> sc_cli::Result<()> { }; cmd.run(frontier_database_config)?; } + #[cfg(feature = "testnet")] crate::eth::BackendType::Sql => { let db_path = db_config_dir.join("sql"); match std::fs::remove_dir_all(&db_path) { diff --git a/node/src/main.rs b/node/src/main.rs index 6c1195ee..4fdaf61f 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -14,6 +14,7 @@ mod chain_spec; mod cli; mod client; mod command; +#[cfg(feature = "testnet")] mod eth; mod rpc; mod service; diff --git a/node/src/rpc/mod.rs b/node/src/rpc/mod.rs index cd067de7..19708cb9 100644 --- a/node/src/rpc/mod.rs +++ b/node/src/rpc/mod.rs @@ -102,6 +102,7 @@ where } // Ethereum compatibility RPCs + #[cfg(feature = "testnet")] let io = create_eth::<_, _, _, _, _, _, _, DefaultEthConfig>( io, eth, diff --git a/node/src/service.rs b/node/src/service.rs index 847db1e8..5cdb872e 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -19,13 +19,13 @@ use std::{ use crate::{ cli::Sealing, client::{Client, FullBackend}, - eth::{ - new_frontier_partial, spawn_frontier_tasks, BackendType, FrontierBackend, - FrontierPartialComponents, StorageOverride, StorageOverrideHandler, - }, }; -pub use crate::eth::{db_config_dir, EthConfiguration}; +#[cfg(feature = "testnet")] +pub use crate::eth::{ + db_config_dir, new_frontier_partial, spawn_frontier_tasks, BackendType, EthConfiguration, + FrontierBackend, FrontierPartialComponents, StorageOverride, StorageOverrideHandler, +}; mod decrypter; mod manual_seal; @@ -106,7 +106,9 @@ where telemetry.as_ref().map(|x| x.handle()), )?; + #[cfg(feature = "testnet")] let storage_override = Arc::new(StorageOverrideHandler::new(client.clone())); + #[cfg(feature = "testnet")] let frontier_backend = match eth_config.frontier_backend_type { BackendType::KeyValue => FrontierBackend::KeyValue(Arc::new(fc_db::kv::Backend::open( Arc::clone(&client), @@ -259,6 +261,7 @@ where mut other, } = new_partial(config, eth_config, build_import_queue)?; + #[cfg(feature = "testnet")] let FrontierPartialComponents { filter_pool, fee_history_cache, @@ -461,6 +464,7 @@ where telemetry: other.telemetry.as_mut(), })?; + #[cfg(feature = "testnet")] spawn_frontier_tasks( &task_manager, client.clone(), diff --git a/runtime/src/lib.rs b/runtime/src/lib.rs index 96823afe..023ee7f6 100644 --- a/runtime/src/lib.rs +++ b/runtime/src/lib.rs @@ -115,7 +115,9 @@ pub use sp_runtime::BuildStorage; pub use pallet_subspace; // Precompiles module (for EVM precompiles) +#[cfg(feature = "testnet")] mod precompiles; +#[cfg(feature = "testnet")] use precompiles::FrontierPrecompiles; use frame_system::RawOrigin; @@ -186,7 +188,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("node-subspace"), impl_name: create_runtime_str!("node-subspace"), authoring_version: 1, - spec_version: 511, + spec_version: 512, impl_version: 1, apis: RUNTIME_API_VERSIONS, transaction_version: 1, @@ -520,9 +522,12 @@ impl> FindAuthor for FindAuthorTruncated { } } +#[cfg(feature = "testnet")] const BLOCK_GAS_LIMIT: u64 = 75_000_000; +#[cfg(feature = "testnet")] const MAX_POV_SIZE: u64 = 5 * 1024 * 1024; +#[cfg(feature = "testnet")] parameter_types! { pub BlockGasLimit: U256 = U256::from(BLOCK_GAS_LIMIT); pub const GasLimitPovSizeRatio: u64 = BLOCK_GAS_LIMIT.saturating_div(MAX_POV_SIZE); @@ -531,6 +536,7 @@ parameter_types! { pub SuicideQuickClearLimit: u32 = 0; } +#[cfg(feature = "testnet")] impl pallet_evm::Config for Runtime { type FeeCalculator = BaseFee; type GasWeightMapping = pallet_evm::FixedGasWeightMapping; @@ -556,10 +562,12 @@ impl pallet_evm::Config for Runtime { type WeightInfo = pallet_evm::weights::SubstrateWeight; } +#[cfg(feature = "testnet")] parameter_types! { pub const PostBlockAndTxnHashes: PostLogContent = PostLogContent::BlockAndTxnHashes; } +#[cfg(feature = "testnet")] impl pallet_ethereum::Config for Runtime { type RuntimeEvent = RuntimeEvent; type StateRoot = pallet_ethereum::IntermediateStateRoot; @@ -567,19 +575,24 @@ impl pallet_ethereum::Config for Runtime { type ExtraDataLength = ConstU32<30>; } +#[cfg(feature = "testnet")] parameter_types! { pub BoundDivision: U256 = U256::from(1024); } +#[cfg(feature = "testnet")] impl pallet_dynamic_fee::Config for Runtime { type MinGasPriceBoundDivisor = BoundDivision; } +#[cfg(feature = "testnet")] parameter_types! { pub DefaultBaseFeePerGas: U256 = U256::from(1_000_000_000); pub DefaultElasticity: Permill = Permill::from_parts(125_000); } +#[cfg(feature = "testnet")] pub struct BaseFeeThreshold; +#[cfg(feature = "testnet")] impl pallet_base_fee::BaseFeeThreshold for BaseFeeThreshold { fn lower() -> Permill { Permill::zero() @@ -591,6 +604,8 @@ impl pallet_base_fee::BaseFeeThreshold for BaseFeeThreshold { Permill::from_parts(1_000_000) } } + +#[cfg(feature = "testnet")] impl pallet_base_fee::Config for Runtime { type RuntimeEvent = RuntimeEvent; type Threshold = BaseFeeThreshold; @@ -619,10 +634,14 @@ construct_runtime!( #[cfg(feature = "testnet-faucet")] FaucetModule: pallet_faucet, - // EVM Support + // EVM Support, for now only on testnet + #[cfg(feature = "testnet")] EVM: pallet_evm, + #[cfg(feature = "testnet")] Ethereum: pallet_ethereum, + #[cfg(feature = "testnet")] BaseFee: pallet_base_fee, + #[cfg(feature = "testnet")] DynamicFee: pallet_dynamic_fee, } ); @@ -636,6 +655,7 @@ impl Default for TransactionConverter { } } +#[cfg(feature = "testnet")] impl fp_rpc::ConvertTransaction<::Extrinsic> for TransactionConverter { fn convert_transaction( &self, @@ -719,9 +739,16 @@ pub type SignedExtra = ( ); // Unchecked extrinsic type as expected by this runtime. +#[cfg(feature = "testnet")] pub type UncheckedExtrinsic = fp_self_contained::UncheckedExtrinsic; + +#[cfg(not(feature = "testnet"))] +pub type UncheckedExtrinsic = + generic::UncheckedExtrinsic; + /// Extrinsic type that has already been checked. +#[cfg(feature = "testnet")] pub type CheckedExtrinsic = fp_self_contained::CheckedExtrinsic; // The payload being signed in transactions. @@ -736,6 +763,7 @@ pub type Executive = frame_executive::Executive< Migrations, >; +#[cfg(feature = "testnet")] impl fp_self_contained::SelfContainedCall for RuntimeCall { type SignedInfo = H160; @@ -1007,6 +1035,7 @@ impl_runtime_apis! { } + #[cfg(feature = "testnet")] impl fp_rpc::EthereumRuntimeRPCApi for Runtime { fn chain_id() -> u64 { ::ChainId::get() @@ -1198,6 +1227,7 @@ impl_runtime_apis! { } } + #[cfg(feature = "testnet")] impl fp_rpc::ConvertTransactionRuntimeApi for Runtime { fn convert_transaction(transaction: EthereumTransaction) -> ::Extrinsic { UncheckedExtrinsic::new_unsigned(