diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 509d0c43803872de424def7be08cc5906116c924..8561cfac8c140ee716ef14f573a79d379037de20 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -219,14 +219,14 @@ check-web-wasm: script: # WASM support is in progress. As more and more crates support WASM, we # should add entries here. See https://github.com/paritytech/substrate/issues/2416 - - time cargo web build -p sr-io - - time cargo web build -p sr-primitives - - time cargo web build -p sr-std - - time cargo web build -p substrate-client - - time cargo web build -p substrate-consensus-aura - - time cargo web build -p substrate-consensus-babe - - time cargo web build -p substrate-consensus-common - - time cargo web build -p substrate-telemetry + - time cargo build --target=wasm32-unknown-unknown -p sr-io + - time cargo build --target=wasm32-unknown-unknown -p sr-primitives + - time cargo build --target=wasm32-unknown-unknown -p sr-std + - time cargo build --target=wasm32-unknown-unknown -p substrate-client + - time cargo build --target=wasm32-unknown-unknown -p substrate-consensus-aura + - time cargo build --target=wasm32-unknown-unknown -p substrate-consensus-babe + - time cargo build --target=wasm32-unknown-unknown -p substrate-consensus-common + - time cargo build --target=wasm32-unknown-unknown -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=bin/node/cli/Cargo.toml --no-default-features --features "browser" --target=wasm32-unknown-unknown - sccache -s @@ -296,7 +296,7 @@ build-linux-subkey: variables: - $DEPLOY_TAG script: - - cd ./subkey + - cd ./bin/subkey - BUILD_DUMMY_WASM_BINARY=1 time cargo build --release --verbose - cd - - sccache -s @@ -323,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).maintain/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 diff --git a/.maintain/gitlab/check_runtime.sh b/.maintain/gitlab/check_runtime.sh index c10dc6ecc7b7ed1787e9bac75582a4be4d2a470f..c4744197598555fb7057c58f41c67d7c85c70aed 100755 --- a/.maintain/gitlab/check_runtime.sh +++ b/.maintain/gitlab/check_runtime.sh @@ -1,7 +1,7 @@ #!/bin/sh # # -# check for any changes in the node/src/runtime, palette/ and core/sr_* trees. if +# check for any changes in the node/src/runtime, palette/ and primitives/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. @@ -12,9 +12,7 @@ set -e # fail on any error # give some context git log --graph --oneline --decorate=short -n 10 - -RUNTIME="node/runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm" -VERSIONS_FILE="node/runtime/src/lib.rs" +VERSIONS_FILE="bin/node/runtime/src/lib.rs" github_label () { echo @@ -29,10 +27,9 @@ 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 '^palette/' -e '^core/sr-' | grep -v -e '^core/sr-arithmetic/fuzzer' + | grep -q -e '^bin/node/src/runtime' -e '^palette/' -e '^primitives/sr-' | grep -v -e '^primitives/sr-arithmetic/fuzzer' then cat <<-EOT @@ -66,7 +63,7 @@ then changes to the runtime sources and changes in the spec version. spec_version: ${sub_spec_version} -> ${add_spec_version} - + EOT exit 0 @@ -101,9 +98,9 @@ else If they do change logic, bump 'spec_version' and rebuild wasm. source file directories: - - node/src/runtime + - bin/node/src/runtime - palette - - core/sr-* + - primitives/sr-* versions file: ${VERSIONS_FILE} diff --git a/Cargo.lock b/Cargo.lock index a5c62e4685aa2fa58f99ef747825b2276ccd4c26..2165f04dd0dcf3d71073c4d5ba264515164f89fc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -465,7 +465,6 @@ dependencies = [ "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1133,11 +1132,10 @@ dependencies = [ [[package]] name = "finality-grandpa" -version = "0.9.1" +version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "hashbrown 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.9 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1267,15 +1265,6 @@ dependencies = [ "futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "futures-channel-preview" -version = "0.3.0-alpha.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "futures-core" version = "0.3.1" @@ -1306,26 +1295,11 @@ dependencies = [ "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "futures-executor-preview" -version = "0.3.0-alpha.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.11.1 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "futures-io" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "futures-io-preview" -version = "0.3.0-alpha.19" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "futures-macro" version = "0.3.1" @@ -1337,29 +1311,11 @@ dependencies = [ "syn 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "futures-preview" -version = "0.3.0-alpha.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-executor-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-io-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "futures-sink" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "futures-sink-preview" -version = "0.3.0-alpha.19" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "futures-task" version = "0.3.1" @@ -1375,6 +1331,11 @@ dependencies = [ "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures-timer" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "futures-util" version = "0.3.1" @@ -1399,16 +1360,19 @@ name = "futures-util-preview" version = "0.3.0-alpha.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", "futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-io-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "futures01" +version = "0.1.29" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "gcc" version = "0.3.55" @@ -1731,7 +1695,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1741,7 +1705,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2676,7 +2640,7 @@ dependencies = [ "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.52 (registry+https://github.com/rust-lang/crates.io-index)", "schannel 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2711,9 +2675,8 @@ dependencies = [ "console_error_panic_hook 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "console_log 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "js-sys 0.3.32 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2907,8 +2870,8 @@ version = "2.0.0" dependencies = [ "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "node-template-runtime 2.0.0", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3178,6 +3141,7 @@ dependencies = [ "paste 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-arithmetic 2.0.0", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3270,7 +3234,7 @@ name = "palette-system-rpc" version = "2.0.0" dependencies = [ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core-client 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-derive 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3417,7 +3381,6 @@ dependencies = [ "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", - "substrate-keyring 2.0.0", "substrate-primitives 2.0.0", ] @@ -3855,6 +3818,7 @@ dependencies = [ name = "pallet-transaction-payment-rpc-runtime-api" version = "2.0.0" dependencies = [ + "palette-support 2.0.0", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.102 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4834,7 +4798,7 @@ dependencies = [ [[package]] name = "security-framework" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5096,7 +5060,7 @@ name = "sp-rpc-api" version = "2.0.0" dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core-client 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-derive 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5132,7 +5096,7 @@ dependencies = [ "criterion 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5415,8 +5379,8 @@ version = "2.0.0" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5451,7 +5415,7 @@ dependencies = [ name = "substrate-basic-authorship" version = "2.0.0" dependencies = [ - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-blockchain 2.0.0", @@ -5539,10 +5503,9 @@ dependencies = [ "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures01 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5572,8 +5535,7 @@ dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", @@ -5609,8 +5571,7 @@ dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", @@ -5674,7 +5635,7 @@ dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5726,7 +5687,7 @@ dependencies = [ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "fork-tree 2.0.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "merlin 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5786,7 +5747,7 @@ name = "substrate-consensus-common" version = "2.0.0" dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5805,7 +5766,7 @@ name = "substrate-consensus-pow" version = "2.0.0" dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-blockchain 2.0.0", @@ -5834,8 +5795,8 @@ dependencies = [ name = "substrate-consensus-slots" version = "2.0.0" dependencies = [ - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5926,10 +5887,10 @@ name = "substrate-finality-grandpa" version = "2.0.0" dependencies = [ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "finality-grandpa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "finality-grandpa 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "fork-tree 2.0.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6020,7 +5981,7 @@ dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "fork-tree 2.0.0", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6067,8 +6028,8 @@ dependencies = [ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.12.35 (registry+https://github.com/rust-lang/crates.io-index)", "hyper-rustls 0.17.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6110,7 +6071,7 @@ dependencies = [ name = "substrate-peerset" version = "2.0.0" dependencies = [ - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6188,7 +6149,7 @@ version = "2.0.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-pubsub 14.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6312,7 +6273,7 @@ dependencies = [ "derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "node-executor 2.0.0", @@ -6363,7 +6324,7 @@ dependencies = [ "env_logger 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", @@ -6410,7 +6371,7 @@ dependencies = [ "substrate-panic-handler 2.0.0", "substrate-primitives 2.0.0", "substrate-trie 2.0.0", - "trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "trie-root 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -6420,8 +6381,8 @@ version = "2.0.0" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", - "futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.13.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -6439,7 +6400,7 @@ dependencies = [ name = "substrate-test-client" version = "2.0.0" dependencies = [ - "futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-scale-codec 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "sp-blockchain 2.0.0", @@ -6502,7 +6463,7 @@ dependencies = [ "substrate-transaction-pool-runtime-api 2.0.0", "substrate-trie 2.0.0", "substrate-wasm-builder-runner 1.0.4", - "trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -6541,7 +6502,7 @@ dependencies = [ "sr-std 2.0.0", "substrate-primitives 2.0.0", "trie-bench 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-db 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", "trie-root 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "trie-standardmap 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -7032,18 +6993,6 @@ dependencies = [ "trie-standardmap 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "trie-db" -version = "0.15.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hashbrown 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "trie-db" version = "0.16.0" @@ -7156,10 +7105,10 @@ dependencies = [ [[package]] name = "unicode-normalization" -version = "0.1.9" +version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -7683,11 +7632,6 @@ name = "xdg" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "yaml-rust" -version = "0.3.5" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "yamux" version = "0.2.2" @@ -7869,7 +7813,7 @@ dependencies = [ "checksum fallible-iterator 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4443176a9f2c162692bd3d352d745ef9413eec5782a80d8fd6f8a1ac692a07f7" "checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa" "checksum file-per-thread-logger 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8505b75b31ef7285168dd237c4a7db3c1f3e0927e7d314e670bc98e854272fe9" -"checksum finality-grandpa 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34754852da8d86bc509715292c73140a5b678656d0b16132acd6737bdb5fd5f8" +"checksum finality-grandpa 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b36ece7dc398ce17438d815f3202d2cdba8fd930452a68b616965662742b7e10" "checksum fixed-hash 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "72fe7539e2c5692c6989f2f9c0457e42f1e5768f96b85c87d273574670ae459f" "checksum fixedbitset 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "86d4de0081402f5e88cdac65c8dcdcc73118c1a7a465e2a05f0da05843a8ea33" "checksum flate2 1.0.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6bd6d6f4752952feb71363cffc9ebac9411b75b87c6ab6058c40c8900cf43c0f" @@ -7884,22 +7828,19 @@ dependencies = [ "checksum futures 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "1b980f2816d6ee8673b6517b52cb0e808a180efc92e5c19d02cdda79066703ef" "checksum futures 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b6f16056ecbb57525ff698bb955162d0cd03bee84e6241c27ff75c08d8ca5987" "checksum futures-channel 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fcae98ca17d102fd8a3603727b9259fcf7fa4239b603d2142926189bc8999b86" -"checksum futures-channel-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "d5e5f4df964fa9c1c2f8bddeb5c3611631cacd93baf810fc8bb2fb4b495c263a" "checksum futures-core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "79564c427afefab1dfb3298535b21eda083ef7935b4f0ecbfcb121f0aec10866" "checksum futures-core-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "b35b6263fb1ef523c3056565fa67b1d16f0a8604ff12b11b08c25f28a734c60a" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum futures-executor 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e274736563f686a837a0568b478bdabfeaec2dca794b5649b04e2fe1627c231" -"checksum futures-executor-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "75236e88bd9fe88e5e8bfcd175b665d0528fe03ca4c5207fabc028c8f9d93e98" "checksum futures-io 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e676577d229e70952ab25f3945795ba5b16d63ca794ca9d2c860e5595d20b5ff" -"checksum futures-io-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "f4914ae450db1921a56c91bde97a27846287d062087d4a652efc09bb3a01ebda" "checksum futures-macro 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52e7c56c15537adb4f76d0b7a76ad131cb4d2f4f32d3b0bcabcbe1c7c5e87764" -"checksum futures-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3b1dce2a0267ada5c6ff75a8ba864b4e679a9e2aa44262af7a3b5516d530d76e" "checksum futures-sink 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "171be33efae63c2d59e6dbba34186fe0d6394fb378069a76dfd80fdcffd43c16" -"checksum futures-sink-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "86f148ef6b69f75bb610d4f9a2336d4fc88c4b5b67129d1a340dd0fd362efeec" "checksum futures-task 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0bae52d6b29cf440e298856fec3965ee6fa71b06aa7495178615953fd669e5f9" "checksum futures-timer 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "878f1d2fc31355fa02ed2372e741b0c17e58373341e6a122569b4623a14a7d33" +"checksum futures-timer 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a1de7508b218029b0f01662ed8f61b1c964b3ae99d6f25462d0f55a595109df6" "checksum futures-util 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c0d66274fb76985d3c62c886d1da7ac4c0903a8c9f754e8fe0f35a6a6cc39e76" "checksum futures-util-preview 0.3.0-alpha.19 (registry+https://github.com/rust-lang/crates.io-index)" = "5ce968633c17e5f97936bd2797b6e38fb56cf16a7422319f7ec2e30d3c470e8d" +"checksum futures01 0.1.29 (registry+https://github.com/rust-lang/crates.io-index)" = "7ef8cbbf52909170053540c6c05a62433ddb60662dabee714e2a882caa864f22" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" "checksum get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "abddb55a898d32925f3148bd281174a68eeb68bbfd9a5938a57b18f506ee4ef7" @@ -8141,7 +8082,7 @@ dependencies = [ "checksum scroll 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "abb2332cb595d33f7edd5700f4cbf94892e680c7f0ae56adab58a35190b66cb1" "checksum scroll_derive 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f8584eea9b9ff42825b46faf46a8c24d2cff13ec152fa2a50df788b87c07ee28" "checksum sct 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e3042af939fca8c3453b7af0f1c66e533a15a86169e39de2657310ade8f98d3c" -"checksum security-framework 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "301c862a6d0ee78f124c5e1710205965fc5c553100dcda6d98f13ef87a763f04" +"checksum security-framework 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8ef2429d7cefe5fd28bd1d2ed41c944547d4ff84776f5935b456da44593a16df" "checksum security-framework-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e31493fc37615debb8c5090a7aeb4a9730bc61e77ab10b9af59f1a202284f895" "checksum semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a3186ec9e65071a2095434b1f5bb24838d4e8e130f584c790f6033c79943537" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" @@ -8221,7 +8162,6 @@ dependencies = [ "checksum toml 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "01d1404644c8b12b16bfcffa4322403a91a451584daaaa7c28d3152e6cbc98cf" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum trie-bench 0.16.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d14da20d0549737c88299aee9e7b46098c30dd2af7cbca0518bdd420f3766191" -"checksum trie-db 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d0b62d27e8aa1c07414549ac872480ac82380bab39e730242ab08d82d7cc098a" "checksum trie-db 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "784a9813d23f18bccab728ab039c39b8a87d0d6956dcdece39e92f5cffe5076e" "checksum trie-root 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0b779f7c1c8fe9276365d9d5be5c4b5adeacf545117bb3f64c974305789c5c0b" "checksum trie-standardmap 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c3161ba520ab28cd8e6b68e1126f1009f6e335339d1a73b978139011703264c8" @@ -8235,7 +8175,7 @@ dependencies = [ "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" -"checksum unicode-normalization 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "09c8070a9942f5e7cfccd93f490fdebd230ee3c3c9f107cb25bad5351ef671cf" +"checksum unicode-normalization 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "f0d98d53dfd9509a7c7f36fa8857b8f1fb699edbddd7dc2fb688db2ae5d0b2c1" "checksum unicode-segmentation 1.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e83e153d1053cbb5a118eeff7fd5be06ed99153f00dbcd8ae310c5fb2b22edc0" "checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" @@ -8290,7 +8230,6 @@ dependencies = [ "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" "checksum xdg 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d089681aa106a86fade1b0128fb5daf07d5867a509ab036d99988dec80429a57" -"checksum yaml-rust 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "e66366e18dc58b46801afbf2ca7661a9f59cc8c5962c29892b6039b4f86fa992" "checksum yamux 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2758f29014c1cb7a6e74c1b1160ac8c8203be342d35b73462fc6a13cc6385423" "checksum zeroize 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "45af6a010d13e4cf5b54c94ba5a2b2eba5596b9e46bf5875612d332a1f2b3f86" "checksum zeroize 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdc979d9b5ead18184c357c4d8a3f81b579aae264e32507223032e64715462d3" diff --git a/bin/node-template/Cargo.toml b/bin/node-template/Cargo.toml index 50714461b5e45fdc38345472ed3ceeb037b0ee98..c3d9a98cca66c436fd41a8fd27255bf61790e211 100644 --- a/bin/node-template/Cargo.toml +++ b/bin/node-template/Cargo.toml @@ -11,11 +11,11 @@ path = "src/main.rs" [dependencies] derive_more = "0.15.0" -futures = "0.1.29" +futures = "0.3.1" +futures01 = { package = "futures", version = "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" diff --git a/bin/node-template/runtime/src/lib.rs b/bin/node-template/runtime/src/lib.rs index 4b7a572da23373ed965155c02b60f9968dda7b12..26bace2eaa2891d500f7ce79e151d318b61c7659 100644 --- a/bin/node-template/runtime/src/lib.rs +++ b/bin/node-template/runtime/src/lib.rs @@ -17,7 +17,6 @@ use sr_primitives::{ use sr_primitives::traits::{ NumberFor, BlakeTwo256, Block as BlockT, StaticLookup, Verify, ConvertInto, IdentifyAccount }; -use sr_primitives::weights::Weight; use sr_api::impl_runtime_apis; use aura_primitives::sr25519::AuthorityId as AuraId; use grandpa::AuthorityList as GrandpaAuthorityList; @@ -32,7 +31,11 @@ pub use sr_primitives::BuildStorage; pub use timestamp::Call as TimestampCall; pub use balances::Call as BalancesCall; pub use sr_primitives::{Permill, Perbill}; -pub use support::{StorageValue, construct_runtime, parameter_types, traits::Randomness}; +pub use support::{ + StorageValue, construct_runtime, parameter_types, + traits::Randomness, + weights::Weight, +}; /// An index to a block. pub type BlockNumber = u32; diff --git a/bin/node-template/runtime/src/template.rs b/bin/node-template/runtime/src/template.rs index 0942c04528cb54e8a1c1b60af8422d0f5e1d08d0..f6a12e51ce6c13b4ea6e2695b0ecb59e6dfb9d50 100644 --- a/bin/node-template/runtime/src/template.rs +++ b/bin/node-template/runtime/src/template.rs @@ -70,9 +70,9 @@ mod tests { use super::*; use primitives::H256; - use support::{impl_outer_origin, assert_ok, parameter_types}; + use support::{impl_outer_origin, assert_ok, parameter_types, weights::Weight}; use sr_primitives::{ - traits::{BlakeTwo256, IdentityLookup}, testing::Header, weights::Weight, Perbill, + traits::{BlakeTwo256, IdentityLookup}, testing::Header, Perbill, }; impl_outer_origin! { diff --git a/bin/node-template/src/cli.rs b/bin/node-template/src/cli.rs index ec463a236b2e0f361c44589f77b6537c38ece459..1171a906549357fc2e9373b9a9c026edaeee1c5b 100644 --- a/bin/node-template/src/cli.rs +++ b/bin/node-template/src/cli.rs @@ -1,5 +1,5 @@ use crate::service; -use futures::{future, Future, sync::oneshot}; +use futures::{future::{select, Map}, FutureExt, TryFutureExt, channel::oneshot, compat::Future01CompatExt}; use std::cell::RefCell; use tokio::runtime::Runtime; pub use substrate_cli::{VersionInfo, IntoExit, error}; @@ -69,25 +69,37 @@ where T: AbstractService, E: IntoExit, { - let (exit_send, exit) = exit_future::signal(); + let (exit_send, exit) = oneshot::channel(); let informant = informant::build(&service); - runtime.executor().spawn(exit.until(informant).map(|_| ())); + + let future = select(exit, informant) + .map(|_| Ok(())) + .compat(); + + runtime.executor().spawn(future); // we eagerly drop the service so that the internal exit future is fired, // but we need to keep holding a reference to the global telemetry guard let _telemetry = service.telemetry(); let service_res = { - let exit = e.into_exit().map_err(|_| error::Error::Other("Exit future failed.".into())); - let service = service.map_err(|err| error::Error::Service(err)); - let select = service.select(exit).map(|_| ()).map_err(|(err, _)| err); + let exit = e.into_exit(); + let service = service + .map_err(|err| error::Error::Service(err)) + .compat(); + let select = select(service, exit) + .map(|_| Ok(())) + .compat(); runtime.block_on(select) }; - exit_send.fire(); + let _ = exit_send.send(()); // TODO [andre]: timeout this future #1318 + + use futures01::Future; + let _ = runtime.shutdown_on_idle().wait(); service_res @@ -96,7 +108,7 @@ where // handles ctrl-c pub struct Exit; impl IntoExit for Exit { - type Exit = future::MapErr<oneshot::Receiver<()>, fn(oneshot::Canceled) -> ()>; + type Exit = Map<oneshot::Receiver<()>, fn(Result<(), oneshot::Canceled>) -> ()>; fn into_exit(self) -> Self::Exit { // can't use signal directly here because CtrlC takes only `Fn`. let (exit_send, exit) = oneshot::channel(); @@ -109,6 +121,6 @@ impl IntoExit for Exit { } }).expect("Error setting Ctrl-C handler"); - exit.map_err(drop) + exit.map(drop) } } diff --git a/bin/node/cli/Cargo.toml b/bin/node/cli/Cargo.toml index 40f57d79d378f1504373a17900bbcdbea1875000..c832d303252bed895d5101eae4d40fc668e35167 100644 --- a/bin/node/cli/Cargo.toml +++ b/bin/node/cli/Cargo.toml @@ -25,8 +25,8 @@ crate-type = ["cdylib", "rlib"] # third-party dependencies codec = { package = "parity-scale-codec", version = "1.0.6" } serde = { version = "1.0.102", features = [ "derive" ] } -futures = "0.1.29" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } +futures01 = { package = "futures", version = "0.1.29" } +futures = { version = "0.3.1", features = ["compat"] } hex-literal = "0.2.1" jsonrpc-core = "14.0.3" log = "0.4.8" @@ -80,7 +80,6 @@ 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 = "../../../client/cli", optional = true } transaction-factory = { path = "../../../test/utils/transaction-factory", optional = true } ctrlc = { version = "3.1.3", features = ["termination"], optional = true } @@ -101,7 +100,7 @@ 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" } +futures = "0.3.1" tempfile = "3.1.0" [build-dependencies] @@ -128,7 +127,6 @@ cli = [ "substrate-cli", "transaction-factory", "tokio", - "exit-future", "ctrlc", "substrate-service/rocksdb", "node-executor/wasmi-errno", diff --git a/bin/node/cli/bin/main.rs b/bin/node/cli/bin/main.rs index e4415a2a89e664d21248d189381133a107c6b484..45cf173efb3e94095d910427a6b6c2f2b328b151 100644 --- a/bin/node/cli/bin/main.rs +++ b/bin/node/cli/bin/main.rs @@ -18,8 +18,8 @@ #![warn(missing_docs)] -use futures::sync::oneshot; -use futures::{future, Future}; +use futures::channel::oneshot; +use futures::{future, FutureExt}; use substrate_cli::VersionInfo; use std::cell::RefCell; @@ -27,7 +27,7 @@ use std::cell::RefCell; // handles ctrl-c struct Exit; impl substrate_cli::IntoExit for Exit { - type Exit = future::MapErr<oneshot::Receiver<()>, fn(oneshot::Canceled) -> ()>; + type Exit = future::Map<oneshot::Receiver<()>, fn(Result<(), oneshot::Canceled>) -> ()>; fn into_exit(self) -> Self::Exit { // can't use signal directly here because CtrlC takes only `Fn`. let (exit_send, exit) = oneshot::channel(); @@ -39,7 +39,7 @@ impl substrate_cli::IntoExit for Exit { } }).expect("Error setting Ctrl-C handler"); - exit.map_err(drop) + exit.map(|_| ()) } } diff --git a/bin/node/cli/src/browser.rs b/bin/node/cli/src/browser.rs index ada8a52e1e8b38a8a1eef60f7dddef2468ce9cda..93df41402b9f2c4fbc210644fd5dd17d4278614a 100644 --- a/bin/node/cli/src/browser.rs +++ b/bin/node/cli/src/browser.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see <http://www.gnu.org/licenses/>. use crate::ChainSpec; -use futures::{prelude::*, sync::oneshot, sync::mpsc}; +use futures01::{prelude::*, sync::oneshot, sync::mpsc}; use libp2p::wasm_ext; use log::{debug, info}; use std::sync::Arc; @@ -71,7 +71,7 @@ fn start_inner(wasm_ext: wasm_ext::ffi::Transport) -> Result<Client, Box<dyn std // `service.poll()`. // The rest consists in handling RPC requests. let (rpc_send_tx, mut rpc_send_rx) = mpsc::unbounded::<RpcMessage>(); - wasm_bindgen_futures::spawn_local(futures::future::poll_fn(move || { + wasm_bindgen_futures::spawn_local(futures01::future::poll_fn(move || { loop { match rpc_send_rx.poll() { Ok(Async::Ready(Some(message))) => { diff --git a/bin/node/cli/src/cli.rs b/bin/node/cli/src/cli.rs index 4bddb50b4bcac95d6c9084cbd398dcdb5d037318..f648038d82cb5eefd3207a1d87d8edfe4d14b68d 100644 --- a/bin/node/cli/src/cli.rs +++ b/bin/node/cli/src/cli.rs @@ -185,23 +185,34 @@ where T: AbstractService, E: IntoExit, { - let (exit_send, exit) = exit_future::signal(); + use futures::{FutureExt, TryFutureExt, channel::oneshot, future::select, compat::Future01CompatExt}; + + let (exit_send, exit) = oneshot::channel(); let informant = substrate_cli::informant::build(&service); - runtime.executor().spawn(exit.until(informant).map(|_| ())); + + let future = select(informant, exit) + .map(|_| Ok(())) + .compat(); + + runtime.executor().spawn(future); // we eagerly drop the service so that the internal exit future is fired, // but we need to keep holding a reference to the global telemetry guard let _telemetry = service.telemetry(); let service_res = { - let exit = e.into_exit().map_err(|_| error::Error::Other("Exit future failed.".into())); - let service = service.map_err(|err| error::Error::Service(err)); - let select = service.select(exit).map(|_| ()).map_err(|(err, _)| err); + let exit = e.into_exit(); + let service = service + .map_err(|err| error::Error::Service(err)) + .compat(); + let select = select(service, exit) + .map(|_| Ok(())) + .compat(); runtime.block_on(select) }; - exit_send.fire(); + let _ = exit_send.send(()); // TODO [andre]: timeout this future #1318 let _ = runtime.shutdown_on_idle().wait(); diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index c627e7774fa081cd3a3137ba0ee4e47897511ca3..93422bd3b4eaad2ce84039c8180c1a24912ab67e 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -110,9 +110,9 @@ macro_rules! new_full_start { /// concrete types instead. macro_rules! new_full { ($config:expr, $with_startup_data: expr) => {{ - use futures::sync::mpsc; + use futures01::sync::mpsc; use network::DhtEvent; - use futures03::{ + use futures::{ compat::Stream01CompatExt, stream::StreamExt, future::{FutureExt, TryFutureExt}, @@ -515,7 +515,7 @@ mod tests { digest.push(<DigestItem as CompatibleDigestItem>::babe_pre_digest(babe_pre_digest)); let mut proposer = proposer_factory.init(&parent_header).unwrap(); - let new_block = futures03::executor::block_on(proposer.propose( + let new_block = futures::executor::block_on(proposer.propose( inherent_data, digest, std::time::Duration::from_secs(1), diff --git a/bin/node/executor/src/lib.rs b/bin/node/executor/src/lib.rs index ebff2da1a4b963e8a215851d9885a463e63505dd..0c3c9027b329b1a1b2eaa5d26d2c1eebabc44906 100644 --- a/bin/node/executor/src/lib.rs +++ b/bin/node/executor/src/lib.rs @@ -34,7 +34,11 @@ mod tests { use super::Executor; use {balances, contracts, indices, system, timestamp}; use codec::{Encode, Decode, Joiner}; - use runtime_support::{Hashable, StorageValue, StorageMap, traits::Currency}; + use runtime_support::{ + Hashable, StorageValue, StorageMap, + traits::Currency, + weights::GetDispatchInfo, + }; use state_machine::TestExternalities as CoreTestExternalities; use primitives::{ Blake2Hasher, NeverNativeValue, NativeOrEncoded, map, @@ -43,7 +47,7 @@ mod tests { use sr_primitives::{ Fixed64, traits::{Header as HeaderT, Hash as HashT, Convert}, ApplyResult, - transaction_validity::InvalidTransaction, weights::GetDispatchInfo, + transaction_validity::InvalidTransaction, }; use contracts::ContractAddressFor; use substrate_executor::{NativeExecutor, WasmExecutionMethod}; diff --git a/bin/node/runtime/src/impls.rs b/bin/node/runtime/src/impls.rs index f6d31cc22507b4751ed010b5ca70f1a57588b196..de2efdae4af2ead5541c8f48b2d671ab1184fbb1 100644 --- a/bin/node/runtime/src/impls.rs +++ b/bin/node/runtime/src/impls.rs @@ -17,10 +17,9 @@ //! Some configurable implementations as associated type for the substrate runtime. use node_primitives::Balance; -use sr_primitives::weights::Weight; use sr_primitives::traits::{Convert, Saturating}; use sr_primitives::{Fixed64, Perbill}; -use support::traits::{OnUnbalanced, Currency, Get}; +use support::{traits::{OnUnbalanced, Currency, Get}, weights::Weight}; use crate::{Balances, System, Authorship, MaximumBlockWeight, NegativeImbalance}; pub struct Author; @@ -116,10 +115,10 @@ impl<T: Get<Perbill>> Convert<Fixed64, Fixed64> for TargetedFeeAdjustment<T> { #[cfg(test)] mod tests { use super::*; - use sr_primitives::weights::Weight; use sr_primitives::assert_eq_error_rate; use crate::{MaximumBlockWeight, AvailableBlockRatio, Runtime}; use crate::{constants::currency::*, TransactionPayment, TargetBlockFullness}; + use support::weights::Weight; fn max() -> Weight { MaximumBlockWeight::get() diff --git a/bin/node/runtime/src/lib.rs b/bin/node/runtime/src/lib.rs index 7018ed10eccb57ae7ede71f3a171744953f83518..746508f23522bd3839146ece6db07dd47975b460 100644 --- a/bin/node/runtime/src/lib.rs +++ b/bin/node/runtime/src/lib.rs @@ -22,7 +22,9 @@ use rstd::prelude::*; use support::{ - construct_runtime, parameter_types, traits::{SplitTwoWays, Currency, Randomness} + construct_runtime, parameter_types, + weights::Weight, + traits::{SplitTwoWays, Currency, Randomness}, }; use primitives::u32_trait::{_1, _2, _3, _4}; use node_primitives::{AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, Moment, Signature}; @@ -30,7 +32,6 @@ use sr_api::impl_runtime_apis; use sr_primitives::{Permill, Perbill, ApplyResult, impl_opaque_keys, generic, create_runtime_str}; use sr_primitives::curve::PiecewiseLinear; use sr_primitives::transaction_validity::TransactionValidity; -use sr_primitives::weights::Weight; use sr_primitives::traits::{ self, BlakeTwo256, Block as BlockT, NumberFor, StaticLookup, SaturatedConversion, OpaqueKeys, @@ -732,7 +733,7 @@ mod tests { #[test] fn block_hooks_weight_should_not_exceed_limits() { - use sr_primitives::weights::WeighBlock; + use support::weights::WeighBlock; let check_for_block = |b| { let block_hooks_weight = <AllModules as WeighBlock<BlockNumber>>::on_initialize(b) + diff --git a/bin/subkey/Cargo.toml b/bin/subkey/Cargo.toml index 9e3186569212b742597363378bfc9c259af4d706..2060e5c640fc6d1fb63ff46eb19cfceb480923b7 100644 --- a/bin/subkey/Cargo.toml +++ b/bin/subkey/Cargo.toml @@ -10,7 +10,7 @@ node-runtime = { version = "*", path = "../node/runtime" } node-primitives = { version = "*", path = "../node/primitives" } sr-primitives = { version = "*", path = "../../primitives/sr-primitives" } rand = "0.7.2" -clap = { version = "2.33.0", features = ["yaml"] } +clap = "2.33.0" tiny-bip39 = "0.6.2" rustc-hex = "2.0.1" substrate-bip39 = "0.3.1" diff --git a/bin/subkey/src/cli.yml b/bin/subkey/src/cli.yml deleted file mode 100644 index 5d8cd11b1e6f8def2ff8a4dfb3ae877e6f8d6057..0000000000000000000000000000000000000000 --- a/bin/subkey/src/cli.yml +++ /dev/null @@ -1,144 +0,0 @@ -name: subkey -author: "Parity Team <admin@parity.io>" -about: Utility for generating and restoring with Substrate keys -args: - - ed25519: - short: e - long: ed25519 - help: Use Ed25519/BIP39 cryptography - takes_value: false - - sr25519: - short: s - long: sr25519 - help: Use Schnorr/Ristretto x25519/BIP39 cryptography - takes_value: false - - secp256k1: - short: k - long: secp256k1 - help: Use SECP256k1/ECDSA/BIP39 cryptography - takes_value: false - - password: - short: p - long: password - takes_value: true - required: false - help: The password for the key - - network: - short: n - long: network - takes_value: true - required: false - help: Specify a network. One of substrate (default), polkadot, kusama, or dothereum. -subcommands: - - generate: - about: Generate a random account - args: - - words: - short: w - long: words - help: The number of words in the phrase to generate. One of 12 (default), 15, 18, 21 and 24. - takes_value: true - - inspect: - about: Gets a public key and a SS58 address from the provided Secret URI - args: - - uri: - index: 1 - required: true - help: A Key URI to be inspected. May be a secret seed, secret URI (with derivation paths and password), SS58 or public URI. - - sign: - about: Sign a message, provided on STDIN, with a given (secret) key - args: - - suri: - index: 1 - required: true - help: The secret key URI. - - hex: - short: h - long: hex - help: The message on STDIN is hex-encoded data - takes_value: false - - transfer: - about: Author and sign a Node balances::Transfer transaction with a given (secret) key - args: - - from: - index: 1 - required: true - help: The signing secret key URI. - - to: - index: 2 - required: true - help: The destination account public key URI. - - amount: - index: 3 - required: true - help: The number of units to transfer. - - index: - index: 4 - required: true - help: The signing account's transaction index. - - genesis: - short: g - long: genesis - help: The genesis hash or a recognised chain identifier (dev, elm, alex). - takes_value: true - - verify: - about: Verify a signature for a message, provided on STDIN, with a given (public or secret) key - args: - - sig: - index: 1 - required: true - help: Signature, hex-encoded. - - uri: - index: 2 - required: true - help: The public or secret key URI. - - hex: - short: h - long: hex - help: The message on STDIN is hex-encoded data - takes_value: false - - vanity: - about: Generate a seed that provides a vanity address - args: - - pattern: - index: 1 - help: Desired pattern - - number: - short: n - long: number - help: Number of keys to generate - takes_value: true - default_value: "1" - - sign-transaction: - about: Sign transaction from encoded Call. Returns a signed and encoded UncheckedMortalCompactExtrinsic as hex. - args: - - call: - short: c - long: call - help: The call, hex-encoded. - takes_value: true - required: true - - nonce: - short: n - long: nonce - help: The nonce. - takes_value: true - required: true - - suri: - long: suri - short: s - help: The secret key URI. - takes_value: true - required: true - - password: - short: p - long: password - takes_value: true - help: The password for the key. - required: true - - prior-block-hash: - short: h - long: prior-block-hash - help: The prior block hash, hex-encoded. - takes_value: true - required: true diff --git a/bin/subkey/src/main.rs b/bin/subkey/src/main.rs index 1b537580f57ff739f41c9a552ebbfd28bac7161c..b1dce363146fde5ea8340ebadf9ffc86cde71712 100644 --- a/bin/subkey/src/main.rs +++ b/bin/subkey/src/main.rs @@ -19,7 +19,7 @@ extern crate test; use bip39::{Language, Mnemonic, MnemonicType}; -use clap::{load_yaml, App, ArgMatches}; +use clap::{App, ArgMatches, SubCommand}; use codec::{Decode, Encode}; use hex_literal::hex; use node_primitives::{Balance, Hash, Index, AccountId, Signature}; @@ -155,11 +155,76 @@ impl PublicT for sr25519::Public { fn into_runtime(self) -> AccountPublic { self impl PublicT for ed25519::Public { fn into_runtime(self) -> AccountPublic { self.into() } } impl PublicT for ecdsa::Public { fn into_runtime(self) -> AccountPublic { self.into() } } -fn main() { - let yaml = load_yaml!("cli.yml"); - let matches = App::from_yaml(yaml) +fn get_app<'a, 'b>() -> App<'a, 'b> { + App::new("subkey") + .author("Parity Team <admin@parity.io>") + .about("Utility for generating and restoring with Substrate keys") .version(env!("CARGO_PKG_VERSION")) - .get_matches(); + .args_from_usage(" + -e, --ed25519 'Use Ed25519/BIP39 cryptography' + -k, --secp256k1 'Use SECP256k1/ECDSA/BIP39 cryptography' + -s, --sr25519 'Use Schnorr/Ristretto x25519/BIP39 cryptography' + [network] -n, --network <network> 'Specify a network. One of substrate \ + (default), polkadot, kusama, or dothereum.' + [password] -p, --password <password> 'The password for the key' + ") + .subcommands(vec![ + SubCommand::with_name("generate") + .about("Generate a random account") + .args_from_usage("[words] -w, --words <words> \ + 'The number of words in the phrase to generate. One of 12 \ + (default), 15, 18, 21 and 24.' + "), + SubCommand::with_name("inspect") + .about("Gets a public key and a SS58 address from the provided Secret URI") + .args_from_usage("<uri> 'A Key URI to be inspected. May be a secret seed, \ + secret URI (with derivation paths and password), SS58 or public URI.' + "), + SubCommand::with_name("sign") + .about("Sign a message, provided on STDIN, with a given (secret) key") + .args_from_usage(" + -h, --hex 'The message on STDIN is hex-encoded data' + <suri> 'The secret key URI.' + "), + SubCommand::with_name("sign-transaction") + .about("Sign transaction from encoded Call. Returns a signed and encoded \ + UncheckedMortalCompactExtrinsic as hex.") + .args_from_usage(" + -c, --call <call> 'The call, hex-encoded.' + -n, --nonce <nonce> 'The nonce.' + -p, --password <password> 'The password for the key.' + -h, --prior-block-hash <prior-block-hash> 'The prior block hash, hex-encoded.' + -s, --suri <suri> 'The secret key URI.' + "), + SubCommand::with_name("transfer") + .about("Author and sign a Node balances::Transfer transaction with a given (secret) key") + .args_from_usage(" + <genesis> -g, --genesis <genesis> 'The genesis hash or a recognised \ + chain identifier (dev, elm, alex).' + <from> 'The signing secret key URI.' + <to> 'The destination account public key URI.' + <amount> 'The number of units to transfer.' + <index> 'The signing account's transaction index.' + "), + SubCommand::with_name("vanity") + .about("Generate a seed that provides a vanity address") + .args_from_usage(" + -n, --number <number> 'Number of keys to generate' + <pattern> 'Desired pattern' + "), + SubCommand::with_name("verify") + .about("Verify a signature for a message, provided on STDIN, with a given \ + (public or secret) key") + .args_from_usage(" + -h, --hex 'The message on STDIN is hex-encoded data' + <sig> 'Signature, hex-encoded.' + <uri> 'The public or secret key URI.' + "), + ]) +} + +fn main() { + let matches = get_app().get_matches(); if matches.is_present("ed25519") { return execute::<Ed25519>(matches) @@ -470,8 +535,7 @@ mod tests { SignatureOf<CryptoType>: SignatureT, PublicOf<CryptoType>: PublicT, { - let yaml = load_yaml!("cli.yml"); - let app = App::from_yaml(yaml); + let app = get_app(); let password = None; // Generate public key and seed. @@ -499,7 +563,7 @@ mod tests { // Verify the previous signature. let arg_vec = vec!["subkey", "verify", &signature[..], &public_key[..]]; - let matches = App::from_yaml(yaml).get_matches_from(arg_vec); + let matches = get_app().get_matches_from(arg_vec); let matches = matches.subcommand().1.unwrap(); assert!(do_verify::<CryptoType>(matches, message)); } diff --git a/client/Cargo.toml b/client/Cargo.toml index 0efd978e84faca570cfa7d5c5598422da7a95e92..58dfd00851d10f3398f4ab1162ffce723cf4a7e4 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -13,8 +13,7 @@ kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c 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"] } +futures = { version = "0.3.1", features = ["compat"] } hash-db = { version = "0.15.2" } hex-literal = { version = "0.2.1" } inherents = { package = "substrate-inherents", path = "../primitives/inherents" } @@ -38,4 +37,3 @@ client-db = { package = "substrate-client-db", path = "./db", features = ["kvdb- 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" } - diff --git a/client/api/Cargo.toml b/client/api/Cargo.toml index f3f7f164010c5091f90a697ade37ce947564c494..4c865f875d0d4813443c75694ddfc4b48aeaf49b 100644 --- a/client/api/Cargo.toml +++ b/client/api/Cargo.toml @@ -11,8 +11,7 @@ consensus = { package = "substrate-consensus-common", path = "../../primitives/c 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"] } +futures = { version = "0.3.1" } hash-db = { version = "0.15.2", default-features = false } sp-blockchain = { path = "../../primitives/blockchain" } hex-literal = { version = "0.2.1" } diff --git a/client/api/src/client.rs b/client/api/src/client.rs index b790bf95e4b045d3eeaba3a01ce913a8568428e6..b328bd65fd2c5e6a3acf246663e90a20bd055fb4 100644 --- a/client/api/src/client.rs +++ b/client/api/src/client.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see <http://www.gnu.org/licenses/>. use std::collections::HashMap; -use futures03::channel::mpsc; +use futures::channel::mpsc; use primitives::storage::StorageKey; use state_machine::ExecutionStrategy; use sr_primitives::{ diff --git a/client/api/src/light.rs b/client/api/src/light.rs index e53b653f9a7f820a4c1652955cdd7722075e56f7..d0206dbc40fbcaf8dfa5931073cc0635a3ccd844 100644 --- a/client/api/src/light.rs +++ b/client/api/src/light.rs @@ -281,7 +281,7 @@ pub trait RemoteBlockchain<Block: BlockT>: Send + Sync { #[cfg(test)] pub mod tests { - use futures03::future::Ready; + use futures::future::Ready; use parking_lot::Mutex; use sp_blockchain::Error as ClientError; use test_primitives::{Block, Header, Extrinsic}; @@ -293,7 +293,7 @@ pub mod tests { where E: std::convert::From<&'static str>, { - futures03::future::ready(Err("Not implemented on test node".into())) + futures::future::ready(Err("Not implemented on test node".into())) } impl Fetcher<Block> for OkCallFetcher { @@ -316,7 +316,7 @@ pub mod tests { } fn remote_call(&self, _request: RemoteCallRequest<Header>) -> Self::RemoteCallResult { - futures03::future::ready(Ok((*self.lock()).clone())) + futures::future::ready(Ok((*self.lock()).clone())) } fn remote_changes(&self, _request: RemoteChangesRequest<Header>) -> Self::RemoteChangesResult { @@ -327,4 +327,4 @@ pub mod tests { not_implemented_in_tests() } } -} \ No newline at end of file +} diff --git a/client/api/src/notifications.rs b/client/api/src/notifications.rs index 37f90dcc0ba64a0bb10a5a4b31cc70a988582edc..0ddc4c72cdb5530aba3570a2586a3132a353df24 100644 --- a/client/api/src/notifications.rs +++ b/client/api/src/notifications.rs @@ -22,7 +22,7 @@ use std::{ }; use fnv::{FnvHashSet, FnvHashMap}; -use futures03::channel::mpsc; +use futures::channel::mpsc; use primitives::storage::{StorageKey, StorageData}; use sr_primitives::traits::Block as BlockT; @@ -347,7 +347,7 @@ mod tests { // given let mut notifications = StorageNotifications::<Block>::default(); let child_filter = [(StorageKey(vec![4]), None)]; - let mut recv = futures03::executor::block_on_stream( + let mut recv = futures::executor::block_on_stream( notifications.listen(None, Some(&child_filter[..])) ); @@ -382,13 +382,13 @@ mod tests { // given let mut notifications = StorageNotifications::<Block>::default(); let child_filter = [(StorageKey(vec![4]), Some(vec![StorageKey(vec![5])]))]; - let mut recv1 = futures03::executor::block_on_stream( + let mut recv1 = futures::executor::block_on_stream( notifications.listen(Some(&[StorageKey(vec![1])]), None) ); - let mut recv2 = futures03::executor::block_on_stream( + let mut recv2 = futures::executor::block_on_stream( notifications.listen(Some(&[StorageKey(vec![2])]), None) ); - let mut recv3 = futures03::executor::block_on_stream( + let mut recv3 = futures::executor::block_on_stream( notifications.listen(Some(&[]), Some(&child_filter)) ); @@ -429,16 +429,16 @@ mod tests { let mut notifications = StorageNotifications::<Block>::default(); { let child_filter = [(StorageKey(vec![4]), Some(vec![StorageKey(vec![5])]))]; - let _recv1 = futures03::executor::block_on_stream( + let _recv1 = futures::executor::block_on_stream( notifications.listen(Some(&[StorageKey(vec![1])]), None) ); - let _recv2 = futures03::executor::block_on_stream( + let _recv2 = futures::executor::block_on_stream( notifications.listen(Some(&[StorageKey(vec![2])]), None) ); - let _recv3 = futures03::executor::block_on_stream( + let _recv3 = futures::executor::block_on_stream( notifications.listen(None, None) ); - let _recv4 = futures03::executor::block_on_stream( + let _recv4 = futures::executor::block_on_stream( notifications.listen(None, Some(&child_filter)) ); assert_eq!(notifications.listeners.len(), 2); @@ -465,7 +465,7 @@ mod tests { // given let mut recv = { let mut notifications = StorageNotifications::<Block>::default(); - let recv = futures03::executor::block_on_stream(notifications.listen(None, None)); + let recv = futures::executor::block_on_stream(notifications.listen(None, None)); // when let changeset = vec![]; diff --git a/client/authority-discovery/Cargo.toml b/client/authority-discovery/Cargo.toml index 642b444ec595efc1692947e5a67af8cb424ee9ac..2856772260fd65aabe114fed0ad83997cc50cdec 100644 --- a/client/authority-discovery/Cargo.toml +++ b/client/authority-discovery/Cargo.toml @@ -14,8 +14,8 @@ bytes = "0.4.12" client-api = { package = "substrate-client-api", path = "../api" } codec = { package = "parity-scale-codec", default-features = false, version = "1.0.3" } derive_more = "0.15.0" -futures-preview = "0.3.0-alpha.19" -futures-timer = "0.4" +futures = "0.3.1" +futures-timer = "2.0" keystore = { package = "substrate-keystore", path = "../keystore" } libp2p = { version = "0.13.0", default-features = false, features = ["secp256k1", "libp2p-websocket"] } log = "0.4.8" diff --git a/client/authority-discovery/src/lib.rs b/client/authority-discovery/src/lib.rs index 034c35866bb511ab04fcf59607817caba78725d4..f404ad3c43702829a0971f1e5da7104a3891d7f2 100644 --- a/client/authority-discovery/src/lib.rs +++ b/client/authority-discovery/src/lib.rs @@ -51,9 +51,8 @@ use std::sync::Arc; use std::time::{Duration, Instant}; use futures::task::{Context, Poll}; -use futures::Future; -use futures_timer::Interval; -use futures::prelude::*; +use futures::{Future, FutureExt, Stream, StreamExt}; +use futures_timer::Delay; use authority_discovery_primitives::{AuthorityDiscoveryApi, AuthorityId, AuthoritySignature, AuthorityPair}; use client_api::blockchain::HeaderBackend; @@ -68,6 +67,8 @@ use prost::Message; use sr_primitives::generic::BlockId; use sr_primitives::traits::{Block as BlockT, ProvideRuntimeApi}; +type Interval = Box<dyn Stream<Item = ()> + Unpin + Send + Sync>; + mod error; /// Dht payload schemas generated from Protobuf definitions via Prost crate in build.rs. mod schema { @@ -129,14 +130,14 @@ where // Kademlia's default time-to-live for Dht records is 36h, republishing records every 24h. Given that a node // could restart at any point in time, one can not depend on the republishing process, thus publishing own // external addresses should happen on an interval < 36h. - let publish_interval = Interval::new_at( + let publish_interval = interval_at( Instant::now() + LIBP2P_KADEMLIA_BOOTSTRAP_TIME, Duration::from_secs(12 * 60 * 60), ); // External addresses of other authorities can change at any given point in time. The interval on which to query // for external addresses of other authorities is a trade off between efficiency and performance. - let query_interval = Interval::new_at( + let query_interval = interval_at( Instant::now() + LIBP2P_KADEMLIA_BOOTSTRAP_TIME, Duration::from_secs(10 * 60), ); @@ -455,6 +456,19 @@ fn hash_authority_id(id: &[u8]) -> Result<libp2p::kad::record::Key> { .map_err(Error::HashingAuthorityId) } +fn interval_at(start: Instant, duration: Duration) -> Interval { + let stream = futures::stream::unfold((), move |_| { + let wait_time = start.saturating_duration_since(Instant::now()); + + futures::future::join( + Delay::new(wait_time), + Delay::new(duration) + ).map(|_| Some(((), ()))) + }).map(drop); + + Box::new(stream) +} + #[cfg(test)] mod tests { use super::*; diff --git a/client/basic-authorship/Cargo.toml b/client/basic-authorship/Cargo.toml index ef8117b30d2d74bd7c77233ff30c78b438d03899..c41e0c259125f25776afcd541b40d7800ab828db 100644 --- a/client/basic-authorship/Cargo.toml +++ b/client/basic-authorship/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] log = "0.4.8" -futures-preview = "0.3.0-alpha.19" +futures = "0.3.1" codec = { package = "parity-scale-codec", version = "1.0.0" } sr-primitives = { path = "../../primitives/sr-primitives" } primitives = { package = "substrate-primitives", path = "../../primitives/core" } diff --git a/client/chain-spec/Cargo.toml b/client/chain-spec/Cargo.toml index e352ef01a0083d76c6dc12d80536266a27d6af44..da9543e398774dd0161a83c6bc166abd85da2a8a 100644 --- a/client/chain-spec/Cargo.toml +++ b/client/chain-spec/Cargo.toml @@ -10,6 +10,6 @@ impl-trait-for-tuples = "0.1.3" network = { package = "substrate-network", path = "../network" } primitives = { package = "substrate-primitives", path = "../../primitives/core" } serde = { version = "1.0.101", features = ["derive"] } -serde_json = { version = "1.0.41", features = [ "arbitrary_precision" ] } +serde_json = "1.0.41" sr-primitives = { path = "../../primitives/sr-primitives" } tel = { package = "substrate-telemetry", path = "../telemetry" } diff --git a/client/cli/Cargo.toml b/client/cli/Cargo.toml index e64e03cea6c60d3c3925dc7422ade47cd3c03ddc..bac381e825eeae7618d843b018d112e363340525 100644 --- a/client/cli/Cargo.toml +++ b/client/cli/Cargo.toml @@ -17,10 +17,9 @@ ansi_term = "0.12.1" lazy_static = "1.4.0" app_dirs = "1.2.1" tokio = "0.1.22" -futures = "0.1.29" -futures03 = { package = "futures-preview", version = "=0.3.0-alpha.19", features = ["compat"] } +futures = { version = "0.3.1", features = ["compat"] } +futures01 = "0.1.29" fdlimit = "0.1.1" -exit-future = "0.1.4" serde_json = "1.0.41" panic-handler = { package = "substrate-panic-handler", path = "../../primitives/panic-handler" } client-api = { package = "substrate-client-api", path = "../api" } diff --git a/client/cli/src/informant.rs b/client/cli/src/informant.rs index 778e05ab0b0efc099b374ece99fc3750a74f9d01..46dca3e54c19c5a743091dcb18f84154433e94da 100644 --- a/client/cli/src/informant.rs +++ b/client/cli/src/informant.rs @@ -17,8 +17,7 @@ //! Console informant. Prints sync progress and block events. Runs on the calling thread. use client_api::BlockchainEvents; -use futures::{Future, Stream}; -use futures03::{StreamExt as _, TryStreamExt as _}; +use futures::{StreamExt, TryStreamExt, FutureExt, future, compat::Stream01CompatExt}; use log::{info, warn}; use sr_primitives::traits::Header; use service::AbstractService; @@ -27,17 +26,18 @@ use std::time::Duration; mod display; /// Creates an informant in the form of a `Future` that must be polled regularly. -pub fn build(service: &impl AbstractService) -> impl Future<Item = (), Error = ()> { +pub fn build(service: &impl AbstractService) -> impl futures::Future<Output = ()> { let client = service.client(); let mut display = display::InformantDisplay::new(); let display_notifications = service .network_status(Duration::from_millis(5000)) - .for_each(move |(net_status, _)| { + .compat() + .try_for_each(move |(net_status, _)| { let info = client.info(); display.display(&info, net_status); - Ok(()) + future::ok(()) }); let client = service.client(); @@ -46,7 +46,7 @@ pub fn build(service: &impl AbstractService) -> impl Future<Item = (), Error = ( Some((info.chain.best_number, info.chain.best_hash)) }; - let display_block_import = client.import_notification_stream().map(|v| Ok::<_, ()>(v)).compat().for_each(move |n| { + let display_block_import = client.import_notification_stream().for_each(move |n| { // detect and log reorganizations. if let Some((ref last_num, ref last_hash)) = last_best { if n.header.parent_hash() != last_hash && n.is_new_best { @@ -74,9 +74,11 @@ pub fn build(service: &impl AbstractService) -> impl Future<Item = (), Error = ( } info!(target: "substrate", "Imported #{} ({})", n.header.number(), n.hash); - Ok(()) + future::ready(()) }); - display_notifications.join(display_block_import) - .map(|((), ())| ()) + future::join( + display_notifications, + display_block_import + ).map(|_| ()) } diff --git a/client/cli/src/lib.rs b/client/cli/src/lib.rs index 696a6eaeae0d21499f5f7e4b5e0dd93fe3feb73b..3f8ecb8f904c53837750a76910f3a7741c2c1847 100644 --- a/client/cli/src/lib.rs +++ b/client/cli/src/lib.rs @@ -61,8 +61,8 @@ pub use traits::{GetLogFilter, AugmentClap}; use app_dirs::{AppInfo, AppDataType}; use log::info; use lazy_static::lazy_static; - -use futures::{Async, Future}; +use futures::{Future, FutureExt, TryFutureExt}; +use futures01::{Async, Future as _}; use substrate_telemetry::TelemetryEndpoints; /// default sub directory to store network config @@ -102,7 +102,7 @@ pub struct VersionInfo { /// Something that can be converted into an exit signal. pub trait IntoExit { /// Exit signal type. - type Exit: Future<Item=(),Error=()> + Send + 'static; + type Exit: Future<Output=()> + Unpin + Send + 'static; /// Convert into exit signal. fn into_exit(self) -> Self::Exit; } @@ -391,14 +391,16 @@ impl<'a> ParseAndPrepareExport<'a> { // Note: while we would like the user to handle the exit themselves, we handle it here // for backwards compatibility reasons. let (exit_send, exit_recv) = std::sync::mpsc::channel(); - let exit = exit.into_exit(); + let exit = exit.into_exit() + .map(|_| Ok::<_, ()>(())) + .compat(); std::thread::spawn(move || { let _ = exit.wait(); let _ = exit_send.send(()); }); let mut export_fut = builder(config)?.export_blocks(file, from.into(), to.map(Into::into), json); - let fut = futures::future::poll_fn(|| { + let fut = futures01::future::poll_fn(|| { if exit_recv.try_recv().is_ok() { return Ok(Async::Ready(())); } @@ -453,14 +455,16 @@ impl<'a> ParseAndPrepareImport<'a> { // Note: while we would like the user to handle the exit themselves, we handle it here // for backwards compatibility reasons. let (exit_send, exit_recv) = std::sync::mpsc::channel(); - let exit = exit.into_exit(); + let exit = exit.into_exit() + .map(|_| Ok::<_, ()>(())) + .compat(); std::thread::spawn(move || { let _ = exit.wait(); let _ = exit_send.send(()); }); let mut import_fut = builder(config)?.import_blocks(file); - let fut = futures::future::poll_fn(|| { + let fut = futures01::future::poll_fn(|| { if exit_recv.try_recv().is_ok() { return Ok(Async::Ready(())); } diff --git a/client/consensus/aura/Cargo.toml b/client/consensus/aura/Cargo.toml index f1344356bfc68fe16f80337d0247d96ef4230a7f..a023cf2d0a64e90795c0cd2475a31a68c9e365c7 100644 --- a/client/consensus/aura/Cargo.toml +++ b/client/consensus/aura/Cargo.toml @@ -14,9 +14,9 @@ client-api = { package = "substrate-client-api", path = "../../api" } codec = { package = "parity-scale-codec", version = "1.0.0" } consensus_common = { package = "substrate-consensus-common", path = "../../../primitives/consensus/common" } derive_more = "0.15.0" -futures-preview = { version = "0.3.0-alpha.19", features = ["compat"] } -futures-timer = "0.4.0" +futures = { version = "0.3.1", features = ["compat"] } futures01 = { package = "futures", version = "0.1" } +futures-timer = "0.4.0" inherents = { package = "substrate-inherents", path = "../../../primitives/inherents" } keystore = { package = "substrate-keystore", path = "../../keystore" } log = "0.4.8" diff --git a/client/consensus/babe/Cargo.toml b/client/consensus/babe/Cargo.toml index 1af683387127ec6a9f553c192e478d943b31c153..07060d03fdc40b5f2bfa479ab9dd7bb785bab890 100644 --- a/client/consensus/babe/Cargo.toml +++ b/client/consensus/babe/Cargo.toml @@ -29,7 +29,7 @@ uncles = { package = "substrate-consensus-uncles", path = "../uncles" } slots = { package = "substrate-consensus-slots", path = "../slots" } sr-primitives = { path = "../../../primitives/sr-primitives" } fork-tree = { path = "../../../utils/fork-tree" } -futures-preview = { version = "0.3.0-alpha.19", features = ["compat"] } +futures = { version = "0.3.1", features = ["compat"] } futures01 = { package = "futures", version = "0.1" } futures-timer = "0.4.0" parking_lot = "0.9.0" diff --git a/client/consensus/pow/Cargo.toml b/client/consensus/pow/Cargo.toml index a992dcbc9c488a417819eb122f8ffc92a7dca4f8..b48f29428dffdd96ad0bff965e3d4b1762324545 100644 --- a/client/consensus/pow/Cargo.toml +++ b/client/consensus/pow/Cargo.toml @@ -16,6 +16,6 @@ inherents = { package = "substrate-inherents", path = "../../../primitives/inher pow-primitives = { package = "substrate-consensus-pow-primitives", path = "../../../primitives/consensus/pow" } consensus-common = { package = "substrate-consensus-common", path = "../../../primitives/consensus/common" } log = "0.4.8" -futures-preview = { version = "0.3.0-alpha.19", features = ["compat"] } +futures = { version = "0.3.1", features = ["compat"] } sp-timestamp = { path = "../../../primitives/timestamp" } derive_more = "0.15.0" diff --git a/client/consensus/slots/Cargo.toml b/client/consensus/slots/Cargo.toml index f9072dfcf99234f9b479c57818a4807a5a391656..083ecdae11cf7c5555626c9289af4f52618da99a 100644 --- a/client/consensus/slots/Cargo.toml +++ b/client/consensus/slots/Cargo.toml @@ -15,8 +15,8 @@ sr-primitives = { path = "../../../primitives/sr-primitives" } substrate-telemetry = { path = "../../telemetry" } consensus_common = { package = "substrate-consensus-common", path = "../../../primitives/consensus/common" } inherents = { package = "substrate-inherents", path = "../../../primitives/inherents" } -futures-preview = "0.3.0-alpha.19" -futures-timer = "0.4.0" +futures = "0.3.1" +futures-timer = "2.0" parking_lot = "0.9.0" log = "0.4.8" diff --git a/client/consensus/slots/src/lib.rs b/client/consensus/slots/src/lib.rs index 537fb658be0b514dbbd70d1658c68df413744e69..54f0fd5589d632ebb3b1049dac05aa5bd91692bd 100644 --- a/client/consensus/slots/src/lib.rs +++ b/client/consensus/slots/src/lib.rs @@ -192,12 +192,10 @@ pub trait SimpleSlotWorker<B: BlockT> { remaining_duration, ).map_err(|e| consensus_common::Error::ClientImport(format!("{:?}", e))), Delay::new(remaining_duration) - .map_err(consensus_common::Error::FaultyTimer) ).map(|v| match v { futures::future::Either::Left((b, _)) => b.map(|b| (b, claim)), - futures::future::Either::Right((Ok(_), _)) => + futures::future::Either::Right(_) => Err(consensus_common::Error::ClientImport("Timeout in the Slots proposer".into())), - futures::future::Either::Right((Err(err), _)) => Err(err), }); let block_import_params_maker = self.block_import_params(); diff --git a/client/consensus/slots/src/slots.rs b/client/consensus/slots/src/slots.rs index 0157bc70355d0ef644c0a96fd4bf69fe28308536..0166d09bb74d2ef20dc4bde0802f37e7044c221c 100644 --- a/client/consensus/slots/src/slots.rs +++ b/client/consensus/slots/src/slots.rs @@ -137,8 +137,7 @@ impl<SC: SlotCompatible + Unpin> Stream for Slots<SC> { if let Some(ref mut inner_delay) = self.inner_delay { match Future::poll(Pin::new(inner_delay), cx) { Poll::Pending => return Poll::Pending, - Poll::Ready(Err(err)) => return Poll::Ready(Some(Err(Error::FaultyTimer(err)))), - Poll::Ready(Ok(())) => {} + Poll::Ready(()) => {} } } diff --git a/client/finality-grandpa/Cargo.toml b/client/finality-grandpa/Cargo.toml index 02d769c9cb331702cebad0377dab59a01e913ae4..8599c9f3c5c5d9faa66873340290b7ad4085e675 100644 --- a/client/finality-grandpa/Cargo.toml +++ b/client/finality-grandpa/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] fork-tree = { path = "../../utils/fork-tree" } futures = "0.1.29" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } +futures03 = { package = "futures", version = "0.3.1", features = ["compat"] } log = "0.4.8" parking_lot = "0.9.0" tokio-executor = "0.1.8" @@ -27,10 +27,10 @@ sp-blockchain = { path = "../../primitives/blockchain" } network = { package = "substrate-network", path = "../network" } sp-finality-tracker = { path = "../../primitives/finality-tracker" } fg_primitives = { package = "substrate-finality-grandpa-primitives", path = "../../primitives/finality-grandpa" } -grandpa = { package = "finality-grandpa", version = "0.9.0", features = ["derive-codec"] } +grandpa = { package = "finality-grandpa", version = "0.10.0", features = ["derive-codec"] } [dev-dependencies] -grandpa = { package = "finality-grandpa", version = "0.9.0", features = ["derive-codec", "test-helpers"] } +grandpa = { package = "finality-grandpa", version = "0.10.0", features = ["derive-codec", "test-helpers"] } network = { package = "substrate-network", path = "../network", features = ["test-helpers"] } keyring = { package = "substrate-keyring", path = "../../primitives/keyring" } test-client = { package = "substrate-test-runtime-client", path = "../../test/utils/runtime/client"} diff --git a/client/finality-grandpa/src/environment.rs b/client/finality-grandpa/src/environment.rs index 54c81e9e28eba6b0a709b4880d68df8446a561a9..af6e03743a42d2ff4f0093a89b4593c30b59251d 100644 --- a/client/finality-grandpa/src/environment.rs +++ b/client/finality-grandpa/src/environment.rs @@ -34,7 +34,7 @@ use client_api::{ utils::is_descendent_of, }; use client::{ - apply_aux, Client, + apply_aux, Client, }; use grandpa::{ BlockNumberOps, Equivocation, Error as GrandpaError, round::State as RoundState, @@ -497,8 +497,18 @@ where // note that we pass the original `best_header`, i.e. before the // authority set limit filter, which can be considered a // mandatory/implicit voting rule. + // + // we also make sure that the restricted vote is higher than the + // round base (i.e. last finalized), otherwise the value + // returned by the given voting rule is ignored and the original + // target is used instead. self.voting_rule .restrict_vote(&*self.client, &base_header, &best_header, target_header) + .filter(|(_, restricted_number)| { + // we can only restrict votes within the interval [base, target] + restricted_number >= base_header.number() && + restricted_number < target_header.number() + }) .or(Some((target_header.hash(), *target_header.number()))) }, Ok(None) => { @@ -788,7 +798,7 @@ where let mut completed_rounds = completed_rounds.clone(); // TODO: Future integration will store the prevote and precommit index. See #2611. - let votes = historical_votes.seen().clone(); + let votes = historical_votes.seen().to_vec(); completed_rounds.push(CompletedRound { number: round, @@ -815,6 +825,61 @@ where Ok(()) } + fn concluded( + &self, + round: RoundNumber, + state: RoundState<Block::Hash, NumberFor<Block>>, + _base: (Block::Hash, NumberFor<Block>), + historical_votes: &HistoricalVotes<Block>, + ) -> Result<(), Self::Error> { + debug!( + target: "afg", "Voter {} concluded round {} in set {}. Estimate = {:?}, Finalized in round = {:?}", + self.config.name(), + round, + self.set_id, + state.estimate.as_ref().map(|e| e.1), + state.finalized.as_ref().map(|e| e.1), + ); + + self.update_voter_set_state(|voter_set_state| { + // NOTE: we don't use `with_current_round` here, because a concluded + // round is completed and cannot be current. + let (completed_rounds, current_rounds) = + if let VoterSetState::Live { completed_rounds, current_rounds } = voter_set_state { + (completed_rounds, current_rounds) + } else { + let msg = "Voter acting while in paused state."; + return Err(Error::Safety(msg.to_string())); + }; + + let mut completed_rounds = completed_rounds.clone(); + + if let Some(already_completed) = completed_rounds.rounds + .iter_mut().find(|r| r.number == round) + { + let n_existing_votes = already_completed.votes.len(); + + // the interface of Environment guarantees that the previous `historical_votes` + // from `completable` is a prefix of what is passed to `concluded`. + already_completed.votes.extend( + historical_votes.seen().iter().skip(n_existing_votes).cloned() + ); + already_completed.state = state; + } + + let set_state = VoterSetState::<Block>::Live { + completed_rounds, + current_rounds: current_rounds.clone(), + }; + + crate::aux_schema::write_voter_set_state(&*self.client, &set_state)?; + + Ok(Some(set_state)) + })?; + + Ok(()) + } + fn finalize_block( &self, hash: Block::Hash, diff --git a/client/finality-grandpa/src/lib.rs b/client/finality-grandpa/src/lib.rs index ce2a30801f7cfe62630556e8e0529f91f7ef5e9b..2b83488d5990b44f909e4789f997c942d61ac0b9 100644 --- a/client/finality-grandpa/src/lib.rs +++ b/client/finality-grandpa/src/lib.rs @@ -744,7 +744,8 @@ where (*self.env.voters).clone(), global_comms, last_completed_round.number, - last_completed_round.state.clone(), + last_completed_round.votes.clone(), + last_completed_round.base.clone(), last_finalized, ); diff --git a/client/finality-grandpa/src/tests.rs b/client/finality-grandpa/src/tests.rs index a883a0775c0422b37bed991b8e19e492bea766b9..fde730e2984503d7fe06dcfbd0a3b11b40837f22 100644 --- a/client/finality-grandpa/src/tests.rs +++ b/client/finality-grandpa/src/tests.rs @@ -1660,6 +1660,19 @@ fn grandpa_environment_respects_voting_rules() { ).unwrap().1, 19, ); + + // we finalize block 20 with block 20 being the best block + peer.client().finalize_block(BlockId::Number(20), None, false).unwrap(); + + // even though the default environment will always try to not vote on the + // best block, there's a hard rule that we can't cast any votes lower than + // the given base (#20). + assert_eq!( + default_env.best_chain_containing( + peer.client().info().chain.finalized_hash + ).unwrap().1, + 20, + ); } #[test] diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index 22b870936dd21b4d5b95c2b0761cf83cda8a235c..36b89b077cf12aa0eaff67df1161fb3fedb1cfd2 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -15,7 +15,7 @@ parking_lot = "0.9.0" bitflags = "1.2.0" fnv = "1.0.6" futures = "0.1.29" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } +futures03 = { package = "futures", version = "0.3.1", features = ["compat"] } futures-timer = "0.4.0" linked-hash-map = "0.5.2" linked_hash_set = "0.1.3" diff --git a/client/network/src/debug_info.rs b/client/network/src/debug_info.rs index 0283853a5fa14e5b3a2d721c96f9ac4c9242e7d3..daf49df6375404a422ad15b2acc91e99b0e52d39 100644 --- a/client/network/src/debug_info.rs +++ b/client/network/src/debug_info.rs @@ -27,7 +27,7 @@ use log::{debug, trace, error}; use std::collections::hash_map::Entry; use std::time::{Duration, Instant}; use tokio_io::{AsyncRead, AsyncWrite}; -use futures_timer::Interval; +use crate::utils::interval; /// Time after we disconnect from a node before we purge its information from the cache. const CACHE_EXPIRE: Duration = Duration::from_secs(10 * 60); @@ -76,7 +76,7 @@ impl<TSubstream> DebugInfoBehaviour<TSubstream> { ping: Ping::new(PingConfig::new()), identify, nodes_info: FnvHashMap::default(), - garbage_collect: Box::new(Interval::new(GARBAGE_COLLECT_INTERVAL).map(|()| Ok(())).compat()), + garbage_collect: Box::new(interval(GARBAGE_COLLECT_INTERVAL).map(|()| Ok(())).compat()), } } diff --git a/client/network/src/lib.rs b/client/network/src/lib.rs index d0977d90c90053fba40cddecd105d54bb83b9e02..96efd49958763821188b2eb1a94eb711b9c76467 100644 --- a/client/network/src/lib.rs +++ b/client/network/src/lib.rs @@ -177,6 +177,7 @@ mod on_demand_layer; mod protocol; mod service; mod transport; +mod utils; pub mod config; pub mod error; diff --git a/client/network/src/protocol.rs b/client/network/src/protocol.rs index 780a071505a656da6b9d7199258264f986d8af0c..6634ca9c859167084cb607757bef7d970b4c12a9 100644 --- a/client/network/src/protocol.rs +++ b/client/network/src/protocol.rs @@ -16,6 +16,7 @@ use crate::{DiscoveryNetBehaviour, config::ProtocolId}; use crate::legacy_proto::{LegacyProto, LegacyProtoOut}; +use crate::utils::interval; use bytes::BytesMut; use futures::prelude::*; use futures03::{StreamExt as _, TryStreamExt as _}; @@ -430,8 +431,8 @@ impl<B: BlockT, S: NetworkSpecialization<B>, H: ExHashT> Protocol<B, S, H> { let behaviour = LegacyProto::new(protocol_id, versions, peerset); let protocol = Protocol { - tick_timeout: Box::new(futures_timer::Interval::new(TICK_TIMEOUT).map(|v| Ok::<_, ()>(v)).compat()), - propagate_timeout: Box::new(futures_timer::Interval::new(PROPAGATE_TIMEOUT).map(|v| Ok::<_, ()>(v)).compat()), + tick_timeout: Box::new(interval(TICK_TIMEOUT).map(|v| Ok::<_, ()>(v)).compat()), + propagate_timeout: Box::new(interval(PROPAGATE_TIMEOUT).map(|v| Ok::<_, ()>(v)).compat()), config, context_data: ContextData { peers: HashMap::new(), diff --git a/client/network/src/utils.rs b/client/network/src/utils.rs new file mode 100644 index 0000000000000000000000000000000000000000..db8bf2086ff28469c35166eaa54d9dadf634a49d --- /dev/null +++ b/client/network/src/utils.rs @@ -0,0 +1,25 @@ +// 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::time::Duration; +use futures03::{FutureExt, Stream, StreamExt, stream::unfold}; +use futures_timer::Delay; + +pub fn interval(duration: Duration) -> impl Stream<Item=()> + Unpin { + unfold((), move |_| { + Delay::new(duration).map(|_| Some(((), ()))) + }).map(drop) +} diff --git a/client/offchain/Cargo.toml b/client/offchain/Cargo.toml index 7dd63ab0e8637177caa54e0d7dad676cc4f2eca5..4bde96b2f452b200a75d2e531b33c4b72b05c532 100644 --- a/client/offchain/Cargo.toml +++ b/client/offchain/Cargo.toml @@ -12,8 +12,8 @@ client-api = { package = "substrate-client-api", path = "../api" } sr-api = { path = "../../primitives/sr-api" } fnv = "1.0.6" futures01 = { package = "futures", version = "0.1" } -futures-preview = "0.3.0-alpha.19" -futures-timer = "0.4.0" +futures = "0.3.1" +futures-timer = "2.0" log = "0.4.8" threadpool = "1.7" num_cpus = "1.10" diff --git a/client/peerset/Cargo.toml b/client/peerset/Cargo.toml index c64c5e499c14962f3ea1d9b12424b15bf131b690..16a71b5f6d6b514b368d4653811d26daf09bde19 100644 --- a/client/peerset/Cargo.toml +++ b/client/peerset/Cargo.toml @@ -8,7 +8,7 @@ authors = ["Parity Technologies <admin@parity.io>"] edition = "2018" [dependencies] -futures-preview = "0.3.0-alpha.19" +futures = "0.3.1" libp2p = { version = "0.13.0", default-features = false } log = "0.4.8" serde_json = "1.0.41" diff --git a/client/rpc/Cargo.toml b/client/rpc/Cargo.toml index 92089869b651b8e2961b0e88834d245b77ee7370..618456cadaa2a83f2cdd038caed99f7468ce11a6 100644 --- a/client/rpc/Cargo.toml +++ b/client/rpc/Cargo.toml @@ -10,13 +10,13 @@ client-api = { package = "substrate-client-api", path = "../api" } client = { package = "substrate-client", path = "../" } sr-api = { path = "../../primitives/sr-api" } codec = { package = "parity-scale-codec", version = "1.0.0" } -futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } +futures = { version = "0.3.1", features = ["compat"] } jsonrpc-pubsub = "14.0.3" log = "0.4.8" primitives = { package = "substrate-primitives", path = "../../primitives/core" } rpc = { package = "jsonrpc-core", version = "14.0.3" } runtime_version = { package = "sr-version", path = "../../primitives/sr-version" } -serde_json = { version = "1.0.41", features = ["arbitrary_precision"] } +serde_json = "1.0.41" session = { package = "substrate-session", path = "../../primitives/session" } sr-primitives = { path = "../../primitives/sr-primitives" } rpc-primitives = { package = "substrate-rpc-primitives", path = "../../primitives/rpc" } @@ -30,7 +30,7 @@ parking_lot = { version = "0.9.0" } [dev-dependencies] assert_matches = "1.3.0" -futures = "0.1.29" +futures01 = { package = "futures", version = "0.1.29" } network = { package = "substrate-network", path = "../network" } rustc-hex = "2.0.1" sr-io = { path = "../../primitives/sr-io" } diff --git a/client/rpc/src/author/mod.rs b/client/rpc/src/author/mod.rs index a92b2728f4932fe2679a68f763ef76f29cc1da5d..920331d9aebf48efab57c47d7e3ec633a8d394b5 100644 --- a/client/rpc/src/author/mod.rs +++ b/client/rpc/src/author/mod.rs @@ -20,7 +20,7 @@ mod tests; use std::{sync::Arc, convert::TryInto}; -use futures03::future::{FutureExt, TryFutureExt}; +use futures::future::{FutureExt, TryFutureExt}; use log::warn; use client::Client; @@ -30,7 +30,7 @@ use rpc::futures::{ Sink, Future, future::result, }; -use futures03::{StreamExt as _, compat::Compat, future::ready}; +use futures::{StreamExt as _, compat::Compat, future::ready}; use api::Subscriptions; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; use codec::{Encode, Decode}; diff --git a/client/rpc/src/chain/chain_light.rs b/client/rpc/src/chain/chain_light.rs index 5c2f1f803a438fcea0fd22835c14f5c966760ab6..94afc7a9d347d79d1bd7187796a512d898fd20a5 100644 --- a/client/rpc/src/chain/chain_light.rs +++ b/client/rpc/src/chain/chain_light.rs @@ -17,7 +17,7 @@ //! Blockchain API backend for light nodes. use std::sync::Arc; -use futures03::{future::ready, FutureExt, TryFutureExt}; +use futures::{future::ready, FutureExt, TryFutureExt}; use rpc::futures::future::{result, Future, Either}; use api::Subscriptions; diff --git a/client/rpc/src/chain/mod.rs b/client/rpc/src/chain/mod.rs index 8ea7af09aa7d769c9d45b599dfd5222eee619cc9..572f5f246988afd8674ab422de13c8d2082e5e9e 100644 --- a/client/rpc/src/chain/mod.rs +++ b/client/rpc/src/chain/mod.rs @@ -23,7 +23,7 @@ mod chain_light; mod tests; use std::sync::Arc; -use futures03::{future, StreamExt as _, TryStreamExt as _}; +use futures::{future, StreamExt, TryStreamExt}; use log::warn; use rpc::{ Result as RpcResult, diff --git a/client/rpc/src/state/state_full.rs b/client/rpc/src/state/state_full.rs index 4b0b96286882ef6de4ef571b202fe4055b7e4803..55b6e65d484dff0d3457064d705f8dff48844860 100644 --- a/client/rpc/src/state/state_full.rs +++ b/client/rpc/src/state/state_full.rs @@ -19,7 +19,7 @@ use std::collections::{BTreeMap, HashMap}; use std::sync::Arc; use std::ops::Range; -use futures03::{future, StreamExt as _, TryStreamExt as _}; +use futures::{future, StreamExt as _, TryStreamExt as _}; use log::warn; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; use rpc::{ diff --git a/client/rpc/src/state/state_light.rs b/client/rpc/src/state/state_light.rs index 176badd24536c1d40ab69c155cd7baafd1f6c06f..c761d3bfe408a4309c2523f36b3bb9743ec8fcbd 100644 --- a/client/rpc/src/state/state_light.rs +++ b/client/rpc/src/state/state_light.rs @@ -21,7 +21,7 @@ use std::{ collections::{HashSet, HashMap, hash_map::Entry}, }; use codec::Decode; -use futures03::{ +use futures::{ future::{ready, Either}, channel::oneshot::{channel, Sender}, FutureExt, TryFutureExt, @@ -753,7 +753,7 @@ mod tests { #[test] fn maybe_share_remote_request_shares_request() { - type UnreachableFuture = futures03::future::Ready<Result<u32, Error>>; + type UnreachableFuture = futures::future::Ready<Result<u32, Error>>; let shared_requests = SimpleSubscriptions::default(); diff --git a/client/rpc/src/state/tests.rs b/client/rpc/src/state/tests.rs index 2e3690f3058a2122c5619f60b10b7846b1dd5e30..87a4b004667f7bf734f66a7a32f89244a4b3aeeb 100644 --- a/client/rpc/src/state/tests.rs +++ b/client/rpc/src/state/tests.rs @@ -20,7 +20,7 @@ use self::error::Error; use std::sync::Arc; use assert_matches::assert_matches; -use futures::stream::Stream; +use futures01::stream::Stream; use primitives::storage::well_known_keys; use sr_io::hashing::blake2_256; use test_client::{ diff --git a/client/rpc/src/system/mod.rs b/client/rpc/src/system/mod.rs index 8907151d9ac6984bb8396c3f7af263b1b9994ee3..88d29386655286c7cb54bafc6c88739c9190bd5d 100644 --- a/client/rpc/src/system/mod.rs +++ b/client/rpc/src/system/mod.rs @@ -19,7 +19,7 @@ #[cfg(test)] mod tests; -use futures03::{channel::{mpsc, oneshot}, compat::Compat}; +use futures::{channel::{mpsc, oneshot}, compat::Compat}; use api::Receiver; use sr_primitives::traits::{self, Header as HeaderT}; use self::error::Result; diff --git a/client/rpc/src/system/tests.rs b/client/rpc/src/system/tests.rs index 1c532be372660fbee4c8210a56c15842413e553e..b4b3e67cee878b23e16027bfe65f76d4df518a62 100644 --- a/client/rpc/src/system/tests.rs +++ b/client/rpc/src/system/tests.rs @@ -20,7 +20,7 @@ use network::{self, PeerId}; use network::config::Roles; use test_client::runtime::Block; use assert_matches::assert_matches; -use futures03::{prelude::*, channel::mpsc}; +use futures::{prelude::*, channel::mpsc}; use std::thread; struct Status { @@ -46,7 +46,7 @@ fn api<T: Into<Option<Status>>>(sync: T) -> System<Block> { let should_have_peers = !status.is_dev; let (tx, rx) = mpsc::unbounded(); thread::spawn(move || { - futures03::executor::block_on(rx.for_each(move |request| { + futures::executor::block_on(rx.for_each(move |request| { match request { Request::Health(sender) => { let _ = sender.send(Health { @@ -231,4 +231,4 @@ fn system_node_roles() { wait_receiver(api(None).system_node_roles()), vec![NodeRole::Authority] ); -} \ No newline at end of file +} diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index 950365de7df8ebc6a6fb1e99ea6565e83b890dd2..ab77cd70b1ec93fbd38832ef7341ef48408b90e3 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -16,7 +16,7 @@ wasmtime = [ [dependencies] derive_more = "0.15.0" futures = "0.1.29" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } +futures03 = { package = "futures", version = "0.3.1", features = ["compat"] } parking_lot = "0.9.0" lazy_static = "1.4.0" log = "0.4.8" diff --git a/client/service/test/Cargo.toml b/client/service/test/Cargo.toml index 82b39ce767e3807f9d26ac23d6231039b368f3d4..365fd87bfec86989508d8cd3db0e96c1a4e457db 100644 --- a/client/service/test/Cargo.toml +++ b/client/service/test/Cargo.toml @@ -11,7 +11,7 @@ futures = "0.1.29" log = "0.4.8" env_logger = "0.7.0" fdlimit = "0.1.1" -futures03 = { package = "futures-preview", version = "=0.3.0-alpha.19", features = ["compat"] } +futures03 = { package = "futures", version = "0.3.1", features = ["compat"] } service = { package = "substrate-service", path = "../../service", default-features = false } network = { package = "substrate-network", path = "../../network" } consensus = { package = "substrate-consensus-common", path = "../../../primitives/consensus/common" } diff --git a/client/src/client.rs b/client/src/client.rs index 2158e96896ff5d9ea9e86634736c423fab032aa2..5c6ed35c1606eb4a403879573c72550546c13865 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -21,7 +21,7 @@ use std::{ panic::UnwindSafe, result, cell::RefCell, }; use log::{info, trace, warn}; -use futures03::channel::mpsc; +use futures::channel::mpsc; use parking_lot::{Mutex, RwLock}; use codec::{Encode, Decode}; use hash_db::{Hasher, Prefix}; diff --git a/client/src/light/blockchain.rs b/client/src/light/blockchain.rs index a59cd49d69031ca2ba48069cb36e7784577a5e9b..11982e45291c8ba04700d935ee688c2af63d4727 100644 --- a/client/src/light/blockchain.rs +++ b/client/src/light/blockchain.rs @@ -177,7 +177,7 @@ pub fn future_header<Block: BlockT, F: Fetcher<Block>>( fetcher: &F, id: BlockId<Block>, ) -> impl Future<Output = Result<Option<Block::Header>, ClientError>> { - use futures03::future::{ready, Either, FutureExt}; + use futures::future::{ready, Either, FutureExt}; match blockchain.header(id) { Ok(LocalOrRemote::Remote(request)) => Either::Left( diff --git a/client/telemetry/Cargo.toml b/client/telemetry/Cargo.toml index 82096a2cbf78854fc1def0ecd4da044ed02baf6d..07a296b02f8e0f51fbe672572dc5c0beae4180c4 100644 --- a/client/telemetry/Cargo.toml +++ b/client/telemetry/Cargo.toml @@ -9,8 +9,8 @@ edition = "2018" bytes = "0.4.12" parking_lot = "0.9.0" futures01 = { package = "futures", version = "0.1" } -futures-preview = { version = "0.3.0-alpha.19", features = ["compat"] } -futures-timer = "0.4.0" +futures = { version = "0.3.1", features = ["compat"] } +futures-timer = "2.0.0" libp2p = { version = "0.13.0", default-features = false, features = ["libp2p-websocket"] } log = "0.4.8" rand = "0.7.2" diff --git a/client/telemetry/src/worker/node.rs b/client/telemetry/src/worker/node.rs index 0f606e40638024c82c9c2cc96784d4faf3217580..6d9c6c241b669532d9134adcdd672228d6b2047b 100644 --- a/client/telemetry/src/worker/node.rs +++ b/client/telemetry/src/worker/node.rs @@ -254,11 +254,7 @@ where TTrans::Output: Sink<BytesMut, Error = TSinkErr> if let Some(timeout) = self.timeout.as_mut() { match Future::poll(Pin::new(timeout), cx) { Poll::Pending => {}, - Poll::Ready(Err(err)) => { - self.timeout = None; - warn!(target: "telemetry", "Connection timeout error for {} {:?}", my_addr, err); - } - Poll::Ready(Ok(_)) => { + Poll::Ready(()) => { self.timeout = None; return Poll::Ready(Err(ConnectionError::Timeout)) } diff --git a/client/transaction-pool/Cargo.toml b/client/transaction-pool/Cargo.toml index 7cf9807c0a1710e7aeedd733c149dfa09ec6c658..1b49c95985c23cb1591d9e39457f1d2fb5133087 100644 --- a/client/transaction-pool/Cargo.toml +++ b/client/transaction-pool/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] codec = { package = "parity-scale-codec", version = "1.0.0" } derive_more = "0.15.0" -futures = { version = "0.3.0", features = ["thread-pool"] } +futures = { version = "0.3.1", features = ["thread-pool"] } log = "0.4.8" parking_lot = "0.9.0" primitives = { package = "substrate-primitives", path = "../../primitives/core" } diff --git a/palette/authorship/src/lib.rs b/palette/authorship/src/lib.rs index 154d1b6b8e1d0eab2aa26b94985c48a22c3996b4..b4118b93a0d61a553c2d67c6eb8a61e3ca9051ad 100644 --- a/palette/authorship/src/lib.rs +++ b/palette/authorship/src/lib.rs @@ -28,7 +28,7 @@ use support::dispatch::Result as DispatchResult; use codec::{Encode, Decode}; use system::ensure_none; use sr_primitives::traits::{Header as HeaderT, One, Zero}; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use inherents::{InherentIdentifier, ProvideInherent, InherentData, MakeFatalError}; use sp_authorship::{ INHERENT_IDENTIFIER, UnclesInherentData, diff --git a/palette/balances/Cargo.toml b/palette/balances/Cargo.toml index d1ba5852935a9baa24416d675134c1c1741164c8..5fcbc5e0f0676454ceaea9fefecca6f1a752f40b 100644 --- a/palette/balances/Cargo.toml +++ b/palette/balances/Cargo.toml @@ -8,7 +8,6 @@ edition = "2018" serde = { version = "1.0.101", optional = true } safe-mix = { version = "1.0.0", default-features = false } codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } -substrate-keyring = { path = "../../primitives/keyring", optional = true } rstd = { package = "sr-std", path = "../../primitives/sr-std", default-features = false } sr-primitives = { path = "../../primitives/sr-primitives", default-features = false } support = { package = "palette-support", path = "../support", default-features = false } @@ -16,7 +15,7 @@ system = { package = "palette-system", path = "../system", default-features = fa [dev-dependencies] runtime-io = { package = "sr-io", path = "../../primitives/sr-io" } -primitives = { package = "substrate-primitives", path = "../../primitives/core" } +primitives = { package = "substrate-primitives", path = "../../primitives/core" } transaction-payment = { package = "pallet-transaction-payment", path = "../transaction-payment" } [features] @@ -24,7 +23,6 @@ default = ["std"] std = [ "serde", "safe-mix/std", - "substrate-keyring", "codec/std", "rstd/std", "support/std", diff --git a/palette/balances/src/lib.rs b/palette/balances/src/lib.rs index 8f258c0da073204a527f7bceee32988346137552..4c5df40e080679377a0481b149308a73adb41de1 100644 --- a/palette/balances/src/lib.rs +++ b/palette/balances/src/lib.rs @@ -169,6 +169,7 @@ use support::{ WithdrawReason, WithdrawReasons, LockIdentifier, LockableCurrency, ExistenceRequirement, Imbalance, SignedImbalance, ReservableCurrency, Get, }, + weights::SimpleDispatchInfo, dispatch::Result, }; use sr_primitives::{ @@ -177,11 +178,12 @@ use sr_primitives::{ Zero, SimpleArithmetic, StaticLookup, Member, CheckedAdd, CheckedSub, MaybeSerializeDeserialize, Saturating, Bounded, }, - weights::SimpleDispatchInfo, }; use system::{IsDeadAccount, OnNewAccount, ensure_signed, ensure_root}; +#[cfg(test)] mod mock; +#[cfg(test)] mod tests; pub use self::imbalances::{PositiveImbalance, NegativeImbalance}; diff --git a/palette/balances/src/mock.rs b/palette/balances/src/mock.rs index cd42fed6731fdc3d3070ed581158a2370b244cb0..62eabd1cf04d91494353a9d67e936675d06035c5 100644 --- a/palette/balances/src/mock.rs +++ b/palette/balances/src/mock.rs @@ -16,14 +16,12 @@ //! Test utilities -#![cfg(test)] - -use sr_primitives::{Perbill, traits::{ConvertInto, IdentityLookup}, testing::Header, - weights::{DispatchInfo, Weight}}; +use sr_primitives::{Perbill, traits::{ConvertInto, IdentityLookup}, testing::Header}; use primitives::H256; use runtime_io; use support::{impl_outer_origin, parameter_types}; use support::traits::Get; +use support::weights::{Weight, DispatchInfo}; use std::cell::RefCell; use crate::{GenesisConfig, Module, Trait}; diff --git a/palette/balances/src/tests.rs b/palette/balances/src/tests.rs index 61e5a82f086dbaab2da6f58bfd51af0b374bb91d..3849df676425fa7436c0ae5f41add65ef0bc8077 100644 --- a/palette/balances/src/tests.rs +++ b/palette/balances/src/tests.rs @@ -16,8 +16,6 @@ //! Tests for the module. -#![cfg(test)] - use super::*; use mock::{Balances, ExtBuilder, Runtime, System, info_from_weight, CALL}; use sr_primitives::traits::SignedExtension; diff --git a/palette/collective/src/lib.rs b/palette/collective/src/lib.rs index 37c1482f9ba15e785a1e784bb7f7aed53142a208..eff8366f0707c56f3f1f351780ed02f9c17432b6 100644 --- a/palette/collective/src/lib.rs +++ b/palette/collective/src/lib.rs @@ -27,7 +27,7 @@ use rstd::{prelude::*, result}; use primitives::u32_trait::Value as U32; use sr_primitives::RuntimeDebug; use sr_primitives::traits::{Hash, EnsureOrigin}; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use support::{ dispatch::{Dispatchable, Parameter}, codec::{Encode, Decode}, traits::{ChangeMembers, InitializeMembers}, decl_module, decl_event, diff --git a/palette/contracts/src/lib.rs b/palette/contracts/src/lib.rs index bcb131aa77ccc6cd9ad8403f69a9fa76a3dedbc4..e84214a0195b5310b33184ce43ab137d4365e14a 100644 --- a/palette/contracts/src/lib.rs +++ b/palette/contracts/src/lib.rs @@ -114,7 +114,6 @@ use codec::{Codec, Encode, Decode}; use runtime_io::hashing::blake2_256; use sr_primitives::{ traits::{Hash, StaticLookup, Zero, MaybeSerializeDeserialize, Member, SignedExtension}, - weights::DispatchInfo, transaction_validity::{ ValidTransaction, InvalidTransaction, TransactionValidity, TransactionValidityError, }, @@ -123,7 +122,8 @@ use sr_primitives::{ use support::dispatch::{Result, Dispatchable}; use support::{ Parameter, decl_module, decl_event, decl_storage, storage::child, - parameter_types, IsSubType + parameter_types, IsSubType, + weights::DispatchInfo, }; use support::traits::{OnFreeBalanceZero, OnUnbalanced, Currency, Get, Time, Randomness}; use system::{ensure_signed, RawOrigin, ensure_root}; @@ -1034,6 +1034,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckBlockGasLimit<T> { type AccountId = T::AccountId; type Call = <T as Trait>::Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -1042,7 +1043,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckBlockGasLimit<T> { &self, _: &Self::AccountId, call: &Self::Call, - _: DispatchInfo, + _: Self::DispatchInfo, _: usize, ) -> TransactionValidity { let call = match call.is_sub_type() { diff --git a/palette/contracts/src/tests.rs b/palette/contracts/src/tests.rs index 28ba77f0bbfc7f75d6819d15dbf78cf8e6ed62f4..5532a0cc9aad32b0d604fc65380e36bf3ddf858c 100644 --- a/palette/contracts/src/tests.rs +++ b/palette/contracts/src/tests.rs @@ -30,12 +30,12 @@ use codec::{Decode, Encode, KeyedVec}; use sr_primitives::{ Perbill, BuildStorage, transaction_validity::{InvalidTransaction, ValidTransaction}, traits::{BlakeTwo256, Hash, IdentityLookup, SignedExtension}, - weights::{DispatchInfo, DispatchClass}, testing::{Digest, DigestItem, Header, UintAuthorityId, H256}, }; use support::{ assert_ok, assert_err, impl_outer_dispatch, impl_outer_event, impl_outer_origin, parameter_types, storage::child, StorageMap, StorageValue, traits::{Currency, Get}, + weights::{DispatchInfo, DispatchClass}, }; use std::{cell::RefCell, sync::atomic::{AtomicUsize, Ordering}}; use primitives::storage::well_known_keys; diff --git a/palette/democracy/src/lib.rs b/palette/democracy/src/lib.rs index 545666e493026202199aff88ef74d717f3c3ab52..3ff6c1e2ecc72a2e1bc18a7c7a7354b586fa78ec 100644 --- a/palette/democracy/src/lib.rs +++ b/palette/democracy/src/lib.rs @@ -23,12 +23,12 @@ use rstd::{result, convert::TryFrom}; use sr_primitives::{ RuntimeDebug, traits::{Zero, Bounded, CheckedMul, CheckedDiv, EnsureOrigin, Hash, Dispatchable}, - weights::SimpleDispatchInfo, }; use codec::{Ref, Encode, Decode, Input, Output, Error}; use support::{ decl_module, decl_storage, decl_event, ensure, Parameter, + weights::SimpleDispatchInfo, traits::{ Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, Get, OnFreeBalanceZero diff --git a/palette/elections-phragmen/Cargo.toml b/palette/elections-phragmen/Cargo.toml index a9b3da18c944c5a49da222e83039ad067cc6abf9..fb13161bfc905603a1cb83a894b3b1a523412bae 100644 --- a/palette/elections-phragmen/Cargo.toml +++ b/palette/elections-phragmen/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false, features = ["derive"] } sr-primitives = { path = "../../primitives/sr-primitives", default-features = false } phragmen = { package = "substrate-phragmen", path = "../../primitives/phragmen", default-features = false } -palette-support = { path = "../support", default-features = false } +support = { package = "palette-support", path = "../support", default-features = false } system = { package = "palette-system", path = "../system", default-features = false } rstd = { package = "sr-std", path = "../../primitives/sr-std", default-features = false } @@ -23,7 +23,7 @@ serde = { version = "1.0.101" } default = ["std"] std = [ "codec/std", - "palette-support/std", + "support/std", "sr-primitives/std", "phragmen/std", "system/std", diff --git a/palette/elections-phragmen/src/lib.rs b/palette/elections-phragmen/src/lib.rs index 7ecbfe84b8c74a8b5185f81439b9c6de82b7b36b..978a2be0d79cb70b98499c9fa6de1b415a0dce06 100644 --- a/palette/elections-phragmen/src/lib.rs +++ b/palette/elections-phragmen/src/lib.rs @@ -79,8 +79,8 @@ use rstd::prelude::*; use codec::Decode; use sr_primitives::{print, traits::{Zero, StaticLookup, Bounded, Convert}}; -use sr_primitives::weights::SimpleDispatchInfo; -use palette_support::{ +use support::weights::SimpleDispatchInfo; +use support::{ decl_storage, decl_event, ensure, decl_module, dispatch, storage::unhashed, traits::{ @@ -667,7 +667,7 @@ impl<T: Trait> Module<T> { mod tests { use super::*; use std::cell::RefCell; - use palette_support::{assert_ok, assert_noop, parameter_types, assert_eq_uvec}; + use support::{assert_ok, assert_noop, parameter_types, assert_eq_uvec}; use primitives::H256; use sr_primitives::{ Perbill, testing::Header, BuildStorage, @@ -783,7 +783,7 @@ mod tests { pub type Block = sr_primitives::generic::Block<Header, UncheckedExtrinsic>; pub type UncheckedExtrinsic = sr_primitives::generic::UncheckedExtrinsic<u32, u64, Call, ()>; - palette_support::construct_runtime!( + support::construct_runtime!( pub enum Test where Block = Block, NodeBlock = Block, @@ -863,7 +863,7 @@ mod tests { #[test] fn temp_migration_works() { ExtBuilder::default().build().execute_with(|| { - use palette_support::storage::unhashed; + use support::storage::unhashed; use codec::Encode; let old_members = vec![1u64, 2]; diff --git a/palette/elections/src/lib.rs b/palette/elections/src/lib.rs index 1e2349440f1681abff31e6554d662cd4668a8af4..e4426c22d810925866fb438e3e6f41930dbecc45 100644 --- a/palette/elections/src/lib.rs +++ b/palette/elections/src/lib.rs @@ -28,10 +28,10 @@ use sr_primitives::{ RuntimeDebug, print, traits::{Zero, One, StaticLookup, Bounded, Saturating}, - weights::SimpleDispatchInfo, }; use support::{ dispatch::Result, decl_storage, decl_event, ensure, decl_module, + weights::SimpleDispatchInfo, traits::{ Currency, ExistenceRequirement, Get, LockableCurrency, LockIdentifier, OnUnbalanced, ReservableCurrency, WithdrawReason, WithdrawReasons, ChangeMembers diff --git a/palette/evm/src/lib.rs b/palette/evm/src/lib.rs index 30835986e20143ac9f364aeb5c007122b6962190..9a602d9077e52fca2958e31e38ec5988e4173a4a 100644 --- a/palette/evm/src/lib.rs +++ b/palette/evm/src/lib.rs @@ -28,7 +28,7 @@ use support::{dispatch::Result, decl_module, decl_storage, decl_event}; use support::traits::{Currency, WithdrawReason, ExistenceRequirement}; use system::ensure_signed; use sr_primitives::ModuleId; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use sr_primitives::traits::{UniqueSaturatedInto, AccountIdConversion}; use primitives::{U256, H256, H160}; use evm::{ExitReason, ExitSucceed, ExitError}; diff --git a/palette/example/src/lib.rs b/palette/example/src/lib.rs index 87693fcfa8bc65a14b9862f565f649c1f1154947..42e8f28b768ed49a438c7635940610dc4ca2cb18 100644 --- a/palette/example/src/lib.rs +++ b/palette/example/src/lib.rs @@ -254,12 +254,14 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::marker::PhantomData; -use support::{dispatch::Result, decl_module, decl_storage, decl_event}; +use support::{ + dispatch::Result, decl_module, decl_storage, decl_event, + weights::{SimpleDispatchInfo, DispatchInfo, DispatchClass, ClassifyDispatch, WeighData, Weight}, +}; use system::{ensure_signed, ensure_root}; use codec::{Encode, Decode}; use sr_primitives::{ traits::{SignedExtension, Bounded, SaturatedConversion}, - weights::{SimpleDispatchInfo, DispatchInfo, DispatchClass, ClassifyDispatch, WeighData, Weight}, transaction_validity::{ ValidTransaction, TransactionValidityError, InvalidTransaction, TransactionValidity, }, @@ -602,6 +604,7 @@ impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> { // other modules. type Call = Call<T>; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -610,7 +613,7 @@ impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> { &self, _who: &Self::AccountId, call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { // if the transaction is too big, just drop it. @@ -636,12 +639,12 @@ impl<T: Trait + Send + Sync> SignedExtension for WatchDummy<T> { mod tests { use super::*; - use support::{assert_ok, impl_outer_origin, parameter_types}; + use support::{assert_ok, impl_outer_origin, parameter_types, weights::GetDispatchInfo}; use primitives::H256; // The testing primitives are very useful for avoiding having to work with signatures // or public keys. `u64` is used as the `AccountId` and no `Signature`s are required. use sr_primitives::{ - Perbill, weights::GetDispatchInfo, testing::Header, + Perbill, testing::Header, traits::{BlakeTwo256, OnInitialize, OnFinalize, IdentityLookup}, }; diff --git a/palette/executive/src/lib.rs b/palette/executive/src/lib.rs index 998fb65eda004ffb072c59b756b16e6c13308223..6868d732a9165ee3e4549644fdcdc708c94f1b32 100644 --- a/palette/executive/src/lib.rs +++ b/palette/executive/src/lib.rs @@ -77,9 +77,9 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::{prelude::*, marker::PhantomData}; +use support::weights::{GetDispatchInfo, WeighBlock, DispatchInfo}; use sr_primitives::{ generic::Digest, ApplyResult, - weights::{GetDispatchInfo, WeighBlock}, traits::{ self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize, OnInitialize, NumberFor, Block as BlockT, OffchainWorker, Dispatchable, @@ -119,7 +119,9 @@ impl< > ExecuteBlock<Block> for Executive<System, Block, Context, UnsignedValidator, AllModules> where Block::Extrinsic: Checkable<Context> + Codec, - CheckedOf<Block::Extrinsic, Context>: Applyable<AccountId=System::AccountId> + GetDispatchInfo, + CheckedOf<Block::Extrinsic, Context>: + Applyable<AccountId=System::AccountId, DispatchInfo=DispatchInfo> + + GetDispatchInfo, CallOf<Block::Extrinsic, Context>: Dispatchable, OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>, UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>, @@ -143,7 +145,9 @@ impl< > Executive<System, Block, Context, UnsignedValidator, AllModules> where Block::Extrinsic: Checkable<Context> + Codec, - CheckedOf<Block::Extrinsic, Context>: Applyable<AccountId=System::AccountId> + GetDispatchInfo, + CheckedOf<Block::Extrinsic, Context>: + Applyable<AccountId=System::AccountId, DispatchInfo=DispatchInfo> + + GetDispatchInfo, CallOf<Block::Extrinsic, Context>: Dispatchable, OriginOf<Block::Extrinsic, Context>: From<Option<System::AccountId>>, UnsignedValidator: ValidateUnsigned<Call=CallOf<Block::Extrinsic, Context>>, @@ -316,12 +320,13 @@ mod tests { use super::*; use primitives::H256; use sr_primitives::{ - generic::Era, Perbill, DispatchError, weights::Weight, testing::{Digest, Header, Block}, + generic::Era, Perbill, DispatchError, testing::{Digest, Header, Block}, traits::{Bounded, Header as HeaderT, BlakeTwo256, IdentityLookup, ConvertInto}, transaction_validity::{InvalidTransaction, UnknownTransaction}, ApplyError, }; use support::{ impl_outer_event, impl_outer_origin, parameter_types, impl_outer_dispatch, + weights::Weight, traits::{Currency, LockIdentifier, LockableCurrency, WithdrawReasons, WithdrawReason}, }; use system::{Call as SystemCall, ChainContext}; @@ -329,7 +334,7 @@ mod tests { use hex_literal::hex; mod custom { - use sr_primitives::weights::SimpleDispatchInfo; + use support::weights::SimpleDispatchInfo; pub trait Trait: system::Trait {} diff --git a/palette/membership/src/lib.rs b/palette/membership/src/lib.rs index 6cd2a914e6bffea346b79ad1b3c33b763b0c1e48..472220cffdd51f1175b06a79b1b0c36f84d30a4c 100644 --- a/palette/membership/src/lib.rs +++ b/palette/membership/src/lib.rs @@ -24,10 +24,12 @@ use rstd::prelude::*; use support::{ - decl_module, decl_storage, decl_event, traits::{ChangeMembers, InitializeMembers}, + decl_module, decl_storage, decl_event, + traits::{ChangeMembers, InitializeMembers}, + weights::SimpleDispatchInfo, }; use system::ensure_root; -use sr_primitives::{traits::EnsureOrigin, weights::SimpleDispatchInfo}; +use sr_primitives::traits::EnsureOrigin; pub trait Trait<I=DefaultInstance>: system::Trait { /// The overarching event type. diff --git a/palette/nicks/src/lib.rs b/palette/nicks/src/lib.rs index 6b914ca5dc220c27ea7139a231a4d2d0b2046cf1..94b7043c17c94304032824d4d46776652a0c874d 100644 --- a/palette/nicks/src/lib.rs +++ b/palette/nicks/src/lib.rs @@ -40,12 +40,12 @@ use rstd::prelude::*; use sr_primitives::{ - traits::{StaticLookup, EnsureOrigin, Zero}, weights::SimpleDispatchInfo + traits::{StaticLookup, EnsureOrigin, Zero} }; use support::{ - decl_module, decl_event, decl_storage, ensure, traits::{ - Currency, ReservableCurrency, OnUnbalanced, Get - }, + decl_module, decl_event, decl_storage, ensure, + traits::{Currency, ReservableCurrency, OnUnbalanced, Get}, + weights::SimpleDispatchInfo, }; use system::{ensure_signed, ensure_root}; diff --git a/palette/session/src/lib.rs b/palette/session/src/lib.rs index 2057900f79dcc405d00bc62c61a7e4c9d94db976..290bffed0fffa95cf413d527afd80eee8711613b 100644 --- a/palette/session/src/lib.rs +++ b/palette/session/src/lib.rs @@ -122,7 +122,7 @@ use rstd::{prelude::*, marker::PhantomData, ops::{Sub, Rem}}; use codec::Decode; use sr_primitives::{KeyTypeId, Perbill, RuntimeAppPublic, BoundToRuntimeAppPublic}; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use sr_primitives::traits::{Convert, Zero, Member, OpaqueKeys}; use sr_staking_primitives::SessionIndex; use support::{dispatch::Result, ConsensusEngineId, decl_module, decl_event, decl_storage}; diff --git a/palette/staking/src/lib.rs b/palette/staking/src/lib.rs index d7681da76f491fb327ec28737c959ecc9610471d..29aeb7901c47b2efebe5fcc2975f50fbbce0cdda 100644 --- a/palette/staking/src/lib.rs +++ b/palette/staking/src/lib.rs @@ -255,6 +255,7 @@ use rstd::{prelude::*, result}; use codec::{HasCompact, Encode, Decode}; use support::{ decl_module, decl_event, decl_storage, ensure, + weights::SimpleDispatchInfo, traits::{ Currency, OnFreeBalanceZero, LockIdentifier, LockableCurrency, WithdrawReasons, OnUnbalanced, Imbalance, Get, Time @@ -265,7 +266,6 @@ use sr_primitives::{ Perbill, RuntimeDebug, curve::PiecewiseLinear, - weights::SimpleDispatchInfo, traits::{ Convert, Zero, One, StaticLookup, CheckedSub, Saturating, Bounded, SaturatedConversion, } diff --git a/palette/sudo/src/lib.rs b/palette/sudo/src/lib.rs index f67de6f6d885b7ed63e69860bd9c2372aceb9983..202734edb2b7a0fd2e0a94d11ca0e31b50f55a91 100644 --- a/palette/sudo/src/lib.rs +++ b/palette/sudo/src/lib.rs @@ -88,9 +88,12 @@ use rstd::prelude::*; use sr_primitives::{ - traits::{StaticLookup, Dispatchable}, weights::SimpleDispatchInfo, DispatchError, + traits::{StaticLookup, Dispatchable}, DispatchError, +}; +use support::{ + Parameter, decl_module, decl_event, decl_storage, ensure, + weights::SimpleDispatchInfo, }; -use support::{Parameter, decl_module, decl_event, decl_storage, ensure}; use system::ensure_signed; pub trait Trait: system::Trait { diff --git a/palette/support/Cargo.toml b/palette/support/Cargo.toml index 2a098b6afa2e68d04da77f16cb5e1cb1a95ca62d..07d0fee96ea9452098ffaa464591e2e1685fc336 100644 --- a/palette/support/Cargo.toml +++ b/palette/support/Cargo.toml @@ -13,6 +13,7 @@ rstd = { package = "sr-std", path = "../../primitives/sr-std", default-features runtime-io ={ package = "sr-io", path = "../../primitives/sr-io", default-features = false } sr-primitives = { path = "../../primitives/sr-primitives", default-features = false } primitives = { package = "substrate-primitives", path = "../../primitives/core", default-features = false } +sr-arithmetic = { path = "../../primitives/sr-arithmetic", default-features = false } inherents = { package = "substrate-inherents", path = "../../primitives/inherents", default-features = false } palette-support-procedural = { package = "palette-support-procedural", path = "./procedural" } paste = "0.1.6" @@ -35,6 +36,7 @@ std = [ "codec/std", "rstd/std", "sr-primitives/std", + "sr-arithmetic/std", "palette-metadata/std", "inherents/std", "state-machine", diff --git a/palette/support/src/dispatch.rs b/palette/support/src/dispatch.rs index d8d2391734cf2e12e7ddbb88fcc86edfdb652712..e53ce1cabca5f22c049af6177b5eed31c9b8263a 100644 --- a/palette/support/src/dispatch.rs +++ b/palette/support/src/dispatch.rs @@ -23,11 +23,11 @@ pub use palette_metadata::{ FunctionMetadata, DecodeDifferent, DecodeDifferentArray, FunctionArgumentMetadata, ModuleConstantMetadata, DefaultByte, DefaultByteGetter, ModuleErrorMetadata, ErrorMetadata }; +pub use crate::weights::{ + SimpleDispatchInfo, GetDispatchInfo, DispatchInfo, WeighData, ClassifyDispatch, + TransactionPriority, Weight, WeighBlock, +}; pub use sr_primitives::{ - weights::{ - SimpleDispatchInfo, GetDispatchInfo, DispatchInfo, WeighData, ClassifyDispatch, - TransactionPriority, Weight, WeighBlock, - }, traits::{Dispatchable, DispatchResult, ModuleDispatchError}, DispatchError, }; @@ -1832,7 +1832,7 @@ macro_rules! __check_reserved_fn_name { mod tests { use super::*; use crate::sr_primitives::traits::{OnInitialize, OnFinalize}; - use sr_primitives::weights::{DispatchInfo, DispatchClass}; + use crate::weights::{DispatchInfo, DispatchClass}; pub trait Trait: system::Trait + Sized where Self::AccountId: From<u32> { type Origin; diff --git a/palette/support/src/lib.rs b/palette/support/src/lib.rs index 04b4a1e8912a34f741b457e5e2d105ecab545ea3..b6578a56fd5716cc0ce357a038f6d2e3a19ea6e9 100644 --- a/palette/support/src/lib.rs +++ b/palette/support/src/lib.rs @@ -64,6 +64,7 @@ pub mod unsigned; #[macro_use] pub mod error; pub mod traits; +pub mod weights; pub use self::hash::{Twox256, Twox128, Blake2_256, Blake2_128, Twox64Concat, Hashable}; pub use self::storage::{StorageValue, StorageMap, StorageLinkedMap, StorageDoubleMap}; diff --git a/primitives/sr-primitives/src/weights.rs b/palette/support/src/weights.rs similarity index 87% rename from primitives/sr-primitives/src/weights.rs rename to palette/support/src/weights.rs index 09ebe3591394b9aca6f0f3634a252df4fa8636c6..7aaa8b31366c04aa50b68d6de0521e7752d00972 100644 --- a/primitives/sr-primitives/src/weights.rs +++ b/palette/support/src/weights.rs @@ -39,11 +39,15 @@ use serde::{Serialize, Deserialize}; use impl_trait_for_tuples::impl_for_tuples; use codec::{Encode, Decode}; -use arithmetic::traits::{Bounded, Zero}; -use crate::RuntimeDebug; +use sr_arithmetic::traits::{Bounded, Zero}; +use sr_primitives::{ + RuntimeDebug, + traits::SignedExtension, + generic::{CheckedExtrinsic, UncheckedExtrinsic}, +}; /// Re-export priority as type -pub use crate::transaction_validity::TransactionPriority; +pub use sr_primitives::transaction_validity::TransactionPriority; /// Numeric range of a transaction weight. pub type Weight = u32; @@ -219,3 +223,39 @@ impl SimpleDispatchInfo { Self::FixedNormal(0) } } + +/// Implementation for unchecked extrinsic. +impl<Address, Call, Signature, Extra> GetDispatchInfo + for UncheckedExtrinsic<Address, Call, Signature, Extra> +where + Call: GetDispatchInfo, + Extra: SignedExtension, +{ + fn get_dispatch_info(&self) -> DispatchInfo { + self.function.get_dispatch_info() + } +} + +/// Implementation for checked extrinsic. +impl<AccountId, Call, Extra> GetDispatchInfo + for CheckedExtrinsic<AccountId, Call, Extra> +where + Call: GetDispatchInfo, +{ + fn get_dispatch_info(&self) -> DispatchInfo { + self.function.get_dispatch_info() + } +} + +/// Implementation for test extrinsic. +#[cfg(feature = "std")] +impl<Call: Encode, Extra: Encode> GetDispatchInfo for sr_primitives::testing::TestXt<Call, Extra> { + fn get_dispatch_info(&self) -> DispatchInfo { + // for testing: weight == size. + DispatchInfo { + weight: self.encode().len() as _, + ..Default::default() + } + } +} + diff --git a/palette/system/rpc/Cargo.toml b/palette/system/rpc/Cargo.toml index cf179dc9f3c78e47599a2bee387f3bb2267c77ea..3b7c137b553a5205ebb7ea0bd60599018f9bb406 100644 --- a/palette/system/rpc/Cargo.toml +++ b/palette/system/rpc/Cargo.toml @@ -21,4 +21,4 @@ sp-transaction-graph = { path = "../../../primitives/transaction-pool/graph" } test-client = { package = "substrate-test-runtime-client", path = "../../../test/utils/runtime/client" } sp-transaction-pool = { path = "../../../primitives/transaction-pool" } env_logger = "0.7.0" -futures03 = { package = "futures-preview", version = "=0.3.0-alpha.19" } +futures = "0.3.1" diff --git a/palette/system/rpc/src/lib.rs b/palette/system/rpc/src/lib.rs index 1522f4d366774443da0dced18abbd13ffde79889..1f8e03bea3869d5b1469c1cf4c63d7ecc5210001 100644 --- a/palette/system/rpc/src/lib.rs +++ b/palette/system/rpc/src/lib.rs @@ -120,7 +120,7 @@ mod tests { use super::*; use sp_transaction_pool; - use futures03::executor::block_on; + use futures::executor::block_on; use test_client::{ runtime::Transfer, AccountKeyring, diff --git a/palette/system/src/lib.rs b/palette/system/src/lib.rs index 51b7820a43f881f233cc7ca0969f6371a9eb2af4..c7038f41686974307a2f2a25ee38b4718ea06732 100644 --- a/palette/system/src/lib.rs +++ b/palette/system/src/lib.rs @@ -99,7 +99,6 @@ use sr_version::RuntimeVersion; use sr_primitives::{ RuntimeDebug, generic::{self, Era}, Perbill, ApplyError, ApplyOutcome, DispatchError, - weights::{Weight, DispatchInfo, DispatchClass, SimpleDispatchInfo}, transaction_validity::{ ValidTransaction, TransactionPriority, TransactionLongevity, TransactionValidityError, InvalidTransaction, TransactionValidity, @@ -115,6 +114,7 @@ use primitives::storage::well_known_keys; use support::{ decl_module, decl_event, decl_storage, decl_error, storage, Parameter, traits::{Contains, Get}, + weights::{Weight, DispatchInfo, DispatchClass, SimpleDispatchInfo}, }; use codec::{Encode, Decode}; @@ -802,7 +802,9 @@ impl<T: Trait + Send + Sync> CheckWeight<T> { /// Checks if the current extrinsic can fit into the block with respect to block weight limits. /// /// Upon successes, it returns the new block weight as a `Result`. - fn check_weight(info: DispatchInfo) -> Result<Weight, TransactionValidityError> { + fn check_weight( + info: <Self as SignedExtension>::DispatchInfo, + ) -> Result<Weight, TransactionValidityError> { let current_weight = Module::<T>::all_extrinsics_weight(); let maximum_weight = T::MaximumBlockWeight::get(); let limit = Self::get_dispatch_limit_ratio(info.class) * maximum_weight; @@ -818,7 +820,10 @@ impl<T: Trait + Send + Sync> CheckWeight<T> { /// Checks if the current extrinsic can fit into the block with respect to block length limits. /// /// Upon successes, it returns the new block length as a `Result`. - fn check_block_length(info: DispatchInfo, len: usize) -> Result<u32, TransactionValidityError> { + fn check_block_length( + info: <Self as SignedExtension>::DispatchInfo, + len: usize, + ) -> Result<u32, TransactionValidityError> { let current_len = Module::<T>::all_extrinsics_len(); let maximum_len = T::MaximumBlockLength::get(); let limit = Self::get_dispatch_limit_ratio(info.class) * maximum_len; @@ -832,7 +837,7 @@ impl<T: Trait + Send + Sync> CheckWeight<T> { } /// get the priority of an extrinsic denoted by `info`. - fn get_priority(info: DispatchInfo) -> TransactionPriority { + fn get_priority(info: <Self as SignedExtension>::DispatchInfo) -> TransactionPriority { match info.class { DispatchClass::Normal => info.weight.into(), DispatchClass::Operational => Bounded::max_value() @@ -849,6 +854,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -857,7 +863,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> { self, _who: &Self::AccountId, _call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> Result<(), ApplyError> { let next_len = Self::check_block_length(info, len)?; @@ -871,7 +877,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckWeight<T> { &self, _who: &Self::AccountId, _call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { // There is no point in writing to storage here since changes are discarded. This basically @@ -928,6 +934,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -936,7 +943,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> { self, who: &Self::AccountId, _call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> Result<(), ApplyError> { let expected = <AccountNonce<T>>::get(who); @@ -958,7 +965,7 @@ impl<T: Trait> SignedExtension for CheckNonce<T> { &self, who: &Self::AccountId, _call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { // check index @@ -1011,13 +1018,14 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckEra<T> { type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = T::Hash; + type DispatchInfo = DispatchInfo; type Pre = (); fn validate( &self, _who: &Self::AccountId, _call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { let current_u64 = <Module<T>>::block_number().saturated_into::<u64>(); @@ -1066,6 +1074,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckGenesis<T> { type AccountId = T::AccountId; type Call = <T as Trait>::Call; type AdditionalSigned = T::Hash; + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> { @@ -1100,6 +1109,7 @@ impl<T: Trait + Send + Sync> SignedExtension for CheckVersion<T> { type AccountId = T::AccountId; type Call = <T as Trait>::Call; type AdditionalSigned = u32; + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> { diff --git a/palette/timestamp/src/lib.rs b/palette/timestamp/src/lib.rs index 52e3081c2ac7fe36f7102dbaa00d8f104802b588..523d83e0acb2918d81a8152ffda0905cd8fc8489 100644 --- a/palette/timestamp/src/lib.rs +++ b/palette/timestamp/src/lib.rs @@ -100,7 +100,7 @@ use sr_primitives::{ SimpleArithmetic, Zero, SaturatedConversion, Scale } }; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use system::ensure_none; use sp_timestamp::{ InherentError, INHERENT_IDENTIFIER, InherentType, diff --git a/palette/transaction-payment/rpc/runtime-api/Cargo.toml b/palette/transaction-payment/rpc/runtime-api/Cargo.toml index e61846d74ec282100ce452af6d58a2b69df67640..82bbf977a42a8f07cf40c7e177068c6e47adb836 100644 --- a/palette/transaction-payment/rpc/runtime-api/Cargo.toml +++ b/palette/transaction-payment/rpc/runtime-api/Cargo.toml @@ -10,9 +10,10 @@ sr-api = { path = "../../../../primitives/sr-api", default-features = false } codec = { package = "parity-scale-codec", version = "1.0.6", default-features = false, features = ["derive"] } rstd = { package = "sr-std", path = "../../../../primitives/sr-std", default-features = false } sr-primitives = { path = "../../../../primitives/sr-primitives", default-features = false } +support = { package = "palette-support", path = "../../../support", default-features = false } [dev-dependencies] -serde_json = { version = "1.0.41", features = ["arbitrary_precision"] } +serde_json = "1.0.41" [features] default = ["std"] diff --git a/palette/transaction-payment/rpc/runtime-api/src/lib.rs b/palette/transaction-payment/rpc/runtime-api/src/lib.rs index 4b20ba0c1209994ebbe89efbf88278587d859df4..755e98a212bd89607c50fae812e2f2c31d9f7bc8 100644 --- a/palette/transaction-payment/rpc/runtime-api/src/lib.rs +++ b/palette/transaction-payment/rpc/runtime-api/src/lib.rs @@ -19,7 +19,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::prelude::*; -use sr_primitives::weights::{Weight, DispatchClass}; +use support::weights::{Weight, DispatchClass}; use codec::{Encode, Codec, Decode}; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; @@ -52,11 +52,11 @@ mod tests { use super::*; #[test] - fn should_serialize_properly_with_u128() { + fn should_serialize_properly_with_u64() { let info = RuntimeDispatchInfo { weight: 5, class: DispatchClass::Normal, - partial_fee: 1_000_000_u128, + partial_fee: 1_000_000_u64, }; assert_eq!( diff --git a/palette/transaction-payment/src/lib.rs b/palette/transaction-payment/src/lib.rs index 2314edf053958537e9be6e5afe5652ba99e2a222..c3fa13c0ba869751baa6e2ab8c2b1f9194f58216 100644 --- a/palette/transaction-payment/src/lib.rs +++ b/palette/transaction-payment/src/lib.rs @@ -36,6 +36,7 @@ use codec::{Encode, Decode}; use support::{ decl_storage, decl_module, traits::{Currency, Get, OnUnbalanced, ExistenceRequirement, WithdrawReason}, + weights::{Weight, DispatchInfo, GetDispatchInfo}, }; use sr_primitives::{ Fixed64, @@ -44,7 +45,6 @@ use sr_primitives::{ TransactionValidity, }, traits::{Zero, Saturating, SignedExtension, SaturatedConversion, Convert}, - weights::{Weight, DispatchInfo, GetDispatchInfo}, }; use transaction_payment_rpc_runtime_api::RuntimeDispatchInfo; @@ -56,7 +56,7 @@ type NegativeImbalanceOf<T> = pub trait Trait: system::Trait { /// The currency type in which fees will be paid. - type Currency: Currency<Self::AccountId>; + type Currency: Currency<Self::AccountId> + Send + Sync; /// Handler for the unbalanced reduction when taking transaction fees. type OnTransactionPayment: OnUnbalanced<NegativeImbalanceOf<Self>>; @@ -113,7 +113,9 @@ impl<T: Trait> Module<T> { unchecked_extrinsic: Extrinsic, len: u32, ) -> RuntimeDispatchInfo<BalanceOf<T>> - where T: Send + Sync, + where + T: Send + Sync, + BalanceOf<T>: Send + Sync, { let dispatch_info = <Extrinsic as GetDispatchInfo>::get_dispatch_info(&unchecked_extrinsic); @@ -144,7 +146,14 @@ impl<T: Trait + Send + Sync> ChargeTransactionPayment<T> { /// and the time it consumes. /// - (optional) _tip_: if included in the transaction, it will be added on top. Only signed /// transactions can have a tip. - fn compute_fee(len: u32, info: DispatchInfo, tip: BalanceOf<T>) -> BalanceOf<T> { + fn compute_fee( + len: u32, + info: <Self as SignedExtension>::DispatchInfo, + tip: BalanceOf<T>, + ) -> BalanceOf<T> + where + BalanceOf<T>: Sync + Send, + { let len_fee = if info.pay_length_fee() { let len = <BalanceOf<T>>::from(len); let base = T::TransactionBaseFee::get(); @@ -187,6 +196,7 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T> type AccountId = T::AccountId; type Call = T::Call; type AdditionalSigned = (); + type DispatchInfo = DispatchInfo; type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } @@ -194,7 +204,7 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T> &self, who: &Self::AccountId, _call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { // pay any fees. @@ -227,13 +237,15 @@ impl<T: Trait + Send + Sync> SignedExtension for ChargeTransactionPayment<T> mod tests { use super::*; use codec::Encode; - use support::{parameter_types, impl_outer_origin, impl_outer_dispatch}; + use support::{ + parameter_types, impl_outer_origin, impl_outer_dispatch, + weights::{DispatchClass, DispatchInfo, GetDispatchInfo, Weight}, + }; use primitives::H256; use sr_primitives::{ Perbill, testing::{Header, TestXt}, traits::{BlakeTwo256, IdentityLookup, Extrinsic}, - weights::{DispatchClass, DispatchInfo, GetDispatchInfo}, }; use balances::Call as BalancesCall; use rstd::cell::RefCell; @@ -424,8 +436,6 @@ mod tests { .build() .execute_with(|| { - use sr_primitives::weights::Weight; - // maximum weight possible assert!( ChargeTransactionPayment::<Runtime>::from(0) diff --git a/palette/treasury/src/lib.rs b/palette/treasury/src/lib.rs index 4a613dfb7859c32aa19a18173519eaaa5c397dc3..d71f8731c43dd771a811feb1ef38f65a6a778ce3 100644 --- a/palette/treasury/src/lib.rs +++ b/palette/treasury/src/lib.rs @@ -69,7 +69,7 @@ use sr_primitives::{Permill, ModuleId}; use sr_primitives::traits::{ Zero, EnsureOrigin, StaticLookup, AccountIdConversion, Saturating }; -use sr_primitives::weights::SimpleDispatchInfo; +use support::weights::SimpleDispatchInfo; use codec::{Encode, Decode}; use system::ensure_signed; diff --git a/palette/utility/src/lib.rs b/palette/utility/src/lib.rs index d69e260ff9aac4f7b25c8b1923ff238e28456c7a..ae5a4bd6cbc39f98474b7b2004afacbeee4f4b42 100644 --- a/palette/utility/src/lib.rs +++ b/palette/utility/src/lib.rs @@ -21,9 +21,9 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::prelude::*; -use support::{decl_module, decl_event, Parameter}; +use support::{decl_module, decl_event, Parameter, weights::SimpleDispatchInfo}; use system::ensure_root; -use sr_primitives::{traits::Dispatchable, weights::SimpleDispatchInfo, DispatchError}; +use sr_primitives::{traits::Dispatchable, DispatchError}; /// Configuration trait. pub trait Trait: system::Trait { diff --git a/primitives/consensus/common/Cargo.toml b/primitives/consensus/common/Cargo.toml index 6901bf09b70dc8e22757d41ea1a449908353b6c6..11a266ac9dc1042bad4e3497d63bb1acc4c26527 100644 --- a/primitives/consensus/common/Cargo.toml +++ b/primitives/consensus/common/Cargo.toml @@ -11,7 +11,7 @@ libp2p = { version = "0.13.0", default-features = false } log = "0.4.8" primitives = { package = "substrate-primitives", path= "../../core" } inherents = { package = "substrate-inherents", path = "../../inherents" } -futures-preview = "0.3.0-alpha.19" +futures = { version = "0.3.1", features = ["thread-pool"] } futures-timer = "0.4.0" rstd = { package = "sr-std", path = "../../sr-std" } runtime_version = { package = "sr-version", path = "../../sr-version" } diff --git a/primitives/core/Cargo.toml b/primitives/core/Cargo.toml index 9e6b984ac2d82e690b0ab7276019609e366b4f65..240da745f46ca983bf67afae7ea118f78ccc9807 100644 --- a/primitives/core/Cargo.toml +++ b/primitives/core/Cargo.toml @@ -17,7 +17,7 @@ impl-serde = { version = "0.2.3", optional = true } wasmi = { version = "0.6.2", optional = true } hash-db = { version = "0.15.2", default-features = false } hash256-std-hasher = { version = "0.15.2", default-features = false } -ed25519-dalek = { version = "0.9.1", default-features = false, features = ["u64_backend"], optional = true } +ed25519-dalek = { version = "0.9.1", default-features = false, features = ["u64_backend"], optional = true } base58 = { version = "0.1.0", optional = true } blake2-rfc = { version = "0.2.18", default-features = false, optional = true } schnorrkel = { version = "0.8.5", features = ["preaudit_deprecated"], default-features = false, optional = true } diff --git a/primitives/rpc/api/Cargo.toml b/primitives/rpc/api/Cargo.toml index 14f608df39517edc523ea3f4b4d89738693cb76c..b6c8d9fc72b8cbc605583216d05e40d33d7b9a35 100644 --- a/primitives/rpc/api/Cargo.toml +++ b/primitives/rpc/api/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] codec = { package = "parity-scale-codec", version = "1.0.0" } derive_more = "0.15.0" -futures03 = { package = "futures-preview", version = "0.3.0-alpha.19", features = ["compat"] } +futures = { version = "0.3.1", features = ["compat"] } jsonrpc-core = "14.0.3" jsonrpc-core-client = "14.0.3" jsonrpc-derive = "14.0.3" diff --git a/primitives/rpc/api/src/helpers.rs b/primitives/rpc/api/src/helpers.rs index d500a50a869b49dac52745643c8240f0d2145c55..2735879daf56bab3b26fd56e8601834f8b8049af 100644 --- a/primitives/rpc/api/src/helpers.rs +++ b/primitives/rpc/api/src/helpers.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see <http://www.gnu.org/licenses/>. use jsonrpc_core::futures::prelude::*; -use futures03::{channel::oneshot, compat::Compat}; +use futures::{channel::oneshot, compat::Compat}; /// Wraps around `oneshot::Receiver` and adjusts the error type to produce an internal error if the /// sender gets dropped. diff --git a/primitives/runtime-interface/src/impls.rs b/primitives/runtime-interface/src/impls.rs index 7a6adc90c96ea66eb5ee89670aca172a1e38dd9a..c2821ce6ec8ac9e1bce0cf5cd73bef396b559fdd 100644 --- a/primitives/runtime-interface/src/impls.rs +++ b/primitives/runtime-interface/src/impls.rs @@ -47,7 +47,7 @@ assert_eq_size!(*const u8, u32); /// Converts a pointer and length into an `u64`. pub fn pointer_and_len_to_u64(ptr: u32, len: u32) -> u64 { // The static assertions from above are changed into a runtime check. - #[cfg(all(feature = "std", not(feature = "disable_target_static_assertions")))] + #[cfg(all(not(feature = "std"), feature = "disable_target_static_assertions"))] assert_eq!(4, rstd::mem::size_of::<usize>()); (u64::from(len) << 32) | u64::from(ptr) @@ -56,7 +56,7 @@ pub fn pointer_and_len_to_u64(ptr: u32, len: u32) -> u64 { /// Splits an `u64` into the pointer and length. pub fn pointer_and_len_from_u64(val: u64) -> (u32, u32) { // The static assertions from above are changed into a runtime check. - #[cfg(all(feature = "std", not(feature = "disable_target_static_assertions")))] + #[cfg(all(not(feature = "std"), feature = "disable_target_static_assertions"))] assert_eq!(4, rstd::mem::size_of::<usize>()); let ptr = (val & (!0u32 as u64)) as u32; diff --git a/primitives/sr-primitives/src/generic/checked_extrinsic.rs b/primitives/sr-primitives/src/generic/checked_extrinsic.rs index 3fc7711ccc451455a67877dd56c7c7db6542820a..1243261882caf369b3eabdff610330b1e38129c2 100644 --- a/primitives/sr-primitives/src/generic/checked_extrinsic.rs +++ b/primitives/sr-primitives/src/generic/checked_extrinsic.rs @@ -22,7 +22,6 @@ use crate::traits::{ }; #[allow(deprecated)] use crate::traits::ValidateUnsigned; -use crate::weights::{GetDispatchInfo, DispatchInfo}; use crate::transaction_validity::TransactionValidity; /// Definition of something that the external world might want to say; its @@ -38,16 +37,18 @@ pub struct CheckedExtrinsic<AccountId, Call, Extra> { pub function: Call, } -impl<AccountId, Call, Extra, Origin> traits::Applyable for +impl<AccountId, Call, Extra, Origin, Info> traits::Applyable for CheckedExtrinsic<AccountId, Call, Extra> where AccountId: Member + MaybeDisplay, Call: Member + Dispatchable<Origin=Origin>, - Extra: SignedExtension<AccountId=AccountId, Call=Call>, + Extra: SignedExtension<AccountId=AccountId, Call=Call, DispatchInfo=Info>, Origin: From<Option<AccountId>>, + Info: Clone, { type AccountId = AccountId; type Call = Call; + type DispatchInfo = Info; fn sender(&self) -> Option<&Self::AccountId> { self.signed.as_ref().map(|x| &x.0) @@ -56,11 +57,11 @@ where #[allow(deprecated)] // Allow ValidateUnsigned fn validate<U: ValidateUnsigned<Call = Self::Call>>( &self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { if let Some((ref id, ref extra)) = self.signed { - Extra::validate(extra, id, &self.function, info, len) + Extra::validate(extra, id, &self.function, info.clone(), len) } else { let valid = Extra::validate_unsigned(&self.function, info, len)?; let unsigned_validation = U::validate_unsigned(&self.function)?; @@ -71,28 +72,19 @@ where #[allow(deprecated)] // Allow ValidateUnsigned fn apply<U: ValidateUnsigned<Call=Self::Call>>( self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> crate::ApplyResult { let (maybe_who, pre) = if let Some((id, extra)) = self.signed { - let pre = Extra::pre_dispatch(extra, &id, &self.function, info, len)?; + let pre = Extra::pre_dispatch(extra, &id, &self.function, info.clone(), len)?; (Some(id), pre) } else { - let pre = Extra::pre_dispatch_unsigned(&self.function, info, len)?; + let pre = Extra::pre_dispatch_unsigned(&self.function, info.clone(), len)?; U::pre_dispatch(&self.function)?; (None, pre) }; let res = self.function.dispatch(Origin::from(maybe_who)); - Extra::post_dispatch(pre, info, len); + Extra::post_dispatch(pre, info.clone(), len); Ok(res.map_err(Into::into)) } } - -impl<AccountId, Call, Extra> GetDispatchInfo for CheckedExtrinsic<AccountId, Call, Extra> -where - Call: GetDispatchInfo, -{ - fn get_dispatch_info(&self) -> DispatchInfo { - self.function.get_dispatch_info() - } -} diff --git a/primitives/sr-primitives/src/generic/unchecked_extrinsic.rs b/primitives/sr-primitives/src/generic/unchecked_extrinsic.rs index 79d86a0756d3ca3dbd566c0ac1e866ee3935f833..e2bda54a313b97e529027c2abc1f2fee2cef0060 100644 --- a/primitives/sr-primitives/src/generic/unchecked_extrinsic.rs +++ b/primitives/sr-primitives/src/generic/unchecked_extrinsic.rs @@ -22,7 +22,6 @@ use codec::{Decode, Encode, EncodeLike, Input, Error}; use crate::{ traits::{self, Member, MaybeDisplay, SignedExtension, Checkable, Extrinsic, IdentifyAccount}, generic::CheckedExtrinsic, transaction_validity::{TransactionValidityError, InvalidTransaction}, - weights::{GetDispatchInfo, DispatchInfo}, }; const TRANSACTION_VERSION: u8 = 4; @@ -280,17 +279,6 @@ where } } -impl<Address, Call, Signature, Extra> GetDispatchInfo - for UncheckedExtrinsic<Address, Call, Signature, Extra> -where - Call: GetDispatchInfo, - Extra: SignedExtension, -{ - fn get_dispatch_info(&self) -> DispatchInfo { - self.function.get_dispatch_info() - } -} - #[cfg(test)] mod tests { use super::*; @@ -331,6 +319,7 @@ mod tests { type AccountId = u64; type Call = (); type AdditionalSigned = (); + type DispatchInfo = (); type Pre = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } diff --git a/primitives/sr-primitives/src/lib.rs b/primitives/sr-primitives/src/lib.rs index 33759f5d7291db439b4ae12cbb4a821ddf2eb162..4aaebe1e2209c03edc1952ff5607363031635e1d 100644 --- a/primitives/sr-primitives/src/lib.rs +++ b/primitives/sr-primitives/src/lib.rs @@ -52,7 +52,6 @@ pub mod offchain; pub mod testing; pub mod traits; pub mod transaction_validity; -pub mod weights; /// Re-export these since they're only "kind of" generic. pub use generic::{DigestItem, Digest}; diff --git a/primitives/sr-primitives/src/testing.rs b/primitives/sr-primitives/src/testing.rs index bd3f673cd5c43719d503e42085873b668add8b7a..f59346232e8d4b4cd56a12f363ed137d0c3723c9 100644 --- a/primitives/sr-primitives/src/testing.rs +++ b/primitives/sr-primitives/src/testing.rs @@ -26,7 +26,6 @@ use crate::traits::{ #[allow(deprecated)] use crate::traits::ValidateUnsigned; use crate::{generic, KeyTypeId, ApplyResult}; -use crate::weights::{GetDispatchInfo, DispatchInfo}; pub use primitives::{H256, sr25519}; use primitives::{crypto::{CryptoType, Dummy, key_types, Public}, U256}; use crate::transaction_validity::{TransactionValidity, TransactionValidityError}; @@ -326,13 +325,15 @@ impl<Call: Codec + Sync + Send, Extra> traits::Extrinsic for TestXt<Call, Extra> } } -impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where +impl<Origin, Call, Extra, Info> Applyable for TestXt<Call, Extra> where Call: 'static + Sized + Send + Sync + Clone + Eq + Codec + Debug + Dispatchable<Origin=Origin>, - Extra: SignedExtension<AccountId=u64, Call=Call>, + Extra: SignedExtension<AccountId=u64, Call=Call, DispatchInfo=Info>, Origin: From<Option<u64>>, + Info: Clone, { type AccountId = u64; type Call = Call; + type DispatchInfo = Info; fn sender(&self) -> Option<&Self::AccountId> { self.0.as_ref().map(|x| &x.0) } @@ -340,7 +341,7 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where #[allow(deprecated)] // Allow ValidateUnsigned fn validate<U: ValidateUnsigned<Call=Self::Call>>( &self, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { Ok(Default::default()) @@ -351,7 +352,7 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where #[allow(deprecated)] // Allow ValidateUnsigned fn apply<U: ValidateUnsigned<Call=Self::Call>>( self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> ApplyResult { let maybe_who = if let Some((who, extra)) = self.0 { @@ -365,13 +366,3 @@ impl<Origin, Call, Extra> Applyable for TestXt<Call, Extra> where Ok(self.1.dispatch(maybe_who.into()).map_err(Into::into)) } } - -impl<Call: Encode, Extra: Encode> GetDispatchInfo for TestXt<Call, Extra> { - fn get_dispatch_info(&self) -> DispatchInfo { - // for testing: weight == size. - DispatchInfo { - weight: self.encode().len() as _, - ..Default::default() - } - } -} diff --git a/primitives/sr-primitives/src/traits.rs b/primitives/sr-primitives/src/traits.rs index edddaf035aa9524930c3061396d61b34a3a35c1d..f4143f0c20d33a28531a90b2ffaf9e3c57b84abd 100644 --- a/primitives/sr-primitives/src/traits.rs +++ b/primitives/sr-primitives/src/traits.rs @@ -29,7 +29,6 @@ use crate::transaction_validity::{ ValidTransaction, TransactionValidity, TransactionValidityError, UnknownTransaction, }; use crate::generic::{Digest, DigestItem}; -use crate::weights::DispatchInfo; pub use arithmetic::traits::{ SimpleArithmetic, UniqueSaturatedInto, UniqueSaturatedFrom, Saturating, SaturatedConversion, Zero, One, Bounded, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, @@ -713,6 +712,11 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq /// The type that encodes information that can be passed from pre_dispatch to post-dispatch. type Pre: Default; + /// An opaque set of information attached to the transaction. This could be constructed anywhere + /// down the line in a runtime. The current substrate runtime uses a struct with the same name + /// to represent the dispatch class and weight. + type DispatchInfo: Clone; + /// Construct any additional data that should be in the signed payload of the transaction. Can /// also perform any pre-signature-verification checks and return an error if needed. fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError>; @@ -730,7 +734,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq &self, _who: &Self::AccountId, _call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { Ok(ValidTransaction::default()) @@ -748,10 +752,10 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq self, who: &Self::AccountId, call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> Result<Self::Pre, crate::ApplyError> { - self.validate(who, call, info, len) + self.validate(who, call, info.clone(), len) .map(|_| Self::Pre::default()) .map_err(Into::into) } @@ -766,7 +770,7 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq /// Make sure to perform the same checks in `pre_dispatch_unsigned` function. fn validate_unsigned( _call: &Self::Call, - _info: DispatchInfo, + _info: Self::DispatchInfo, _len: usize, ) -> TransactionValidity { Ok(ValidTransaction::default()) @@ -782,16 +786,16 @@ pub trait SignedExtension: Codec + Debug + Sync + Send + Clone + Eq + PartialEq /// perform the same validation as in `validate_unsigned`. fn pre_dispatch_unsigned( call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> Result<Self::Pre, crate::ApplyError> { - Self::validate_unsigned(call, info, len) + Self::validate_unsigned(call, info.clone(), len) .map(|_| Self::Pre::default()) .map_err(Into::into) } /// Do any post-flight stuff for a transaction. - fn post_dispatch(_pre: Self::Pre, _info: DispatchInfo, _len: usize) { } + fn post_dispatch(_pre: Self::Pre, _info: Self::DispatchInfo, _len: usize) { } } /// An error that is returned by a dispatchable function of a module. @@ -806,10 +810,11 @@ pub trait ModuleDispatchError { } #[impl_for_tuples(1, 12)] -impl<AccountId, Call> SignedExtension for Tuple { - for_tuples!( where #( Tuple: SignedExtension<AccountId=AccountId, Call=Call> )* ); +impl<AccountId, Call, Info: Clone> SignedExtension for Tuple { + for_tuples!( where #( Tuple: SignedExtension<AccountId=AccountId, Call=Call, DispatchInfo=Info> )* ); type AccountId = AccountId; type Call = Call; + type DispatchInfo = Info; for_tuples!( type AdditionalSigned = ( #( Tuple::AdditionalSigned ),* ); ); for_tuples!( type Pre = ( #( Tuple::Pre ),* ); ); @@ -821,44 +826,44 @@ impl<AccountId, Call> SignedExtension for Tuple { &self, who: &Self::AccountId, call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { let valid = ValidTransaction::default(); - for_tuples!( #( let valid = valid.combine_with(Tuple.validate(who, call, info, len)?); )* ); + for_tuples!( #( let valid = valid.combine_with(Tuple.validate(who, call, info.clone(), len)?); )* ); Ok(valid) } - fn pre_dispatch(self, who: &Self::AccountId, call: &Self::Call, info: DispatchInfo, len: usize) + fn pre_dispatch(self, who: &Self::AccountId, call: &Self::Call, info: Self::DispatchInfo, len: usize) -> Result<Self::Pre, crate::ApplyError> { - Ok(for_tuples!( ( #( Tuple.pre_dispatch(who, call, info, len)? ),* ) )) + Ok(for_tuples!( ( #( Tuple.pre_dispatch(who, call, info.clone(), len)? ),* ) )) } fn validate_unsigned( call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity { let valid = ValidTransaction::default(); - for_tuples!( #( let valid = valid.combine_with(Tuple::validate_unsigned(call, info, len)?); )* ); + for_tuples!( #( let valid = valid.combine_with(Tuple::validate_unsigned(call, info.clone(), len)?); )* ); Ok(valid) } fn pre_dispatch_unsigned( call: &Self::Call, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> Result<Self::Pre, crate::ApplyError> { - Ok(for_tuples!( ( #( Tuple::pre_dispatch_unsigned(call, info, len)? ),* ) )) + Ok(for_tuples!( ( #( Tuple::pre_dispatch_unsigned(call, info.clone(), len)? ),* ) )) } fn post_dispatch( pre: Self::Pre, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) { - for_tuples!( #( Tuple::post_dispatch(pre.Tuple, info, len); )* ) + for_tuples!( #( Tuple::post_dispatch(pre.Tuple, info.clone(), len); )* ) } } @@ -869,6 +874,7 @@ impl SignedExtension for () { type AdditionalSigned = (); type Call = (); type Pre = (); + type DispatchInfo = (); fn additional_signed(&self) -> rstd::result::Result<(), TransactionValidityError> { Ok(()) } } @@ -885,6 +891,9 @@ pub trait Applyable: Sized + Send + Sync { /// Type by which we can dispatch. Restricts the UnsignedValidator type. type Call; + /// An opaque set of information attached to the transaction. + type DispatchInfo: Clone; + /// Returns a reference to the sender if any. fn sender(&self) -> Option<&Self::AccountId>; @@ -892,7 +901,7 @@ pub trait Applyable: Sized + Send + Sync { #[allow(deprecated)] // Allow ValidateUnsigned fn validate<V: ValidateUnsigned<Call=Self::Call>>( &self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> TransactionValidity; @@ -901,7 +910,7 @@ pub trait Applyable: Sized + Send + Sync { #[allow(deprecated)] // Allow ValidateUnsigned fn apply<V: ValidateUnsigned<Call=Self::Call>>( self, - info: DispatchInfo, + info: Self::DispatchInfo, len: usize, ) -> crate::ApplyResult; } diff --git a/primitives/state-machine/Cargo.toml b/primitives/state-machine/Cargo.toml index 3f02056647a001bedd90814de3bb64a419099254..36557803e10e893f202d4cbdc3ddcedb9e3ea1c4 100644 --- a/primitives/state-machine/Cargo.toml +++ b/primitives/state-machine/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" log = "0.4.8" parking_lot = "0.9.0" hash-db = "0.15.2" -trie-db = "0.15.2" +trie-db = "0.16.0" trie-root = "0.15.2" trie = { package = "substrate-trie", path = "../trie" } primitives = { package = "substrate-primitives", path = "../core" } diff --git a/primitives/transaction-pool/graph/Cargo.toml b/primitives/transaction-pool/graph/Cargo.toml index 46d59a2a6ac63df11e9f279fae0523dbe40027cb..428b643ddbeace6a031a4e164cd41dfdd45d8e48 100644 --- a/primitives/transaction-pool/graph/Cargo.toml +++ b/primitives/transaction-pool/graph/Cargo.toml @@ -6,7 +6,7 @@ edition = "2018" [dependencies] derive_more = "0.15.0" -futures-preview = "0.3.0-alpha.19" +futures = "0.3.1" log = "0.4.8" parking_lot = "0.9.0" serde = { version = "1.0.101", features = ["derive"] } diff --git a/primitives/trie/Cargo.toml b/primitives/trie/Cargo.toml index 202c9066d0917f34f2d369d40cdfa13c0794cb84..a8e98bee0e700b3b3cf98337d18222a306a1b0d3 100644 --- a/primitives/trie/Cargo.toml +++ b/primitives/trie/Cargo.toml @@ -15,13 +15,13 @@ harness = false codec = { package = "parity-scale-codec", version = "1.0.0", default-features = false } rstd = { package = "sr-std", path = "../sr-std", default-features = false } hash-db = { version = "0.15.2", default-features = false } -trie-db = { version = "0.15.2", default-features = false } +trie-db = { version = "0.16.0", default-features = false } trie-root = { version = "0.15.2", default-features = false } memory-db = { version = "0.15.2", default-features = false } primitives = { package = "substrate-primitives", path = "../core", default-features = false } [dev-dependencies] -trie-bench = "0.16.2" +trie-bench = "0.16.3" trie-standardmap = "0.15.2" criterion = "0.2.11" hex-literal = "0.2.1" diff --git a/primitives/trie/src/lib.rs b/primitives/trie/src/lib.rs index eab05bab28af016ed9d9c092d832f97ad69b6122..de056cace1b7e39162a1457c6ad938e57cd838e6 100644 --- a/primitives/trie/src/lib.rs +++ b/primitives/trie/src/lib.rs @@ -323,7 +323,7 @@ mod tests { type Layout = super::Layout<Blake2Hasher>; fn hashed_null_node<T: TrieConfiguration>() -> TrieHash<T> { - <T::Codec as NodeCodecT<_>>::hashed_null_node() + <T::Codec as NodeCodecT>::hashed_null_node() } fn check_equivalent<T: TrieConfiguration>(input: &Vec<(&[u8], &[u8])>) { diff --git a/primitives/trie/src/node_codec.rs b/primitives/trie/src/node_codec.rs index 03cbdfce528f493a2a2a4e0bcdbe927a21e855ec..e31ce8cc912456d95c0772fbb01b67454cc84596 100644 --- a/primitives/trie/src/node_codec.rs +++ b/primitives/trie/src/node_codec.rs @@ -17,105 +17,147 @@ //! `NodeCodec` implementation for Substrate's trie format. use rstd::marker::PhantomData; +use rstd::ops::Range; use rstd::vec::Vec; use rstd::borrow::Borrow; -use codec::{Encode, Decode, Compact}; +use codec::{Encode, Decode, Input, Compact}; use hash_db::Hasher; -use trie_db::{self, NibbleSlice, node::Node, ChildReference, +use trie_db::{self, node::{NibbleSlicePlan, NodePlan, NodeHandlePlan}, ChildReference, nibble_ops, Partial, NodeCodec as NodeCodecT}; use crate::error::Error; use crate::trie_constants; use super::{node_header::{NodeHeader, NodeKind}}; -fn take<'a>(input: &mut &'a[u8], count: usize) -> Option<&'a[u8]> { - if input.len() < count { - return None +/// Helper struct for trie node decoder. This implements `codec::Input` on a byte slice, while +/// tracking the absolute position. This is similar to `std::io::Cursor` but does not implement +/// `Read` and `io` is not in `rstd`. +struct ByteSliceInput<'a> { + data: &'a [u8], + offset: usize, +} + +impl<'a> ByteSliceInput<'a> { + fn new(data: &'a [u8]) -> Self { + ByteSliceInput { + data, + offset: 0, + } + } + + fn take(&mut self, count: usize) -> Result<Range<usize>, codec::Error> { + if self.offset + count > self.data.len() { + return Err("out of data".into()); + } + + let range = self.offset..(self.offset + count); + self.offset += count; + Ok(range) + } +} + +impl<'a> Input for ByteSliceInput<'a> { + fn remaining_len(&mut self) -> Result<Option<usize>, codec::Error> { + let remaining = if self.offset <= self.data.len() { + Some(self.data.len() - self.offset) + } else { + None + }; + Ok(remaining) + } + + fn read(&mut self, into: &mut [u8]) -> Result<(), codec::Error> { + let range = self.take(into.len())?; + into.copy_from_slice(&self.data[range]); + Ok(()) + } + + fn read_byte(&mut self) -> Result<u8, codec::Error> { + if self.offset + 1 > self.data.len() { + return Err("out of data".into()); + } + + let byte = self.data[self.offset]; + self.offset += 1; + Ok(byte) } - let r = &(*input)[..count]; - *input = &(*input)[count..]; - Some(r) } /// Concrete implementation of a `NodeCodec` with Parity Codec encoding, generic over the `Hasher` #[derive(Default, Clone)] pub struct NodeCodec<H>(PhantomData<H>); -impl<H: Hasher> NodeCodecT<H> for NodeCodec<H> { +impl<H: Hasher> NodeCodecT for NodeCodec<H> { type Error = Error; + type HashOut = H::Out; fn hashed_null_node() -> <H as Hasher>::Out { - H::hash(<Self as NodeCodecT<_>>::empty_node()) + H::hash(<Self as NodeCodecT>::empty_node()) } - fn decode(data: &[u8]) -> rstd::result::Result<Node, Self::Error> { - let input = &mut &*data; - let head = NodeHeader::decode(input)?; - match head { - NodeHeader::Null => Ok(Node::Empty), + fn decode_plan(data: &[u8]) -> rstd::result::Result<NodePlan, Self::Error> { + let mut input = ByteSliceInput::new(data); + match NodeHeader::decode(&mut input)? { + NodeHeader::Null => Ok(NodePlan::Empty), NodeHeader::Branch(has_value, nibble_count) => { let padding = nibble_count % nibble_ops::NIBBLE_PER_BYTE != 0; // check that the padding is valid (if any) - if padding && nibble_ops::pad_left(input[0]) != 0 { + if padding && nibble_ops::pad_left(data[input.offset]) != 0 { return Err(Error::BadFormat); } - let nibble_data = take( - input, + let partial = input.take( (nibble_count + (nibble_ops::NIBBLE_PER_BYTE - 1)) / nibble_ops::NIBBLE_PER_BYTE, - ).ok_or(Error::BadFormat)?; - let nibble_slice = NibbleSlice::new_offset( - nibble_data, - nibble_ops::number_padding(nibble_count), - ); - let bitmap_slice = take(input, BITMAP_LENGTH).ok_or(Error::BadFormat)?; - let bitmap = Bitmap::decode(&bitmap_slice[..])?; + )?; + let partial_padding = nibble_ops::number_padding(nibble_count); + let bitmap_range = input.take(BITMAP_LENGTH)?; + let bitmap = Bitmap::decode(&data[bitmap_range])?; let value = if has_value { - let count = <Compact<u32>>::decode(input)?.0 as usize; - Some(take(input, count).ok_or(Error::BadFormat)?) + let count = <Compact<u32>>::decode(&mut input)?.0 as usize; + Some(input.take(count)?) } else { None }; - let mut children = [None; 16]; - + let mut children = [ + None, None, None, None, None, None, None, None, + None, None, None, None, None, None, None, None, + ]; for i in 0..nibble_ops::NIBBLE_LENGTH { if bitmap.value_at(i) { - let count = <Compact<u32>>::decode(input)?.0 as usize; - children[i] = Some(take(input, count).ok_or(Error::BadFormat)?); + let count = <Compact<u32>>::decode(&mut input)?.0 as usize; + let range = input.take(count)?; + children[i] = Some(if count == H::LENGTH { + NodeHandlePlan::Hash(range) + } else { + NodeHandlePlan::Inline(range) + }); } } - Ok(Node::NibbledBranch(nibble_slice, children, value)) + Ok(NodePlan::NibbledBranch { + partial: NibbleSlicePlan::new(partial, partial_padding), + value, + children, + }) } NodeHeader::Leaf(nibble_count) => { let padding = nibble_count % nibble_ops::NIBBLE_PER_BYTE != 0; // check that the padding is valid (if any) - if padding && nibble_ops::pad_left(input[0]) != 0 { + if padding && nibble_ops::pad_left(data[input.offset]) != 0 { return Err(Error::BadFormat); } - let nibble_data = take( - input, + let partial = input.take( (nibble_count + (nibble_ops::NIBBLE_PER_BYTE - 1)) / nibble_ops::NIBBLE_PER_BYTE, - ).ok_or(Error::BadFormat)?; - let nibble_slice = NibbleSlice::new_offset( - nibble_data, - nibble_ops::number_padding(nibble_count), - ); - let count = <Compact<u32>>::decode(input)?.0 as usize; - Ok(Node::Leaf(nibble_slice, take(input, count).ok_or(Error::BadFormat)?)) + )?; + let partial_padding = nibble_ops::number_padding(nibble_count); + let count = <Compact<u32>>::decode(&mut input)?.0 as usize; + Ok(NodePlan::Leaf { + partial: NibbleSlicePlan::new(partial, partial_padding), + value: input.take(count)?, + }) } } } - fn try_decode_hash(data: &[u8]) -> Option<<H as Hasher>::Out> { - if data.len() == H::LENGTH { - let mut r = <H as Hasher>::Out::default(); - r.as_mut().copy_from_slice(data); - Some(r) - } else { - None - } - } - fn is_empty_node(data: &[u8]) -> bool { - data == <Self as NodeCodecT<_>>::empty_node() + data == <Self as NodeCodecT>::empty_node() } fn empty_node() -> &'static [u8] { diff --git a/test/utils/client/Cargo.toml b/test/utils/client/Cargo.toml index 82bae9dbab2f411b4c9fbacf210500f0efe5c1be..e1536046034df1ae41424392dd2a3ba0d30ba1d0 100644 --- a/test/utils/client/Cargo.toml +++ b/test/utils/client/Cargo.toml @@ -10,7 +10,7 @@ client = { package = "substrate-client", path = "../../../client/" } client-db = { package = "substrate-client-db", path = "../../../client//db", features = ["test-helpers"] } consensus = { package = "substrate-consensus-common", path = "../../../primitives/consensus/common" } executor = { package = "substrate-executor", path = "../../../client/executor" } -futures-preview = "0.3.0-alpha.19" +futures = "0.3.1" hash-db = "0.15.2" keyring = { package = "substrate-keyring", path = "../../../primitives/keyring" } codec = { package = "parity-scale-codec", version = "1.0.0" } diff --git a/test/utils/runtime/Cargo.toml b/test/utils/runtime/Cargo.toml index 4caba58301e4ae293a16202a3a02c1b5a8fd01b9..580ed816e0c2bc2c4088b45a86da328c20201c77 100644 --- a/test/utils/runtime/Cargo.toml +++ b/test/utils/runtime/Cargo.toml @@ -35,7 +35,7 @@ pallet-timestamp = { path = "../../../palette/timestamp", default-features = fal substrate-client = { path = "../../../client", optional = true } substrate-trie = { path = "../../../primitives/trie", default-features = false } transaction-pool-api = { package = "substrate-transaction-pool-runtime-api", path = "../../../primitives/transaction-pool/runtime-api", default-features = false } -trie-db = { version = "0.15.2", default-features = false } +trie-db = { version = "0.16.0", default-features = false } [dev-dependencies] substrate-executor = { path = "../../../client/executor" }