Skip to content

Commit

Permalink
Statement store (paritytech#13701)
Browse files Browse the repository at this point in the history
* WIP Statement store

* Sync with networking changes in master

* WIP statement pallet

* Statement validation

* pallet tests

* Validation queue

* Store maintenance

* Basic statement refactoring + tests + docs

* Store metrics

* Store tests

* Store maintenance test

* cargo fmt

* Build fix

* OCW Api

* Offchain worker

* Enable host functions

* fmt

* Minor tweaks

* Fixed a warning

* Removed tracing

* Manual expiration

* Reworked constraint management

* Updated pallet constraint calculation

* Added small test

* Added remove function to the APIs

* Copy-paste spec into readme

* Comments

* Made the store optional

* Removed network protocol controller

* fmt

* Clippy fixes

* fmt

* fmt

* More clippy fixes

* More clippy fixes

* More clippy fixes

* Update client/statement-store/README.md

Co-authored-by: cheme <[email protected]>

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

* Removed sstore from node-template

* Sort out data path

* Added offline check

* Removed dispatch_statement

* Renamed into_generic

* Fixed commit placement

* Use HashSet for tracking peers/statements

* fmt

* Use ExtendedHostFunctions

* Fixed benches

* Tweaks

* Apply suggestions from code review

Co-authored-by: cheme <[email protected]>

* Fixed priority mixup

* Rename

* newtypes for priorities

* Added MAX_TOPICS

* Fixed key filtering logic

* Remove empty entrie

* Removed prefix from signing

* More documentation

* fmt

* Moved store setup from sc-service to node

* Handle maintenance task in sc-statement-store

* Use statement iterator

* Renamed runtime API mod

* fmt

* Remove dump_encoded

* fmt

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <[email protected]>

* Fixed build after applying review suggestions

* License exceptions

* fmt

* Store options

* Moved pallet consts to config trait

* Removed global priority

* Validate fields when decoding

* Limit validation channel size

* Made a comment into module doc

* Removed submit_encoded

---------

Co-authored-by: cheme <[email protected]>
Co-authored-by: Bastian Köcher <[email protected]>
  • Loading branch information
3 people authored and nathanwhit committed Jul 19, 2023
1 parent e02c6a6 commit 13ca13f
Show file tree
Hide file tree
Showing 48 changed files with 3,911 additions and 26 deletions.
88 changes: 88 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ members = [
"client/merkle-mountain-range/rpc",
"client/network",
"client/network/transactions",
"client/network/statement",
"client/network-gossip",
"client/network/bitswap",
"client/network/common",
Expand All @@ -63,6 +64,7 @@ members = [
"client/service",
"client/service/test",
"client/state-db",
"client/statement-store",
"client/storage-monitor",
"client/sysinfo",
"client/sync-state-rpc",
Expand Down Expand Up @@ -151,6 +153,7 @@ members = [
"frame/sudo",
"frame/root-offences",
"frame/root-testing",
"frame/statement",
"frame/support",
"frame/support/procedural",
"frame/support/procedural/tools",
Expand Down Expand Up @@ -220,6 +223,7 @@ members = [
"primitives/session",
"primitives/staking",
"primitives/state-machine",
"primitives/statement-store",
"primitives/std",
"primitives/storage",
"primitives/test-primitives",
Expand Down
1 change: 1 addition & 0 deletions bin/node-template/node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ sc-telemetry = { version = "4.0.0-dev", path = "../../../client/telemetry" }
sc-keystore = { version = "4.0.0-dev", path = "../../../client/keystore" }
sc-transaction-pool = { version = "4.0.0-dev", path = "../../../client/transaction-pool" }
sc-transaction-pool-api = { version = "4.0.0-dev", path = "../../../client/transaction-pool/api" }
sc-statement-store = { version = "4.0.0-dev", path = "../../../client/statement-store" }
sc-consensus-aura = { version = "0.10.0-dev", path = "../../../client/consensus/aura" }
sp-consensus-aura = { version = "0.10.0-dev", path = "../../../primitives/consensus/aura" }
sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/common" }
Expand Down
2 changes: 2 additions & 0 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,11 @@ sc-chain-spec = { version = "4.0.0-dev", path = "../../../client/chain-spec" }
sc-consensus = { version = "0.10.0-dev", path = "../../../client/consensus/common" }
sc-transaction-pool = { version = "4.0.0-dev", path = "../../../client/transaction-pool" }
sc-transaction-pool-api = { version = "4.0.0-dev", path = "../../../client/transaction-pool/api" }
sc-statement-store = { version = "4.0.0-dev", path = "../../../client/statement-store" }
sc-network = { version = "0.10.0-dev", path = "../../../client/network" }
sc-network-common = { version = "0.10.0-dev", path = "../../../client/network/common" }
sc-network-sync = { version = "0.10.0-dev", path = "../../../client/network/sync" }
sc-network-statement = { version = "0.10.0-dev", path = "../../../client/network/statement" }
sc-consensus-slots = { version = "0.10.0-dev", path = "../../../client/consensus/slots" }
sc-consensus-babe = { version = "0.10.0-dev", path = "../../../client/consensus/babe" }
grandpa = { version = "0.10.0-dev", package = "sc-consensus-grandpa", path = "../../../client/consensus/grandpa" }
Expand Down
3 changes: 2 additions & 1 deletion bin/node/cli/benches/block_production.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
max_runtime_instances: 8,
runtime_cache_size: 2,
announce_block: true,
base_path: Some(base_path),
data_path: base_path.path().into(),
base_path,
informant_output_format: Default::default(),
wasm_runtime_overrides: None,
};
Expand Down
3 changes: 2 additions & 1 deletion bin/node/cli/benches/transaction_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ fn new_node(tokio_handle: Handle) -> node_cli::service::NewFullBase {
max_runtime_instances: 8,
runtime_cache_size: 2,
announce_block: true,
base_path: Some(base_path),
data_path: base_path.path().into(),
base_path,
informant_output_format: Default::default(),
wasm_runtime_overrides: None,
};
Expand Down
49 changes: 46 additions & 3 deletions bin/node/cli/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ use sc_network::{event::Event, NetworkEventStream, NetworkService};
use sc_network_common::sync::warp::WarpSyncParams;
use sc_network_sync::SyncingService;
use sc_service::{config::Configuration, error::Error as ServiceError, RpcHandlers, TaskManager};
use sc_statement_store::Store as StatementStore;
use sc_telemetry::{Telemetry, TelemetryWorker};
use sp_api::ProvideRuntimeApi;
use sp_core::crypto::Pair;
Expand Down Expand Up @@ -148,6 +149,7 @@ pub fn new_partial(
),
grandpa::SharedVoterState,
Option<Telemetry>,
Arc<StatementStore>,
),
>,
ServiceError,
Expand Down Expand Up @@ -227,6 +229,15 @@ pub fn new_partial(

let import_setup = (block_import, grandpa_link, babe_link);

let statement_store = sc_statement_store::Store::new_shared(
&config.data_path,
Default::default(),
client.clone(),
config.prometheus_registry(),
&task_manager.spawn_handle(),
)
.map_err(|e| ServiceError::Other(format!("Statement store error: {:?}", e)))?;

let (rpc_extensions_builder, rpc_setup) = {
let (_, grandpa_link, _) = &import_setup;

Expand All @@ -247,6 +258,7 @@ pub fn new_partial(
let chain_spec = config.chain_spec.cloned_box();

let rpc_backend = backend.clone();
let rpc_statement_store = statement_store.clone();
let rpc_extensions_builder = move |deny_unsafe, subscription_executor| {
let deps = node_rpc::FullDeps {
client: client.clone(),
Expand All @@ -265,6 +277,7 @@ pub fn new_partial(
subscription_executor,
finality_provider: finality_proof_provider.clone(),
},
statement_store: rpc_statement_store.clone(),
};

node_rpc::create_full(deps, rpc_backend.clone()).map_err(Into::into)
Expand All @@ -281,7 +294,7 @@ pub fn new_partial(
select_chain,
import_queue,
transaction_pool,
other: (rpc_extensions_builder, import_setup, rpc_setup, telemetry),
other: (rpc_extensions_builder, import_setup, rpc_setup, telemetry, statement_store),
})
}

Expand Down Expand Up @@ -325,7 +338,7 @@ pub fn new_full_base(
keystore_container,
select_chain,
transaction_pool,
other: (rpc_builder, import_setup, rpc_setup, mut telemetry),
other: (rpc_builder, import_setup, rpc_setup, mut telemetry, statement_store),
} = new_partial(&config)?;

let shared_voter_state = rpc_setup;
Expand All @@ -335,6 +348,16 @@ pub fn new_full_base(
&config.chain_spec,
);

let statement_handler_proto = sc_network_statement::StatementHandlerPrototype::new(
client
.block_hash(0u32.into())
.ok()
.flatten()
.expect("Genesis block exists; qed"),
config.chain_spec.fork_id(),
);
config.network.extra_sets.push(statement_handler_proto.set_config());

config
.network
.extra_sets
Expand Down Expand Up @@ -526,7 +549,7 @@ pub fn new_full_base(
sync: Arc::new(sync_service.clone()),
telemetry: telemetry.as_ref().map(|x| x.handle()),
voting_rule: grandpa::VotingRulesBuilder::default().build(),
prometheus_registry,
prometheus_registry: prometheus_registry.clone(),
shared_voter_state,
};

Expand All @@ -539,6 +562,26 @@ pub fn new_full_base(
);
}

// Spawn statement protocol worker
let statement_protocol_executor = {
let spawn_handle = task_manager.spawn_handle();
Box::new(move |fut| {
spawn_handle.spawn("network-statement-validator", Some("networking"), fut);
})
};
let statement_handler = statement_handler_proto.build(
network.clone(),
sync_service.clone(),
statement_store.clone(),
prometheus_registry.as_ref(),
statement_protocol_executor,
)?;
task_manager.spawn_handle().spawn(
"network-statement-handler",
Some("networking"),
statement_handler.run(),
);

network_starter.start_network();
Ok(NewFullBase {
task_manager,
Expand Down
1 change: 1 addition & 0 deletions bin/node/executor/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ sp-keystore = { version = "0.13.0", path = "../../../primitives/keystore" }
sp-state-machine = { version = "0.13.0", path = "../../../primitives/state-machine" }
sp-tracing = { version = "6.0.0", path = "../../../primitives/tracing" }
sp-trie = { version = "7.0.0", path = "../../../primitives/trie" }
sp-statement-store = { version = "4.0.0-dev", path = "../../../primitives/statement-store" }

[dev-dependencies]
criterion = "0.4.0"
Expand Down
5 changes: 4 additions & 1 deletion bin/node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ pub use sc_executor::NativeElseWasmExecutor;
pub struct ExecutorDispatch;

impl sc_executor::NativeExecutionDispatch for ExecutorDispatch {
type ExtendHostFunctions = frame_benchmarking::benchmarking::HostFunctions;
type ExtendHostFunctions = (
frame_benchmarking::benchmarking::HostFunctions,
sp_statement_store::runtime_api::HostFunctions,
);

fn dispatch(method: &str, data: &[u8]) -> Option<Vec<u8>> {
kitchensink_runtime::api::dispatch(method, data)
Expand Down
1 change: 1 addition & 0 deletions bin/node/rpc/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ sp-consensus = { version = "0.10.0-dev", path = "../../../primitives/consensus/c
sp-consensus-babe = { version = "0.10.0-dev", path = "../../../primitives/consensus/babe" }
sp-keystore = { version = "0.13.0", path = "../../../primitives/keystore" }
sp-runtime = { version = "7.0.0", path = "../../../primitives/runtime" }
sp-statement-store = { version = "4.0.0-dev", path = "../../../primitives/statement-store" }
substrate-frame-rpc-system = { version = "4.0.0-dev", path = "../../../utils/frame/rpc/system" }
substrate-state-trie-migration-rpc = { version = "4.0.0-dev", path = "../../../utils/frame/rpc/state-trie-migration-rpc/" }
Loading

0 comments on commit 13ca13f

Please sign in to comment.