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
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
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-rc3"
license = "GPL-3.0-or-later WITH Classpath-exception-2.0"
authors = ["Parity Technologies <[email protected]>"]
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
57 changes: 57 additions & 0 deletions client/light/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// 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.

use sp_runtime::traits::{Block as BlockT, HashFor};
use sc_client_api::CloneableSpawn;
use std::sync::Arc;
use sp_core::traits::CodeExecutor;

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

pub use {backend::*, blockchain::*, call_executor::*, fetcher::*};

/// Create an instance of fetch data checker.
pub fn new_fetch_checker<E, B: BlockT, S: BlockchainStorage<B>>(
blockchain: Arc<Blockchain<S>>,
executor: E,
spawn_handle: Box<dyn CloneableSpawn>,
) -> LightDataChecker<E, HashFor<B>, B, S>
where
E: CodeExecutor,
{
LightDataChecker::new(blockchain, executor, spawn_handle)
}

/// Create an instance of light client blockchain backend.
pub fn new_light_blockchain<B: BlockT, S: BlockchainStorage<B>>(storage: S) -> Arc<Blockchain<S>> {
Arc::new(Blockchain::new(storage))
}

/// Create an instance of light client backend.
pub fn new_light_backend<B, S>(blockchain: Arc<Blockchain<S>>) -> Arc<Backend<S, HashFor<B>>>
where
B: BlockT,
S: BlockchainStorage<B>,
{
Arc::new(Backend::new(blockchain))
}
1 change: 1 addition & 0 deletions client/service/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ sp-application-crypto = { version = "2.0.0-rc3", path = "../../primitives/applic
sp-consensus = { version = "0.8.0-rc3", path = "../../primitives/consensus/common" }
sc-network = { version = "0.8.0-rc3", path = "../network" }
sc-chain-spec = { version = "2.0.0-rc3", path = "../chain-spec" }
sc-light = { version = "2.0.0-rc3", path = "../light" }
sc-client-api = { version = "2.0.0-rc3", path = "../api" }
sp-api = { version = "2.0.0-rc3", path = "../../primitives/api" }
sc-client-db = { version = "0.8.0-rc3", default-features = false, path = "../db" }
Expand Down
25 changes: 13 additions & 12 deletions client/service/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,14 @@
use crate::{
Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID, MallocSizeOfWasm,
start_rpc_servers, build_network_future, TransactionPoolAdapter, TaskManager, SpawnTaskHandle,
status_sinks, metrics::MetricsService, client::{Client, ClientConfig},
status_sinks, metrics::MetricsService,
client::{light, Client, ClientConfig},
config::{Configuration, KeystoreConfig, PrometheusConfig, OffchainWorkerConfig},
};
use sc_client_api::{
BlockchainEvents, backend::RemoteBackend, light::RemoteBlockchain,
execution_extensions::ExtensionsFactory, ExecutorProvider, CallExecutor, ForkBlocks, BadBlocks,
CloneableSpawn, UsageProvider,
self, BlockchainEvents, light::RemoteBlockchain, execution_extensions::ExtensionsFactory,
ExecutorProvider, CallExecutor, ForkBlocks, BadBlocks, CloneableSpawn, UsageProvider,
backend::RemoteBackend,
};
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
use sc_chain_spec::get_extension;
Expand Down Expand Up @@ -179,19 +180,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 @@ -415,18 +416,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 = sc_light::new_light_blockchain(db_storage);
let fetch_checker = Arc::new(
crate::client::light::new_fetch_checker::<_, TBl, _>(
sc_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 = sc_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::{TracingUnboundedSender, 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 rand::Rng;

#[cfg(feature="test-helpers")]
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,24 +32,8 @@ 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;

/// Create an instance of light client blockchain backend.
pub fn new_light_blockchain<B: BlockT, S: BlockchainStorage<B>>(storage: S) -> Arc<Blockchain<S>> {
Arc::new(Blockchain::new(storage))
}
use sc_light::{Backend, GenesisCallExecutor};

/// Create an instance of light client backend.
pub fn new_light_backend<B, S>(blockchain: Arc<Blockchain<S>>) -> Arc<Backend<S, HashFor<B>>>
where
B: BlockT,
S: BlockchainStorage<B>,
{
Arc::new(Backend::new(blockchain))
}

/// Create an instance of light client.
pub fn new_light<B, S, RA, E>(
Expand All @@ -79,7 +58,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 All @@ -92,15 +76,3 @@ pub fn new_light<B, S, RA, E>(
ClientConfig::default(),
)
}

/// Create an instance of fetch data checker.
pub fn new_fetch_checker<E, B: BlockT, S: BlockchainStorage<B>>(
blockchain: Arc<Blockchain<S>>,
executor: E,
spawn_handle: Box<dyn CloneableSpawn>,
) -> LightDataChecker<E, HashFor<B>, B, S>
where
E: CodeExecutor,
{
LightDataChecker::new(blockchain, executor, spawn_handle)
}
1 change: 1 addition & 0 deletions client/service/test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ log = "0.4.8"
env_logger = "0.7.0"
fdlimit = "0.1.4"
parking_lot = "0.10.0"
sc-light = { version = "2.0.0-rc3", path = "../../light" }
sp-blockchain = { version = "2.0.0-rc3", path = "../../../primitives/blockchain" }
sp-api = { version = "2.0.0-rc3", path = "../../../primitives/api" }
sp-state-machine = { version = "0.8.0-rc3", path = "../../../primitives/state-machine" }
Expand Down
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-rc3", path = "../../client/api" }
sc-light = { version = "2.0.0-rc3", path = "../../client/light" }
sc-client-db = { version = "0.8.0-rc3", features = ["test-helpers"], path = "../../client/db" }
sp-consensus = { version = "0.8.0-rc3", path = "../../primitives/consensus/common" }
sc-executor = { version = "0.8.0-rc3", 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
1 change: 1 addition & 0 deletions test-utils/runtime/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ publish = false
targets = ["x86_64-unknown-linux-gnu"]

[dependencies]
sc-light = { version = "2.0.0-rc3", path = "../../../client/light" }
sp-consensus = { version = "0.8.0-rc3", path = "../../../primitives/consensus/common" }
sc-block-builder = { version = "0.8.0-rc3", path = "../../../client/block-builder" }
substrate-test-client = { version = "2.0.0-rc3", path = "../../client" }
Expand Down
Loading