From 9299f2be2a670c583d56b18ffb4b92362718e361 Mon Sep 17 00:00:00 2001 From: Honza <115138297+Supremesource@users.noreply.github.com> Date: Mon, 25 Nov 2024 13:08:38 -0300 Subject: [PATCH] compiles --- node/src/command.rs | 20 +++++----- node/src/rpc/mod.rs | 66 +++++++++++++++++++++++++++++++-- node/src/service.rs | 63 ++++++++++++++++++++++++------- node/src/service/manual_seal.rs | 20 ++++++++-- 4 files changed, 138 insertions(+), 31 deletions(-) diff --git a/node/src/command.rs b/node/src/command.rs index b871c5825..92f87e168 100644 --- a/node/src/command.rs +++ b/node/src/command.rs @@ -3,14 +3,18 @@ use futures::TryFutureExt; use sc_cli::SubstrateCli; use sc_service::{DatabaseSource, PartialComponents}; // Frontier +#[cfg(feature = "testnet")] use fc_db::kv::frontier_database_dir; use crate::{ chain_spec, cli::{Cli, Subcommand}, - service::{self, db_config_dir, Other}, + service::{self, Other}, }; +#[cfg(feature = "testnet")] +use crate::service::db_config_dir; + #[cfg(feature = "runtime-benchmarks")] use crate::chain_spec::get_account_id_from_seed; @@ -149,6 +153,7 @@ pub fn run() -> sc_cli::Result<()> { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { // Remove Frontier offchain db + #[cfg(feature = "testnet")] let db_config_dir = db_config_dir(&config); #[cfg(feature = "testnet")] match cli.eth.frontier_backend_type { @@ -286,6 +291,7 @@ pub fn run() -> sc_cli::Result<()> { Some(Subcommand::Benchmark) => Err("Benchmarking wasn't enabled when building the node. \ You can enable it with `--features runtime-benchmarks`." .into()), + #[cfg(feature = "testnet")] Some(Subcommand::FrontierDb(cmd)) => { let runner = cli.create_runner(cmd)?; runner.sync_run(|config| { @@ -293,22 +299,16 @@ pub fn run() -> sc_cli::Result<()> { client, other: Other { - #[cfg(feature = "testnet")] - frontier_backend, - .. + frontier_backend, .. }, .. - } = service::new_chain_ops( - config, - #[cfg(feature = "testnet")] - cli.eth, - )?; + } = service::new_chain_ops(config, cli.eth)?; - #[cfg(feature = "testnet")] let frontier_backend = match frontier_backend { fc_db::Backend::KeyValue(kv) => kv, _ => panic!("Only fc_db::Backend::KeyValue supported"), }; + #[cfg(feature = "testnet")] cmd.run(client, frontier_backend) }) } diff --git a/node/src/rpc/mod.rs b/node/src/rpc/mod.rs index 4d91c9d44..73fb8cf10 100644 --- a/node/src/rpc/mod.rs +++ b/node/src/rpc/mod.rs @@ -22,10 +22,13 @@ use sp_runtime::traits::Block as BlockT; // Runtime use node_subspace_runtime::{opaque::Block, AccountId, Balance, Hash, Nonce}; +#[cfg(feature = "testnet")] mod eth; +#[cfg(feature = "testnet")] pub use self::eth::{create_eth, EthDeps}; -/// Full client dependencies. +// /// Full client dependencies. +#[cfg(feature = "testnet")] pub struct FullDeps { /// The client instance to use. pub client: Arc, @@ -34,12 +37,25 @@ pub struct FullDeps { /// Manual seal command sink pub command_sink: Option>>, /// Ethereum-compatibility specific dependencies. - #[cfg(feature = "testnet")] pub eth: EthDeps, } +#[cfg(not(feature = "testnet"))] +/// Full client dependencies. +pub struct FullDeps { + /// The client instance to use. + pub client: Arc, + /// Transaction pool instance. + pub pool: Arc

