Reorganising the repository - external renames and moves (#4074)

* Adding first rough ouline of the repository structure

* Remove old CI stuff

* add title

* formatting fixes

* move node-exits job's script to scripts dir

* Move docs into subdir

* move to bin

* move maintainence scripts, configs and helpers into its own dir

* add .local to ignore

* move core->client

* start up 'test' area

* move test client

* move test runtime

* make test move compile

* Add dependencies rule enforcement.

* Fix indexing.

* Update docs to reflect latest changes

* Moving /srml->/paint

* update docs

* move client/sr-* -> primitives/

* clean old readme

* remove old broken code in rhd

* update lock

* Step 1.

* starting to untangle client

* Fix after merge.

* start splitting out client interfaces

* move children and blockchain interfaces

* Move trie and state-machine to primitives.

* Fix WASM builds.

* fixing broken imports

* more interface moves

* move backend and light to interfaces

* move CallExecutor

* move cli off client

* moving around more interfaces

* re-add consensus crates into the mix

* fix subkey path

* relieve client from executor

* starting to pull out client from grandpa

* move is_decendent_of out of client

* grandpa still depends on client directly

* lemme tests pass

* rename srml->paint

* Make it compile.

* rename interfaces->client-api

* Move keyring to primitives.

* fixup libp2p dep

* fix broken use

* allow dependency enforcement to fail

* move fork-tree

* Moving wasm-builder

* make env

* move build-script-utils

* fixup broken crate depdencies and names

* fix imports for authority discovery

* fix typo

* update cargo.lock

* fixing imports

* Fix paths and add missing crates

* re-add missing crates
This commit is contained in:
Benjamin Kampmann
2019-11-14 21:51:17 +01:00
committed by Bastian Köcher
parent becc3b0a4f
commit 60e5011c72
809 changed files with 7801 additions and 6464 deletions
+1
View File
@@ -3,3 +3,4 @@ doc
.idea/
Dockerfile
.dockerignore
.local
+1
View File
@@ -21,3 +21,4 @@ rls*.log
*.orig
*.rej
**/wip/*.stderr
.local
+28 -19
View File
@@ -78,7 +78,7 @@ check-runtime:
GITLAB_API: "https://gitlab.parity.io/api/v4"
GITHUB_API_PROJECT: "parity%2Finfrastructure%2Fgithub-api"
script:
- ./scripts/gitlab/check_runtime.sh
- ./.maintain/gitlab/check_runtime.sh
allow_failure: true
@@ -89,7 +89,7 @@ check-line-width:
only:
- /^[0-9]+$/
script:
- ./scripts/gitlab/check_line_width.sh
- ./.maintain/gitlab/check_line_width.sh
allow_failure: true
@@ -117,7 +117,7 @@ cargo-check-subkey:
except:
- /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
script:
- cd ./subkey
- cd ./bin/subkey
- BUILD_DUMMY_WASM_BINARY=1 time cargo check --release
- sccache -s
@@ -145,8 +145,17 @@ test-linux-stable: &test-linux
paths:
- ${CI_COMMIT_SHORT_SHA}_warnings.log
test-dependency-rules: &test-linux
stage: test
<<: *docker-env
allow_failure: true
except:
variables:
- $DEPLOY_TAG
script:
- .maintain/ensure-deps.sh
test-srml-staking: &test-srml-staking
test-paint-staking: &test-paint-staking
stage: test
<<: *docker-env
variables:
@@ -158,7 +167,7 @@ test-srml-staking: &test-srml-staking
variables:
- $DEPLOY_TAG
script:
- cd srml/staking/
- cd paint/staking/
- WASM_BUILD_NO_COLOR=1 time cargo test --release --verbose --no-default-features --features std
- sccache -s
@@ -174,7 +183,7 @@ test-wasmtime: &test-wasmtime
variables:
- $DEPLOY_TAG
script:
- cd core/executor
- cd client/executor
- WASM_BUILD_NO_COLOR=1 time cargo test --release --verbose --features wasmtime
- sccache -s
@@ -219,7 +228,7 @@ check-web-wasm:
- time cargo web build -p substrate-consensus-common
- time cargo web build -p substrate-telemetry
# Note: the command below is a bit weird because several Cargo issues prevent us from compiling the node in a more straight-forward way.
- time cargo build --manifest-path=node/cli/Cargo.toml --no-default-features --features "browser" --target=wasm32-unknown-unknown
- time cargo build --manifest-path=bin/node/cli/Cargo.toml --no-default-features --features "browser" --target=wasm32-unknown-unknown
- sccache -s
node-exits:
@@ -228,7 +237,7 @@ node-exits:
except:
- /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1
script:
- ./ci/check_for_exit.sh
- ./.maintain/check_for_exit.sh
test-full-crypto-feature: &test-full-crypto-feature
@@ -243,7 +252,7 @@ test-full-crypto-feature: &test-full-crypto-feature
variables:
- $DEPLOY_TAG
script:
- cd core/primitives/
- cd primitives/core/
- time cargo +nightly build --verbose --no-default-features --features full_crypto
- cd ../application-crypto
- time cargo +nightly build --verbose --no-default-features --features full_crypto
@@ -274,8 +283,8 @@ build-linux-substrate:
fi
- sha256sum ./artifacts/substrate/substrate | tee ./artifacts/substrate/substrate.sha256
- printf '\n# building node-template\n\n'
- ./scripts/node-template-release.sh ./artifacts/substrate/substrate-node-template.tar.gz
- cp -r scripts/docker/substrate.Dockerfile ./artifacts/substrate/
- ./.maintain/node-template-release.sh ./artifacts/substrate/substrate-node-template.tar.gz
- cp -r .maintain/docker/substrate.Dockerfile ./artifacts/substrate/
- sccache -s
build-linux-subkey:
@@ -298,7 +307,7 @@ build-linux-subkey:
sed -n -r 's/^subkey ([0-9.]+.*)/\1/p' |
tee ./artifacts/subkey/VERSION;
- sha256sum ./artifacts/subkey/subkey | tee ./artifacts/subkey/subkey.sha256
- cp -r scripts/docker/subkey.Dockerfile ./artifacts/subkey/
- cp -r .maintain/docker/subkey.Dockerfile ./artifacts/subkey/
- sccache -s
build-rust-doc-release:
@@ -314,7 +323,7 @@ build-rust-doc-release:
<<: *build-only
script:
- rm -f ./crate-docs/index.html # use it as an indicator if the job succeeds
- BUILD_DUMMY_WASM_BINARY=1 RUSTDOCFLAGS="--html-in-header $(pwd)/rustdoc-header.html" time cargo +nightly doc --release --all --verbose
- BUILD_DUMMY_WASM_BINARY=1 RUSTDOCFLAGS="--html-in-header $(pwd).maintain/rustdoc-header.html" time cargo +nightly doc --release --all --verbose
- cp -R ./target/doc ./crate-docs
- echo "<meta http-equiv=refresh content=0;url=substrate_service/index.html>" > ./crate-docs/index.html
- sccache -s
@@ -533,10 +542,10 @@ publish-gh-doc:
- echo "Substrate version = ${DEPLOY_TAG}"
# or use helm to render the template
- helm template
--values ./scripts/kubernetes/values.yaml
--values ./.maintain/kubernetes/values.yaml
--set image.tag=${DEPLOY_TAG}
--set validator.keys=${VALIDATOR_KEYS}
./scripts/kubernetes | kubectl apply -f - --dry-run=false
./.maintain/kubernetes | kubectl apply -f - --dry-run=false
- echo "# substrate namespace ${KUBE_NAMESPACE}"
- kubectl -n ${KUBE_NAMESPACE} get all
- echo "# substrate's nodes' external ip addresses:"
@@ -598,16 +607,16 @@ deploy-ue1-tag:
validator 1 4:
<<: *validator-deploy
script:
- ./scripts/flamingfir-deploy.sh flamingfir-validator1
- ./.maintain/flamingfir-deploy.sh flamingfir-validator1
validator 2 4:
<<: *validator-deploy
script:
- ./scripts/flamingfir-deploy.sh flamingfir-validator2
- ./.maintain/flamingfir-deploy.sh flamingfir-validator2
validator 3 4:
<<: *validator-deploy
script:
- ./scripts/flamingfir-deploy.sh flamingfir-validator3
- ./.maintain/flamingfir-deploy.sh flamingfir-validator3
validator 4 4:
<<: *validator-deploy
script:
- ./scripts/flamingfir-deploy.sh flamingfir-validator4
- ./.maintain/flamingfir-deploy.sh flamingfir-validator4
@@ -8,7 +8,7 @@ LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="parity/subkey" \
io.parity.image.description="Subkey: key generating utility for Substrate." \
io.parity.image.source="https://github.com/paritytech/substrate/blob/${VCS_REF}/scripts/docker/subkey.Dockerfile" \
io.parity.image.source="https://github.com/paritytech/substrate/blob/${VCS_REF}/.maintain/docker/subkey.Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://github.com/paritytech/substrate/tree/${VCS_REF}/subkey"
@@ -8,7 +8,7 @@ LABEL io.parity.image.authors="devops-team@parity.io" \
io.parity.image.vendor="Parity Technologies" \
io.parity.image.title="parity/substrate" \
io.parity.image.description="Substrate: The platform for blockchain innovators." \
io.parity.image.source="https://github.com/paritytech/substrate/blob/${VCS_REF}/scripts/docker/Dockerfile" \
io.parity.image.source="https://github.com/paritytech/substrate/blob/${VCS_REF}/.maintain/docker/Dockerfile" \
io.parity.image.revision="${VCS_REF}" \
io.parity.image.created="${BUILD_DATE}" \
io.parity.image.documentation="https://wiki.parity.io/Parity-Substrate"
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env bash
# The script is meant to check if the rules regarding packages
# dependencies are satisfied.
# The general format is:
# [top-lvl-dir]<[crate-name-prefix]
# For instance no crate within `./client` directory
# is allowed to import any crate with a directory path containing `paint`.
# Such rule is just: `client<paint`.
# The script should be run from the main repo directory!
set -u
PLEASE_DONT=(
"client<paint"
"client<node"
"paint<node"
"paint<client"
"primitives<paint"
"primitives<client"
)
VIOLATIONS=()
PACKAGES=()
for rule in "${PLEASE_DONT[@]}"
do
from=$(echo $rule | cut -f1 -d\<)
to=$(echo $rule | cut -f2 -d\<)
cd $from
echo "Checking rule $rule"
packages=$(find -name Cargo.toml | xargs grep -wn "path.*$to")
has_references=$(echo -n $packages | wc -c)
if [ "$has_references" != "0" ]; then
VIOLATIONS+=("$rule")
# Find packages that violate:
PACKAGES+=("$packages")
fi
cd - > /dev/null
done
# Display violations and fail
I=0
for v in "${VIOLATIONS[@]}"
do
cat << EOF
===========================================
======= Violation of rule: $v
===========================================
${PACKAGES[$I]}
EOF
I=$I+1
done
exit ${#VIOLATIONS[@]}
@@ -1,7 +1,7 @@
#!/bin/sh
#
#
# check for any changes in the node/src/runtime, srml/ and core/sr_* trees. if
# check for any changes in the node/src/runtime, paint/ and core/sr_* trees. if
# there are any changes found, it should mark the PR breaksconsensus and
# "auto-fail" the PR if there isn't a change in the runtime/src/lib.rs file
# that alters the version.
@@ -32,7 +32,7 @@ github_label () {
# check if the wasm sources changed
if ! git diff --name-only origin/master...${CI_COMMIT_SHA} \
| grep -q -e '^node/src/runtime' -e '^srml/' -e '^core/sr-' | grep -v -e '^core/sr-arithmetic/fuzzer'
| grep -q -e '^node/src/runtime' -e '^paint/' -e '^core/sr-' | grep -v -e '^core/sr-arithmetic/fuzzer'
then
cat <<-EOT
@@ -102,7 +102,7 @@ else
source file directories:
- node/src/runtime
- srml
- paint
- core/sr-*
versions file: ${VERSIONS_FILE}
@@ -11,6 +11,6 @@ if [ "$#" -ne 1 ]; then
fi
PATH_TO_ARCHIVE=$(pwd)/$1
cd $PROJECT_ROOT/scripts/node-template-release
cd $PROJECT_ROOT/.maintain/node-template-release
cargo run $PROJECT_ROOT/node-template $PATH_TO_ARCHIVE
@@ -4,7 +4,7 @@
# pip install toml
# sudo apt-get install graphviz
# the first parameter is the runtime folder
# python ./scripts/runtime-dep.py ./substrate/runtime | dot -Tpng -o output.png
# python ./.maintain/runtime-dep.py ./substrate/runtime | dot -Tpng -o output.png
import sys
import os
import toml
@@ -12,7 +12,7 @@
#
# 1. Build `target/release/substrate` binary: `cargo build --release`
#
# 2. Start networks and containers: `sudo docker-compose -f scripts/sentry-node/docker-compose.yml up`
# 2. Start networks and containers: `sudo docker-compose -f .maintain/sentry-node/docker-compose.yml up`
#
# 3. Reach:
# - polkadot/apps on localhost:3000
-28
View File
@@ -1,28 +0,0 @@
# Request an environment that provides sudo (that goes with larger containers)
# and a minimal language environment.
sudo: true
language: minimal
cache: cargo
branches:
only:
- master
env:
global:
- RUST_BACKTRACE=1
matrix:
- RUST_TOOLCHAIN=nightly TARGET=wasm
- RUST_TOOLCHAIN=stable TARGET=native
before_install:
# Check how much space we've got on this machine.
- df -h
script:
- ./ci/script.sh
after_script:
# Check how much free disk space left after the build
- df -h
+897 -890
View File
File diff suppressed because it is too large Load Diff
+134 -113
View File
@@ -1,118 +1,139 @@
[workspace]
members = [
"core/authority-discovery",
"core/application-crypto",
"core/chain-spec",
"core/chain-spec/derive",
"core/cli",
"core/client",
"core/client/db",
"core/client/header-metadata",
"core/consensus/aura",
"core/consensus/babe",
"core/consensus/common",
"core/consensus/rhd",
"core/consensus/slots",
"core/consensus/uncles",
"core/consensus/pow",
"core/block-builder",
"core/block-builder/runtime-api",
"core/executor",
"core/executor/runtime-test",
"core/externalities",
"core/finality-grandpa",
"core/finality-grandpa/primitives",
"core/inherents",
"core/keyring",
"core/keystore",
"core/network",
"core/panic-handler",
"core/primitives",
"core/rpc",
"core/rpc/primitives",
"core/rpc-servers",
"core/runtime-interface",
"core/runtime-interface/proc-macro",
"core/runtime-interface/test-wasm",
"core/serializer",
"core/service",
"core/service/test",
"core/session",
"core/sr-api",
"core/sr-api/proc-macro",
"core/sr-api/test",
"core/sr-arithmetic",
"core/sr-io",
"core/sr-primitives",
"core/sr-staking-primitives",
"core/sr-sandbox",
"core/sr-std",
"core/sr-version",
"core/state-machine",
"core/telemetry",
"core/test-client",
"core/test-runtime",
"core/test-runtime/client",
"core/transaction-pool",
"core/transaction-pool/graph",
"core/transaction-pool/runtime-api",
"core/trie",
"core/utils/fork-tree",
"core/utils/wasm-builder",
"core/utils/wasm-builder-runner",
"core/wasm-interface",
"srml/support",
"srml/support/rpc",
"srml/support/procedural",
"srml/support/procedural/tools",
"srml/support/procedural/tools/derive",
"srml/support/test",
"srml/authorship",
"srml/assets",
"srml/aura",
"srml/balances",
"srml/contracts",
"srml/contracts/rpc",
"srml/collective",
"srml/democracy",
"srml/elections",
"srml/elections-phragmen",
"srml/example",
"srml/executive",
"srml/finality-tracker",
"srml/generic-asset",
"srml/grandpa",
"srml/im-online",
"srml/authority-discovery",
"srml/indices",
"srml/membership",
"srml/metadata",
"srml/nicks",
"srml/offences",
"srml/randomness-collective-flip",
"srml/scored-pool",
"srml/session",
"srml/staking",
"srml/staking/reward-curve",
"srml/sudo",
"srml/system",
"srml/system/rpc",
"srml/timestamp",
"srml/treasury",
"srml/transaction-payment",
"srml/transaction-payment/rpc",
"srml/utility",
"srml/evm",
"node/cli",
"node/executor",
"node/primitives",
"node/rpc",
"node/rpc-client",
"node/runtime",
"node/testing",
"node-template",
"subkey",
"test-utils/chain-spec-builder",
"bin/node-template",
"bin/node-template/runtime",
"bin/node/cli",
"bin/node/executor",
"bin/node/primitives",
"bin/node/rpc-client",
"bin/node/rpc",
"bin/node/runtime",
"bin/node/testing",
"bin/subkey",
"client",
"client/api",
"client/authority-discovery",
"client/basic-authorship",
"client/block-builder",
"client/chain-spec",
"client/chain-spec/derive",
"client/cli",
"client/consensus/aura",
"client/consensus/babe",
"client/consensus/pow",
"client/consensus/slots",
"client/consensus/uncles",
"client/db",
"client/executor",
"client/executor/runtime-test",
"client/finality-grandpa",
"client/header-metadata",
"client/keystore",
"client/network",
"client/offchain",
"client/rpc-servers",
"client/rpc",
"client/rpc/api",
"client/service",
"client/service/test",
"client/state-db",
"client/telemetry",
"client/transaction-pool",
"client/transaction-pool/graph",
"client/utils/wasm-builder-runner",
"paint/assets",
"paint/aura",
"paint/authority-discovery",
"paint/authorship",
"paint/babe",
"paint/balances",
"paint/collective",
"paint/contracts",
"paint/contracts/rpc",
"paint/contracts/rpc/runtime-api",
"paint/democracy",
"paint/elections-phragmen",
"paint/elections",
"paint/evm",
"paint/example",
"paint/executive",
"paint/finality-tracker",
"paint/generic-asset",
"paint/grandpa",
"paint/im-online",
"paint/indices",
"paint/membership",
"paint/metadata",
"paint/nicks",
"paint/offences",
"paint/randomness-collective-flip",
"paint/scored-pool",
"paint/session",
"paint/staking",
"paint/staking/reward-curve",
"paint/sudo",
"paint/support",
"paint/support/procedural",
"paint/support/procedural/tools",
"paint/support/procedural/tools/derive",
"paint/support/rpc",
"paint/support/test",
"paint/system",
"paint/system/rpc",
"paint/system/rpc/runtime-api",
"paint/timestamp",
"paint/transaction-payment",
"paint/transaction-payment/rpc",
"paint/transaction-payment/rpc/runtime-api",
"paint/treasury",
"paint/utility",
"primitives/application-crypto",
"primitives/authority-discovery",
"primitives/block-builder/runtime-api",
"primitives/consensus/aura",
"primitives/consensus/babe",
"primitives/consensus/common",
"primitives/consensus/pow",
"primitives/core",
"primitives/core/debug-derive",
"primitives/core/storage",
"primitives/externalities",
"primitives/finality-grandpa",
"primitives/inherents",
"primitives/keyring",
"primitives/offchain",
"primitives/panic-handler",
"primitives/peerset",
"primitives/phragmen",
"primitives/rpc",
"primitives/runtime-interface",
"primitives/runtime-interface/proc-macro",
"primitives/runtime-interface/test-wasm",
"primitives/serializer",
"primitives/session",
"primitives/sr-api",
"primitives/sr-api/proc-macro",
"primitives/sr-api/test",
"primitives/sr-arithmetic",
"primitives/sr-io",
"primitives/sr-primitives",
"primitives/sr-sandbox",
"primitives/sr-staking-primitives",
"primitives/sr-std",
"primitives/sr-version",
"primitives/state-machine",
"primitives/transaction-pool/runtime-api",
"primitives/trie",
"primitives/wasm-interface",
"test/utils/chain-spec-builder",
"test/utils/client",
"test/utils/primitives",
"test/utils/runtime",
"test/utils/runtime/client",
"test/utils/transaction-factory",
"utils/build-script-utils",
"utils/fork-tree",
"utils/wasm-builder",
]
[profile.release]
+7 -512
View File
@@ -4,525 +4,20 @@
:toc:
:sectnums:
== Intro in one sentence
Substrate is a next-generation framework for blockchain innovation.
== Description
== Trying it out
At its heart, Substrate is a combination of three technologies: https://webassembly.org/[WebAssembly], https://libp2p.io/[Libp2p] and GRANDPA Consensus. About GRANDPA, see this https://hackmd.io/Jd0byWX0RiqFiXUVC78Bdw?view#GRANDPA[definition], https://medium.com/polkadot-network/grandpa-block-finality-in-polkadot-an-introduction-part-1-d08a24a021b5[introduction] and https://github.com/w3f/consensus/blob/master/pdf/grandpa.pdf[formal specification]. It is both a library for building new blockchains and a "skeleton key" of a blockchain client, able to synchronize to any Substrate-based chain.
Simply go to [substrate.dev](https://substrate.dev) and follow the instructions as listed.
Substrate chains have three distinct features that make them "next-generation": a dynamic, self-defining state-transition function; light-client functionality from day one; and a progressive consensus algorithm with fast block production and adaptive, definite finality. The STF, encoded in WebAssembly, is known as the "runtime". This defines the `execute_block` function, and can specify everything from the staking algorithm, transaction semantics, logging mechanisms and procedures for replacing any aspect of itself or of the blockchain's state ("governance"). Because the runtime is entirely dynamic all of these can be switched out or upgraded at any time. A Substrate chain is very much a "living organism".
== Contributions & Code of Conduct
See also https://www.parity.io/what-is-substrate/.
Please follow the contributions guidelines as outlined in [`docs/CONTRIBUTING.adoc`](docs/CONTRIBUTING.adoc). In all communications and contributions, this project follows the [Contributor Covenant Code of Conduct](docs/CODE_OF_CONDUCT.adoc).
== Usage
== Security
Substrate is still an early stage project, and while it has already been used as the basis of major projects like Polkadot, using it is still a significant undertaking. In particular, you should have a good knowledge of blockchain concepts and basic cryptography. Terminology like header, block, client, hash, transaction and signature should be familiar. At present you will need a working knowledge of Rust to be able to do anything interesting (though eventually, we aim for this not to be the case).
Substrate is designed for use in one of three ways:
**1. Trivial**: By running the Substrate binary `substrate` and configuring it with a genesis block that includes the current demonstration runtime. In this case, you just build Substrate, configure a JSON file, and launch your own blockchain. This affords you the least amount of customizability, primarily allowing you to change the genesis parameters of the various included runtime modules such as balances, staking, block-period, fees, and governance.
**2. Modular**: By hacking together modules from the Substrate Runtime Module Library (SRML) into a new runtime and possibly altering or reconfiguring the Substrate client's block authoring logic. This affords you a very large amount of freedom over your blockchain's logic, letting you change datatypes, add or remove modules, and crucially, add your own modules. Much can be changed without touching the block authoring logic (since it is generic). If this is the case, then the existing Substrate binary can be used for block authoring and syncing. If the block authoring logic needs to be tweaked, then a new, altered block authoring binary must be built as a separate project and used by validators. This is how the Polkadot relay chain is built and should suffice for almost all circumstances in the near to mid-term.
**3. Generic**: The entire SRML can be ignored and the entire runtime designed and implemented from scratch. If desired, this can be done in a language other than Rust, provided it can target WebAssembly. If the runtime can be made compatible with the existing client's block authoring logic, then you can simply construct a new genesis block from your Wasm blob and launch your chain with the existing Rust-based Substrate client. If not, then you'll need to alter the client's block authoring logic accordingly. This is probably a useless option for most projects right now, but provides complete flexibility allowing for a long-term, far-reaching upgrade path for the Substrate paradigm.
=== The Basics of Substrate
Substrate is a blockchain platform with a completely generic state transition function. That said, it does come with both standards and conventions (particularly regarding the Runtime Module Library) regarding underlying data structures. Roughly speaking, these core datatypes correspond to +trait+s in terms of the actual non-negotiable standard and generic +struct+s in terms of the convention.
```
Header := Parent + ExtrinsicsRoot + StorageRoot + Digest
Block := Header + Extrinsics + Justifications
```
=== Extrinsics
Extrinsics in Substrate are pieces of information from "the outside world" that are contained in the blocks of the chain. You might think "ahh, that means *transactions*": in fact, no. Extrinsics fall into two broad categories of which only one is *transactions*. The other is known as *inherents*. The difference between these two is that transactions are signed and gossiped on the network and can be deemed useful *per se*. This fits the mold of what you would call transactions in Bitcoin or Ethereum.
Inherents, meanwhile, are not passed on the network and are not signed. They represent data which describes the environment but which cannot call upon anything to prove it such as a signature. Rather they are assumed to be "true" simply because a sufficiently large number of validators have agreed on them being reasonable.
To give an example, there is the timestamp inherent, which sets the current timestamp of the block. This is not a fixed part of Substrate, but does come as part of the Substrate Runtime Module Library to be used as desired. No signature could fundamentally prove that a block were authored at a given time in quite the same way that a signature can "prove" the desire to spend some particular funds. Rather, it is the business of each validator to ensure that they believe the timestamp is set to something reasonable before they agree that the block candidate is valid.
Other examples include the parachain-heads extrinsic in Polkadot and the "note-missed-proposal" extrinsic used in the Substrate Runtime Module Library to determine and punish or deactivate offline validators.
=== Runtime and API
Substrate chains all have a runtime. The runtime is a WebAssembly "blob" that includes a number of entry-points. Some entry-points are required as part of the underlying Substrate specification. Others are merely convention and required for the default implementation of the Substrate client to be able to author blocks.
If you want to develop a chain with Substrate, you will need to implement the `Core` trait. This `Core` trait generates an API with the minimum necessary functionality to interact with your runtime. A special macro is provided called `impl_runtime_apis!` that help you implement runtime API traits. All runtime API trait implementations need to be done in one call of the `impl_runtime_apis!` macro. All parameters and return values need to implement https://crates.io/crates/parity-codec[`parity-codec`] to be encodable and decodable.
Here's a snippet of the Polkadot API implementation as of PoC-3:
```rust
impl_runtime_apis! {
impl client_api::Core<Block> for Runtime {
fn version() -> RuntimeVersion {
VERSION
}
fn execute_block(block: Block) {
Executive::execute_block(block)
}
fn initialize_block(header: <Block as BlockT>::Header) {
Executive::initialize_block(&header)
}
}
// ---snip---
}
```
=== Inherent Extrinsics
The Substrate Runtime Module Library includes functionality for timestamps and slashing. If used, these rely on "trusted" external information being passed in via inherent extrinsics. The Substrate reference block authoring client software will expect to be able to call into the runtime API with collated data (in the case of the reference Substrate authoring client, this is merely the current timestamp and which nodes were offline) in order to return the appropriate extrinsics ready for inclusion. If new inherent extrinsic types and data are to be used in a modified runtime, then it is this function (and its argument type) that would change.
=== Block-authoring Logic
In Substrate, there is a major distinction between blockchain *syncing* and block *authoring* ("authoring" is a more general term for what is called "mining" in Bitcoin). The first case might be referred to as a "full node" (or "light node" - Substrate supports both): authoring necessarily requires a synced node and, therefore, all authoring clients must necessarily be able to synchronize. However, the reverse is not true. The primary functionality that authoring nodes have which is not in "sync nodes" is threefold: transaction queue logic, inherent transaction knowledge and BFT consensus logic. BFT consensus logic is provided as a core element of Substrate and can be ignored since it is only exposed in the SDK under the `authorities()` API entry.
Transaction queue logic in Substrate is designed to be as generic as possible, allowing a runtime to express which transactions are fit for inclusion in a block through the `initialize_block` and `apply_extrinsic` calls. However, more subtle aspects like prioritization and replacement policy must currently be expressed "hard coded" as part of the blockchain's authoring code. That said, Substrate's reference implementation for a transaction queue should be sufficient for an initial chain implementation.
Inherent extrinsic knowledge is again somewhat generic, and the actual construction of the extrinsics is, by convention, delegated to the "soft code" in the runtime. If ever there needs to be additional extrinsic information in the chain, then both the block authoring logic will need to be altered to provide it into the runtime and the runtime's `inherent_extrinsics` call will need to use this extra information in order to construct any additional extrinsic transactions for inclusion in the block.
== Roadmap
=== So far
- 0.1 "PoC-1": PBFT consensus, Wasm runtime engine, basic runtime modules.
- 0.2 "PoC-2": Libp2p
=== In progress
- AfG consensus
- Improved PoS
- Smart contract runtime module
=== The future
- Splitting out runtime modules into separate repo
- Introduce substrate executable (the skeleton-key runtime)
- Introduce basic but extensible transaction queue and block-builder and place them in the executable.
- DAO runtime module
- Audit
== Trying out Substrate Node
Substrate Node is Substrate's pre-baked blockchain client. You can run a development node locally or configure a new chain and launch your own global testnet.
=== On Mac and Ubuntu
To get going as fast as possible, there is a simple script that installs all required dependencies and installs Substrate into your path. Just open a terminal and run:
[source, shell]
----
curl https://getsubstrate.io -sSf | bash
----
You can start a local Substrate development chain with running `substrate --dev`.
To create your own global network/cryptocurrency, you'll need to make a new Substrate Node chain specification file ("chainspec").
First let's get a template chainspec that you can edit. We'll use the "staging" chain, a sort of default chain that the node comes pre-configured with:
[source, shell]
----
substrate build-spec --chain=staging > ~/chainspec.json
----
Now, edit `~/chainspec.json` in your editor. There are a lot of individual fields for each module, and one very large one which contains the WebAssembly code blob for this chain. The easiest field to edit is the block `period`. Change it to 10 (seconds):
[source, json]
----
"timestamp": {
"minimumPeriod": 10
},
----
Now with this new chainspec file, you can build a "raw" chain definition for your new chain:
[source, shell]
----
substrate build-spec --chain ~/chainspec.json --raw > ~/mychain.json
----
This can be fed into Substrate:
[source, shell]
----
substrate --chain ~/mychain.json
----
It won't do much until you start producing blocks though, so to do that you'll need to use the `--validator` option together with passing the seed for the account(s) that is configured to be the initial authorities:
[source, shell]
----
substrate --chain ~/mychain.json --validator
----
You can distribute `mychain.json` so that everyone can synchronize and (depending on your authorities list) validate on your chain.
== Building
=== Hacking on Substrate
If you'd actually like to hack on Substrate, you can just grab the source code and
build it. Ensure you have Rust and the support software installed:
==== Linux and Mac
For Unix-based operating systems, you should run the following commands:
[source, shell]
----
curl https://sh.rustup.rs -sSf | sh
rustup update nightly
rustup target add wasm32-unknown-unknown --toolchain nightly
rustup update stable
----
You will also need to install the following packages:
- Linux:
[source, shell]
sudo apt install cmake pkg-config libssl-dev git clang libclang-dev
- Linux on ARM:
`rust-lld` is required for linking wasm, but is missing on non Tier 1 platforms.
So, use this https://github.com/Plume-org/Plume/blob/master/script/wasm-deps.sh[script]
to build `lld` and create the symlink `/usr/bin/rust-lld` to the build binary.
- Mac:
[source, shell]
brew install cmake pkg-config openssl git llvm
To finish installation of Substrate, jump down to <<shared-steps,shared steps>>.
==== Windows
If you are trying to set up Substrate on Windows, you should do the following:
1. First, you will need to download and install "Build Tools for Visual Studio:"
* You can get it at this link: https://aka.ms/buildtools
* Run the installation file: `vs_buildtools.exe`
* Please ensure the Windows 10 SDK component is included when installing the Visual C++ Build Tools.
* image:https://i.imgur.com/zayVLmu.png[image]
* Restart your computer.
2. Next, you need to install Rust:
* Detailed instructions are provided by the https://doc.rust-lang.org/book/ch01-01-installation.html#installing-rustup-on-windows[Rust Book].
* Download from: https://www.rust-lang.org/tools/install
* Run the installation file: `rustup-init.exe`
> Note that it should not prompt you to install vs_buildtools since you did it in step 1.
* Choose "Default Installation."
* To get started, you need Cargo's bin directory (%USERPROFILE%\.cargo\bin) in your PATH environment variable. Future applications will automatically have the correct environment, but you may need to restart your current shell.
3. Then, you will need to run some commands in CMD to set up your Wasm Build Environment:
rustup update nightly
rustup update stable
rustup target add wasm32-unknown-unknown --toolchain nightly
4. Then, you need to install LLVM: https://releases.llvm.org/download.html
5. Next, you need to install OpenSSL, which we will do with `vcpkg`:
mkdir \Tools
cd \Tools
git clone https://github.com/Microsoft/vcpkg.git
cd vcpkg
.\bootstrap-vcpkg.bat
.\vcpkg.exe install openssl:x64-windows-static
6. After, you need to add OpenSSL to your System Variables. Note that in order for the following commands to work, you need to use Windows Powershell:
$env:OPENSSL_DIR = 'C:\Tools\vcpkg\installed\x64-windows-static'
$env:OPENSSL_STATIC = 'Yes'
[System.Environment]::SetEnvironmentVariable('OPENSSL_DIR', $env:OPENSSL_DIR, [System.EnvironmentVariableTarget]::User)
[System.Environment]::SetEnvironmentVariable('OPENSSL_STATIC', $env:OPENSSL_STATIC, [System.EnvironmentVariableTarget]::User)
7. Finally, you need to install `cmake`: https://cmake.org/download/
==== Shared Steps
Then, grab the Substrate source code:
[source, shell]
----
git clone https://github.com/paritytech/substrate.git
cd substrate
----
Then build the code:
[source, shell]
----
cargo build # Builds all native code
----
You can run all the tests if you like:
[source, shell]
cargo test --all
Or just run the tests of a specific package (i.e. `cargo test -p srml-assets`)
You can start a development chain with:
[source, shell]
cargo run --release -- --dev
Detailed logs may be shown by running the node with the following environment variables set: `RUST_LOG=debug RUST_BACKTRACE=1 cargo run --release \-- --dev`.
If you want to see the multi-node consensus algorithm in action locally, then you can create a local testnet with two validator nodes for Alice and Bob, who are the initial authorities of the genesis chain specification that have been endowed with a testnet DOTs. We'll give each node a name and expose them so they are listed on link:https://telemetry.polkadot.io/#/Local%20Testnet[Telemetry]. You'll need two terminal windows open.
We'll start Alice's Substrate node first on default TCP port 30333 with her chain database stored locally at `/tmp/alice`. The Bootnode ID of her node is `QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR`, which is generated from the `--node-key` value that we specify below:
[source, shell]
cargo run --release \-- \
--base-path /tmp/alice \
--chain=local \
--alice \
--node-key 0000000000000000000000000000000000000000000000000000000000000001 \
--telemetry-url ws://telemetry.polkadot.io:1024 \
--validator
In the second terminal, we'll run the following to start Bob's Substrate node on a different TCP port of 30334, and with his chain database stored locally at `/tmp/bob`. We'll specify a value for the `--bootnodes` option that will connect his node to Alice's Bootnode ID on TCP port 30333:
[source, shell]
cargo run --release \-- \
--base-path /tmp/bob \
--bootnodes /ip4/127.0.0.1/tcp/30333/p2p/QmRpheLN4JWdAnY7HGJfWFNbfkQCb6tFf4vvA6hgjMZKrR \
--chain=local \
--bob \
--port 30334 \
--telemetry-url ws://telemetry.polkadot.io:1024 \
--validator
Additional Substrate CLI usage options are available and may be shown by running `cargo run \-- --help`.
=== WASM binaries
The WASM binaries are built during the normal `cargo build` process. To control the WASM binary building,
we support multiple environment variables:
* `SKIP_WASM_BUILD` - Skips building any WASM binary. This is useful when only native should be recompiled.
* `BUILD_DUMMY_WASM_BINARY` - Builds dummy WASM binaries. These dummy binaries are empty and useful
for `cargo check` runs.
* `WASM_BUILD_TYPE` - Sets the build type for building WASM binaries. Supported values are `release` or `debug`.
By default the build type is equal to the build type used by the main build.
* `TRIGGER_WASM_BUILD` - Can be set to trigger a WASM build. On subsequent calls the value of the variable
needs to change. As WASM builder instructs `cargo` to watch for file changes
this environment variable should only be required in certain circumstances.
* `WASM_TARGET_DIRECTORY` - Will copy any build WASM binary to the given directory. The path needs
to be absolute.
* `WASM_BUILD_RUSTFLAGS` - Extend `RUSTFLAGS` given to `cargo build` while building the wasm binary.
* `WASM_BUILD_NO_COLOR` - Disable color output of the wasm build.
Each project can be skipped individually by using the environment variable `SKIP_PROJECT_NAME_WASM_BUILD`.
Where `PROJECT_NAME` needs to be replaced by the name of the cargo project, e.g. `node-runtime` will
be `NODE_RUNTIME`.
[[flaming-fir]]
=== Joining the Flaming Fir Testnet
Flaming Fir is the new testnet for Substrate master (2.0) to test the latest development features. Please note that master is not compatible with the BBQ Birch, Charred Cherry, Dried Danta or Emberic Elm testnets. Ensure you have the dependencies listed above before compiling.
Since Flaming Fir is targeting the master branch we make absolutely no guarantees of stability and/or persistence of the network. We might reset the chain at any time if it is necessary to deploy new changes. Currently, the validators are running with a client built from `d013bd900`, if you build from this commit you should be able to successfully sync, later commits may not work as new breaking changes may be introduced in master.
Latest known working version: `a2a0eb5398d6223e531455b4c155ef053a4a3a2b`
[source, shell]
----
git clone https://github.com/paritytech/substrate.git
cd substrate
git checkout -b flaming-fir a2a0eb5398d6223e531455b4c155ef053a4a3a2b
----
You can run the tests if you like:
[source, shell]
cargo test --all
Start your node:
[source, shell]
cargo run --release \--
To see a list of command line options, enter:
[source, shell]
cargo run --release \-- --help
For example, you can choose a custom node name:
[source, shell]
cargo run --release \-- --name my_custom_name
If you are successful, you will see your node syncing at https://telemetry.polkadot.io/#/Flaming%20Fir
=== Joining the Emberic Elm Testnet
Emberic Elm is the testnet for Substrate 1.0. Please note that 1.0 is not compatible with the BBQ Birch, Charred Cherry, Dried Danta or Flaming Fir testnets.
In order to join the Emberic Elm testnet you should build from the `v1.0` branch. Ensure you have the dependencies listed above before compiling.
[source, shell]
----
git clone https://github.com/paritytech/substrate.git
cd substrate
git checkout -b v1.0 origin/v1.0
----
You can then follow the same steps for building and running as described above in <<flaming-fir>>.
== Key management
Keys in Substrate are stored in the keystore in the file system. To store keys into this keystore,
you need to use one of the two provided RPC calls. If your keys are encrypted or should be encrypted
by the keystore, you need to provide the key using one of the cli arguments `--password`,
`--password-interactive` or `--password-filename`.
=== Recommended RPC call
For most users who want to run a validator node, the `author_rotateKeys` RPC call is sufficient.
The RPC call will generate `N` Session keys for you and return their public keys. `N` is the number
of session keys configured in the runtime. The output of the RPC call can be used as input for the
`session::set_keys` transaction.
```
curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_rotateKeys", "id":1 }' localhost:9933
```
=== Advanced RPC call
If the Session keys need to match a fixed seed, they can be set individually key by key. The RPC call
expects the key seed and the key type. The key types supported by default in Substrate are listed
https://github.com/paritytech/substrate/blob/master/core/primitives/src/crypto.rs#L767[here], but the
user can declare any key type.
```
curl -H 'Content-Type: application/json' --data '{ "jsonrpc":"2.0", "method":"author_insertKey", "params":["KEY_TYPE", "SEED", "PUBLIC"],"id":1 }' localhost:9933
```
`KEY_TYPE` - needs to be replaced with the 4-character key type identifier.
`SEED` - is the seed of the key.
`PUBLIC` - public key for the given key.
== Documentation
=== Viewing documentation for Substrate packages
You can generate documentation for a Substrate Rust package and have it automatically open in your web browser using https://doc.rust-lang.org/rustdoc/what-is-rustdoc.html#using-rustdoc-with-cargo[rustdoc with Cargo],
(of the The Rustdoc Book), by running the following command:
```
cargo doc --package <spec> --open
```
Replacing `<spec>` with one of the following (i.e. `cargo doc --package substrate --open`):
* All Substrate Packages
[source, shell]
substrate
* Substrate Core
[source, shell]
substrate, substrate-cli, substrate-client, substrate-client-db,
substrate-consensus-common, substrate-consensus-rhd,
substrate-executor, substrate-finality-grandpa, substrate-keyring, substrate-keystore, substrate-network,
substrate-network-libp2p, substrate-primitives, substrate-rpc, substrate-rpc-servers,
substrate-serializer, substrate-service, substrate-service-test, substrate-state-db,
substrate-state-machine, substrate-telemetry, substrate-test-client,
substrate-test-runtime, substrate-transaction-graph, substrate-transaction-pool,
substrate-trie
* Substrate Runtime
[source, shell]
sr-api, sr-io, sr-primitives, sr-sandbox, sr-std, sr-version
* Substrate Runtime Module Library (SRML)
[source, shell]
srml-assets, srml-balances, srml-consensus, srml-contracts, srml-council, srml-democracy, srml-example,
srml-executive, srml-metadata, srml-session, srml-staking, srml-support, srml-system, srml-timestamp,
srml-treasury
* Node
[source, shell]
node-cli, node-consensus, node-executor, node-network, node-primitives, node-runtime
* Subkey
[source, shell]
subkey
=== Contributing to documentation for Substrate packages
https://doc.rust-lang.org/1.9.0/book/documentation.html[Document source code] for Substrate packages by annotating the source code with documentation comments.
Example (generic):
```markdown
/// Summary
///
/// Description
///
/// # Panics
///
/// # Errors
///
/// # Safety
///
/// # Examples
///
/// Summary of Example 1
///
/// ```rust
/// // insert example 1 code here
/// ```
///
```
* Important notes:
** Documentation comments must use annotations with a triple slash `///`
** Modules are documented using `//!`
```
//! Summary (of module)
//!
//! Description (of module)
```
* Special section header is indicated with a hash `#`.
** `Panics` section requires an explanation if the function triggers a panic
** `Errors` section is for describing conditions under which a function of method returns `Err(E)` if it returns a `Result<T, E>`
** `Safety` section requires an explanation if the function is `unsafe`
** `Examples` section includes examples of using the function or method
* Code block annotations for examples are included between triple graves, as shown above.
Instead of including the programming language to use for syntax highlighting as the annotation
after the triple graves, alternative annotations include the `ignore`, `text`, `should_panic`, or `no_run`.
* Summary sentence is a short high level single sentence of its functionality
* Description paragraph is for details additional to the summary sentence
* Missing documentation annotations may be used to identify where to generate warnings with `#![warn(missing_docs)]`
or errors `#![deny(missing_docs)]`
* Hide documentation for items with `#[doc(hidden)]`
=== Contributing to documentation (tests, extended examples, macros) for Substrate packages
The code block annotations in the `# Example` section may be used as https://doc.rust-lang.org/1.9.0/book/documentation.html#documentation-as-tests[documentation as tests and for extended examples].
* Important notes:
** Rustdoc will automatically add a `main()` wrapper around the code block to test it
** https://doc.rust-lang.org/1.9.0/book/documentation.html#documenting-macros[Documenting macros].
** Documentation as tests examples are included when running `cargo test`
== Contributing
=== Contributing Guidelines
include::CONTRIBUTING.adoc[]
=== Contributor Code of Conduct
include::CODE_OF_CONDUCT.adoc[]
The security policy and procedures can be found in [`docs/SECURITY.md`](docs/SECURITY.md).
== License
https://github.com/paritytech/substrate/blob/master/LICENSE[LICENSE]
GPL 3.0 see `LICENSE`-file in the repo root.
+41
View File
@@ -0,0 +1,41 @@
[package]
name = "node-template"
version = "2.0.0"
authors = ["Anonymous"]
build = "build.rs"
edition = "2018"
[[bin]]
name = "node-template"
path = "src/main.rs"
[dependencies]
derive_more = "0.15.0"
futures = "0.1.29"
ctrlc = { version = "3.1.3", features = ["termination"] }
log = "0.4.8"
tokio = "0.1.22"
exit-future = "0.1.4"
parking_lot = "0.9.0"
codec = { package = "parity-scale-codec", version = "1.0.0" }
trie-root = "0.15.2"
sr-io = { path = "../../primitives/sr-io" }
substrate-cli = { path = "../../client/cli" }
primitives = { package = "substrate-primitives", path = "../../primitives/core" }
substrate-executor = { path = "../../client/executor" }
substrate-service = { path = "../../client/service" }
inherents = { package = "substrate-inherents", path = "../../primitives/inherents" }
transaction-pool = { package = "substrate-transaction-pool", path = "../../client/transaction-pool" }
network = { package = "substrate-network", path = "../../client/network" }
aura = { package = "substrate-consensus-aura", path = "../../client/consensus/aura" }
aura-primitives = { package = "substrate-consensus-aura-primitives", path = "../../primitives/consensus/aura" }
grandpa = { package = "substrate-finality-grandpa", path = "../../client/finality-grandpa" }
grandpa-primitives = { package = "substrate-finality-grandpa-primitives", path = "../../primitives/finality-grandpa" }
substrate-client = { path = "../../client/" }
runtime = { package = "node-template-runtime", path = "runtime" }
sr-primitives = { path = "../../primitives/sr-primitives" }
basic-authorship = { package = "substrate-basic-authorship", path = "../../client/basic-authorship"}
[build-dependencies]
vergen = "3.0.4"
build-script-utils = { package = "substrate-build-script-utils", path = "../../utils/build-script-utils" }
@@ -0,0 +1,67 @@
[package]
name = "node-template-runtime"
version = "2.0.0"
authors = ["Anonymous"]
edition = "2018"
[dependencies]
aura = { package = "paint-aura", path = "../../../paint/aura", default-features = false }
aura-primitives = { package = "substrate-consensus-aura-primitives", path = "../../../primitives/consensus/aura", default-features = false }
balances = { package = "paint-balances", path = "../../../paint/balances", default-features = false }
block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../../primitives/block-builder/runtime-api", default-features = false}
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
executive = { package = "paint-executive", path = "../../../paint/executive", default-features = false }
grandpa = { package = "paint-grandpa", path = "../../../paint/grandpa", default-features = false }
indices = { package = "paint-indices", path = "../../../paint/indices", default-features = false }
inherents = { package = "substrate-inherents", path = "../../../primitives/inherents", default-features = false}
offchain-primitives = { package = "substrate-offchain-primitives", path = "../../../primitives/offchain", default-features = false }
primitives = { package = "substrate-primitives", path = "../../../primitives/core", default-features = false }
randomness-collective-flip = { package = "paint-randomness-collective-flip", path = "../../../paint/randomness-collective-flip", default-features = false }
rstd = { package = "sr-std", path = "../../../primitives/sr-std", default-features = false }
runtime-io = { package = "sr-io", path = "../../../primitives/sr-io", default-features = false }
safe-mix = { version = "1.0.0", default-features = false }
serde = { version = "1.0.101", optional = true, features = ["derive"] }
sr-api = { path = "../../../primitives/sr-api", default-features = false }
sr-primitives = { path = "../../../primitives/sr-primitives", default-features = false }
substrate-session = { path = "../../../primitives/session", default-features = false }
sudo = { package = "paint-sudo", path = "../../../paint/sudo", default-features = false }
support = { package = "paint-support", path = "../../../paint/support", default-features = false }
system = { package = "paint-system", path = "../../../paint/system", default-features = false }
timestamp = { package = "paint-timestamp", path = "../../../paint/timestamp", default-features = false }
transaction-payment = { package = "paint-transaction-payment", path = "../../../paint/transaction-payment", default-features = false }
tx-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../../../primitives/transaction-pool/runtime-api", default-features = false }
version = { package = "sr-version", path = "../../../primitives/sr-version", default-features = false }
[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", path = "../../../client/utils/wasm-builder-runner", version = "1.0.4" }
[features]
default = ["std"]
std = [
"aura-primitives/std",
"aura/std",
"balances/std",
"block-builder-api/std",
"codec/std",
"executive/std",
"grandpa/std",
"indices/std",
"inherents/std",
"offchain-primitives/std",
"primitives/std",
"randomness-collective-flip/std",
"rstd/std",
"runtime-io/std",
"safe-mix/std",
"serde",
"sr-api/std",
"sr-primitives/std",
"substrate-session/std",
"sudo/std",
"support/std",
"system/std",
"timestamp/std",
"transaction-payment/std",
"tx-pool-api/std",
"version/std",
]
@@ -6,7 +6,7 @@
/// For more guidance on Substrate modules, see the example module
/// https://github.com/paritytech/substrate/blob/master/srml/example/src/lib.rs
/// https://github.com/paritytech/substrate/blob/master/paint/example/src/lib.rs
use support::{decl_module, decl_storage, decl_event, dispatch::Result};
use system::ensure_signed;
@@ -12,6 +12,7 @@ use substrate_executor::native_executor_instance;
pub use substrate_executor::NativeExecutor;
use aura_primitives::sr25519::{AuthorityPair as AuraPair};
use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider};
use basic_authorship;
// Our native executor instance.
native_executor_instance!(
@@ -34,41 +34,43 @@ rand = "0.7.2"
structopt = "0.3.3"
# primitives
primitives = { package = "substrate-primitives", path = "../../core/primitives" }
sr-primitives = { path = "../../core/sr-primitives" }
babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../../core/consensus/babe/primitives" }
grandpa_primitives = { package = "substrate-finality-grandpa-primitives", path = "../../core/finality-grandpa/primitives" }
authority-discovery-primitives = { package = "substrate-authority-discovery-primitives", path = "../../core/authority-discovery/primitives"}
authority-discovery-primitives = { package = "substrate-authority-discovery-primitives", path = "../../../primitives/authority-discovery"}
babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../../../primitives/consensus/babe" }
grandpa_primitives = { package = "substrate-finality-grandpa-primitives", path = "../../../primitives/finality-grandpa" }
primitives = { package = "substrate-primitives", path = "../../../primitives/core" }
sr-primitives = { path = "../../../primitives/sr-primitives" }
# core dependencies
runtime-io = { package = "sr-io", path = "../../core/sr-io" }
client = { package = "substrate-client", path = "../../core/client" }
inherents = { package = "substrate-inherents", path = "../../core/inherents" }
chain-spec = { package = "substrate-chain-spec", path = "../../core/chain-spec" }
transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" }
network = { package = "substrate-network", path = "../../core/network" }
babe = { package = "substrate-consensus-babe", path = "../../core/consensus/babe" }
grandpa = { package = "substrate-finality-grandpa", path = "../../core/finality-grandpa" }
authority-discovery = { package = "substrate-authority-discovery", path = "../../core/authority-discovery"}
keyring = { package = "substrate-keyring", path = "../../core/keyring" }
client_db = { package = "substrate-client-db", path = "../../core/client/db", default-features = false }
offchain = { package = "substrate-offchain", path = "../../core/offchain" }
substrate-rpc = { package = "substrate-rpc", path = "../../core/rpc" }
substrate-basic-authorship = { path = "../../core/basic-authorship" }
substrate-service = { path = "../../core/service", default-features = false }
substrate-telemetry = { package = "substrate-telemetry", path = "../../core/telemetry" }
runtime-io = { package = "sr-io", path = "../../../primitives/sr-io" }
client-api = { package = "substrate-client-api", path = "../../../client/api" }
client = { package = "substrate-client", path = "../../../client/" }
inherents = { package = "substrate-inherents", path = "../../../primitives/inherents" }
chain-spec = { package = "substrate-chain-spec", path = "../../../client/chain-spec" }
transaction_pool = { package = "substrate-transaction-pool", path = "../../../client/transaction-pool" }
network = { package = "substrate-network", path = "../../../client/network" }
babe = { package = "substrate-consensus-babe", path = "../../../client/consensus/babe" }
grandpa = { package = "substrate-finality-grandpa", path = "../../../client/finality-grandpa" }
keyring = { package = "substrate-keyring", path = "../../../primitives/keyring" }
client_db = { package = "substrate-client-db", path = "../../../client/db", default-features = false }
offchain = { package = "substrate-offchain", path = "../../../client/offchain" }
substrate-rpc = { package = "substrate-rpc", path = "../../../client/rpc" }
substrate-basic-authorship = { path = "../../../client/basic-authorship" }
substrate-service = { path = "../../../client/service", default-features = false }
substrate-telemetry = { package = "substrate-telemetry", path = "../../../client/telemetry" }
authority-discovery = { package = "substrate-authority-discovery", path = "../../../client/authority-discovery"}
# paint dependencies
indices = { package = "paint-indices", path = "../../../paint/indices" }
timestamp = { package = "paint-timestamp", path = "../../../paint/timestamp", default-features = false }
finality_tracker = { package = "paint-finality-tracker", path = "../../../paint/finality-tracker", default-features = false }
contracts = { package = "paint-contracts", path = "../../../paint/contracts" }
system = { package = "paint-system", path = "../../../paint/system" }
balances = { package = "paint-balances", path = "../../../paint/balances" }
transaction-payment = { package = "paint-transaction-payment", path = "../../../paint/transaction-payment" }
support = { package = "paint-support", path = "../../../paint/support", default-features = false }
im_online = { package = "paint-im-online", path = "../../../paint/im-online", default-features = false }
sr-authority-discovery = { package = "paint-authority-discovery", path = "../../../paint/authority-discovery"}
# srml dependencies
indices = { package = "srml-indices", path = "../../srml/indices" }
timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default-features = false }
finality_tracker = { package = "srml-finality-tracker", path = "../../srml/finality-tracker", default-features = false }
contracts = { package = "srml-contracts", path = "../../srml/contracts" }
system = { package = "srml-system", path = "../../srml/system" }
balances = { package = "srml-balances", path = "../../srml/balances" }
transaction-payment = { package = "srml-transaction-payment", path = "../../srml/transaction-payment" }
support = { package = "srml-support", path = "../../srml/support", default-features = false }
im_online = { package = "srml-im-online", path = "../../srml/im-online", default-features = false }
sr-authority-discovery = { package = "srml-authority-discovery", path = "../../srml/authority-discovery", default-features = false }
# node-specific dependencies
node-runtime = { path = "../runtime" }
@@ -79,8 +81,8 @@ node-executor = { path = "../executor" }
# CLI-specific dependencies
tokio = { version = "0.1.22", optional = true }
exit-future = { version = "0.1.4", optional = true }
substrate-cli = { path = "../../core/cli", optional = true }
transaction-factory = { path = "../../test-utils/transaction-factory", optional = true }
substrate-cli = { path = "../../../client/cli", optional = true }
transaction-factory = { path = "../../../test/utils/transaction-factory", optional = true }
ctrlc = { version = "3.1.3", features = ["termination"], optional = true }
# WASM-specific dependencies
@@ -95,16 +97,16 @@ kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b031
rand6 = { package = "rand", version = "0.6", features = ["wasm-bindgen"], optional = true } # Imported just for the `wasm-bindgen` feature
[dev-dependencies]
keystore = { package = "substrate-keystore", path = "../../core/keystore" }
babe = { package = "substrate-consensus-babe", path = "../../core/consensus/babe", features = ["test-helpers"] }
consensus-common = { package = "substrate-consensus-common", path = "../../core/consensus/common" }
service-test = { package = "substrate-service-test", path = "../../core/service/test" }
keystore = { package = "substrate-keystore", path = "../../../client/keystore" }
babe = { package = "substrate-consensus-babe", path = "../../../client/consensus/babe", features = ["test-helpers"] }
consensus-common = { package = "substrate-consensus-common", path = "../../../primitives/consensus/common" }
service-test = { package = "substrate-service-test", path = "../../../client/service/test" }
futures03 = { package = "futures-preview", version = "0.3.0-alpha.19" }
tempfile = "3.1.0"
[build-dependencies]
substrate-cli = { package = "substrate-cli", path = "../../core/cli" }
build-script-utils = { package = "substrate-build-script-utils", path = "../../core/utils/build-script-utils" }
substrate-cli = { package = "substrate-cli", path = "../../../client/cli" }
build-script-utils = { package = "substrate-build-script-utils", path = "../../../utils/build-script-utils" }
structopt = "0.3.3"
vergen = "3.0.4"

Before

Width:  |  Height:  |  Size: 10 KiB

After

Width:  |  Height:  |  Size: 10 KiB

@@ -283,7 +283,7 @@ pub fn new_full<C: Send + Default + 'static>(config: NodeConfiguration<C>)
TransactionPool<transaction_pool::FullChainApi<ConcreteClient, ConcreteBlock>>,
OffchainWorkers<
ConcreteClient,
<ConcreteBackend as client::backend::Backend<Block, Blake2Hasher>>::OffchainStorage,
<ConcreteBackend as client_api::backend::Backend<Block, Blake2Hasher>>::OffchainStorage,
ConcreteBlock,
>
>,
+48
View File
@@ -0,0 +1,48 @@
[package]
name = "node-executor"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Substrate node implementation in Rust."
edition = "2018"
[dependencies]
trie-root = "0.15.2"
codec = { package = "parity-scale-codec", version = "1.0.0" }
runtime_io = { package = "sr-io", path = "../../../primitives/sr-io" }
state_machine = { package = "substrate-state-machine", path = "../../../primitives/state-machine" }
substrate-executor = { path = "../../../client/executor" }
primitives = { package = "substrate-primitives", path = "../../../primitives/core" }
trie = { package = "substrate-trie", path = "../../../primitives/trie" }
node-primitives = { path = "../primitives" }
node-runtime = { path = "../runtime" }
[dev-dependencies]
node-testing = { path = "../testing" }
test-client = { package = "substrate-test-client", path = "../../../test/utils/client" }
sr-primitives = { path = "../../../primitives/sr-primitives" }
runtime_support = { package = "paint-support", path = "../../../paint/support" }
balances = { package = "paint-balances", path = "../../../paint/balances" }
transaction-payment = { package = "paint-transaction-payment", path = "../../../paint/transaction-payment" }
session = { package = "paint-session", path = "../../../paint/session" }
system = { package = "paint-system", path = "../../../paint/system" }
timestamp = { package = "paint-timestamp", path = "../../../paint/timestamp" }
treasury = { package = "paint-treasury", path = "../../../paint/treasury" }
contracts = { package = "paint-contracts", path = "../../../paint/contracts" }
grandpa = { package = "paint-grandpa", path = "../../../paint/grandpa" }
indices = { package = "paint-indices", path = "../../../paint/indices" }
wabt = "0.9.2"
criterion = "0.3.0"
[features]
wasmtime = [
"substrate-executor/wasmtime",
]
wasmi-errno = [
"substrate-executor/wasmi-errno",
]
stress-test = []
[[bench]]
name = "bench"
harness = false
@@ -5,11 +5,11 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false }
sr-primitives = { path = "../../core/sr-primitives", default-features = false }
primitives = { package = "substrate-primitives", path = "../../../primitives/core", default-features = false }
sr-primitives = { path = "../../../primitives/sr-primitives", default-features = false }
[dev-dependencies]
substrate-serializer = { path = "../../core/serializer" }
substrate-serializer = { path = "../../../primitives/serializer" }
pretty_assertions = "0.6.1"
[features]
@@ -11,4 +11,4 @@ hyper = "0.12.35"
jsonrpc-core-client = { version = "14.0.3", features = ["http", "ws"] }
log = "0.4.8"
node-primitives = { path = "../primitives" }
substrate-rpc = { path = "../../core/rpc", version = "2.0.0" }
substrate-rpc = { path = "../../../client/rpc", version = "2.0.0" }
+16
View File
@@ -0,0 +1,16 @@
[package]
name = "node-rpc"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
client = { package = "substrate-client", path = "../../../client/" }
jsonrpc-core = "14.0.3"
node-primitives = { path = "../primitives" }
node-runtime = { path = "../runtime" }
sr-primitives = { path = "../../../primitives/sr-primitives" }
paint-contracts-rpc = { path = "../../../paint/contracts/rpc/" }
paint-transaction-payment-rpc = { path = "../../../paint/transaction-payment/rpc/" }
paint-system-rpc = { path = "../../../paint/system/rpc/" }
transaction_pool = { package = "substrate-transaction-pool", path = "../../../client/transaction-pool" }
@@ -19,7 +19,7 @@
//! Since `substrate` core functionality makes no assumptions
//! about the modules used inside the runtime, so do
//! RPC methods defined in `substrate-rpc` crate.
//! It means that `core/rpc` can't have any methods that
//! It means that `client/rpc` can't have any methods that
//! need some strong assumptions about the particular runtime.
//!
//! The RPCs available in this crate however can make some assumptions
@@ -41,15 +41,15 @@ pub fn create<C, P, M>(client: Arc<C>, pool: Arc<Pool<P>>) -> jsonrpc_core::IoHa
C: ProvideRuntimeApi,
C: client::blockchain::HeaderBackend<Block>,
C: Send + Sync + 'static,
C::Api: srml_system_rpc::AccountNonceApi<Block, AccountId, Index>,
C::Api: srml_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance>,
C::Api: srml_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance, UncheckedExtrinsic>,
C::Api: paint_system_rpc::AccountNonceApi<Block, AccountId, Index>,
C::Api: paint_contracts_rpc::ContractsRuntimeApi<Block, AccountId, Balance>,
C::Api: paint_transaction_payment_rpc::TransactionPaymentRuntimeApi<Block, Balance, UncheckedExtrinsic>,
P: ChainApi + Sync + Send + 'static,
M: jsonrpc_core::Metadata + Default,
{
use srml_system_rpc::{System, SystemApi};
use srml_contracts_rpc::{Contracts, ContractsApi};
use srml_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
use paint_system_rpc::{System, SystemApi};
use paint_contracts_rpc::{Contracts, ContractsApi};
use paint_transaction_payment_rpc::{TransactionPayment, TransactionPaymentApi};
let mut io = jsonrpc_core::IoHandler::default();
io.extend_with(
+122
View File
@@ -0,0 +1,122 @@
[package]
name = "node-runtime"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
build = "build.rs"
[dependencies]
# third-party dependencies
codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false, features = ["derive"] }
integer-sqrt = { version = "0.1.2" }
safe-mix = { version = "1.0", default-features = false }
rustc-hex = { version = "2.0", optional = true }
serde = { version = "1.0.102", optional = true }
# primitives
authority-discovery-primitives = { package = "substrate-authority-discovery-primitives", path = "../../../primitives/authority-discovery", default-features = false }
babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../../../primitives/consensus/babe", default-features = false }
block-builder-api = { package = "substrate-block-builder-runtime-api", path = "../../../primitives/block-builder/runtime-api", default-features = false}
inherents = { package = "substrate-inherents", path = "../../../primitives/inherents", default-features = false }
node-primitives = { path = "../primitives", default-features = false }
offchain-primitives = { package = "substrate-offchain-primitives", path = "../../../primitives/offchain", default-features = false }
primitives = { package = "substrate-primitives", path = "../../../primitives/core", default-features = false }
rstd = { package = "sr-std", path = "../../../primitives/sr-std", default-features = false }
sr-api = { path = "../../../primitives/sr-api", default-features = false }
sr-primitives = { path = "../../../primitives/sr-primitives", default-features = false }
sr-staking-primitives = { path = "../../../primitives/sr-staking-primitives", default-features = false }
substrate-keyring = { path = "../../../primitives/keyring", optional = true }
substrate-session = { path = "../../../primitives/session", default-features = false }
tx-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../../../primitives/transaction-pool/runtime-api", default-features = false }
version = { package = "sr-version", path = "../../../primitives/sr-version", default-features = false }
# paint dependencies
authority-discovery = { package = "paint-authority-discovery", path = "../../../paint/authority-discovery", default-features = false }
authorship = { package = "paint-authorship", path = "../../../paint/authorship", default-features = false }
babe = { package = "paint-babe", path = "../../../paint/babe", default-features = false }
balances = { package = "paint-balances", path = "../../../paint/balances", default-features = false }
collective = { package = "paint-collective", path = "../../../paint/collective", default-features = false }
contracts = { package = "paint-contracts", path = "../../../paint/contracts", default-features = false }
contracts-rpc-runtime-api = { package = "paint-contracts-rpc-runtime-api", path = "../../../paint/contracts/rpc/runtime-api/", default-features = false }
democracy = { package = "paint-democracy", path = "../../../paint/democracy", default-features = false }
elections-phragmen = { package = "paint-elections-phragmen", path = "../../../paint/elections-phragmen", default-features = false }
executive = { package = "paint-executive", path = "../../../paint/executive", default-features = false }
finality-tracker = { package = "paint-finality-tracker", path = "../../../paint/finality-tracker", default-features = false }
grandpa = { package = "paint-grandpa", path = "../../../paint/grandpa", default-features = false }
im-online = { package = "paint-im-online", path = "../../../paint/im-online", default-features = false }
indices = { package = "paint-indices", path = "../../../paint/indices", default-features = false }
membership = { package = "paint-membership", path = "../../../paint/membership", default-features = false }
nicks = { package = "paint-nicks", path = "../../../paint/nicks", default-features = false }
offences = { package = "paint-offences", path = "../../../paint/offences", default-features = false }
randomness-collective-flip = { package = "paint-randomness-collective-flip", path = "../../../paint/randomness-collective-flip", default-features = false }
session = { package = "paint-session", path = "../../../paint/session", default-features = false, features = ["historical"] }
staking = { package = "paint-staking", path = "../../../paint/staking", default-features = false }
paint-staking-reward-curve = { path = "../../../paint/staking/reward-curve"}
sudo = { package = "paint-sudo", path = "../../../paint/sudo", default-features = false }
support = { package = "paint-support", path = "../../../paint/support", default-features = false }
system = { package = "paint-system", path = "../../../paint/system", default-features = false }
system-rpc-runtime-api = { package = "paint-system-rpc-runtime-api", path = "../../../paint/system/rpc/runtime-api/", default-features = false }
timestamp = { package = "paint-timestamp", path = "../../../paint/timestamp", default-features = false }
treasury = { package = "paint-treasury", path = "../../../paint/treasury", default-features = false }
utility = { package = "paint-utility", path = "../../../paint/utility", default-features = false }
transaction-payment = { package = "paint-transaction-payment", path = "../../../paint/transaction-payment", default-features = false }
transaction-payment-rpc-runtime-api = { package = "paint-transaction-payment-rpc-runtime-api", path = "../../../paint/transaction-payment/rpc/runtime-api/", default-features = false }
[build-dependencies]
wasm-builder-runner = { package = "substrate-wasm-builder-runner", path = "../../../client/utils/wasm-builder-runner", version = "1.0.4" }
[dev-dependencies]
runtime_io = { package = "sr-io", path = "../../../primitives/sr-io" }
[features]
default = ["std"]
std = [
"authority-discovery-primitives/std",
"authority-discovery/std",
"authorship/std",
"babe-primitives/std",
"babe/std",
"balances/std",
"block-builder-api/std",
"codec/std",
"collective/std",
"contracts-rpc-runtime-api/std",
"contracts/std",
"democracy/std",
"elections-phragmen/std",
"executive/std",
"finality-tracker/std",
"grandpa/std",
"im-online/std",
"indices/std",
"inherents/std",
"membership/std",
"nicks/std",
"node-primitives/std",
"offchain-primitives/std",
"offences/std",
"primitives/std",
"randomness-collective-flip/std",
"rstd/std",
"rustc-hex",
"safe-mix/std",
"serde",
"session/std",
"sr-api/std",
"sr-primitives/std",
"sr-staking-primitives/std",
"staking/std",
"substrate-keyring",
"substrate-session/std",
"sudo/std",
"support/std",
"system-rpc-runtime-api/std",
"system/std",
"timestamp/std",
"transaction-payment-rpc-runtime-api/std",
"transaction-payment/std",
"treasury/std",
"tx-pool-api/std",
"utility/std",
"version/std",
]
@@ -20,7 +20,7 @@ fn main() {
build_current_project_with_rustflags(
"wasm_binary.rs",
WasmBuilderSource::CratesOrPath {
path: "../../utils/wasm-builder",
path: "../../../utils/wasm-builder",
version: "1.0.8",
},
// This instructs LLD to export __heap_base as a global variable, which is used by the
@@ -235,7 +235,7 @@ impl session::historical::Trait for Runtime {
type FullIdentificationOf = staking::ExposureOf<Runtime>;
}
srml_staking_reward_curve::build! {
paint_staking_reward_curve::build! {
const REWARD_CURVE: PiecewiseLinear<'static> = curve!(
min_inflation: 0_025_000,
max_inflation: 0_100_000,
+31
View File
@@ -0,0 +1,31 @@
[package]
name = "node-testing"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
description = "Test utilities for Substrate node."
edition = "2018"
[dependencies]
balances = { package = "paint-balances", path = "../../../paint/balances" }
client = { package = "substrate-client", path = "../../../client/" }
codec = { package = "parity-scale-codec", version = "1.0.0" }
contracts = { package = "paint-contracts", path = "../../../paint/contracts" }
grandpa = { package = "paint-grandpa", path = "../../../paint/grandpa" }
indices = { package = "paint-indices", path = "../../../paint/indices" }
keyring = { package = "substrate-keyring", path = "../../../primitives/keyring" }
node-executor = { path = "../executor" }
node-primitives = { path = "../primitives" }
node-runtime = { path = "../runtime" }
primitives = { package = "substrate-primitives", path = "../../../primitives/core" }
runtime-io = { package = "sr-io", path = "../../../primitives/sr-io" }
runtime_support = { package = "paint-support", path = "../../../paint/support" }
session = { package = "paint-session", path = "../../../paint/session" }
sr-primitives = { path = "../../../primitives/sr-primitives" }
staking = { package = "paint-staking", path = "../../../paint/staking" }
substrate-executor = { path = "../../../client/executor" }
system = { package = "paint-system", path = "../../../paint/system" }
test-client = { package = "substrate-test-client", path = "../../../test/utils/client" }
timestamp = { package = "paint-timestamp", path = "../../../paint/timestamp" }
transaction-payment = { package = "paint-transaction-payment", path = "../../../paint/transaction-payment" }
treasury = { package = "paint-treasury", path = "../../../paint/treasury" }
wabt = "0.9.2"
@@ -5,10 +5,10 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
primitives = { package = "substrate-primitives", version = "*", path = "../core/primitives" }
primitives = { package = "substrate-primitives", version = "*", path = "../../primitives/core" }
node-runtime = { version = "*", path = "../node/runtime" }
node-primitives = { version = "*", path = "../node/primitives" }
sr-primitives = { version = "*", path = "../core/sr-primitives" }
sr-primitives = { version = "*", path = "../../primitives/sr-primitives" }
rand = "0.7.2"
clap = { version = "2.33.0", features = ["yaml"] }
tiny-bip39 = "0.6.2"
@@ -17,9 +17,9 @@ substrate-bip39 = "0.3.1"
hex = "0.3.2"
hex-literal = "0.2.1"
codec = { package = "parity-scale-codec", version = "1.0.0" }
system = { package = "srml-system", path = "../srml/system" }
balances = { package = "srml-balances", path = "../srml/balances" }
transaction-payment = { package = "srml-transaction-payment", path = "../srml/transaction-payment" }
system = { package = "paint-system", path = "../../paint/system" }
balances = { package = "paint-balances", path = "../../paint/balances" }
transaction-payment = { package = "paint-transaction-payment", path = "../../paint/transaction-payment" }
[features]
bench = []
-31
View File
@@ -1,31 +0,0 @@
#!/usr/bin/env bash
set -eux
# Enable warnings about unused extern crates
export RUSTFLAGS=" -W unused-extern-crates"
# Install rustup and the specified rust toolchain.
curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain=$RUST_TOOLCHAIN -y
# Load cargo environment. Specifically, put cargo into PATH.
source ~/.cargo/env
rustc --version
rustup --version
cargo --version
case $TARGET in
"native")
sudo apt-get -y update
sudo apt-get install -y cmake pkg-config libssl-dev
cargo test --all --release --locked "$@"
;;
"wasm")
# Install prerequisites and build all wasm projects
./scripts/init.sh
./scripts/build.sh "$@"
;;
esac
@@ -5,36 +5,37 @@ authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
client-api = { package = "substrate-client-api", path = "api" }
block-builder = { package = "substrate-block-builder", path = "block-builder" }
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
consensus = { package = "substrate-consensus-common", path = "../primitives/consensus/common" }
kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
derive_more = { version = "0.15.0" }
executor = { package = "substrate-executor", path = "executor" }
fnv = { version = "1.0.6" }
log = { version = "0.4.8" }
parking_lot = { version = "0.9.0" }
hex-literal = { version = "0.2.1" }
futures = { version = "0.1.29" }
futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] }
consensus = { package = "substrate-consensus-common", path = "../consensus/common" }
executor = { package = "substrate-executor", path = "../executor" }
state-machine = { package = "substrate-state-machine", path = "../state-machine" }
keyring = { package = "substrate-keyring", path = "../keyring" }
trie = { package = "substrate-trie", path = "../trie" }
substrate-telemetry = { path = "../telemetry" }
hash-db = { version = "0.15.2" }
kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
codec = { package = "parity-scale-codec", version = "1.0.0", features = ["derive"] }
primitives = { package = "substrate-primitives", path = "../primitives" }
sr-primitives = { path = "../sr-primitives" }
runtime-version = { package = "sr-version", path = "../sr-version" }
rstd = { package = "sr-std", path = "../sr-std" }
inherents = { package = "substrate-inherents", path = "../inherents" }
sr-api = { path = "../sr-api" }
header-metadata = { package = "substrate-header-metadata", path = "header-metadata" }
block-builder = { package = "substrate-block-builder", path = "../block-builder" }
hex-literal = { version = "0.2.1" }
inherents = { package = "substrate-inherents", path = "../primitives/inherents" }
keyring = { package = "substrate-keyring", path = "../primitives/keyring" }
log = { version = "0.4.8" }
parking_lot = { version = "0.9.0" }
primitives = { package = "substrate-primitives", path = "../primitives/core" }
rstd = { package = "sr-std", path = "../primitives/sr-std" }
runtime-version = { package = "sr-version", path = "../primitives/sr-version" }
sr-api = { path = "../primitives/sr-api" }
sr-primitives = { path = "../primitives/sr-primitives" }
state-machine = { package = "substrate-state-machine", path = "../primitives/state-machine" }
substrate-telemetry = { path = "telemetry" }
trie = { package = "substrate-trie", path = "../primitives/trie" }
[dev-dependencies]
env_logger = "0.7.0"
tempfile = "3.1.0"
client-db = { package = "substrate-client-db", path = "./db", features = ["kvdb-rocksdb"] }
test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" }
test-client = { package = "substrate-test-runtime-client", path = "../test/utils/runtime/client" }
kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" }
panic-handler = { package = "substrate-panic-handler", path = "../primitives/panic-handler" }
+41
View File
@@ -0,0 +1,41 @@
[package]
name = "substrate-client-api"
version = "2.0.0"
authors = ["Parity Technologies <admin@parity.io>"]
edition = "2018"
[dependencies]
block-builder = { package = "substrate-block-builder", path = "../block-builder" }
codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] }
consensus = { package = "substrate-consensus-common", path = "../../primitives/consensus/common" }
derive_more = { version = "0.15.0" }
executor = { package = "substrate-executor", path = "../executor" }
fnv = { version = "1.0.6" }
futures = { version = "0.1.29" }
futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] }
hash-db = { version = "0.15.2", default-features = false }
header-metadata = { package = "substrate-header-metadata", path = "../header-metadata" }
hex-literal = { version = "0.2.1" }
inherents = { package = "substrate-inherents", path = "../../primitives/inherents", default-features = false }
keyring = { package = "substrate-keyring", path = "../../primitives/keyring" }
kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
log = { version = "0.4.8" }
parking_lot = { version = "0.9.0" }
primitives = { package = "substrate-primitives", path = "../../primitives/core", default-features = false }
rstd = { package = "sr-std", path = "../../primitives/sr-std", default-features = false }
runtime-version = { package = "sr-version", path = "../../primitives/sr-version", default-features = false }
sr-api = { path = "../../primitives/sr-api" }
sr-primitives = { path = "../../primitives/sr-primitives", default-features = false }
state-machine = { package = "substrate-state-machine", path = "../../primitives/state-machine" }
substrate-telemetry = { path = "../telemetry" }
trie = { package = "substrate-trie", path = "../../primitives/trie" }
[dev-dependencies]
env_logger = "0.7.0"
tempfile = "3.1.0"
client-db = { package = "substrate-client-db", path = ".././db", features = ["kvdb-rocksdb"] }
test-primitives = { package = "substrate-test-primitives", path = "../../test/utils/primitives" }
test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client" }
kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
panic-handler = { package = "substrate-panic-handler", path = "../../primitives/panic-handler" }
@@ -18,14 +18,19 @@
use std::sync::Arc;
use std::collections::HashMap;
use crate::error;
use crate::light::blockchain::RemoteBlockchain;
use primitives::ChangesTrieConfiguration;
use sr_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay};
use sr_primitives::traits::{Block as BlockT, NumberFor};
use state_machine::backend::Backend as StateBackend;
use state_machine::{ChangesTrieStorage as StateChangesTrieStorage, ChangesTrieTransaction};
use crate::blockchain::well_known_cache_keys;
use crate::{
blockchain::{
Backend as BlockchainBackend, well_known_cache_keys
},
offchain::OffchainStorage,
error,
light::RemoteBlockchain,
};
use consensus::BlockOrigin;
use hash_db::Hasher;
use parking_lot::Mutex;
@@ -36,13 +41,13 @@ pub type StorageCollection = Vec<(Vec<u8>, Option<Vec<u8>>)>;
/// In memory arrays of storage values for multiple child tries.
pub type ChildStorageCollection = Vec<(Vec<u8>, StorageCollection)>;
pub(crate) struct ImportSummary<Block: BlockT> {
pub(crate) hash: Block::Hash,
pub(crate) origin: BlockOrigin,
pub(crate) header: Block::Header,
pub(crate) is_new_best: bool,
pub(crate) storage_changes: Option<(StorageCollection, ChildStorageCollection)>,
pub(crate) retracted: Vec<Block::Hash>,
pub struct ImportSummary<Block: BlockT> {
pub hash: Block::Hash,
pub origin: BlockOrigin,
pub header: Block::Header,
pub is_new_best: bool,
pub storage_changes: Option<(StorageCollection, ChildStorageCollection)>,
pub retracted: Vec<Block::Hash>,
}
/// Import operation wrapper
@@ -51,9 +56,9 @@ pub struct ClientImportOperation<
H: Hasher<Out=Block::Hash>,
B: Backend<Block, H>,
> {
pub(crate) op: B::BlockImportOperation,
pub(crate) notify_imported: Option<ImportSummary<Block>>,
pub(crate) notify_finalized: Vec<Block::Hash>,
pub op: B::BlockImportOperation,
pub notify_imported: Option<ImportSummary<Block>>,
pub notify_finalized: Vec<Block::Hash>,
}
/// State of a new block.
@@ -216,7 +221,7 @@ pub trait Backend<Block, H>: AuxStore + Send + Sync where
/// Associated block insertion operation type.
type BlockImportOperation: BlockImportOperation<Block, H, State=Self::State>;
/// Associated blockchain backend type.
type Blockchain: crate::blockchain::Backend<Block>;
type Blockchain: BlockchainBackend<Block>;
/// Associated state backend type.
type State: StateBackend<H>;
/// Changes trie storage.
@@ -295,26 +300,6 @@ pub trait Backend<Block, H>: AuxStore + Send + Sync where
fn get_import_lock(&self) -> &Mutex<()>;
}
/// Offchain workers local storage.
pub trait OffchainStorage: Clone + Send + Sync {
/// Persist a value in storage under given key and prefix.
fn set(&mut self, prefix: &[u8], key: &[u8], value: &[u8]);
/// Retrieve a value from storage under given key and prefix.
fn get(&self, prefix: &[u8], key: &[u8]) -> Option<Vec<u8>>;
/// Replace the value in storage if given old_value matches the current one.
///
/// Returns `true` if the value has been set and false otherwise.
fn compare_and_set(
&mut self,
prefix: &[u8],
key: &[u8],
old_value: Option<&[u8]>,
new_value: &[u8],
) -> bool;
}
/// Changes trie storage that supports pruning.
pub trait PrunableStateChangesTrieStorage<Block: BlockT, H: Hasher>:
StateChangesTrieStorage<H, NumberFor<Block>>
+148
View File
@@ -0,0 +1,148 @@
// Copyright 2017-2019 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/>.
use std::{cmp::Ord, panic::UnwindSafe, result, cell::RefCell};
use codec::{Encode, Decode};
use sr_primitives::{
generic::BlockId, traits::Block as BlockT, traits::NumberFor,
};
use state_machine::{
self, OverlayedChanges, ExecutionManager, ExecutionStrategy,
ChangesTrieTransaction, StorageProof,
};
use executor::{RuntimeVersion, NativeVersion};
use hash_db::Hasher;
use primitives::{offchain::OffchainExt, Blake2Hasher, NativeOrEncoded};
use sr_api::{ProofRecorder, InitializeBlock};
use crate::error;
/// Method call executor.
pub trait CallExecutor<B, H>
where
B: BlockT,
H: Hasher<Out=B::Hash>,
H::Out: Ord,
{
/// Externalities error type.
type Error: state_machine::Error;
/// Execute a call to a contract on top of state in a block of given hash.
///
/// No changes are made.
fn call(
&self,
id: &BlockId<B>,
method: &str,
call_data: &[u8],
strategy: ExecutionStrategy,
side_effects_handler: Option<OffchainExt>,
) -> Result<Vec<u8>, error::Error>;
/// Execute a contextual call on top of state in a block of a given hash.
///
/// No changes are made.
/// Before executing the method, passed header is installed as the current header
/// of the execution context.
fn contextual_call<
'a,
IB: Fn() -> error::Result<()>,
EM: Fn(
Result<NativeOrEncoded<R>, Self::Error>,
Result<NativeOrEncoded<R>, Self::Error>
) -> Result<NativeOrEncoded<R>, Self::Error>,
R: Encode + Decode + PartialEq,
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
>(
&self,
initialize_block_fn: IB,
at: &BlockId<B>,
method: &str,
call_data: &[u8],
changes: &RefCell<OverlayedChanges>,
initialize_block: InitializeBlock<'a, B>,
execution_manager: ExecutionManager<EM>,
native_call: Option<NC>,
side_effects_handler: Option<OffchainExt>,
proof_recorder: &Option<ProofRecorder<B>>,
enable_keystore: bool,
) -> error::Result<NativeOrEncoded<R>> where ExecutionManager<EM>: Clone;
/// Extract RuntimeVersion of given block
///
/// No changes are made.
fn runtime_version(&self, id: &BlockId<B>) -> Result<RuntimeVersion, error::Error>;
/// Execute a call to a contract on top of given state.
///
/// No changes are made.
fn call_at_state<
S: state_machine::Backend<H>,
F: FnOnce(
Result<NativeOrEncoded<R>, Self::Error>,
Result<NativeOrEncoded<R>, Self::Error>,
) -> Result<NativeOrEncoded<R>, Self::Error>,
R: Encode + Decode + PartialEq,
NC: FnOnce() -> result::Result<R, String> + UnwindSafe,
>(&self,
state: &S,
overlay: &mut OverlayedChanges,
method: &str,
call_data: &[u8],
manager: ExecutionManager<F>,
native_call: Option<NC>,
side_effects_handler: Option<OffchainExt>,
) -> Result<
(
NativeOrEncoded<R>,
(S::Transaction, H::Out),
Option<ChangesTrieTransaction<Blake2Hasher, NumberFor<B>>>
),
error::Error,
>;
/// Execute a call to a contract on top of given state, gathering execution proof.
///
/// No changes are made.
fn prove_at_state<S: state_machine::Backend<H>>(
&self,
mut state: S,
overlay: &mut OverlayedChanges,
method: &str,
call_data: &[u8]
) -> Result<(Vec<u8>, StorageProof), error::Error> {
let trie_state = state.as_trie_backend()
.ok_or_else(||
Box::new(state_machine::ExecutionError::UnableToGenerateProof)
as Box<dyn state_machine::Error>
)?;
self.prove_at_trie_state(trie_state, overlay, method, call_data)
}
/// Execute a call to a contract on top of given trie state, gathering execution proof.
///
/// No changes are made.
fn prove_at_trie_state<S: state_machine::TrieBackendStorage<H>>(
&self,
trie_state: &state_machine::TrieBackend<S, H>,
overlay: &mut OverlayedChanges,
method: &str,
call_data: &[u8]
) -> Result<(Vec<u8>, StorageProof), error::Error>;
/// Get runtime version if supported.
fn native_runtime_version(&self) -> Option<&NativeVersion>;
}
+141
View File
@@ -0,0 +1,141 @@
// Copyright 2019 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/>.
use std::collections::HashMap;
use futures03::channel::mpsc;
use primitives::storage::StorageKey;
use state_machine::ExecutionStrategy;
use sr_primitives::{
traits::{Block as BlockT, NumberFor},
generic::BlockId
};
use consensus::BlockOrigin;
use crate::blockchain::Info;
use crate::notifications::StorageEventStream;
use crate::error;
/// Type that implements `futures::Stream` of block import events.
pub type ImportNotifications<Block> = mpsc::UnboundedReceiver<BlockImportNotification<Block>>;
/// A stream of block finality notifications.
pub type FinalityNotifications<Block> = mpsc::UnboundedReceiver<FinalityNotification<Block>>;
/// Expected hashes of blocks at given heights.
///
/// This may be used as chain spec extension to filter out known, unwanted forks.
pub type ForkBlocks<Block> = Option<HashMap<NumberFor<Block>, <Block as BlockT>::Hash>>;
/// Execution strategies settings.
#[derive(Debug, Clone)]
pub struct ExecutionStrategies {
/// Execution strategy used when syncing.
pub syncing: ExecutionStrategy,
/// Execution strategy used when importing blocks.
pub importing: ExecutionStrategy,
/// Execution strategy used when constructing blocks.
pub block_construction: ExecutionStrategy,
/// Execution strategy used for offchain workers.
pub offchain_worker: ExecutionStrategy,
/// Execution strategy used in other cases.
pub other: ExecutionStrategy,
}
impl Default for ExecutionStrategies {
fn default() -> ExecutionStrategies {
ExecutionStrategies {
syncing: ExecutionStrategy::NativeElseWasm,
importing: ExecutionStrategy::NativeElseWasm,
block_construction: ExecutionStrategy::AlwaysWasm,
offchain_worker: ExecutionStrategy::NativeWhenPossible,
other: ExecutionStrategy::NativeElseWasm,
}
}
}
/// Figure out the block type for a given type (for now, just a `Client`).
pub trait BlockOf {
/// The type of the block.
type Type: BlockT;
}
/// A source of blockchain events.
pub trait BlockchainEvents<Block: BlockT> {
/// Get block import event stream. Not guaranteed to be fired for every
/// imported block.
fn import_notification_stream(&self) -> ImportNotifications<Block>;
/// Get a stream of finality notifications. Not guaranteed to be fired for every
/// finalized block.
fn finality_notification_stream(&self) -> FinalityNotifications<Block>;
/// Get storage changes event stream.
///
/// Passing `None` as `filter_keys` subscribes to all storage changes.
fn storage_changes_notification_stream(
&self,
filter_keys: Option<&[StorageKey]>,
child_filter_keys: Option<&[(StorageKey, Option<Vec<StorageKey>>)]>,
) -> error::Result<StorageEventStream<Block::Hash>>;
}
/// Fetch block body by ID.
pub trait BlockBody<Block: BlockT> {
/// Get block body by ID. Returns `None` if the body is not stored.
fn block_body(&self,
id: &BlockId<Block>
) -> error::Result<Option<Vec<<Block as BlockT>::Extrinsic>>>;
}
/// Provide a list of potential uncle headers for a given block.
pub trait ProvideUncles<Block: BlockT> {
/// Gets the uncles of the block with `target_hash` going back `max_generation` ancestors.
fn uncles(&self, target_hash: Block::Hash, max_generation: NumberFor<Block>)
-> error::Result<Vec<Block::Header>>;
}
/// Client info
#[derive(Debug)]
pub struct ClientInfo<Block: BlockT> {
/// Best block hash.
pub chain: Info<Block>,
/// State Cache Size currently used by the backend
pub used_state_cache_size: Option<usize>,
}
/// Summary of an imported block
#[derive(Clone, Debug)]
pub struct BlockImportNotification<Block: BlockT> {
/// Imported block header hash.
pub hash: Block::Hash,
/// Imported block origin.
pub origin: BlockOrigin,
/// Imported block header.
pub header: Block::Header,
/// Is this the new best block.
pub is_new_best: bool,
/// List of retracted blocks ordered by block number.
pub retracted: Vec<Block::Hash>,
}
/// Summary of a finalized block.
#[derive(Clone, Debug)]
pub struct FinalityNotification<Block: BlockT> {
/// Imported block header hash.
pub hash: Block::Hash,
/// Imported block header.
pub header: Block::Header,
}
+84
View File
@@ -0,0 +1,84 @@
// Copyright 2019 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/>.
//! Substrate client interfaces.
// TODO: make internal
pub mod error;
pub mod backend;
pub mod blockchain;
pub mod light;
pub mod notifications;
pub mod call_executor;
pub mod client;
pub mod offchain;
pub use error::*;
pub use backend::*;
pub use blockchain::*;
pub use light::*;
pub use notifications::*;
pub use call_executor::*;
pub use offchain::*;
pub use client::*;
pub use state_machine::{StorageProof, ExecutionStrategy};
/// Utility methods for the client.
pub mod utils {
use super::HeaderBackend;
use header_metadata::HeaderMetadata;
use crate::error;
use primitives::H256;
use sr_primitives::traits::{Block as BlockT};
use std::borrow::Borrow;
/// Returns a function for checking block ancestry, the returned function will
/// return `true` if the given hash (second parameter) is a descendent of the
/// base (first parameter). If the `current` parameter is defined, it should
/// represent the current block `hash` and its `parent hash`, if given the
/// function that's returned will assume that `hash` isn't part of the local DB
/// yet, and all searches in the DB will instead reference the parent.
pub fn is_descendent_of<'a, Block: BlockT<Hash=H256>, T, H: Borrow<H256> + 'a>(
client: &'a T,
current: Option<(H, H)>,
) -> impl Fn(&H256, &H256) -> Result<bool, error::Error> + 'a
where T: HeaderBackend<Block> + HeaderMetadata<Block, Error=error::Error>,
{
move |base, hash| {
if base == hash { return Ok(false); }
let current = current.as_ref().map(|(c, p)| (c.borrow(), p.borrow()));
let mut hash = hash;
if let Some((current_hash, current_parent_hash)) = current {
if base == current_hash { return Ok(false); }
if hash == current_hash {
if base == current_parent_hash {
return Ok(true);
} else {
hash = current_parent_hash;
}
}
}
let ancestor = header_metadata::lowest_common_ancestor(client, *hash, *base)?;
Ok(ancestor.hash == *base)
}
}
}
+335
View File
@@ -0,0 +1,335 @@
// Copyright 2019 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/>.
//! Substrate light client interfaces
use std::sync::Arc;
use std::collections::{BTreeMap, HashMap};
use std::future::Future;
use sr_primitives::{
traits::{
Block as BlockT, Header as HeaderT, NumberFor,
},
generic::BlockId
};
use primitives::{ChangesTrieConfiguration};
use state_machine::StorageProof;
use header_metadata::HeaderMetadata;
use crate::{
backend::{
AuxStore, NewBlockState,
},
blockchain::{
well_known_cache_keys, HeaderBackend, Cache as BlockchainCache,
},
error::{ Error as ClientError, Result as ClientResult },
};
/// Remote call request.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RemoteCallRequest<Header: HeaderT> {
/// Call at state of given block.
pub block: Header::Hash,
/// Header of block at which call is performed.
pub header: Header,
/// Method to call.
pub method: String,
/// Call data.
pub call_data: Vec<u8>,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option<usize>,
}
/// Remote canonical header request.
#[derive(Clone, Debug, Default, PartialEq, Eq, Hash)]
pub struct RemoteHeaderRequest<Header: HeaderT> {
/// The root of CHT this block is included in.
pub cht_root: Header::Hash,
/// Number of the header to query.
pub block: Header::Number,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option<usize>,
}
/// Remote storage read request.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RemoteReadRequest<Header: HeaderT> {
/// Read at state of given block.
pub block: Header::Hash,
/// Header of block at which read is performed.
pub header: Header,
/// Storage key to read.
pub keys: Vec<Vec<u8>>,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option<usize>,
}
/// Remote storage read child request.
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct RemoteReadChildRequest<Header: HeaderT> {
/// Read at state of given block.
pub block: Header::Hash,
/// Header of block at which read is performed.
pub header: Header,
/// Storage key for child.
pub storage_key: Vec<u8>,
/// Child storage key to read.
pub keys: Vec<Vec<u8>>,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option<usize>,
}
/// Remote key changes read request.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct RemoteChangesRequest<Header: HeaderT> {
/// Changes trie configuration.
pub changes_trie_config: ChangesTrieConfiguration,
/// Query changes from range of blocks, starting (and including) with this hash...
pub first_block: (Header::Number, Header::Hash),
/// ...ending (and including) with this hash. Should come after first_block and
/// be the part of the same fork.
pub last_block: (Header::Number, Header::Hash),
/// Only use digests from blocks up to this hash. Should be last_block OR come
/// after this block and be the part of the same fork.
pub max_block: (Header::Number, Header::Hash),
/// Known changes trie roots for the range of blocks [tries_roots.0..max_block].
/// Proofs for roots of ascendants of tries_roots.0 are provided by the remote node.
pub tries_roots: (Header::Number, Header::Hash, Vec<Header::Hash>),
/// Optional Child Storage key to read.
pub storage_key: Option<Vec<u8>>,
/// Storage key to read.
pub key: Vec<u8>,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option<usize>,
}
/// Key changes read proof.
#[derive(Debug, PartialEq, Eq)]
pub struct ChangesProof<Header: HeaderT> {
/// Max block that has been used in changes query.
pub max_block: Header::Number,
/// All touched nodes of all changes tries.
pub proof: Vec<Vec<u8>>,
/// All changes tries roots that have been touched AND are missing from
/// the requester' node. It is a map of block number => changes trie root.
pub roots: BTreeMap<Header::Number, Header::Hash>,
/// The proofs for all changes tries roots that have been touched AND are
/// missing from the requester' node. It is a map of CHT number => proof.
pub roots_proof: StorageProof,
}
/// Remote block body request
#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)]
pub struct RemoteBodyRequest<Header: HeaderT> {
/// Header of the requested block body
pub header: Header,
/// Number of times to retry request. None means that default RETRY_COUNT is used.
pub retry_count: Option<usize>,
}
/// Light client data fetcher. Implementations of this trait must check if remote data
/// is correct (see FetchedDataChecker) and return already checked data.
pub trait Fetcher<Block: BlockT>: Send + Sync {
/// Remote header future.
type RemoteHeaderResult: Future<Output = Result<Block::Header, ClientError>> + Send + 'static;
/// Remote storage read future.
type RemoteReadResult: Future<Output = Result<HashMap<Vec<u8>, Option<Vec<u8>>>, ClientError>> + Send + 'static;
/// Remote call result future.
type RemoteCallResult: Future<Output = Result<Vec<u8>, ClientError>> + Send + 'static;
/// Remote changes result future.
type RemoteChangesResult: Future<Output = Result<Vec<(NumberFor<Block>, u32)>, ClientError>> + Send + 'static;
/// Remote block body result future.
type RemoteBodyResult: Future<Output = Result<Vec<Block::Extrinsic>, ClientError>> + Send + 'static;
/// Fetch remote header.
fn remote_header(&self, request: RemoteHeaderRequest<Block::Header>) -> Self::RemoteHeaderResult;
/// Fetch remote storage value.
fn remote_read(
&self,
request: RemoteReadRequest<Block::Header>
) -> Self::RemoteReadResult;
/// Fetch remote storage child value.
fn remote_read_child(
&self,
request: RemoteReadChildRequest<Block::Header>
) -> Self::RemoteReadResult;
/// Fetch remote call result.
fn remote_call(&self, request: RemoteCallRequest<Block::Header>) -> Self::RemoteCallResult;
/// Fetch remote changes ((block number, extrinsic index)) where given key has been changed
/// at a given blocks range.
fn remote_changes(&self, request: RemoteChangesRequest<Block::Header>) -> Self::RemoteChangesResult;
/// Fetch remote block body
fn remote_body(&self, request: RemoteBodyRequest<Block::Header>) -> Self::RemoteBodyResult;
}
/// Light client remote data checker.
///
/// Implementations of this trait should not use any prunable blockchain data
/// except that is passed to its methods.
pub trait FetchChecker<Block: BlockT>: Send + Sync {
/// Check remote header proof.
fn check_header_proof(
&self,
request: &RemoteHeaderRequest<Block::Header>,
header: Option<Block::Header>,
remote_proof: StorageProof,
) -> ClientResult<Block::Header>;
/// Check remote storage read proof.
fn check_read_proof(
&self,
request: &RemoteReadRequest<Block::Header>,
remote_proof: StorageProof,
) -> ClientResult<HashMap<Vec<u8>, Option<Vec<u8>>>>;
/// Check remote storage read proof.
fn check_read_child_proof(
&self,
request: &RemoteReadChildRequest<Block::Header>,
remote_proof: StorageProof,
) -> ClientResult<HashMap<Vec<u8>, Option<Vec<u8>>>>;
/// Check remote method execution proof.
fn check_execution_proof(
&self,
request: &RemoteCallRequest<Block::Header>,
remote_proof: StorageProof,
) -> ClientResult<Vec<u8>>;
/// Check remote changes query proof.
fn check_changes_proof(
&self,
request: &RemoteChangesRequest<Block::Header>,
proof: ChangesProof<Block::Header>
) -> ClientResult<Vec<(NumberFor<Block>, u32)>>;
/// Check remote body proof.
fn check_body_proof(
&self,
request: &RemoteBodyRequest<Block::Header>,
body: Vec<Block::Extrinsic>
) -> ClientResult<Vec<Block::Extrinsic>>;
}
/// Light client blockchain storage.
pub trait Storage<Block: BlockT>: AuxStore + HeaderBackend<Block> + HeaderMetadata<Block, Error=ClientError> {
/// Store new header. Should refuse to revert any finalized blocks.
///
/// Takes new authorities, the leaf state of the new block, and
/// any auxiliary storage updates to place in the same operation.
fn import_header(
&self,
header: Block::Header,
cache: HashMap<well_known_cache_keys::Id, Vec<u8>>,
state: NewBlockState,
aux_ops: Vec<(Vec<u8>, Option<Vec<u8>>)>,
) -> ClientResult<()>;
/// Set an existing block as new best block.
fn set_head(&self, block: BlockId<Block>) -> ClientResult<()>;
/// Mark historic header as finalized.
fn finalize_header(&self, block: BlockId<Block>) -> ClientResult<()>;
/// Get last finalized header.
fn last_finalized(&self) -> ClientResult<Block::Hash>;
/// Get headers CHT root for given block. Fails if the block is not pruned (not a part of any CHT).
fn header_cht_root(
&self,
cht_size: NumberFor<Block>,
block: NumberFor<Block>,
) -> ClientResult<Block::Hash>;
/// Get changes trie CHT root for given block. Fails if the block is not pruned (not a part of any CHT).
fn changes_trie_cht_root(
&self,
cht_size: NumberFor<Block>,
block: NumberFor<Block>,
) -> ClientResult<Block::Hash>;
/// Get storage cache.
fn cache(&self) -> Option<Arc<dyn BlockchainCache<Block>>>;
}
/// Remote header.
#[derive(Debug)]
pub enum LocalOrRemote<Data, Request> {
/// When data is available locally, it is returned.
Local(Data),
/// When data is unavailable locally, the request to fetch it from remote node is returned.
Remote(Request),
/// When data is unknown.
Unknown,
}
/// Futures-based blockchain backend that either resolves blockchain data
/// locally, or fetches required data from remote node.
pub trait RemoteBlockchain<Block: BlockT>: Send + Sync {
/// Get block header.
fn header(&self, id: BlockId<Block>) -> ClientResult<LocalOrRemote<
Block::Header,
RemoteHeaderRequest<Block::Header>,
>>;
}
#[cfg(test)]
pub mod tests {
use futures03::future::Ready;
use parking_lot::Mutex;
use crate::error::Error as ClientError;
use test_primitives::{Block, Header, Extrinsic};
use super::*;
pub type OkCallFetcher = Mutex<Vec<u8>>;
fn not_implemented_in_tests<T, E>() -> Ready<Result<T, E>>
where
E: std::convert::From<&'static str>,
{
futures03::future::ready(Err("Not implemented on test node".into()))
}
impl Fetcher<Block> for OkCallFetcher {
type RemoteHeaderResult = Ready<Result<Header, ClientError>>;
type RemoteReadResult = Ready<Result<HashMap<Vec<u8>, Option<Vec<u8>>>, ClientError>>;
type RemoteCallResult = Ready<Result<Vec<u8>, ClientError>>;
type RemoteChangesResult = Ready<Result<Vec<(NumberFor<Block>, u32)>, ClientError>>;
type RemoteBodyResult = Ready<Result<Vec<Extrinsic>, ClientError>>;
fn remote_header(&self, _request: RemoteHeaderRequest<Header>) -> Self::RemoteHeaderResult {
not_implemented_in_tests()
}
fn remote_read(&self, _request: RemoteReadRequest<Header>) -> Self::RemoteReadResult {
not_implemented_in_tests()
}
fn remote_read_child(&self, _request: RemoteReadChildRequest<Header>) -> Self::RemoteReadResult {
not_implemented_in_tests()
}
fn remote_call(&self, _request: RemoteCallRequest<Header>) -> Self::RemoteCallResult {
futures03::future::ready(Ok((*self.lock()).clone()))
}
fn remote_changes(&self, _request: RemoteChangesRequest<Header>) -> Self::RemoteChangesResult {
not_implemented_in_tests()
}
fn remote_body(&self, _request: RemoteBodyRequest<Header>) -> Self::RemoteBodyResult {
not_implemented_in_tests()
}
}
}

Some files were not shown because too many files have changed in this diff Show More