mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 16:57:58 +00:00
Removal of light client from substrate (#9684)
* Removal of light client from substrate * add missing import * These tests relate to there being light and non light clients. * removing lightnodes from test * cargo fmt * not needed * LightDataChecker not needed any longer * cargo fmt * Update client/service/test/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * Update client/service/test/src/lib.rs Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com> * cargo fmt Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
@@ -418,7 +418,7 @@ pub fn local_testnet_config() -> ChainSpec {
|
||||
#[cfg(test)]
|
||||
pub(crate) mod tests {
|
||||
use super::*;
|
||||
use crate::service::{new_full_base, new_light_base, NewFullBase};
|
||||
use crate::service::{new_full_base, NewFullBase};
|
||||
use sc_service_test;
|
||||
use sp_runtime::BuildStorage;
|
||||
|
||||
@@ -466,28 +466,16 @@ pub(crate) mod tests {
|
||||
fn test_connectivity() {
|
||||
sp_tracing::try_init_simple();
|
||||
|
||||
sc_service_test::connectivity(
|
||||
integration_test_config_with_two_authorities(),
|
||||
|config| {
|
||||
let NewFullBase { task_manager, client, network, transaction_pool, .. } =
|
||||
new_full_base(config, |_, _| ())?;
|
||||
Ok(sc_service_test::TestNetComponents::new(
|
||||
task_manager,
|
||||
client,
|
||||
network,
|
||||
transaction_pool,
|
||||
))
|
||||
},
|
||||
|config| {
|
||||
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
|
||||
Ok(sc_service_test::TestNetComponents::new(
|
||||
keep_alive,
|
||||
client,
|
||||
network,
|
||||
transaction_pool,
|
||||
))
|
||||
},
|
||||
);
|
||||
sc_service_test::connectivity(integration_test_config_with_two_authorities(), |config| {
|
||||
let NewFullBase { task_manager, client, network, transaction_pool, .. } =
|
||||
new_full_base(config, |_, _| ())?;
|
||||
Ok(sc_service_test::TestNetComponents::new(
|
||||
task_manager,
|
||||
client,
|
||||
network,
|
||||
transaction_pool,
|
||||
))
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
use crate::{chain_spec, service, service::new_partial, Cli, Subcommand};
|
||||
use node_executor::ExecutorDispatch;
|
||||
use node_runtime::{Block, RuntimeApi};
|
||||
use sc_cli::{ChainSpec, Result, Role, RuntimeVersion, SubstrateCli};
|
||||
use sc_cli::{ChainSpec, Result, RuntimeVersion, SubstrateCli};
|
||||
use sc_service::PartialComponents;
|
||||
|
||||
impl SubstrateCli for Cli {
|
||||
@@ -77,11 +77,7 @@ pub fn run() -> Result<()> {
|
||||
None => {
|
||||
let runner = cli.create_runner(&cli.run)?;
|
||||
runner.run_node_until_exit(|config| async move {
|
||||
match config.role {
|
||||
Role::Light => service::new_light(config),
|
||||
_ => service::new_full(config),
|
||||
}
|
||||
.map_err(sc_cli::Error::Service)
|
||||
service::new_full(config).map_err(sc_cli::Error::Service)
|
||||
})
|
||||
},
|
||||
Some(Subcommand::Inspect(cmd)) => {
|
||||
|
||||
@@ -26,11 +26,11 @@ use futures::prelude::*;
|
||||
use node_executor::ExecutorDispatch;
|
||||
use node_primitives::Block;
|
||||
use node_runtime::RuntimeApi;
|
||||
use sc_client_api::{BlockBackend, ExecutorProvider, RemoteBackend};
|
||||
use sc_client_api::{BlockBackend, ExecutorProvider};
|
||||
use sc_consensus_babe::{self, SlotProportion};
|
||||
use sc_executor::NativeElseWasmExecutor;
|
||||
use sc_network::{Event, NetworkService};
|
||||
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
|
||||
use sc_service::{config::Configuration, error::Error as ServiceError, TaskManager};
|
||||
use sc_telemetry::{Telemetry, TelemetryWorker};
|
||||
use sp_api::ProvideRuntimeApi;
|
||||
use sp_core::crypto::Pair;
|
||||
@@ -44,8 +44,7 @@ type FullBackend = sc_service::TFullBackend<Block>;
|
||||
type FullSelectChain = sc_consensus::LongestChain<FullBackend, Block>;
|
||||
type FullGrandpaBlockImport =
|
||||
grandpa::GrandpaBlockImport<FullBackend, Block, FullClient, FullSelectChain>;
|
||||
type LightClient =
|
||||
sc_service::TLightClient<Block, RuntimeApi, NativeElseWasmExecutor<ExecutorDispatch>>;
|
||||
|
||||
/// The transaction pool type defintion.
|
||||
pub type TransactionPool = sc_transaction_pool::FullPool<Block, FullClient>;
|
||||
|
||||
@@ -516,186 +515,9 @@ pub fn new_full(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
new_full_base(config, |_, _| ()).map(|NewFullBase { task_manager, .. }| task_manager)
|
||||
}
|
||||
|
||||
/// Creates a light service from the configuration.
|
||||
pub fn new_light_base(
|
||||
mut config: Configuration,
|
||||
) -> Result<
|
||||
(
|
||||
TaskManager,
|
||||
RpcHandlers,
|
||||
Arc<LightClient>,
|
||||
Arc<NetworkService<Block, <Block as BlockT>::Hash>>,
|
||||
Arc<
|
||||
sc_transaction_pool::LightPool<Block, LightClient, sc_network::config::OnDemand<Block>>,
|
||||
>,
|
||||
),
|
||||
ServiceError,
|
||||
> {
|
||||
let telemetry = config
|
||||
.telemetry_endpoints
|
||||
.clone()
|
||||
.filter(|x| !x.is_empty())
|
||||
.map(|endpoints| -> Result<_, sc_telemetry::Error> {
|
||||
let worker = TelemetryWorker::new(16)?;
|
||||
let telemetry = worker.handle().new_telemetry(endpoints);
|
||||
Ok((worker, telemetry))
|
||||
})
|
||||
.transpose()?;
|
||||
|
||||
let executor = NativeElseWasmExecutor::<ExecutorDispatch>::new(
|
||||
config.wasm_method,
|
||||
config.default_heap_pages,
|
||||
config.max_runtime_instances,
|
||||
);
|
||||
|
||||
let (client, backend, keystore_container, mut task_manager, on_demand) =
|
||||
sc_service::new_light_parts::<Block, RuntimeApi, _>(
|
||||
&config,
|
||||
telemetry.as_ref().map(|(_, telemetry)| telemetry.handle()),
|
||||
executor,
|
||||
)?;
|
||||
|
||||
let mut telemetry = telemetry.map(|(worker, telemetry)| {
|
||||
task_manager.spawn_handle().spawn("telemetry", worker.run());
|
||||
telemetry
|
||||
});
|
||||
|
||||
config.network.extra_sets.push(grandpa::grandpa_peers_set_config());
|
||||
|
||||
let select_chain = sc_consensus::LongestChain::new(backend.clone());
|
||||
|
||||
let transaction_pool = Arc::new(sc_transaction_pool::BasicPool::new_light(
|
||||
config.transaction_pool.clone(),
|
||||
config.prometheus_registry(),
|
||||
task_manager.spawn_essential_handle(),
|
||||
client.clone(),
|
||||
on_demand.clone(),
|
||||
));
|
||||
|
||||
let (grandpa_block_import, grandpa_link) = grandpa::block_import(
|
||||
client.clone(),
|
||||
&(client.clone() as Arc<_>),
|
||||
select_chain.clone(),
|
||||
telemetry.as_ref().map(|x| x.handle()),
|
||||
)?;
|
||||
let justification_import = grandpa_block_import.clone();
|
||||
|
||||
let (babe_block_import, babe_link) = sc_consensus_babe::block_import(
|
||||
sc_consensus_babe::Config::get_or_compute(&*client)?,
|
||||
grandpa_block_import,
|
||||
client.clone(),
|
||||
)?;
|
||||
|
||||
let slot_duration = babe_link.config().slot_duration();
|
||||
let import_queue = sc_consensus_babe::import_queue(
|
||||
babe_link,
|
||||
babe_block_import,
|
||||
Some(Box::new(justification_import)),
|
||||
client.clone(),
|
||||
select_chain,
|
||||
move |_, ()| async move {
|
||||
let timestamp = sp_timestamp::InherentDataProvider::from_system_time();
|
||||
|
||||
let slot =
|
||||
sp_consensus_babe::inherents::InherentDataProvider::from_timestamp_and_duration(
|
||||
*timestamp,
|
||||
slot_duration,
|
||||
);
|
||||
|
||||
let uncles =
|
||||
sp_authorship::InherentDataProvider::<<Block as BlockT>::Header>::check_inherents();
|
||||
|
||||
Ok((timestamp, slot, uncles))
|
||||
},
|
||||
&task_manager.spawn_essential_handle(),
|
||||
config.prometheus_registry(),
|
||||
sp_consensus::NeverCanAuthor,
|
||||
telemetry.as_ref().map(|x| x.handle()),
|
||||
)?;
|
||||
|
||||
let warp_sync = Arc::new(grandpa::warp_proof::NetworkProvider::new(
|
||||
backend.clone(),
|
||||
grandpa_link.shared_authority_set().clone(),
|
||||
Vec::default(),
|
||||
));
|
||||
|
||||
let (network, system_rpc_tx, network_starter) =
|
||||
sc_service::build_network(sc_service::BuildNetworkParams {
|
||||
config: &config,
|
||||
client: client.clone(),
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
spawn_handle: task_manager.spawn_handle(),
|
||||
import_queue,
|
||||
on_demand: Some(on_demand.clone()),
|
||||
block_announce_validator_builder: None,
|
||||
warp_sync: Some(warp_sync),
|
||||
})?;
|
||||
|
||||
let enable_grandpa = !config.disable_grandpa;
|
||||
if enable_grandpa {
|
||||
let name = config.network.node_name.clone();
|
||||
|
||||
let config = grandpa::Config {
|
||||
gossip_duration: std::time::Duration::from_millis(333),
|
||||
justification_period: 512,
|
||||
name: Some(name),
|
||||
observer_enabled: false,
|
||||
keystore: None,
|
||||
local_role: config.role.clone(),
|
||||
telemetry: telemetry.as_ref().map(|x| x.handle()),
|
||||
};
|
||||
|
||||
task_manager.spawn_handle().spawn_blocking(
|
||||
"grandpa-observer",
|
||||
grandpa::run_grandpa_observer(config, grandpa_link, network.clone())?,
|
||||
);
|
||||
}
|
||||
|
||||
if config.offchain_worker.enabled {
|
||||
sc_service::build_offchain_workers(
|
||||
&config,
|
||||
task_manager.spawn_handle(),
|
||||
client.clone(),
|
||||
network.clone(),
|
||||
);
|
||||
}
|
||||
|
||||
let light_deps = node_rpc::LightDeps {
|
||||
remote_blockchain: backend.remote_blockchain(),
|
||||
fetcher: on_demand.clone(),
|
||||
client: client.clone(),
|
||||
pool: transaction_pool.clone(),
|
||||
};
|
||||
|
||||
let rpc_extensions = node_rpc::create_light(light_deps);
|
||||
|
||||
let rpc_handlers = sc_service::spawn_tasks(sc_service::SpawnTasksParams {
|
||||
on_demand: Some(on_demand),
|
||||
remote_blockchain: Some(backend.remote_blockchain()),
|
||||
rpc_extensions_builder: Box::new(sc_service::NoopRpcExtensionBuilder(rpc_extensions)),
|
||||
client: client.clone(),
|
||||
transaction_pool: transaction_pool.clone(),
|
||||
keystore: keystore_container.sync_keystore(),
|
||||
config,
|
||||
backend,
|
||||
system_rpc_tx,
|
||||
network: network.clone(),
|
||||
task_manager: &mut task_manager,
|
||||
telemetry: telemetry.as_mut(),
|
||||
})?;
|
||||
|
||||
network_starter.start_network();
|
||||
Ok((task_manager, rpc_handlers, client, network, transaction_pool))
|
||||
}
|
||||
|
||||
/// Builds a new service for a light client.
|
||||
pub fn new_light(config: Configuration) -> Result<TaskManager, ServiceError> {
|
||||
new_light_base(config).map(|(task_manager, _, _, _, _)| task_manager)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::service::{new_full_base, new_light_base, NewFullBase};
|
||||
use crate::service::{new_full_base, NewFullBase};
|
||||
use codec::Encode;
|
||||
use node_primitives::{Block, DigestItem, Signature};
|
||||
use node_runtime::{
|
||||
@@ -771,15 +593,6 @@ mod tests {
|
||||
);
|
||||
Ok((node, setup_handles.unwrap()))
|
||||
},
|
||||
|config| {
|
||||
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
|
||||
Ok(sc_service_test::TestNetComponents::new(
|
||||
keep_alive,
|
||||
client,
|
||||
network,
|
||||
transaction_pool,
|
||||
))
|
||||
},
|
||||
|service, &mut (ref mut block_import, ref babe_link)| {
|
||||
let parent_id = BlockId::number(service.client().chain_info().best_number);
|
||||
let parent_header = service.client().header(&parent_id).unwrap().unwrap();
|
||||
@@ -946,15 +759,6 @@ mod tests {
|
||||
transaction_pool,
|
||||
))
|
||||
},
|
||||
|config| {
|
||||
let (keep_alive, _, client, network, transaction_pool) = new_light_base(config)?;
|
||||
Ok(sc_service_test::TestNetComponents::new(
|
||||
keep_alive,
|
||||
client,
|
||||
network,
|
||||
transaction_pool,
|
||||
))
|
||||
},
|
||||
vec!["//Alice".into(), "//Bob".into()],
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,116 +0,0 @@
|
||||
// This file is part of Substrate.
|
||||
|
||||
// Copyright (C) 2020-2021 Parity Technologies (UK) Ltd.
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later WITH Classpath-exception-2.0
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use sc_client_db::{
|
||||
light::LightStorage, DatabaseSettings, DatabaseSource, KeepBlocks, PruningMode,
|
||||
TransactionStorageMode,
|
||||
};
|
||||
use sp_runtime::testing::{Block as RawBlock, ExtrinsicWrapper};
|
||||
use tempfile::tempdir;
|
||||
|
||||
pub mod common;
|
||||
|
||||
#[tokio::test]
|
||||
#[cfg(unix)]
|
||||
async fn database_role_subdir_migration() {
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
let base_path = tempdir().expect("could not create a temp dir");
|
||||
let path = base_path.path().join("chains/dev/db");
|
||||
// create a dummy database dir
|
||||
{
|
||||
let _old_db = LightStorage::<Block>::new(DatabaseSettings {
|
||||
state_cache_size: 0,
|
||||
state_cache_child_ratio: None,
|
||||
state_pruning: PruningMode::ArchiveAll,
|
||||
source: DatabaseSource::RocksDb { path: path.to_path_buf(), cache_size: 128 },
|
||||
keep_blocks: KeepBlocks::All,
|
||||
transaction_storage: TransactionStorageMode::BlockBody,
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
assert!(path.join("db_version").exists());
|
||||
assert!(!path.join("light").exists());
|
||||
|
||||
// start a light client
|
||||
common::run_node_for_a_while(
|
||||
base_path.path(),
|
||||
&[
|
||||
"--dev",
|
||||
"--light",
|
||||
"--port",
|
||||
"30335",
|
||||
"--rpc-port",
|
||||
"44444",
|
||||
"--ws-port",
|
||||
"44445",
|
||||
"--no-prometheus",
|
||||
],
|
||||
)
|
||||
.await;
|
||||
|
||||
// check if the database dir had been migrated
|
||||
assert!(!path.join("db_version").exists());
|
||||
assert!(path.join("light/db_version").exists());
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(unix)]
|
||||
fn database_role_subdir_migration_fail_on_different_role() {
|
||||
type Block = RawBlock<ExtrinsicWrapper<u64>>;
|
||||
|
||||
let base_path = tempdir().expect("could not create a temp dir");
|
||||
let path = base_path.path().join("chains/dev/db");
|
||||
|
||||
// create a database with the old layout
|
||||
{
|
||||
let _old_db = LightStorage::<Block>::new(DatabaseSettings {
|
||||
state_cache_size: 0,
|
||||
state_cache_child_ratio: None,
|
||||
state_pruning: PruningMode::ArchiveAll,
|
||||
source: DatabaseSource::RocksDb { path: path.to_path_buf(), cache_size: 128 },
|
||||
keep_blocks: KeepBlocks::All,
|
||||
transaction_storage: TransactionStorageMode::BlockBody,
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
assert!(path.join("db_version").exists());
|
||||
assert!(!path.join("light/db_version").exists());
|
||||
|
||||
// start a client with a different role (full), it should fail and not change any files on disk
|
||||
common::run_node_assert_fail(
|
||||
&base_path.path(),
|
||||
&[
|
||||
"--dev",
|
||||
"--port",
|
||||
"30334",
|
||||
"--rpc-port",
|
||||
"44446",
|
||||
"--ws-port",
|
||||
"44447",
|
||||
"--no-prometheus",
|
||||
],
|
||||
);
|
||||
|
||||
// check if the files are unchanged
|
||||
assert!(path.join("db_version").exists());
|
||||
assert!(!path.join("light/db_version").exists());
|
||||
assert!(!path.join("full/db_version").exists());
|
||||
}
|
||||
Reference in New Issue
Block a user