Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

new crate sc-light #6235

Merged
merged 9 commits into from
Jun 9, 2020
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ members = [
"client/executor/runtime-test",
"client/finality-grandpa",
"client/informant",
"client/light",
"client/tracing",
"client/keystore",
"client/network",
Expand Down
27 changes: 27 additions & 0 deletions client/light/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
[package]
description = "components for a light client"
name = "sc-light"
version = "2.0.0-rc2"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
homepage = "https://substrate.dev"
repository = "https://github.com/paritytech/substrate/"
documentation = "https://docs.rs/sc-light"

[dependencies]
parking_lot = "0.10.0"
lazy_static = "1.4.0"
hash-db = "0.15.2"
sp-runtime = { version = "2.0.0-rc2", path = "../../primitives/runtime" }
sp-externalities = { version = "0.8.0-rc2", path = "../../primitives/externalities" }
sp-blockchain = { version = "2.0.0-rc2", path = "../../primitives/blockchain" }
sp-core = { version = "2.0.0-rc2", path = "../../primitives/core" }
sp-state-machine = { version = "0.8.0-rc2", path = "../../primitives/state-machine" }
sc-client-api = { version = "2.0.0-rc2", path = "../api" }
sp-api = { version = "2.0.0-rc2", path = "../../primitives/api" }
codec = { package = "parity-scale-codec", version = "1.3.0" }
sc-executor = { version = "0.8.0-rc2", path = "../executor" }

[features]
default = []
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ use sp_runtime::{Justification, generic::BlockId};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero};

use sp_blockchain::{
HeaderMetadata, CachedHeaderMetadata,
Error as ClientError, Result as ClientResult,
HeaderMetadata, CachedHeaderMetadata, Error as ClientError, Result as ClientResult,
};
pub use sc_client_api::{
backend::{
Expand All @@ -42,7 +41,7 @@ pub use sc_client_api::{
},
cht,
};
use super::fetcher::RemoteHeaderRequest;
use crate::fetcher::RemoteHeaderRequest;

/// Light client blockchain.
pub struct Blockchain<S> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ pub use sc_client_api::{
},
cht,
};
use super::blockchain::{Blockchain};
use super::call_executor::check_execution_proof;
use crate::blockchain::Blockchain;
use crate::call_executor::check_execution_proof;

