Skip to content

Commit

Permalink
compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
functor-flow committed Nov 25, 2024
1 parent 461d305 commit 9299f2b
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 31 deletions.
20 changes: 10 additions & 10 deletions node/src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -286,29 +291,24 @@ 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| {
let PartialComponents {
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)
})
}
Expand Down
66 changes: 62 additions & 4 deletions node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<C, P, A: ChainApi, CT, CIDP> {
/// The client instance to use.
pub client: Arc<C>,
Expand All @@ -34,12 +37,25 @@ pub struct FullDeps<C, P, A: ChainApi, CT, CIDP> {
/// Manual seal command sink
pub command_sink: Option<mpsc::Sender<EngineCommand<Hash>>>,
/// Ethereum-compatibility specific dependencies.
#[cfg(feature = "testnet")]
pub eth: EthDeps<Block, C, P, A, CT, CIDP>,
}

#[cfg(not(feature = "testnet"))]
/// Full client dependencies.
pub struct FullDeps<C, P> {
/// The client instance to use.
pub client: Arc<C>,
/// Transaction pool instance.
pub pool: Arc<P>,
/// Whether to deny unsafe calls
/// Manual seal command sink
pub command_sink: Option<mpsc::Sender<EngineCommand<Hash>>>,
}

#[cfg(feature = "testnet")]
pub struct DefaultEthConfig<C, BE>(std::marker::PhantomData<(C, BE)>);

#[cfg(feature = "testnet")]
impl<C, BE> fc_rpc::EthConfig<Block, C> for DefaultEthConfig<C, BE>
where
C: StorageProvider<Block, BE> + Sync + Send + 'static,
Expand All @@ -51,6 +67,7 @@ where
}

/// Instantiate all Full RPC extensions.
#[cfg(feature = "testnet")]
pub fn create_full<C, P, BE, A, CT, CIDP>(
deps: FullDeps<C, P, A, CT, CIDP>,
subscription_task_executor: SubscriptionTaskExecutor,
Expand Down Expand Up @@ -87,7 +104,6 @@ where
client,
pool,
command_sink,
#[cfg(feature = "testnet")]
eth,
} = deps;

Expand All @@ -104,7 +120,6 @@ where
}

// Ethereum compatibility RPCs
#[cfg(feature = "testnet")]
let io = create_eth::<_, _, _, _, _, _, _, DefaultEthConfig<C, BE>>(
io,
eth,
Expand All @@ -114,3 +129,46 @@ where

Ok(io)
}

#[cfg(not(feature = "testnet"))]
pub fn create_full<C, P, BE>(
deps: FullDeps<C, P>,
) -> Result<RpcModule<()>, Box<dyn std::error::Error + Send + Sync>>
where
C: CallApiAt<Block> + ProvideRuntimeApi<Block>,
C::Api: sp_block_builder::BlockBuilder<Block>,
C::Api: sp_consensus_aura::AuraApi<Block, AuraId>,
C::Api: substrate_frame_rpc_system::AccountNonceApi<Block, AccountId, Nonce>,
C::Api: pallet_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance>,
C: HeaderBackend<Block> + HeaderMetadata<Block, Error = BlockChainError> + 'static,
C: BlockchainEvents<Block> + AuxStore + UsageProvider<Block> + StorageProvider<Block, BE>,
C::Api: subspace_rpc::SubspaceRuntimeApi<Block>,
BE: Backend<Block> + 'static,
P: TransactionPool<Block = Block> + '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)
}
63 changes: 49 additions & 14 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -470,34 +477,47 @@ 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(),
));

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()
Expand All @@ -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::<InherentDataProviders, Box<dyn std::error::Error + Send + Sync>>((
slot,
timestamp,
#[cfg(feature = "testnet")]
dynamic_fee,
))
};

let command_sink = command_sink.clone();
Expand All @@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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::<AuraPair, _, _, _, _, _, _, _, _, _, _>(
Expand Down
20 changes: 17 additions & 3 deletions node/src/service/manual_seal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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();
Expand Down Expand Up @@ -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,
))
}
}
};
Expand Down

0 comments on commit 9299f2b

Please sign in to comment.