Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
9fda259
Move Service::new to a macro
tomaka Aug 8, 2019
ec9c66d
Move function calls to macros
tomaka Aug 8, 2019
0b28c31
Extract offchain_workers and start_rpc in separate function
tomaka Aug 8, 2019
7600276
Introduce an AbstractService trait
tomaka Aug 8, 2019
4af1fc7
Introduce NewService as an implementation detail of Service
tomaka Aug 9, 2019
8ef6cc3
Implement traits on NewService instead
tomaka Aug 9, 2019
d66692d
Move components creation back to macro invocation
tomaka Aug 9, 2019
e169901
Add a $block parameter to new_impl
tomaka Aug 9, 2019
9d667d8
Introduce the ServiceBuilder struct
tomaka Aug 9, 2019
4fc8aac
Macro-ify import_blocks, export_blocks and revert_chain
tomaka Aug 9, 2019
8467efb
Add export_blocks, import_blocks and revert_chain methods on ServiceB…
tomaka Aug 9, 2019
be2a712
Add run_with_builder
tomaka Aug 12, 2019
7eee475
Transition node and node-template to ServiceBuilder
tomaka Aug 12, 2019
8e623c7
Transition transaction-factory to the new service factory
tomaka Aug 12, 2019
3d8f9cc
Remove old service factory
tomaka Aug 12, 2019
f290efe
Adjust the AbstractService trait to be more usable
tomaka Aug 13, 2019
8107b28
Make substrate-service-test compile
tomaka Aug 13, 2019
a44e91f
Fix the node-cli tests
tomaka Aug 13, 2019
00e5e35
Remove the old API
tomaka Aug 13, 2019
98252b4
Remove the components module
tomaka Aug 13, 2019
1bded02
Fix indentation on chain_ops
tomaka Aug 13, 2019
bd34a60
Line widths
tomaka Aug 13, 2019
0ebb4fe
Fix bad line widths commit
tomaka Aug 13, 2019
7f4c953
Line widths again 🤦
tomaka Aug 13, 2019
1dbe6f6
Fix the sync test
tomaka Aug 13, 2019
69f3131
Apply suggestions from code review
tomaka Aug 13, 2019
f814f4e
Address some concerns
tomaka Aug 26, 2019
36d3f27
Remove TelemetryOnConnect
tomaka Aug 26, 2019
9b034c4
Remove informant::start
tomaka Aug 26, 2019
df96677
Update jsonrpc
tomaka Aug 26, 2019
1695b73
Rename factory to builder
tomaka Aug 26, 2019
9374085
Line widths 😩
tomaka Aug 26, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 73 additions & 45 deletions Cargo.lock

Large diffs are not rendered by default.

14 changes: 2 additions & 12 deletions core/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,12 @@ use futures::{Future, Stream};
use futures03::{StreamExt as _, TryStreamExt as _};
use log::{info, warn};
use sr_primitives::{generic::BlockId, traits::Header};
use service::{Service, Components};
use tokio::runtime::TaskExecutor;
use service::AbstractService;

mod display;

/// Spawn informant on the event loop
#[deprecated(note = "Please use informant::build instead, and then create the task manually")]
pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExecutor) where
C: Components,
{
handle.spawn(exit.until(build(service)).map(|_| ()));
}