/// Remote data checker.
pub struct LightDataChecker<E, H, B: BlockT, S: BlockchainStorage<B>> {
Expand Down
26 changes: 26 additions & 0 deletions client/light/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// This file is part of Substrate.

// Copyright (C) 2017-2020 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/>.

//! Light client components.

pub mod backend;
pub mod blockchain;
pub mod call_executor;
pub mod fetcher;

pub use {backend::*, blockchain::*, call_executor::*, fetcher::*};
1 change: 1 addition & 0 deletions client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ sp-application-crypto = { version = "2.0.0-rc2", path = "../../primitives/applic
sp-consensus = { version = "0.8.0-rc2", path = "../../primitives/consensus/common" }
sc-network = { version = "0.8.0-rc2", path = "../network" }
sc-chain-spec = { version = "2.0.0-rc2", path = "../chain-spec" }
sc-light = { version = "2.0.0-rc2", path = "../light" }
sc-client-api = { version = "2.0.0-rc2", path = "../api" }
sp-api = { version = "2.0.0-rc2", path = "../../primitives/api" }
sc-client-db = { version = "0.8.0-rc2", default-features = false, path = "../db" }
Expand Down
21 changes: 11 additions & 10 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,11 @@ use crate::status_sinks;
use crate::config::{Configuration, KeystoreConfig, PrometheusConfig, OffchainWorkerConfig};
use crate::metrics::MetricsService;
use sc_client_api::{
self, BlockchainEvents, backend::RemoteBackend, light::RemoteBlockchain, execution_extensions::ExtensionsFactory,
self, BlockchainEvents, light::RemoteBlockchain, execution_extensions::ExtensionsFactory,
ExecutorProvider, CallExecutor, ForkBlocks, BadBlocks, CloneableSpawn, UsageProvider,
backend::RemoteBackend,
};
use crate::client::{Client, ClientConfig};
use crate::client::{light, Client, ClientConfig};
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
use sc_chain_spec::get_extension;
use sp_consensus::{
Expand Down Expand Up @@ -177,19 +178,19 @@ pub type TLightClient<TBl, TRtApi, TExecDisp> = Client<
>;

/// Light client backend type.
pub type TLightBackend<TBl> = crate::client::light::backend::Backend<
pub type TLightBackend<TBl> = sc_light::Backend<
sc_client_db::light::LightStorage<TBl>,
HashFor<TBl>,
>;

/// Light call executor type.
pub type TLightCallExecutor<TBl, TExecDisp> = crate::client::light::call_executor::GenesisCallExecutor<
crate::client::light::backend::Backend<
pub type TLightCallExecutor<TBl, TExecDisp> = sc_light::GenesisCallExecutor<
sc_light::Backend<
sc_client_db::light::LightStorage<TBl>,
HashFor<TBl>
>,
crate::client::LocalCallExecutor<
crate::client::light::backend::Backend<
sc_light::Backend<
sc_client_db::light::LightStorage<TBl>,
HashFor<TBl>
>,
Expand Down Expand Up @@ -412,18 +413,18 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
};
sc_client_db::light::LightStorage::new(db_settings)?
};
let light_blockchain = crate::client::light::new_light_blockchain(db_storage);
let light_blockchain = light::new_light_blockchain(db_storage);
let fetch_checker = Arc::new(
crate::client::light::new_fetch_checker::<_, TBl, _>(
light::new_fetch_checker::<_, TBl, _>(
light_blockchain.clone(),
executor.clone(),
Box::new(task_manager.spawn_handle()),
),
);
let fetcher = Arc::new(sc_network::config::OnDemand::new(fetch_checker));
let backend = crate::client::light::new_light_backend(light_blockchain);
let backend = light::new_light_backend(light_blockchain);
let remote_blockchain = backend.remote_blockchain();
let client = Arc::new(crate::client::light::new_light(
let client = Arc::new(light::new_light(
backend.clone(),
config.chain_spec.as_storage_builder(),
executor,
Expand Down
5 changes: 2 additions & 3 deletions client/service/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,9 @@ use sp_utils::mpsc::tracing_unbounded;
use sp_blockchain::Error;
use prometheus_endpoint::Registry;
use super::{
genesis,
light::{call_executor::prove_execution, fetcher::ChangesProof},
block_rules::{BlockRules, LookupResult as BlockLookupResult},
genesis, block_rules::{BlockRules, LookupResult as BlockLookupResult},
};
use sc_light::{call_executor::prove_execution, fetcher::ChangesProof};
use futures::channel::mpsc;
use rand::Rng;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.

//! Light client components.

pub mod backend;
pub mod blockchain;
pub mod call_executor;
pub mod fetcher;
//! Light client utilities.

use std::sync::Arc;

Expand All @@ -37,10 +32,7 @@ use super::client::{Client,ClientConfig};
use sc_client_api::{
light::Storage as BlockchainStorage, CloneableSpawn,
};
use self::backend::Backend;
use self::blockchain::Blockchain;
use self::call_executor::GenesisCallExecutor;
use self::fetcher::LightDataChecker;
use sc_light::{Backend, Blockchain, GenesisCallExecutor, LightDataChecker};

/// Create an instance of light client blockchain backend.
pub fn new_light_blockchain<B: BlockT, S: BlockchainStorage<B>>(storage: S) -> Arc<Blockchain<S>> {
Expand Down Expand Up @@ -79,7 +71,12 @@ pub fn new_light<B, S, RA, E>(
S: BlockchainStorage<B> + 'static,
E: CodeExecutor + RuntimeInfo + Clone + 'static,
{
let local_executor = LocalCallExecutor::new(backend.clone(), code_executor, spawn_handle.clone(), ClientConfig::default());
let local_executor = LocalCallExecutor::new(
backend.clone(),
code_executor,
spawn_handle.clone(),
ClientConfig::default()
);
let executor = GenesisCallExecutor::new(backend.clone(), local_executor);
Client::new(
backend,
Expand Down
1 change: 1 addition & 0 deletions client/service/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,6 @@ substrate-test-runtime-client = { version = "2.0.0-rc2", path = "../../../test-u
sc-client-api = { version = "2.0.0-rc2", path = "../../api" }
sc-block-builder = { version = "0.8.0-rc2", path = "../../block-builder" }
sc-executor = { version = "0.8.0-rc2", path = "../../executor" }
sc-light = { version = "2.0.0-rc2", path = "../../light" }
sp-panic-handler = { version = "2.0.0-rc2", path = "../../../primitives/panic-handler" }
parity-scale-codec = "1.3.0"
2 changes: 1 addition & 1 deletion client/service/test/src/client/light.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// 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_service::client::light::{
use sc_light::{
call_executor::{
GenesisCallExecutor,
check_execution_proof,
Expand Down
1 change: 1 addition & 0 deletions test-utils/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
sc-client-api = { version = "2.0.0-rc2", path = "../../client/api" }
sc-light = { version = "2.0.0-rc2", path = "../../client/light" }
sc-client-db = { version = "0.8.0-rc2", features = ["test-helpers"], path = "../../client/db" }
sp-consensus = { version = "0.8.0-rc2", path = "../../primitives/consensus/common" }
sc-executor = { version = "0.8.0-rc2", path = "../../client/executor" }
Expand Down
2 changes: 1 addition & 1 deletion test-utils/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ use sp_runtime::traits::{Block as BlockT, BlakeTwo256};
use sc_service::client::{LocalCallExecutor, ClientConfig};

/// Test client light database backend.
pub type LightBackend<Block> = client::light::backend::Backend<
pub type LightBackend<Block> = sc_light::Backend<
sc_client_db::light::LightStorage<Block>,
BlakeTwo256,
>;
Expand Down
2 changes: 2 additions & 0 deletions test-utils/runtime/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ codec = { package = "parity-scale-codec", version = "1.3.0" }
sc-client-api = { version = "2.0.0-rc2", path = "../../../client/api" }
sc-consensus = { version = "0.8.0-rc2", path = "../../../client/consensus/common" }
sc-service = { version = "0.8.0-rc2", default-features = false, path = "../../../client/service" }
sc-light = { version = "2.0.0-rc2", default-features = false, path = "../../../client/light" }

futures = "0.3.4"
15 changes: 6 additions & 9 deletions test-utils/runtime/client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ use sp_core::{sr25519, ChangesTrieConfiguration};
use sp_core::storage::{ChildInfo, Storage, StorageChild};
use substrate_test_runtime::genesismap::{GenesisConfig, additional_storage_with_genesis};
use sp_runtime::traits::{Block as BlockT, Header as HeaderT, Hash as HashT, NumberFor, HashFor};
use sc_service::client::{
light::fetcher::{
Fetcher,
RemoteHeaderRequest, RemoteReadRequest, RemoteReadChildRequest,
RemoteCallRequest, RemoteChangesRequest, RemoteBodyRequest,
},
use sc_client_api::light::{
RemoteCallRequest, RemoteChangesRequest, RemoteBodyRequest,
Fetcher, RemoteHeaderRequest, RemoteReadRequest, RemoteReadChildRequest,
};

/// A prelude to import in tests.
Expand Down Expand Up @@ -78,10 +75,10 @@ pub type Executor = client::LocalCallExecutor<
pub type LightBackend = substrate_test_client::LightBackend<substrate_test_runtime::Block>;

/// Test client light executor.
pub type LightExecutor = client::light::call_executor::GenesisCallExecutor<
pub type LightExecutor = sc_light::GenesisCallExecutor<
LightBackend,
client::LocalCallExecutor<
client::light::backend::Backend<
sc_light::Backend<
sc_client_db::light::LightStorage<substrate_test_runtime::Block>,
HashFor<substrate_test_runtime::Block>
>,
Expand Down Expand Up @@ -350,7 +347,7 @@ pub fn new_light() -> (
) {

let storage = sc_client_db::light::LightStorage::new_test();
let blockchain = Arc::new(client::light::blockchain::Blockchain::new(storage));
let blockchain = Arc::new(sc_light::Blockchain::new(storage));
let backend = Arc::new(LightBackend::new(blockchain.clone()));
let executor = new_native_executor();
let local_call_executor = client::LocalCallExecutor::new(backend.clone(), executor, sp_core::tasks::executor(), Default::default());
Expand Down