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

Implement runtime api client side directly in the runtime #1094

Merged
merged 19 commits into from
Nov 13, 2018
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
20 changes: 7 additions & 13 deletions Cargo.lock

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

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ members = [
"core/primitives",
"core/rpc",
"core/rpc-servers",
"core/sr-api",
"core/sr-io",
"core/sr-sandbox",
"core/sr-std",
Expand Down
6 changes: 2 additions & 4 deletions core/cli/src/informant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ use runtime_primitives::traits::{Header, As};
const TIMER_INTERVAL_MS: u64 = 5000;

/// Spawn informant on the event loop
pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExecutor)
where
C: Components,
pub fn start<C>(service: &Service<C>, exit: ::exit_future::Exit, handle: TaskExecutor) where
C: Components,
{
let interval = Interval::new(Instant::now(), Duration::from_millis(TIMER_INTERVAL_MS));

Expand Down Expand Up @@ -121,4 +120,3 @@ fn speed(best_number: u64, last_number: Option<u64>) -> String {
format!(" {:4.1} bps", speed / 10.0)
}
}

68 changes: 48 additions & 20 deletions core/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,55 @@ version = "0.1.0"
authors = ["Parity Technologies <admin@parity.io>"]

[dependencies]
error-chain = "0.12"
fnv = "1.0"
log = "0.4"
parking_lot = "0.4"
hex-literal = "0.1"
futures = "0.1.17"
slog = "^2"
heapsize = "0.4"
substrate-consensus-common = { path = "../consensus/common" }
parity-codec = "2.1"
substrate-executor = { path = "../executor" }
substrate-primitives = { path = "../primitives" }
sr-primitives = { path = "../sr-primitives" }
sr-api = { path = "../sr-api" }
substrate-state-machine = { path = "../state-machine" }
substrate-keyring = { path = "../keyring" }
substrate-trie = { path = "../trie" }
substrate-telemetry = { path = "../telemetry" }
hash-db = { git = "https://github.com/paritytech/trie" }
kvdb = "0.1"
error-chain = { version = "0.12", optional = true }
fnv = { version = "1.0", optional = true }
log = { version = "0.4", optional = true }
parking_lot = { version = "0.4", optional = true }
hex-literal = { version = "0.1", optional = true }
futures = { version = "0.1.17", optional = true }
slog = { version = "^2", optional = true }
heapsize = { version = "0.4", optional = true }
substrate-consensus-common = { path = "../consensus/common", optional = true }
substrate-executor = { path = "../executor", optional = true }
substrate-state-machine = { path = "../state-machine", optional = true }
substrate-keyring = { path = "../keyring", optional = true }
substrate-trie = { path = "../trie", optional = true }
substrate-telemetry = { path = "../telemetry", optional = true }
hash-db = { git = "https://github.com/paritytech/trie", optional = true }
kvdb = { version = "0.1", optional = true }

parity-codec = { version = "2.1", default-features = false }
substrate-primitives = { path = "../primitives", default-features = false }
sr-primitives = { path = "../sr-primitives", default-features = false }
sr-version = { path = "../sr-version", default-features = false }
sr-std = { path = "../sr-std", default-features = false }

[dev-dependencies]
substrate-test-client = { path = "../test-client" }
kvdb-memorydb = "0.1"

[features]
default = ["std"]
std = [
"parity-codec/std",
"substrate-consensus-common",
"substrate-primitives/std",
"parking_lot",
"error-chain",
"fnv",
"log",
"hex-literal",
"futures",
"slog",
"heapsize",
"substrate-executor",
"sr-primitives/std",
"sr-version/std",
"sr-std/std",
"substrate-state-machine",
"substrate-keyring",
"substrate-trie",
"substrate-telemetry",
"hash-db",
"kvdb"
]
12 changes: 6 additions & 6 deletions core/client/db/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,17 @@ pub struct DatabaseSettings {
}

/// Create an instance of db-backed client.
pub fn new_client<E, S, Block>(
pub fn new_client<E, S, Block, RA>(
settings: DatabaseSettings,
executor: E,
genesis_storage: S,
block_execution_strategy: ExecutionStrategy,
api_execution_strategy: ExecutionStrategy,
) -> Result<client::Client<Backend<Block>, client::LocalCallExecutor<Backend<Block>, E>, Block>, client::error::Error>
where
Block: BlockT<Hash=H256>,
E: CodeExecutor<Blake2Hasher> + RuntimeInfo,
S: BuildStorage,
) -> Result<client::Client<Backend<Block>, client::LocalCallExecutor<Backend<Block>, E>, Block, RA>, client::error::Error>
where
Block: BlockT<Hash=H256>,
E: CodeExecutor<Blake2Hasher> + RuntimeInfo,
S: BuildStorage,
{
let backend = Arc::new(Backend::new(settings, CANONICALIZATION_DELAY)?);
let executor = client::LocalCallExecutor::new(backend.clone(), executor);
Expand Down
7 changes: 2 additions & 5 deletions core/client/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ impl NewBlockState {
}

/// Block insertion operation. Keeps hold if the inserted block state and data.
pub trait BlockImportOperation<Block, H>
where
pub trait BlockImportOperation<Block, H> where
Block: BlockT,
H: Hasher<Out=Block::Hash>,
{
Expand Down Expand Up @@ -85,11 +84,9 @@ where
///
/// The same applies for live `BlockImportOperation`s: while an import operation building on a parent `P`
/// is alive, the state for `P` should not be pruned.
pub trait Backend<Block, H>: Send + Sync
where
pub trait Backend<Block, H>: Send + Sync where
Block: BlockT,
H: Hasher<Out=Block::Hash>,

{
/// Associated block insertion operation type.
type BlockImportOperation: BlockImportOperation<Block, H>;
Expand Down
40 changes: 40 additions & 0 deletions core/client/src/block_builder/api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright 2018 Parity Technologies (UK) Ltd.
// This file is part of Substrate.

// Substrate 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.

// Substrate 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 Substrate. If not, see <http://www.gnu.org/licenses/>.

//! The runtime api for building blocks.

use runtime_primitives::{traits::Block as BlockT, ApplyResult};
use rstd::vec::Vec;

decl_runtime_apis! {
/// The `BlockBuilder` api trait that provides required functions for building a block for a runtime.
pub trait BlockBuilder<Block: BlockT> {
/// The runtime api for building blocks./// Apply the given extrinsics.
fn apply_extrinsic(extrinsic: <Block as BlockT>::Extrinsic) -> ApplyResult;
/// Finish the current block.
fn finalise_block() -> <Block as BlockT>::Header;
/// Generate inherent extrinsics.
fn inherent_extrinsics<InherentExtrinsic, UncheckedExtrinsic>(
inherent: InherentExtrinsic
) -> Vec<UncheckedExtrinsic>;
/// Check that the inherents are valid.
fn check_inherents<InherentData, Error>(
block: Block, data: InherentData
) -> Result<(), Error>;
/// Generate a random seed.
fn random_seed() -> <Block as BlockT>::Hash;
}
}
Loading