Skip to content

Commit

Permalink
flagging eth related functionality (#236)
Browse files Browse the repository at this point in the history
* wip: flagged eth

* wip: comment eth

* compiles

* fix: compile warnings

---------

Co-authored-by: devwckd <[email protected]>
  • Loading branch information
Supremesource and devwckd authored Nov 25, 2024
1 parent 31ce9dd commit 8e46c47
Show file tree
Hide file tree
Showing 8 changed files with 442 additions and 91 deletions.
1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
2 changes: 2 additions & 0 deletions node/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::path::PathBuf;

#[cfg(feature = "testnet")]
use crate::service::EthConfiguration;

/// Available Sealing methods.
Expand Down Expand Up @@ -31,6 +32,7 @@ pub struct Cli {
#[arg(long, value_enum, ignore_case = true)]
pub sealing: Option<Sealing>,

#[cfg(feature = "testnet")]
#[command(flatten)]
pub eth: EthConfiguration,
}
Expand Down
58 changes: 48 additions & 10 deletions node/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,23 @@
use futures::TryFutureExt;
// Substrate
use sc_cli::SubstrateCli;
use sc_service::{DatabaseSource, PartialComponents};
use sc_service::PartialComponents;

#[cfg(feature = "testnet")]
use sc_service::DatabaseSource;
// 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 @@ -85,7 +92,11 @@ pub fn run() -> sc_cli::Result<()> {
import_queue,
task_manager,
..
} = service::new_chain_ops(config, cli.eth)?;
} = service::new_chain_ops(
config,
#[cfg(feature = "testnet")]
cli.eth,
)?;

Ok((cmd.run(client, import_queue), task_manager))
})
Expand All @@ -98,7 +109,11 @@ pub fn run() -> sc_cli::Result<()> {
task_manager,
other: Other { config, .. },
..
} = service::new_chain_ops(config, cli.eth)?;
} = service::new_chain_ops(
config,
#[cfg(feature = "testnet")]
cli.eth,
)?;

Ok((cmd.run(client, config.database), task_manager))
})
Expand All @@ -111,7 +126,11 @@ pub fn run() -> sc_cli::Result<()> {
task_manager,
other: Other { config, .. },
..
} = service::new_chain_ops(config, cli.eth)?;
} = service::new_chain_ops(
config,
#[cfg(feature = "testnet")]
cli.eth,
)?;

Ok((cmd.run(client, config.chain_spec), task_manager))
})
Expand All @@ -124,7 +143,11 @@ pub fn run() -> sc_cli::Result<()> {
import_queue,
task_manager,
..
} = service::new_chain_ops(config, cli.eth)?;
} = service::new_chain_ops(
config,
#[cfg(feature = "testnet")]
cli.eth,
)?;

Ok((cmd.run(client, import_queue), task_manager))
})
Expand All @@ -133,7 +156,9 @@ 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 {
crate::eth::BackendType::KeyValue => {
let frontier_database_config = match config.database {
Expand All @@ -154,6 +179,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) {
Expand Down Expand Up @@ -184,7 +210,11 @@ pub fn run() -> sc_cli::Result<()> {
backend,
task_manager,
..
} = service::new_chain_ops(config, cli.eth)?;
} = service::new_chain_ops(
config,
#[cfg(feature = "testnet")]
cli.eth,
)?;

let aux_revert = Box::new(move |client, _, blocks| {
sc_consensus_grandpa::revert(client, blocks)?;
Expand Down Expand Up @@ -264,6 +294,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| {
Expand All @@ -280,15 +311,22 @@ pub fn run() -> sc_cli::Result<()> {
fc_db::Backend::KeyValue(kv) => kv,
_ => panic!("Only fc_db::Backend::KeyValue supported"),
};
#[cfg(feature = "testnet")]
cmd.run(client, frontier_backend)
})
}
_ => {
let runner = cli.create_runner(&cli.run)?;
runner.run_node_until_exit(|config| async move {
service::build_full(config, cli.eth, cli.sealing, cli.rsa_path)
.map_err(Into::into)
.await
service::build_full(
config,
#[cfg(feature = "testnet")]
cli.eth,
cli.sealing,
cli.rsa_path,
)
.map_err(Into::into)
.await
})
}
}
Expand Down
1 change: 1 addition & 0 deletions node/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ mod chain_spec;
mod cli;
mod client;
mod command;
#[cfg(feature = "testnet")]
mod eth;
mod rpc;
mod service;
Expand Down
67 changes: 66 additions & 1 deletion node/src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@ use sc_client_api::{
AuxStore, UsageProvider,
};
use sc_consensus_manual_seal::rpc::EngineCommand;
#[cfg(feature = "testnet")]
use sc_rpc::SubscriptionTaskExecutor;
use sc_service::TransactionPool;
#[cfg(feature = "testnet")]
use sc_transaction_pool::ChainApi;
use sp_api::{CallApiAt, ProvideRuntimeApi};
use sp_blockchain::{Error as BlockChainError, HeaderBackend, HeaderMetadata};
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
#[cfg(feature = "testnet")]
use sp_inherents::CreateInherentDataProviders;
#[cfg(feature = "testnet")]
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 @@ -37,8 +44,22 @@ pub struct FullDeps<C, P, A: ChainApi, CT, CIDP> {
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 @@ -50,6 +71,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 @@ -111,3 +133,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)
}
Loading

0 comments on commit 8e46c47

Please sign in to comment.