, + /// Whether to deny unsafe calls + /// Manual seal command sink + pub command_sink: Option>>, +} + +#[cfg(feature = "testnet")] pub struct DefaultEthConfig(std::marker::PhantomData<(C, BE)>); +#[cfg(feature = "testnet")] impl fc_rpc::EthConfig for DefaultEthConfig where C: StorageProvider + Sync + Send + 'static, @@ -51,6 +67,7 @@ where } /// Instantiate all Full RPC extensions. +#[cfg(feature = "testnet")] pub fn create_full( deps: FullDeps, subscription_task_executor: SubscriptionTaskExecutor, @@ -87,7 +104,6 @@ where client, pool, command_sink, - #[cfg(feature = "testnet")] eth, } = deps; @@ -104,7 +120,6 @@ where } // Ethereum compatibility RPCs - #[cfg(feature = "testnet")] let io = create_eth::<_, _, _, _, _, _, _, DefaultEthConfig>( io, eth, @@ -114,3 +129,46 @@ where Ok(io) } + +#[cfg(not(feature = "testnet"))] +pub fn create_full( + deps: FullDeps, +) -> Result, Box> +where + C: CallApiAt + ProvideRuntimeApi, + C::Api: sp_block_builder::BlockBuilder, + C::Api: sp_consensus_aura::AuraApi, + C::Api: substrate_frame_rpc_system::AccountNonceApi, + C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi, + C: HeaderBackend + HeaderMetadata + 'static, + C: BlockchainEvents + AuxStore + UsageProvider + StorageProvider, + C::Api: subspace_rpc::SubspaceRuntimeApi, + BE: Backend + 'static, + P: TransactionPool + 'static, +{ + use pallet_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApiServer}; + use sc_consensus_manual_seal::rpc::{ManualSeal, ManualSealApiServer}; + use subspace_rpc::{SubspaceApiServer, SubspacePallet}; + use substrate_frame_rpc_system::{System, SystemApiServer}; + + let mut io = RpcModule::new(()); + let FullDeps { + client, + pool, + command_sink, + } = deps; + + io.merge(System::new(client.clone(), pool).into_rpc())?; + io.merge(TransactionPayment::new(client.clone()).into_rpc())?; + io.merge(SubspacePallet::new(client).into_rpc())?; + + if let Some(command_sink) = command_sink { + io.merge( + // We provide the rpc handler with the sending end of the channel to allow the rpc + // send EngineCommands to the background block authorship task. + ManualSeal::new(command_sink).into_rpc(), + )?; + } + + Ok(io) +} diff --git a/node/src/service.rs b/node/src/service.rs index f97bb2ecf..0aac66cf9 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -16,11 +16,16 @@ use std::{ time::Duration, }; +use sp_core::H256; + use crate::{ cli::Sealing, client::{Client, FullBackend}, }; +#[cfg(not(feature = "testnet"))] +use sp_runtime::traits::NumberFor; + #[cfg(feature = "testnet")] pub use crate::eth::{ db_config_dir, new_frontier_partial, spawn_frontier_tasks, BackendType, EthConfiguration, @@ -432,9 +437,11 @@ where network_provider: Arc::new(network.clone()), enable_http_requests: true, custom_extensions: move |_| { - vec![Box::new(ow_extensions::OffworkerExt::new( - decrypter::Decrypter::new(rsa_key.clone()), - ))] + vec![ + Box::new(ow_extensions::OffworkerExt::new(decrypter::Decrypter::new( + rsa_key.clone(), + ))) as Box<_>, + ] }, }) .run(client.clone(), task_manager.spawn_handle()) @@ -470,26 +477,25 @@ where let is_authority = role.is_authority(); #[cfg(feature = "testnet")] - #[cfg(feature = "testnet")] let enable_dev_signer = other.eth_config.enable_dev_signer; #[cfg(feature = "testnet")] let max_past_logs = other.eth_config.max_past_logs; + #[cfg(feature = "testnet")] let execute_gas_limit_multiplier = other.eth_config.execute_gas_limit_multiplier; #[cfg(feature = "testnet")] let filter_pool = filter_pool.clone(); + #[cfg(feature = "testnet")] let frontier_backend = frontier_backend.clone(); let pubsub_notification_sinks = pubsub_notification_sinks.clone(); #[cfg(feature = "testnet")] let storage_override = other.storage_override.clone(); #[cfg(feature = "testnet")] let fee_history_cache = fee_history_cache.clone(); + #[cfg(feature = "testnet")] let block_data_cache = Arc::new(fc_rpc::EthBlockDataCacheTask::new( task_manager.spawn_handle(), - #[cfg(feature = "testnet")] storage_override.clone(), - #[cfg(feature = "testnet")] other.eth_config.eth_log_block_cache, - #[cfg(feature = "testnet")] other.eth_config.eth_statuses_cache, prometheus_registry.clone(), )); @@ -497,7 +503,21 @@ where let slot_duration = sc_consensus_aura::slot_duration(&*client)?; #[cfg(feature = "testnet")] let target_gas_price = other.eth_config.target_gas_price; - let pending_create_inherent_data_providers = move |_, ()| async move { + + #[cfg(not(feature = "testnet"))] + type InherentDataProviders = ( + sp_consensus_aura::inherents::InherentDataProvider, + sp_timestamp::InherentDataProvider, + ); + + #[cfg(feature = "testnet")] + type InherentDataProviders = ( + sp_consensus_aura::inherents::InherentDataProvider, + sp_timestamp::InherentDataProvider, + fp_dynamic_fee::InherentDataProvider, + ); + + let pending_create_inherent_data_providers = move |_: H256, _: ()| async move { let current = sp_timestamp::InherentDataProvider::from_system_time(); let next_slot = current .timestamp() @@ -506,11 +526,18 @@ where .expect("Overflow when calculating next slot"); let timestamp = sp_timestamp::InherentDataProvider::new(next_slot.into()); let slot = sp_consensus_aura::inherents::InherentDataProvider::from_timestamp_and_slot_duration( - *timestamp, - slot_duration, - ); + *timestamp, + slot_duration, + ); + #[cfg(feature = "testnet")] let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price)); - Ok((slot, timestamp, dynamic_fee)) + + Ok::>(( + slot, + timestamp, + #[cfg(feature = "testnet")] + dynamic_fee, + )) }; let command_sink = command_sink.clone(); @@ -534,7 +561,7 @@ where filter_pool: filter_pool.clone(), max_past_logs, fee_history_cache: fee_history_cache.clone(), - vvfee_history_cache_limit, + fee_history_cache_limit, execute_gas_limit_multiplier, forced_parent_hashes: None, pending_create_inherent_data_providers, @@ -554,7 +581,9 @@ where crate::rpc::create_full( deps, + #[cfg(feature = "testnet")] subscription_task_executor, + #[cfg(feature = "testnet")] pubsub_notification_sinks.clone(), ) .map_err(Into::into) @@ -643,8 +672,14 @@ where *timestamp, slot_duration, ); + #[cfg(feature = "testnet")] let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price)); - Ok((slot, timestamp, dynamic_fee)) + Ok(( + slot, + timestamp, + #[cfg(feature = "testnet")] + dynamic_fee, + )) }; let aura = sc_consensus_aura::start_aura::( diff --git a/node/src/service/manual_seal.rs b/node/src/service/manual_seal.rs index 8c6c08b74..342d64fe5 100644 --- a/node/src/service/manual_seal.rs +++ b/node/src/service/manual_seal.rs @@ -13,7 +13,10 @@ use sp_core::{traits::SpawnEssentialNamed, U256}; use crate::{cli::Sealing, client::Client}; -use super::{BoxBlockImport, EthConfiguration, FullPool, FullSelectChain}; +use super::{BoxBlockImport, FullPool, FullSelectChain}; + +#[cfg(feature = "testnet")] +use super::EthConfiguration; pub struct ManualSealComponents { pub sealing: Sealing, @@ -34,8 +37,13 @@ pub fn run_manual_seal_authorship(components: ManualSealComponents) -> Result<() let target_gas_price = components.eth_config.target_gas_price; let create_inherent_data_providers = move |_, ()| async move { let timestamp = MockTimestampInherentDataProvider; + #[cfg(feature = "testnet")] let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price)); - Ok((timestamp, dynamic_fee)) + Ok(( + timestamp, + #[cfg(feature = "testnet")] + dynamic_fee, + )) }; let spawn_handle = components.spawn_handle.clone(); @@ -112,9 +120,15 @@ fn localnet_seal( .map_err(|err| format!("{:?}", err))?; let aura = sp_consensus_aura::inherents::InherentDataProvider::new(timestamp.slot()); + #[cfg(feature = "testnet")] let dynamic_fee = fp_dynamic_fee::InherentDataProvider(U256::from(target_gas_price)); - Ok((timestamp, aura, dynamic_fee)) + Ok(( + timestamp, + aura, + #[cfg(feature = "testnet")] + dynamic_fee, + )) } } };