/// Creates an informant in the form of a `Future` that must be polled regularly.
pub fn build<C>(service: &Service<C>) -> impl Future<Item = (), Error = ()>
where C: Components {
pub fn build(service: &impl AbstractService) -> impl Future<Item = (), Error = ()> {
let client = service.client();

let mut display = display::InformantDisplay::new();
Expand Down
93 changes: 28 additions & 65 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ pub mod informant;
use client::ExecutionStrategies;
use service::{
config::Configuration,
ServiceFactory, FactoryFullConfiguration, RuntimeGenesis,
FactoryGenesis, PruningMode, ChainSpec,
ServiceBuilderExport, ServiceBuilderImport, ServiceBuilderRevert,
RuntimeGenesis, PruningMode, ChainSpec,
};
use network::{
self, multiaddr::Protocol,
Expand Down Expand Up @@ -317,13 +317,17 @@ pub struct ParseAndPrepareExport<'a> {

impl<'a> ParseAndPrepareExport<'a> {
/// Runs the command and exports from the chain.
pub fn run<F, S, E>(
pub fn run_with_builder<C, G, F, B, S, E>(
self,
builder: F,
spec_factory: S,
exit: E,
) -> error::Result<()>
where S: FnOnce(&str) -> Result<Option<ChainSpec<FactoryGenesis<F>>>, String>,
F: ServiceFactory,
where S: FnOnce(&str) -> Result<Option<ChainSpec<G>>, String>,
F: FnOnce(Configuration<C, G>) -> Result<B, error::Error>,
B: ServiceBuilderExport,
C: Default,
G: RuntimeGenesis,
E: IntoExit
{
let config = create_config_with_db_path(spec_factory, &self.params.shared_params, self.version)?;
Expand All @@ -338,9 +342,8 @@ impl<'a> ParseAndPrepareExport<'a> {
None => Box::new(stdout()),
};

service::chain_ops::export_blocks::<F, _, _>(
config, exit.into_exit(), file, from.into(), to.map(Into::into), json
).map_err(Into::into)
builder(config)?.export_blocks(exit.into_exit(), file, from.into(), to.map(Into::into), json)?;
Ok(())
}
}

Expand All @@ -352,13 +355,17 @@ pub struct ParseAndPrepareImport<'a> {

impl<'a> ParseAndPrepareImport<'a> {
/// Runs the command and imports to the chain.
pub fn run<F, S, E>(
pub fn run_with_builder<C, G, F, B, S, E>(
self,
builder: F,
spec_factory: S,
exit: E,
) -> error::Result<()>
where S: FnOnce(&str) -> Result<Option<ChainSpec<FactoryGenesis<F>>>, String>,
F: ServiceFactory,
where S: FnOnce(&str) -> Result<Option<ChainSpec<G>>, String>,
F: FnOnce(Configuration<C, G>) -> Result<B, error::Error>,
B: ServiceBuilderImport,
C: Default,
G: RuntimeGenesis,
E: IntoExit
{
let mut config = create_config_with_db_path(spec_factory, &self.params.shared_params, self.version)?;
Expand All @@ -377,7 +384,7 @@ impl<'a> ParseAndPrepareImport<'a> {
},
};

let fut = service::chain_ops::import_blocks::<F, _, _>(config, exit.into_exit(), file)?;
let fut = builder(config)?.import_blocks(exit.into_exit(), file)?;
tokio::run(fut);
Ok(())
}
Expand Down Expand Up @@ -440,67 +447,23 @@ pub struct ParseAndPrepareRevert<'a> {

impl<'a> ParseAndPrepareRevert<'a> {
/// Runs the command and reverts the chain.
pub fn run<F, S>(
pub fn run_with_builder<C, G, F, B, S>(
self,
builder: F,
spec_factory: S
) -> error::Result<()>
where S: FnOnce(&str) -> Result<Option<ChainSpec<FactoryGenesis<F>>>, String>,
F: ServiceFactory {
where S: FnOnce(&str) -> Result<Option<ChainSpec<G>>, String>,
F: FnOnce(Configuration<C, G>) -> Result<B, error::Error>,
B: ServiceBuilderRevert,
C: Default,
G: RuntimeGenesis {
let config = create_config_with_db_path(spec_factory, &self.params.shared_params, self.version)?;
let blocks = self.params.num;
Ok(service::chain_ops::revert_chain::<F>(config, blocks.into())?)
builder(config)?.revert_chain(blocks.into())?;
Ok(())
}
}

/// Parse command line interface arguments and executes the desired command.
///
/// # Return value
///
/// A result that indicates if any error occurred.
/// If no error occurred and a custom subcommand was found, the subcommand is returned.
/// The user needs to handle this subcommand on its own.
///
/// # Remarks
///
/// `CC` is a custom subcommand. This needs to be an `enum`! If no custom subcommand is required,
/// `NoCustom` can be used as type here.
/// `RP` are custom parameters for the run command. This needs to be a `struct`! The custom
/// parameters are visible to the user as if they were normal run command parameters. If no custom
/// parameters are required, `NoCustom` can be used as type here.
#[deprecated(
note = "Use parse_and_prepare instead; see the source code of parse_and_execute for how to transition"
)]
pub fn parse_and_execute<'a, F, CC, RP, S, RS, E, I, T>(
spec_factory: S,
version: &VersionInfo,
impl_name: &'static str,
args: I,
exit: E,
run_service: RS,
) -> error::Result<Option<CC>>
where
F: ServiceFactory,
S: FnOnce(&str) -> Result<Option<ChainSpec<FactoryGenesis<F>>>, String>,
CC: StructOpt + Clone + GetLogFilter,
RP: StructOpt + Clone + AugmentClap,
E: IntoExit,
RS: FnOnce(E, RunCmd, RP, FactoryFullConfiguration<F>) -> Result<(), String>,
I: IntoIterator<Item = T>,
T: Into<std::ffi::OsString> + Clone,
{
match parse_and_prepare::<CC, RP, _>(version, impl_name, args) {
ParseAndPrepare::Run(cmd) => cmd.run(spec_factory, exit, run_service),
ParseAndPrepare::BuildSpec(cmd) => cmd.run(spec_factory),
ParseAndPrepare::ExportBlocks(cmd) => cmd.run::<F, _, _>(spec_factory, exit),
ParseAndPrepare::ImportBlocks(cmd) => cmd.run::<F, _, _>(spec_factory, exit),
ParseAndPrepare::PurgeChain(cmd) => cmd.run(spec_factory),
ParseAndPrepare::RevertChain(cmd) => cmd.run::<F, _>(spec_factory),
ParseAndPrepare::CustomCommand(cmd) => return Ok(Some(cmd))
}?;

Ok(None)
}

/// Create a `NodeKeyConfig` from the given `NodeKeyParams` in the context
/// of an optional network config storage directory.
fn node_key_config<P>(params: NodeKeyParams, net_config_dir: &Option<P>)
Expand Down
5 changes: 0 additions & 5 deletions core/finality-grandpa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ serde_json = "1.0"
client = { package = "substrate-client", path = "../client" }
inherents = { package = "substrate-inherents", path = "../../core/inherents" }
network = { package = "substrate-network", path = "../network" }
service = { package = "substrate-service", path = "../service", optional = true }
srml-finality-tracker = { path = "../../srml/finality-tracker" }
fg_primitives = { package = "substrate-finality-grandpa-primitives", path = "primitives" }
grandpa = { package = "finality-grandpa", version = "0.9.0", features = ["derive-codec"] }
Expand All @@ -37,7 +36,3 @@ babe_primitives = { package = "substrate-consensus-babe-primitives", path = "../
env_logger = "0.6"
tokio = "0.1.17"
tempfile = "3.1"

[features]
default = ["service-integration"]
service-integration = ["service"]
9 changes: 2 additions & 7 deletions core/finality-grandpa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,6 @@ mod light_import;
mod observer;
mod until_imported;

#[cfg(feature="service-integration")]
mod service_integration;
#[cfg(feature="service-integration")]
pub use service_integration::{LinkHalfForService, BlockImportForService, BlockImportForLightService};
pub use communication::Network;
pub use finality_proof::FinalityProofProvider;
pub use light_import::light_block_import;
Expand All @@ -107,7 +103,6 @@ use environment::{Environment, VoterSetState};
use import::GrandpaBlockImport;
use until_imported::UntilGlobalMessageBlocksImported;
use communication::NetworkBridge;
use service::TelemetryOnConnect;
use fg_primitives::{AuthoritySignature, SetId, AuthorityWeight};

// Re-export these two because it's just so damn convenient.
Expand Down Expand Up @@ -484,7 +479,7 @@ pub struct GrandpaParams<B, E, Block: BlockT<Hash=H256>, N, RA, SC, X> {
/// Handle to a future that will resolve on exit.
pub on_exit: X,
/// If supplied, can be used to hook on telemetry connection established events.
pub telemetry_on_connect: Option<TelemetryOnConnect>,
pub telemetry_on_connect: Option<mpsc::UnboundedReceiver<()>>,
}

/// Run a GRANDPA voter as a task. Provide configuration and a link to a
Expand Down Expand Up @@ -531,7 +526,7 @@ pub fn run_grandpa_voter<B, E, Block: BlockT<Hash=H256>, N, RA, SC, X>(

let telemetry_task = if let Some(telemetry_on_connect) = telemetry_on_connect {
let authorities = persistent_data.authority_set.clone();
let events = telemetry_on_connect.telemetry_connection_sinks
let events = telemetry_on_connect
.for_each(move |_| {
telemetry!(CONSENSUS_INFO; "afg.authority_set";
"authority_set_id" => ?authorities.set_id(),
Expand Down
49 changes: 0 additions & 49 deletions core/finality-grandpa/src/service_integration.rs

This file was deleted.

8 changes: 4 additions & 4 deletions core/rpc-servers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ authors = ["Parity Technologies <[email protected]>"]
edition = "2018"

[dependencies]
jsonrpc-core = "13.0.0"
pubsub = { package = "jsonrpc-pubsub", version = "13.0.0" }
jsonrpc-core = "13.1.0"
pubsub = { package = "jsonrpc-pubsub", version = "13.1.0" }
log = "0.4"
serde = "1.0"
sr-primitives = { path = "../sr-primitives" }

[target.'cfg(not(target_os = "unknown"))'.dependencies]
http = { package = "jsonrpc-http-server", version = "13.0.0" }
ws = { package = "jsonrpc-ws-server", version = "13.0.0" }
http = { package = "jsonrpc-http-server", version = "13.1.0" }
ws = { package = "jsonrpc-ws-server", version = "13.1.0" }
8 changes: 4 additions & 4 deletions core/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ edition = "2018"
derive_more = "0.14.0"
futures = "0.1"
futures03 = { package = "futures-preview", version = "0.3.0-alpha.17", features = ["compat"] }
jsonrpc-core = "13.0.0"
jsonrpc-core-client = "13.0.0"
jsonrpc-pubsub = "13.0.0"
jsonrpc-derive = "13.0.0"
jsonrpc-core = "13.1.0"
jsonrpc-core-client = "13.1.0"
jsonrpc-pubsub = "13.1.0"
jsonrpc-derive = "13.1.0"
log = "0.4"
parking_lot = "0.9.0"
codec = { package = "parity-scale-codec", version = "1.0.0" }
Expand Down
Loading