diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index bcedb0c6e123a37adbe99fd3f91f0f6a0fa414c2..82fb604112e17b1d0b3c141ddf8679552fed068e 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -7,17 +7,18 @@ stages: + - pre-test - test - build - publish - - deploy - -image: parity/rust-builder:latest + - kubernetes + - flaming-fir variables: GIT_STRATEGY: fetch CARGO_HOME: "/ci-cache/${CI_PROJECT_NAME}/cargo/${CI_JOB_NAME}" SCCACHE_DIR: "/ci-cache/${CI_PROJECT_NAME}/sccache" + CARGO_INCREMENTAL: 0 CI_SERVER_NAME: "GitLab CI" DOCKER_OS: "debian:stretch" ARCH: "x86_64" @@ -37,11 +38,27 @@ variables: environment: name: parity-build +.docker-env: &docker-env + image: parity/rust-builder:latest + before_script: + - rustup show + - cargo --version + - sccache -s + only: + - tags + - master + - /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 + - schedules + - web + - /^[0-9]+$/ # PRs + tags: + - linux-docker + #### stage: test check-runtime: - stage: test + stage: pre-test image: parity/tools:latest <<: *kubernetes-build only: @@ -51,59 +68,91 @@ check-runtime: GITHUB_API_PROJECT: "parity%2Finfrastructure%2Fgithub-api" script: - ./scripts/gitlab/check_runtime.sh + allow_failure: true check-line-width: - stage: test + stage: pre-test image: parity/tools:latest <<: *kubernetes-build only: - /^[0-9]+$/ script: - ./scripts/gitlab/check_line_width.sh - allow_failure: false + allow_failure: true -test-linux-stable: &test +cargo-audit: + stage: pre-test + <<: *docker-env + except: + - /^[0-9]+$/ + script: + - cargo audit + allow_failure: true + + +cargo-check-subkey: + stage: test + <<: *docker-env + except: + - /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 + script: + - cd ./subkey + - time cargo check --release # makes sense to save artifacts for building it + - sccache -s + + +test-linux-stable: &test-linux stage: test + <<: *docker-env variables: - RUST_TOOLCHAIN: stable # Enable debug assertions since we are running optimized builds for testing # but still want to have debug assertions. RUSTFLAGS: -Cdebug-assertions=y - TARGET: native - tags: - - linux-docker - only: - - tags - - master - - schedules - - web - - /^[0-9]+$/ except: variables: - $DEPLOY_TAG - before_script: - - sccache -s - - ./scripts/build.sh script: + - ./scripts/build.sh --locked - time cargo test --all --release --verbose --locked - sccache -s +test-linux-stable-int: + <<: *test-linux + except: + refs: + - /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 + variables: + - $DEPLOY_TAG + script: + - ./scripts/build.sh --locked + - time RUST_LOG=sync=trace,consensus=trace,client=trace,state-db=trace,db=trace,forks=trace,state_db=trace,storage_cache=trace + cargo test -p node-cli --release --verbose --locked -- --ignored --test-threads=1 + - sccache -s + allow_failure: true + + check-web-wasm: stage: test + <<: *docker-env allow_failure: true - only: - - master - - /^[0-9]+$/ + except: + - /^v[0-9]+\.[0-9]+.*$/ # i.e. v1.0, v2.1rc1 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-keyring + - time cargo web build -p substrate-keystore - time cargo web build -p substrate-executor + - time cargo web build -p substrate-network - time cargo web build -p substrate-network-libp2p - time cargo web build -p substrate-panic-handler - time cargo web build -p substrate-peerset @@ -111,11 +160,11 @@ check-web-wasm: - time cargo web build -p substrate-serializer - time cargo web build -p substrate-state-db - time cargo web build -p substrate-state-machine + - time cargo web build -p substrate-telemetry - time cargo web build -p substrate-trie - tags: - - linux-docker + - sccache -s -.build-only: &build-only +.build-only: &build-only only: - master - tags @@ -123,19 +172,16 @@ check-web-wasm: #### stage: build -build-linux-release: &build +build-linux-release: stage: build <<: *collect-artifacts + <<: *docker-env <<: *build-only except: variables: - $DEPLOY_TAG - tags: - - linux-docker - before_script: - - sccache -s - - ./scripts/build.sh script: + - ./scripts/build.sh --locked - time cargo build --release --verbose - mkdir -p ./artifacts - mv ./target/release/substrate ./artifacts/. @@ -153,8 +199,9 @@ build-linux-release: &build - cp -r scripts/docker/* ./artifacts - sccache -s -build-rust-doc-release: &build +build-rust-doc-release: stage: build + <<: *docker-env allow_failure: true artifacts: name: "${CI_JOB_NAME}_${CI_COMMIT_REF_NAME}-doc" @@ -163,14 +210,10 @@ build-rust-doc-release: &build paths: - ./crate-docs <<: *build-only - tags: - - linux-docker - before_script: - - sccache -s - - ./scripts/build.sh script: + - ./scripts/build.sh --locked - rm -f ./crate-docs/index.html # use it as an indicator if the job succeeds - - time cargo +nightly doc --release --verbose + - time cargo +nightly doc --release --all --verbose - cp -R ./target/doc ./crate-docs - echo "" > ./crate-docs/index.html - sccache -s @@ -208,9 +251,9 @@ publish-docker-release: - test -z "${VERSION}" && exit 1 - cd ./artifacts - docker build - --build-arg VCS_REF="${CI_COMMIT_SHORT_SHA}" + --build-arg VCS_REF="${CI_COMMIT_SHA}" --build-arg BUILD_DATE="$(date -u '+%Y-%m-%dT%H:%M:%SZ')" - --tag $CONTAINER_IMAGE:$VERSION + --tag $CONTAINER_IMAGE:$VERSION --tag $CONTAINER_IMAGE:latest . - docker push $CONTAINER_IMAGE:$VERSION - docker push $CONTAINER_IMAGE:latest @@ -264,7 +307,7 @@ publish-s3-doc: --human-readable --summarize .deploy-template: &deploy - stage: deploy + stage: kubernetes when: manual retry: 1 image: parity/kubetools:latest @@ -314,40 +357,46 @@ publish-s3-doc: deploy-ew3: <<: *deploy-cibuild environment: - name: parity-prod-ew3 + name: parity-prod-ew3 deploy-ue1: <<: *deploy-cibuild environment: - name: parity-prod-ue1 + name: parity-prod-ue1 deploy-ew3-tag: <<: *deploy-tag environment: - name: parity-prod-ew3 + name: parity-prod-ew3 deploy-ue1-tag: <<: *deploy-tag environment: - name: parity-prod-ue1 + name: parity-prod-ue1 -.validator-deploy: &validator-deploy - stage: publish +.validator-deploy: &validator-deploy + stage: flaming-fir dependencies: - build-linux-release - image: parity/azure-ansible:v1 - allow_failure: true - when: manual + image: parity/azure-ansible:v1 + allow_failure: true + when: manual tags: - linux-docker -validator1: - <<: *validator-deploy +validator 1 4: + <<: *validator-deploy script: - - ansible-playbook -i scripts/ansible/inventory.ini -u gitlab scripts/ansible/alexander.yml -l validator1 - -validator2: - <<: *validator-deploy + - ./scripts/flamingfir-deploy.sh flamingfir-validator1 +validator 2 4: + <<: *validator-deploy script: - - ansible-playbook -i scripts/ansible/inventory.ini -u gitlab scripts/ansible/alexander.yml -l validator2 - + - ./scripts/flamingfir-deploy.sh flamingfir-validator2 +validator 3 4: + <<: *validator-deploy + script: + - ./scripts/flamingfir-deploy.sh flamingfir-validator3 +validator 4 4: + <<: *validator-deploy + script: + - ./scripts/flamingfir-deploy.sh flamingfir-validator4 diff --git a/Cargo.lock b/Cargo.lock index a2a3a4c2bd98b84cdc2d3b14b148fdb803663034..ef24acc3d5579b614523f0fbb862941d4c511574 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1,22 +1,9 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. [[package]] -name = "MacTypes-sys" -version = "2.1.0" +name = "adler32" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "aes" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "aes-ctr" @@ -35,7 +22,7 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -62,12 +49,12 @@ name = "aio-limited" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -116,7 +103,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -129,27 +116,26 @@ name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.15" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -157,15 +143,10 @@ name = "backtrace-sys" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "base-x" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "base58" version = "0.1.0" @@ -176,7 +157,7 @@ name = "base64" version = "0.9.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -185,7 +166,7 @@ name = "base64" version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -193,7 +174,7 @@ name = "bigint" version = "4.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -202,9 +183,9 @@ name = "bindgen" version = "0.47.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -212,15 +193,15 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "bitflags" -version = "1.0.4" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -257,15 +238,6 @@ dependencies = [ "generic-array 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "block-buffer" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "block-buffer" version = "0.7.3" @@ -273,7 +245,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -285,15 +257,6 @@ dependencies = [ "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "block-modes" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "block-padding" version = "0.1.4" @@ -309,15 +272,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "bstr" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "build_const" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bumpalo" -version = "2.4.1" +version = "2.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -337,7 +305,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "byteorder" -version = "1.3.1" +version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -345,7 +313,8 @@ name = "bytes" version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -361,7 +330,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.26" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -377,7 +346,7 @@ dependencies = [ [[package]] name = "cfg-if" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -395,8 +364,8 @@ name = "chrono" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -406,8 +375,8 @@ version = "0.26.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "libloading 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -417,7 +386,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -430,7 +399,7 @@ name = "clear_on_drop" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -438,15 +407,15 @@ name = "cloudabi" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "cmake" -version = "0.1.35" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -456,19 +425,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "core-foundation" -version = "0.5.1" +version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "core-foundation-sys" -version = "0.5.1" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "crc" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -483,18 +465,18 @@ dependencies = [ "csv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xoshiro 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "tinytemplate 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tinytemplate 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "walkdir 2.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -502,7 +484,7 @@ name = "criterion-plot" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -512,13 +494,13 @@ name = "crossbeam" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -528,7 +510,7 @@ version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -564,7 +546,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -578,7 +560,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -598,7 +580,7 @@ name = "crossbeam-utils" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -606,7 +588,7 @@ name = "crossbeam-utils" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -617,7 +599,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crunchy" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -629,15 +611,6 @@ dependencies = [ "generic-array 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crypto-mac" -version = "0.6.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "crypto-mac" version = "0.7.0" @@ -653,9 +626,9 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -672,7 +645,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -686,10 +659,10 @@ dependencies = [ [[package]] name = "ctrlc" -version = "3.1.2" +version = "3.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)", + "nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -704,14 +677,14 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "1.1.3" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -721,13 +694,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "derive_more" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -743,14 +716,6 @@ dependencies = [ "generic-array 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "digest" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "digest" version = "0.8.0" @@ -759,17 +724,12 @@ dependencies = [ "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "dns-parser" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -779,7 +739,7 @@ version = "1.0.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -806,8 +766,8 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -820,15 +780,16 @@ name = "erased-serde" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "error-chain" -version = "0.12.0" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)", + "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -836,7 +797,7 @@ name = "exit-future" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -845,7 +806,7 @@ name = "failure" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -854,10 +815,10 @@ name = "failure_derive" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -870,7 +831,7 @@ name = "fdlimit" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -878,10 +839,10 @@ name = "finality-grandpa" version = "0.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -892,14 +853,27 @@ name = "fixed-hash" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "flate2" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "fnv" version = "1.0.6" @@ -931,8 +905,8 @@ version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "libloading 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -946,7 +920,7 @@ name = "fuchsia-zircon" version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -957,7 +931,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.1.26" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -965,8 +939,8 @@ name = "futures-cpupool" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -983,14 +957,6 @@ dependencies = [ "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "generic-array" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "generic-array" version = "0.12.0" @@ -1006,7 +972,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "get_if_addrs-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1016,7 +982,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1035,26 +1001,26 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "bstr 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "bstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "h2" -version = "0.1.18" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "string 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1068,7 +1034,7 @@ name = "hash256-std-hasher" version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1076,7 +1042,7 @@ name = "hashbrown" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1098,7 +1064,7 @@ name = "heck" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1121,7 +1087,7 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hex-literal-impl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1137,7 +1103,7 @@ name = "hex-literal-impl" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1150,15 +1116,6 @@ dependencies = [ "generic-array 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "hmac" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "crypto-mac 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "hmac" version = "0.7.0" @@ -1185,7 +1142,18 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "http-body" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1203,7 +1171,7 @@ dependencies = [ [[package]] name = "hyper" -version = "0.10.15" +version = "0.10.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1211,7 +1179,7 @@ dependencies = [ "language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", "traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1221,28 +1189,30 @@ dependencies = [ [[package]] name = "hyper" -version = "0.12.27" +version = "0.12.29" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", - "h2 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)", + "h2 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1270,7 +1240,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "impl-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1293,10 +1271,15 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ipnet" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "itertools" version = "0.8.0" @@ -1307,91 +1290,116 @@ dependencies = [ [[package]] name = "itoa" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "js-sys" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "jsonrpc-client-transports" +version = "12.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.12.29 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "websocket 0.22.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "jsonrpc-core" -version = "10.1.0" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "jsonrpc-core-client" +version = "12.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "jsonrpc-client-transports 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "jsonrpc-derive" -version = "10.1.0" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "jsonrpc-http-server" -version = "10.1.0" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hyper 0.12.27 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-server-utils 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.12.29 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-server-utils 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "unicase 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "jsonrpc-pubsub" -version = "10.1.0" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "jsonrpc-core 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "jsonrpc-server-utils" -version = "10.1.0" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "globset 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "unicase 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "unicase 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "jsonrpc-ws-server" -version = "10.1.0" +version = "12.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-server-utils 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-server-utils 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-ws 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ws 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1406,7 +1414,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1446,9 +1454,9 @@ dependencies = [ "interleaved-ordered 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1469,56 +1477,58 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.51" +version = "0.2.58" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libloading" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core-derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-dns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-floodsub 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-identify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-kad 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-mdns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-mplex 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-noise 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-ping 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-plaintext 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-ratelimit 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-secio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-tcp 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-uds 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-websocket 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-yamux 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core-derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-deflate 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-dns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-floodsub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identify 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-kad 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-mdns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-mplex 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-noise 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-ping 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-plaintext 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-ratelimit 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-secio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-tcp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-uds 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-wasm-ext 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-websocket 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-yamux 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-core" -version = "0.7.1" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1527,66 +1537,76 @@ dependencies = [ "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "multistream-select 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "secp256k1 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-core-derive" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libp2p-deflate" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-dns" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-floodsub" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "cuckoofilter 0.3.2 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1594,28 +1614,28 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-kad" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1624,54 +1644,55 @@ dependencies = [ "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-mdns" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-mplex" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1679,59 +1700,62 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", "snow 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-ping" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-plaintext" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-ratelimit" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1739,44 +1763,44 @@ dependencies = [ [[package]] name = "libp2p-secio" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "secp256k1 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-futures 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-tcp" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ipnet 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1784,53 +1808,68 @@ dependencies = [ [[package]] name = "libp2p-uds" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libp2p-websocket" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "soketto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "websocket 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-rustls 0.10.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-yamux" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "yamux 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "yamux 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "librocksdb-sys" -version = "5.17.2" +version = "5.18.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bindgen 0.47.3 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1868,6 +1907,14 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lock_api" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.3.9" @@ -1881,7 +1928,7 @@ name = "log" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1902,7 +1949,7 @@ name = "memchr" version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1927,10 +1974,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "merlin" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1944,17 +1991,44 @@ dependencies = [ "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "miniz-sys" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide_c_api" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "mio" -version = "0.6.16" +version = "0.6.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1969,7 +2043,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1979,8 +2053,8 @@ version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2000,9 +2074,9 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2018,19 +2092,19 @@ dependencies = [ [[package]] name = "native-tls" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl 0.10.23 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)", "schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2038,20 +2112,20 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "nix" -version = "0.13.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2060,22 +2134,28 @@ name = "node-cli" version = "2.0.0" dependencies = [ "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "node-executor 2.0.0", "node-primitives 2.0.0", "node-runtime 2.0.0", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", - "structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", + "srml-finality-tracker 2.0.0", + "srml-indices 2.0.0", + "srml-timestamp 2.0.0", + "structopt 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-basic-authorship 2.0.0", "substrate-cli 2.0.0", "substrate-client 2.0.0", "substrate-consensus-aura 2.0.0", + "substrate-consensus-common 2.0.0", "substrate-finality-grandpa 2.0.0", "substrate-inherents 2.0.0", + "substrate-keyring 2.0.0", "substrate-keystore 2.0.0", "substrate-network 2.0.0", "substrate-primitives 2.0.0", @@ -2083,7 +2163,8 @@ dependencies = [ "substrate-service-test 2.0.0", "substrate-telemetry 2.0.0", "substrate-transaction-pool 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "transaction-factory 0.0.1", ] [[package]] @@ -2110,6 +2191,7 @@ dependencies = [ "substrate-keyring 2.0.0", "substrate-primitives 2.0.0", "substrate-state-machine 2.0.0", + "substrate-test-client 2.0.0", "substrate-trie 2.0.0", "trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2121,13 +2203,26 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "substrate-primitives 2.0.0", "substrate-serializer 2.0.0", ] +[[package]] +name = "node-rpc-client" +version = "2.0.0" +dependencies = [ + "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.12.29 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core-client 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "node-primitives 2.0.0", + "substrate-rpc 2.0.0", +] + [[package]] name = "node-runtime" version = "2.0.0" @@ -2137,7 +2232,7 @@ dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "sr-version 2.0.0", @@ -2170,14 +2265,14 @@ dependencies = [ name = "node-template" version = "2.0.0" dependencies = [ - "ctrlc 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "node-template-runtime 2.0.0", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "substrate-basic-authorship 2.0.0", "substrate-cli 2.0.0", @@ -2189,7 +2284,7 @@ dependencies = [ "substrate-primitives 2.0.0", "substrate-service 2.0.0", "substrate-transaction-pool 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2200,7 +2295,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2242,23 +2337,27 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.39" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "num_cpus" -version = "1.10.0" +version = "1.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2290,15 +2389,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "openssl" -version = "0.10.20" +version = "0.10.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2308,13 +2407,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "openssl-sys" -version = "0.9.43" +version = "0.9.47" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2354,7 +2453,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2362,80 +2461,53 @@ name = "parity-codec-derive" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "parity-crypto" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "block-modes 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ripemd160 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "scrypt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-multiaddr" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-multihash" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "parity-wasm" -version = "0.31.3" +name = "parity-send-wrapper" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] -name = "parity-ws" -version = "0.8.0" +name = "parity-wasm" +version = "0.31.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2465,14 +2537,24 @@ dependencies = [ "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parking_lot_core" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2481,10 +2563,10 @@ name = "parking_lot_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2493,41 +2575,46 @@ name = "parking_lot_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "paste" -version = "0.1.5" +name = "parking_lot_core" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "paste-impl" +name = "paste" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "pbkdf2" -version = "0.2.3" +name = "paste-impl" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crypto-mac 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2535,7 +2622,7 @@ name = "pbkdf2" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2577,21 +2664,21 @@ dependencies = [ [[package]] name = "primitive-types" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-crate" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2604,12 +2691,12 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.5.5" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2619,7 +2706,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "0.4.28" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2627,7 +2714,7 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.5.0" +version = "2.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2635,7 +2722,7 @@ name = "pwasm-utils" version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2655,7 +2742,7 @@ name = "quote" version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2663,7 +2750,7 @@ name = "rand" version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2673,7 +2760,7 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2686,7 +2773,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2696,13 +2783,13 @@ name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2714,7 +2801,7 @@ name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2749,10 +2836,10 @@ dependencies = [ [[package]] name = "rand_jitter" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2764,7 +2851,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2775,7 +2862,7 @@ name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2792,7 +2879,7 @@ name = "rand_xoshiro" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2813,8 +2900,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2845,19 +2932,19 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "regex" -version = "1.1.6" +version = "1.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", - "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" -version = "0.6.6" +version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2876,8 +2963,8 @@ name = "rhododendron" version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2888,31 +2975,21 @@ name = "ring" version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ripemd160" -version = "0.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "rocksdb" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "librocksdb-sys 5.17.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "librocksdb-sys 5.18.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2921,13 +2998,13 @@ version = "3.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-demangle" -version = "0.1.14" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2943,19 +3020,32 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustls" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rw-stream-sink" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ryu" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2994,15 +3084,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3011,45 +3101,36 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "scrypt" -version = "0.1.2" +name = "scopeguard" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hmac 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", - "pbkdf2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] -name = "secp256k1" -version = "0.12.2" +name = "sct" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "security-framework" -version = "0.2.2" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", - "security-framework-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", + "security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "security-framework-sys" -version = "0.2.3" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "MacTypes-sys 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3072,20 +3153,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.90" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.90" +version = "1.0.92" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3093,9 +3174,9 @@ name = "serde_json" version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3126,17 +3207,6 @@ dependencies = [ "generic-array 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "sha2" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)", - "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "sha2" version = "0.8.0" @@ -3150,7 +3220,7 @@ dependencies = [ [[package]] name = "sha3" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3182,16 +3252,6 @@ dependencies = [ "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "slog-async" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "slog-json" version = "2.3.0" @@ -3199,7 +3259,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3219,14 +3279,14 @@ name = "slog_derive" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "smallvec" -version = "0.6.9" +version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3235,15 +3295,33 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "soketto" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3263,8 +3341,8 @@ dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-version 2.0.0", @@ -3272,9 +3350,9 @@ dependencies = [ "substrate-consensus-common 2.0.0", "substrate-primitives 2.0.0", "substrate-state-machine 2.0.0", - "substrate-test-client 2.0.0", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", - "trybuild 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-test-runtime-client 2.0.0", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", + "trybuild 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3287,10 +3365,11 @@ dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", + "substrate-offchain 2.0.0", "substrate-primitives 2.0.0", "substrate-state-machine 2.0.0", "substrate-trie 2.0.0", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3299,10 +3378,10 @@ version = "2.0.0" dependencies = [ "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-std 2.0.0", @@ -3335,7 +3414,7 @@ version = "2.0.0" dependencies = [ "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", ] @@ -3345,7 +3424,7 @@ name = "srml-assets" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3360,8 +3439,8 @@ version = "2.0.0" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3382,8 +3461,8 @@ dependencies = [ "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3404,7 +3483,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3419,7 +3498,7 @@ name = "srml-consensus" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3434,11 +3513,12 @@ name = "srml-contract" version = "2.0.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", "pwasm-utils 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-sandbox 2.0.0", @@ -3460,7 +3540,7 @@ dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3477,7 +3557,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3492,7 +3572,7 @@ name = "srml-example" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "srml-balances 2.0.0", @@ -3507,7 +3587,7 @@ version = "2.0.0" dependencies = [ "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3524,8 +3604,8 @@ version = "2.0.0" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3540,7 +3620,7 @@ name = "srml-grandpa" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3560,7 +3640,7 @@ dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "ref_thread_local 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3575,7 +3655,7 @@ name = "srml-metadata" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-primitives 2.0.0", ] @@ -3587,7 +3667,7 @@ dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3603,8 +3683,9 @@ name = "srml-staking" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3623,7 +3704,7 @@ name = "srml-sudo" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3642,7 +3723,7 @@ dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "paste 0.1.5 (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.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3656,31 +3737,31 @@ dependencies = [ name = "srml-support-procedural" version = "2.0.0" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "srml-support-procedural-tools 2.0.0", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "srml-support-procedural-tools" version = "2.0.0" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "srml-support-procedural-tools-derive 2.0.0", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "srml-support-procedural-tools-derive" version = "2.0.0" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3688,11 +3769,12 @@ name = "srml-support-test" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "srml-support 2.0.0", "substrate-inherents 2.0.0", "substrate-primitives 2.0.0", + "trybuild 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3702,7 +3784,7 @@ dependencies = [ "criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3715,7 +3797,7 @@ name = "srml-timestamp" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3730,7 +3812,7 @@ name = "srml-treasury" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3755,51 +3837,6 @@ name = "static_slice" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "stdweb" -version = "0.4.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-macros 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-runtime 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base-x 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "stream-cipher" version = "0.3.0" @@ -3810,8 +3847,11 @@ dependencies = [ [[package]] name = "string" -version = "0.1.3" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "strsim" @@ -3820,22 +3860,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "structopt" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", - "structopt-derive 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt-derive 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "structopt-derive" -version = "0.2.15" +version = "0.2.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3849,9 +3889,9 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3877,9 +3917,8 @@ dependencies = [ name = "substrate" version = "2.0.0" dependencies = [ - "ctrlc 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "node-cli 2.0.0", "vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3897,7 +3936,7 @@ dependencies = [ "substrate-inherents 2.0.0", "substrate-primitives 2.0.0", "substrate-telemetry 2.0.0", - "substrate-test-client 2.0.0", + "substrate-test-runtime-client 2.0.0", "substrate-transaction-pool 2.0.0", ] @@ -3920,19 +3959,19 @@ dependencies = [ "app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "rpassword 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", - "structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)", + "structopt 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-client 2.0.0", "substrate-keyring 2.0.0", "substrate-network 2.0.0", @@ -3941,26 +3980,26 @@ dependencies = [ "substrate-service 2.0.0", "substrate-state-machine 2.0.0", "substrate-telemetry 2.0.0", - "sysinfo 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sysinfo 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-client" version = "2.0.0" dependencies = [ - "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -3972,7 +4011,7 @@ dependencies = [ "substrate-primitives 2.0.0", "substrate-state-machine 2.0.0", "substrate-telemetry 2.0.0", - "substrate-test-client 2.0.0", + "substrate-test-runtime-client 2.0.0", "substrate-trie 2.0.0", ] @@ -3988,7 +4027,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", @@ -3997,7 +4036,7 @@ dependencies = [ "substrate-primitives 2.0.0", "substrate-state-db 2.0.0", "substrate-state-machine 2.0.0", - "substrate-test-client 2.0.0", + "substrate-test-runtime-client 2.0.0", "substrate-trie 2.0.0", ] @@ -4006,11 +4045,10 @@ name = "substrate-consensus-aura" version = "2.0.0" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-version 2.0.0", @@ -4029,8 +4067,9 @@ dependencies = [ "substrate-primitives 2.0.0", "substrate-service 2.0.0", "substrate-telemetry 2.0.0", - "substrate-test-client 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-test-runtime-client 2.0.0", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4060,13 +4099,12 @@ name = "substrate-consensus-babe" version = "2.0.0" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -4087,8 +4125,9 @@ dependencies = [ "substrate-primitives 2.0.0", "substrate-service 2.0.0", "substrate-telemetry 2.0.0", - "substrate-test-client 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-test-runtime-client 2.0.0", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4106,29 +4145,31 @@ name = "substrate-consensus-common" version = "2.0.0" dependencies = [ "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", + "sr-std 2.0.0", "sr-version 2.0.0", "substrate-inherents 2.0.0", "substrate-primitives 2.0.0", - "substrate-test-client 2.0.0", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-test-runtime-client 2.0.0", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-consensus-rhd" version = "2.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rhododendron 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", @@ -4141,24 +4182,24 @@ dependencies = [ "substrate-keyring 2.0.0", "substrate-primitives 2.0.0", "substrate-transaction-pool 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-consensus-slots" version = "2.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", "substrate-inherents 2.0.0", "substrate-primitives 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-test-runtime-client 2.0.0", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4166,14 +4207,14 @@ name = "substrate-executor" version = "2.0.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-version 2.0.0", "substrate-panic-handler 2.0.0", @@ -4181,7 +4222,7 @@ dependencies = [ "substrate-serializer 2.0.0", "substrate-state-machine 2.0.0", "substrate-trie 2.0.0", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4193,10 +4234,10 @@ dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "finality-grandpa 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)", "fork-tree 2.0.0", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", @@ -4210,8 +4251,8 @@ dependencies = [ "substrate-primitives 2.0.0", "substrate-service 2.0.0", "substrate-telemetry 2.0.0", - "substrate-test-client 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-test-runtime-client 2.0.0", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4230,7 +4271,7 @@ name = "substrate-inherents" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", ] @@ -4250,13 +4291,12 @@ dependencies = [ name = "substrate-keystore" version = "2.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-crypto 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 2.0.0", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4264,18 +4304,17 @@ dependencies = [ name = "substrate-network" version = "2.0.0" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "fork-tree 2.0.0", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "linked_hash_set 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", @@ -4285,8 +4324,9 @@ dependencies = [ "substrate-network-libp2p 2.0.0", "substrate-peerset 2.0.0", "substrate-primitives 2.0.0", - "substrate-test-client 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-test-runtime-client 2.0.0", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4294,29 +4334,29 @@ dependencies = [ name = "substrate-network-libp2p" version = "2.0.0" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "slog_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-peerset 2.0.0", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4324,18 +4364,18 @@ name = "substrate-offchain" version = "2.0.0" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", - "substrate-inherents 2.0.0", "substrate-offchain-primitives 2.0.0", "substrate-primitives 2.0.0", - "substrate-test-client 2.0.0", + "substrate-test-runtime-client 2.0.0", "substrate-transaction-pool 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4350,7 +4390,7 @@ dependencies = [ name = "substrate-panic-handler" version = "2.0.0" dependencies = [ - "backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4358,14 +4398,14 @@ dependencies = [ name = "substrate-peerset" version = "2.0.0" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.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)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4374,7 +4414,7 @@ version = "2.0.0" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4382,20 +4422,21 @@ dependencies = [ "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)", "substrate-serializer 2.0.0", "tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "twox-hash 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "twox-hash 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4404,41 +4445,40 @@ name = "substrate-rpc" version = "2.0.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-core 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-derive 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-pubsub 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-core-client 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-derive 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-pubsub 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-version 2.0.0", "substrate-client 2.0.0", - "substrate-consensus-common 2.0.0", "substrate-executor 2.0.0", "substrate-network 2.0.0", "substrate-primitives 2.0.0", "substrate-state-machine 2.0.0", - "substrate-test-client 2.0.0", - "substrate-test-runtime 2.0.0", + "substrate-test-runtime-client 2.0.0", "substrate-transaction-pool 2.0.0", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-rpc-servers" version = "2.0.0" dependencies = [ - "jsonrpc-http-server 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-pubsub 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-ws-server 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-http-server 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-pubsub 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-ws-server 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-rpc 2.0.0", ] @@ -4447,7 +4487,7 @@ dependencies = [ name = "substrate-serializer" version = "2.0.0" dependencies = [ - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4455,17 +4495,17 @@ dependencies = [ name = "substrate-service" version = "2.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "node-executor 2.0.0", "node-primitives 2.0.0", "node-runtime 2.0.0", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", @@ -4475,17 +4515,16 @@ dependencies = [ "substrate-consensus-common 2.0.0", "substrate-executor 2.0.0", "substrate-finality-grandpa 2.0.0", - "substrate-inherents 2.0.0", "substrate-keystore 2.0.0", "substrate-network 2.0.0", "substrate-offchain 2.0.0", "substrate-primitives 2.0.0", "substrate-rpc-servers 2.0.0", "substrate-telemetry 2.0.0", - "substrate-test-client 2.0.0", + "substrate-test-runtime-client 2.0.0", "substrate-transaction-pool 2.0.0", "target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4494,7 +4533,7 @@ version = "2.0.0" dependencies = [ "env_logger 0.6.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.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", @@ -4503,7 +4542,7 @@ dependencies = [ "substrate-primitives 2.0.0", "substrate-service 2.0.0", "tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4513,7 +4552,7 @@ dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-primitives 2.0.0", ] @@ -4524,8 +4563,9 @@ dependencies = [ "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-panic-handler 2.0.0", "substrate-primitives 2.0.0", "substrate-trie 2.0.0", @@ -4537,24 +4577,28 @@ dependencies = [ name = "substrate-telemetry" version = "2.0.0" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-test-client" version = "2.0.0" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", @@ -4564,18 +4608,17 @@ dependencies = [ "substrate-keyring 2.0.0", "substrate-primitives 2.0.0", "substrate-state-machine 2.0.0", - "substrate-test-runtime 2.0.0", ] [[package]] name = "substrate-test-runtime" version = "2.0.0" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -4591,23 +4634,33 @@ dependencies = [ "substrate-keyring 2.0.0", "substrate-offchain-primitives 2.0.0", "substrate-primitives 2.0.0", - "substrate-test-client 2.0.0", + "substrate-test-runtime-client 2.0.0", "substrate-trie 2.0.0", "trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "substrate-test-runtime-client" +version = "2.0.0" +dependencies = [ + "sr-primitives 2.0.0", + "substrate-primitives 2.0.0", + "substrate-test-client 2.0.0", + "substrate-test-runtime 2.0.0", +] + [[package]] name = "substrate-transaction-graph" version = "2.0.0" dependencies = [ "assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-primitives 2.0.0", "substrate-test-runtime 2.0.0", @@ -4617,16 +4670,16 @@ dependencies = [ name = "substrate-transaction-pool" version = "2.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", "substrate-keyring 2.0.0", "substrate-primitives 2.0.0", - "substrate-test-client 2.0.0", + "substrate-test-runtime-client 2.0.0", "substrate-transaction-graph 2.0.0", ] @@ -4645,7 +4698,7 @@ dependencies = [ "trie-bench 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-standardmap 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-standardmap 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4655,46 +4708,41 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "subtle" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.32" +version = "0.15.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "synstructure" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "sysinfo" -version = "0.8.2" +version = "0.8.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "target_info" version = "0.1.0" @@ -4711,11 +4759,11 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.0.7" +version = "3.0.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4724,7 +4772,7 @@ dependencies = [ [[package]] name = "termcolor" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4735,7 +4783,7 @@ name = "termion" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4762,7 +4810,7 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4783,7 +4831,7 @@ dependencies = [ [[package]] name = "tiny-keccak" -version = "1.4.2" +version = "1.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4791,10 +4839,10 @@ dependencies = [ [[package]] name = "tinytemplate" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4803,43 +4851,53 @@ name = "tk-listen" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio" -version = "0.1.19" +version = "0.1.21" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-trace-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "tokio-buf" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "tokio-codec" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4848,7 +4906,7 @@ name = "tokio-current-thread" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4857,10 +4915,10 @@ name = "tokio-dns-unofficial" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4869,7 +4927,7 @@ version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4877,7 +4935,7 @@ name = "tokio-fs" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4888,7 +4946,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4898,25 +4956,38 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-rustls" +version = "0.10.0-alpha.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-sync" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -4925,9 +4996,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4940,9 +5011,9 @@ dependencies = [ "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4950,11 +5021,11 @@ dependencies = [ [[package]] name = "tokio-timer" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -4964,14 +5035,14 @@ name = "tokio-tls" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-trace-core" -version = "0.1.0" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4983,9 +5054,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4997,11 +5068,11 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5010,18 +5081,10 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "toml" -version = "0.5.0" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5029,6 +5092,20 @@ name = "traitobject" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "transaction-factory" +version = "0.0.1" +dependencies = [ + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-primitives 2.0.0", + "substrate-cli 2.0.0", + "substrate-client 2.0.0", + "substrate-consensus-common 2.0.0", + "substrate-primitives 2.0.0", + "substrate-service 2.0.0", +] + [[package]] name = "trie-bench" version = "0.12.2" @@ -5041,7 +5118,7 @@ dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "trie-standardmap 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "trie-standardmap 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5066,10 +5143,9 @@ dependencies = [ [[package]] name = "trie-standardmap" -version = "0.12.2" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "keccak-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5081,15 +5157,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "trybuild" -version = "1.0.4" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5098,16 +5174,16 @@ version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "twox-hash" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5127,11 +5203,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "uint" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5146,7 +5222,7 @@ dependencies = [ [[package]] name = "unicase" -version = "2.3.0" +version = "2.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5165,12 +5241,12 @@ name = "unicode-normalization" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "unicode-segmentation" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -5209,7 +5285,7 @@ dependencies = [ [[package]] name = "utf8-ranges" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -5227,7 +5303,7 @@ name = "vergen" version = "3.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5247,8 +5323,8 @@ name = "wabt" version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "wabt-sys 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5258,14 +5334,14 @@ name = "wabt-sys" version = "0.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)", - "cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "cmake 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "walkdir" -version = "2.2.7" +version = "2.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5278,82 +5354,94 @@ name = "want" version = "0.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen-macro 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bumpalo 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-futures" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro-support 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro-support 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen-webidl" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "weedle 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-timer" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5377,32 +5465,53 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-webidl 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-webidl 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki-roots" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "websocket" -version = "0.22.3" +version = "0.22.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", - "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", - "native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)", + "native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5410,7 +5519,7 @@ dependencies = [ [[package]] name = "weedle" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5422,7 +5531,7 @@ version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -5473,18 +5582,17 @@ dependencies = [ [[package]] name = "ws" -version = "0.7.9" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5504,7 +5612,7 @@ version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -5520,11 +5628,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "yamux" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5539,9 +5647,45 @@ name = "zeroize" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "zeroize" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "zeroize_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zeroize" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "zeroize_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zeroize_derive" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zeroize_derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] -"checksum MacTypes-sys 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eaf9f0d0b1cc33a4d2aee14fb4b2eac03462ef4db29c8ac4057327d8a71ad86f" -"checksum aes 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "54eb1d8fe354e5fc611daf4f2ea97dd45a765f4f1e4512306ec183ae2e8f20c9" +"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" "checksum aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" @@ -5555,47 +5699,47 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum asn1_der_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e7f92edafad155aff997fa5b727c6429b91e996b5a5d62a2b0adbae1306b5fe" "checksum assert_matches 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7deb0a829ca7bcfaf5da70b073a8d128619259a7be8216a355e23f00763059e5" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum backtrace 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f106c02a3604afcdc0df5d36cc47b44b55917dbaf3d808f71c163a0ddba64637" +"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" +"checksum backtrace 0.3.30 (registry+https://github.com/rust-lang/crates.io-index)" = "ada4c783bb7e7443c14e0480f429ae2cc99da95065aeab7ee1b81ada0419404f" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" -"checksum base-x 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d55aa264e822dbafa12db4d54767aff17c6ba55ea2d8559b3e17392c7d000e5d" "checksum base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ebecac13b3c745150d7b6c3ea7572d372f09d627c2077e893bf26c5c7f70d282" "checksum bindgen 0.47.3 (registry+https://github.com/rust-lang/crates.io-index)" = "df683a55b54b41d5ea8ebfaebb5aa7e6b84e3f3006a78f010dadc9ca88469260" -"checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" +"checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" "checksum bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5da9b3d9f6f585199287a473f4f8dfab6566cf827d15c00c219f53c645687ead" "checksum blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91721a6330935673395a0607df4d49a9cb90ae12d259f1b3e0a3f6e1d486872e" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum block-buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1339a1042f5d9f295737ad4d9a6ab6bf81c84a933dba110b9200cd6d1448b814" -"checksum block-buffer 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a076c298b9ecdb530ed9d967e74a6027d6a7478924520acddcddc24c1c8ab3ab" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" -"checksum block-modes 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "31aa8410095e39fdb732909fb5730a48d5bd7c2e3cd76bd1b07b3dbea130c529" "checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" "checksum bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0de79cfb98e7aa9988188784d8664b4b5dad6eaaa0863b91d9a4ed871d4f7a42" -"checksum bstr 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6c8203ca06c502958719dae5f653a79e0cc6ba808ed02beffbf27d09610f2143" -"checksum bumpalo 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4639720be048090544634e0402490838995ccdc9d2fe648f528f30d3c33ae71f" +"checksum bstr 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "59604ece62a407dc9164732e5adea02467898954c3a5811fd2dc140af14ef15b" +"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" +"checksum bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "84dca3afd8e01b9526818b7963e5b4916063b3cdf9f10cf6b73ef0bd0ec37aa5" "checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" -"checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" +"checksum byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a7c3dd8985a7111efc5c80b44e23ecdd8c007de8ade3b96595387e812b957cf5" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" "checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" -"checksum cc 1.0.26 (registry+https://github.com/rust-lang/crates.io-index)" = "389803e36973d242e7fecb092b2de44a3d35ac62524b3b9339e51d577d668e02" +"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" "checksum cexpr 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "a7fa24eb00d5ffab90eaeaf1092ac85c04c64aaf358ea6f84505b8116d24c6af" -"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" +"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum clang-sys 0.26.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6ef0c1bcf2e99c649104bd7a7012d8f8802684400e03db0ec0af48583c6fa0e4" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum cmake 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)" = "6ec65ee4f9c9d16f335091d23693457ed4928657ba4982289d7fafee03bc614a" +"checksum cmake 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "2ca4386c8954b76a8415b63959337d940d724b336cabd3afe189c2b51a7e1ff0" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" -"checksum core-foundation 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "286e0b41c3a20da26536c6000a280585d519fd07b3956b43aed8a79e9edce980" -"checksum core-foundation-sys 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "716c271e8613ace48344f723b60b900a93150271e5be206212d052bbc0883efa" +"checksum core-foundation 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "25b9e03f145fd4f2bf705e07b900cd41fc636598fe5dc452fd0db1441c3f496d" +"checksum core-foundation-sys 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e7ca8a5221364ef15ce201e8ed2f609fc312682a8f4e0e3d4aa5879764e0fa3b" +"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum criterion 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0363053954f3e679645fc443321ca128b7b950a6fe288cf5f9335cc22ee58394" "checksum criterion-plot 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "76f9212ddf2f4a9eb2d401635190600656a1f88a932ef53d06e7fa4c7e02fb8e" "checksum crossbeam 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4c7ea749d9fb09e23c5cb17e3b70650860553a0e2744e38446b1803bf7db94" @@ -5609,24 +5753,21 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" -"checksum crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c240f247c278fa08a6d4820a6a222bfc6e0d999e51ba67be94f44c905b2161f2" +"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" "checksum crypto-mac 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "779015233ac67d65098614aec748ac1c756ab6677fa2e14cf8b37c08dfed1198" -"checksum crypto-mac 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7afa06d05a046c7a47c3a849907ec303504608c927f4e85f7bfff22b7180d971" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum csv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9044e25afb0924b5a5fc5511689b0918629e85d68ea591e5e87fbf1e85ea1b3b" "checksum csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5cdef62f37e6ffe7d1f07a381bc0db32b7a3ff1cac0de56cb0d81e71f53d65" "checksum ctor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3b4c17619643c1252b5f690084b82639dd7fac141c57c8e77a00e0148132092c" "checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" -"checksum ctrlc 3.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5531b7f0698d9220b4729f8811931dbe0e91a05be2f7b3245fdc50dd856bae26" +"checksum ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c7dfd2d8b4c82121dfdff120f818e09fc4380b0b7e17a742081a89b94853e87f" "checksum cuckoofilter 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" -"checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1" +"checksum curve25519-dalek 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5d4b820e8711c211745880150f5fac78ab07d6e3851d8ce9f5a02cedc199174c" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" -"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615" +"checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" "checksum difference 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "524cbf6897b527295dff137cec09ecf3a05f4fddffd7dfcd1585403449e74198" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" -"checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" -"checksum discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" "checksum dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d33be9473d06f75f58220f71f7a9317aca647dc061dbd3c361b0bef505fbea" "checksum ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81956bcf7ef761fb4e1d88de3fa181358a0d26cbcb9755b587a08f9119824b86" "checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" @@ -5634,7 +5775,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c7464757b80de8930c91c9afe77ddce501826bf9d134a87db2c67d9dc177e2c" "checksum erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3beee4bc16478a1b26f2e80ad819a52d24745e292f521a63c16eea5f74b7eb60" -"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" +"checksum error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3ab49e9dcb602294bc42f9a7dfc9bc6e936fca4418ea300dbfb84fe16de0b7d9" "checksum exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d8013f441e38e31c670e7f34ec8f1d5d3a2bd9d303c1ff83976ca886005e8f48" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" @@ -5642,6 +5783,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa" "checksum finality-grandpa 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5cdd9ef7c48777665dacc9657c272778121d4d09848100bcc2bd9c773c6cf837" "checksum fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" +"checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" @@ -5649,18 +5791,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "62941eff9507c8177d448bd83a44d9b9760856e184081d8cd79ba9f03dd24981" +"checksum futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a2037ec1c6c1c4f79557762eab1f7eae1f64f6cb418ace90fae88f0942b60139" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" "checksum generic-array 0.8.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fceb69994e330afed50c93524be68c42fa898c2d9fd4ee8da03bd7363acd26f2" -"checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" "checksum get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "abddb55a898d32925f3148bd281174a68eeb68bbfd9a5938a57b18f506ee4ef7" "checksum get_if_addrs-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d04f9fb746cf36b191c00f3ede8bde9c8e64f9f4b05ae2694a9ccf5e3f5ab48" "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum glob 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" "checksum globset 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ef4feaabe24a0a658fd9cf4a9acf6ed284f045c77df0f49020ba3245cfb7b454" -"checksum h2 0.1.18 (registry+https://github.com/rust-lang/crates.io-index)" = "85ab6286db06040ddefb71641b50017c06874614001a134b423783e2db2920bd" +"checksum h2 0.1.23 (registry+https://github.com/rust-lang/crates.io-index)" = "1e42e3daed5a7e17b12a0c23b5b2fbff23a925a570938ebee4baca1a9a1a2240" "checksum hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fb417e5c470acdd61068c79767d0e65962e70836cf6c9dfd2409f06345ce0" "checksum hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b2027c19ec91eb304999abae7307d225cf93be42af53b0039f76e98ed5af86" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" @@ -5673,30 +5814,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "520870c3213943eb8d7803e80180d12a6c7ceb4ae74602544529d1643dc4ddda" "checksum hex-literal-impl 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "06095d08c7c05760f11a071b3e1d4c5b723761c01bd8d7201c30a9536668a612" "checksum hmac 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a13f4163aa0c5ca1be584aace0e2212b2e41be5478218d4f657f5f778b2ae2a" -"checksum hmac 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "733e1b3ac906631ca01ebb577e9bb0f5e37a454032b9036b5eaea4013ed6f99a" "checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" "checksum hmac-drbg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe727d41d2eec0a6574d887914347e5ff96a3b87177817e2a9820c5c87fecc2" "checksum http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a" +"checksum http-body 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6741c859c1b2463a423a1dbce98d418e6c3c3fc720fb0d45528657320920292d" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" -"checksum hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)" = "df0caae6b71d266b91b4a83111a61d2b94ed2e2bea024c532b933dcff867e58c" -"checksum hyper 0.12.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4f2777434f26af6e4ce4fdcdccd3bed9d861d11e87bcbe72c0f51ddaca8ff848" +"checksum hyper 0.10.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0a0652d9a2609a968c14be1a9ea00bf4b1d64e2e1f53a1b51b6fff3a6e829273" +"checksum hyper 0.12.29 (registry+https://github.com/rust-lang/crates.io-index)" = "e2cd6adf83b3347d36e271f030621a8cf95fd1fd0760546b9fc5a24a0f1447c7" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2050d823639fbeae26b2b5ba09aca8907793117324858070ade0673c49f793b" "checksum impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5158079de9d4158e0ce1de3ae0bd7be03904efc40b3d7dd8b8c301cbf6b52b56" +"checksum impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d26be4b97d738552ea423f76c4f681012ff06c3fa36fa968656b3679f60b4a1" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" "checksum integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ea155abb3ba6f382a75f1418988c05fe82959ed9ce727de427f9cfd425b0c903" "checksum interleaved-ordered 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "141340095b15ed7491bd3d4ced9d20cebfb826174b6bb03386381f62b01e3d77" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" +"checksum ipnet 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e61c2da0d0f700c77d2d313dbf4f93e41d235fa12c6681fee06621036df4c2af" "checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3c994fd445b81741d77f6bcd227d6ed645b95b35a2ecfd2050767450ff1c0b6d" -"checksum jsonrpc-core 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dc15eef5f8b6bef5ac5f7440a957ff95d036e2f98706947741bfc93d1976db4c" -"checksum jsonrpc-derive 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c2dae61ca8a3b047fb11309b00661bc56837085bd07e46f907b9c562c0b03e68" -"checksum jsonrpc-http-server 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "11d2a00824306155b8ef57fe957f31b8cd8ad24262f15cf911d84dcf9a3f206d" -"checksum jsonrpc-pubsub 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37fce55133ee264d0ab42bd862efcd45ae1d062cda599f4cc12ccc4be3195f2a" -"checksum jsonrpc-server-utils 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9527f01ef25f251d64082cbefc0c6d6f367349afe6848ef908a674e06b2bdd3" -"checksum jsonrpc-ws-server 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3889012aa638a2f18eb1a879f46fc8b34e7e1423cbff3247cd1531de0d51084b" +"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +"checksum js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "9987e7c13a91d9cf0efe59cca48a3a7a70e2b11695d5a4640f85ae71e28f5e73" +"checksum jsonrpc-client-transports 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0245e08f98d627a579cdee6a2138d05ab64f6093efbcdeec50805d121ee13c0c" +"checksum jsonrpc-core 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "288dca7f9713710a29e485076b9340156cb701edb46a881f5d0c31aa4f5b9143" +"checksum jsonrpc-core-client 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05e499e393aaa97cf5ff3a7444549c94a6d27e70be1c300b865187d722f1b426" +"checksum jsonrpc-derive 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f7b65eafb36286a4251c9a1d4cdf4e9a7cf8fa4f7bf991383e42f0cf26908767" +"checksum jsonrpc-http-server 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea8b3996f19dc6dd90d928c81d30b3ce9535840487734290da9fae3b3185db5d" +"checksum jsonrpc-pubsub 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fcdd238ecccde73faea93760b068f3fe3ca84caeb6b5414c2aabd4f008dad418" +"checksum jsonrpc-server-utils 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "036a53ffa47533dcccf1e1bb16abb0f45ef9a2dc9a63654d2d2cd199b80ad33e" +"checksum jsonrpc-ws-server 12.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "977ea40f077c027553e4112d750114b9e5cc7bcf5642512838abc2a9b322bd23" "checksum keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" "checksum keccak-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "af672553b2abac1c86c29fd62c79880638b6abc91d96db4aa42a5baab2bc1ca9" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" @@ -5706,31 +5851,34 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.51 (registry+https://github.com/rust-lang/crates.io-index)" = "bedcc7a809076656486ffe045abeeac163da1b558e963a31e29fbfbeba916917" -"checksum libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9c3ad660d7cb8c5822cd83d10897b0f1f1526792737a179e73896152f85b88c2" -"checksum libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0231edab431064b30b7749484a39735eb36492cef4658c372c9059e58c3003aa" -"checksum libp2p-core 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cdcbded83195ac0e560090fc5da9c1b7f980d1ec221f02d97432db4d36793eb7" -"checksum libp2p-core-derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f765f103b680cbed910b02bfdbdcfce5b1142899c93e51acb960bf59b6f81b1" -"checksum libp2p-dns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b129d20cc8cbb6ce5da8361045649c024659173e246c5dfbf20ae06071c046a" -"checksum libp2p-floodsub 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70d68816b8435d6788399416eb2f0a6974fb1d15c4be5c30141f87c8e81746df" -"checksum libp2p-identify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "718ca645a065fd70855ca6042a7df686c24cd21add750c37a82c811fbd1e5c43" -"checksum libp2p-kad 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bbe27c623a6a720efd5d704347838972062f89149a9c3cd149748da60bdcd3e0" -"checksum libp2p-mdns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9bc1a5d85f4812cae6367b49a432763fe28997bac7c530dc55b70ec18a78aa7" -"checksum libp2p-mplex 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe5a858342a1cc89464474f7edc4bae1da649b9c823a3e04d9fb494493601746" -"checksum libp2p-noise 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc6b5185c50a52a12e7bbe2ee7799059e24de4e52ab25edbfd26c8ab8515d317" -"checksum libp2p-ping 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7905c1431ad115bee83405770629a27d6f17153ad02ec9670a7347998ef20e22" -"checksum libp2p-plaintext 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc17626763ded57da8fed73187c2d9f6ebb89d30838673c430315bf560c7e4db" -"checksum libp2p-ratelimit 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2409d08b809ab1a74269597f7da2829d117cc11b9ed3343af33fc20831619726" -"checksum libp2p-secio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258cdc6742945c8f6402997bbbf36733588e2db18e5a0014da6d46e3ccfb92cf" -"checksum libp2p-tcp 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b5691e2ba2720d42bd1e93d6b90239fa9235c1956ef6a5f1dd499a7ae2767be" -"checksum libp2p-uds 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ab0b9ca050105fd94229c48911c0c84aef4d6b86a53d1b6df81d938354e47e" -"checksum libp2p-websocket 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "81692c3141a9aefd84f4faffdc93985af3858ef82ed7fe8185e6b27437b36183" -"checksum libp2p-yamux 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6ff51a5b2056bacee1c9f2ed8455cdf3c5c619261ddb4efc783119130aaf52" -"checksum librocksdb-sys 5.17.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7dfb546562f9b450237bb8df7a31961849ee9fb1186d9e356db1d7a6b7609ff2" +"checksum libc 0.2.58 (registry+https://github.com/rust-lang/crates.io-index)" = "6281b86796ba5e4366000be6e9e18bf35580adf9e63fbe2294aadb587613a319" +"checksum libloading 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a5692f82b51823e27c4118b3e5c0d98aee9be90633ebc71ad12afef380b50219" +"checksum libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6abde4e6fc777dc06ae2a15202ddedb1a38d7c71ed16bc10fa704b03f73aec37" +"checksum libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ceb4791289534d4c1ad8e4bd3c6f06d3670efa55ce71482951a287df93ddd1" +"checksum libp2p-core-derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "851a59dcaab66c96777ae0cace96de88a700243c3b8360ab51c7e093f3727066" +"checksum libp2p-deflate 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "902b44e92e1f8b7e697b3a186d15c841e0e38037f14286513207a5407650a635" +"checksum libp2p-dns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71a6630a84552b39e5f752e1f6a951d31f3211079465d2e7af73491b6f48fc3f" +"checksum libp2p-floodsub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9fced4da0c31e0dc8a759472c65fab41db40c01de2d93bc45e1431c13f0564f0" +"checksum libp2p-identify 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba5e882d72c71cdf77f45ab68dd715451d3b78a23085f8d385c7a31ec1b4272" +"checksum libp2p-kad 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d71966dbbb4cedcfcdb1d4c87d5dbb6f3f07b465d1ca74f2624256669997d1f2" +"checksum libp2p-mdns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdbdaea6f0049cc09ba5db00308f5b93105a8a33b65ba2e36bd35da707850ea2" +"checksum libp2p-mplex 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b351bfd67e97154e7b60f62402237671486c8a89f83eabdb6838f37d4d5f006" +"checksum libp2p-noise 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44324032b2f9260d2b862c741d79d250dc02298dbba56354a992528a826ee2d5" +"checksum libp2p-ping 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1ac43ffd01de4210cf1b969bbb55a008c77f9ec22b74df26a6590bb6bd4c93f" +"checksum libp2p-plaintext 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0506e10770bcbcb59f2a6154ce93c8fd5cb9730b6ceb5aa1463164af1fd0b9c6" +"checksum libp2p-ratelimit 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3886b79a35c0348497bab763517a9a2b4965173f4b4c7438d59f1e4dcf5122ff" +"checksum libp2p-secio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b811272e5cd86d39bd71fb94687025d9802b13daf0998ebe0d3f2885c636c51a" +"checksum libp2p-tcp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b2c54cb75f17557de6ce0149aa03e729455e2d240f84d854272bc4b11012a324" +"checksum libp2p-uds 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbedf4a1e72a5f67523915414e9e12d71d128731873f0f24d8b878398fb47aa4" +"checksum libp2p-wasm-ext 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c1f615b56aa2a6f4ec07bf9667be9fff8877b9c5bd5335601af47490eda341" +"checksum libp2p-websocket 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d1bfe60577558f48a9fdf9f35c0ee2dc5baa01f685ff847d3b5cf4f12ee135" +"checksum libp2p-yamux 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf4bfc7ff127cd622502dbe56f10513dd6776b970e33d8ebb6e367f0752324f6" +"checksum librocksdb-sys 5.18.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d19778314deaa7048f2ea7d07b8aa12e1c227acebe975a37eeab6d2f8c74e41b" "checksum libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "688e8d65e495567c2c35ea0001b26b9debf0b4ea11f8cccc954233b75fc3428a" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" "checksum linked_hash_set 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7c91c4c7bbeb4f2f7c4e5be11e6a05bd6830bc37249c47ce1ad86ad453ff9c" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +"checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" "checksum log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "e19e8d5c34a3e0e2223db8e060f9e8264aeeb5c5fc64a4ee9965c062211c024b" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c" @@ -5739,63 +5887,66 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7623b01a4f1b7acb7cf8e3f678f05e15e6ae26cb0b738dfeb5cc186fd6b82ef4" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" -"checksum merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "83c2dda19c01176e8e7148f7bdb88bbdf215a8db0641f89fc40e4b81736aeda5" +"checksum merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c39467de91b004f5b9c06fac5bbc8e7d28309a205ee66905166b70804a71fea" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" -"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432" +"checksum miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9e3ae51cea1576ceba0dde3d484d30e6e5b86dee0b2d412fe3a16a15c98202" +"checksum miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c468f2369f07d651a5d0bb2c9079f8488a66d5466efe42d0c5c6466edcb7f71e" +"checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab" +"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" "checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum multistream-select 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f989d40aab0ed0d83c1cdb4856b5790e980b96548d1a921f280e985eb049f38d" "checksum names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef320dab323286b50fb5cdda23f61c796a72a89998ab565ca32525c5c556f2da" -"checksum native-tls 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ff8e08de0070bbf4c31f452ea2a70db092f36f6f2e4d897adf5674477d488fb2" +"checksum native-tls 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4b2df1a4c22fd44a62147fd8f13dd0f95c9d8ca7b2610299b2a2f9cf8964274e" "checksum net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)" = "42550d9fb7b6684a6d404d9fa7250c2eb2646df731d1c06afc06dcee9e1bcf88" -"checksum nix 0.13.0 (registry+https://github.com/rust-lang/crates.io-index)" = "46f0f3210768d796e8fa79ec70ee6af172dacbe7147f5e69be5240a47778302b" +"checksum nix 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6c722bee1037d430d0f8e687bbdbf222f27cc6e4e68d5caf630857bb2b6dbdce" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d138afcce92d219ccb6eb53d9b1e8a96ac0d633cfd3c53cd9856d96d1741bb8" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" -"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" -"checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" +"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" +"checksum num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "bcef43580c035376c0705c42792c294b66974abbfd2789b511784023f71f3273" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" "checksum ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2c49021782e5233cd243168edfa8037574afed4eba4bbaf538b3d8d1789d8c" "checksum once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" -"checksum openssl 0.10.20 (registry+https://github.com/rust-lang/crates.io-index)" = "5a0d6b781aac4ac1bd6cafe2a2f0ad8c16ae8e1dd5184822a16c50139f8838d9" +"checksum openssl 0.10.23 (registry+https://github.com/rust-lang/crates.io-index)" = "97c140cbb82f3b3468193dd14c1b88def39f341f68257f8a7fe8ed9ed3f628a5" "checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" -"checksum openssl-sys 0.9.43 (registry+https://github.com/rust-lang/crates.io-index)" = "33c86834957dd5b915623e94f2f4ab2c70dd8f6b70679824155d5ae21dbd495d" +"checksum openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)" = "75bdd6dbbb4958d38e47a1d2348847ad1eb4dc205dc5d37473ae504391865acc" "checksum output_vt100 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb43c05fb71c03b4ea7327bf15694da1e0f23f19d5b1e95bab6c6d74097e336" "checksum parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00a486fd383382ddcb2de928364b1f82571c1e48274fc43b7667a4738ee4056c" -"checksum parity-crypto 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cf1b9c063d87e1507cb3807493c8d21859ef23b5414b39f81c53f0ba267d64c1" -"checksum parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18a130a727008cfcd1068a28439fe939897ccad28664422aeca65b384d6de6d0" -"checksum parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05d6a68e07ab34a9e87bd8dd4936f6bb5be21e4f6dbcdbaf04d8e854eba0af01" +"checksum parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "045b3c7af871285146300da35b1932bb6e4639b66c7c98e85d06a32cbc4e8fa7" +"checksum parity-multihash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "eb83358a0c05e52c44d658981fec2d146d3516d1adffd9e553684f8c8e9e8fa5" +"checksum parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" "checksum parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)" = "511379a8194230c2395d2f5fa627a5a7e108a9f976656ce723ae68fca4097bfc" -"checksum parity-ws 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2fec5048fba72a2e01baeb0d08089db79aead4b57e2443df172fb1840075a233" "checksum parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4d05f1349491390b1730afba60bb20d55761bef489a954546b58b4b34e1e2ac" "checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +"checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" +"checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" "checksum paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4a4a1c555c6505821f9d58b8779d0f630a6b7e4e1be24ba718610acf01fa79" "checksum paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "26e796e623b8b257215f27e6c80a5478856cae305f5b59810ff9acdaa34570e6" -"checksum pbkdf2 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0c09cddfbfc98de7f76931acf44460972edb4023eb14d0c6d4018800e552d8e0" "checksum pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" "checksum peeking_take_while 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "19b17cddbe7ec3f8bc800887bab5e717348c95ea2ca0b1bf0837fb964dc67099" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3a029430f0d744bc3d15dd474d591bed2402b645d024583082b9f63bb936dac6" "checksum pretty_assertions 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3f81e1644e1b54f5a68959a29aa86cde704219254669da328ecfdf6a1f09d427" -"checksum primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edb92f1ebfc177432c03287b15d48c202e6e2c95993a7af3ba039abb43b1492e" -"checksum proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c6cf4e5b00300d151dfffae39f529dfa5188f42eeb14201229aa420d6aad10c" +"checksum primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6e8612a8dc70f26276fed6131c153ca277cf275ee0a5e2a50cd8a69c697beb8f" +"checksum proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" "checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" -"checksum proc-macro-hack 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6a9bed9ebc40cf53e3a76d7486c54d05002eae6485b2711ab9104476fb2eb8bc" +"checksum proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0c1dd4172a1e1f96f709341418f49b11ea6c2d95d53dca08c0f74cbd332d9cf3" "checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" -"checksum proc-macro2 0.4.28 (registry+https://github.com/rust-lang/crates.io-index)" = "ba92c84f814b3f9a44c5cfca7d2ad77fa10710867d2bbb1b3d175ab5f47daa12" -"checksum protobuf 2.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc7badf647ae2fa27ba51c218e347386c88cc604fcfe71f2aba0ad017f3f2b75" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum protobuf 2.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e9076cae823584ab4d8fab3a111658d1232faf106611dc8378161b7d062b628" "checksum pwasm-utils 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "efb0dcbddbb600f47a7098d33762a00552c671992171637f5bb310b37fe1f0e4" "checksum quick-error 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5fb6ccf8db7bbcb9c2eae558db5ab4f3da1c2a87e4e597ed394726bc8ea6ca1d" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" @@ -5809,7 +5960,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -"checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" +"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" @@ -5820,86 +5971,81 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum ref_thread_local 0.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d813022b2e00774a48eaf43caaa3c20b45f040ba8cbf398e2e8911a06668dbe6" -"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" -"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" +"checksum regex 1.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0b2f0808e7d7e4fb1cb07feb6ff2f4bc827938f24f8c2e6a3beb7370af544bdd" +"checksum regex-syntax 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d76410686f9e3a17f06128962e0ecc5755870bb890c34820c7af7f1db2e1d48" "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum rhododendron 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9381ed76c1ec4e8994f1f7d2c6d7e33eed3ff7176e16fece09c2e993fc4a5a" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" -"checksum ripemd160 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad5112e0dbbb87577bfbc56c42450235e3012ce336e29c5befd7807bd626da4a" "checksum rocksdb 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f1651697fefd273bfb4fd69466cc2a9d20de557a0213b97233b22b5e95924b5e" "checksum rpassword 3.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c34fa7bcae7fca3c8471e8417088bbc3ad9af8066b0ecf4f3c0d98a0d772716e" -"checksum rustc-demangle 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "ccc78bfd5acd7bf3e89cffcf899e5cb1a52d6fafa8dec2739ad70c9577a57288" +"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d548a40fe17c3a77d54b82457b79fcc9b8a288d509ca20fbf5aa1dac386d22d6" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" +"checksum rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" +"checksum rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9cbe61c20455d3015b2bb7be39e1872310283b8e5a52f5b242b0ac7581fe78" +"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" "checksum safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f7bf422d23a88c16d5090d455f182bc99c60af4df6a345c63428acf5129e347" "checksum safemem 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8dca453248a96cb0749e36ccdfe2b0b4e54a61bfef89fb97ec621eb8e0a93dd9" "checksum same-file 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8f20c4be53a8a1ff4c1f1b2bd14570d2f634628709752f0702ecdd2b3f9a5267" "checksum schannel 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "f2f6abf258d99c3c1c5c2131d99d064e94b7b3dd5f416483057f308fea253339" "checksum schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5eff518f9bed3d803a0d002af0ab96339b0ebbedde3bec98a684986134b7a39" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum scrypt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8570c5e2fa69cb29d492fd4e9974b6b5facb5a888e1c6da630d4a3cd7ebfef4a" -"checksum secp256k1 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfaccd3a23619349e0878d9a241f34b1982343cdf67367058cd7d078d326b63e" -"checksum security-framework 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bfab8dda0e7a327c696d893df9ffa19cadc4bd195797997f5223cf5831beaf05" -"checksum security-framework-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3d6696852716b589dff9e886ff83778bb635150168e83afa8ac6b8a78cb82abc" +"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" +"checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" +"checksum security-framework 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "eee63d0f4a9ec776eeb30e220f0bc1e092c3ad744b2a379e3993070364d3adc2" +"checksum security-framework-sys 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9636f8989cbf61385ae4824b98c1aaa54c994d7d8b41f11c601ed799f0549a56" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0eddf2e8f50ced781f288c19f18621fa72a3779e3cb58dbf23b07469b0abeb4" -"checksum serde 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "aa5f7c20820475babd2c077c3ab5f8c77a31c15e16ea38687b4c02d3e48680f4" -"checksum serde_derive 1.0.90 (registry+https://github.com/rust-lang/crates.io-index)" = "58fc82bec244f168b23d1963b45c8bf5726e9a15a9d146a067f9081aeed2de79" +"checksum serde 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)" = "32746bf0f26eab52f06af0d0aa1984f641341d06d8d673c693871da2d188c9be" +"checksum serde_derive 1.0.92 (registry+https://github.com/rust-lang/crates.io-index)" = "46a3223d0c9ba936b61c0d2e3e559e3217dbfb8d65d06d26e8b3c25de38bae3e" "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" "checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" "checksum sha2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d963c78ce367df26d7ea8b8cc655c651b42e8a1e584e869c1e17dae3ccb116a" -"checksum sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eb6be24e4c23a84d7184280d2722f7f2731fcdd4a9d886efbfe4413e4847ea0" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" -"checksum sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34a5e54083ce2b934bf059fdf38e7330a154177e029ab6c4e18638f2f624053a" +"checksum sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" "checksum shell32-sys 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9ee04b46101f57121c9da2b151988283b6beb79b34f5bb29a58ee48cb695122c" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e1a2eec401952cd7b12a84ea120e2d57281329940c3f93c2bf04f462539508e" -"checksum slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e544d16c6b230d84c866662fe55e31aacfca6ae71e6fc49ae9a311cb379bfc2f" "checksum slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc0d2aff1f8f325ef660d9a0eb6e6dcd20b30b3f581a5897f58bf42d061c37a" "checksum slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "60c04b4726fa04595ccf2c2dad7bcd15474242c4c5e109a8a376e8a2c9b1539a" "checksum slog_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9eff3b513cf2e0d1a60e1aba152dc72bedc5b05585722bb3cebd7bcb1e31b98f" -"checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" +"checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" "checksum snow 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5a64f02fd208ef15bd2d1a65861df4707e416151e1272d02c8faafad1c138100" +"checksum soketto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8cf3ae22c0bce5437c7dce6a2b00e492c19da1feb21ad64a7b6fd7058438c3f2" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "92a7e0c5e3dfb52e8fbe0e63a1b947bbb17b4036408b151353c4491374931362" -"checksum stdweb 0.4.16 (registry+https://github.com/rust-lang/crates.io-index)" = "b2c1d5ac2f828b2877a6be60a51b8e3ebb57b56862b10be1a72676ca8900b69d" -"checksum stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e21ebd9179de08f2300a65454268a17ea3de204627458588c84319c4def3930" -"checksum stdweb-internal-macros 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "e68f7d08b76979a43e93fe043b66d2626e35d41d68b0b85519202c6dd8ac59fa" -"checksum stdweb-internal-runtime 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d52317523542cc0af5b7e31017ad0f7d1e78da50455e38d5657cd17754f617da" "checksum stream-cipher 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8861bc80f649f5b4c9bd38b696ae9af74499d479dbfb327f0607de6b326a36bc" -"checksum string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "b639411d0b9c738748b5397d5ceba08e648f4f1992231aa859af1a017f31f60b" +"checksum string 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0bbfb8937e38e34c3444ff00afb28b0811d9554f15c5ad64d12b0308d1d1995" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" -"checksum structopt 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "3d0760c312538987d363c36c42339b55f5ee176ea8808bbe4543d484a291c8d1" -"checksum structopt-derive 0.2.15 (registry+https://github.com/rust-lang/crates.io-index)" = "528aeb7351d042e6ffbc2a6fb76a86f9b622fdf7c25932798e7a82cb03bc94c6" +"checksum structopt 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fa19a5a708e22bb5be31c1b6108a2a902f909c4b9ba85cba44c06632386bc0ff" +"checksum structopt-derive 0.2.16 (registry+https://github.com/rust-lang/crates.io-index)" = "c6d59d0ae8ef8de16e49e3ca7afa16024a3e0dfd974a75ef93fdc5464e34523f" "checksum strum 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1810e25f576e7ffce1ff5243b37066da5ded0310b3274c20baaeccb1145b2806" "checksum strum_macros 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "572a2f4e53dd4c3483fd79e5cc10ddd773a3acb1169bbfe8762365e107110579" "checksum substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)" = "" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" -"checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" -"checksum syn 0.15.32 (registry+https://github.com/rust-lang/crates.io-index)" = "846620ec526c1599c070eff393bfeeeb88a93afa2513fc3b49f1fea84cf7b0ed" -"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" -"checksum sysinfo 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b5a0cb7899e248ed0baa6ef6f8406352523c2f99bc7c4b1800f4cd6d5dde99eb" -"checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" +"checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829" +"checksum syn 0.15.35 (registry+https://github.com/rust-lang/crates.io-index)" = "641e117d55514d6d918490e47102f7e08d096fdde360247e4a10f7a91a8478d3" +"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" +"checksum sysinfo 0.8.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1cf62641ed7e88e20242b948d17b9fcc37e80b5599cf09cde190d6d4bb4bf289" "checksum target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c63f48baada5c52e65a29eef93ab4f8982681b67f9e8d29c7b05abcfec2b9ffe" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" -"checksum tempfile 3.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "b86c784c88d98c801132806dadd3819ed29d8600836c4088e855cdf3e178ed8a" -"checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" +"checksum tempfile 3.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7dc4738f2e68ed2855de5ac9cdbe05c9216773ecde4739b2f095002ab03a13ef" +"checksum termcolor 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "96d6098003bde162e4277c70665bd87c326f5a0c3f3fbfb285787fa482d54e6e" "checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" -"checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" -"checksum tinytemplate 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7655088894274afb52b807bd3c87072daa1fedd155068b8705cabfd628956115" +"checksum tiny-keccak 1.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "dbbdebb0b801c7fa4260b6b9ac5a15980276d7d7bcc2dc2959a7c4dc8b426a1a" +"checksum tinytemplate 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4574b75faccaacddb9b284faecdf0b544b80b6b294f3d062d325c5726a209c20" "checksum tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5462b0f968c0457efe38fcd2df7e487096b992419e4f5337b06775a614bbda4b" -"checksum tokio 0.1.19 (registry+https://github.com/rust-lang/crates.io-index)" = "cec6c34409089be085de9403ba2010b80e36938c9ca992c4f67f407bb13db0b1" +"checksum tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)" = "ec2ffcf4bcfc641413fa0f1427bf8f91dfc78f56a6559cbf50e04837ae442a87" +"checksum tokio-buf 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8fb220f46c53859a4b7ec083e41dec9778ff0b1851c0942b211edb89e0ccdc46" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" "checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" "checksum tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "82c65483db54eb91b4ef3a9389a3364558590faf30ce473141707c0e16fda975" @@ -5907,40 +6053,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce" -"checksum tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5b2f843ffdf8d6e1f90bddd48da43f99ab071660cd92b7ec560ef3cdfd7a409a" +"checksum tokio-rustls 0.10.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)" = "316fdbc899efec48b3b492bd0f339e6d81c4ee96a409257572147ec341943452" +"checksum tokio-sync 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2162248ff317e2bc713b261f242b69dbb838b85248ed20bb21df56d60ea4cae7" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" "checksum tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72558af20be886ea124595ea0f806dd5703b8958e4705429dd58b3d8231f72f2" -"checksum tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2910970404ba6fa78c5539126a9ae2045d62e3713041e447f695f41405a120c6" +"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" "checksum tokio-tls 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "354b8cd83825b3c20217a9dc174d6a0c67441a2fae5c41bcb1ea6679f6ae0f7c" -"checksum tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "350c9edade9830dc185ae48ba45667a445ab59f6167ef6d0254ec9d2430d9dd3" +"checksum tokio-trace-core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a9c8a256d6956f7cb5e2bdfe8b1e8022f1a09206c6c2b1ba00f3b746b260c613" "checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" -"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" -"checksum toml 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "87c5890a989fa47ecdc7bcb4c63a77a82c18f306714104b1decfd722db17b39e" +"checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum trie-bench 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba20f7d9865497ea46511860b43e05a44f4ac9a76ee089d34cd80a839a690264" "checksum trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba73747fd3a64ab531274c04cb588dfa9d30d972d62990831e63fbce2cfec59" "checksum trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfa2e20c4f1418ac2e71ddc418e35e1b56e34022e2146209ffdbf1b2de8b1bd9" -"checksum trie-standardmap 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e4e24277af05f38f3aaf03ac78e3a154be83f13db9c8ef0cb95bb1aa764a477b" +"checksum trie-standardmap 0.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ebaa4b340046196efad8872b2dffe585b5ea330230dc44ee14e399f77da29f51" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" -"checksum trybuild 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0b0df728de48978b759da185ed7ef76676ef0c878ae4800c9e90024c998dc75b" +"checksum trybuild 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d1506db833ec4a139b8e3d2e88125d8999270cc944046ca1fb138f6bbfbc2e43" "checksum twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d261e83e727c8e2dbb75dacac67c36e35db36a958ee504f2164fc052434e1" -"checksum twox-hash 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09871da9f15424236082e0b220fd404a4eb6bebc7205c67653701229234ac64c" +"checksum twox-hash 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6c7bcecad121018bdcd6b709fa2325b004878fcb3d3067934ce90749f0faff9a" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" -"checksum uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7780bb27fd8a22295e0d9d53ae3be253f715a0dccb1808527f478f1c2603708" +"checksum uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2143cded94692b156c356508d92888acc824db5bffc0b4089732264c6fcf86d4" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" -"checksum unicase 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "41d17211f887da8e4a70a45b9536f26fc5de166b81e2d5d80de4a17fd22553bd" +"checksum unicase 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a84e5511b2a947f3ae965dcb29b13b7b1691b6e7332cf5dbc1744138d5acb7f6" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" -"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" +"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2c64cdf40b4a9645534a943668681bcb219faf51874d4b65d2e0abda1b10a2ab" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" -"checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" +"checksum utf8-ranges 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "9d50aa7650df78abf942826607c62468ce18d9019673d4a2ebe1865dbb96ffde" "checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6aba5e34f93dc7051dfad05b98a18e9156f27e7b431fe1d2398cb6061c0a1dba" @@ -5948,20 +6094,23 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" "checksum wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "74e463a508e390cc7447e70f640fbf44ad52e1bd095314ace1fdf99516d32add" "checksum wabt-sys 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a6265b25719e82598d104b3717375e37661d41753e2c84cde3f51050c7ed7e3c" -"checksum walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9d9d7ed3431229a144296213105a390676cc49c9b6a72bd19f3176c98e129fa1" +"checksum walkdir 2.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "c7904a7e2bb3cdf0cf5e783f44204a85a37a93151738fa349f06680f59a98b45" "checksum want 0.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "797464475f30ddb8830cc529aaaae648d581f99e2036a928877dfde027ddf6b3" -"checksum wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "ffde3534e5fa6fd936e3260cd62cd644b8656320e369388f9303c955895e35d4" -"checksum wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "40c0543374a7ae881cdc5d32d19de28d1d1929e92263ffa7e31712cc2d53f9f1" -"checksum wasm-bindgen-futures 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "0ad171fc1f6e43f97d155d27f4ee5657bd8aa5cce7c497ef3a0a0c5b44618b2d" -"checksum wasm-bindgen-macro 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "f914c94c2c5f4c9364510ca2429e59c92157ec89429243bcc245e983db990a71" -"checksum wasm-bindgen-macro-support 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "9168c413491e4233db7b6884f09a43beb00c14d11d947ffd165242daa48a2385" -"checksum wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "326c32126e1a157b6ced7400061a84ac5b11182b2cda6edad7314eb3ae9ac9fe" -"checksum wasm-bindgen-webidl 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "613dbf4d7d3bf10aeb212b35de14a8ef07222c26526d4f931061a83fc9e2a851" +"checksum wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "b7ccc7b93cfd13e26700a9e2e41e6305f1951b87e166599069f77d10358100e6" +"checksum wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "1953f91b1608eb1522513623c7739f047bb0fed4128ce51a93f08e12cc314645" +"checksum wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fa1af11c73eca3dc8c51c76ea475a4416e912da6402064a49fc6c0214701866d" +"checksum wasm-bindgen-macro 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "0f69da5696545d7ca6607a2e4b1a0edf5a6b36b2c49dbb0f1df6ad1d92884047" +"checksum wasm-bindgen-macro-support 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d4246f3bc73223bbb846f4f2430a60725826a96c9389adf715ed1d5af46dec6" +"checksum wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "c08381e07e7a79e5e229ad7c60d15833d19033542cc5dd91d085df59d235f4a6" +"checksum wasm-bindgen-webidl 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "1f42ff7adb8102bf5ad8adbc45b1635c520c8175f9fdf6eb2c54479d485d435a" +"checksum wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad9ac33c834103916e373d648adf65f58c83fb3d8a0f3e6b9a64bca7253a4dca" "checksum wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aebbaef470840d157a5c47c8c49f024da7b1b80e90ff729ca982b2b80447e78b" "checksum wasmi-validation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab380192444b3e8522ae79c0a1976e42a82920916ccdfbce3def89f456ea33f3" -"checksum web-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "24129e4be2281109b3e15a328d3d7f233ee232a5405f75ba1e9bb59a25ebc4d4" -"checksum websocket 0.22.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7cc2d74d89f9df981ab41ae624e33cf302fdf456b93455c6a31911a99c9f0bb8" -"checksum weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26a4c67f132386d965390b8a734d5d10adbcd30eb5cc74bd9229af8b83f10044" +"checksum web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "540b8259eb242ff3a566fa0140bda03a4ece4e5c226e1284b5c95dddcd4341f6" +"checksum webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4f7e1cd7900a3a6b65a3e8780c51a3e6b59c0e2c55c6dc69578c288d69f7d082" +"checksum webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c10fa4212003ba19a564f25cd8ab572c6791f99a03cc219c13ed35ccab00de0e" +"checksum websocket 0.22.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0adcd2a64c5746c9702b354a1b992802b0c363df1dfa324a74cb7aebe10e0cbf" +"checksum weedle 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc44aa200daee8b1f3a004beaf16554369746f1b4486f0cf93b0caf8a3c2d1e" "checksum which 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b57acb10231b9493c8472b20cb57317d0679a49e0bdbee44b3b803a6473af164" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" "checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" @@ -5970,10 +6119,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" -"checksum ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "329d3e6dd450a9c5c73024e1047f0be7e24121a68484eb0b5368977bee3cf8c3" +"checksum ws 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ec91ea61b83ce033c43c06c52ddc7532f465c0153281610d44c58b74083aee1a" "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.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9073f5dbc901abb0b2ec4f866e726fed2f54953bdf81f8a5fde7762b7cc3b3" +"checksum yamux 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "01bd67889938c48f0049fc60a77341039e6c3eaf16cb7693e6ead7c0ba701295" "checksum zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ddfeb6eee2fb3b262ef6e0898a52b7563bb8e0d5955a313b3cf2f808246ea14" +"checksum zeroize 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e68403b858b6af538b11614e62dfe9ab2facba9f13a0cafb974855cfb495ec95" +"checksum zeroize 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b60a6c572b91d8ecb0a460950d84fe5b40699edd07d65f73789b31237afc8f66" +"checksum zeroize_derive 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3f07490820219949839d0027b965ffdd659d75be9220c00798762e36c6cd281" +"checksum zeroize_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9dac4b660d969bff9c3fe1847a891cacaa8b21dd5f2aae6e0a3e0975aea96431" diff --git a/Cargo.toml b/Cargo.toml index f109d235af15d9ca1151a31c84fec3771dbcd1d7..0f681dc766d3fc3f5730f88847c3753db06f8115 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,6 @@ build = "build.rs" edition = "2018" [dependencies] -error-chain = "0.12" cli = { package = "node-cli", path = "node/cli" } futures = "0.1" ctrlc = { version = "3.0", features = ["termination"] } @@ -23,15 +22,17 @@ members = [ "core/cli", "core/client", "core/client/db", - "core/consensus/common", "core/consensus/aura", "core/consensus/babe", + "core/consensus/common", "core/consensus/rhd", "core/consensus/slots", "core/executor", "core/finality-grandpa", "core/finality-grandpa/primitives", + "core/inherents", "core/keyring", + "core/keystore", "core/network", "core/panic-handler", "core/primitives", @@ -47,13 +48,13 @@ members = [ "core/sr-std", "core/sr-version", "core/state-machine", - "core/test-runtime", "core/telemetry", - "core/trie", - "core/keystore", + "core/test-client", + "core/test-runtime", + "core/test-runtime/client", "core/transaction-pool", "core/transaction-pool/graph", - "core/inherents", + "core/trie", "core/util/fork-tree", "srml/support", "srml/support/procedural", @@ -83,6 +84,7 @@ members = [ "node/executor", "node/primitives", "node/runtime", + "node/rpc-client", "node-template", "subkey", "test-utils/chain-spec-builder", diff --git a/Dockerfile b/Dockerfile index df39db5abb5d17991d49bba67850dd9e8310817e..c5944dbab6de9231c9fa61af735fcf48d2b5be6b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,8 +20,8 @@ RUN curl https://sh.rustup.rs -sSf | sh -s -- -y && \ rustup target add wasm32-unknown-unknown --toolchain nightly && \ cargo install --git https://github.com/alexcrichton/wasm-gc && \ rustup default nightly && \ - ./scripts/build.sh && \ - rustup default stable && \ + ./scripts/build.sh && \ + rustup default stable && \ cargo build --$PROFILE # ===== SECOND STAGE ====== diff --git a/README.adoc b/README.adoc index f1ffc20d91542be3e4a86dc178fae1d6b2c7cac4..2a76525914b0753c7e6b0ffae9e6c951731bc819 100644 --- a/README.adoc +++ b/README.adoc @@ -307,7 +307,7 @@ cargo run --release \-- \ --telemetry-url ws://telemetry.polkadot.io:1024 \ --validator -Additional Substate CLI usage options are available and may be shown by running `cargo run \-- --help`. +Additional Substrate CLI usage options are available and may be shown by running `cargo run \-- --help`. [[flaming-fir]] === Joining the Flaming Fir Testnet diff --git a/ci/script.sh b/ci/script.sh index 0ab5f34fb2551aa379525325de5b5065dc03dbe3..b1b7dd3edf3564b5455dff53d4708c8e34139d24 100755 --- a/ci/script.sh +++ b/ci/script.sh @@ -20,12 +20,12 @@ case $TARGET in sudo apt-get -y update sudo apt-get install -y cmake pkg-config libssl-dev - cargo test --all --release --locked + cargo test --all --release --locked "$@" ;; "wasm") # Install prerequisites and build all wasm projects ./scripts/init.sh - ./scripts/build.sh + ./scripts/build.sh "$@" ;; esac diff --git a/core/basic-authorship/Cargo.toml b/core/basic-authorship/Cargo.toml index 63408b4329a2f7b60cf7985bbac26d5d3378f437..547fca9030ee651ec0680d1caf01b39035bf4623 100644 --- a/core/basic-authorship/Cargo.toml +++ b/core/basic-authorship/Cargo.toml @@ -17,4 +17,4 @@ transaction_pool = { package = "substrate-transaction-pool", path = "../../core/ substrate-telemetry = { path = "../telemetry" } [dev-dependencies] -test-client = { package = "substrate-test-client", path = "../../core/test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" } diff --git a/core/basic-authorship/src/basic_authorship.rs b/core/basic-authorship/src/basic_authorship.rs index 9f0db708daf184137ae54275065f36aa028a26ef..166a89447e0c424d041d7e45007904bf9886bdad 100644 --- a/core/basic-authorship/src/basic_authorship.rs +++ b/core/basic-authorship/src/basic_authorship.rs @@ -20,7 +20,7 @@ // use std::{self, time, sync::Arc}; -use log::{info, debug, warn, trace}; +use log::{info, debug, trace}; use client::{ self, error, Client as SubstrateClient, CallExecutor, @@ -30,12 +30,13 @@ use codec::Decode; use consensus_common::{self, evaluation}; use primitives::{H256, Blake2Hasher, ExecutionContext}; use runtime_primitives::traits::{ - Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi, AuthorityIdFor + Block as BlockT, Hash as HashT, Header as HeaderT, ProvideRuntimeApi, + AuthorityIdFor, DigestFor, }; use runtime_primitives::generic::BlockId; use runtime_primitives::ApplyError; use transaction_pool::txpool::{self, Pool as TransactionPool}; -use inherents::{InherentData, pool::InherentsPool}; +use inherents::InherentData; use substrate_telemetry::{telemetry, CONSENSUS_INFO}; /// Build new blocks. @@ -53,11 +54,13 @@ pub trait AuthoringApi: Send + Sync + ProvideRuntimeApi where /// The error used by this API type. type Error: std::error::Error; - /// Build a block on top of the given, with inherent extrinsics pre-pushed. - fn build_block) -> ()>( + /// Build a block on top of the given block, with inherent extrinsics and + /// inherent digests pre-pushed. + fn build_block) -> ()>( &self, at: &BlockId, inherent_data: InherentData, + inherent_digests: DigestFor, build_ctx: F, ) -> Result; } @@ -88,13 +91,15 @@ impl AuthoringApi for SubstrateClient where type Block = Block; type Error = client::error::Error; - fn build_block) -> ()>( + fn build_block) -> ()>( &self, at: &BlockId, inherent_data: InherentData, + inherent_digests: DigestFor, mut build_ctx: F, ) -> Result { - let mut block_builder = self.new_block_at(at)?; + + let mut block_builder = self.new_block_at(at, inherent_digests)?; let runtime_api = self.runtime_api(); // We don't check the API versions any further here since the dispatch compatibility @@ -114,8 +119,6 @@ pub struct ProposerFactory where A: txpool::ChainApi { pub client: Arc, /// The transaction pool. pub transaction_pool: Arc>, - /// The inherents pool - pub inherents_pool: Arc::Extrinsic>>, } impl consensus_common::Environment<::Block> for ProposerFactory where @@ -145,7 +148,6 @@ impl consensus_common::Environment<::Block> for Propose parent_id: id, parent_number: *parent_header.number(), transaction_pool: self.transaction_pool.clone(), - inherents_pool: self.inherents_pool.clone(), now: Box::new(time::Instant::now), }; @@ -160,8 +162,7 @@ pub struct Proposer { parent_id: BlockId, parent_number: <::Header as HeaderT>::Number, transaction_pool: Arc>, - inherents_pool: Arc::Extrinsic>>, - now: Box time::Instant>, + now: Box time::Instant>, } impl consensus_common::Proposer<::Block> for Proposer where @@ -174,12 +175,16 @@ impl consensus_common::Proposer<::Block> for Pro type Create = Result<::Block, error::Error>; type Error = error::Error; - fn propose(&self, inherent_data: InherentData, max_duration: time::Duration) - -> Result<::Block, error::Error> + fn propose( + &self, + inherent_data: InherentData, + inherent_digests: DigestFor, + max_duration: time::Duration, + ) -> Result<::Block, error::Error> { // leave some time for evaluation and block finalization (33%) let deadline = (self.now)() + max_duration - max_duration / 3; - self.propose_with(inherent_data, deadline) + self.propose_with(inherent_data, inherent_digests, deadline) } } @@ -190,8 +195,12 @@ impl Proposer where A: txpool::ChainApi, client::error::Error: From<::Error>, { - fn propose_with(&self, inherent_data: InherentData, deadline: time::Instant) - -> Result<::Block, error::Error> + fn propose_with( + &self, + inherent_data: InherentData, + inherent_digests: DigestFor, + deadline: time::Instant, + ) -> Result<::Block, error::Error> { use runtime_primitives::traits::BlakeTwo256; @@ -203,17 +212,8 @@ impl Proposer where let block = self.client.build_block( &self.parent_id, inherent_data, + inherent_digests.clone(), |block_builder| { - // Add inherents from the internal pool - - let inherents = self.inherents_pool.drain(); - debug!("Pushing {} queued inherents.", inherents.len()); - for i in inherents { - if let Err(e) = block_builder.push_extrinsic(i) { - warn!("Error while pushing inherent extrinsic from the pool: {:?}", e); - } - } - // proceed with transactions let mut is_first = true; let mut skipped = 0; @@ -316,7 +316,6 @@ mod tests { let proposer_factory = ProposerFactory { client: client.clone(), transaction_pool: txpool.clone(), - inherents_pool: Default::default(), }; let mut proposer = proposer_factory.init( @@ -331,40 +330,11 @@ mod tests { cell.replace(new) }); let deadline = time::Duration::from_secs(3); - let block = proposer.propose(Default::default(), deadline).unwrap(); + let block = proposer.propose(Default::default(), Default::default(), deadline).unwrap(); // then // block should have some extrinsics although we have some more in the pool. assert_eq!(block.extrinsics().len(), 1); assert_eq!(txpool.ready().count(), 2); } - - #[test] - fn should_include_inherents_from_the_pool() { - // given - let client = Arc::new(test_client::new()); - let chain_api = transaction_pool::ChainApi::new(client.clone()); - let txpool = Arc::new(TransactionPool::new(Default::default(), chain_api)); - let inpool = Arc::new(InherentsPool::default()); - - let proposer_factory = ProposerFactory { - client: client.clone(), - transaction_pool: txpool.clone(), - inherents_pool: inpool.clone(), - }; - - inpool.add(extrinsic(0)); - - let proposer = proposer_factory.init( - &client.header(&BlockId::number(0)).unwrap().unwrap(), - &[] - ).unwrap(); - - // when - let deadline = time::Duration::from_secs(3); - let block = proposer.propose(Default::default(), deadline).unwrap(); - - // then - assert_eq!(block.extrinsics().len(), 1); - } } diff --git a/core/cli/Cargo.toml b/core/cli/Cargo.toml index 2482323c80fe8590ac88bdaaa01263945a7998fd..54cde50d1a0c80bc601680c34dcb20fc26d3f99e 100644 --- a/core/cli/Cargo.toml +++ b/core/cli/Cargo.toml @@ -7,8 +7,8 @@ edition = "2018" [dependencies] clap = "~2.32" +derive_more = "0.14.0" env_logger = "0.6" -error-chain = "0.12" log = "0.4" atty = "0.2" regex = "1" diff --git a/core/cli/src/error.rs b/core/cli/src/error.rs index 07d14eb479873f3b26a41eeb67ff804cb3d15c0f..b052a29710d7fce5f737b3f64b377f7b015d3bbc 100644 --- a/core/cli/src/error.rs +++ b/core/cli/src/error.rs @@ -16,26 +16,38 @@ //! Initialization errors. -// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting` -// https://github.com/paritytech/substrate/issues/1547 -#![allow(deprecated)] - use client; -use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed, - impl_extract_backtrace, impl_error_chain_kind}; - -error_chain! { - foreign_links { - Io(::std::io::Error) #[doc="IO error"]; - Cli(::clap::Error) #[doc="CLI error"]; - Service(::service::Error) #[doc="Substrate service error"]; - Client(client::error::Error) #[doc="Client error"]; - } - errors { - /// Input error. - Input(m: String) { - description("Invalid input"), - display("{}", m), + +/// Result type alias for the CLI. +pub type Result = std::result::Result; + +/// Error type for the CLI. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Io error + Io(std::io::Error), + /// Cli error + Cli(clap::Error), + /// Service error + Service(service::Error), + /// Client error + Client(client::error::Error), + /// Input error + Input(String), + /// Invalid listen multiaddress + #[display(fmt="Invalid listen multiaddress")] + InvalidListenMultiaddress +} + +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Io(ref err) => Some(err), + Error::Cli(ref err) => Some(err), + Error::Service(ref err) => Some(err), + Error::Client(ref err) => Some(err), + Error::Input(_) => None, + Error::InvalidListenMultiaddress => None, } } } diff --git a/core/cli/src/informant.rs b/core/cli/src/informant.rs index 0d100c1963b3d0e25534b778d9ce2266d966f173..607ab9ae8591f430ecf9f3a3bead5c28d8e0dbcd 100644 --- a/core/cli/src/informant.rs +++ b/core/cli/src/informant.rs @@ -29,12 +29,19 @@ use substrate_telemetry::{telemetry, SUBSTRATE_INFO}; use log::{info, warn}; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{Header, As}; +use runtime_primitives::traits::{Header, SaturatedConversion}; /// Spawn informant on the event loop +#[deprecated(note = "Please use informant::build instead, and then create the task manually")] pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExecutor) where C: Components, { + handle.spawn(exit.until(build(service)).map(|_| ())); +} + +/// Creates an informant in the form of a `Future` that must be polled regularly. +pub fn build(service: &Service) -> impl Future +where C: Components { let network = service.network(); let client = service.client(); let txpool = service.transaction_pool(); @@ -46,78 +53,76 @@ pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExe let display_notifications = network.status().for_each(move |sync_status| { - if let Ok(info) = client.info() { - let best_number: u64 = info.chain.best_number.as_(); - let best_hash = info.chain.best_hash; - let num_peers = sync_status.num_peers; - let speed = move || speed(best_number, last_number, last_update); - last_update = time::Instant::now(); - let (status, target) = match (sync_status.sync.state, sync_status.sync.best_seen_block) { - (SyncState::Idle, _) => ("Idle".into(), "".into()), - (SyncState::Downloading, None) => (format!("Syncing{}", speed()), "".into()), - (SyncState::Downloading, Some(n)) => (format!("Syncing{}", speed()), format!(", target=#{}", n)), - }; - last_number = Some(best_number); - let txpool_status = txpool.status(); - let finalized_number: u64 = info.chain.finalized_number.as_(); - let bandwidth_download = network.average_download_per_sec(); - let bandwidth_upload = network.average_upload_per_sec(); - info!( - target: "substrate", - "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", - Colour::White.bold().paint(&status), - target, - Colour::White.bold().paint(format!("{}", sync_status.num_peers)), - Colour::White.paint(format!("{}", best_number)), - best_hash, - Colour::White.paint(format!("{}", finalized_number)), - info.chain.finalized_hash, - TransferRateFormat(bandwidth_download), - TransferRateFormat(bandwidth_upload), - ); - - let backend = (*client).backend(); - let used_state_cache_size = match backend.used_state_cache_size(){ - Some(size) => size, - None => 0, - }; - - // get cpu usage and memory usage of this process - let (cpu_usage, memory) = if sys.refresh_process(self_pid) { - let proc = sys.get_process(self_pid).expect("Above refresh_process succeeds, this should be Some(), qed"); - (proc.cpu_usage(), proc.memory()) - } else { (0.0, 0) }; - - let network_state = network.network_state(); - - telemetry!( - SUBSTRATE_INFO; - "system.interval"; - "network_state" => network_state, - "status" => format!("{}{}", status, target), - "peers" => num_peers, - "height" => best_number, - "best" => ?best_hash, - "txcount" => txpool_status.ready, - "cpu" => cpu_usage, - "memory" => memory, - "finalized_height" => finalized_number, - "finalized_hash" => ?info.chain.finalized_hash, - "bandwidth_download" => bandwidth_download, - "bandwidth_upload" => bandwidth_upload, - "used_state_cache_size" => used_state_cache_size, - ); - } else { - warn!("Error getting best block information"); - } + let info = client.info(); + let best_number = info.chain.best_number.saturated_into::(); + let best_hash = info.chain.best_hash; + let num_peers = sync_status.num_peers; + let speed = move || speed(best_number, last_number, last_update); + last_update = time::Instant::now(); + let (status, target) = match (sync_status.sync.state, sync_status.sync.best_seen_block) { + (SyncState::Idle, _) => ("Idle".into(), "".into()), + (SyncState::Downloading, None) => (format!("Syncing{}", speed()), "".into()), + (SyncState::Downloading, Some(n)) => (format!("Syncing{}", speed()), format!(", target=#{}", n)), + }; + last_number = Some(best_number); + let txpool_status = txpool.status(); + let finalized_number: u64 = info.chain.finalized_number.saturated_into::(); + let bandwidth_download = network.average_download_per_sec(); + let bandwidth_upload = network.average_upload_per_sec(); + info!( + target: "substrate", + "{}{} ({} peers), best: #{} ({}), finalized #{} ({}), ⬇ {} ⬆ {}", + Colour::White.bold().paint(&status), + target, + Colour::White.bold().paint(format!("{}", sync_status.num_peers)), + Colour::White.paint(format!("{}", best_number)), + best_hash, + Colour::White.paint(format!("{}", finalized_number)), + info.chain.finalized_hash, + TransferRateFormat(bandwidth_download), + TransferRateFormat(bandwidth_upload), + ); + + #[allow(deprecated)] + let backend = (*client).backend(); + let used_state_cache_size = match backend.used_state_cache_size(){ + Some(size) => size, + None => 0, + }; + + // get cpu usage and memory usage of this process + let (cpu_usage, memory) = if sys.refresh_process(self_pid) { + let proc = sys.get_process(self_pid).expect("Above refresh_process succeeds, this should be Some(), qed"); + (proc.cpu_usage(), proc.memory()) + } else { (0.0, 0) }; + + let network_state = network.network_state(); + + telemetry!( + SUBSTRATE_INFO; + "system.interval"; + "network_state" => network_state, + "status" => format!("{}{}", status, target), + "peers" => num_peers, + "height" => best_number, + "best" => ?best_hash, + "txcount" => txpool_status.ready, + "cpu" => cpu_usage, + "memory" => memory, + "finalized_height" => finalized_number, + "finalized_hash" => ?info.chain.finalized_hash, + "bandwidth_download" => bandwidth_download, + "bandwidth_upload" => bandwidth_upload, + "used_state_cache_size" => used_state_cache_size, + ); Ok(()) }); let client = service.client(); - let mut last = match client.info() { - Ok(info) => Some((info.chain.best_number, info.chain.best_hash)), - Err(e) => { warn!("Error getting best block information: {:?}", e); None } + let mut last = { + let info = client.info(); + Some((info.chain.best_number, info.chain.best_hash)) }; let display_block_import = client.import_notification_stream().for_each(move |n| { @@ -125,6 +130,7 @@ pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExe if let Some((ref last_num, ref last_hash)) = last { if n.header.parent_hash() != last_hash { let tree_route = ::client::blockchain::tree_route( + #[allow(deprecated)] client.backend().blockchain(), BlockId::Hash(last_hash.clone()), BlockId::Hash(n.hash), @@ -156,8 +162,8 @@ pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExe Ok(()) }); - let informant_work = display_notifications.join3(display_block_import, display_txpool_import); - handle.spawn(exit.until(informant_work).map(|_| ())); + display_notifications.join3(display_block_import, display_txpool_import) + .map(|((), (), ())| ()) } fn speed(best_number: u64, last_number: Option, last_update: time::Instant) -> String { diff --git a/core/cli/src/lib.rs b/core/cli/src/lib.rs index 4bdaaee8e53ddfd78759780a1b45850f03a274bc..c14c9625917e51d9a6b487668b634151d38429c8 100644 --- a/core/cli/src/lib.rs +++ b/core/cli/src/lib.rs @@ -26,7 +26,6 @@ pub mod error; pub mod informant; use client::ExecutionStrategies; -use runtime_primitives::traits::As; use service::{ ServiceFactory, FactoryFullConfiguration, RuntimeGenesis, FactoryGenesis, PruningMode, ChainSpec, @@ -50,13 +49,12 @@ use structopt::{StructOpt, clap::AppSettings}; pub use structopt::clap::App; use params::{ RunCmd, PurgeChainCmd, RevertCmd, ImportBlocksCmd, ExportBlocksCmd, BuildSpecCmd, - NetworkConfigurationParams, SharedParams, MergeParameters, TransactionPoolParams, - NodeKeyParams, NodeKeyType + NetworkConfigurationParams, MergeParameters, TransactionPoolParams, + NodeKeyParams, NodeKeyType, Cors, }; -pub use params::{NoCustom, CoreParams}; +pub use params::{NoCustom, CoreParams, SharedParams}; pub use traits::{GetLogFilter, AugmentClap}; use app_dirs::{AppInfo, AppDataType}; -use error_chain::bail; use log::info; use lazy_static::lazy_static; @@ -146,10 +144,6 @@ fn base_path(cli: &SharedParams, version: &VersionInfo) -> PathBuf { ) } -fn input_err>(msg: T) -> error::Error { - error::ErrorKind::Input(msg.into()).into() -} - /// Check whether a node name is considered as valid fn is_node_name_valid(_name: &str) -> Result<(), &str> { let name = _name.to_string(); @@ -184,7 +178,7 @@ fn is_node_name_valid(_name: &str) -> Result<(), &str> { /// /// `CC` is a custom subcommand. This needs to be an `enum`! If no custom subcommand is required, /// `NoCustom` can be used as type here. -/// `RP` is are custom parameters for the run command. This needs to be a `struct`! The custom +/// `RP` are custom parameters for the run command. This needs to be a `struct`! The custom /// parameters are visible to the user as if they were normal run command parameters. If no custom /// parameters are required, `NoCustom` can be used as type here. pub fn parse_and_execute<'a, F, CC, RP, S, RS, E, I, T>( @@ -279,7 +273,7 @@ where /// Create an error caused by an invalid node key argument. fn invalid_node_key(e: impl std::fmt::Display) -> error::Error { - input_err(format!("Invalid node key: {}", e)) + error::Error::Input(format!("Invalid node key: {}", e)) } /// Parse a Secp256k1 secret key from a hex string into a `network::Secret`. @@ -335,7 +329,7 @@ fn fill_network_configuration( } for addr in cli.listen_addr.iter() { - let addr = addr.parse().map_err(|_| "Invalid listen multiaddress")?; + let addr = addr.parse().ok().ok_or(error::Error::InvalidListenMultiaddress)?; config.listen_addresses.push(addr); } @@ -393,14 +387,14 @@ where }; match is_node_name_valid(&config.name) { Ok(_) => (), - Err(msg) => bail!( - input_err( + Err(msg) => Err( + error::Error::Input( format!("Invalid node name '{}'. Reason: {}. If unsure, use none.", config.name, msg ) ) - ) + )? } let base_path = base_path(&cli.shared_params, version); @@ -418,7 +412,7 @@ where Some(ref s) if s == "archive" => PruningMode::ArchiveAll, None => PruningMode::default(), Some(s) => PruningMode::keep_blocks( - s.parse().map_err(|_| input_err("Invalid pruning mode specified"))? + s.parse().map_err(|_| error::Error::Input("Invalid pruning mode specified".to_string()))? ), }; @@ -471,7 +465,7 @@ where config.keys.push(key); } - if cli.shared_params.dev { + if cli.shared_params.dev && cli.keyring.account.is_none() { config.keys.push("//Alice".into()); } @@ -488,11 +482,12 @@ where config.rpc_ws = Some( parse_address(&format!("{}:{}", ws_interface, 9944), cli.ws_port)? ); + config.rpc_ws_max_connections = cli.ws_max_connections; config.rpc_cors = cli.rpc_cors.unwrap_or_else(|| if is_dev { log::warn!("Running in --dev mode, RPC CORS has been disabled."); - None + Cors::All } else { - Some(vec![ + Cors::List(vec![ "http://localhost:*".into(), "http://127.0.0.1:*".into(), "https://localhost:*".into(), @@ -500,7 +495,7 @@ where "https://polkadot.js.org".into(), "https://substrate-ui.parity.io".into(), ]) - }); + }).into(); // Override telemetry if cli.no_telemetry { @@ -587,7 +582,8 @@ where Ok(()) } -fn create_config_with_db_path( +/// Creates a configuration including the database path. +pub fn create_config_with_db_path( spec_factory: S, cli: &SharedParams, version: &VersionInfo, ) -> error::Result> where @@ -621,13 +617,13 @@ where let to = cli.to; let json = cli.json; - let file: Box = match cli.output { + let file: Box = match cli.output { Some(filename) => Box::new(File::create(filename)?), None => Box::new(stdout()), }; service::chain_ops::export_blocks::( - config, exit.into_exit(), file, As::sa(from), to.map(As::sa), json + config, exit.into_exit(), file, from.into(), to.map(Into::into), json ).map_err(Into::into) } @@ -644,7 +640,7 @@ where { let config = create_config_with_db_path::(spec_factory, &cli.shared_params, version)?; - let file: Box = match cli.input { + let file: Box = match cli.input { Some(filename) => Box::new(File::open(filename)?), None => Box::new(stdin()), }; @@ -663,7 +659,7 @@ where { let config = create_config_with_db_path::(spec_factory, &cli.shared_params, version)?; let blocks = cli.num; - Ok(service::chain_ops::revert_chain::(config, As::sa(blocks))?) + Ok(service::chain_ops::revert_chain::(config, blocks.into())?) } fn purge_chain( @@ -836,7 +832,7 @@ mod tests { NodeKeyType::variants().into_iter().try_for_each(|t| { let node_key_type = NodeKeyType::from_str(t).unwrap(); let sk = match node_key_type { - NodeKeyType::Secp256k1 => secp256k1::SecretKey::generate().as_ref().to_vec(), + NodeKeyType::Secp256k1 => secp256k1::SecretKey::generate().to_bytes().to_vec(), NodeKeyType::Ed25519 => ed25519::SecretKey::generate().as_ref().to_vec() }; let params = NodeKeyParams { @@ -847,11 +843,11 @@ mod tests { node_key_config(params, &net_config_dir).and_then(|c| match c { NodeKeyConfig::Secp256k1(network::Secret::Input(ref ski)) if node_key_type == NodeKeyType::Secp256k1 && - &sk[..] == ski.as_ref() => Ok(()), + &sk[..] == ski.to_bytes() => Ok(()), NodeKeyConfig::Ed25519(network::Secret::Input(ref ski)) if node_key_type == NodeKeyType::Ed25519 && &sk[..] == ski.as_ref() => Ok(()), - _ => Err(input_err("Unexpected node key config")) + _ => Err(error::Error::Input("Unexpected node key config".into())) }) }) } @@ -877,7 +873,7 @@ mod tests { if node_key_type == NodeKeyType::Secp256k1 && f == &file => Ok(()), NodeKeyConfig::Ed25519(network::Secret::File(ref f)) if node_key_type == NodeKeyType::Ed25519 && f == &file => Ok(()), - _ => Err(input_err("Unexpected node key config")) + _ => Err(error::Error::Input("Unexpected node key config".into())) }) }) } @@ -911,7 +907,7 @@ mod tests { if typ == NodeKeyType::Secp256k1 => Ok(()), NodeKeyConfig::Ed25519(network::Secret::New) if typ == NodeKeyType::Ed25519 => Ok(()), - _ => Err(input_err("Unexpected node key config")) + _ => Err(error::Error::Input("Unexpected node key config".into())) }) }) } @@ -928,7 +924,7 @@ mod tests { NodeKeyConfig::Ed25519(network::Secret::File(ref f)) if typ == NodeKeyType::Ed25519 && f == &dir.join(NODE_KEY_ED25519_FILE) => Ok(()), - _ => Err(input_err("Unexpected node key config")) + _ => Err(error::Error::Input("Unexpected node key config".into())) }) }) } diff --git a/core/cli/src/params.rs b/core/cli/src/params.rs index 503d8fca327e5fbb25734c0eae8b94d7300e03d7..0cdc633188d7dc3ef8ee80b6bece823e1730b74f 100644 --- a/core/cli/src/params.rs +++ b/core/cli/src/params.rs @@ -333,13 +333,17 @@ pub struct RunCmd { #[structopt(long = "ws-port", value_name = "PORT")] pub ws_port: Option, + /// Maximum number of WS RPC server connections. + #[structopt(long = "ws-max-connections", value_name = "COUNT")] + pub ws_max_connections: Option, + /// Specify browser Origins allowed to access the HTTP & WS RPC servers. /// It's a comma-separated list of origins (protocol://domain or special `null` value). /// Value of `all` will disable origin validation. /// Default is to allow localhost, https://polkadot.js.org and https://substrate-ui.parity.io origins. /// When running in --dev mode the default is to allow all origins. #[structopt(long = "rpc-cors", value_name = "ORIGINS", parse(try_from_str = "parse_cors"))] - pub rpc_cors: Option>>, + pub rpc_cors: Option, /// Specify the pruning mode, a number of blocks to keep or 'archive'. Default is 256. #[structopt(long = "pruning", value_name = "PRUNING_MODE")] @@ -472,7 +476,7 @@ impl Keyring { } /// Default to verbosity level 0, if none is provided. -fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), Box> { +fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), Box> { let pos = s.find(' '); match pos { None => { @@ -486,8 +490,29 @@ fn parse_telemetry_endpoints(s: &str) -> Result<(String, u8), Box>` +/// handling of `structopt`. +#[derive(Clone, Debug)] +pub enum Cors { + /// All hosts allowed + All, + /// Only hosts on the list are allowed. + List(Vec), +} + +impl From for Option> { + fn from(cors: Cors) -> Self { + match cors { + Cors::All => None, + Cors::List(list) => Some(list), + } + } +} + /// Parse cors origins -fn parse_cors(s: &str) -> Result>, Box> { +fn parse_cors(s: &str) -> Result> { let mut is_all = false; let mut origins = Vec::new(); for part in s.split(',') { @@ -500,7 +525,7 @@ fn parse_cors(s: &str) -> Result>, Box> { } } - Ok(if is_all { None } else { Some(origins) }) + Ok(if is_all { Cors::All } else { Cors::List(origins) }) } impl_augment_clap!(RunCmd); @@ -533,11 +558,11 @@ pub struct ExportBlocksCmd { /// Specify starting block number. 1 by default. #[structopt(long = "from", value_name = "BLOCK")] - pub from: Option, + pub from: Option, /// Specify last block number. Best block by default. #[structopt(long = "to", value_name = "BLOCK")] - pub to: Option, + pub to: Option, /// Use JSON output rather than binary. #[structopt(long = "json")] @@ -573,7 +598,7 @@ impl_get_log_filter!(ImportBlocksCmd); pub struct RevertCmd { /// Number of blocks to revert. #[structopt(default_value = "256")] - pub num: u64, + pub num: u32, #[allow(missing_docs)] #[structopt(flatten)] diff --git a/core/cli/src/traits.rs b/core/cli/src/traits.rs index ddb389e454ece4aafacc64e7a40e02a171255e68..0f8d247e49ab144f0f916c54fd1f5998e3701734 100644 --- a/core/cli/src/traits.rs +++ b/core/cli/src/traits.rs @@ -16,7 +16,7 @@ use structopt::{StructOpt, clap::App}; -/// Something that can augment a clapp app with further parameters. +/// Something that can augment a clap app with further parameters. /// `derive(StructOpt)` is implementing this function by default, so a macro `impl_augment_clap!` /// is provided to simplify the implementation of this trait. pub trait AugmentClap: StructOpt { diff --git a/core/client/Cargo.toml b/core/client/Cargo.toml index e295894b83fe420d977a3a7149c233898e5d46af..510ec50b8b5c1bb527460cadfa0059d70b2e6cc7 100644 --- a/core/client/Cargo.toml +++ b/core/client/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" derive_more = { version = "0.14.0", optional = true } fnv = { version = "1.0", optional = true } log = { version = "0.4", optional = true } -parking_lot = { version = "0.7.1", optional = true } +parking_lot = { version = "0.8.0", optional = true } hex = { package = "hex-literal", version = "0.1", optional = true } futures = { version = "0.1.17", optional = true } consensus = { package = "substrate-consensus-common", path = "../consensus/common", optional = true } @@ -28,7 +28,7 @@ inherents = { package = "substrate-inherents", path = "../inherents", default-fe sr-api-macros = { path = "../sr-api-macros" } [dev-dependencies] -test-client = { package = "substrate-test-client", path = "../test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" } kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } [features] diff --git a/core/client/db/Cargo.toml b/core/client/db/Cargo.toml index 3fea4fd8122a23adaea6271bfbd0fa1c71d50119..e40b1568f6014611ecbb422f81b6dd1e2544a592 100644 --- a/core/client/db/Cargo.toml +++ b/core/client/db/Cargo.toml @@ -5,12 +5,12 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -parking_lot = "0.7.1" +parking_lot = "0.8" log = "0.4" kvdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } # FIXME replace with release as soon as our rocksdb changes are released upstream https://github.com/paritytech/parity-common/issues/88 -kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } -kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d", optional = true } +kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d", optional = true } +kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } lru-cache = "0.1.1" hash-db = { version = "0.12" } primitives = { package = "substrate-primitives", path = "../../primitives" } @@ -24,11 +24,10 @@ trie = { package = "substrate-trie", path = "../../trie" } consensus_common = { package = "substrate-consensus-common", path = "../../consensus/common" } [dev-dependencies] -kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" } substrate-keyring = { path = "../../keyring" } -test-client = { package = "substrate-test-client", path = "../../test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" } env_logger = { version = "0.6" } [features] default = [] -test-helpers = ["kvdb-memorydb"] +test-helpers = [] diff --git a/core/client/db/src/cache/list_cache.rs b/core/client/db/src/cache/list_cache.rs index 4d7b4e2e51f8ce3cfbe1dac51e77415ef277860e..4f343e93fdc93f5dbadf066879b4393be623f076 100644 --- a/core/client/db/src/cache/list_cache.rs +++ b/core/client/db/src/cache/list_cache.rs @@ -44,7 +44,9 @@ use std::collections::BTreeSet; use log::warn; use client::error::{Error as ClientError, Result as ClientResult}; -use runtime_primitives::traits::{Block as BlockT, NumberFor, As, Zero}; +use runtime_primitives::traits::{ + Block as BlockT, NumberFor, Zero, Bounded, CheckedSub +}; use crate::cache::{CacheItemT, ComplexBlockId, EntryType}; use crate::cache::list_entry::{Entry, StorageEntry}; @@ -135,7 +137,7 @@ impl> ListCache // BUT since we're not guaranteeing to provide correct values for forks // behind the finalized block, check if the block is finalized first - if !chain::is_finalized_block(&self.storage, at, As::sa(::std::u64::MAX))? { + if !chain::is_finalized_block(&self.storage, at, Bounded::max_value())? { return Ok(None); } @@ -349,9 +351,9 @@ impl> ListCache ) { let mut do_pruning = || -> ClientResult<()> { // calculate last ancient block number - let ancient_block = match block.number.as_().checked_sub(self.prune_depth.as_()) { - Some(number) => match self.storage.read_id(As::sa(number))? { - Some(hash) => ComplexBlockId::new(hash, As::sa(number)), + let ancient_block = match block.number.checked_sub(&self.prune_depth) { + Some(number) => match self.storage.read_id(number)? { + Some(hash) => ComplexBlockId::new(hash, number), None => return Ok(()), }, None => return Ok(()), diff --git a/core/client/db/src/cache/list_storage.rs b/core/client/db/src/cache/list_storage.rs index 6271f892bc859059cdc01b44a5d0acd4f3ca67f3..af0b74066c213dc93064a966342c677367568046 100644 --- a/core/client/db/src/cache/list_storage.rs +++ b/core/client/db/src/cache/list_storage.rs @@ -97,19 +97,19 @@ pub struct DbColumns { pub struct DbStorage { name: Vec, meta_key: Vec, - db: Arc, + db: Arc, columns: DbColumns, } impl DbStorage { /// Create new database-backed list cache storage. - pub fn new(name: Vec, db: Arc, columns: DbColumns) -> Self { + pub fn new(name: Vec, db: Arc, columns: DbColumns) -> Self { let meta_key = meta::key(&name); DbStorage { name, meta_key, db, columns } } /// Get reference to the database. - pub fn db(&self) -> &Arc { &self.db } + pub fn db(&self) -> &Arc { &self.db } /// Get reference to the database columns. pub fn columns(&self) -> &DbColumns { &self.columns } diff --git a/core/client/db/src/cache/mod.rs b/core/client/db/src/cache/mod.rs index e4e23a5ca1d3b8820241f254b0ca01d328211f8e..64d3c4a25e7bf7e2d2a0e594295722b5bd64c307 100644 --- a/core/client/db/src/cache/mod.rs +++ b/core/client/db/src/cache/mod.rs @@ -25,7 +25,7 @@ use client::blockchain::Cache as BlockchainCache; use client::error::Result as ClientResult; use parity_codec::{Encode, Decode}; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, As, Zero}; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor, Zero}; use consensus_common::well_known_cache_keys::Id as CacheKeyId; use crate::utils::{self, COLUMN_META, db_err}; @@ -35,8 +35,8 @@ mod list_cache; mod list_entry; mod list_storage; -/// Minimal post-finalization age age of finalized blocks before they'll pruned. -const PRUNE_DEPTH: u64 = 1024; +/// Minimal post-finalization age of finalized blocks before they'll pruned. +const PRUNE_DEPTH: u32 = 1024; /// The type of entry that is inserted to the cache. #[derive(Clone, Copy, Debug, PartialEq)] @@ -77,7 +77,7 @@ impl CacheItemT for T where T: Clone + Decode + Encode + PartialEq {} /// Database-backed blockchain data cache. pub struct DbCache { cache_at: HashMap, self::list_storage::DbStorage>>, - db: Arc, + db: Arc, key_lookup_column: Option, header_column: Option, authorities_column: Option, @@ -88,7 +88,7 @@ pub struct DbCache { impl DbCache { /// Create new cache. pub fn new( - db: Arc, + db: Arc, key_lookup_column: Option, header_column: Option, authorities_column: Option, @@ -150,7 +150,7 @@ impl DbCache { fn get_cache_helper<'a, Block: BlockT>( cache_at: &'a mut HashMap, self::list_storage::DbStorage>>, name: CacheKeyId, - db: &Arc, + db: &Arc, key_lookup: Option, header: Option, cache: Option, @@ -166,7 +166,7 @@ fn get_cache_helper<'a, Block: BlockT>( cache, }, ), - As::sa(PRUNE_DEPTH), + PRUNE_DEPTH.into(), best_finalized_block.clone(), ) }) diff --git a/core/client/db/src/lib.rs b/core/client/db/src/lib.rs index a7d793527876b48f2e51c4cc0ef95666d5b20aac..674e8022dcf1872121108723090b481d1a460361 100644 --- a/core/client/db/src/lib.rs +++ b/core/client/db/src/lib.rs @@ -46,12 +46,15 @@ use parking_lot::{Mutex, RwLock}; use primitives::{H256, Blake2Hasher, ChangesTrieConfiguration, convert_hash}; use primitives::storage::well_known_keys; use runtime_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay}; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, NumberFor, Zero, Digest, DigestItem}; +use runtime_primitives::traits::{ + Block as BlockT, Header as HeaderT, NumberFor, Zero, One, Digest, DigestItem, + SaturatedConversion +}; use runtime_primitives::BuildStorage; use state_machine::backend::Backend as StateBackend; use executor::RuntimeInfo; use state_machine::{CodeExecutor, DBValue}; -use crate::utils::{Meta, db_err, meta_keys, open_database, read_db, block_id_to_lookup_key, read_meta}; +use crate::utils::{Meta, db_err, meta_keys, read_db, block_id_to_lookup_key, read_meta}; use client::leaves::{LeafSet, FinalizationDisplaced}; use client::children; use state_db::StateDb; @@ -64,10 +67,101 @@ pub use state_db::PruningMode; use client::in_mem::Backend as InMemoryBackend; const CANONICALIZATION_DELAY: u64 = 4096; -const MIN_BLOCKS_TO_KEEP_CHANGES_TRIES_FOR: u64 = 32768; +const MIN_BLOCKS_TO_KEEP_CHANGES_TRIES_FOR: u32 = 32768; /// DB-backed patricia trie state, transaction type is an overlay of changes to commit. -pub type DbState = state_machine::TrieBackend>, Blake2Hasher>; +pub type DbState = state_machine::TrieBackend>, Blake2Hasher>; + +pub struct RefTrackingState { + state: DbState, + storage: Arc>, + parent_hash: Option, +} + +impl RefTrackingState { + fn new(state: DbState, storage: Arc>, parent_hash: Option) -> RefTrackingState { + if let Some(hash) = &parent_hash { + storage.state_db.pin(hash); + } + RefTrackingState { + state, + parent_hash, + storage, + } + } +} + +impl Drop for RefTrackingState { + fn drop(&mut self) { + if let Some(hash) = &self.parent_hash { + self.storage.state_db.unpin(hash); + } + } +} + +impl StateBackend for RefTrackingState { + type Error = >::Error; + type Transaction = >::Transaction; + type TrieBackendStorage = >::TrieBackendStorage; + + fn storage(&self, key: &[u8]) -> Result>, Self::Error> { + self.state.storage(key) + } + + fn storage_hash(&self, key: &[u8]) -> Result, Self::Error> { + self.state.storage_hash(key) + } + + fn child_storage(&self, storage_key: &[u8], key: &[u8]) -> Result>, Self::Error> { + self.state.child_storage(storage_key, key) + } + + fn exists_storage(&self, key: &[u8]) -> Result { + self.state.exists_storage(key) + } + + fn exists_child_storage(&self, storage_key: &[u8], key: &[u8]) -> Result { + self.state.exists_child_storage(storage_key, key) + } + + fn for_keys_with_prefix(&self, prefix: &[u8], f: F) { + self.state.for_keys_with_prefix(prefix, f) + } + + fn for_keys_in_child_storage(&self, storage_key: &[u8], f: F) { + self.state.for_keys_in_child_storage(storage_key, f) + } + + fn storage_root(&self, delta: I) -> (H256, Self::Transaction) + where + I: IntoIterator, Option>)> + { + self.state.storage_root(delta) + } + + fn child_storage_root(&self, storage_key: &[u8], delta: I) -> (Vec, bool, Self::Transaction) + where + I: IntoIterator, Option>)>, + { + self.state.child_storage_root(storage_key, delta) + } + + fn pairs(&self) -> Vec<(Vec, Vec)> { + self.state.pairs() + } + + fn keys(&self, prefix: &[u8]) -> Vec> { + self.state.keys(prefix) + } + + fn child_keys(&self, child_key: &[u8], prefix: &[u8]) -> Vec> { + self.state.child_keys(child_key, prefix) + } + + fn as_trie_backend(&mut self) -> Option<&state_machine::TrieBackend> { + self.state.as_trie_backend() + } +} /// Database settings. pub struct DatabaseSettings { @@ -119,7 +213,7 @@ struct PendingBlock { } // wrapper that implements trait required for state_db -struct StateMetaDb<'a>(&'a KeyValueDB); +struct StateMetaDb<'a>(&'a dyn KeyValueDB); impl<'a> state_db::MetaDb for StateMetaDb<'a> { type Error = io::Error; @@ -131,13 +225,13 @@ impl<'a> state_db::MetaDb for StateMetaDb<'a> { /// Block database pub struct BlockchainDb { - db: Arc, + db: Arc, meta: Arc, Block::Hash>>>, leaves: RwLock>>, } impl BlockchainDb { - fn new(db: Arc) -> Result { + fn new(db: Arc) -> Result { let meta = read_meta::(&*db, columns::META, columns::HEADER)?; let leaves = LeafSet::read_from_db(&*db, columns::META, meta_keys::LEAF_PREFIX)?; Ok(BlockchainDb { @@ -177,15 +271,15 @@ impl client::blockchain::HeaderBackend for BlockchainDb Result, client::error::Error> { + fn info(&self) -> client::blockchain::Info { let meta = self.meta.read(); - Ok(client::blockchain::Info { + client::blockchain::Info { best_hash: meta.best_hash, best_number: meta.best_number, genesis_hash: meta.genesis_hash, finalized_hash: meta.finalized_hash, finalized_number: meta.finalized_number, - }) + } } fn status(&self, id: BlockId) -> Result { @@ -246,7 +340,7 @@ impl client::blockchain::Backend for BlockchainDb { Ok(self.meta.read().finalized_hash.clone()) } - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { None } @@ -260,14 +354,14 @@ impl client::blockchain::Backend for BlockchainDb { } impl client::blockchain::ProvideCache for BlockchainDb { - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { None } } /// Database transaction pub struct BlockImportOperation { - old_state: CachingState, + old_state: CachingState, Block>, db_updates: PrefixedMemoryDB, storage_updates: Vec<(Vec, Option>)>, changes_trie_updates: MemoryDB, @@ -292,7 +386,7 @@ impl client::backend::BlockImportOperation for BlockImportOperation where Block: BlockT, { - type State = CachingState; + type State = CachingState, Block>; fn state(&self) -> Result, client::error::Error> { Ok(Some(&self.old_state)) @@ -379,7 +473,7 @@ where Block: BlockT, } struct StorageDb { - pub db: Arc, + pub db: Arc, pub state_db: StateDb>, } @@ -418,13 +512,13 @@ impl state_machine::Storage for DbGenesisStorage { } pub struct DbChangesTrieStorage { - db: Arc, + db: Arc, meta: Arc, Block::Hash>>>, - min_blocks_to_keep: Option, + min_blocks_to_keep: Option, _phantom: ::std::marker::PhantomData, } -impl DbChangesTrieStorage { +impl> DbChangesTrieStorage { /// Commit new changes trie. pub fn commit(&self, tx: &mut DBTransaction, mut changes_trie: MemoryDB) { for (key, (val, _)) in changes_trie.drain() { @@ -443,53 +537,79 @@ impl DbChangesTrieStorage { state_machine::prune_changes_tries( config, &*self, - min_blocks_to_keep, + min_blocks_to_keep.into(), &state_machine::ChangesTrieAnchorBlockId { hash: convert_hash(&block_hash), - number: block_num.as_(), + number: block_num, }, |node| tx.delete(columns::CHANGES_TRIE, node.as_ref())); } } -impl client::backend::PrunableStateChangesTrieStorage for DbChangesTrieStorage { +impl client::backend::PrunableStateChangesTrieStorage + for DbChangesTrieStorage +where + Block: BlockT, +{ fn oldest_changes_trie_block( &self, config: &ChangesTrieConfiguration, - best_finalized_block: u64 - ) -> u64 { + best_finalized_block: NumberFor, + ) -> NumberFor { match self.min_blocks_to_keep { Some(min_blocks_to_keep) => state_machine::oldest_non_pruned_changes_trie( config, - min_blocks_to_keep, + min_blocks_to_keep.into(), best_finalized_block, ), - None => 1, + None => One::one(), } } } -impl state_machine::ChangesTrieRootsStorage for DbChangesTrieStorage { - fn root(&self, anchor: &state_machine::ChangesTrieAnchorBlockId, block: u64) -> Result, String> { +impl state_machine::ChangesTrieRootsStorage> + for DbChangesTrieStorage +where + Block: BlockT, +{ + fn build_anchor( + &self, + hash: H256, + ) -> Result>, String> { + utils::read_header::(&*self.db, columns::KEY_LOOKUP, columns::HEADER, BlockId::Hash(hash)) + .map_err(|e| e.to_string()) + .and_then(|maybe_header| maybe_header.map(|header| + state_machine::ChangesTrieAnchorBlockId { + hash, + number: *header.number(), + } + ).ok_or_else(|| format!("Unknown header: {}", hash))) + } + + fn root( + &self, + anchor: &state_machine::ChangesTrieAnchorBlockId>, + block: NumberFor, + ) -> Result, String> { // check API requirement: we can't get NEXT block(s) based on anchor if block > anchor.number { return Err(format!("Can't get changes trie root at {} using anchor at {}", block, anchor.number)); } // we need to get hash of the block to resolve changes trie root - let block_id = if block <= self.meta.read().finalized_number.as_() { + let block_id = if block <= self.meta.read().finalized_number { // if block is finalized, we could just read canonical hash - BlockId::Number(As::sa(block)) + BlockId::Number(block) } else { // the block is not finalized let mut current_num = anchor.number; let mut current_hash: Block::Hash = convert_hash(&anchor.hash); let maybe_anchor_header: Block::Header = utils::require_header::( - &*self.db, columns::KEY_LOOKUP, columns::HEADER, BlockId::Number(As::sa(current_num)) + &*self.db, columns::KEY_LOOKUP, columns::HEADER, BlockId::Number(current_num) ).map_err(|e| e.to_string())?; if maybe_anchor_header.hash() == current_hash { // if anchor is canonicalized, then the block is also canonicalized - BlockId::Number(As::sa(block)) + BlockId::Number(block) } else { // else (block is not finalized + anchor is not canonicalized): // => we should find the required block hash by traversing @@ -500,7 +620,7 @@ impl state_machine::ChangesTrieRootsStorage for DbC ).map_err(|e| e.to_string())?; current_hash = *current_header.parent_hash(); - current_num = current_num - 1; + current_num = current_num - One::one(); } BlockId::Hash(current_hash) @@ -514,7 +634,11 @@ impl state_machine::ChangesTrieRootsStorage for DbC } } -impl state_machine::ChangesTrieStorage for DbChangesTrieStorage { +impl state_machine::ChangesTrieStorage> + for DbChangesTrieStorage +where + Block: BlockT, +{ fn get(&self, key: &H256, _prefix: &[u8]) -> Result, String> { self.db.get(columns::CHANGES_TRIE, &key[..]) .map_err(|err| format!("{}", err)) @@ -532,6 +656,7 @@ pub struct Backend { blockchain: BlockchainDb, canonicalization_delay: u64, shared_cache: SharedCache, + import_lock: Mutex<()>, } impl> Backend { @@ -539,8 +664,19 @@ impl> Backend { /// /// The pruning window is how old a block must be before the state is pruned. pub fn new(config: DatabaseSettings, canonicalization_delay: u64) -> Result { - let db = open_database(&config, columns::META, "full")?; + Self::new_inner(config, canonicalization_delay) + } + + #[cfg(feature = "kvdb-rocksdb")] + fn new_inner(config: DatabaseSettings, canonicalization_delay: u64) -> Result { + let db = crate::utils::open_database(&config, columns::META, "full")?; + Backend::from_kvdb(db as Arc<_>, config.pruning, canonicalization_delay, config.state_cache_size) + } + #[cfg(not(feature = "kvdb-rocksdb"))] + fn new_inner(config: DatabaseSettings, canonicalization_delay: u64) -> Result { + log::warn!("Running without the RocksDB feature. The database will NOT be saved."); + let db = Arc::new(kvdb_memorydb::create(crate::utils::NUM_COLUMNS)); Backend::from_kvdb(db as Arc<_>, config.pruning, canonicalization_delay, config.state_cache_size) } @@ -558,7 +694,12 @@ impl> Backend { ).expect("failed to create test-db") } - fn from_kvdb(db: Arc, pruning: PruningMode, canonicalization_delay: u64, state_cache_size: usize) -> Result { + fn from_kvdb( + db: Arc, + pruning: PruningMode, + canonicalization_delay: u64, + state_cache_size: usize + ) -> Result { let is_archive_pruning = pruning.is_archive(); let blockchain = BlockchainDb::new(db.clone())?; let meta = blockchain.meta.clone(); @@ -582,6 +723,7 @@ impl> Backend { blockchain, canonicalization_delay, shared_cache: new_shared_cache(state_cache_size), + import_lock: Default::default(), }) } @@ -607,7 +749,7 @@ impl> Backend { } // insert all other headers + bodies + justifications - let info = self.blockchain.info().unwrap(); + let info = self.blockchain.info(); for (number, hash, header) in headers { let id = BlockId::Hash(hash); let justification = self.blockchain.justification(id).unwrap(); @@ -770,7 +912,7 @@ impl> Backend { ) -> Result<(), client::error::Error> { - let number_u64 = number.as_(); + let number_u64 = number.saturated_into::(); if number_u64 > self.canonicalization_delay { let new_canonical = number_u64 - self.canonicalization_delay; @@ -781,7 +923,7 @@ impl> Backend { let hash = if new_canonical == number_u64 { hash } else { - ::client::blockchain::HeaderBackend::hash(&self.blockchain, As::sa(new_canonical))? + ::client::blockchain::HeaderBackend::hash(&self.blockchain, new_canonical.saturated_into())? .expect("existence of block with number `new_canonical` \ implies existence of blocks with all numbers before it; qed") }; @@ -865,7 +1007,7 @@ impl> Backend { changeset.deleted.push(key); } } - let number_u64 = number.as_(); + let number_u64 = number.saturated_into::(); let commit = self.storage.state_db.insert_block(&hash, number_u64, &pending_block.header.parent_hash(), changeset) .map_err(|e: state_db::Error| client::error::Error::from(format!("State database error: {:?}", e)))?; apply_state_commit(&mut transaction, commit); @@ -878,6 +1020,8 @@ impl> Backend { let changes_trie_updates = operation.changes_trie_updates; self.changes_tries_storage.commit(&mut transaction, changes_trie_updates); + let cache = operation.old_state.release(); // release state reference so that it can be finalized + if finalized { // TODO: ensure best chain contains this block. @@ -909,7 +1053,7 @@ impl> Backend { meta_updates.push((hash, number, pending_block.leaf_state.is_best(), finalized)); - Some((number, hash, enacted, retracted, displaced_leaf, is_best)) + Some((number, hash, enacted, retracted, displaced_leaf, is_best, cache)) } else { None }; @@ -931,7 +1075,7 @@ impl> Backend { let write_result = self.storage.db.write(transaction).map_err(db_err); - if let Some((number, hash, enacted, retracted, displaced_leaf, is_best)) = imported { + if let Some((number, hash, enacted, retracted, displaced_leaf, is_best, mut cache)) = imported { if let Err(e) = write_result { let mut leaves = self.blockchain.leaves.write(); let mut undo = leaves.undo(); @@ -946,7 +1090,7 @@ impl> Backend { return Err(e) } - operation.old_state.sync_cache( + cache.sync_cache( &enacted, &retracted, operation.storage_updates, @@ -978,7 +1122,7 @@ impl> Backend { { let f_num = f_header.number().clone(); - if self.storage.state_db.best_canonical().map(|c| f_num.as_() > c).unwrap_or(true) { + if self.storage.state_db.best_canonical().map(|c| f_num.saturated_into::() > c).unwrap_or(true) { let parent_hash = f_header.parent_hash().clone(); let lookup_key = utils::number_and_hash_to_lookup_key(f_num, f_hash.clone()); @@ -1046,7 +1190,7 @@ impl client::backend::AuxStore for Backend where Block: BlockT client::backend::Backend for Backend where Block: BlockT { type BlockImportOperation = BlockImportOperation; type Blockchain = BlockchainDb; - type State = CachingState; + type State = CachingState, Block>; type ChangesTrieStorage = DbChangesTrieStorage; fn begin_operation(&self) -> Result { @@ -1121,14 +1265,14 @@ impl client::backend::Backend for Backend whe } fn revert(&self, n: NumberFor) -> Result, client::error::Error> { - let mut best = self.blockchain.info()?.best_number; - let finalized = self.blockchain.info()?.finalized_number; + let mut best = self.blockchain.info().best_number; + let finalized = self.blockchain.info().finalized_number; let revertible = best - finalized; let n = if revertible < n { revertible } else { n }; - for c in 0 .. n.as_() { - if best == As::sa(0) { - return Ok(As::sa(c)) + for c in 0 .. n.saturated_into::() { + if best.is_zero() { + return Ok(c.saturated_into::>()) } let mut transaction = DBTransaction::new(); match self.storage.state_db.revert_one() { @@ -1138,7 +1282,7 @@ impl client::backend::Backend for Backend whe || client::error::Error::UnknownBlock( format!("Error reverting to {}. Block hash not found.", best)))?; - best -= As::sa(1); // prev block + best -= One::one(); // prev block let hash = self.blockchain.hash(best)?.ok_or_else( || client::error::Error::UnknownBlock( format!("Error reverting to {}. Block hash not found.", best)))?; @@ -1150,7 +1294,7 @@ impl client::backend::Backend for Backend whe self.blockchain.update_meta(hash, best, true, false); self.blockchain.leaves.write().revert(removed.hash().clone(), removed.number().clone(), removed.parent_hash().clone()); } - None => return Ok(As::sa(c)) + None => return Ok(c.saturated_into::>()) } } Ok(n) @@ -1173,7 +1317,8 @@ impl client::backend::Backend for Backend whe BlockId::Hash(h) if h == Default::default() => { let genesis_storage = DbGenesisStorage::new(); let root = genesis_storage.0.clone(); - let state = DbState::new(Arc::new(genesis_storage), root); + let db_state = DbState::new(Arc::new(genesis_storage), root); + let state = RefTrackingState::new(db_state, self.storage.clone(), None); return Ok(CachingState::new(state, self.shared_cache.clone(), None)); }, _ => {} @@ -1182,9 +1327,10 @@ impl client::backend::Backend for Backend whe match self.blockchain.header(block) { Ok(Some(ref hdr)) => { let hash = hdr.hash(); - if !self.storage.state_db.is_pruned(&hash, hdr.number().as_()) { + if !self.storage.state_db.is_pruned(&hash, (*hdr.number()).saturated_into::()) { let root = H256::from_slice(hdr.state_root().as_ref()); - let state = DbState::new(self.storage.clone(), root); + let db_state = DbState::new(self.storage.clone(), root); + let state = RefTrackingState::new(db_state, self.storage.clone(), Some(hash.clone())); Ok(CachingState::new(state, self.shared_cache.clone(), Some(hash))) } else { Err(client::error::Error::UnknownBlock(format!("State already discarded for {:?}", block))) @@ -1196,16 +1342,20 @@ impl client::backend::Backend for Backend whe } fn have_state_at(&self, hash: &Block::Hash, number: NumberFor) -> bool { - !self.storage.state_db.is_pruned(hash, number.as_()) + !self.storage.state_db.is_pruned(hash, number.saturated_into::()) } - fn destroy_state(&self, mut state: Self::State) -> Result<(), client::error::Error> { - if let Some(hash) = state.parent_hash.clone() { + fn destroy_state(&self, state: Self::State) -> Result<(), client::error::Error> { + if let Some(hash) = state.cache.parent_hash.clone() { let is_best = || self.blockchain.meta.read().best_hash == hash; - state.sync_cache(&[], &[], vec![], None, None, is_best); + state.release().sync_cache(&[], &[], vec![], None, None, is_best); } Ok(()) } + + fn get_import_lock(&self) -> &Mutex<()> { + &self.import_lock + } } impl client::backend::LocalBackend for Backend @@ -1324,7 +1474,7 @@ mod tests { }; let backend = Backend::::from_kvdb(backing, PruningMode::keep_blocks(1), 0, 16777216).unwrap(); - assert_eq!(backend.blockchain().info().unwrap().best_number, 9); + assert_eq!(backend.blockchain().info().best_number, 9); for i in 0..10 { assert!(backend.blockchain().hash(i).unwrap().is_some()) } diff --git a/core/client/db/src/light.rs b/core/client/db/src/light.rs index 39817140c661337ec69b61010d1be446bc573048..b3398bfdffae7c0379e84d4c5113a8957faf2863 100644 --- a/core/client/db/src/light.rs +++ b/core/client/db/src/light.rs @@ -17,6 +17,7 @@ //! RocksDB-based light client blockchain storage. use std::{sync::Arc, collections::HashMap}; +use std::convert::TryInto; use parking_lot::RwLock; use kvdb::{KeyValueDB, DBTransaction}; @@ -31,12 +32,13 @@ use client::light::blockchain::Storage as LightBlockchainStorage; use parity_codec::{Decode, Encode}; use primitives::Blake2Hasher; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, - Zero, One, As, NumberFor, Digest, DigestItem}; +use runtime_primitives::traits::{ + Block as BlockT, Header as HeaderT, + Zero, One, NumberFor, Digest, DigestItem, +}; use consensus_common::well_known_cache_keys; use crate::cache::{DbCacheSync, DbCache, ComplexBlockId, EntryType as CacheEntryType}; -use crate::utils::{self, meta_keys, Meta, db_err, open_database, - read_db, block_id_to_lookup_key, read_meta}; +use crate::utils::{self, meta_keys, Meta, db_err, read_db, block_id_to_lookup_key, read_meta}; use crate::DatabaseSettings; use log::{trace, warn, debug}; @@ -57,7 +59,7 @@ const CHANGES_TRIE_CHT_PREFIX: u8 = 1; /// Light blockchain storage. Stores most recent headers + CHTs for older headers. /// Locks order: meta, leaves, cache. pub struct LightStorage { - db: Arc, + db: Arc, meta: RwLock, Block::Hash>>, leaves: RwLock>>, cache: Arc>, @@ -69,8 +71,19 @@ impl LightStorage { /// Create new storage with given settings. pub fn new(config: DatabaseSettings) -> ClientResult { - let db = open_database(&config, columns::META, "light")?; + Self::new_inner(config) + } + + #[cfg(feature = "kvdb-rocksdb")] + fn new_inner(config: DatabaseSettings) -> ClientResult { + let db = crate::utils::open_database(&config, columns::META, "light")?; + Self::from_kvdb(db as Arc<_>) + } + #[cfg(not(feature = "kvdb-rocksdb"))] + fn new_inner(_config: DatabaseSettings) -> ClientResult { + log::warn!("Running without the RocksDB feature. The database will NOT be saved."); + let db = Arc::new(kvdb_memorydb::create(crate::utils::NUM_COLUMNS)); Self::from_kvdb(db as Arc<_>) } @@ -83,7 +96,7 @@ impl LightStorage Self::from_kvdb(db as Arc<_>).expect("failed to create test-db") } - fn from_kvdb(db: Arc) -> ClientResult { + fn from_kvdb(db: Arc) -> ClientResult { let meta = read_meta::(&*db, columns::META, columns::HEADER)?; let leaves = LeafSet::read_from_db(&*db, columns::META, meta_keys::LEAF_PREFIX)?; let cache = DbCache::new( @@ -142,15 +155,15 @@ impl BlockchainHeaderBackend for LightStorage utils::read_header(&*self.db, columns::KEY_LOOKUP, columns::HEADER, id) } - fn info(&self) -> ClientResult> { + fn info(&self) -> BlockchainInfo { let meta = self.meta.read(); - Ok(BlockchainInfo { + BlockchainInfo { best_hash: meta.best_hash, best_number: meta.best_number, genesis_hash: meta.genesis_hash, finalized_hash: meta.finalized_hash, finalized_number: meta.finalized_number, - }) + } } fn status(&self, id: BlockId) -> ClientResult { @@ -267,12 +280,18 @@ impl LightStorage { transaction.put(columns::META, meta_keys::FINALIZED_BLOCK, &lookup_key); // build new CHT(s) if required - if let Some(new_cht_number) = cht::is_build_required(cht::SIZE, *header.number()) { - let new_cht_start: NumberFor = cht::start_number(cht::SIZE, new_cht_number); + if let Some(new_cht_number) = cht::is_build_required(cht::size(), *header.number()) { + let new_cht_start: NumberFor = cht::start_number(cht::size(), new_cht_number); + + let mut current_num = new_cht_start; + let cht_range = ::std::iter::from_fn(|| { + let old_current_num = current_num; + current_num = current_num + One::one(); + Some(old_current_num) + }); let new_header_cht_root = cht::compute_root::( - cht::SIZE, new_cht_number, (new_cht_start.as_()..) - .map(|num| self.hash(As::sa(num))) + cht::size(), new_cht_number, cht_range.map(|num| self.hash(num)) )?; transaction.put( columns::CHT, @@ -282,9 +301,15 @@ impl LightStorage { // if the header includes changes trie root, let's build a changes tries roots CHT if header.digest().log(DigestItem::as_changes_trie_root).is_some() { + let mut current_num = new_cht_start; + let cht_range = ::std::iter::from_fn(|| { + let old_current_num = current_num; + current_num = current_num + One::one(); + Some(old_current_num) + }); let new_changes_trie_cht_root = cht::compute_root::( - cht::SIZE, new_cht_number, (new_cht_start.as_()..) - .map(|num| self.changes_trie_root(BlockId::Number(As::sa(num)))) + cht::size(), new_cht_number, cht_range + .map(|num| self.changes_trie_root(BlockId::Number(num))) )?; transaction.put( columns::CHT, @@ -295,7 +320,7 @@ impl LightStorage { // prune headers that are replaced with CHT let mut prune_block = new_cht_start; - let new_cht_end = cht::end_number(cht::SIZE, new_cht_number); + let new_cht_end = cht::end_number(cht::size(), new_cht_number); trace!(target: "db", "Replacing blocks [{}..{}] with CHT#{}", new_cht_start, new_cht_end, new_cht_number); @@ -328,7 +353,7 @@ impl LightStorage { fn read_cht_root( &self, cht_type: u8, - cht_size: u64, + cht_size: NumberFor, block: NumberFor ) -> ClientResult { let no_cht_for_block = || ClientError::Backend(format!("CHT for block {} not exists", block)); @@ -480,11 +505,19 @@ impl LightBlockchainStorage for LightStorage } } - fn header_cht_root(&self, cht_size: u64, block: NumberFor) -> ClientResult { + fn header_cht_root( + &self, + cht_size: NumberFor, + block: NumberFor, + ) -> ClientResult { self.read_cht_root(HEADER_CHT_PREFIX, cht_size, block) } - fn changes_trie_cht_root(&self, cht_size: u64, block: NumberFor) -> ClientResult { + fn changes_trie_cht_root( + &self, + cht_size: NumberFor, + block: NumberFor, + ) -> ClientResult { self.read_cht_root(CHANGES_TRIE_CHT_PREFIX, cht_size, block) } @@ -524,13 +557,13 @@ impl LightBlockchainStorage for LightStorage Ok(self.meta.read().finalized_hash.clone()) } - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { Some(self.cache.clone()) } } /// Build the key for inserting header-CHT at given block. -fn cht_key>(cht_type: u8, block: N) -> [u8; 5] { +fn cht_key>(cht_type: u8, block: N) -> [u8; 5] { let mut key = [cht_type; 5]; key[1..].copy_from_slice(&utils::number_index_key(block)); key @@ -622,12 +655,12 @@ pub(crate) mod tests { fn returns_info() { let db = LightStorage::new_test(); let genesis_hash = insert_block(&db, HashMap::new(), || default_header(&Default::default(), 0)); - let info = db.info().unwrap(); + let info = db.info(); assert_eq!(info.best_hash, genesis_hash); assert_eq!(info.best_number, 0); assert_eq!(info.genesis_hash, genesis_hash); let best_hash = insert_block(&db, HashMap::new(), || default_header(&genesis_hash, 1)); - let info = db.info().unwrap(); + let info = db.info(); assert_eq!(info.best_hash, best_hash); assert_eq!(info.best_number, 1); assert_eq!(info.genesis_hash, genesis_hash); @@ -668,33 +701,44 @@ pub(crate) mod tests { fn finalized_ancient_headers_are_replaced_with_cht() { fn insert_headers Header>(header_producer: F) -> LightStorage { let db = LightStorage::new_test(); + let cht_size: u64 = cht::size(); + let ucht_size: usize = cht_size as _; // insert genesis block header (never pruned) let mut prev_hash = insert_final_block(&db, HashMap::new(), || header_producer(&Default::default(), 0)); // insert SIZE blocks && ensure that nothing is pruned - for number in 0..cht::SIZE { + + for number in 0..cht::size() { prev_hash = insert_block(&db, HashMap::new(), || header_producer(&prev_hash, 1 + number)); } - assert_eq!(db.db.iter(columns::HEADER).count(), (1 + cht::SIZE) as usize); + assert_eq!(db.db.iter(columns::HEADER).count(), 1 + ucht_size); assert_eq!(db.db.iter(columns::CHT).count(), 0); // insert next SIZE blocks && ensure that nothing is pruned - for number in 0..cht::SIZE { - prev_hash = insert_block(&db, HashMap::new(), || header_producer(&prev_hash, 1 + cht::SIZE + number)); + for number in 0..(cht_size as _) { + prev_hash = insert_block( + &db, + HashMap::new(), + || header_producer(&prev_hash, 1 + cht_size + number), + ); } - assert_eq!(db.db.iter(columns::HEADER).count(), (1 + cht::SIZE + cht::SIZE) as usize); + assert_eq!(db.db.iter(columns::HEADER).count(), 1 + ucht_size + ucht_size); assert_eq!(db.db.iter(columns::CHT).count(), 0); - // insert block #{2 * cht::SIZE + 1} && check that new CHT is created + headers of this CHT are pruned + // insert block #{2 * cht::size() + 1} && check that new CHT is created + headers of this CHT are pruned // nothing is yet finalized, so nothing is pruned. - prev_hash = insert_block(&db, HashMap::new(), || header_producer(&prev_hash, 1 + cht::SIZE + cht::SIZE)); - assert_eq!(db.db.iter(columns::HEADER).count(), (2 + cht::SIZE + cht::SIZE) as usize); + prev_hash = insert_block( + &db, + HashMap::new(), + || header_producer(&prev_hash, 1 + cht_size + cht_size), + ); + assert_eq!(db.db.iter(columns::HEADER).count(), 2 + ucht_size + ucht_size); assert_eq!(db.db.iter(columns::CHT).count(), 0); // now finalize the block. - for i in (0..(cht::SIZE + cht::SIZE)).map(|i| i + 1) { - db.finalize_header(BlockId::Number(i)).unwrap(); + for i in (0..(ucht_size + ucht_size)).map(|i| i + 1) { + db.finalize_header(BlockId::Number(i as _)).unwrap(); } db.finalize_header(BlockId::Hash(prev_hash)).unwrap(); db @@ -702,34 +746,36 @@ pub(crate) mod tests { // when headers are created without changes tries roots let db = insert_headers(default_header); - assert_eq!(db.db.iter(columns::HEADER).count(), (1 + cht::SIZE + 1) as usize); - assert_eq!(db.db.iter(columns::KEY_LOOKUP).count(), (2 * (1 + cht::SIZE + 1)) as usize); + let cht_size: u64 = cht::size(); + assert_eq!(db.db.iter(columns::HEADER).count(), (1 + cht_size + 1) as usize); + assert_eq!(db.db.iter(columns::KEY_LOOKUP).count(), (2 * (1 + cht_size + 1)) as usize); assert_eq!(db.db.iter(columns::CHT).count(), 1); - assert!((0..cht::SIZE).all(|i| db.header(BlockId::Number(1 + i)).unwrap().is_none())); - assert!(db.header_cht_root(cht::SIZE, cht::SIZE / 2).is_ok()); - assert!(db.header_cht_root(cht::SIZE, cht::SIZE + cht::SIZE / 2).is_err()); - assert!(db.changes_trie_cht_root(cht::SIZE, cht::SIZE / 2).is_err()); - assert!(db.changes_trie_cht_root(cht::SIZE, cht::SIZE + cht::SIZE / 2).is_err()); + assert!((0..cht_size as _).all(|i| db.header(BlockId::Number(1 + i)).unwrap().is_none())); + assert!(db.header_cht_root(cht_size, cht_size / 2).is_ok()); + assert!(db.header_cht_root(cht_size, cht_size + cht_size / 2).is_err()); + assert!(db.changes_trie_cht_root(cht_size, cht_size / 2).is_err()); + assert!(db.changes_trie_cht_root(cht_size, cht_size + cht_size / 2).is_err()); // when headers are created with changes tries roots let db = insert_headers(header_with_changes_trie); - assert_eq!(db.db.iter(columns::HEADER).count(), (1 + cht::SIZE + 1) as usize); + assert_eq!(db.db.iter(columns::HEADER).count(), (1 + cht_size + 1) as usize); assert_eq!(db.db.iter(columns::CHT).count(), 2); - assert!((0..cht::SIZE).all(|i| db.header(BlockId::Number(1 + i)).unwrap().is_none())); - assert!(db.header_cht_root(cht::SIZE, cht::SIZE / 2).is_ok()); - assert!(db.header_cht_root(cht::SIZE, cht::SIZE + cht::SIZE / 2).is_err()); - assert!(db.changes_trie_cht_root(cht::SIZE, cht::SIZE / 2).is_ok()); - assert!(db.changes_trie_cht_root(cht::SIZE, cht::SIZE + cht::SIZE / 2).is_err()); + assert!((0..cht_size as _).all(|i| db.header(BlockId::Number(1 + i)).unwrap().is_none())); + assert!(db.header_cht_root(cht_size, cht_size / 2).is_ok()); + assert!(db.header_cht_root(cht_size, cht_size + cht_size / 2).is_err()); + assert!(db.changes_trie_cht_root(cht_size, cht_size / 2).is_ok()); + assert!(db.changes_trie_cht_root(cht_size, cht_size + cht_size / 2).is_err()); } #[test] fn get_cht_fails_for_genesis_block() { - assert!(LightStorage::::new_test().header_cht_root(cht::SIZE, 0).is_err()); + assert!(LightStorage::::new_test().header_cht_root(cht::size(), 0).is_err()); } #[test] fn get_cht_fails_for_non_existant_cht() { - assert!(LightStorage::::new_test().header_cht_root(cht::SIZE, (cht::SIZE / 2) as u64).is_err()); + let cht_size: u64 = cht::size(); + assert!(LightStorage::::new_test().header_cht_root(cht_size, cht_size / 2).is_err()); } #[test] @@ -738,20 +784,22 @@ pub(crate) mod tests { // insert 1 + SIZE + SIZE + 1 blocks so that CHT#0 is created let mut prev_hash = insert_final_block(&db, HashMap::new(), || header_with_changes_trie(&Default::default(), 0)); - for i in 1..1 + cht::SIZE + cht::SIZE + 1 { + let cht_size: u64 = cht::size(); + let ucht_size: usize = cht_size as _; + for i in 1..1 + ucht_size + ucht_size + 1 { prev_hash = insert_block(&db, HashMap::new(), || header_with_changes_trie(&prev_hash, i as u64)); db.finalize_header(BlockId::Hash(prev_hash)).unwrap(); } - let cht_root_1 = db.header_cht_root(cht::SIZE, cht::start_number(cht::SIZE, 0)).unwrap(); - let cht_root_2 = db.header_cht_root(cht::SIZE, (cht::start_number(cht::SIZE, 0) + cht::SIZE / 2) as u64).unwrap(); - let cht_root_3 = db.header_cht_root(cht::SIZE, cht::end_number(cht::SIZE, 0)).unwrap(); + let cht_root_1 = db.header_cht_root(cht_size, cht::start_number(cht_size, 0)).unwrap(); + let cht_root_2 = db.header_cht_root(cht_size, cht::start_number(cht_size, 0) + cht_size / 2).unwrap(); + let cht_root_3 = db.header_cht_root(cht_size, cht::end_number(cht_size, 0)).unwrap(); assert_eq!(cht_root_1, cht_root_2); assert_eq!(cht_root_2, cht_root_3); - let cht_root_1 = db.changes_trie_cht_root(cht::SIZE, cht::start_number(cht::SIZE, 0)).unwrap(); - let cht_root_2 = db.changes_trie_cht_root(cht::SIZE, (cht::start_number(cht::SIZE, 0) + cht::SIZE / 2) as u64).unwrap(); - let cht_root_3 = db.changes_trie_cht_root(cht::SIZE, cht::end_number(cht::SIZE, 0)).unwrap(); + let cht_root_1 = db.changes_trie_cht_root(cht_size, cht::start_number(cht_size, 0)).unwrap(); + let cht_root_2 = db.changes_trie_cht_root(cht_size, cht::start_number(cht_size, 0) + cht_size / 2).unwrap(); + let cht_root_3 = db.changes_trie_cht_root(cht_size, cht::end_number(cht_size, 0)).unwrap(); assert_eq!(cht_root_1, cht_root_2); assert_eq!(cht_root_2, cht_root_3); } @@ -840,7 +888,7 @@ pub(crate) mod tests { map } - fn get_authorities(cache: &BlockchainCache, at: BlockId) -> Option> { + fn get_authorities(cache: &dyn BlockchainCache, at: BlockId) -> Option> { cache.get_at(&well_known_cache_keys::AUTHORITIES, &at).and_then(|val| Decode::decode(&mut &val[..])) } @@ -986,12 +1034,12 @@ pub(crate) mod tests { fn database_is_reopened() { let db = LightStorage::new_test(); let hash0 = insert_final_block(&db, HashMap::new(), || default_header(&Default::default(), 0)); - assert_eq!(db.info().unwrap().best_hash, hash0); + assert_eq!(db.info().best_hash, hash0); assert_eq!(db.header(BlockId::Hash(hash0)).unwrap().unwrap().hash(), hash0); let db = db.db; let db = LightStorage::from_kvdb(db).unwrap(); - assert_eq!(db.info().unwrap().best_hash, hash0); + assert_eq!(db.info().best_hash, hash0); assert_eq!(db.header(BlockId::Hash::(hash0)).unwrap().unwrap().hash(), hash0); } diff --git a/core/client/db/src/storage_cache.rs b/core/client/db/src/storage_cache.rs index 439a749c85346668b0f4620ed6bc709469382d28..cc4670866caadb62ad8417b4c50893251abe44fb 100644 --- a/core/client/db/src/storage_cache.rs +++ b/core/client/db/src/storage_cache.rs @@ -99,6 +99,17 @@ struct LocalCache { hashes: HashMap>, } +/// Cache changes. +pub struct CacheChanges { + /// Shared canonical state cache. + shared_cache: SharedCache, + /// Local cache of values for this state. + local_cache: RwLock>, + /// Hash of the block on top of which this instance was created or + /// `None` if cache is disabled + pub parent_hash: Option, +} + /// State abstraction. /// Manages shared global state cache which reflects the canonical /// state as it is on the disk. @@ -109,56 +120,11 @@ struct LocalCache { pub struct CachingState, B: Block> { /// Backing state. state: S, - /// Shared canonical state cache. - shared_cache: SharedCache, - /// Local cache of values for this state. - local_cache: RwLock>, - /// Hash of the block on top of which this instance was created or - /// `None` if cache is disabled - pub parent_hash: Option, + /// Cache data. + pub cache: CacheChanges } -impl, B: Block> CachingState { - /// Create a new instance wrapping generic State and shared cache. - pub fn new(state: S, shared_cache: SharedCache, parent_hash: Option) -> CachingState { - CachingState { - state, - shared_cache, - local_cache: RwLock::new(LocalCache { - storage: Default::default(), - hashes: Default::default(), - }), - parent_hash: parent_hash, - } - } - - fn storage_insert(cache: &mut Cache, k: StorageValue, v: Option) { - if let Some(v_) = &v { - while cache.storage_used_size + v_.len() > cache.shared_cache_size { - // pop until space constraint satisfied - match cache.storage.remove_lru() { - Some((_, Some(popped_v))) => - cache.storage_used_size = cache.storage_used_size - popped_v.len(), - Some((_, None)) => continue, - None => break, - }; - } - cache.storage_used_size = cache.storage_used_size + v_.len(); - } - cache.storage.insert(k, v); - } - - fn storage_remove( - storage: &mut LruCache>, - k: &StorageKey, - storage_used_size: &mut usize, - ) { - let v = storage.remove(k); - if let Some(Some(v_)) = v { - *storage_used_size = *storage_used_size - v_.len(); - } - } - +impl CacheChanges { /// Propagate local cache into the shared cache and synchronize /// the shared cache with the best block state. /// This function updates the shared cache by removing entries @@ -189,7 +155,7 @@ impl, B: Block> CachingState { m.is_canon = true; for a in &m.storage { trace!("Reverting enacted key {:?}", a); - CachingState::::storage_remove(&mut cache.storage, a, &mut cache.storage_used_size); + CacheChanges::::storage_remove(&mut cache.storage, a, &mut cache.storage_used_size); } false } else { @@ -205,7 +171,7 @@ impl, B: Block> CachingState { m.is_canon = false; for a in &m.storage { trace!("Retracted key {:?}", a); - CachingState::::storage_remove(&mut cache.storage, a, &mut cache.storage_used_size); + CacheChanges::::storage_remove(&mut cache.storage, a, &mut cache.storage_used_size); } false } else { @@ -228,7 +194,7 @@ impl, B: Block> CachingState { if is_best { trace!("Committing {} local, {} hashes, {} modified entries", local_cache.storage.len(), local_cache.hashes.len(), changes.len()); for (k, v) in local_cache.storage.drain() { - CachingState::::storage_insert(cache, k, v); + CacheChanges::::storage_insert(cache, k, v); } for (k, v) in local_cache.hashes.drain() { cache.hashes.insert(k, v); @@ -248,7 +214,7 @@ impl, B: Block> CachingState { modifications.insert(k.clone()); if is_best { cache.hashes.remove(&k); - CachingState::::storage_insert(cache, k, v); + CacheChanges::::storage_insert(cache, k, v); } } // Save modified storage. These are ordered by the block number. @@ -272,6 +238,50 @@ impl, B: Block> CachingState { } } + fn storage_insert(cache: &mut Cache, k: StorageValue, v: Option) { + if let Some(v_) = &v { + while cache.storage_used_size + v_.len() > cache.shared_cache_size { + // pop until space constraint satisfied + match cache.storage.remove_lru() { + Some((_, Some(popped_v))) => + cache.storage_used_size = cache.storage_used_size - popped_v.len(), + Some((_, None)) => continue, + None => break, + }; + } + cache.storage_used_size = cache.storage_used_size + v_.len(); + } + cache.storage.insert(k, v); + } + + fn storage_remove( + storage: &mut LruCache>, + k: &StorageKey, + storage_used_size: &mut usize, + ) { + let v = storage.remove(k); + if let Some(Some(v_)) = v { + *storage_used_size = *storage_used_size - v_.len(); + } + } +} + +impl, B: Block> CachingState { + /// Create a new instance wrapping generic State and shared cache. + pub fn new(state: S, shared_cache: SharedCache, parent_hash: Option) -> CachingState { + CachingState { + state, + cache: CacheChanges { + shared_cache, + local_cache: RwLock::new(LocalCache { + storage: Default::default(), + hashes: Default::default(), + }), + parent_hash: parent_hash, + }, + } + } + /// Check if the key can be returned from cache by matching current block parent hash against canonical /// state and filtering out entries modified in later blocks. fn is_allowed( @@ -312,6 +322,11 @@ impl, B: Block> CachingState { trace!("Cache lookup skipped for {:?}: parent hash is unknown", key); false } + + /// Dispose state and return cache data. + pub fn release(self) -> CacheChanges { + self.cache + } } impl, B:Block> StateBackend for CachingState { @@ -320,13 +335,13 @@ impl, B:Block> StateBackend for CachingState Result>, Self::Error> { - let local_cache = self.local_cache.upgradable_read(); + let local_cache = self.cache.local_cache.upgradable_read(); if let Some(entry) = local_cache.storage.get(key).cloned() { trace!("Found in local cache: {:?}", key); return Ok(entry) } - let mut cache = self.shared_cache.lock(); - if Self::is_allowed(key, &self.parent_hash, &cache.modifications) { + let mut cache = self.cache.shared_cache.lock(); + if Self::is_allowed(key, &self.cache.parent_hash, &cache.modifications) { if let Some(entry) = cache.storage.get_mut(key).map(|a| a.clone()) { trace!("Found in shared cache: {:?}", key); return Ok(entry) @@ -339,13 +354,13 @@ impl, B:Block> StateBackend for CachingState Result, Self::Error> { - let local_cache = self.local_cache.upgradable_read(); + let local_cache = self.cache.local_cache.upgradable_read(); if let Some(entry) = local_cache.hashes.get(key).cloned() { trace!("Found hash in local cache: {:?}", key); return Ok(entry) } - let mut cache = self.shared_cache.lock(); - if Self::is_allowed(key, &self.parent_hash, &cache.modifications) { + let mut cache = self.cache.shared_cache.lock(); + if Self::is_allowed(key, &self.cache.parent_hash, &cache.modifications) { if let Some(entry) = cache.hashes.get_mut(key).map(|a| a.clone()) { trace!("Found hash in shared cache: {:?}", key); return Ok(entry) @@ -397,12 +412,16 @@ impl, B:Block> StateBackend for CachingState) -> Vec> { + fn keys(&self, prefix: &[u8]) -> Vec> { self.state.keys(prefix) } - fn try_into_trie_backend(self) -> Option> { - self.state.try_into_trie_backend() + fn child_keys(&self, child_key: &[u8], prefix: &[u8]) -> Vec> { + self.state.child_keys(child_key, prefix) + } + + fn as_trie_backend(&mut self) -> Option<&TrieBackend> { + self.state.as_trie_backend() } } @@ -432,22 +451,22 @@ mod tests { // blocks [ 3a(c) 2a(c) 2b 1b 1a(c) 0 ] // state [ 5 5 4 3 2 2 ] let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(root_parent.clone())); - s.sync_cache(&[], &[], vec![(key.clone(), Some(vec![2]))], Some(h0.clone()), Some(0), || true); + s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![2]))], Some(h0.clone()), Some(0), || true); let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(h0.clone())); - s.sync_cache(&[], &[], vec![], Some(h1a.clone()), Some(1), || true); + s.cache.sync_cache(&[], &[], vec![], Some(h1a.clone()), Some(1), || true); let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(h0.clone())); - s.sync_cache(&[], &[], vec![(key.clone(), Some(vec![3]))], Some(h1b.clone()), Some(1), || false); + s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![3]))], Some(h1b.clone()), Some(1), || false); let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(h1b.clone())); - s.sync_cache(&[], &[], vec![(key.clone(), Some(vec![4]))], Some(h2b.clone()), Some(2), || false); + s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![4]))], Some(h2b.clone()), Some(2), || false); let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(h1a.clone())); - s.sync_cache(&[], &[], vec![(key.clone(), Some(vec![5]))], Some(h2a.clone()), Some(2), || true); + s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![5]))], Some(h2a.clone()), Some(2), || true); let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(h2a.clone())); - s.sync_cache(&[], &[], vec![], Some(h3a.clone()), Some(3), || true); + s.cache.sync_cache(&[], &[], vec![], Some(h3a.clone()), Some(3), || true); let s = CachingState::new(InMemory::::default(), shared.clone(), Some(h3a.clone())); assert_eq!(s.storage(&key).unwrap().unwrap(), vec![5]); @@ -464,7 +483,14 @@ mod tests { // reorg to 3b // blocks [ 3b(c) 3a 2a 2b(c) 1b 1a 0 ] let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(h2b.clone())); - s.sync_cache(&[h1b.clone(), h2b.clone(), h3b.clone()], &[h1a.clone(), h2a.clone(), h3a.clone()], vec![], Some(h3b.clone()), Some(3), || true); + s.cache.sync_cache( + &[h1b.clone(), h2b.clone(), h3b.clone()], + &[h1a.clone(), h2a.clone(), h3a.clone()], + vec![], + Some(h3b.clone()), + Some(3), + || true + ); let s = CachingState::new(InMemory::::default(), shared.clone(), Some(h3a.clone())); assert!(s.storage(&key).unwrap().is_none()); } @@ -478,11 +504,11 @@ mod tests { let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(root_parent.clone())); let key = H256::random()[..].to_vec(); - s.sync_cache(&[], &[], vec![(key.clone(), Some(vec![1, 2, 3]))], Some(h0.clone()), Some(0), || true); + s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![1, 2, 3]))], Some(h0.clone()), Some(0), || true); assert_eq!(shared.lock().used_storage_cache_size(), 3 /* bytes */); let key = H256::random()[..].to_vec(); - s.sync_cache(&[], &[], vec![(key.clone(), Some(vec![1, 2]))], Some(h0.clone()), Some(0), || true); + s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![1, 2]))], Some(h0.clone()), Some(0), || true); assert_eq!(shared.lock().used_storage_cache_size(), 5 /* bytes */); } @@ -495,11 +521,11 @@ mod tests { let mut s = CachingState::new(InMemory::::default(), shared.clone(), Some(root_parent.clone())); let key = H256::random()[..].to_vec(); - s.sync_cache(&[], &[], vec![(key.clone(), Some(vec![1, 2, 3, 4]))], Some(h0.clone()), Some(0), || true); + s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![1, 2, 3, 4]))], Some(h0.clone()), Some(0), || true); assert_eq!(shared.lock().used_storage_cache_size(), 4 /* bytes */); let key = H256::random()[..].to_vec(); - s.sync_cache(&[], &[], vec![(key.clone(), Some(vec![1, 2]))], Some(h0.clone()), Some(0), || true); + s.cache.sync_cache(&[], &[], vec![(key.clone(), Some(vec![1, 2]))], Some(h0.clone()), Some(0), || true); assert_eq!(shared.lock().used_storage_cache_size(), 2 /* bytes */); } } diff --git a/core/client/db/src/utils.rs b/core/client/db/src/utils.rs index b51faae6de857620702f839be2ac38ea9913d035..bd7cf660ea4db03d8f70e3e0bb0b4ac163dbc4e1 100644 --- a/core/client/db/src/utils.rs +++ b/core/client/db/src/utils.rs @@ -17,10 +17,10 @@ //! Db-based backend utility structures and functions, used by both //! full and light storages. -use std::sync::Arc; -use std::io; +use std::{io, convert::TryInto, sync::Arc}; use kvdb::{KeyValueDB, DBTransaction}; +#[cfg(feature = "kvdb-rocksdb")] use kvdb_rocksdb::{Database, DatabaseConfig}; use log::debug; @@ -28,7 +28,10 @@ use client; use parity_codec::Decode; use trie::DBValue; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{As, Block as BlockT, Header as HeaderT, Zero}; +use runtime_primitives::traits::{ + Block as BlockT, Header as HeaderT, Zero, UniqueSaturatedFrom, + UniqueSaturatedInto, CheckedConversion +}; use crate::DatabaseSettings; /// Number of columns in the db. Must be the same for both full && light dbs. @@ -78,10 +81,8 @@ pub type NumberIndexKey = [u8; 4]; /// /// In the current database schema, this kind of key is only used for /// lookups into an index, NOT for storing header data or others. -pub fn number_index_key(n: N) -> NumberIndexKey where N: As { - let n: u64 = n.as_(); - assert!(n & 0xffffffff00000000 == 0); - +pub fn number_index_key>(n: N) -> NumberIndexKey { + let n = n.checked_into::().unwrap(); [ (n >> 24) as u8, ((n >> 16) & 0xff) as u8, @@ -93,7 +94,7 @@ pub fn number_index_key(n: N) -> NumberIndexKey where N: As { /// Convert number and hash into long lookup key for blocks that are /// not in the canonical chain. pub fn number_and_hash_to_lookup_key(number: N, hash: H) -> Vec where - N: As, + N: TryInto, H: AsRef<[u8]> { let mut lookup_key = number_index_key(number).to_vec(); @@ -103,18 +104,20 @@ pub fn number_and_hash_to_lookup_key(number: N, hash: H) -> Vec where /// Convert block lookup key into block number. /// all block lookup keys start with the block number. -pub fn lookup_key_to_number(key: &[u8]) -> client::error::Result where N: As { +pub fn lookup_key_to_number(key: &[u8]) -> client::error::Result where + N: From +{ if key.len() < 4 { return Err(client::error::Error::Backend("Invalid block key".into())); } - Ok((key[0] as u64) << 24 - | (key[1] as u64) << 16 - | (key[2] as u64) << 8 - | (key[3] as u64)).map(As::sa) + Ok((key[0] as u32) << 24 + | (key[1] as u32) << 16 + | (key[2] as u32) << 8 + | (key[3] as u32)).map(Into::into) } /// Delete number to hash mapping in DB transaction. -pub fn remove_number_to_key_mapping>( +pub fn remove_number_to_key_mapping>( transaction: &mut DBTransaction, key_lookup_col: Option, number: N, @@ -123,7 +126,7 @@ pub fn remove_number_to_key_mapping>( } /// Remove key mappings. -pub fn remove_key_mappings, H: AsRef<[u8]>>( +pub fn remove_key_mappings, H: AsRef<[u8]>>( transaction: &mut DBTransaction, key_lookup_col: Option, number: N, @@ -135,7 +138,7 @@ pub fn remove_key_mappings, H: AsRef<[u8]>>( /// Place a number mapping into the database. This maps number to current perceived /// block hash at that position. -pub fn insert_number_to_key_mapping + Clone, H: AsRef<[u8]>>( +pub fn insert_number_to_key_mapping + Clone, H: AsRef<[u8]>>( transaction: &mut DBTransaction, key_lookup_col: Option, number: N, @@ -149,7 +152,7 @@ pub fn insert_number_to_key_mapping + Clone, H: AsRef<[u8]>>( } /// Insert a hash to key mapping in the database. -pub fn insert_hash_to_key_mapping, H: AsRef<[u8]> + Clone>( +pub fn insert_hash_to_key_mapping, H: AsRef<[u8]> + Clone>( transaction: &mut DBTransaction, key_lookup_col: Option, number: N, @@ -166,12 +169,12 @@ pub fn insert_hash_to_key_mapping, H: AsRef<[u8]> + Clone>( /// block lookup key is the DB-key header, block and justification are stored under. /// looks up lookup key by hash from DB as necessary. pub fn block_id_to_lookup_key( - db: &KeyValueDB, + db: &dyn KeyValueDB, key_lookup_col: Option, id: BlockId ) -> Result>, client::error::Error> where Block: BlockT, - ::runtime_primitives::traits::NumberFor: As, + ::runtime_primitives::traits::NumberFor: UniqueSaturatedFrom + UniqueSaturatedInto, { let res = match id { BlockId::Number(n) => db.get( @@ -191,7 +194,12 @@ pub fn db_err(err: io::Error) -> client::error::Error { } /// Open RocksDB database. -pub fn open_database(config: &DatabaseSettings, col_meta: Option, db_type: &str) -> client::error::Result> { +#[cfg(feature = "kvdb-rocksdb")] +pub fn open_database( + config: &DatabaseSettings, + col_meta: Option, + db_type: &str +) -> client::error::Result> { let mut db_config = DatabaseConfig::with_columns(Some(NUM_COLUMNS)); db_config.memory_budget = config.cache_size; let path = config.path.to_str().ok_or_else(|| client::error::Error::Backend("Invalid database path".into()))?; @@ -216,7 +224,12 @@ pub fn open_database(config: &DatabaseSettings, col_meta: Option, db_type: } /// Read database column entry for the given block. -pub fn read_db(db: &KeyValueDB, col_index: Option, col: Option, id: BlockId) -> client::error::Result> +pub fn read_db( + db: &dyn KeyValueDB, + col_index: Option, + col: Option, + id: BlockId +) -> client::error::Result> where Block: BlockT, { @@ -228,7 +241,7 @@ pub fn read_db(db: &KeyValueDB, col_index: Option, col: Option, /// Read a header from the database. pub fn read_header( - db: &KeyValueDB, + db: &dyn KeyValueDB, col_index: Option, col: Option, id: BlockId, @@ -246,7 +259,7 @@ pub fn read_header( /// Required header from the database. pub fn require_header( - db: &KeyValueDB, + db: &dyn KeyValueDB, col_index: Option, col: Option, id: BlockId, @@ -256,7 +269,7 @@ pub fn require_header( } /// Read meta from the database. -pub fn read_meta(db: &KeyValueDB, col_meta: Option, col_header: Option) -> Result< +pub fn read_meta(db: &dyn KeyValueDB, col_meta: Option, col_header: Option) -> Result< Meta<<::Header as HeaderT>::Number, Block::Hash>, client::error::Error, > diff --git a/core/client/src/backend.rs b/core/client/src/backend.rs index 09faab1a12fedaed23ce6c3017d471acf5487fa6..5028b9dde7a6e3e0614a4588b444a8b9a7872f0b 100644 --- a/core/client/src/backend.rs +++ b/core/client/src/backend.rs @@ -26,6 +26,7 @@ use state_machine::ChangesTrieStorage as StateChangesTrieStorage; use consensus::well_known_cache_keys; use hash_db::Hasher; use trie::MemoryDB; +use parking_lot::Mutex; /// State of a new block. #[derive(Debug, Clone, Copy, PartialEq, Eq)] @@ -127,7 +128,7 @@ pub trait Backend: AuxStore + Send + Sync where /// Associated state backend type. type State: StateBackend; /// Changes trie storage. - type ChangesTrieStorage: PrunableStateChangesTrieStorage; + type ChangesTrieStorage: PrunableStateChangesTrieStorage; /// Begin a new block insertion transaction with given parent block id. /// When constructing the genesis, this is called with all-zero hash. @@ -174,12 +175,25 @@ pub trait Backend: AuxStore + Send + Sync where fn get_aux(&self, key: &[u8]) -> error::Result>> { AuxStore::get_aux(self, key) } + + /// Gain access to the import lock around this backend. + /// _Note_ Backend isn't expected to acquire the lock by itself ever. Rather + /// the using components should acquire and hold the lock whenever they do + /// something that the import of a block would interfere with, e.g. importing + /// a new block or calculating the best head. + fn get_import_lock(&self) -> &Mutex<()>; } /// Changes trie storage that supports pruning. -pub trait PrunableStateChangesTrieStorage: StateChangesTrieStorage { +pub trait PrunableStateChangesTrieStorage: + StateChangesTrieStorage> +{ /// Get number block of oldest, non-pruned changes trie. - fn oldest_changes_trie_block(&self, config: &ChangesTrieConfiguration, best_finalized: u64) -> u64; + fn oldest_changes_trie_block( + &self, + config: &ChangesTrieConfiguration, + best_finalized: NumberFor, + ) -> NumberFor; } /// Mark for all Backend implementations, that are making use of state data, stored locally. diff --git a/core/client/src/block_builder/block_builder.rs b/core/client/src/block_builder/block_builder.rs index 4d40bed9b050e31a68b091666dcbdc3e1da390a3..4564c29aae4191956e48cd9d9ac21342c1e5f224 100644 --- a/core/client/src/block_builder/block_builder.rs +++ b/core/client/src/block_builder/block_builder.rs @@ -20,7 +20,7 @@ use parity_codec::Encode; use runtime_primitives::ApplyOutcome; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{ - Header as HeaderT, Hash, Block as BlockT, One, HashFor, ProvideRuntimeApi, ApiRef + Header as HeaderT, Hash, Block as BlockT, One, HashFor, ProvideRuntimeApi, ApiRef, DigestFor, }; use primitives::{H256, ExecutionContext}; use crate::blockchain::HeaderBackend; @@ -41,23 +41,23 @@ where A: ProvideRuntimeApi + HeaderBackend + 'a, A::Api: BlockBuilderApi, { - /// Create a new instance of builder from the given client, building on the latest block. - pub fn new(api: &'a A) -> error::Result { - api.info().and_then(|i| - Self::at_block(&BlockId::Hash(i.best_hash), api, false) - ) + /// Create a new instance of builder from the given client, building on the + /// latest block. + pub fn new(api: &'a A, inherent_digests: DigestFor) -> error::Result { + Self::at_block(&BlockId::Hash(api.info().best_hash), api, false, inherent_digests) } /// Create a new instance of builder from the given client using a /// particular block's ID to build upon with optional proof recording enabled. /// /// While proof recording is enabled, all accessed trie nodes are saved. - /// These recorded trie nodes can be used by a third party to proof the + /// These recorded trie nodes can be used by a third party to prove the /// output of this block builder without having access to the full storage. pub fn at_block( block_id: &BlockId, api: &'a A, - proof_recording: bool + proof_recording: bool, + inherent_digests: DigestFor, ) -> error::Result { let number = api.block_number_from_id(block_id)? .ok_or_else(|| error::Error::UnknownBlock(format!("{}", block_id)))? @@ -70,7 +70,7 @@ where Default::default(), Default::default(), parent_hash, - Default::default() + inherent_digests, ); let mut api = api.runtime_api(); @@ -80,7 +80,7 @@ where } api.initialize_block_with_context( - block_id, ExecutionContext::BlockConstruction, &header + block_id, ExecutionContext::BlockConstruction, &header, )?; Ok(BlockBuilder { diff --git a/core/client/src/blockchain.rs b/core/client/src/blockchain.rs index d168ecda197c687adba005bad36af0288cb099a4..b07e26396efb5bee8eda6edaab74d97913b26989 100644 --- a/core/client/src/blockchain.rs +++ b/core/client/src/blockchain.rs @@ -30,7 +30,7 @@ pub trait HeaderBackend: Send + Sync { /// Get block header. Returns `None` if block is not found. fn header(&self, id: BlockId) -> Result>; /// Get blockchain info. - fn info(&self) -> Result>; + fn info(&self) -> Info; /// Get block status. fn status(&self, id: BlockId) -> Result; /// Get block number by hash. Returns `None` if the header is not in the chain. @@ -81,7 +81,7 @@ pub trait Backend: HeaderBackend { /// Get last finalized block hash. fn last_finalized(&self) -> Result; /// Returns data cache reference, if it is enabled on this backend. - fn cache(&self) -> Option>>; + fn cache(&self) -> Option>>; /// Returns hashes of all blocks that are leaves of the block tree. /// in other words, that have no children, are chain heads. @@ -95,7 +95,7 @@ pub trait Backend: HeaderBackend { /// Provides access to the optional cache. pub trait ProvideCache { /// Returns data cache reference, if it is enabled on this backend. - fn cache(&self) -> Option>>; + fn cache(&self) -> Option>>; } /// Blockchain optional data cache. diff --git a/core/client/src/call_executor.rs b/core/client/src/call_executor.rs index 9a47d1ac21497920dc0f55caf3b57b2053db0a7d..f956f27b5058b813452a00e448599da946be27f9 100644 --- a/core/client/src/call_executor.rs +++ b/core/client/src/call_executor.rs @@ -26,9 +26,7 @@ use state_machine::{ use executor::{RuntimeVersion, RuntimeInfo, NativeVersion}; use hash_db::Hasher; use trie::MemoryDB; -use primitives::{ - H256, Blake2Hasher, NativeOrEncoded, NeverNativeValue, OffchainExt -}; +use primitives::{offchain, H256, Blake2Hasher, NativeOrEncoded, NeverNativeValue}; use crate::runtime_api::{ProofRecorder, InitializeBlock}; use crate::backend; @@ -48,7 +46,7 @@ where /// /// No changes are made. fn call< - O: OffchainExt, + O: offchain::Externalities, >( &self, id: &BlockId, @@ -65,7 +63,7 @@ where /// of the execution context. fn contextual_call< 'a, - O: OffchainExt, + O: offchain::Externalities, IB: Fn() -> error::Result<()>, EM: Fn( Result, Self::Error>, @@ -96,7 +94,7 @@ where /// /// No changes are made. fn call_at_state< - O: OffchainExt, + O: offchain::Externalities, S: state_machine::Backend, F: FnOnce( Result, Self::Error>, @@ -119,17 +117,17 @@ where /// No changes are made. fn prove_at_state>( &self, - state: S, + mut state: S, overlay: &mut OverlayedChanges, method: &str, call_data: &[u8] ) -> Result<(Vec, Vec>), error::Error> { - let trie_state = state.try_into_trie_backend() + let trie_state = state.as_trie_backend() .ok_or_else(|| Box::new(state_machine::ExecutionError::UnableToGenerateProof) - as Box + as Box )?; - self.prove_at_trie_state(&trie_state, overlay, method, call_data) + self.prove_at_trie_state(trie_state, overlay, method, call_data) } /// Execute a call to a contract on top of given trie state, gathering execution proof. @@ -181,7 +179,7 @@ where { type Error = E::Error; - fn call( + fn call( &self, id: &BlockId, method: &str, @@ -211,7 +209,7 @@ where fn contextual_call< 'a, - O: OffchainExt, + O: offchain::Externalities, IB: Fn() -> error::Result<()>, EM: Fn( Result, Self::Error>, @@ -241,18 +239,18 @@ where _ => {}, } - let state = self.backend.state_at(*at)?; + let mut state = self.backend.state_at(*at)?; match recorder { Some(recorder) => { - let trie_state = state.try_into_trie_backend() + let trie_state = state.as_trie_backend() .ok_or_else(|| Box::new(state_machine::ExecutionError::UnableToGenerateProof) - as Box + as Box )?; let backend = state_machine::ProvingBackend::new_with_recorder( - &trie_state, + trie_state, recorder.clone() ); @@ -300,7 +298,7 @@ where } fn call_at_state< - O: OffchainExt, + O: offchain::Externalities, S: state_machine::Backend, F: FnOnce( Result, Self::Error>, diff --git a/core/client/src/children.rs b/core/client/src/children.rs index 3a9f0a6bea5b43c9242e9e6a7d9a60b682c74693..4423ad8939467e911382a7d286387e4f9bcf683f 100644 --- a/core/client/src/children.rs +++ b/core/client/src/children.rs @@ -26,7 +26,7 @@ use std::hash::Hash; pub fn read_children< K: Eq + Hash + Clone + Encode + Decode, V: Eq + Hash + Clone + Encode + Decode, ->(db: &KeyValueDB, column: Option, prefix: &[u8], parent_hash: K) -> error::Result> { +>(db: &dyn KeyValueDB, column: Option, prefix: &[u8], parent_hash: K) -> error::Result> { let mut buf = prefix.to_vec(); parent_hash.using_encoded(|s| buf.extend(s)); @@ -116,6 +116,6 @@ mod tests { let r2: Vec = read_children(&db, None, PREFIX, 1_2).unwrap(); assert_eq!(r1, vec![1_3, 1_5]); - assert_eq!(r2.len(), 0); + assert_eq!(r2.len(), 0); } } diff --git a/core/client/src/cht.rs b/core/client/src/cht.rs index 8002f52b6f6d47b60e171d1f234d945c624c1d60..fc8920327e90b64b58542ca62161f4f9af2b5c77 100644 --- a/core/client/src/cht.rs +++ b/core/client/src/cht.rs @@ -26,10 +26,11 @@ use std::collections::HashSet; use hash_db; +use parity_codec::Encode; use trie; use primitives::{H256, convert_hash}; -use runtime_primitives::traits::{As, Header as HeaderT, SimpleArithmetic, One}; +use runtime_primitives::traits::{Header as HeaderT, SimpleArithmetic, Zero, One}; use state_machine::backend::InMemory as InMemoryState; use state_machine::{MemoryDB, TrieBackend, Backend as StateBackend, prove_read_on_trie_backend, read_proof_check, read_proof_check_on_proving_backend}; @@ -38,14 +39,19 @@ use crate::error::{Error as ClientError, Result as ClientResult}; /// The size of each CHT. This value is passed to every CHT-related function from /// production code. Other values are passed from tests. -pub const SIZE: u64 = 2048; +const SIZE: u32 = 2048; + +/// Gets default CHT size. +pub fn size>() -> N { + SIZE.into() +} /// Returns Some(cht_number) if CHT is need to be built when the block with given number is canonized. -pub fn is_build_required(cht_size: u64, block_num: N) -> Option +pub fn is_build_required(cht_size: N, block_num: N) -> Option where N: Clone + SimpleArithmetic, { - let block_cht_num = block_to_cht_number(cht_size, block_num.clone())?; + let block_cht_num = block_to_cht_number(cht_size.clone(), block_num.clone())?; let two = N::one() + N::one(); if block_cht_num < two { return None; @@ -62,7 +68,7 @@ pub fn is_build_required(cht_size: u64, block_num: N) -> Option /// SIZE items. The items are assumed to proceed sequentially from `start_number(cht_num)`. /// Discards the trie's nodes. pub fn compute_root( - cht_size: u64, + cht_size: Header::Number, cht_num: Header::Number, hashes: I, ) -> ClientResult @@ -79,7 +85,7 @@ pub fn compute_root( /// Build CHT-based header proof. pub fn build_proof( - cht_size: u64, + cht_size: Header::Number, cht_num: Header::Number, blocks: BlocksI, hashes: HashesI @@ -95,14 +101,14 @@ pub fn build_proof( .into_iter() .map(|(k, v)| (None, k, Some(v))) .collect::>(); - let storage = InMemoryState::::default().update(transaction); - let trie_storage = storage.try_into_trie_backend() - .expect("InMemoryState::try_into_trie_backend always returns Some; qed"); + let mut storage = InMemoryState::::default().update(transaction); + let trie_storage = storage.as_trie_backend() + .expect("InMemoryState::as_trie_backend always returns Some; qed"); let mut total_proof = HashSet::new(); for block in blocks.into_iter() { debug_assert_eq!(block_to_cht_number(cht_size, block), Some(cht_num)); - let (value, proof) = prove_read_on_trie_backend(&trie_storage, &encode_cht_key(block))?; + let (value, proof) = prove_read_on_trie_backend(trie_storage, &encode_cht_key(block))?; assert!(value.is_some(), "we have just built trie that includes the value for block"); total_proof.extend(proof); } @@ -170,7 +176,7 @@ fn do_check_proof( /// Group ordered blocks by CHT number and call functor with blocks of each group. pub fn for_each_cht_group( - cht_size: u64, + cht_size: Header::Number, blocks: I, mut functor: F, mut functor_param: P, @@ -183,7 +189,7 @@ pub fn for_each_cht_group( let mut current_cht_num = None; let mut current_cht_blocks = Vec::new(); for block in blocks { - let new_cht_num = match block_to_cht_number(cht_size, block.as_()) { + let new_cht_num = match block_to_cht_number(cht_size, block) { Some(new_cht_num) => new_cht_num, None => return Err(ClientError::Backend(format!( "Cannot compute CHT root for the block #{}", block)).into() @@ -198,7 +204,7 @@ pub fn for_each_cht_group( functor_param = functor( functor_param, - As::sa(current_cht_num), + current_cht_num, ::std::mem::replace(&mut current_cht_blocks, Vec::new()), )?; } @@ -210,7 +216,7 @@ pub fn for_each_cht_group( if let Some(current_cht_num) = current_cht_num { functor( functor_param, - As::sa(current_cht_num), + current_cht_num, ::std::mem::replace(&mut current_cht_blocks, Vec::new()), )?; } @@ -220,7 +226,7 @@ pub fn for_each_cht_group( /// Build pairs for computing CHT. fn build_pairs( - cht_size: u64, + cht_size: Header::Number, cht_num: Header::Number, hashes: I ) -> ClientResult, Vec)>> @@ -230,22 +236,25 @@ fn build_pairs( { let start_num = start_number(cht_size, cht_num); let mut pairs = Vec::new(); - let mut hash_number = start_num; - for hash in hashes.into_iter().take(cht_size as usize) { + let mut hash_index = Header::Number::zero(); + for hash in hashes.into_iter() { let hash = hash?.ok_or_else(|| ClientError::from( - ClientError::MissingHashRequiredForCHT(cht_num.as_(), hash_number.as_()) + ClientError::MissingHashRequiredForCHT ))?; pairs.push(( - encode_cht_key(hash_number).to_vec(), + encode_cht_key(start_num + hash_index).to_vec(), encode_cht_value(hash) )); - hash_number += Header::Number::one(); + hash_index += Header::Number::one(); + if hash_index == cht_size { + break; + } } - if pairs.len() as u64 == cht_size { + if hash_index == cht_size { Ok(pairs) } else { - Err(ClientError::MissingHashRequiredForCHT(cht_num.as_(), hash_number.as_())) + Err(ClientError::MissingHashRequiredForCHT) } } @@ -255,38 +264,28 @@ fn build_pairs( /// More generally: CHT N includes block (1 + N*SIZE)...((N+1)*SIZE). /// This is because the genesis hash is assumed to be known /// and including it would be redundant. -pub fn start_number(cht_size: u64, cht_num: N) -> N { - (cht_num * As::sa(cht_size)) + N::one() +pub fn start_number(cht_size: N, cht_num: N) -> N { + (cht_num * cht_size) + N::one() } /// Get the ending block of a given CHT. -pub fn end_number(cht_size: u64, cht_num: N) -> N { - (cht_num + N::one()) * As::sa(cht_size) +pub fn end_number(cht_size: N, cht_num: N) -> N { + (cht_num + N::one()) * cht_size } /// Convert a block number to a CHT number. /// Returns `None` for `block_num` == 0, `Some` otherwise. -pub fn block_to_cht_number(cht_size: u64, block_num: N) -> Option { +pub fn block_to_cht_number(cht_size: N, block_num: N) -> Option { if block_num == N::zero() { None } else { - Some((block_num - N::one()) / As::sa(cht_size)) + Some((block_num - N::one()) / cht_size) } } /// Convert header number into CHT key. -pub fn encode_cht_key>(number: N) -> Vec { - let number: u64 = number.as_(); - vec![ - (number >> 56) as u8, - ((number >> 48) & 0xff) as u8, - ((number >> 40) & 0xff) as u8, - ((number >> 32) & 0xff) as u8, - ((number >> 24) & 0xff) as u8, - ((number >> 16) & 0xff) as u8, - ((number >> 8) & 0xff) as u8, - (number & 0xff) as u8 - ] +pub fn encode_cht_key(number: N) -> Vec { + number.encode() } /// Convert header hash into CHT value. @@ -311,8 +310,8 @@ mod tests { #[test] fn is_build_required_works() { - assert_eq!(is_build_required(SIZE, 0u64), None); - assert_eq!(is_build_required(SIZE, 1u64), None); + assert_eq!(is_build_required(SIZE, 0u32.into()), None); + assert_eq!(is_build_required(SIZE, 1u32.into()), None); assert_eq!(is_build_required(SIZE, SIZE), None); assert_eq!(is_build_required(SIZE, SIZE + 1), None); assert_eq!(is_build_required(SIZE, 2 * SIZE), None); @@ -323,73 +322,101 @@ mod tests { #[test] fn start_number_works() { - assert_eq!(start_number(SIZE, 0u64), 1u64); - assert_eq!(start_number(SIZE, 1u64), SIZE + 1); - assert_eq!(start_number(SIZE, 2u64), SIZE + SIZE + 1); + assert_eq!(start_number(SIZE, 0u32), 1u32); + assert_eq!(start_number(SIZE, 1u32), SIZE + 1); + assert_eq!(start_number(SIZE, 2u32), SIZE + SIZE + 1); } #[test] fn end_number_works() { - assert_eq!(end_number(SIZE, 0u64), SIZE); - assert_eq!(end_number(SIZE, 1u64), SIZE + SIZE); - assert_eq!(end_number(SIZE, 2u64), SIZE + SIZE + SIZE); + assert_eq!(end_number(SIZE, 0u32), SIZE); + assert_eq!(end_number(SIZE, 1u32), SIZE + SIZE); + assert_eq!(end_number(SIZE, 2u32), SIZE + SIZE + SIZE); } #[test] fn build_pairs_fails_when_no_enough_blocks() { - assert!(build_pairs::(SIZE, 0, + assert!(build_pairs::(SIZE as _, 0, ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize / 2)).is_err()); } #[test] fn build_pairs_fails_when_missing_block() { - assert!(build_pairs::(SIZE, 0, ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize / 2) - .chain(::std::iter::once(Ok(None))) - .chain(::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(2)))).take(SIZE as usize / 2 - 1))).is_err()); + assert!(build_pairs::( + SIZE as _, + 0, + ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))) + .take(SIZE as usize / 2) + .chain(::std::iter::once(Ok(None))) + .chain(::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(2)))) + .take(SIZE as usize / 2 - 1)) + ).is_err()); } #[test] fn compute_root_works() { - assert!(compute_root::(SIZE, 42, - ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize)).is_ok()); + assert!(compute_root::( + SIZE as _, + 42, + ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))) + .take(SIZE as usize) + ).is_ok()); } #[test] #[should_panic] fn build_proof_panics_when_querying_wrong_block() { assert!(build_proof::( - SIZE, 0, vec![(SIZE * 1000) as u64], - ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize)).is_err()); + SIZE as _, + 0, + vec![(SIZE * 1000) as u64], + ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))) + .take(SIZE as usize) + ).is_err()); } #[test] fn build_proof_works() { assert!(build_proof::( - SIZE, 0, vec![(SIZE / 2) as u64], - ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))).take(SIZE as usize)).is_ok()); + SIZE as _, + 0, + vec![(SIZE / 2) as u64], + ::std::iter::repeat_with(|| Ok(Some(H256::from_low_u64_be(1)))) + .take(SIZE as usize) + ).is_ok()); } #[test] #[should_panic] fn for_each_cht_group_panics() { - let _ = for_each_cht_group::(SIZE, vec![SIZE * 5, SIZE * 2], |_, _, _| Ok(()), ()); + let cht_size = SIZE as u64; + let _ = for_each_cht_group::( + cht_size, + vec![cht_size * 5, cht_size * 2], + |_, _, _| Ok(()), + (), + ); } #[test] fn for_each_cht_group_works() { - let _ = for_each_cht_group::(SIZE, vec![ - SIZE * 2 + 1, SIZE * 2 + 2, SIZE * 2 + 5, - SIZE * 4 + 1, SIZE * 4 + 7, - SIZE * 6 + 1 - ], |_, cht_num, blocks| { - match cht_num { - 2 => assert_eq!(blocks, vec![SIZE * 2 + 1, SIZE * 2 + 2, SIZE * 2 + 5]), - 4 => assert_eq!(blocks, vec![SIZE * 4 + 1, SIZE * 4 + 7]), - 6 => assert_eq!(blocks, vec![SIZE * 6 + 1]), - _ => unreachable!(), - } - - Ok(()) - }, ()); + let cht_size = SIZE as u64; + let _ = for_each_cht_group::( + cht_size, + vec![ + cht_size * 2 + 1, cht_size * 2 + 2, cht_size * 2 + 5, + cht_size * 4 + 1, cht_size * 4 + 7, + cht_size * 6 + 1 + ], |_, cht_num, blocks| { + match cht_num { + 2 => assert_eq!(blocks, vec![cht_size * 2 + 1, cht_size * 2 + 2, cht_size * 2 + 5]), + 4 => assert_eq!(blocks, vec![cht_size * 4 + 1, cht_size * 4 + 7]), + 6 => assert_eq!(blocks, vec![cht_size * 6 + 1]), + _ => unreachable!(), + } + + Ok(()) + }, () + ); } } diff --git a/core/client/src/client.rs b/core/client/src/client.rs index 4091e23b5f01c9c876d295751d1217ad1171f9aa..8336a90ca46b8d8d640c11c9a720ea203edfcce4 100644 --- a/core/client/src/client.rs +++ b/core/client/src/client.rs @@ -29,14 +29,15 @@ use runtime_primitives::{ generic::{BlockId, SignedBlock}, }; use consensus::{ - Error as ConsensusError, ErrorKind as ConsensusErrorKind, ImportBlock, + Error as ConsensusError, ImportBlock, ImportResult, BlockOrigin, ForkChoiceStrategy, well_known_cache_keys::Id as CacheKeyId, SelectChain, self, }; use runtime_primitives::traits::{ - Block as BlockT, Header as HeaderT, Zero, As, NumberFor, CurrentHeight, - BlockNumberToHash, ApiRef, ProvideRuntimeApi, Digest, DigestItem + Block as BlockT, Header as HeaderT, Zero, NumberFor, CurrentHeight, + BlockNumberToHash, ApiRef, ProvideRuntimeApi, Digest, DigestItem, + SaturatedConversion, One, DigestFor, }; use runtime_primitives::BuildStorage; use crate::runtime_api::{ @@ -82,7 +83,11 @@ pub type ImportNotifications = mpsc::UnboundedReceiver = mpsc::UnboundedReceiver>; -type StorageUpdate = <<>::BlockImportOperation as BlockImportOperation>::State as state_machine::Backend>::Transaction; +type StorageUpdate = < + < + >::BlockImportOperation + as BlockImportOperation + >::State as state_machine::Backend>::Transaction; type ChangesUpdate = trie::MemoryDB; /// Execution strategies settings. @@ -119,7 +124,6 @@ pub struct Client where Block: BlockT { storage_notifications: Mutex>, import_notification_sinks: Mutex>>>, finality_notification_sinks: Mutex>>>, - import_lock: Arc>, // holds the block hash currently being imported. TODO: replace this with block queue importing_block: RwLock>, execution_strategies: ExecutionStrategies, @@ -146,13 +150,17 @@ pub trait BlockchainEvents { /// Get storage changes event stream. /// /// Passing `None` as `filter_keys` subscribes to all storage changes. - fn storage_changes_notification_stream(&self, filter_keys: Option<&[StorageKey]>) -> error::Result>; + fn storage_changes_notification_stream(&self, + filter_keys: Option<&[StorageKey]> + ) -> error::Result>; } /// Fetch block body by ID. pub trait BlockBody { /// Get block body by ID. Returns `None` if the body is not stored. - fn block_body(&self, id: &BlockId) -> error::Result::Extrinsic>>>; + fn block_body(&self, + id: &BlockId + ) -> error::Result::Extrinsic>>>; } /// Client info @@ -160,10 +168,6 @@ pub trait BlockBody { pub struct ClientInfo { /// Best block hash. pub chain: ChainInfo, - /// Best block number in the queue. - pub best_queued_number: Option<<::Header as HeaderT>::Number>, - /// Best queued block hash. - pub best_queued_hash: Option, } /// Block status. @@ -242,11 +246,15 @@ impl PrePostHeader { pub fn new_in_mem( executor: E, genesis_storage: S, -) -> error::Result, LocalCallExecutor, E>, Block, RA>> - where - E: CodeExecutor + RuntimeInfo, - S: BuildStorage, - Block: BlockT, +) -> error::Result, + LocalCallExecutor, E>, + Block, + RA +>> where + E: CodeExecutor + RuntimeInfo, + S: BuildStorage, + Block: BlockT, { new_with_backend(Arc::new(in_mem::Backend::new()), executor, genesis_storage) } @@ -286,7 +294,10 @@ impl Client where backend.begin_state_operation(&mut op, BlockId::Hash(Default::default()))?; let state_root = op.reset_storage(genesis_storage, children_genesis_storage)?; let genesis_block = genesis::construct_genesis_block::(state_root.into()); - info!("Initializing Genesis block/state (state: {}, header-hash: {})", genesis_block.header().state_root(), genesis_block.header().hash()); + info!("Initializing Genesis block/state (state: {}, header-hash: {})", + genesis_block.header().state_root(), + genesis_block.header().hash() + ); op.set_block_data( genesis_block.deconstruct().0, Some(vec![]), @@ -302,7 +313,6 @@ impl Client where storage_notifications: Default::default(), import_notification_sinks: Default::default(), finality_notification_sinks: Default::default(), - import_lock: Default::default(), importing_block: Default::default(), execution_strategies, _phantom: Default::default(), @@ -328,32 +338,51 @@ impl Client where &self.backend } - /// Expose reference to import lock - #[doc(hidden)] - #[deprecated(note="Rather than relying on `client` to provide this, access \ - to the backend should be handled at setup only - see #1134. This function \ - will be removed once that is in place.")] - pub fn import_lock(&self) -> Arc> { - self.import_lock.clone() - } - - /// Return storage entry keys in state in a block of given hash with given prefix. + /// Given a `BlockId` and a key prefix, return the matching child storage keys in that block. pub fn storage_keys(&self, id: &BlockId, key_prefix: &StorageKey) -> error::Result> { let keys = self.state_at(id)?.keys(&key_prefix.0).into_iter().map(StorageKey).collect(); Ok(keys) } - /// Return single storage entry of contract under given address in state in a block of given hash. + /// Given a `BlockId` and a key, return the value under the key in that block. pub fn storage(&self, id: &BlockId, key: &StorageKey) -> error::Result> { Ok(self.state_at(id)? .storage(&key.0).map_err(|e| error::Error::from_state(Box::new(e)))? .map(StorageData)) } + /// Given a `BlockId`, a key prefix, and a child storage key, return the matching child storage keys. + pub fn child_storage_keys( + &self, + id: &BlockId, + child_storage_key: &StorageKey, + key_prefix: &StorageKey + ) -> error::Result> { + let keys = self.state_at(id)? + .child_keys(&child_storage_key.0, &key_prefix.0) + .into_iter() + .map(StorageKey) + .collect(); + Ok(keys) + } + + /// Given a `BlockId`, a key and a child storage key, return the value under the key in that block. + pub fn child_storage( + &self, + id: &BlockId, + child_storage_key: &StorageKey, + key: &StorageKey + ) -> error::Result> { + Ok(self.state_at(id)? + .child_storage(&child_storage_key.0, &key.0).map_err(|e| error::Error::from_state(Box::new(e)))? + .map(StorageData)) + } + /// Get the code at a given block. pub fn code_at(&self, id: &BlockId) -> error::Result> { Ok(self.storage(id, &StorageKey(well_known_keys::CODE.to_vec()))? - .expect("None is returned if there's no value stored for the given key; ':code' key is always defined; qed").0) + .expect("None is returned if there's no value stored for the given key;\ + ':code' key is always defined; qed").0) } /// Get the RuntimeVersion at a given block. @@ -392,7 +421,11 @@ impl Client where /// AND returning execution proof. /// /// No changes are made. - pub fn execution_proof(&self, id: &BlockId, method: &str, call_data: &[u8]) -> error::Result<(Vec, Vec>)> { + pub fn execution_proof(&self, + id: &BlockId, + method: &str, + call_data: &[u8] + ) -> error::Result<(Vec, Vec>)> { let state = self.state_at(id)?; let header = self.prepare_environment_block(id)?; prove_execution(state, header, &self.executor, method, call_data) @@ -400,22 +433,34 @@ impl Client where /// Reads given header and generates CHT-based header proof. pub fn header_proof(&self, id: &BlockId) -> error::Result<(Block::Header, Vec>)> { - self.header_proof_with_cht_size(id, cht::SIZE) + self.header_proof_with_cht_size(id, cht::size()) } /// Get block hash by number. - pub fn block_hash(&self, block_number: <::Header as HeaderT>::Number) -> error::Result> { + pub fn block_hash(&self, + block_number: <::Header as HeaderT>::Number + ) -> error::Result> { self.backend.blockchain().hash(block_number) } /// Reads given header and generates CHT-based header proof for CHT of given size. - pub fn header_proof_with_cht_size(&self, id: &BlockId, cht_size: u64) -> error::Result<(Block::Header, Vec>)> { + pub fn header_proof_with_cht_size( + &self, + id: &BlockId, + cht_size: NumberFor, + ) -> error::Result<(Block::Header, Vec>)> { let proof_error = || error::Error::Backend(format!("Failed to generate header proof for {:?}", id)); let header = self.backend.blockchain().expect_header(*id)?; let block_num = *header.number(); let cht_num = cht::block_to_cht_number(cht_size, block_num).ok_or_else(proof_error)?; let cht_start = cht::start_number(cht_size, cht_num); - let headers = (cht_start.as_()..).map(|num| self.block_hash(As::sa(num))); + let mut current_num = cht_start; + let cht_range = ::std::iter::from_fn(|| { + let old_current_num = current_num; + current_num = current_num + One::one(); + Some(old_current_num) + }); + let headers = cht_range.map(|num| self.block_hash(num)); let proof = cht::build_proof::(cht_size, cht_num, ::std::iter::once(block_num), headers)?; Ok((header, proof)) } @@ -433,14 +478,13 @@ impl Client where Some((config, storage)) => (config, storage), None => return Ok(None), }; - let first = first.as_(); - let last_num = self.backend.blockchain().expect_block_number_from_id(&last)?.as_(); + let last_num = self.backend.blockchain().expect_block_number_from_id(&last)?; if first > last_num { return Err(error::Error::ChangesTrieAccessFailed("Invalid changes trie range".into())); } - let finalized_number = self.backend.blockchain().info()?.finalized_number; - let oldest = storage.oldest_changes_trie_block(&config, finalized_number.as_()); - let first = As::sa(::std::cmp::max(first, oldest)); + let finalized_number = self.backend.blockchain().info().finalized_number; + let oldest = storage.oldest_changes_trie_block(&config, finalized_number); + let first = ::std::cmp::max(first, oldest); Ok(Some((first, last))) } @@ -453,20 +497,20 @@ impl Client where key: &StorageKey ) -> error::Result, u32)>> { let (config, storage) = self.require_changes_trie()?; - let last_number = self.backend.blockchain().expect_block_number_from_id(&last)?.as_(); + let last_number = self.backend.blockchain().expect_block_number_from_id(&last)?; let last_hash = self.backend.blockchain().expect_block_hash_from_id(&last)?; - key_changes::<_, Blake2Hasher>( + key_changes::<_, Blake2Hasher, _>( &config, &*storage, - first.as_(), + first, &ChangesTrieAnchorBlockId { hash: convert_hash(&last_hash), number: last_number, }, - self.backend.blockchain().info()?.best_number.as_(), + self.backend.blockchain().info().best_number, &key.0) - .and_then(|r| r.map(|r| r.map(|(block, tx)| (As::sa(block), tx))).collect::>()) + .and_then(|r| r.map(|r| r.map(|(block, tx)| (block, tx))).collect::>()) .map_err(|err| error::Error::ChangesTrieAccessFailed(err)) } @@ -490,7 +534,7 @@ impl Client where min, max, key, - cht::SIZE, + cht::size(), ) } @@ -502,21 +546,29 @@ impl Client where min: Block::Hash, max: Block::Hash, key: &StorageKey, - cht_size: u64, + cht_size: NumberFor, ) -> error::Result> { struct AccessedRootsRecorder<'a, Block: BlockT> { - storage: &'a ChangesTrieStorage, - min: u64, + storage: &'a dyn ChangesTrieStorage>, + min: NumberFor, required_roots_proofs: Mutex, H256>>, }; - impl<'a, Block: BlockT> ChangesTrieRootsStorage for AccessedRootsRecorder<'a, Block> { - fn root(&self, anchor: &ChangesTrieAnchorBlockId, block: u64) -> Result, String> { + impl<'a, Block: BlockT> ChangesTrieRootsStorage> for AccessedRootsRecorder<'a, Block> { + fn build_anchor(&self, hash: H256) -> Result>, String> { + self.storage.build_anchor(hash) + } + + fn root( + &self, + anchor: &ChangesTrieAnchorBlockId>, + block: NumberFor, + ) -> Result, String> { let root = self.storage.root(anchor, block)?; if block < self.min { if let Some(ref root) = root { self.required_roots_proofs.lock().insert( - As::sa(block), + block, root.clone() ); } @@ -525,7 +577,7 @@ impl Client where } } - impl<'a, Block: BlockT> ChangesTrieStorage for AccessedRootsRecorder<'a, Block> { + impl<'a, Block: BlockT> ChangesTrieStorage> for AccessedRootsRecorder<'a, Block> { fn get(&self, key: &H256, prefix: &[u8]) -> Result, String> { self.storage.get(key, prefix) } @@ -536,19 +588,21 @@ impl Client where let recording_storage = AccessedRootsRecorder:: { storage, - min: min_number.as_(), + min: min_number, required_roots_proofs: Mutex::new(BTreeMap::new()), }; let max_number = ::std::cmp::min( - self.backend.blockchain().info()?.best_number, + self.backend.blockchain().info().best_number, self.backend.blockchain().expect_block_number_from_id(&BlockId::Hash(max))?, ); // fetch key changes proof - let first_number = self.backend.blockchain().expect_block_number_from_id(&BlockId::Hash(first))?.as_(); - let last_number = self.backend.blockchain().expect_block_number_from_id(&BlockId::Hash(last))?.as_(); - let key_changes_proof = key_changes_proof::<_, Blake2Hasher>( + let first_number = self.backend.blockchain() + .expect_block_number_from_id(&BlockId::Hash(first))?; + let last_number = self.backend.blockchain() + .expect_block_number_from_id(&BlockId::Hash(last))?; + let key_changes_proof = key_changes_proof::<_, Blake2Hasher, _>( &config, &recording_storage, first_number, @@ -556,7 +610,7 @@ impl Client where hash: convert_hash(&last), number: last_number, }, - max_number.as_(), + max_number, &key.0 ) .map_err(|err| error::Error::from(error::Error::ChangesTrieAccessFailed(err)))?; @@ -577,7 +631,7 @@ impl Client where /// Generate CHT-based proof for roots of changes tries at given blocks. fn changes_trie_roots_proof>>( &self, - cht_size: u64, + cht_size: NumberFor, blocks: I ) -> error::Result>> { // most probably we have touched several changes tries that are parts of the single CHT @@ -596,12 +650,19 @@ impl Client where /// Generates CHT-based proof for roots of changes tries at given blocks (that are part of single CHT). fn changes_trie_roots_proof_at_cht( &self, - cht_size: u64, + cht_size: NumberFor, cht_num: NumberFor, blocks: Vec> ) -> error::Result>> { let cht_start = cht::start_number(cht_size, cht_num); - let roots = (cht_start.as_()..).map(|num| self.header(&BlockId::Number(As::sa(num))) + let mut current_num = cht_start; + let cht_range = ::std::iter::from_fn(|| { + let old_current_num = current_num; + current_num = current_num + One::one(); + Some(old_current_num) + }); + let roots = cht_range + .map(|num| self.header(&BlockId::Number(num)) .map(|block| block.and_then(|block| block.digest().log(DigestItem::as_changes_trie_root).cloned()))); let proof = cht::build_proof::(cht_size, cht_num, blocks, roots)?; Ok(proof) @@ -619,26 +680,29 @@ impl Client where /// Create a new block, built on the head of the chain. pub fn new_block( - &self + &self, + inherent_digests: DigestFor, ) -> error::Result> where E: Clone + Send + Sync, RA: Send + Sync, Self: ProvideRuntimeApi, ::Api: BlockBuilderAPI { - block_builder::BlockBuilder::new(self) + block_builder::BlockBuilder::new(self, inherent_digests) } /// Create a new block, built on top of `parent`. pub fn new_block_at( - &self, parent: &BlockId + &self, + parent: &BlockId, + inherent_digests: DigestFor, ) -> error::Result> where E: Clone + Send + Sync, RA: Send + Sync, Self: ProvideRuntimeApi, ::Api: BlockBuilderAPI { - block_builder::BlockBuilder::at_block(parent, &self, false) + block_builder::BlockBuilder::at_block(parent, &self, false, inherent_digests) } /// Create a new block, built on top of `parent` with proof recording enabled. @@ -647,14 +711,16 @@ impl Client where /// These recorded trie nodes can be used by a third party to proof the /// output of this block builder without having access to the full storage. pub fn new_block_at_with_proof_recording( - &self, parent: &BlockId + &self, + parent: &BlockId, + inherent_digests: DigestFor, ) -> error::Result> where E: Clone + Send + Sync, RA: Send + Sync, Self: ProvideRuntimeApi, ::Api: BlockBuilderAPI { - block_builder::BlockBuilder::at_block(parent, &self, true) + block_builder::BlockBuilder::at_block(parent, &self, true, inherent_digests) } /// Lock the import lock, and run operations inside. @@ -663,7 +729,7 @@ impl Client where Err: From, { let inner = || { - let _import_lock = self.import_lock.lock(); + let _import_lock = self.backend.get_import_lock().lock(); let mut op = ClientImportOperation { op: self.backend.begin_operation()?, @@ -750,7 +816,7 @@ impl Client where }; let hash = import_headers.post().hash(); - let height: u64 = import_headers.post().number().as_(); + let height = (*import_headers.post().number()).saturated_into::(); *self.importing_block.write() = Some(hash); @@ -798,7 +864,7 @@ impl Client where } let (last_best, last_best_number) = { - let info = self.backend.blockchain().info()?; + let info = self.backend.blockchain().info(); (info.best_hash, info.best_number) }; @@ -1071,7 +1137,7 @@ impl Client where justification: Option, notify: bool, ) -> error::Result<()> { - let last_best = self.backend.blockchain().info()?.best_hash; + let last_best = self.backend.blockchain().info().best_hash; let to_finalize_hash = self.backend.blockchain().expect_block_hash_from_id(&id)?; self.apply_finality_with_block_hash(operation, to_finalize_hash, justification, last_best, notify) } @@ -1084,7 +1150,7 @@ impl Client where /// while performing major synchronization work. pub fn finalize_block(&self, id: BlockId, justification: Option, notify: bool) -> error::Result<()> { self.lock_import_and_run(|operation| { - let last_best = self.backend.blockchain().info()?.best_hash; + let last_best = self.backend.blockchain().info().best_hash; let to_finalize_hash = self.backend.blockchain().expect_block_hash_from_id(&id)?; self.apply_finality_with_block_hash(operation, to_finalize_hash, justification, last_best, notify) }) @@ -1097,13 +1163,11 @@ impl Client where } /// Get blockchain info. - pub fn info(&self) -> error::Result> { - let info = self.backend.blockchain().info().map_err(|e| error::Error::from_blockchain(Box::new(e)))?; - Ok(ClientInfo { + pub fn info(&self) -> ClientInfo { + let info = self.backend.blockchain().info(); + ClientInfo { chain: info, - best_queued_hash: None, - best_queued_number: None, - }) + } } /// Get block status. @@ -1165,7 +1229,7 @@ impl Client where } }; - let genesis_hash = self.backend.blockchain().info()?.genesis_hash; + let genesis_hash = self.backend.blockchain().info().genesis_hash; if genesis_hash == target_hash { return Ok(Vec::new()); } let mut current_hash = target_hash; @@ -1174,7 +1238,7 @@ impl Client where let mut ancestor = load_header(ancestor_hash)?; let mut uncles = Vec::new(); - for _generation in 0..max_generation.as_() { + for _generation in 0..max_generation.saturated_into() { let children = self.backend.blockchain().children(ancestor_hash)?; uncles.extend(children.into_iter().filter(|h| h != ¤t_hash)); current_hash = ancestor_hash; @@ -1188,7 +1252,7 @@ impl Client where } fn changes_trie_config(&self) -> Result, Error> { - Ok(self.backend.state_at(BlockId::Number(self.backend.blockchain().info()?.best_number))? + Ok(self.backend.state_at(BlockId::Number(self.backend.blockchain().info().best_number))? .storage(well_known_keys::CHANGES_TRIE_CONFIG) .map_err(|e| error::Error::from_state(Box::new(e)))? .and_then(|c| Decode::decode(&mut &*c))) @@ -1196,11 +1260,12 @@ impl Client where /// Prepare in-memory header that is used in execution environment. fn prepare_environment_block(&self, parent: &BlockId) -> error::Result { + let parent_header = self.backend.blockchain().expect_header(*parent)?; Ok(<::Header as HeaderT>::new( - self.backend.blockchain().expect_block_number_from_id(parent)? + As::sa(1), + self.backend.blockchain().expect_block_number_from_id(parent)? + One::one(), Default::default(), Default::default(), - self.backend.blockchain().expect_block_hash_from_id(&parent)?, + parent_header.hash(), Default::default(), )) } @@ -1216,7 +1281,7 @@ impl ChainHeaderBackend for Client wher self.backend.blockchain().header(id) } - fn info(&self) -> error::Result> { + fn info(&self) -> blockchain::Info { self.backend.blockchain().info() } @@ -1237,7 +1302,7 @@ impl ProvideCache for Client where B: backend::Backend, Block: BlockT, { - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { self.backend.blockchain().cache() } } @@ -1330,7 +1395,7 @@ impl consensus::BlockImport for Client ) -> Result { self.lock_import_and_run(|operation| { self.apply_block(operation, import_block, new_cache) - }).map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()).into()) + }).map_err(|e| ConsensusError::ClientImport(e.to_string()).into()) } /// Check block preconditions. @@ -1340,7 +1405,7 @@ impl consensus::BlockImport for Client parent_hash: Block::Hash, ) -> Result { match self.block_status(&BlockId::Hash(parent_hash)) - .map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))? + .map_err(|e| ConsensusError::ClientImport(e.to_string()))? { BlockStatus::InChainWithState | BlockStatus::Queued => {}, BlockStatus::Unknown | BlockStatus::InChainPruned => return Ok(ImportResult::UnknownParent), @@ -1348,7 +1413,7 @@ impl consensus::BlockImport for Client } match self.block_status(&BlockId::Hash(hash)) - .map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))? + .map_err(|e| ConsensusError::ClientImport(e.to_string()))? { BlockStatus::InChainWithState | BlockStatus::Queued => return Ok(ImportResult::AlreadyInChain), BlockStatus::Unknown | BlockStatus::InChainPruned => {}, @@ -1366,7 +1431,7 @@ impl CurrentHeight for Client where { type BlockNumber = ::Number; fn current_height(&self) -> Self::BlockNumber { - self.backend.blockchain().info().map(|i| i.best_number).unwrap_or_else(|_| Zero::zero()) + self.backend.blockchain().info().best_number } } @@ -1411,17 +1476,14 @@ where /// where 'longest' is defined as the highest number of blocks pub struct LongestChain { backend: Arc, - import_lock: Arc>, _phantom: PhantomData } impl Clone for LongestChain { fn clone(&self) -> Self { let backend = self.backend.clone(); - let import_lock = self.import_lock.clone(); LongestChain { backend, - import_lock, _phantom: Default::default() } } @@ -1433,19 +1495,15 @@ where Block: BlockT, { /// Instantiate a new LongestChain for Backend B - pub fn new(backend: Arc, import_lock: Arc>) -> Self { + pub fn new(backend: Arc) -> Self { LongestChain { backend, - import_lock, _phantom: Default::default() } } fn best_block_header(&self) -> error::Result<::Header> { - let info : ChainInfo = match self.backend.blockchain().info() { - Ok(i) => i, - Err(e) => return Err(error::Error::from_blockchain(Box::new(e))) - }; + let info : ChainInfo = self.backend.blockchain().info(); Ok(self.backend.blockchain().header(BlockId::Hash(info.best_hash))? .expect("Best block header must always exist")) } @@ -1485,9 +1543,9 @@ where // ensure no blocks are imported during this code block. // an import could trigger a reorg which could change the canonical chain. // we depend on the canonical chain staying the same during this code block. - let _import_lock = self.import_lock.lock(); + let _import_lock = self.backend.get_import_lock().lock(); - let info = self.backend.blockchain().info()?; + let info = self.backend.blockchain().info(); let canon_hash = self.backend.blockchain().hash(*target_header.number())? .ok_or_else(|| error::Error::from(format!("failed to get hash for block number {}", target_header.number())))?; @@ -1584,14 +1642,14 @@ where fn leaves(&self) -> Result::Hash>, ConsensusError> { LongestChain::leaves(self) - .map_err(|e| ConsensusErrorKind::ChainLookup(e.to_string()).into()) + .map_err(|e| ConsensusError::ChainLookup(e.to_string()).into()) } fn best_chain(&self) -> Result<::Header, ConsensusError> { LongestChain::best_block_header(&self) - .map_err(|e| ConsensusErrorKind::ChainLookup(e.to_string()).into()) + .map_err(|e| ConsensusError::ChainLookup(e.to_string()).into()) } fn finality_target( @@ -1600,7 +1658,7 @@ where maybe_max_number: Option> ) -> Result, ConsensusError> { LongestChain::best_containing(self, target_hash, maybe_max_number) - .map_err(|e| ConsensusErrorKind::ChainLookup(e.to_string()).into()) + .map_err(|e| ConsensusError::ChainLookup(e.to_string()).into()) } } @@ -1649,11 +1707,12 @@ pub(crate) mod tests { use primitives::blake2_256; use runtime_primitives::traits::DigestItem as DigestItemT; use runtime_primitives::generic::DigestItem; - use test_client::{self, TestClient, AccountKeyring}; use consensus::{BlockOrigin, SelectChain}; - use test_client::client::backend::Backend as TestBackend; - use test_client::BlockBuilderExt; - use test_client::runtime::{self, Block, Transfer, RuntimeApi, TestAPI}; + use test_client::{ + prelude::*, + client::backend::Backend as TestBackend, + runtime::{self, Block, Transfer, RuntimeApi, TestAPI}, + }; /// Returns tuple, consisting of: /// 1) test client pre-filled with blocks changing balances; @@ -1674,10 +1733,10 @@ pub(crate) mod tests { // prepare client ang import blocks let mut local_roots = Vec::new(); - let remote_client = test_client::new_with_changes_trie(); + let remote_client = TestClientBuilder::new().set_support_changes_trie(true).build(); let mut nonces: HashMap<_, u64> = Default::default(); for (i, block_transfers) in blocks_transfers.into_iter().enumerate() { - let mut builder = remote_client.new_block().unwrap(); + let mut builder = remote_client.new_block(Default::default()).unwrap(); for (from, to) in block_transfers { builder.push_transfer(Transfer { from: from.into(), @@ -1734,14 +1793,14 @@ pub(crate) mod tests { assert_eq!( client.runtime_api().balance_of( - &BlockId::Number(client.info().unwrap().chain.best_number), + &BlockId::Number(client.info().chain.best_number), AccountKeyring::Alice.into() ).unwrap(), 1000 ); assert_eq!( client.runtime_api().balance_of( - &BlockId::Number(client.info().unwrap().chain.best_number), + &BlockId::Number(client.info().chain.best_number), AccountKeyring::Ferdie.into() ).unwrap(), 0 @@ -1752,18 +1811,18 @@ pub(crate) mod tests { fn block_builder_works_with_no_transactions() { let client = test_client::new(); - let builder = client.new_block().unwrap(); + let builder = client.new_block(Default::default()).unwrap(); client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap(); - assert_eq!(client.info().unwrap().chain.best_number, 1); + assert_eq!(client.info().chain.best_number, 1); } #[test] fn block_builder_works_with_transactions() { let client = test_client::new(); - let mut builder = client.new_block().unwrap(); + let mut builder = client.new_block(Default::default()).unwrap(); builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1774,18 +1833,21 @@ pub(crate) mod tests { client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap(); - assert_eq!(client.info().unwrap().chain.best_number, 1); - assert!(client.state_at(&BlockId::Number(1)).unwrap().pairs() != client.state_at(&BlockId::Number(0)).unwrap().pairs()); + assert_eq!(client.info().chain.best_number, 1); + assert_ne!( + client.state_at(&BlockId::Number(1)).unwrap().pairs(), + client.state_at(&BlockId::Number(0)).unwrap().pairs() + ); assert_eq!( client.runtime_api().balance_of( - &BlockId::Number(client.info().unwrap().chain.best_number), + &BlockId::Number(client.info().chain.best_number), AccountKeyring::Alice.into() ).unwrap(), 958 ); assert_eq!( client.runtime_api().balance_of( - &BlockId::Number(client.info().unwrap().chain.best_number), + &BlockId::Number(client.info().chain.best_number), AccountKeyring::Ferdie.into() ).unwrap(), 42 @@ -1796,7 +1858,7 @@ pub(crate) mod tests { fn block_builder_does_not_include_invalid() { let client = test_client::new(); - let mut builder = client.new_block().unwrap(); + let mut builder = client.new_block(Default::default()).unwrap(); builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1814,8 +1876,11 @@ pub(crate) mod tests { client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap(); - assert_eq!(client.info().unwrap().chain.best_number, 1); - assert!(client.state_at(&BlockId::Number(1)).unwrap().pairs() != client.state_at(&BlockId::Number(0)).unwrap().pairs()); + assert_eq!(client.info().chain.best_number, 1); + assert_ne!( + client.state_at(&BlockId::Number(1)).unwrap().pairs(), + client.state_at(&BlockId::Number(0)).unwrap().pairs() + ); assert_eq!(client.body(&BlockId::Number(1)).unwrap().unwrap().len(), 1) } @@ -1824,17 +1889,14 @@ pub(crate) mod tests { // block tree: // G - let client = test_client::new(); - - let genesis_hash = client.info().unwrap().chain.genesis_hash; - let longest_chain_select = test_client::client::LongestChain::new( - client.backend().clone(), - client.import_lock() - ); + let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); + let genesis_hash = client.info().chain.genesis_hash; - assert_eq!(genesis_hash.clone(), longest_chain_select.finality_target( - genesis_hash.clone(), None).unwrap().unwrap()); + assert_eq!( + genesis_hash.clone(), + longest_chain_select.finality_target(genesis_hash.clone(), None).unwrap().unwrap() + ); } #[test] @@ -1842,16 +1904,14 @@ pub(crate) mod tests { // block tree: // G - let client = test_client::new(); + let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); - let uninserted_block = client.new_block().unwrap().bake().unwrap(); - let backend = client.backend().as_in_memory(); - let longest_chain_select = test_client::client::LongestChain::new( - Arc::new(backend), - client.import_lock()); + let uninserted_block = client.new_block(Default::default()).unwrap().bake().unwrap(); - assert_eq!(None, longest_chain_select.finality_target( - uninserted_block.hash().clone(), None).unwrap()); + assert_eq!( + None, + longest_chain_select.finality_target(uninserted_block.hash().clone(), None).unwrap() + ); } #[test] @@ -1861,11 +1921,11 @@ pub(crate) mod tests { let client = test_client::new(); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); // A1 -> A2 - let a2 = client.new_block().unwrap().bake().unwrap(); + let a2 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); let v: Vec = Vec::new(); assert_eq!(v, client.uncles(a2.hash(), 3).unwrap()); @@ -1881,27 +1941,27 @@ pub(crate) mod tests { let client = test_client::new(); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); // A1 -> A2 - let a2 = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap().bake().unwrap(); + let a2 = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); // A2 -> A3 - let a3 = client.new_block_at(&BlockId::Hash(a2.hash())).unwrap().bake().unwrap(); + let a3 = client.new_block_at(&BlockId::Hash(a2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a3.clone()).unwrap(); // A3 -> A4 - let a4 = client.new_block_at(&BlockId::Hash(a3.hash())).unwrap().bake().unwrap(); + let a4 = client.new_block_at(&BlockId::Hash(a3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a4.clone()).unwrap(); // A4 -> A5 - let a5 = client.new_block_at(&BlockId::Hash(a4.hash())).unwrap().bake().unwrap(); + let a5 = client.new_block_at(&BlockId::Hash(a4.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a5.clone()).unwrap(); // A1 -> B2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1913,15 +1973,15 @@ pub(crate) mod tests { client.import(BlockOrigin::Own, b2.clone()).unwrap(); // B2 -> B3 - let b3 = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap().bake().unwrap(); + let b3 = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b3.clone()).unwrap(); // B3 -> B4 - let b4 = client.new_block_at(&BlockId::Hash(b3.hash())).unwrap().bake().unwrap(); + let b4 = client.new_block_at(&BlockId::Hash(b3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b4.clone()).unwrap(); // // B2 -> C3 - let mut builder = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1933,7 +1993,7 @@ pub(crate) mod tests { client.import(BlockOrigin::Own, c3.clone()).unwrap(); // A1 -> D2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -1944,7 +2004,7 @@ pub(crate) mod tests { let d2 = builder.bake().unwrap(); client.import(BlockOrigin::Own, d2.clone()).unwrap(); - let genesis_hash = client.info().unwrap().chain.genesis_hash; + let genesis_hash = client.info().chain.genesis_hash; let uncles1 = client.uncles(a4.hash(), 10).unwrap(); assert_eq!(vec![b2.hash(), d2.hash()], uncles1); @@ -1970,28 +2030,21 @@ pub(crate) mod tests { // block tree: // G -> A1 -> A2 - let client = test_client::new(); + let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); // A1 -> A2 - let a2 = client.new_block().unwrap().bake().unwrap(); + let a2 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); - let genesis_hash = client.info().unwrap().chain.genesis_hash; + let genesis_hash = client.info().chain.genesis_hash; - let longest_chain_select = test_client::client::LongestChain::new( - Arc::new(client.backend().as_in_memory()), - client.import_lock()); - - assert_eq!(a2.hash(), longest_chain_select.finality_target( - genesis_hash, None).unwrap().unwrap()); - assert_eq!(a2.hash(), longest_chain_select.finality_target( - a1.hash(), None).unwrap().unwrap()); - assert_eq!(a2.hash(), longest_chain_select.finality_target( - a2.hash(), None).unwrap().unwrap()); + assert_eq!(a2.hash(), longest_chain_select.finality_target(genesis_hash, None).unwrap().unwrap()); + assert_eq!(a2.hash(), longest_chain_select.finality_target(a1.hash(), None).unwrap().unwrap()); + assert_eq!(a2.hash(), longest_chain_select.finality_target(a2.hash(), None).unwrap().unwrap()); } #[test] @@ -2001,30 +2054,30 @@ pub(crate) mod tests { // A1 -> B2 -> B3 -> B4 // B2 -> C3 // A1 -> D2 - let client = test_client::new(); + let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); // A1 -> A2 - let a2 = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap().bake().unwrap(); + let a2 = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); // A2 -> A3 - let a3 = client.new_block_at(&BlockId::Hash(a2.hash())).unwrap().bake().unwrap(); + let a3 = client.new_block_at(&BlockId::Hash(a2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a3.clone()).unwrap(); // A3 -> A4 - let a4 = client.new_block_at(&BlockId::Hash(a3.hash())).unwrap().bake().unwrap(); + let a4 = client.new_block_at(&BlockId::Hash(a3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a4.clone()).unwrap(); // A4 -> A5 - let a5 = client.new_block_at(&BlockId::Hash(a4.hash())).unwrap().bake().unwrap(); + let a5 = client.new_block_at(&BlockId::Hash(a4.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a5.clone()).unwrap(); // A1 -> B2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -2036,15 +2089,15 @@ pub(crate) mod tests { client.import(BlockOrigin::Own, b2.clone()).unwrap(); // B2 -> B3 - let b3 = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap().bake().unwrap(); + let b3 = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b3.clone()).unwrap(); // B3 -> B4 - let b4 = client.new_block_at(&BlockId::Hash(b3.hash())).unwrap().bake().unwrap(); + let b4 = client.new_block_at(&BlockId::Hash(b3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b4.clone()).unwrap(); // // B2 -> C3 - let mut builder = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -2056,7 +2109,7 @@ pub(crate) mod tests { client.import(BlockOrigin::Own, c3.clone()).unwrap(); // A1 -> D2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -2067,13 +2120,9 @@ pub(crate) mod tests { let d2 = builder.bake().unwrap(); client.import(BlockOrigin::Own, d2.clone()).unwrap(); - assert_eq!(client.info().unwrap().chain.best_hash, a5.hash()); - - let genesis_hash = client.info().unwrap().chain.genesis_hash; - let longest_chain_select = test_client::client::LongestChain::new( - Arc::new(client.backend().as_in_memory()), - client.import_lock()); + assert_eq!(client.info().chain.best_hash, a5.hash()); + let genesis_hash = client.info().chain.genesis_hash; let leaves = longest_chain_select.leaves().unwrap(); assert!(leaves.contains(&a5.hash())); @@ -2289,24 +2338,19 @@ pub(crate) mod tests { // block tree: // G -> A1 -> A2 - let client = test_client::new(); + let (client, longest_chain_select) = TestClientBuilder::new().build_with_longest_chain(); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); // A1 -> A2 - let a2 = client.new_block().unwrap().bake().unwrap(); + let a2 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); - let genesis_hash = client.info().unwrap().chain.genesis_hash; - let longest_chain_select = test_client::client::LongestChain::new( - Arc::new(client.backend().as_in_memory()), - client.import_lock() - ); + let genesis_hash = client.info().chain.genesis_hash; - assert_eq!(a2.hash(), longest_chain_select.finality_target( - genesis_hash, Some(10)).unwrap().unwrap()); + assert_eq!(a2.hash(), longest_chain_select.finality_target(genesis_hash, Some(10)).unwrap().unwrap()); } #[test] @@ -2331,35 +2375,38 @@ pub(crate) mod tests { let client = test_client::new(); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); // A1 -> A2 - let a2 = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap().bake().unwrap(); + let a2 = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); // A2 -> A3 let justification = vec![1, 2, 3]; - let a3 = client.new_block_at(&BlockId::Hash(a2.hash())).unwrap().bake().unwrap(); + let a3 = client.new_block_at(&BlockId::Hash(a2.hash()), Default::default()).unwrap().bake().unwrap(); client.import_justified(BlockOrigin::Own, a3.clone(), justification.clone()).unwrap(); + #[allow(deprecated)] + let blockchain = client.backend().blockchain(); + assert_eq!( - client.backend().blockchain().last_finalized().unwrap(), + blockchain.last_finalized().unwrap(), a3.hash(), ); assert_eq!( - client.backend().blockchain().justification(BlockId::Hash(a3.hash())).unwrap(), + blockchain.justification(BlockId::Hash(a3.hash())).unwrap(), Some(justification), ); assert_eq!( - client.backend().blockchain().justification(BlockId::Hash(a1.hash())).unwrap(), + blockchain.justification(BlockId::Hash(a1.hash())).unwrap(), None, ); assert_eq!( - client.backend().blockchain().justification(BlockId::Hash(a2.hash())).unwrap(), + blockchain.justification(BlockId::Hash(a2.hash())).unwrap(), None, ); } diff --git a/core/client/src/error.rs b/core/client/src/error.rs index b201c092e0ed15af4295b1a33f8cc8cc888651d8..b807d5e11cc5dddaff2d3b93b71b4e14855478f8 100644 --- a/core/client/src/error.rs +++ b/core/client/src/error.rs @@ -42,7 +42,7 @@ pub enum Error { ApplyExtrinsicFailed(ApplyError), /// Execution error. #[display(fmt = "Execution: {}", _0)] - Execution(Box), + Execution(Box), /// Blockchain error. #[display(fmt = "Blockchain: {}", _0)] Blockchain(Box), @@ -92,15 +92,15 @@ pub enum Error { #[display(fmt = "Potential long-range attack: block not in finalized chain.")] NotInFinalizedChain, /// Hash that is required for building CHT is missing. - #[display(fmt = "Failed to get hash of block#{} for building CHT#{}", _0, _1)] - MissingHashRequiredForCHT(u64, u64), + #[display(fmt = "Failed to get hash of block for building CHT")] + MissingHashRequiredForCHT, /// A convenience variant for String #[display(fmt = "{}", _0)] Msg(String), } impl error::Error for Error { - fn source(&self) -> Option<&(error::Error + 'static)> { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { match self { Error::Consensus(e) => Some(e), Error::Blockchain(e) => Some(e), @@ -128,7 +128,7 @@ impl Error { } /// Chain a state error. - pub fn from_state(e: Box) -> Self { + pub fn from_state(e: Box) -> Self { Error::Execution(e) } } diff --git a/core/client/src/genesis.rs b/core/client/src/genesis.rs index 74bc74360a2c9517c7344b4f1dfc31c07cc1b870..73bd1e03680bc7649a2d8bf5fd4424fba65472da 100644 --- a/core/client/src/genesis.rs +++ b/core/client/src/genesis.rs @@ -84,7 +84,7 @@ mod tests { state_machine::new( backend, - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::<_, u64>::new()), state_machine::NeverOffchainExt::new(), &mut overlay, &executor(), @@ -97,7 +97,7 @@ mod tests { for tx in transactions.iter() { state_machine::new( backend, - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::<_, u64>::new()), state_machine::NeverOffchainExt::new(), &mut overlay, &executor(), @@ -110,7 +110,7 @@ mod tests { let (ret_data, _, _) = state_machine::new( backend, - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::<_, u64>::new()), state_machine::NeverOffchainExt::new(), &mut overlay, &executor(), @@ -157,7 +157,7 @@ mod tests { let mut overlay = OverlayedChanges::default(); let _ = state_machine::new( &backend, - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::<_, u64>::new()), state_machine::NeverOffchainExt::new(), &mut overlay, &executor(), @@ -186,7 +186,7 @@ mod tests { let mut overlay = OverlayedChanges::default(); let _ = state_machine::new( &backend, - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::<_, u64>::new()), state_machine::NeverOffchainExt::new(), &mut overlay, &executor(), @@ -215,7 +215,7 @@ mod tests { let mut overlay = OverlayedChanges::default(); let r = state_machine::new( &backend, - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::<_, u64>::new()), state_machine::NeverOffchainExt::new(), &mut overlay, &Executor::new(None), diff --git a/core/client/src/in_mem.rs b/core/client/src/in_mem.rs index 0050cb91101c7c6fd37572263108f64b5d1d31ad..dec10d40f79f4cc2d1f905c6c40705a413689a9e 100644 --- a/core/client/src/in_mem.rs +++ b/core/client/src/in_mem.rs @@ -18,11 +18,13 @@ use std::collections::HashMap; use std::sync::Arc; -use parking_lot::RwLock; +use parking_lot::{RwLock, Mutex}; use primitives::{ChangesTrieConfiguration, storage::well_known_keys}; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, - NumberFor, As, Digest, DigestItem}; +use runtime_primitives::traits::{ + Block as BlockT, Header as HeaderT, Zero, + NumberFor, Digest, DigestItem +}; use runtime_primitives::{Justification, StorageOverlay, ChildrenStorageOverlay}; use state_machine::backend::{Backend as StateBackend, InMemory}; use state_machine::{self, InMemoryChangesTrieStorage, ChangesTrieAnchorBlockId}; @@ -295,15 +297,15 @@ impl HeaderBackend for Blockchain { })) } - fn info(&self) -> error::Result> { + fn info(&self) -> blockchain::Info { let storage = self.storage.read(); - Ok(blockchain::Info { + blockchain::Info { best_hash: storage.best_hash, best_number: storage.best_number, genesis_hash: storage.genesis_hash, finalized_hash: storage.finalized_hash, finalized_number: storage.finalized_number, - }) + } } fn status(&self, id: BlockId) -> error::Result { @@ -341,7 +343,7 @@ impl blockchain::Backend for Blockchain { Ok(self.storage.read().finalized_hash.clone()) } - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { None } @@ -355,7 +357,7 @@ impl blockchain::Backend for Blockchain { } impl blockchain::ProvideCache for Blockchain { - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { None } } @@ -413,17 +415,25 @@ impl light::blockchain::Storage for Blockchain Blockchain::finalize_header(self, id, None) } - fn header_cht_root(&self, _cht_size: u64, block: NumberFor) -> error::Result { + fn header_cht_root( + &self, + _cht_size: NumberFor, + block: NumberFor, + ) -> error::Result { self.storage.read().header_cht_roots.get(&block).cloned() .ok_or_else(|| error::Error::Backend(format!("Header CHT for block {} not exists", block))) } - fn changes_trie_cht_root(&self, _cht_size: u64, block: NumberFor) -> error::Result { + fn changes_trie_cht_root( + &self, + _cht_size: NumberFor, + block: NumberFor, + ) -> error::Result { self.storage.read().changes_trie_cht_roots.get(&block).cloned() .ok_or_else(|| error::Error::Backend(format!("Changes trie CHT for block {} not exists", block))) } - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { None } } @@ -529,8 +539,9 @@ where H::Out: Ord, { states: RwLock>>, - changes_trie_storage: ChangesTrieStorage, + changes_trie_storage: ChangesTrieStorage, blockchain: Blockchain, + import_lock: Mutex<()>, } impl Backend @@ -545,6 +556,7 @@ where states: RwLock::new(HashMap::new()), changes_trie_storage: ChangesTrieStorage(InMemoryChangesTrieStorage::new()), blockchain: Blockchain::new(), + import_lock: Default::default(), } } } @@ -579,7 +591,7 @@ where type BlockImportOperation = BlockImportOperation; type Blockchain = Blockchain; type State = InMemory; - type ChangesTrieStorage = ChangesTrieStorage; + type ChangesTrieStorage = ChangesTrieStorage; fn begin_operation(&self) -> error::Result { let old_state = self.state_at(BlockId::Hash(Default::default()))?; @@ -619,7 +631,11 @@ where if let Some(changes_trie_root) = changes_trie_root { if let Some(changes_trie_update) = operation.changes_trie_update { let changes_trie_root: H::Out = changes_trie_root.into(); - self.changes_trie_storage.0.insert(header.number().as_(), changes_trie_root, changes_trie_update); + self.changes_trie_storage.0.insert( + *header.number(), + changes_trie_root, + changes_trie_update + ); } } @@ -668,7 +684,11 @@ where } fn revert(&self, _n: NumberFor) -> error::Result> { - Ok(As::sa(0)) + Ok(Zero::zero()) + } + + fn get_import_lock(&self) -> &Mutex<()> { + &self.import_lock } } @@ -693,22 +713,45 @@ where } /// Prunable in-memory changes trie storage. -pub struct ChangesTrieStorage(InMemoryChangesTrieStorage); -impl backend::PrunableStateChangesTrieStorage for ChangesTrieStorage { - fn oldest_changes_trie_block(&self, _config: &ChangesTrieConfiguration, _best_finalized: u64) -> u64 { - 0 +pub struct ChangesTrieStorage(InMemoryChangesTrieStorage>); +impl backend::PrunableStateChangesTrieStorage for ChangesTrieStorage { + fn oldest_changes_trie_block( + &self, + _config: &ChangesTrieConfiguration, + _best_finalized: NumberFor, + ) -> NumberFor { + Zero::zero() } } -impl state_machine::ChangesTrieRootsStorage for ChangesTrieStorage { - fn root(&self, anchor: &ChangesTrieAnchorBlockId, block: u64) -> Result, String> { - self.0.root(anchor, block) +impl state_machine::ChangesTrieRootsStorage> for ChangesTrieStorage + where + Block: BlockT, + H: Hasher, +{ + fn build_anchor( + &self, + _hash: H::Out, + ) -> Result>, String> { + Err("Dummy implementation".into()) + } + + fn root( + &self, + _anchor: &ChangesTrieAnchorBlockId>, + _block: NumberFor, + ) -> Result, String> { + Err("Dummy implementation".into()) } } -impl state_machine::ChangesTrieStorage for ChangesTrieStorage { - fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String> { - self.0.get(key, prefix) +impl state_machine::ChangesTrieStorage> for ChangesTrieStorage + where + Block: BlockT, + H: Hasher, +{ + fn get(&self, _key: &H::Out, _prefix: &[u8]) -> Result, String> { + Err("Dummy implementation".into()) } } diff --git a/core/client/src/leaves.rs b/core/client/src/leaves.rs index 144237f777ca8b066be3ba03882bc68bee0d8612..b0e49ead80d40e04bf829c8719fd0f40d3d11fa5 100644 --- a/core/client/src/leaves.rs +++ b/core/client/src/leaves.rs @@ -77,7 +77,7 @@ impl LeafSet where } /// Read the leaf list from the DB, using given prefix for keys. - pub fn read_from_db(db: &KeyValueDB, column: Option, prefix: &[u8]) -> error::Result { + pub fn read_from_db(db: &dyn KeyValueDB, column: Option, prefix: &[u8]) -> error::Result { let mut storage = BTreeMap::new(); for (key, value) in db.iter_from_prefix(column, prefix) { diff --git a/core/client/src/light/backend.rs b/core/client/src/light/backend.rs index 52cdb6a626a11a872b039f8dfa4bf98d53da72cd..60b4c66c17c360d65bda7501ca9751e42e507091 100644 --- a/core/client/src/light/backend.rs +++ b/core/client/src/light/backend.rs @@ -20,7 +20,7 @@ use std::collections::HashMap; use std::sync::{Arc, Weak}; use futures::{Future, IntoFuture}; -use parking_lot::RwLock; +use parking_lot::{RwLock, Mutex}; use runtime_primitives::{generic::BlockId, Justification, StorageOverlay, ChildrenStorageOverlay}; use state_machine::{Backend as StateBackend, TrieBackend, backend::InMemory as InMemoryState}; @@ -38,13 +38,14 @@ use consensus::well_known_cache_keys; const IN_MEMORY_EXPECT_PROOF: &str = "InMemory state backend has Void error type and always suceeds; qed"; /// Light client backend. -pub struct Backend { +pub struct Backend { blockchain: Arc>, genesis_state: RwLock>>, + import_lock: Mutex<()>, } /// Light block (header and justification) import operation. -pub struct ImportOperation { +pub struct ImportOperation { header: Option, cache: HashMap>, leaf_state: NewBlockState, @@ -64,19 +65,20 @@ pub struct OnDemandState { } /// On-demand or in-memory genesis state. -pub enum OnDemandOrGenesisState { +pub enum OnDemandOrGenesisState { /// On-demand state - storage values are fetched from remote nodes. OnDemand(OnDemandState), /// Genesis state - storage values are stored in-memory. Genesis(InMemoryState), } -impl Backend { +impl Backend { /// Create new light backend. pub fn new(blockchain: Arc>) -> Self { Self { blockchain, genesis_state: RwLock::new(None), + import_lock: Default::default(), } } @@ -86,7 +88,7 @@ impl Backend { } } -impl AuxStore for Backend { +impl AuxStore for Backend { fn insert_aux< 'a, 'b: 'a, @@ -112,7 +114,7 @@ impl ClientBackend for Backend where type BlockImportOperation = ImportOperation; type Blockchain = Blockchain; type State = OnDemandOrGenesisState; - type ChangesTrieStorage = in_mem::ChangesTrieStorage; + type ChangesTrieStorage = in_mem::ChangesTrieStorage; fn begin_operation(&self) -> ClientResult { Ok(ImportOperation { @@ -213,6 +215,10 @@ impl ClientBackend for Backend where fn revert(&self, _n: NumberFor) -> ClientResult> { Err(ClientError::NotAvailableOnLightClient.into()) } + + fn get_import_lock(&self) -> &Mutex<()> { + &self.import_lock + } } impl RemoteBackend for Backend @@ -278,11 +284,20 @@ where // this is only called when genesis block is imported => shouldn't be performance bottleneck let mut storage: HashMap>, StorageOverlay> = HashMap::new(); storage.insert(None, top); + + // create a list of children keys to re-compute roots for + let child_delta = children.keys() + .cloned() + .map(|storage_key| (storage_key, None)) + .collect::>(); + + // make sure to persist the child storage for (child_key, child_storage) in children { storage.insert(Some(child_key), child_storage); } + let storage_update: InMemoryState = storage.into(); - let (storage_root, _) = storage_update.storage_root(::std::iter::empty()); + let (storage_root, _) = storage_update.full_storage_root(::std::iter::empty(), child_delta); self.storage_update = Some(storage_update); Ok(storage_root) @@ -373,12 +388,12 @@ where Vec::new() } - fn keys(&self, _prefix: &Vec) -> Vec> { + fn keys(&self, _prefix: &[u8]) -> Vec> { // whole state is not available on light node Vec::new() } - fn try_into_trie_backend(self) -> Option> { + fn as_trie_backend(&mut self) -> Option<&TrieBackend> { None } } @@ -465,7 +480,7 @@ where } } - fn keys(&self, prefix: &Vec) -> Vec> { + fn keys(&self, prefix: &[u8]) -> Vec> { match *self { OnDemandOrGenesisState::OnDemand(ref state) => StateBackend::::keys(state, prefix), @@ -473,10 +488,10 @@ where } } - fn try_into_trie_backend(self) -> Option> { + fn as_trie_backend(&mut self) -> Option<&TrieBackend> { match self { - OnDemandOrGenesisState::OnDemand(state) => state.try_into_trie_backend(), - OnDemandOrGenesisState::Genesis(state) => state.try_into_trie_backend(), + OnDemandOrGenesisState::OnDemand(ref mut state) => state.as_trie_backend(), + OnDemandOrGenesisState::Genesis(ref mut state) => state.as_trie_backend(), } } } diff --git a/core/client/src/light/blockchain.rs b/core/client/src/light/blockchain.rs index c38d50303ecc381378b25b797b79b5bd6377e5c8..e3d9c55a6a4633c0197debdd6ac9f93b2ee93ece 100644 --- a/core/client/src/light/blockchain.rs +++ b/core/client/src/light/blockchain.rs @@ -30,7 +30,7 @@ use crate::blockchain::{Backend as BlockchainBackend, BlockStatus, Cache as Bloc HeaderBackend as BlockchainHeaderBackend, Info as BlockchainInfo, ProvideCache}; use crate::cht; use crate::error::{Error as ClientError, Result as ClientResult}; -use crate::light::fetcher::{Fetcher, RemoteHeaderRequest}; +use crate::light::fetcher::{Fetcher, RemoteBodyRequest, RemoteHeaderRequest}; /// Light client blockchain storage. pub trait Storage: AuxStore + BlockchainHeaderBackend { @@ -56,13 +56,21 @@ pub trait Storage: AuxStore + BlockchainHeaderBackend { fn last_finalized(&self) -> ClientResult; /// Get headers CHT root for given block. Fails if the block is not pruned (not a part of any CHT). - fn header_cht_root(&self, cht_size: u64, block: NumberFor) -> ClientResult; + fn header_cht_root( + &self, + cht_size: NumberFor, + block: NumberFor, + ) -> ClientResult; /// Get changes trie CHT root for given block. Fails if the block is not pruned (not a part of any CHT). - fn changes_trie_cht_root(&self, cht_size: u64, block: NumberFor) -> ClientResult; + fn changes_trie_cht_root( + &self, + cht_size: NumberFor, + block: NumberFor, + ) -> ClientResult; /// Get storage cache. - fn cache(&self) -> Option>>; + fn cache(&self) -> Option>>; } /// Light client blockchain. @@ -116,7 +124,7 @@ impl BlockchainHeaderBackend for Blockchain where Bloc self.fetcher().upgrade().ok_or(ClientError::NotAvailableOnLightClient)? .remote_header(RemoteHeaderRequest { - cht_root: self.storage.header_cht_root(cht::SIZE, number)?, + cht_root: self.storage.header_cht_root(cht::size(), number)?, block: number, retry_count: None, }) @@ -126,7 +134,7 @@ impl BlockchainHeaderBackend for Blockchain where Bloc } } - fn info(&self) -> ClientResult> { + fn info(&self) -> BlockchainInfo { self.storage.info() } @@ -144,9 +152,19 @@ impl BlockchainHeaderBackend for Blockchain where Bloc } impl BlockchainBackend for Blockchain where Block: BlockT, S: Storage, F: Fetcher { - fn body(&self, _id: BlockId) -> ClientResult>> { - // TODO: #1445 fetch from remote node - Ok(None) + fn body(&self, id: BlockId) -> ClientResult>> { + let header = match self.header(id)? { + Some(header) => header, + None => return Ok(None), + }; + + self.fetcher().upgrade().ok_or(ClientError::NotAvailableOnLightClient)? + .remote_body(RemoteBodyRequest { + header, + retry_count: None, + }) + .into_future().wait() + .map(Some) } fn justification(&self, _id: BlockId) -> ClientResult> { @@ -157,7 +175,7 @@ impl BlockchainBackend for Blockchain where Block: Blo self.storage.last_finalized() } - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { self.storage.cache() } @@ -171,7 +189,7 @@ impl BlockchainBackend for Blockchain where Block: Blo } impl, F, Block: BlockT> ProvideCache for Blockchain { - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { self.storage.cache() } } @@ -205,8 +223,8 @@ pub mod tests { Err(ClientError::Backend("Test error".into())) } - fn info(&self) -> ClientResult> { - Err(ClientError::Backend("Test error".into())) + fn info(&self) -> Info { + panic!("Test error") } fn status(&self, _id: BlockId) -> ClientResult { @@ -285,7 +303,7 @@ pub mod tests { ).into()) } - fn cache(&self) -> Option>> { + fn cache(&self) -> Option>> { None } } diff --git a/core/client/src/light/call_executor.rs b/core/client/src/light/call_executor.rs index 8f90aaf54e4895cbabcccae5fd8870f1fc8132b9..a95b73a9602496bc59ffe8d9c2626d2be9568e86 100644 --- a/core/client/src/light/call_executor.rs +++ b/core/client/src/light/call_executor.rs @@ -24,9 +24,9 @@ use std::{ use futures::{IntoFuture, Future}; use parity_codec::{Encode, Decode}; -use primitives::{H256, Blake2Hasher, convert_hash, NativeOrEncoded, OffchainExt}; +use primitives::{offchain, H256, Blake2Hasher, convert_hash, NativeOrEncoded}; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{As, Block as BlockT, Header as HeaderT}; +use runtime_primitives::traits::{One, Block as BlockT, Header as HeaderT}; use state_machine::{ self, Backend as StateBackend, CodeExecutor, OverlayedChanges, ExecutionStrategy, create_proof_check_backend, @@ -87,7 +87,7 @@ where type Error = ClientError; fn call< - O: OffchainExt, + O: offchain::Externalities, >( &self, id: &BlockId, @@ -111,7 +111,7 @@ where fn contextual_call< 'a, - O: OffchainExt, + O: offchain::Externalities, IB: Fn() -> ClientResult<()>, EM: Fn( Result, Self::Error>, @@ -154,7 +154,7 @@ where } fn call_at_state< - O: OffchainExt, + O: offchain::Externalities, S: StateBackend, FF: FnOnce( Result, Self::Error>, @@ -230,7 +230,7 @@ impl CallExecutor for type Error = ClientError; fn call< - O: OffchainExt, + O: offchain::Externalities, >( &self, id: &BlockId, @@ -247,7 +247,7 @@ impl CallExecutor for fn contextual_call< 'a, - O: OffchainExt, + O: offchain::Externalities, IB: Fn() -> ClientResult<()>, EM: Fn( Result, Self::Error>, @@ -327,7 +327,7 @@ impl CallExecutor for } fn call_at_state< - O: OffchainExt, + O: offchain::Externalities, S: StateBackend, FF: FnOnce( Result, Self::Error>, @@ -388,7 +388,7 @@ impl CallExecutor for /// Method is executed using passed header as environment' current block. /// Proof includes both environment preparation proof and method execution proof. pub fn prove_execution( - state: S, + mut state: S, header: Block::Header, executor: &E, method: &str, @@ -399,13 +399,13 @@ pub fn prove_execution( S: StateBackend, E: CallExecutor, { - let trie_state = state.try_into_trie_backend() - .ok_or_else(|| Box::new(state_machine::ExecutionError::UnableToGenerateProof) as Box)?; + let trie_state = state.as_trie_backend() + .ok_or_else(|| Box::new(state_machine::ExecutionError::UnableToGenerateProof) as Box)?; // prepare execution environment + record preparation proof let mut changes = Default::default(); let (_, init_proof) = executor.prove_at_trie_state( - &trie_state, + trie_state, &mut changes, "Core_initialize_block", &header.encode(), @@ -435,7 +435,7 @@ pub fn check_execution_proof( Header: HeaderT, E: CodeExecutor, H: Hasher, - H::Out: Ord, + H::Out: Ord + 'static, { let local_state_root = request.header.state_root(); let root: H::Out = convert_hash(&local_state_root); @@ -444,11 +444,11 @@ pub fn check_execution_proof( let mut changes = OverlayedChanges::default(); let trie_backend = create_proof_check_backend(root, remote_proof)?; let next_block =
::new( - *request.header.number() + As::sa(1), + *request.header.number() + One::one(), Default::default(), Default::default(), request.header.hash(), - Default::default(), + request.header.digest().clone(), ); execution_proof_check_on_trie_backend::( &trie_backend, @@ -473,7 +473,7 @@ pub fn check_execution_proof( #[cfg(test)] mod tests { use consensus::BlockOrigin; - use test_client::{self, runtime::{Block, Header}, runtime::RuntimeApi, TestClient}; + use test_client::{self, runtime::Header, ClientExt, TestClient}; use executor::NativeExecutionDispatch; use crate::backend::{Backend, NewBlockState}; use crate::in_mem::Backend as InMemBackend; @@ -482,13 +482,6 @@ mod tests { #[test] fn execution_proof_is_generated_and_checked() { - type TestClient = test_client::client::Client< - test_client::Backend, - test_client::Executor, - Block, - RuntimeApi - >; - fn execute(remote_client: &TestClient, at: u64, method: &'static str) -> (Vec, Vec) { let remote_block_id = BlockId::Number(at); let remote_root = remote_client.state_at(&remote_block_id) @@ -525,7 +518,7 @@ mod tests { for _ in 1..3 { remote_client.import_justified( BlockOrigin::Own, - remote_client.new_block().unwrap().bake().unwrap(), + remote_client.new_block(Default::default()).unwrap().bake().unwrap(), Default::default(), ).unwrap(); } diff --git a/core/client/src/light/fetcher.rs b/core/client/src/light/fetcher.rs index 1e6f0842fb1c25e5cd3026d69aea33346fc65f72..bacfb45a7e61335ddb11b91db963b3c6c5774ce0 100644 --- a/core/client/src/light/fetcher.rs +++ b/core/client/src/light/fetcher.rs @@ -22,8 +22,12 @@ use std::marker::PhantomData; use futures::IntoFuture; use hash_db::{HashDB, Hasher}; +use parity_codec::{Decode, Encode}; use primitives::{ChangesTrieConfiguration, convert_hash}; -use runtime_primitives::traits::{As, Block as BlockT, Header as HeaderT, NumberFor}; +use runtime_primitives::traits::{ + Block as BlockT, Header as HeaderT, Hash, HashFor, NumberFor, + SimpleArithmetic, CheckedConversion, +}; use state_machine::{CodeExecutor, ChangesTrieRootsStorage, ChangesTrieAnchorBlockId, TrieBackend, read_proof_check, key_changes_proof_check, create_proof_check_backend_storage, read_child_proof_check}; @@ -124,17 +128,28 @@ pub struct ChangesProof { pub roots_proof: Vec>, } +/// Remote block body request +#[derive(Clone, Default, Debug, PartialEq, Eq, Hash)] +pub struct RemoteBodyRequest { + /// Header of the requested block body + pub header: Header, + /// Number of times to retry request. None means that default RETRY_COUNT is used. + pub retry_count: Option, +} + /// Light client data fetcher. Implementations of this trait must check if remote data /// is correct (see FetchedDataChecker) and return already checked data. pub trait Fetcher: Send + Sync { /// Remote header future. - type RemoteHeaderResult: IntoFuture; + type RemoteHeaderResult: IntoFuture; /// Remote storage read future. - type RemoteReadResult: IntoFuture>, Error=ClientError>; + type RemoteReadResult: IntoFuture>, Error = ClientError>; /// Remote call result future. - type RemoteCallResult: IntoFuture, Error=ClientError>; + type RemoteCallResult: IntoFuture, Error = ClientError>; /// Remote changes result future. - type RemoteChangesResult: IntoFuture, u32)>, Error=ClientError>; + type RemoteChangesResult: IntoFuture, u32)>, Error = ClientError>; + /// Remote block body result future. + type RemoteBodyResult: IntoFuture, Error = ClientError>; /// Fetch remote header. fn remote_header(&self, request: RemoteHeaderRequest) -> Self::RemoteHeaderResult; @@ -153,6 +168,8 @@ pub trait Fetcher: Send + Sync { /// Fetch remote changes ((block number, extrinsic index)) where given key has been changed /// at a given blocks range. fn remote_changes(&self, request: RemoteChangesRequest) -> Self::RemoteChangesResult; + /// Fetch remote block body + fn remote_body(&self, request: RemoteBodyRequest) -> Self::RemoteBodyResult; } /// Light client remote data checker. @@ -191,6 +208,12 @@ pub trait FetchChecker: Send + Sync { request: &RemoteChangesRequest, proof: ChangesProof ) -> ClientResult, u32)>>; + /// Check remote body proof. + fn check_body_proof( + &self, + request: &RemoteBodyRequest, + body: Vec + ) -> ClientResult>; } /// Remote data checker. @@ -213,7 +236,7 @@ impl, F> LightDataChecker, remote_proof: ChangesProof, - cht_size: u64, + cht_size: NumberFor, ) -> ClientResult, u32)>> where H: Hasher, @@ -261,28 +284,27 @@ impl, F> LightDataChecker( + key_changes_proof_check::<_, H, _>( &request.changes_trie_config, &RootsStorage { roots: (request.tries_roots.0, &request.tries_roots.2), prev_roots: remote_roots, }, remote_proof, - request.first_block.0.as_(), + request.first_block.0, &ChangesTrieAnchorBlockId { hash: convert_hash(&request.last_block.1), - number: request.last_block.0.as_(), + number: request.last_block.0, }, - remote_max_block.as_(), + remote_max_block, &request.key) - .map(|pairs| pairs.into_iter().map(|(b, x)| (As::sa(b), x)).collect()) .map_err(|err| ClientError::ChangesTrieAccessFailed(err)) } /// Check CHT-based proof for changes tries roots. fn check_changes_tries_proof( &self, - cht_size: u64, + cht_size: NumberFor, remote_roots: &BTreeMap, B::Hash>, remote_roots_proof: Vec>, ) -> ClientResult<()> @@ -338,7 +360,7 @@ impl FetchChecker for LightDataChecker, H: Hasher, - H::Out: Ord, + H::Out: Ord + 'static, S: BlockchainStorage, F: Send + Sync, { @@ -394,30 +416,62 @@ impl FetchChecker for LightDataChecker, remote_proof: ChangesProof ) -> ClientResult, u32)>> { - self.check_changes_proof_with_cht_size(request, remote_proof, cht::SIZE) + self.check_changes_proof_with_cht_size(request, remote_proof, cht::size()) + } + + fn check_body_proof( + &self, + request: &RemoteBodyRequest, + body: Vec + ) -> ClientResult> { + + // TODO: #2621 + let extrinsics_root = HashFor::::ordered_trie_root(body.iter().map(Encode::encode)); + if *request.header.extrinsics_root() == extrinsics_root { + Ok(body) + } else { + Err(format!("RemoteBodyRequest: invalid extrinsics root expected: {} but got {}", + *request.header.extrinsics_root(), + extrinsics_root, + ).into()) + } + } } /// A view of BTreeMap as a changes trie roots storage. -struct RootsStorage<'a, Number: As, Hash: 'a> { +struct RootsStorage<'a, Number: SimpleArithmetic, Hash: 'a> { roots: (Number, &'a [Hash]), prev_roots: BTreeMap, } -impl<'a, H, Number, Hash> ChangesTrieRootsStorage for RootsStorage<'a, Number, Hash> +impl<'a, H, Number, Hash> ChangesTrieRootsStorage for RootsStorage<'a, Number, Hash> where H: Hasher, - Number: Send + Sync + Eq + ::std::cmp::Ord + Copy + As, + Number: ::std::fmt::Display + Clone + SimpleArithmetic + Encode + Decode + Send + Sync + 'static, Hash: 'a + Send + Sync + Clone + AsRef<[u8]>, { - fn root(&self, _anchor: &ChangesTrieAnchorBlockId, block: u64) -> Result, String> { + fn build_anchor( + &self, + _hash: H::Out, + ) -> Result, String> { + Err("build_anchor is only called when building block".into()) + } + + fn root( + &self, + _anchor: &ChangesTrieAnchorBlockId, + block: Number, + ) -> Result, String> { // we can't ask for roots from parallel forks here => ignore anchor - let root = if block < self.roots.0.as_() { - self.prev_roots.get(&As::sa(block)).cloned() + let root = if block < self.roots.0 { + self.prev_roots.get(&Number::unique_saturated_from(block)).cloned() } else { - block.checked_sub(self.roots.0.as_()) - .and_then(|index| self.roots.1.get(index as usize)) - .cloned() + let index: Option = block.checked_sub(&self.roots.0).and_then(|index| index.checked_into()); + match index { + Some(index) => self.roots.1.get(index as usize).cloned(), + None => None, + } }; Ok(root.map(|root| { @@ -437,8 +491,8 @@ pub mod tests { use executor::{self, NativeExecutionDispatch}; use crate::error::Error as ClientError; use test_client::{ - self, TestClient, blockchain::HeaderBackend, AccountKeyring, - runtime::{self, Hash, Block, Header} + self, ClientExt, blockchain::HeaderBackend, AccountKeyring, + runtime::{self, Hash, Block, Header, Extrinsic} }; use consensus::BlockOrigin; @@ -446,7 +500,7 @@ pub mod tests { use crate::light::fetcher::{Fetcher, FetchChecker, LightDataChecker, RemoteCallRequest, RemoteHeaderRequest}; use crate::light::blockchain::tests::{DummyStorage, DummyBlockchain}; - use primitives::{blake2_256, Blake2Hasher}; + use primitives::{blake2_256, Blake2Hasher, H256}; use primitives::storage::{StorageKey, well_known_keys}; use runtime_primitives::generic::BlockId; use state_machine::Backend; @@ -454,22 +508,30 @@ pub mod tests { pub type OkCallFetcher = Mutex>; + fn not_implemented_in_tests() -> FutureResult + where + E: std::convert::From<&'static str>, + { + err("Not implemented on test node".into()) + } + impl Fetcher for OkCallFetcher { type RemoteHeaderResult = FutureResult; type RemoteReadResult = FutureResult>, ClientError>; type RemoteCallResult = FutureResult, ClientError>; type RemoteChangesResult = FutureResult, u32)>, ClientError>; + type RemoteBodyResult = FutureResult, ClientError>; fn remote_header(&self, _request: RemoteHeaderRequest
) -> Self::RemoteHeaderResult { - err("Not implemented on test node".into()) + not_implemented_in_tests() } fn remote_read(&self, _request: RemoteReadRequest
) -> Self::RemoteReadResult { - err("Not implemented on test node".into()) + not_implemented_in_tests() } fn remote_read_child(&self, _request: RemoteReadChildRequest
) -> Self::RemoteReadResult { - err("Not implemented on test node".into()) + not_implemented_in_tests() } fn remote_call(&self, _request: RemoteCallRequest
) -> Self::RemoteCallResult { @@ -477,11 +539,21 @@ pub mod tests { } fn remote_changes(&self, _request: RemoteChangesRequest
) -> Self::RemoteChangesResult { - err("Not implemented on test node".into()) + not_implemented_in_tests() + } + + fn remote_body(&self, _request: RemoteBodyRequest
) -> Self::RemoteBodyResult { + not_implemented_in_tests() } } - type TestChecker = LightDataChecker, Blake2Hasher, Block, DummyStorage, OkCallFetcher>; + type TestChecker = LightDataChecker< + executor::NativeExecutor, + Blake2Hasher, + Block, + DummyStorage, + OkCallFetcher, + >; fn prepare_for_read_proof_check() -> (TestChecker, Header, Vec>, u32) { // prepare remote client @@ -516,7 +588,7 @@ pub mod tests { let remote_client = test_client::new(); let mut local_headers_hashes = Vec::new(); for i in 0..4 { - let builder = remote_client.new_block().unwrap(); + let builder = remote_client.new_block(Default::default()).unwrap(); remote_client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap(); local_headers_hashes.push(remote_client.block_hash(i + 1) .map_err(|_| ClientError::Backend("TestError".into()))); @@ -537,10 +609,18 @@ pub mod tests { (local_checker, local_cht_root, remote_block_header, remote_header_proof) } + fn header_with_computed_extrinsics_root(extrinsics: Vec) -> Header { + let extrinsics_root = + trie::ordered_trie_root::(extrinsics.iter().map(Encode::encode)); + + // only care about `extrinsics_root` + Header::new(0, extrinsics_root, H256::zero(), H256::zero(), Default::default()) + } + #[test] fn storage_read_proof_is_generated_and_checked() { let (local_checker, remote_block_header, remote_read_proof, authorities_len) = prepare_for_read_proof_check(); - assert_eq!((&local_checker as &FetchChecker).check_read_proof(&RemoteReadRequest::
{ + assert_eq!((&local_checker as &dyn FetchChecker).check_read_proof(&RemoteReadRequest::
{ block: remote_block_header.hash(), header: remote_block_header, key: well_known_keys::AUTHORITY_COUNT.to_vec(), @@ -551,7 +631,7 @@ pub mod tests { #[test] fn header_proof_is_generated_and_checked() { let (local_checker, local_cht_root, remote_block_header, remote_header_proof) = prepare_for_header_proof_check(true); - assert_eq!((&local_checker as &FetchChecker).check_header_proof(&RemoteHeaderRequest::
{ + assert_eq!((&local_checker as &dyn FetchChecker).check_header_proof(&RemoteHeaderRequest::
{ cht_root: local_cht_root, block: 1, retry_count: None, @@ -562,7 +642,7 @@ pub mod tests { fn check_header_proof_fails_if_cht_root_is_invalid() { let (local_checker, _, mut remote_block_header, remote_header_proof) = prepare_for_header_proof_check(true); remote_block_header.number = 100; - assert!((&local_checker as &FetchChecker).check_header_proof(&RemoteHeaderRequest::
{ + assert!((&local_checker as &dyn FetchChecker).check_header_proof(&RemoteHeaderRequest::
{ cht_root: Default::default(), block: 1, retry_count: None, @@ -573,7 +653,7 @@ pub mod tests { fn check_header_proof_fails_if_invalid_header_provided() { let (local_checker, local_cht_root, mut remote_block_header, remote_header_proof) = prepare_for_header_proof_check(true); remote_block_header.number = 100; - assert!((&local_checker as &FetchChecker).check_header_proof(&RemoteHeaderRequest::
{ + assert!((&local_checker as &dyn FetchChecker).check_header_proof(&RemoteHeaderRequest::
{ cht_root: local_cht_root, block: 1, retry_count: None, @@ -587,9 +667,9 @@ pub mod tests { Arc::new(DummyBlockchain::new(DummyStorage::new())), test_client::LocalExecutor::new(None) ); - let local_checker = &local_checker as &FetchChecker; - let max = remote_client.info().unwrap().chain.best_number; - let max_hash = remote_client.info().unwrap().chain.best_hash; + let local_checker = &local_checker as &dyn FetchChecker; + let max = remote_client.info().chain.best_number; + let max_hash = remote_client.info().chain.best_hash; for (index, (begin, end, key, expected_result)) in test_cases.into_iter().enumerate() { let begin_hash = remote_client.block_hash(begin).unwrap().unwrap(); @@ -683,9 +763,9 @@ pub mod tests { Arc::new(DummyBlockchain::new(DummyStorage::new())), test_client::LocalExecutor::new(None) ); - let local_checker = &local_checker as &FetchChecker; - let max = remote_client.info().unwrap().chain.best_number; - let max_hash = remote_client.info().unwrap().chain.best_hash; + let local_checker = &local_checker as &dyn FetchChecker; + let max = remote_client.info().chain.best_number; + let max_hash = remote_client.info().chain.best_hash; let (begin, end, key, _) = test_cases[0].clone(); let begin_hash = remote_client.block_hash(begin).unwrap().unwrap(); @@ -776,4 +856,47 @@ pub mod tests { ); assert!(local_checker.check_changes_tries_proof(4, &remote_proof.roots, vec![]).is_err()); } + + #[test] + fn check_body_proof_faulty() { + let header = header_with_computed_extrinsics_root( + vec![Extrinsic::IncludeData(vec![1, 2, 3, 4])] + ); + let block = Block::new(header.clone(), Vec::new()); + + let local_checker = TestChecker::new( + Arc::new(DummyBlockchain::new(DummyStorage::new())), + test_client::LocalExecutor::new(None) + ); + + let body_request = RemoteBodyRequest { + header: header.clone(), + retry_count: None, + }; + + assert!( + local_checker.check_body_proof(&body_request, block.extrinsics).is_err(), + "vec![1, 2, 3, 4] != vec![]" + ); + } + + #[test] + fn check_body_proof_of_same_data_should_succeed() { + let extrinsics = vec![Extrinsic::IncludeData(vec![1, 2, 3, 4, 5, 6, 7, 8, 255])]; + + let header = header_with_computed_extrinsics_root(extrinsics.clone()); + let block = Block::new(header.clone(), extrinsics); + + let local_checker = TestChecker::new( + Arc::new(DummyBlockchain::new(DummyStorage::new())), + test_client::LocalExecutor::new(None) + ); + + let body_request = RemoteBodyRequest { + header: header.clone(), + retry_count: None, + }; + + assert!(local_checker.check_body_proof(&body_request, block.extrinsics).is_ok()); + } } diff --git a/core/client/src/runtime_api.rs b/core/client/src/runtime_api.rs index f5c8a59a903c4565097735d987080b458ed1c5c2..4f2f8414617c8c1edb3361a2a1b854844ca76aa2 100644 --- a/core/client/src/runtime_api.rs +++ b/core/client/src/runtime_api.rs @@ -31,7 +31,7 @@ pub use runtime_primitives::{ generic::BlockId, transaction_validity::TransactionValidity, }; #[doc(hidden)] -pub use primitives::{ExecutionContext, OffchainExt}; +pub use primitives::{offchain, ExecutionContext}; #[doc(hidden)] pub use runtime_version::{ApiId, RuntimeVersion, ApisVec, create_apis_vec}; #[doc(hidden)] @@ -46,7 +46,6 @@ use sr_api_macros::decl_runtime_apis; use primitives::OpaqueMetadata; #[cfg(feature = "std")] use std::{panic::UnwindSafe, cell::RefCell, rc::Rc}; -use rstd::vec::Vec; #[cfg(feature = "std")] use primitives::Hasher as HasherT; @@ -171,9 +170,6 @@ decl_runtime_apis! { #[skip_initialize_block] #[initialize_block] fn initialize_block(header: &::Header); - /// Returns the authorities. - #[deprecated(since = "1.0", note = "Please switch to `AuthoritiesApi`.")] - fn authorities() -> Vec>; } /// The `Metadata` api trait that returns metadata for the runtime. diff --git a/core/consensus/aura/Cargo.toml b/core/consensus/aura/Cargo.toml index 8a589aa12695fafcd6f5a84be398a0924b17b112..c8711d0289205e6f832d16fe30db1469fad56f6a 100644 --- a/core/consensus/aura/Cargo.toml +++ b/core/consensus/aura/Cargo.toml @@ -22,9 +22,8 @@ consensus_common = { package = "substrate-consensus-common", path = "../common" authorities = { package = "substrate-consensus-authorities", path = "../authorities" } runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } futures = "0.1.17" -tokio = "0.1.7" -parking_lot = "0.7.1" -error-chain = "0.12" +tokio-timer = "0.2.11" +parking_lot = "0.8.0" log = "0.4" [dev-dependencies] @@ -32,5 +31,6 @@ keyring = { package = "substrate-keyring", path = "../../keyring" } substrate-executor = { path = "../../executor" } network = { package = "substrate-network", path = "../../network", features = ["test-helpers"]} service = { package = "substrate-service", path = "../../service" } -test_client = { package = "substrate-test-client", path = "../../test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" } +tokio = "0.1.7" env_logger = "0.6" diff --git a/core/consensus/aura/src/digest.rs b/core/consensus/aura/src/digest.rs new file mode 100644 index 0000000000000000000000000000000000000000..fe85c5807ea9d499e059a991b615ca0dbf5c08e0 --- /dev/null +++ b/core/consensus/aura/src/digest.rs @@ -0,0 +1,67 @@ +// Copyright 2018-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 . + +//! Aura (Authority-Round) digests +//! +//! This implements the digests for AuRa, to allow the private +//! `CompatibleDigestItem` trait to appear in public interfaces. +use primitives::Pair; +use aura_primitives::AURA_ENGINE_ID; +use runtime_primitives::generic::DigestItem; +use parity_codec::{Encode, Decode}; + +type Signature

=

::Signature; + +/// A digest item which is usable with aura consensus. +pub trait CompatibleDigestItem: Sized { + /// Construct a digest item which contains a signature on the hash. + fn aura_seal(signature: Signature) -> Self; + + /// If this item is an Aura seal, return the signature. + fn as_aura_seal(&self) -> Option<&Signature>; + + /// Construct a digest item which contains the slot number + fn aura_pre_digest(slot_num: u64) -> Self; + + /// If this item is an AuRa pre-digest, return the slot number + fn as_aura_pre_digest(&self) -> Option; +} + +impl CompatibleDigestItem

for DigestItem + where P: Pair, P::Signature: Clone + Encode + Decode, +{ + fn aura_seal(signature: Signature

) -> Self { + DigestItem::Seal(AURA_ENGINE_ID, signature) + } + + fn as_aura_seal(&self) -> Option<&Signature

> { + match self { + DigestItem::Seal(AURA_ENGINE_ID, ref sig) => Some(sig), + _ => None, + } + } + + fn aura_pre_digest(slot_num: u64) -> Self { + DigestItem::PreRuntime(AURA_ENGINE_ID, slot_num.encode()) + } + + fn as_aura_pre_digest(&self) -> Option { + match self { + DigestItem::PreRuntime(AURA_ENGINE_ID, ref buffer) => Decode::decode(&mut &buffer[..]), + _ => None, + } + } +} diff --git a/core/consensus/aura/src/lib.rs b/core/consensus/aura/src/lib.rs index 2c545cec33fe728d0ad04d6e497ae5132f9d015c..fa878ef1045491d7a95ef89d55a08ea556b93c90 100644 --- a/core/consensus/aura/src/lib.rs +++ b/core/consensus/aura/src/lib.rs @@ -40,22 +40,24 @@ use consensus_common::import_queue::{ use client::{ block_builder::api::BlockBuilder as BlockBuilderApi, blockchain::ProvideCache, - runtime_api::{ApiExt, Core as CoreApi}, + runtime_api::ApiExt, error::Result as CResult, backend::AuxStore, }; -use aura_primitives::AURA_ENGINE_ID; -use runtime_primitives::{generic, generic::BlockId, Justification}; + +use runtime_primitives::{generic::{self, BlockId}, Justification}; use runtime_primitives::traits::{ - Block, Header, Digest, DigestItemFor, DigestItem, ProvideRuntimeApi, AuthorityIdFor, Zero, + Block, Header, Digest, DigestItemFor, DigestItem, ProvideRuntimeApi, AuthorityIdFor, + Zero, Member, }; + use primitives::Pair; -use inherents::{InherentDataProviders, InherentData, RuntimeString}; +use inherents::{InherentDataProviders, InherentData}; use authorities::AuthoritiesApi; -use futures::{Future, IntoFuture, future, stream::Stream}; -use tokio::timer::Timeout; -use log::{warn, debug, info, trace}; +use futures::{Future, IntoFuture, future}; +use tokio_timer::Timeout; +use log::{error, warn, debug, info, trace}; use srml_aura::{ InherentType as AuraInherent, AuraInherentData, @@ -63,29 +65,15 @@ use srml_aura::{ }; use substrate_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG, CONSENSUS_WARN, CONSENSUS_INFO}; -use slots::{CheckedHeader, SlotWorker, SlotInfo, SlotCompatible, slot_now, check_equivocation}; +use slots::{CheckedHeader, SlotData, SlotWorker, SlotInfo, SlotCompatible, slot_now, check_equivocation}; pub use aura_primitives::*; pub use consensus_common::{SyncOracle, ExtraVerification}; +pub use digest::CompatibleDigestItem; -type AuthorityId

=

::Public; -type Signature

=

::Signature; +mod digest; -/// A handle to the network. This is generally implemented by providing some -/// handle to a gossip service or similar. -/// -/// Intended to be a lightweight handle such as an `Arc`. -#[deprecated( - since = "1.0.1", - note = "This is dead code and will be removed in a future release", -)] -pub trait Network: Clone { - /// A stream of input messages for a topic. - type In: Stream,Error=()>; - - /// Send a message at a specific round out. - fn send_message(&self, slot: u64, message: Vec); -} +type AuthorityId

=

::Public; /// A slot duration. Create with `get_or_compute`. #[derive(Clone, Copy, Debug, Encode, Decode, Hash, PartialOrd, Ord, PartialEq, Eq)] @@ -122,52 +110,6 @@ fn slot_author(slot_num: u64, authorities: &[AuthorityId

]) -> Option Some(current_author) } -fn inherent_to_common_error(err: RuntimeString) -> consensus_common::Error { - consensus_common::ErrorKind::InherentData(err.into()).into() -} - -/// A digest item which is usable with aura consensus. -pub trait CompatibleDigestItem: Sized { - /// Construct a digest item which contains a slot number and a signature on the - /// hash. - fn aura_seal(slot_num: u64, signature: Signature) -> Self; - - /// If this item is an Aura seal, return the slot number and signature. - fn as_aura_seal(&self) -> Option<(u64, Signature)>; - - /// Return `true` if this seal type is deprecated. Otherwise, return - /// `false`. - fn is_deprecated(&self) -> bool; -} - -impl CompatibleDigestItem

for generic::DigestItem - where P: Pair, P::Signature: Clone + Encode + Decode, -{ - /// Construct a digest item which is a slot number and a signature on the - /// hash. - fn aura_seal(slot_number: u64, signature: Signature

) -> Self { - generic::DigestItem::Consensus(AURA_ENGINE_ID, (slot_number, signature).encode()) - } - - /// If this item is an Aura seal, return the slot number and signature. - #[allow(deprecated)] - fn as_aura_seal(&self) -> Option<(u64, Signature

)> { - match self { - generic::DigestItem::Seal(slot, ref sig) => Some((*slot, (*sig).clone())), - generic::DigestItem::Consensus(AURA_ENGINE_ID, seal) => Decode::decode(&mut &seal[..]), - _ => None, - } - } - - #[allow(deprecated)] - fn is_deprecated(&self) -> bool { - match self { - generic::DigestItem::Seal(_, _) => true, - _ => false, - } - } -} - #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash)] struct AuraSlotCompatible; @@ -177,64 +119,13 @@ impl SlotCompatible for AuraSlotCompatible { ) -> Result<(TimestampInherent, AuraInherent), consensus_common::Error> { data.timestamp_inherent_data() .and_then(|t| data.aura_inherent_data().map(|a| (t, a))) - .map_err(inherent_to_common_error) + .map_err(Into::into) + .map_err(consensus_common::Error::InherentData) } } -/// Start the aura worker in a separate thread. -#[deprecated(since = "1.1", note = "Please spawn a thread manually")] -pub fn start_aura_thread( - slot_duration: SlotDuration, - local_key: Arc

, - client: Arc, - select_chain: SC, - block_import: Arc, - env: Arc, - sync_oracle: SO, - on_exit: OnExit, - inherent_data_providers: InherentDataProviders, - force_authoring: bool, -) -> Result<(), consensus_common::Error> where - B: Block + 'static, - C: ProvideRuntimeApi + ProvideCache + AuxStore + Send + Sync + 'static, - C::Api: AuthoritiesApi, - SC: SelectChain + Clone + 'static, - E: Environment + Send + Sync + 'static, - E::Proposer: Proposer + Send + 'static, - <>::Create as IntoFuture>::Future: Send + 'static, - I: BlockImport + Send + Sync + 'static, - Error: From + 'static, - P: Pair + Send + Sync + 'static, - P::Public: Encode + Decode + Eq + Clone + Debug + Hash + Send + Sync + 'static, - P::Signature: Encode, - SO: SyncOracle + Send + Sync + Clone + 'static, - OnExit: Future + Send + 'static, - DigestItemFor: CompatibleDigestItem

+ DigestItem> + 'static, - Error: ::std::error::Error + Send + From<::consensus_common::Error> + 'static, -{ - let worker = AuraWorker { - client: client.clone(), - block_import, - env, - local_key, - inherent_data_providers: inherent_data_providers.clone(), - sync_oracle: sync_oracle.clone(), - force_authoring, - }; - - #[allow(deprecated)] // The function we are in is also deprecated. - slots::start_slot_worker_thread::<_, _, _, _, AuraSlotCompatible, u64, _>( - slot_duration.0, - select_chain, - Arc::new(worker), - sync_oracle, - on_exit, - inherent_data_providers - ) -} - /// Start the aura worker. The returned future should be run in a tokio runtime. -pub fn start_aura( +pub fn start_aura( slot_duration: SlotDuration, local_key: Arc

, client: Arc, @@ -242,43 +133,48 @@ pub fn start_aura( block_import: Arc, env: Arc, sync_oracle: SO, - on_exit: OnExit, inherent_data_providers: InherentDataProviders, force_authoring: bool, ) -> Result, consensus_common::Error> where - B: Block, - C: ProvideRuntimeApi + ProvideCache + AuxStore, + B: Block, + C: ProvideRuntimeApi + ProvideCache + AuxStore + Send + Sync, C::Api: AuthoritiesApi, - SC: SelectChain + Clone, - E: Environment, + SC: SelectChain, + generic::DigestItem: DigestItem, E::Proposer: Proposer, <>::Create as IntoFuture>::Future: Send + 'static, - I: BlockImport + Send + Sync + 'static, P: Pair + Send + Sync + 'static, - P::Public: Hash + Eq + Send + Sync + Clone + Debug + Encode + Decode + 'static, - P::Signature: Encode, - SO: SyncOracle + Send + Sync + Clone, + P::Public: Hash + Member + Encode + Decode, + P::Signature: Hash + Member + Encode + Decode, DigestItemFor: CompatibleDigestItem

+ DigestItem>, + H: Header< + Digest=generic::Digest>, + Hash=B::Hash, + >, + E: Environment, + I: BlockImport + Send + Sync + 'static, Error: ::std::error::Error + Send + From<::consensus_common::Error> + From + 'static, - OnExit: Future, + SO: SyncOracle + Send + Sync + Clone, { let worker = AuraWorker { client: client.clone(), block_import, env, local_key, - inherent_data_providers: inherent_data_providers.clone(), sync_oracle: sync_oracle.clone(), force_authoring, }; - slots::start_slot_worker::<_, _, _, _, _, AuraSlotCompatible, _>( + register_aura_inherent_data_provider( + &inherent_data_providers, + slot_duration.0.slot_duration() + )?; + Ok(slots::start_slot_worker::<_, _, _, _, _, AuraSlotCompatible>( slot_duration.0, select_chain, - Arc::new(worker), + worker, sync_oracle, - on_exit, inherent_data_providers - ) + )) } struct AuraWorker { @@ -287,32 +183,29 @@ struct AuraWorker { env: Arc, local_key: Arc

, sync_oracle: SO, - inherent_data_providers: InherentDataProviders, force_authoring: bool, } -impl SlotWorker for AuraWorker where - C: ProvideRuntimeApi + ProvideCache + AuxStore, +impl SlotWorker for AuraWorker where + B: Block, + C: ProvideRuntimeApi + ProvideCache + Sync, C::Api: AuthoritiesApi, E: Environment, E::Proposer: Proposer, <>::Create as IntoFuture>::Future: Send + 'static, + H: Header< + Digest=generic::Digest>, + Hash=B::Hash, + >, I: BlockImport + Send + Sync + 'static, P: Pair + Send + Sync + 'static, - P::Public: Hash + Eq + Send + Sync + Clone + Debug + Encode + Decode + 'static, - P::Signature: Encode, + P::Public: Member + Encode + Decode + Hash, + P::Signature: Member + Encode + Decode + Hash + Debug, SO: SyncOracle + Send + Clone, - DigestItemFor: CompatibleDigestItem

+ DigestItem>, + DigestItemFor: CompatibleDigestItem

+ DigestItem, Hash=B::Hash>, Error: ::std::error::Error + Send + From<::consensus_common::Error> + From + 'static, { - type OnSlot = Box + Send>; - - fn on_start( - &self, - slot_duration: u64 - ) -> Result<(), consensus_common::Error> { - register_aura_inherent_data_provider(&self.inherent_data_providers, slot_duration) - } + type OnSlot = Box + Send>; fn on_slot( &self, @@ -379,7 +272,15 @@ impl SlotWorker for AuraWorker as CompatibleDigestItem

>::aura_pre_digest(slot_num), + ], + }, + remaining_duration, + ).into_future(), remaining_duration, ) } else { @@ -387,72 +288,98 @@ impl SlotWorker for AuraWorker slot_num - ); - return - } + Box::new(proposal_work.map(move |b| { + // minor hack since we don't have access to the timestamp + // that is actually set by the proposer. + let slot_after_building = slot_now(slot_duration); + if slot_after_building != Some(slot_num) { + info!( + "Discarding proposal for slot {}; block production took too long", + slot_num + ); + telemetry!(CONSENSUS_INFO; "aura.discarding_proposal_took_too_long"; + "slot" => slot_num + ); + return + } - let (header, body) = b.deconstruct(); - let header_num = header.number().clone(); - let pre_hash = header.hash(); - let parent_hash = header.parent_hash().clone(); - - // sign the pre-sealed hash of the block and then - // add it to a digest item. - let to_sign = (slot_num, pre_hash).encode(); - let signature = pair.sign(&to_sign[..]); - let item = as CompatibleDigestItem

>::aura_seal( - slot_num, - signature, - ); - - let import_block: ImportBlock = ImportBlock { - origin: BlockOrigin::Own, - header, - justification: None, - post_digests: vec![item], - body: Some(body), - finalized: false, - auxiliary: Vec::new(), - fork_choice: ForkChoiceStrategy::LongestChain, - }; - - info!("Pre-sealed block for proposal at {}. Hash now {:?}, previously {:?}.", - header_num, - import_block.post_header().hash(), - pre_hash - ); - telemetry!(CONSENSUS_INFO; "aura.pre_sealed_block"; - "header_num" => ?header_num, - "hash_now" => ?import_block.post_header().hash(), - "hash_previously" => ?pre_hash - ); - - if let Err(e) = block_import.import_block(import_block, Default::default()) { - warn!(target: "aura", "Error with block built on {:?}: {:?}", - parent_hash, e); - telemetry!(CONSENSUS_WARN; "aura.err_with_block_built_on"; - "hash" => ?parent_hash, "err" => ?e - ); - } - }) - .map_err(|e| consensus_common::ErrorKind::ClientImport(format!("{:?}", e)).into()) - ) + let (header, body) = b.deconstruct(); + let pre_digest: Result = find_pre_digest::(&header); + if let Err(e) = pre_digest { + error!(target: "aura", "FATAL ERROR: Invalid pre-digest: {}!", e); + return + } else { + trace!(target: "aura", "Got correct number of seals. Good!") + }; + + let header_num = header.number().clone(); + let parent_hash = header.parent_hash().clone(); + + // sign the pre-sealed hash of the block and then + // add it to a digest item. + let header_hash = header.hash(); + let signature = pair.sign(header_hash.as_ref()); + let signature_digest_item = as CompatibleDigestItem

>::aura_seal(signature); + + let import_block: ImportBlock = ImportBlock { + origin: BlockOrigin::Own, + header, + justification: None, + post_digests: vec![signature_digest_item], + body: Some(body), + finalized: false, + auxiliary: Vec::new(), + fork_choice: ForkChoiceStrategy::LongestChain, + }; + + info!("Pre-sealed block for proposal at {}. Hash now {:?}, previously {:?}.", + header_num, + import_block.post_header().hash(), + header_hash + ); + telemetry!(CONSENSUS_INFO; "aura.pre_sealed_block"; + "header_num" => ?header_num, + "hash_now" => ?import_block.post_header().hash(), + "hash_previously" => ?header_hash + ); + + if let Err(e) = block_import.import_block(import_block, Default::default()) { + warn!(target: "aura", "Error with block built on {:?}: {:?}", + parent_hash, e); + telemetry!(CONSENSUS_WARN; "aura.err_with_block_built_on"; + "hash" => ?parent_hash, "err" => ?e + ); + } + }).map_err(|e| consensus_common::Error::ClientImport(format!("{:?}", e)).into())) } } +macro_rules! aura_err { + ($($i: expr),+) => { + { debug!(target: "aura", $($i),+) + ; format!($($i),+) + } + }; +} + +fn find_pre_digest(header: &B::Header) -> Result + where DigestItemFor: CompatibleDigestItem

, + P::Signature: Decode, + P::Public: Encode + Decode + PartialEq + Clone, +{ + let mut pre_digest: Option = None; + for log in header.digest().logs() { + trace!(target: "aura", "Checking log {:?}", log); + match (log.as_aura_pre_digest(), pre_digest.is_some()) { + (Some(_), true) => Err(aura_err!("Multiple AuRa pre-runtime headers, rejecting!"))?, + (None, _) => trace!(target: "aura", "Ignoring digest not meant for us"), + (s, false) => pre_digest = s, + } + } + pre_digest.ok_or_else(|| aura_err!("No AuRa pre-runtime digest found")) +} + + /// check a header has been signed by the right key. If the slot is too far in the future, an error will be returned. /// if it's successful, returns the pre-header and the digest item containing the seal. /// @@ -460,35 +387,30 @@ impl SlotWorker for AuraWorker( - client: &Arc, + client: &C, slot_now: u64, mut header: B::Header, hash: B::Hash, authorities: &[AuthorityId

], - allow_old_seals: bool, -) -> Result>, String> - where DigestItemFor: CompatibleDigestItem

, - P::Signature: Decode, - C: client::backend::AuxStore, - P::Public: AsRef + Encode + Decode + PartialEq + Clone, +) -> Result)>, String> where + DigestItemFor: CompatibleDigestItem

, + P::Signature: Decode, + C: client::backend::AuxStore, + P::Public: AsRef + Encode + Decode + PartialEq + Clone, { - let digest_item = match header.digest_mut().pop() { + let seal = match header.digest_mut().pop() { Some(x) => x, None => return Err(format!("Header {:?} is unsealed", hash)), }; - if !allow_old_seals && digest_item.is_deprecated() { - debug!(target: "aura", "Header {:?} uses old seal format, rejecting", hash); - return Err(format!("Header {:?} uses old seal format, rejecting", hash)) - } - - let (slot_num, sig) = digest_item.as_aura_seal().ok_or_else(|| { - debug!(target: "aura", "Header {:?} is unsealed", hash); - format!("Header {:?} is unsealed", hash) + let sig = seal.as_aura_seal().ok_or_else(|| { + aura_err!("Header {:?} has a bad seal", hash) })?; + let slot_num = find_pre_digest::(&header)?; + if slot_num > slot_now { - header.digest_mut().push(digest_item); + header.digest_mut().push(seal); Ok(CheckedHeader::Deferred(header, slot_num)) } else { // check the signature is valid under the expected authority and @@ -499,30 +421,24 @@ fn check_header( }; let pre_hash = header.hash(); - let to_sign = (slot_num, pre_hash).encode(); - let public = expected_author; - if P::verify(&sig, &to_sign[..], public) { - match check_equivocation::<_, _,

::Public>( + if P::verify(&sig, pre_hash.as_ref(), expected_author) { + if let Some(equivocation_proof) = check_equivocation( client, slot_now, slot_num, - header.clone(), - public.clone(), - ) { - Ok(Some(equivocation_proof)) => { - let log_str = format!( - "Slot author is equivocating at slot {} with headers {:?} and {:?}", - slot_num, - equivocation_proof.fst_header().hash(), - equivocation_proof.snd_header().hash(), - ); - info!("{}", log_str); - Err(log_str) - }, - Ok(None) => Ok(CheckedHeader::Checked(header, digest_item)), - Err(e) => Err(e.to_string()), + &header, + expected_author, + ).map_err(|e| e.to_string())? { + info!( + "Slot author is equivocating at slot {} with headers {:?} and {:?}", + slot_num, + equivocation_proof.fst_header().hash(), + equivocation_proof.snd_header().hash(), + ); } + + Ok(CheckedHeader::Checked(header, (slot_num, seal))) } else { Err(format!("Bad signature on {:?}", hash)) } @@ -535,7 +451,6 @@ pub struct AuraVerifier { extra: E, phantom: PhantomData

, inherent_data_providers: inherents::InherentDataProviders, - allow_old_seals: bool, } impl AuraVerifier @@ -634,20 +549,17 @@ impl Verifier for AuraVerifier where ); // we add one to allow for some small drift. - // FIXME #1019 in the future, alter this queue to allow deferring of headers + // FIXME #1019 in the future, alter this queue to allow deferring of + // headers let checked_header = check_header::( &self.client, slot_now + 1, header, hash, &authorities[..], - self.allow_old_seals, )?; match checked_header { - CheckedHeader::Checked(pre_header, seal) => { - let (slot_num, _) = seal.as_aura_seal() - .expect("check_header always returns a seal digest item; qed"); - + CheckedHeader::Checked(pre_header, (slot_num, seal)) => { // if the body is passed through, we need to use the runtime // to check that the internally-set timestamp in the inherents // actually matches the slot set in the seal. @@ -658,7 +570,7 @@ impl Verifier for AuraVerifier where // skip the inherents verification if the runtime API is old. if self.client .runtime_api() - .has_api_with::, _>(&BlockId::Hash(parent_hash), |v| v >= 2) + .has_api_with::, _>(&BlockId::Hash(parent_hash), |v| v >= 2) .map_err(|e| format!("{:?}", e))? { self.check_inherents( @@ -738,7 +650,7 @@ fn initialize_authorities_cache(client: &C) -> Result<(), ConsensusError> return Ok(()); } - let map_err = |error| consensus_common::Error::from(consensus_common::ErrorKind::ClientImport( + let map_err = |error| consensus_common::Error::from(consensus_common::Error::ClientImport( format!( "Error initializing authorities cache: {}", error, @@ -758,15 +670,12 @@ fn authorities(client: &C, at: &BlockId) -> Result>(at).unwrap_or(false) { - AuthoritiesApi::authorities(&*client.runtime_api(), at).ok() - } else { - CoreApi::authorities(&*client.runtime_api(), at).ok() - } - }).ok_or_else(|| consensus_common::ErrorKind::InvalidAuthoritiesSet.into()) + .and_then(|cache| cache + .get_at(&well_known_cache_keys::AUTHORITIES, at) + .and_then(|v| Decode::decode(&mut &v[..])) + ) + .or_else(|| AuthoritiesApi::authorities(&*client.runtime_api(), at).ok()) + .ok_or_else(|| consensus_common::Error::InvalidAuthoritiesSet.into()) } /// The Aura import queue type. @@ -780,7 +689,8 @@ fn register_aura_inherent_data_provider( if !inherent_data_providers.has_provider(&srml_aura::INHERENT_IDENTIFIER) { inherent_data_providers .register_provider(srml_aura::InherentDataProvider::new(slot_duration)) - .map_err(inherent_to_common_error) + .map_err(Into::into) + .map_err(consensus_common::Error::InherentData) } else { Ok(()) } @@ -815,52 +725,6 @@ pub fn import_queue( extra, inherent_data_providers, phantom: PhantomData, - allow_old_seals: false, - } - ); - Ok(BasicQueue::new( - verifier, - block_import, - justification_import, - finality_proof_import, - finality_proof_request_builder, - )) -} - -/// Start an import queue for the Aura consensus algorithm with backwards compatibility. -#[deprecated( - since = "1.0.1", - note = "should not be used unless backwards compatibility with an older chain is needed.", -)] -pub fn import_queue_accept_old_seals( - slot_duration: SlotDuration, - block_import: SharedBlockImport, - justification_import: Option>, - finality_proof_import: Option>, - finality_proof_request_builder: Option>, - client: Arc, - extra: E, - inherent_data_providers: InherentDataProviders, -) -> Result, consensus_common::Error> where - B: Block, - C: 'static + ProvideRuntimeApi + ProvideCache + Send + Sync + AuxStore, - C::Api: BlockBuilderApi + AuthoritiesApi, - DigestItemFor: CompatibleDigestItem

+ DigestItem>, - E: 'static + ExtraVerification, - P: Pair + Send + Sync + 'static, - P::Public: Clone + Eq + Send + Sync + Hash + Debug + Encode + Decode + AsRef, - P::Signature: Encode + Decode, -{ - register_aura_inherent_data_provider(&inherent_data_providers, slot_duration.get())?; - initialize_authorities_cache(&*client)?; - - let verifier = Arc::new( - AuraVerifier { - client: client.clone(), - extra, - inherent_data_providers, - phantom: PhantomData, - allow_old_seals: true, } ); Ok(BasicQueue::new( @@ -875,10 +739,11 @@ pub fn import_queue_accept_old_seals( #[cfg(test)] mod tests { use super::*; + use futures::stream::Stream as _; use consensus_common::NoNetwork as DummyOracle; use network::test::*; use network::test::{Block as TestBlock, PeersClient, PeersFullClient}; - use runtime_primitives::traits::Block as BlockT; + use runtime_primitives::traits::{Block as BlockT, DigestFor}; use network::config::ProtocolConfig; use parking_lot::Mutex; use tokio::runtime::current_thread; @@ -886,9 +751,6 @@ mod tests { use primitives::sr25519; use client::{LongestChain, BlockchainEvents}; use test_client; - use primitives::hash::H256; - use runtime_primitives::testing::{Header as HeaderTest, Digest as DigestTest, Block as RawBlock, ExtrinsicWrapper}; - use slots::{MAX_SLOT_CAPACITY, PRUNING_BOUND}; type Error = client::error::Error; @@ -912,8 +774,13 @@ mod tests { type Error = Error; type Create = Result; - fn propose(&self, _: InherentData, _: Duration) -> Result { - self.1.new_block().unwrap().bake().map_err(|e| e.into()) + fn propose( + &self, + _: InherentData, + digests: DigestFor, + _: Duration, + ) -> Result { + self.1.new_block(digests).unwrap().bake().map_err(|e| e.into()) } } @@ -957,13 +824,16 @@ mod tests { extra: NothingExtra, inherent_data_providers, phantom: Default::default(), - allow_old_seals: false, }) }, PeersClient::Light(_) => unreachable!("No (yet) tests for light client + Aura"), } } + fn uses_tokio(&self) -> bool { + true + } + fn peer(&self, i: usize) -> &Peer { &self.peers[i] } @@ -985,27 +855,8 @@ mod tests { } } - fn create_header(slot_num: u64, number: u64, pair: &sr25519::Pair) -> (HeaderTest, H256) { - let mut header = HeaderTest { - parent_hash: Default::default(), - number, - state_root: Default::default(), - extrinsics_root: Default::default(), - digest: DigestTest { logs: vec![], }, - }; - let header_hash: H256 = header.hash(); - let to_sign = (slot_num, header_hash).encode(); - let signature = pair.sign(&to_sign[..]); - - let item = as CompatibleDigestItem>::aura_seal( - slot_num, - signature, - ); - header.digest_mut().push(item); - (header, header_hash) - } - #[test] + #[allow(deprecated)] fn authoring_blocks() { let _ = ::env_logger::try_init(); let mut net = AuraTestNet::new(3); @@ -1024,9 +875,9 @@ mod tests { let mut runtime = current_thread::Runtime::new().unwrap(); for (peer_id, key) in peers { let client = net.lock().peer(*peer_id).client().as_full().expect("full clients are created").clone(); + #[allow(deprecated)] let select_chain = LongestChain::new( client.backend().clone(), - client.import_lock().clone(), ); let environ = Arc::new(DummyFactory(client.clone())); import_notifications.push( @@ -1051,7 +902,6 @@ mod tests { client, environ.clone(), DummyOracle, - futures::empty(), inherent_data_providers, false, ).expect("Starts aura"); @@ -1064,7 +914,7 @@ mod tests { .map(|_| ()) .map_err(|_| ()); - let drive_to_completion = ::tokio::timer::Interval::new_interval(TEST_ROUTING_INTERVAL) + let drive_to_completion = ::tokio_timer::Interval::new_interval(TEST_ROUTING_INTERVAL) .for_each(move |_| { net.lock().send_import_notifications(); net.lock().sync_without_disconnects(); @@ -1080,50 +930,11 @@ mod tests { fn authorities_call_works() { let client = test_client::new(); - assert_eq!(client.info().unwrap().chain.best_number, 0); + assert_eq!(client.info().chain.best_number, 0); assert_eq!(authorities(&client, &BlockId::Number(0)).unwrap(), vec![ Keyring::Alice.into(), Keyring::Bob.into(), Keyring::Charlie.into() ]); } - - #[test] - fn check_header_works_with_equivocation() { - let client = test_client::new(); - let pair = sr25519::Pair::generate(); - let public = pair.public(); - let authorities = vec![public.clone(), sr25519::Pair::generate().public()]; - - let (header1, header1_hash) = create_header(2, 1, &pair); - let (header2, header2_hash) = create_header(2, 2, &pair); - let (header3, header3_hash) = create_header(4, 2, &pair); - let (header4, header4_hash) = create_header(MAX_SLOT_CAPACITY + 4, 3, &pair); - let (header5, header5_hash) = create_header(MAX_SLOT_CAPACITY + 4, 4, &pair); - let (header6, header6_hash) = create_header(4, 3, &pair); - - type B = RawBlock>; - type P = sr25519::Pair; - - let c = Arc::new(client); - - // It's ok to sign same headers. - assert!(check_header::<_, B, P>(&c, 2, header1.clone(), header1_hash, &authorities, false).is_ok()); - assert!(check_header::<_, B, P>(&c, 3, header1, header1_hash, &authorities, false).is_ok()); - - // But not two different headers at the same slot. - assert!(check_header::<_, B, P>(&c, 4, header2, header2_hash, &authorities, false).is_err()); - - // Different slot is ok. - assert!(check_header::<_, B, P>(&c, 5, header3, header3_hash, &authorities, false).is_ok()); - - // Here we trigger pruning and save header 4. - assert!(check_header::<_, B, P>(&c, PRUNING_BOUND + 2, header4, header4_hash, &authorities, false).is_ok()); - - // This fails because header 5 is an equivocation of header 4. - assert!(check_header::<_, B, P>(&c, PRUNING_BOUND + 3, header5, header5_hash, &authorities, false).is_err()); - - // This is ok because we pruned the corresponding header. Shows that we are pruning. - assert!(check_header::<_, B, P>(&c, PRUNING_BOUND + 4, header6, header6_hash, &authorities, false).is_ok()); - } } diff --git a/core/consensus/babe/Cargo.toml b/core/consensus/babe/Cargo.toml index 8ecfa05c4d48546b0c849c3acf186eaa62d4d3ca..1eaf05e4a0b83bb563de470da6f88954990cbbfb 100644 --- a/core/consensus/babe/Cargo.toml +++ b/core/consensus/babe/Cargo.toml @@ -23,9 +23,8 @@ authorities = { package = "substrate-consensus-authorities", path = "../authorit slots = { package = "substrate-consensus-slots", path = "../slots" } runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } futures = "0.1.26" -tokio = "0.1.18" -parking_lot = "0.7.1" -error-chain = "0.12.0" +tokio-timer = "0.2.11" +parking_lot = "0.8.0" log = "0.4.6" schnorrkel = "0.1.1" rand = "0.6.5" @@ -36,5 +35,6 @@ keyring = { package = "substrate-keyring", path = "../../keyring" } substrate-executor = { path = "../../executor" } network = { package = "substrate-network", path = "../../network", features = ["test-helpers"]} service = { package = "substrate-service", path = "../../service" } -test_client = { package = "substrate-test-client", path = "../../test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" } +tokio = "0.1.18" env_logger = "0.6.1" diff --git a/core/consensus/babe/primitives/src/lib.rs b/core/consensus/babe/primitives/src/lib.rs index 83ba6ccba2bbc377d0b6c35379c68fee6e9821d8..0e49c451983cce36ac9685e1ba33f0c87d833823 100644 --- a/core/consensus/babe/primitives/src/lib.rs +++ b/core/consensus/babe/primitives/src/lib.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see . //! Primitives for BABE. -#![forbid(warnings, unsafe_code, missing_docs)] +#![deny(warnings, unsafe_code, missing_docs)] #![cfg_attr(not(feature = "std"), no_std)] use runtime_primitives::ConsensusEngineId; diff --git a/core/consensus/babe/src/digest.rs b/core/consensus/babe/src/digest.rs new file mode 100644 index 0000000000000000000000000000000000000000..b26a1508b59927a468c58971debc67749756f31b --- /dev/null +++ b/core/consensus/babe/src/digest.rs @@ -0,0 +1,149 @@ +// 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 . + +//! Private mplementation details of BABE digests. +use primitives::sr25519::{Public, Signature}; +use babe_primitives::BABE_ENGINE_ID; +use runtime_primitives::generic::DigestItem; +use std::fmt::Debug; +use parity_codec::{Decode, Encode, Input}; +use log::info; +use schnorrkel::{ + vrf::{VRFProof, VRFOutput, VRF_OUTPUT_LENGTH, VRF_PROOF_LENGTH}, + PUBLIC_KEY_LENGTH, +}; + +/// A BABE pre-digest. It includes: +/// +/// * The public key of the author. +/// * The VRF proof. +/// * The VRF output. +/// * The slot number. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct BabePreDigest { + pub(super) vrf_output: VRFOutput, + pub(super) proof: VRFProof, + pub(super) author: Public, + pub(super) slot_num: u64, +} + +/// The prefix used by BABE for its VRF keys. +pub const BABE_VRF_PREFIX: &'static [u8] = b"substrate-babe-vrf"; + +type TmpDecode = ( + [u8; VRF_OUTPUT_LENGTH], + [u8; VRF_PROOF_LENGTH], + [u8; PUBLIC_KEY_LENGTH], + u64, +); + +impl Encode for BabePreDigest { + fn encode(&self) -> Vec { + let tmp: TmpDecode = ( + *self.vrf_output.as_bytes(), + self.proof.to_bytes(), + self.author.0, + self.slot_num, + ); + parity_codec::Encode::encode(&tmp) + } +} + +impl Decode for BabePreDigest { + fn decode(i: &mut R) -> Option { + let (output, proof, public_key, slot_num): TmpDecode = Decode::decode(i)?; + Some(BabePreDigest { + proof: VRFProof::from_bytes(&proof).ok()?, + vrf_output: VRFOutput::from_bytes(&output).ok()?, + author: Public(public_key), + slot_num, + }) + } +} + +/// A digest item which is usable with BABE consensus. +pub trait CompatibleDigestItem: Sized { + /// Construct a digest item which contains a BABE pre-digest. + fn babe_pre_digest(seal: BabePreDigest) -> Self; + + /// If this item is an BABE pre-digest, return it. + fn as_babe_pre_digest(&self) -> Option; + + /// Construct a digest item which contains a BABE seal. + fn babe_seal(signature: Signature) -> Self; + + /// If this item is a BABE signature, return the signature. + fn as_babe_seal(&self) -> Option; +} + +impl CompatibleDigestItem for DigestItem> +{ + fn babe_pre_digest(digest: BabePreDigest) -> Self { + DigestItem::PreRuntime(BABE_ENGINE_ID, digest.encode()) + } + + fn as_babe_pre_digest(&self) -> Option { + match self { + DigestItem::PreRuntime(BABE_ENGINE_ID, seal) => { + let decoded = Decode::decode(&mut &seal[..]); + if decoded.is_none() { + info!(target: "babe", "Failed to decode {:?}", seal) + } + decoded + } + _ => { + info!(target: "babe", "Invalid consensus: {:?}!", self); + None + } + } + } + + fn babe_seal(signature: Signature) -> Self { + DigestItem::Seal(BABE_ENGINE_ID, signature.encode()) + } + + fn as_babe_seal(&self) -> Option { + match self { + DigestItem::Seal(BABE_ENGINE_ID, signature) => Decode::decode(&mut &signature[..]), + _ => None, + } + } +} + +impl CompatibleDigestItem for DigestItem +{ + fn babe_pre_digest(digest: BabePreDigest) -> Self { + DigestItem::PreRuntime(BABE_ENGINE_ID, digest.encode()) + } + + fn as_babe_pre_digest(&self) -> Option { + match self { + DigestItem::PreRuntime(BABE_ENGINE_ID, seal) => Decode::decode(&mut &seal[..]), + _ => None, + } + } + + fn babe_seal(signature: Signature) -> Self { + DigestItem::Seal(BABE_ENGINE_ID, signature) + } + + fn as_babe_seal(&self) -> Option { + match self { + DigestItem::Seal(BABE_ENGINE_ID, signature) => Some(signature.clone()), + _ => None, + } + } +} \ No newline at end of file diff --git a/core/consensus/babe/src/lib.rs b/core/consensus/babe/src/lib.rs index 9c6ef697776341b88caf11a3997f93264135e2e2..f28c23de542eff4f0b8d14fc357c000d8e1a4cf8 100644 --- a/core/consensus/babe/src/lib.rs +++ b/core/consensus/babe/src/lib.rs @@ -16,7 +16,7 @@ //! # BABE consensus //! -//! BABE (Blind Assignment for Blockchain Extension) consensus in substrate. +//! BABE (Blind Assignment for Blockchain Extension) consensus in Substrate. //! //! # Stability //! @@ -26,32 +26,42 @@ #![forbid(unsafe_code, missing_docs)] #![deny(warnings)] extern crate core; +mod digest; +use digest::CompatibleDigestItem; +pub use digest::{BabePreDigest, BABE_VRF_PREFIX}; pub use babe_primitives::*; pub use consensus_common::SyncOracle; use consensus_common::ExtraVerification; use runtime_primitives::{generic, generic::BlockId, Justification}; use runtime_primitives::traits::{ Block, Header, Digest, DigestItemFor, DigestItem, ProvideRuntimeApi, AuthorityIdFor, + SimpleBitOps, }; -use std::{sync::Arc, u64, fmt::Debug}; -use parity_codec::{Decode, Encode, Input}; +use std::{sync::Arc, u64, fmt::{Debug, Display}}; +use runtime_support::serde::{Serialize, Deserialize}; +use parity_codec::{Decode, Encode}; use primitives::{ crypto::Pair, - sr25519::{Public, Signature, LocalizedSignature, self}, + sr25519::{Public, Signature, self}, }; use merlin::Transcript; -use inherents::{InherentDataProviders, InherentData, RuntimeString}; -use substrate_telemetry::{telemetry, CONSENSUS_TRACE, CONSENSUS_DEBUG, CONSENSUS_WARN, CONSENSUS_INFO}; +use inherents::{InherentDataProviders, InherentData}; +use substrate_telemetry::{ + telemetry, + CONSENSUS_TRACE, + CONSENSUS_DEBUG, + CONSENSUS_WARN, + CONSENSUS_INFO, +}; use schnorrkel::{ keys::Keypair, vrf::{ - VRFProof, VRFProofBatchable, VRFInOut, VRFOutput, - VRF_OUTPUT_LENGTH, VRF_PROOF_LENGTH, + VRFProof, VRFProofBatchable, VRFInOut, }, - PUBLIC_KEY_LENGTH, SIGNATURE_LENGTH, }; use authorities::AuthoritiesApi; -use consensus_common::{self, Authorities, BlockImport, Environment, Proposer, +use consensus_common::{ + self, Authorities, BlockImport, Environment, Proposer, ForkChoiceStrategy, ImportBlock, BlockOrigin, Error as ConsensusError, }; use srml_babe::{ @@ -69,97 +79,15 @@ use client::{ }; use slots::{CheckedHeader, check_equivocation}; use futures::{Future, IntoFuture, future}; -use tokio::timer::Timeout; +use tokio_timer::Timeout; use log::{error, warn, debug, info, trace}; -use slots::{SlotWorker, SlotInfo, SlotCompatible, slot_now}; - -/// A BABE seal. It includes: -/// -/// * The public key -/// * The VRF proof -/// * The signature -/// * The slot number -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct BabeSeal { - vrf_output: VRFOutput, - proof: VRFProof, - signature: LocalizedSignature, - slot_num: u64, -} - -/// The prefix used by BABE for its VRF keys. -pub const BABE_VRF_PREFIX: &'static [u8] = b"substrate-babe-vrf"; +use slots::{SlotWorker, SlotData, SlotInfo, SlotCompatible, slot_now}; -macro_rules! babe_assert_eq { - ($a: expr, $b: expr) => { - { - let ref a = $a; - let ref b = $b; - if a != b { - error!( - target: "babe", - "Expected {:?} to equal {:?}, but they were not", - stringify!($a), - stringify!($b), - ); - assert_eq!(a, b); - } - } - }; -} - -type TmpDecode = ( - [u8; VRF_OUTPUT_LENGTH], - [u8; VRF_PROOF_LENGTH], - [u8; SIGNATURE_LENGTH], - [u8; PUBLIC_KEY_LENGTH], - u64, -); - -impl Encode for BabeSeal { - fn encode(&self) -> Vec { - let tmp: TmpDecode = ( - *self.vrf_output.as_bytes(), - self.proof.to_bytes(), - self.signature.signature.0, - self.signature.signer.0, - self.slot_num, - ); - let encoded = parity_codec::Encode::encode(&tmp); - if cfg!(any(test, debug_assertions)) { - debug!(target: "babe", "Checking if encoding was correct"); - let decoded_version = Self::decode(&mut &encoded[..]) - .expect("we just encoded this ourselves, so it is correct; qed"); - babe_assert_eq!(decoded_version.proof, self.proof); - babe_assert_eq!(decoded_version.vrf_output, self.vrf_output); - babe_assert_eq!(decoded_version.signature.signature, self.signature.signature); - babe_assert_eq!(decoded_version.signature.signer, self.signature.signer); - babe_assert_eq!(decoded_version.slot_num, self.slot_num); - debug!(target: "babe", "Encoding was correct") - } - encoded - } -} - -impl Decode for BabeSeal { - fn decode(i: &mut R) -> Option { - let (output, proof, sig, public_key, slot_num): TmpDecode = Decode::decode(i)?; - Some(BabeSeal { - proof: VRFProof::from_bytes(&proof).ok()?, - vrf_output: VRFOutput::from_bytes(&output).ok()?, - signature: LocalizedSignature { - signature: Signature(sig), - signer: Public(public_key), - }, - slot_num, - }) - } -} /// A slot duration. Create with `get_or_compute`. // FIXME: Once Rust has higher-kinded types, the duplication between this -// and `super::aura::Config` can be eliminated. +// and `super::babe::Config` can be eliminated. // https://github.com/paritytech/substrate/issues/2434 pub struct Config(slots::SlotDuration); @@ -191,49 +119,6 @@ impl Config { } } -fn inherent_to_common_error(err: RuntimeString) -> consensus_common::Error { - consensus_common::ErrorKind::InherentData(err.into()).into() -} - -/// A digest item which is usable with BABE consensus. -pub trait CompatibleDigestItem: Sized { - /// Construct a digest item which contains a slot number and a signature - /// on the hash. - fn babe_seal(signature: BabeSeal) -> Self; - - /// If this item is an Babe seal, return the slot number and signature. - fn as_babe_seal(&self) -> Option; -} - -impl CompatibleDigestItem for generic::DigestItem - where T: Debug, Hash: Debug -{ - /// Construct a digest item which contains a slot number and a signature - /// on the hash. - fn babe_seal(signature: BabeSeal) -> Self { - generic::DigestItem::Consensus(BABE_ENGINE_ID, signature.encode()) - } - - /// If this item is an BABE seal, return the slot number and signature. - fn as_babe_seal(&self) -> Option { - match self { - generic::DigestItem::Consensus(BABE_ENGINE_ID, seal) => { - match Decode::decode(&mut &seal[..]) { - s @ Some(_) => s, - s @ None => { - info!(target: "babe", "Failed to decode {:?}", seal); - s - } - } - } - _ => { - info!(target: "babe", "Invalid consensus: {:?}!", self); - None - } - } - } -} - struct BabeSlotCompatible; impl SlotCompatible for BabeSlotCompatible { @@ -243,12 +128,13 @@ impl SlotCompatible for BabeSlotCompatible { trace!(target: "babe", "extract timestamp"); data.timestamp_inherent_data() .and_then(|t| data.babe_inherent_data().map(|a| (t, a))) - .map_err(slots::inherent_to_common_error) + .map_err(Into::into) + .map_err(consensus_common::Error::InherentData) } } /// Parameters for BABE. -pub struct BabeParams { +pub struct BabeParams { /// The configuration for BABE. Includes the slot duration, threshold, and /// other parameters. @@ -272,9 +158,6 @@ pub struct BabeParams { /// A sync oracle pub sync_oracle: SO, - /// Exit callback. - pub on_exit: OnExit, - /// Providers for inherent data. pub inherent_data_providers: InherentDataProviders, @@ -283,7 +166,7 @@ pub struct BabeParams { } /// Start the babe worker. The returned future should be run in a tokio runtime. -pub fn start_babe(BabeParams { +pub fn start_babe(BabeParams { config, local_key, client, @@ -291,44 +174,46 @@ pub fn start_babe(BabeParams { block_import, env, sync_oracle, - on_exit, inherent_data_providers, force_authoring, -}: BabeParams) -> Result< +}: BabeParams) -> Result< impl Future, consensus_common::Error, > where - B: Block, + B: Block, C: ProvideRuntimeApi + ProvideCache, C::Api: AuthoritiesApi, - E: Environment, + SC: SelectChain, + generic::DigestItem: DigestItem, E::Proposer: Proposer, <>::Create as IntoFuture>::Future: Send + 'static, + DigestItemFor: CompatibleDigestItem + DigestItem, + H: Header< + Digest=generic::Digest>, + Hash=B::Hash, + >, + E: Environment, I: BlockImport + Send + Sync + 'static, + Error: std::error::Error + Send + From<::consensus_common::Error> + From + 'static, SO: SyncOracle + Send + Sync + Clone, - SC: SelectChain, - DigestItemFor: CompatibleDigestItem + DigestItem, - Error: ::std::error::Error + Send + From<::consensus_common::Error> + From + 'static, - OnExit: Future, { let worker = BabeWorker { client: client.clone(), block_import, env, local_key, - inherent_data_providers: inherent_data_providers.clone(), sync_oracle: sync_oracle.clone(), force_authoring, threshold: config.threshold(), }; - slots::start_slot_worker::<_, _, _, _, _, BabeSlotCompatible, _>( + register_babe_inherent_data_provider(&inherent_data_providers, config.0.slot_duration())?; + Ok(slots::start_slot_worker::<_, _, _, _, _, BabeSlotCompatible>( config.0, select_chain, - Arc::new(worker), + worker, sync_oracle, - on_exit, inherent_data_providers - ) + )) } struct BabeWorker { @@ -337,30 +222,29 @@ struct BabeWorker { env: Arc, local_key: Arc, sync_oracle: SO, - inherent_data_providers: InherentDataProviders, force_authoring: bool, threshold: u64, } -impl SlotWorker for BabeWorker where +impl SlotWorker for BabeWorker where + B: Block, C: ProvideRuntimeApi + ProvideCache, C::Api: AuthoritiesApi, E: Environment, E::Proposer: Proposer, <>::Create as IntoFuture>::Future: Send + 'static, + Hash: Debug + Eq + Copy + SimpleBitOps + Encode + Decode + Serialize + + for<'de> Deserialize<'de> + Debug + Default + AsRef<[u8]> + AsMut<[u8]> + + std::hash::Hash + Display + Send + Sync + 'static, + H: Header< + Digest=generic::Digest>, + Hash=B::Hash, + >, I: BlockImport + Send + Sync + 'static, SO: SyncOracle + Send + Clone, - DigestItemFor: CompatibleDigestItem + DigestItem, Error: std::error::Error + Send + From<::consensus_common::Error> + From + 'static, { - type OnSlot = Box + Send>; - - fn on_start( - &self, - slot_duration: u64 - ) -> Result<(), consensus_common::Error> { - register_babe_inherent_data_provider(&self.inherent_data_providers, slot_duration) - } + type OnSlot = Box + Send>; fn on_slot( &self, @@ -402,7 +286,7 @@ impl SlotWorker for BabeWorker whe // FIXME replace the dummy empty slices with real data // https://github.com/paritytech/substrate/issues/2435 // https://github.com/paritytech/substrate/issues/2436 - let authoring_result = if let Some((inout, proof, _batchable_proof)) = claim_slot( + let proposal_work = if let Some((inout, proof, _batchable_proof)) = claim_slot( &[0u8; 0], slot_info.number, &[0u8; 0], @@ -432,145 +316,168 @@ impl SlotWorker for BabeWorker whe } }; + let inherent_digest = BabePreDigest { + proof, + vrf_output: inout.to_output(), + author: pair.public(), + slot_num, + }; + + // deadline our production to approx. the end of the slot let remaining_duration = slot_info.remaining_duration(); - // deadline our production to approx. the end of the - // slot - (Timeout::new( + Timeout::new( proposer.propose( slot_info.inherent_data, + generic::Digest { + logs: vec![ + generic::DigestItem::babe_pre_digest(inherent_digest.clone()), + ], + }, remaining_duration, ).into_future(), remaining_duration, - ), - inout.to_output(), - proof) + ) } else { return Box::new(future::ok(())); }; - let (proposal_work, vrf_output, proof) = authoring_result; - - Box::new( - proposal_work - .map(move |b| { - // minor hack since we don't have access to the timestamp - // that is actually set by the proposer. - let slot_after_building = slot_now(slot_duration); - if slot_after_building != Some(slot_num) { - info!( - target: "babe", - "Discarding proposal for slot {}; block production took too long", - slot_num - ); - telemetry!(CONSENSUS_INFO; "babe.discarding_proposal_took_too_long"; - "slot" => slot_num - ); - return - } - - let (header, body) = b.deconstruct(); - let header_num = header.number().clone(); - let pre_hash = header.hash(); - let parent_hash = header.parent_hash().clone(); - - // sign the pre-sealed hash of the block and then - // add it to a digest item. - let to_sign = (slot_num, pre_hash, proof.to_bytes()).encode(); - let signature = pair.sign(&to_sign[..]); - let item = as CompatibleDigestItem>::babe_seal(BabeSeal { - proof, - signature: LocalizedSignature { - signature, - signer: pair.public(), - }, - slot_num, - vrf_output, - }); - - let import_block: ImportBlock = ImportBlock { - origin: BlockOrigin::Own, - header, - justification: None, - post_digests: vec![item], - body: Some(body), - finalized: false, - auxiliary: Vec::new(), - fork_choice: ForkChoiceStrategy::LongestChain, - }; - - info!(target: "babe", - "Pre-sealed block for proposal at {}. Hash now {:?}, previously {:?}.", - header_num, - import_block.post_header().hash(), - pre_hash - ); - telemetry!(CONSENSUS_INFO; "babe.pre_sealed_block"; - "header_num" => ?header_num, - "hash_now" => ?import_block.post_header().hash(), - "hash_previously" => ?pre_hash - ); + Box::new(proposal_work.map(move |b| { + // minor hack since we don't have access to the timestamp + // that is actually set by the proposer. + let slot_after_building = slot_now(slot_duration); + if slot_after_building != Some(slot_num) { + info!( + target: "babe", + "Discarding proposal for slot {}; block production took too long", + slot_num + ); + telemetry!(CONSENSUS_INFO; "babe.discarding_proposal_took_too_long"; + "slot" => slot_num + ); + return + } + + let (header, body) = b.deconstruct(); + let pre_digest: Result = find_pre_digest::(&header); + if let Err(e) = pre_digest { + error!(target: "babe", "FATAL ERROR: Invalid pre-digest: {}!", e); + return + } else { + trace!(target: "babe", "Got correct number of seals. Good!") + }; + + let header_num = header.number().clone(); + let parent_hash = header.parent_hash().clone(); + + // sign the pre-sealed hash of the block and then + // add it to a digest item. + let header_hash = header.hash(); + let signature = pair.sign(header_hash.as_ref()); + let signature_digest_item = DigestItemFor::::babe_seal(signature); + + let import_block: ImportBlock = ImportBlock { + origin: BlockOrigin::Own, + header, + justification: None, + post_digests: vec![signature_digest_item], + body: Some(body), + finalized: false, + auxiliary: Vec::new(), + fork_choice: ForkChoiceStrategy::LongestChain, + }; + + info!(target: "babe", + "Pre-sealed block for proposal at {}. Hash now {:?}, previously {:?}.", + header_num, + import_block.post_header().hash(), + header_hash, + ); + telemetry!(CONSENSUS_INFO; "babe.pre_sealed_block"; + "header_num" => ?header_num, + "hash_now" => ?import_block.post_header().hash(), + "hash_previously" => ?header_hash, + ); - if let Err(e) = block_import.import_block(import_block, Default::default()) { - warn!(target: "babe", "Error with block built on {:?}: {:?}", - parent_hash, e); - telemetry!(CONSENSUS_WARN; "babe.err_with_block_built_on"; - "hash" => ?parent_hash, "err" => ?e - ); - } - }) - .map_err(|e| { - warn!("Client import failed: {:?}", e); - consensus_common::ErrorKind::ClientImport(format!("{:?}", e)).into() - }) - ) + if let Err(e) = block_import.import_block(import_block, Default::default()) { + warn!(target: "babe", "Error with block built on {:?}: {:?}", + parent_hash, e); + telemetry!(CONSENSUS_WARN; "babe.err_with_block_built_on"; + "hash" => ?parent_hash, "err" => ?e + ); + } + }).map_err(|e| { + warn!("Client import failed: {:?}", e); + consensus_common::Error::ClientImport(format!("{:?}", e)).into() + })) } } +macro_rules! babe_err { + ($($i: expr),+) => { + { debug!(target: "babe", $($i),+) + ; format!($($i),+) + } + }; +} + +fn find_pre_digest(header: &B::Header) -> Result + where DigestItemFor: CompatibleDigestItem, +{ + let mut pre_digest: Option<_> = None; + for log in header.digest().logs() { + trace!(target: "babe", "Checking log {:?}", log); + match (log.as_babe_pre_digest(), pre_digest.is_some()) { + (Some(_), true) => Err(babe_err!("Multiple BABE pre-runtime headers, rejecting!"))?, + (None, _) => trace!(target: "babe", "Ignoring digest not meant for us"), + (s, false) => pre_digest = s, + } + } + pre_digest.ok_or_else(|| babe_err!("No BABE pre-runtime digest found")) +} + /// check a header has been signed by the right key. If the slot is too far in /// the future, an error will be returned. If successful, returns the pre-header /// and the digest item containing the seal. /// -/// This digest item will always return `Some` when used with `as_babe_seal`. +/// The seal must be the last digest. Otherwise, the whole header is considered +/// unsigned. This is required for security and must not be changed. +/// +/// This digest item will always return `Some` when used with `as_babe_pre_digest`. // // FIXME #1018 needs misbehavior types #[forbid(warnings)] fn check_header( - client: &Arc, + client: &C, slot_now: u64, mut header: B::Header, hash: B::Hash, authorities: &[Public], threshold: u64, -) -> Result>, String> +) -> Result, DigestItemFor)>, String> where DigestItemFor: CompatibleDigestItem, { trace!(target: "babe", "Checking header"); - let digest_item = match header.digest_mut().pop() { + let seal = match header.digest_mut().pop() { Some(x) => x, - None => return Err(format!("Header {:?} is unsealed", hash)), + None => return Err(babe_err!("Header {:?} is unsealed", hash)), }; - let BabeSeal { - slot_num, - signature: LocalizedSignature { signer, signature }, - proof, - vrf_output, - } = digest_item.as_babe_seal().ok_or_else(|| { - debug!(target: "babe", "Header {:?} is unsealed", hash); - format!("Header {:?} is unsealed", hash) + let sig = seal.as_babe_seal().ok_or_else(|| { + babe_err!("Header {:?} has a bad seal", hash) })?; + let pre_digest = find_pre_digest::(&header)?; + let BabePreDigest { slot_num, ref author, ref proof, ref vrf_output } = pre_digest; + if slot_num > slot_now { - header.digest_mut().push(digest_item); + header.digest_mut().push(seal); Ok(CheckedHeader::Deferred(header, slot_num)) - } else if !authorities.contains(&signer) { - debug!(target: "babe", "Slot Author not found"); - Err("Slot Author not found".to_string()) + } else if !authorities.contains(&author) { + Err(babe_err!("Slot author not found")) } else { let pre_hash = header.hash(); - let to_sign = (slot_num, pre_hash, proof.to_bytes()).encode(); - if sr25519::Pair::verify(&signature, &to_sign[..], &signer) { + if sr25519::Pair::verify(&sig, pre_hash, author) { let (inout, _batchable_proof) = { let transcript = make_transcript( Default::default(), @@ -578,41 +485,38 @@ fn check_header( Default::default(), 0, ); - schnorrkel::PublicKey::from_bytes(signer.as_slice()).and_then(|p| { - p.vrf_verify(transcript, &vrf_output, &proof) + schnorrkel::PublicKey::from_bytes(author.as_slice()).and_then(|p| { + p.vrf_verify(transcript, vrf_output, proof) }).map_err(|s| { - debug!(target: "babe", "VRF verification failed: {:?}", s); - format!("VRF verification failed") + babe_err!("VRF verification failed: {:?}", s) })? }; - - if check(&inout, threshold) { - match check_equivocation(&client, slot_now, slot_num, header.clone(), signer.clone()) { - Ok(Some(equivocation_proof)) => { - let log_str = format!( - "Slot author {:?} is equivocating at slot {} with headers {:?} and {:?}", - signer, - slot_num, - equivocation_proof.fst_header().hash(), - equivocation_proof.snd_header().hash(), - ); - info!("{}", log_str); - Err(log_str) - }, - Ok(None) => { - Ok(CheckedHeader::Checked(header, digest_item)) - }, - Err(e) => { - Err(e.to_string()) - }, - } - } else { - debug!(target: "babe", "VRF verification failed: threshold {} exceeded", threshold); - Err(format!("Validator {:?} made seal when it wasn’t its turn", signer)) + + if !check(&inout, threshold) { + return Err(babe_err!("VRF verification of block by author {:?} failed: \ + threshold {} exceeded", author, threshold)); } + + if let Some(equivocation_proof) = check_equivocation( + client, + slot_now, + slot_num, + &header, + author, + ).map_err(|e| e.to_string())? { + info!( + "Slot author {:?} is equivocating at slot {} with headers {:?} and {:?}", + author, + slot_num, + equivocation_proof.fst_header().hash(), + equivocation_proof.snd_header().hash(), + ); + } + + let pre_digest = CompatibleDigestItem::babe_pre_digest(pre_digest); + Ok(CheckedHeader::Checked(header, (pre_digest, seal))) } else { - debug!(target: "babe", "Bad signature on {:?}", hash); - Err(format!("Bad signature on {:?}", hash)) + Err(babe_err!("Bad signature on {:?}", hash)) } } } @@ -684,6 +588,8 @@ impl Verifier for BabeVerifier where justification, body, ); + + debug!(target: "babe", "We have {:?} logs in this header", header.digest().logs().len()); let mut inherent_data = self .inherent_data_providers .create_inherent_data() @@ -712,9 +618,9 @@ impl Verifier for BabeVerifier where self.threshold, )?; match checked_header { - CheckedHeader::Checked(pre_header, seal) => { - let BabeSeal { slot_num, .. } = seal.as_babe_seal() - .expect("check_header always returns a seal digest item; qed"); + CheckedHeader::Checked(pre_header, (pre_digest, seal)) => { + let BabePreDigest { slot_num, .. } = pre_digest.as_babe_pre_digest() + .expect("check_header always returns a pre-digest digest item; qed"); // if the body is passed through, we need to use the runtime // to check that the internally-set timestamp in the inherents @@ -741,6 +647,10 @@ impl Verifier for BabeVerifier where extra_verification.into_future().wait()?; + let new_authorities = pre_header.digest() + .log(DigestItem::as_authorities_change) + .map(|digest| digest.to_vec()); + let import_block = ImportBlock { origin, header: pre_header, @@ -753,7 +663,7 @@ impl Verifier for BabeVerifier where }; // FIXME #1019 extract authorities - Ok((import_block, None)) + Ok((import_block, new_authorities)) } CheckedHeader::Deferred(a, b) => { debug!(target: "babe", "Checking {:?} failed; {:?}, {:?}.", hash, a, b); @@ -791,13 +701,13 @@ fn authorities(client: &C, at: &BlockId) -> Result< .and_then(|cache| cache.get_at(&well_known_cache_keys::AUTHORITIES, at) .and_then(|v| Decode::decode(&mut &v[..]))) .or_else(|| { - if client.runtime_api().has_api::>(at).unwrap_or(false) { + if client.runtime_api().has_api::>(at).unwrap_or(false) { AuthoritiesApi::authorities(&*client.runtime_api(), at).ok() } else { panic!("We don’t support deprecated code with new consensus algorithms, \ therefore this is unreachable; qed") } - }).ok_or_else(|| consensus_common::ErrorKind::InvalidAuthoritiesSet.into()) + }).ok_or(consensus_common::Error::InvalidAuthoritiesSet) } /// The BABE import queue type. @@ -812,7 +722,8 @@ fn register_babe_inherent_data_provider( if !inherent_data_providers.has_provider(&srml_babe::INHERENT_IDENTIFIER) { inherent_data_providers .register_provider(srml_babe::InherentDataProvider::new(slot_duration)) - .map_err(inherent_to_common_error) + .map_err(Into::into) + .map_err(consensus_common::Error::InherentData) } else { Ok(()) } @@ -822,6 +733,7 @@ fn get_keypair(q: &sr25519::Pair) -> &Keypair { q.as_ref() } +#[allow(deprecated)] fn make_transcript( randomness: &[u8], slot_number: u64, @@ -873,7 +785,8 @@ fn claim_slot( #[cfg(test)] #[allow(dead_code, unused_imports, deprecated)] -// FIXME #2532: need to allow deprecated until refactor is done https://github.com/paritytech/substrate/issues/2532 +// FIXME #2532: need to allow deprecated until refactor is done +// https://github.com/paritytech/substrate/issues/2532 mod tests { use super::*; @@ -882,20 +795,19 @@ mod tests { use consensus_common::NoNetwork as DummyOracle; use network::test::*; use network::test::{Block as TestBlock, PeersClient}; - use runtime_primitives::traits::Block as BlockT; + use runtime_primitives::traits::{Block as BlockT, DigestFor}; use network::config::ProtocolConfig; use parking_lot::Mutex; use tokio::runtime::current_thread; use keyring::sr25519::Keyring; + use super::generic::DigestItem; use client::BlockchainEvents; use test_client; use futures::stream::Stream; use log::debug; use std::time::Duration; + type Item = generic::DigestItem; use test_client::AuthorityKeyring; - use primitives::hash::H256; - use runtime_primitives::testing::{Header as HeaderTest, Digest as DigestTest, Block as RawBlock, ExtrinsicWrapper}; - use slots::{MAX_SLOT_CAPACITY, PRUNING_BOUND}; type Error = client::error::Error; @@ -924,8 +836,8 @@ mod tests { type Error = Error; type Create = Result; - fn propose(&self, _: InherentData, _: Duration) -> Result { - self.1.new_block().unwrap().bake().map_err(|e| e.into()) + fn propose(&self, _: InherentData, digests: DigestFor, _: Duration) -> Result { + self.1.new_block(digests).unwrap().bake().map_err(|e| e.into()) } } @@ -974,6 +886,10 @@ mod tests { }) } + fn uses_tokio(&self) -> bool { + true + } + fn peer(&self, i: usize) -> &Peer { trace!(target: "babe", "Retreiving a peer"); &self.peers[i] @@ -1000,44 +916,10 @@ mod tests { } } - fn create_header(slot_num: u64, number: u64, pair: &sr25519::Pair) -> (HeaderTest, H256) { - let mut header = HeaderTest { - parent_hash: Default::default(), - number, - state_root: Default::default(), - extrinsics_root: Default::default(), - digest: DigestTest { logs: vec![], }, - }; - - let transcript = make_transcript( - Default::default(), - slot_num, - Default::default(), - 0, - ); - - let (inout, proof, _batchable_proof) = get_keypair(&pair).vrf_sign_n_check(transcript, |inout| check(inout, u64::MAX)).unwrap(); - let pre_hash: H256 = header.hash(); - let to_sign = (slot_num, pre_hash, proof.to_bytes()).encode(); - let signature = pair.sign(&to_sign[..]); - let item = as CompatibleDigestItem>::babe_seal(BabeSeal { - proof, - signature: LocalizedSignature { - signature, - signer: pair.public(), - }, - slot_num, - vrf_output: inout.to_output(), - }); - - header.digest_mut().push(item); - (header, pre_hash) - } - #[test] fn can_serialize_block() { drop(env_logger::try_init()); - assert!(BabeSeal::decode(&mut &b""[..]).is_none()); + assert!(BabePreDigest::decode(&mut &b""[..]).is_none()); } #[test] @@ -1077,15 +959,18 @@ mod tests { &inherent_data_providers, config.get() ).expect("Registers babe inherent data provider"); + + #[allow(deprecated)] + let select_chain = LongestChain::new(client.backend().clone()); + let babe = start_babe(BabeParams { config, local_key: Arc::new(key.clone().into()), block_import: client.clone(), - select_chain: LongestChain::new(client.backend().clone(), client.import_lock().clone()), + select_chain, client, env: environ.clone(), sync_oracle: DummyOracle, - on_exit: futures::empty(), inherent_data_providers, force_authoring: false, }).expect("Starts babe"); @@ -1099,7 +984,7 @@ mod tests { .map(drop) .map_err(drop); - let drive_to_completion = ::tokio::timer::Interval::new_interval(TEST_ROUTING_INTERVAL) + let drive_to_completion = ::tokio_timer::Interval::new_interval(TEST_ROUTING_INTERVAL) .for_each(move |_| { net.lock().send_import_notifications(); net.lock().sync_without_disconnects(); @@ -1112,26 +997,28 @@ mod tests { } #[test] - #[allow(deprecated)] - #[should_panic] - fn old_seals_rejected() { + fn wrong_consensus_engine_id_rejected() { drop(env_logger::try_init()); - generic::DigestItem::::Seal(0, Signature([0; 64])).as_babe_seal().unwrap(); + let sig = sr25519::Pair::generate().sign(b""); + let bad_seal: Item = DigestItem::Seal([0; 4], sig); + assert!(bad_seal.as_babe_pre_digest().is_none()); + assert!(bad_seal.as_babe_seal().is_none()) } #[test] - fn wrong_number_rejected() { + fn malformed_pre_digest_rejected() { drop(env_logger::try_init()); - let bad_seal = generic::DigestItem::::Consensus([0; 4], Signature([0; 64]).encode()); - assert!(bad_seal.as_babe_seal().is_none()) + let bad_seal: Item = DigestItem::Seal(BABE_ENGINE_ID, Signature([0; 64])); + assert!(bad_seal.as_babe_pre_digest().is_none()); } #[test] - #[should_panic] - fn bad_seal_rejected() { + fn sig_is_not_pre_digest() { drop(env_logger::try_init()); - let bad_seal = generic::DigestItem::::Consensus(BABE_ENGINE_ID, Signature([0; 64]).encode()); - bad_seal.as_babe_seal().expect("we should not decode this successfully"); + let sig = sr25519::Pair::generate().sign(b""); + let bad_seal: Item = DigestItem::Seal(BABE_ENGINE_ID, sig); + assert!(bad_seal.as_babe_pre_digest().is_none()); + assert!(bad_seal.as_babe_seal().is_some()) } #[test] @@ -1156,51 +1043,11 @@ mod tests { drop(env_logger::try_init()); let client = test_client::new(); - assert_eq!(client.info().unwrap().chain.best_number, 0); + assert_eq!(client.info().chain.best_number, 0); assert_eq!(authorities(&client, &BlockId::Number(0)).unwrap(), vec![ Keyring::Alice.into(), Keyring::Bob.into(), Keyring::Charlie.into() ]); } - - #[test] - fn check_header_works_with_equivocation() { - let client = test_client::new(); - let pair = sr25519::Pair::generate(); - let public = pair.public(); - let authorities = vec![public.clone(), sr25519::Pair::generate().public()]; - - let (header1, header1_hash) = create_header(2, 1, &pair); - let (header2, header2_hash) = create_header(2, 2, &pair); - let (header3, header3_hash) = create_header(4, 2, &pair); - let (header4, header4_hash) = create_header(MAX_SLOT_CAPACITY + 4, 3, &pair); - let (header5, header5_hash) = create_header(MAX_SLOT_CAPACITY + 4, 4, &pair); - let (header6, header6_hash) = create_header(4, 3, &pair); - - let c = Arc::new(client); - let max = u64::MAX; - - type B = RawBlock>; - type P = sr25519::Pair; - - // It's ok to sign same headers. - assert!(check_header::(&c, 2, header1.clone(), header1_hash, &authorities, max).is_ok()); - assert!(check_header::(&c, 3, header1, header1_hash, &authorities, max).is_ok()); - - // But not two different headers at the same slot. - assert!(check_header::(&c, 4, header2, header2_hash, &authorities, max).is_err()); - - // Different slot is ok. - assert!(check_header::(&c, 5, header3, header3_hash, &authorities, max).is_ok()); - - // Here we trigger pruning and save header 4. - assert!(check_header::(&c, PRUNING_BOUND + 2, header4, header4_hash, &authorities, max).is_ok()); - - // This fails because header 5 is an equivocation of header 4. - assert!(check_header::(&c, PRUNING_BOUND + 3, header5, header5_hash, &authorities, max).is_err()); - - // This is ok because we pruned the corresponding header. Shows that we are pruning. - assert!(check_header::(&c, PRUNING_BOUND + 4, header6, header6_hash, &authorities, max).is_ok()); - } } diff --git a/core/consensus/common/Cargo.toml b/core/consensus/common/Cargo.toml index 52a2c6a1c4b7f4a8dd148ed6374d51134a07ed47..2852f4aa0fe8e22092814049eb652d8475f2ddd3 100644 --- a/core/consensus/common/Cargo.toml +++ b/core/consensus/common/Cargo.toml @@ -6,20 +6,22 @@ description = "Common utilities for substrate consensus" edition = "2018" [dependencies] +derive_more = "0.14.0" crossbeam-channel = "0.3.4" -libp2p = { version = "0.7.0", default-features = false } +libp2p = { version = "0.9.0", default-features = false } log = "0.4" primitives = { package = "substrate-primitives", path= "../../primitives" } inherents = { package = "substrate-inherents", path = "../../inherents" } -error-chain = "0.12" futures = "0.1" +rstd = { package = "sr-std", path = "../../sr-std" } runtime_version = { package = "sr-version", path = "../../sr-version" } runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } tokio-timer = "0.2" parity-codec = { version = "3.3", features = ["derive"] } +parking_lot = "0.8.0" [dev-dependencies] -test_client = { package = "substrate-test-client", path = "../../test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" } [features] default = [] diff --git a/core/consensus/common/src/block_import.rs b/core/consensus/common/src/block_import.rs index 1a6a8d1f5078dbdc99f267399a7bff259b28bc72..8ce60191316dce711dc4f740970fbf03ff5e6b33 100644 --- a/core/consensus/common/src/block_import.rs +++ b/core/consensus/common/src/block_import.rs @@ -197,7 +197,7 @@ pub trait JustificationImport { type Error: ::std::error::Error + Send + 'static; /// Called by the import queue when it is started. - fn on_start(&self, _link: &crate::import_queue::Link) { } + fn on_start(&self, _link: &dyn crate::import_queue::Link) { } /// Import a Block justification and finalize the given block. fn import_justification( @@ -210,10 +210,10 @@ pub trait JustificationImport { /// Finality proof import trait. pub trait FinalityProofImport { - type Error: ::std::error::Error + Send + 'static; + type Error: std::error::Error + Send + 'static; /// Called by the import queue when it is started. - fn on_start(&self, _link: &crate::import_queue::Link) { } + fn on_start(&self, _link: &dyn crate::import_queue::Link) { } /// Import a Block justification and finalize the given block. Returns finalized block or error. fn import_finality_proof( @@ -221,7 +221,7 @@ pub trait FinalityProofImport { hash: B::Hash, number: NumberFor, finality_proof: Vec, - verifier: &Verifier, + verifier: &dyn Verifier, ) -> Result<(B::Hash, NumberFor), Self::Error>; } diff --git a/core/consensus/common/src/error.rs b/core/consensus/common/src/error.rs index 71517c544062e5790c9d6677c4f5d27feeb5aa97..d8683d0b685472de860b405aef7c728e71a84704 100644 --- a/core/consensus/common/src/error.rs +++ b/core/consensus/common/src/error.rs @@ -16,100 +16,69 @@ //! Error types in Consensus use runtime_version::RuntimeVersion; -use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed, - impl_extract_backtrace, impl_error_chain_kind}; use primitives::ed25519::{Public, Signature}; +use std::error; + +/// Result type alias. +pub type Result = std::result::Result; + +/// Error type. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Missing state at block with given descriptor. + #[display(fmt="State unavailable at block {}", _0)] + StateUnavailable(String), + /// I/O terminated unexpectedly + #[display(fmt="I/O terminated unexpectedly.")] + IoTerminated, + /// Unable to schedule wakeup. + #[display(fmt="Timer error: {}", _0)] + FaultyTimer(tokio_timer::Error), + /// Error while working with inherent data. + #[display(fmt="InherentData error: {}", _0)] + InherentData(String), + /// Unable to propose a block. + #[display(fmt="Unable to create block proposal.")] + CannotPropose, + /// Error checking signature + #[display(fmt="Message signature {:?} by {:?} is invalid.", _0, _1)] + InvalidSignature(Signature, Public), + /// Invalid authorities set received from the runtime. + #[display(fmt="Current state of blockchain has invalid authorities set")] + InvalidAuthoritiesSet, + /// Account is not an authority. + #[display(fmt="Message sender {:?} is not a valid authority.", _0)] + InvalidAuthority(Public), + /// Authoring interface does not match the runtime. + #[display(fmt="Authoring for current \ + runtime is not supported. Native ({}) cannot author for on-chain ({}).", native, on_chain)] + IncompatibleAuthoringRuntime { native: RuntimeVersion, on_chain: RuntimeVersion }, + /// Authoring interface does not match the runtime. + #[display(fmt="Authoring for current runtime is not supported since it has no version.")] + RuntimeVersionMissing, + /// Authoring interface does not match the runtime. + #[display(fmt="Authoring in current build is not supported since it has no runtime.")] + NativeRuntimeMissing, + /// Justification requirements not met. + #[display(fmt="Invalid justification.")] + InvalidJustification, + /// Some other error. + #[display(fmt="Other error: {}", _0)] + Other(Box), + /// Error from the client while importing + #[display(fmt="Import failed: {}", _0)] + ClientImport(String), + /// Error from the client while importing + #[display(fmt="Chain lookup failed: {}", _0)] + ChainLookup(String), +} -error_chain! { - errors { - /// Missing state at block with given descriptor. - StateUnavailable(b: String) { - description("State missing at given block."), - display("State unavailable at block {}", b), - } - - /// I/O terminated unexpectedly - IoTerminated { - description("I/O terminated unexpectedly."), - display("I/O terminated unexpectedly."), - } - - /// Unable to schedule wakeup. - FaultyTimer(e: ::tokio_timer::Error) { - description("Timer error"), - display("Timer error: {}", e), - } - - /// Error while working with inherent data. - InherentData(e: String) { - description("InherentData error"), - display("InherentData error: {}", e), - } - - /// Unable to propose a block. - CannotPropose { - description("Unable to create block proposal."), - display("Unable to create block proposal."), - } - - /// Error checking signature - InvalidSignature(s: Signature, a: Public) { - description("Message signature is invalid"), - display("Message signature {:?} by {:?} is invalid.", s, a), - } - - /// Invalid authorities set received from the runtime. - InvalidAuthoritiesSet { - description("authorities set is invalid"), - display("Current state of blockchain has invalid authorities set"), - } - - /// Account is not an authority. - InvalidAuthority(a: Public) { - description("Message sender is not a valid authority"), - display("Message sender {:?} is not a valid authority.", a), - } - - /// Authoring interface does not match the runtime. - IncompatibleAuthoringRuntime(native: RuntimeVersion, on_chain: RuntimeVersion) { - description("Authoring for current runtime is not supported"), - display("Authoring for current runtime is not supported. Native ({}) cannot author for on-chain ({}).", native, on_chain), - } - - /// Authoring interface does not match the runtime. - RuntimeVersionMissing { - description("Current runtime has no version"), - display("Authoring for current runtime is not supported since it has no version."), - } - - /// Authoring interface does not match the runtime. - NativeRuntimeMissing { - description("This build has no native runtime"), - display("Authoring in current build is not supported since it has no runtime."), - } - - /// Justification requirements not met. - InvalidJustification { - description("Invalid justification"), - display("Invalid justification."), - } - - /// Some other error. - Other(e: Box<::std::error::Error + Send>) { - description("Other error") - display("Other error: {}", e.description()) - } - - /// Error from the client while importing - ClientImport(reason: String) { - description("Import failed"), - display("Import failed: {}", reason), - } - - /// Error from the client while importing - ChainLookup(reason: String) { - description("Looking up chain failed"), - display("Chain lookup failed: {}", reason), +impl error::Error for Error { + fn source(&self) -> Option<&(dyn error::Error + 'static)> { + match self { + Error::FaultyTimer(ref err) => Some(err), + Error::Other(ref err) => Some(&**err), + _ => None, } } } diff --git a/core/consensus/common/src/evaluation.rs b/core/consensus/common/src/evaluation.rs index 48016b1e94c93f0b55e8806d8e28cdcc79e6a6bc..ed7515a419194c1cc8ea651a903d89650f03373e 100644 --- a/core/consensus/common/src/evaluation.rs +++ b/core/consensus/common/src/evaluation.rs @@ -19,36 +19,37 @@ use super::MAX_BLOCK_SIZE; use parity_codec::Encode; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As}; -use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed, - impl_extract_backtrace, impl_error_chain_kind, bail}; - -type BlockNumber = u64; - -error_chain! { - errors { - BadProposalFormat { - description("Proposal provided not a block."), - display("Proposal provided not a block."), - } - WrongParentHash(expected: String, got: String) { - description("Proposal had wrong parent hash."), - display("Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got), - } - WrongNumber(expected: BlockNumber, got: BlockNumber) { - description("Proposal had wrong number."), - display("Proposal had wrong number. Expected {}, got {}", expected, got), - } - ProposalTooLarge(size: usize) { - description("Proposal exceeded the maximum size."), - display( - "Proposal exceeded the maximum size of {} by {} bytes.", - MAX_BLOCK_SIZE, size.saturating_sub(MAX_BLOCK_SIZE) - ), - } - } +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, One, CheckedConversion}; + +// This is just a best effort to encode the number. None indicated that it's too big to encode +// in a u128. +type BlockNumber = Option; + +/// Result type alias. +pub type Result = std::result::Result; + +/// Error type. +#[derive(Debug, derive_more::Display)] +pub enum Error { + /// Proposal provided not a block. + #[display(fmt="Proposal provided not a block.")] + BadProposalFormat, + /// Proposal had wrong parent hash. + #[display(fmt="Proposal had wrong parent hash. Expected {:?}, got {:?}", expected, got)] + WrongParentHash { expected: String, got: String }, + /// Proposal had wrong number. + #[display(fmt="Proposal had wrong number. Expected {:?}, got {:?}", expected, got)] + WrongNumber { expected: BlockNumber, got: BlockNumber }, + /// Proposal exceeded the maximum size. + #[display( + fmt="Proposal exceeded the maximum size of {} by {} bytes.", + "MAX_BLOCK_SIZE", "_0.saturating_sub(MAX_BLOCK_SIZE)" + )] + ProposalTooLarge(usize), } +impl std::error::Error for Error {} + /// Attempt to evaluate a substrate block as a node block, returning error /// upon any initial validity checks failing. pub fn evaluate_initial( @@ -59,21 +60,24 @@ pub fn evaluate_initial( let encoded = Encode::encode(proposal); let proposal = Block::decode(&mut &encoded[..]) - .ok_or_else(|| ErrorKind::BadProposalFormat)?; + .ok_or_else(|| Error::BadProposalFormat)?; if encoded.len() > MAX_BLOCK_SIZE { - bail!(ErrorKind::ProposalTooLarge(encoded.len())) + return Err(Error::ProposalTooLarge(encoded.len())) } if *parent_hash != *proposal.header().parent_hash() { - bail!(ErrorKind::WrongParentHash( - format!("{:?}", *parent_hash), - format!("{:?}", proposal.header().parent_hash()) - )); + return Err(Error::WrongParentHash { + expected: format!("{:?}", *parent_hash), + got: format!("{:?}", proposal.header().parent_hash()) + }); } - if parent_number.as_() + 1 != proposal.header().number().as_() { - bail!(ErrorKind::WrongNumber(parent_number.as_() + 1, proposal.header().number().as_())); + if parent_number + One::one() != *proposal.header().number() { + return Err(Error::WrongNumber { + expected: parent_number.checked_into::().map(|x| x + 1), + got: (*proposal.header().number()).checked_into::(), + }); } Ok(()) diff --git a/core/consensus/common/src/import_queue.rs b/core/consensus/common/src/import_queue.rs index 4d64d799b18b73f0f8a009cb1b3aa15f222163b8..118bc641b2f7b0bde30425c07d140b0396db2d39 100644 --- a/core/consensus/common/src/import_queue.rs +++ b/core/consensus/common/src/import_queue.rs @@ -31,12 +31,13 @@ use crate::block_import::{ }; use crossbeam_channel::{self as channel, Receiver, Sender}; use parity_codec::Encode; +use parking_lot::Mutex; use std::sync::Arc; use std::thread; use runtime_primitives::traits::{ - AuthorityIdFor, Block as BlockT, Header as HeaderT, NumberFor + AuthorityIdFor, Block as BlockT, Header as HeaderT, NumberFor, Digest, }; use runtime_primitives::Justification; @@ -97,16 +98,14 @@ pub trait Verifier: Send + Sync { } /// Blocks import queue API. -pub trait ImportQueue: Send + Sync + ImportQueueClone { +pub trait ImportQueue: Send + Sync { /// Start background work for the queue as necessary. /// /// This is called automatically by the network service when synchronization /// begins. - fn start(&self, _link: Box>) -> Result<(), std::io::Error> { + fn start(&self, _link: Box>) -> Result<(), std::io::Error> { Ok(()) } - /// Clears the import queue and stops importing. - fn stop(&self); /// Import bunch of blocks. fn import_blocks(&self, origin: BlockOrigin, blocks: Vec>); /// Import a block justification. @@ -115,13 +114,96 @@ pub trait ImportQueue: Send + Sync + ImportQueueClone { fn import_finality_proof(&self, who: Origin, hash: B::Hash, number: NumberFor, finality_proof: Vec); } -pub trait ImportQueueClone { - fn clone_box(&self) -> Box>; +/// Basic block import queue that performs import in the caller thread. +pub struct BasicSyncQueue> { + data: Arc>, } -impl Clone for Box> { - fn clone(&self) -> Box> { - self.clone_box() +struct BasicSyncQueueData> { + link: Mutex>>>, + block_import: SharedBlockImport, + verifier: Arc, + justification_import: Option>, + finality_proof_import: Option>, +} + +impl> BasicSyncQueue { + pub fn new( + block_import: SharedBlockImport, + verifier: Arc, + justification_import: Option>, + finality_proof_import: Option>, + ) -> Self { + BasicSyncQueue { + data: Arc::new(BasicSyncQueueData { + link: Mutex::new(None), + block_import, + verifier, + justification_import, + finality_proof_import, + }), + } + } +} + +impl> ImportQueue for BasicSyncQueue { + fn start(&self, link: Box>) -> Result<(), std::io::Error> { + if let Some(justification_import) = self.data.justification_import.as_ref() { + justification_import.on_start(&*link); + } + *self.data.link.lock() = Some(link); + Ok(()) + } + + fn import_blocks(&self, origin: BlockOrigin, blocks: Vec>) { + if blocks.is_empty() { + return; + } + + let (imported, count, results) = import_many_blocks( + &*self.data.block_import, + origin, + blocks, + self.data.verifier.clone(), + ); + + let link_ref = self.data.link.lock(); + let link = match link_ref.as_ref() { + Some(link) => link, + None => { + trace!(target: "sync", "Trying to import blocks before starting import queue"); + return; + }, + }; + + process_import_results(&**link, results); + + trace!(target: "sync", "Imported {} of {}", imported, count); + } + + fn import_justification(&self, who: Origin, hash: B::Hash, number: NumberFor, justification: Justification) { + import_single_justification( + &*self.data.link.lock(), + &self.data.justification_import, + who, + hash, + number, + justification, + ) + } + + fn import_finality_proof(&self, who: Origin, hash: B::Hash, number: NumberFor, finality_proof: Vec) { + let result = import_single_finality_proof( + &self.data.finality_proof_import, + &*self.data.verifier, + &who, + hash, + number, + finality_proof, + ); + if let Some(link) = self.data.link.lock().as_ref() { + link.finality_proof_imported(who, (hash, number), result); + } } } @@ -129,16 +211,20 @@ impl Clone for Box> { /// sequentially in a separate thread, with pluggable verification. #[derive(Clone)] pub struct BasicQueue { - sender: Sender>, + sender: Option>>, } -impl ImportQueueClone for BasicQueue { - fn clone_box(&self) -> Box> { - Box::new(self.clone()) +impl Drop for BasicQueue { + fn drop(&mut self) { + if let Some(sender) = self.sender.take() { + let (shutdown_sender, shutdown_receiver) = channel::unbounded(); + if sender.send(BlockImportMsg::Shutdown(shutdown_sender)).is_ok() { + let _ = shutdown_receiver.recv(); + } + } } } - /// "BasicQueue" is a wrapper around a channel sender to the "BlockImporter". /// "BasicQueue" itself does not keep any state or do any importing work, and /// can therefore be send to other threads. @@ -184,7 +270,7 @@ impl BasicQueue { ); Self { - sender: importer_sender, + sender: Some(importer_sender), } } @@ -194,52 +280,47 @@ impl BasicQueue { /// has synchronized with ImportQueue. #[cfg(any(test, feature = "test-helpers"))] pub fn synchronize(&self) { - self - .sender - .send(BlockImportMsg::Synchronize) - .expect("1. self is holding a sender to the Importer, 2. Importer should handle messages while there are senders around; qed"); + if let Some(ref sender) = self.sender { + let _ = sender.send(BlockImportMsg::Synchronize); + } } } impl ImportQueue for BasicQueue { - fn start(&self, link: Box>) -> Result<(), std::io::Error> { - let (sender, port) = channel::unbounded(); - let _ = self - .sender - .send(BlockImportMsg::Start(link, sender)) - .expect("1. self is holding a sender to the Importer, 2. Importer should handle messages while there are senders around; qed"); - port.recv().expect("1. self is holding a sender to the Importer, 2. Importer should handle messages while there are senders around; qed") - } - - fn stop(&self) { - let _ = self - .sender - .send(BlockImportMsg::Stop) - .expect("1. self is holding a sender to the Importer, 2. Importer should handle messages while there are senders around; qed"); + fn start(&self, link: Box>) -> Result<(), std::io::Error> { + let connect_err = || Err(std::io::Error::new( + std::io::ErrorKind::Other, + "Failed to connect import queue threads", + )); + if let Some(ref sender) = self.sender { + let (start_sender, start_port) = channel::unbounded(); + let _ = sender.send(BlockImportMsg::Start(link, start_sender)); + start_port.recv().unwrap_or_else(|_| connect_err()) + } else { + connect_err() + } } fn import_blocks(&self, origin: BlockOrigin, blocks: Vec>) { if blocks.is_empty() { return; } - let _ = self - .sender - .send(BlockImportMsg::ImportBlocks(origin, blocks)) - .expect("1. self is holding a sender to the Importer, 2. Importer should handle messages while there are senders around; qed"); + + if let Some(ref sender) = self.sender { + let _ = sender.send(BlockImportMsg::ImportBlocks(origin, blocks)); + } } fn import_justification(&self, who: Origin, hash: B::Hash, number: NumberFor, justification: Justification) { - let _ = self - .sender - .send(BlockImportMsg::ImportJustification(who.clone(), hash, number, justification)) - .expect("1. self is holding a sender to the Importer, 2. Importer should handle messages while there are senders around; qed"); + if let Some(ref sender) = self.sender { + let _ = sender.send(BlockImportMsg::ImportJustification(who.clone(), hash, number, justification)); + } } fn import_finality_proof(&self, who: Origin, hash: B::Hash, number: NumberFor, finality_proof: Vec) { - let _ = self - .sender - .send(BlockImportMsg::ImportFinalityProof(who, hash, number, finality_proof)) - .expect("1. self is holding a sender to the Importer, 2. Importer should handle messages while there are senders around; qed"); + if let Some(ref sender) = self.sender { + let _ = sender.send(BlockImportMsg::ImportFinalityProof(who, hash, number, finality_proof)); + } } } @@ -247,13 +328,13 @@ pub enum BlockImportMsg { ImportBlocks(BlockOrigin, Vec>), ImportJustification(Origin, B::Hash, NumberFor, Justification), ImportFinalityProof(Origin, B::Hash, NumberFor, Vec), - Start(Box>, Sender>), - Stop, + Start(Box>, Sender>), + Shutdown(Sender<()>), #[cfg(any(test, feature = "test-helpers"))] Synchronize, } -#[cfg_attr(test, derive(Debug, PartialEq))] +#[cfg_attr(test, derive(Debug))] pub enum BlockImportWorkerMsg { ImportBlocks(BlockOrigin, Vec>), ImportedBlocks( @@ -264,6 +345,7 @@ pub enum BlockImportWorkerMsg { ), ImportFinalityProof(Origin, B::Hash, NumberFor, Vec), ImportedFinalityProof(Origin, (B::Hash, NumberFor), Result<(B::Hash, NumberFor), ()>), + Shutdown(Sender<()>), #[cfg(any(test, feature = "test-helpers"))] Synchronize, } @@ -276,9 +358,9 @@ enum ImportMsgType { struct BlockImporter { port: Receiver>, result_port: Receiver>, - worker_sender: Sender>, + worker_sender: Option>>, link: Option>>, - verifier: Arc>, + verifier: Arc>, justification_import: Option>, finality_proof_import: Option>, finality_proof_request_builder: Option>, @@ -288,7 +370,7 @@ impl BlockImporter { fn new( result_port: Receiver>, worker_sender: Sender>, - verifier: Arc>, + verifier: Arc>, justification_import: Option>, finality_proof_import: Option>, finality_proof_request_builder: Option>, @@ -301,7 +383,7 @@ impl BlockImporter { let mut importer = BlockImporter { port, result_port, - worker_sender, + worker_sender: Some(worker_sender), link: None, verifier, justification_import, @@ -345,7 +427,14 @@ impl BlockImporter { self.handle_import_blocks(origin, incoming_blocks) }, BlockImportMsg::ImportJustification(who, hash, number, justification) => { - self.handle_import_justification(who, hash, number, justification) + import_single_justification( + &self.link, + &self.justification_import, + who, + hash, + number, + justification, + ); }, BlockImportMsg::ImportFinalityProof(who, hash, number, finality_proof) => { self.handle_import_finality_proof(who, hash, number, finality_proof) @@ -363,13 +452,24 @@ impl BlockImporter { self.link = Some(link); let _ = sender.send(Ok(())); }, - BlockImportMsg::Stop => return false, + BlockImportMsg::Shutdown(result_sender) => { + // stop worker thread + if let Some(worker_sender) = self.worker_sender.take() { + let (sender, receiver) = channel::unbounded(); + if worker_sender.send(BlockImportWorkerMsg::Shutdown(sender)).is_ok() { + let _ = receiver.recv(); + } + } + // send shutdown notification + let _ = result_sender.send(()); + return false; + }, #[cfg(any(test, feature = "test-helpers"))] BlockImportMsg::Synchronize => { trace!(target: "sync", "Received synchronization message"); - self.worker_sender - .send(BlockImportWorkerMsg::Synchronize) - .expect("1. This is holding a sender to the worker, 2. the worker should not quit while a sender is still held; qed"); + if let Some(ref worker_sender) = self.worker_sender { + let _ = worker_sender.send(BlockImportWorkerMsg::Synchronize); + } }, } true @@ -398,106 +498,26 @@ impl BlockImporter { }, BlockImportWorkerMsg::ImportBlocks(_, _) | BlockImportWorkerMsg::ImportFinalityProof(_, _, _, _) - => unreachable!("Import Worker does not send Import* message; qed"), + | BlockImportWorkerMsg::Shutdown(_) + => unreachable!("Import Worker does not send Import*/Shutdown messages; qed"), }; - let mut has_error = false; - let mut hashes = vec![]; - for (result, hash) in results { - hashes.push(hash); - - if has_error { - continue; - } - - if result.is_err() { - has_error = true; - } - - match result { - Ok(BlockImportResult::ImportedKnown(number)) => link.block_imported(&hash, number), - Ok(BlockImportResult::ImportedUnknown(number, aux, who)) => { - link.block_imported(&hash, number); - - if aux.clear_justification_requests { - trace!(target: "sync", "Block imported clears all pending justification requests {}: {:?}", number, hash); - link.clear_justification_requests(); - } - - if aux.needs_justification { - trace!(target: "sync", "Block imported but requires justification {}: {:?}", number, hash); - link.request_justification(&hash, number); - } - if aux.bad_justification { - if let Some(peer) = who { - info!("Sent block with bad justification to import"); - link.report_peer(peer, BAD_JUSTIFICATION_REPUTATION_CHANGE); - } - } - - if aux.needs_finality_proof { - trace!(target: "sync", "Block imported but requires finality proof {}: {:?}", number, hash); - link.request_finality_proof(&hash, number); - } - }, - Err(BlockImportError::IncompleteHeader(who)) => { - if let Some(peer) = who { - info!("Peer sent block with incomplete header to import"); - link.report_peer(peer, INCOMPLETE_HEADER_REPUTATION_CHANGE); - link.restart(); - } - }, - Err(BlockImportError::VerificationFailed(who, e)) => { - if let Some(peer) = who { - info!("Verification failed from peer: {}", e); - link.report_peer(peer, VERIFICATION_FAIL_REPUTATION_CHANGE); - link.restart(); - } - }, - Err(BlockImportError::BadBlock(who)) => { - if let Some(peer) = who { - info!("Bad block"); - link.report_peer(peer, BAD_BLOCK_REPUTATION_CHANGE); - link.restart(); - } - }, - Err(BlockImportError::UnknownParent) | Err(BlockImportError::Error) => { - link.restart(); - }, - }; - } - if let Some(link) = self.link.as_ref() { - link.blocks_processed(hashes, has_error); - } + process_import_results(&**link, results); true } - fn handle_import_justification(&self, who: Origin, hash: B::Hash, number: NumberFor, justification: Justification) { - let success = self.justification_import.as_ref().map(|justification_import| { - justification_import.import_justification(hash, number, justification) - .map_err(|e| { - debug!(target: "sync", "Justification import failed with {:?} for hash: {:?} number: {:?} coming from node: {:?}", e, hash, number, who); - e - }).is_ok() - }).unwrap_or(false); - - if let Some(link) = self.link.as_ref() { - link.justification_imported(who, &hash, number, success); - } - } - fn handle_import_finality_proof(&self, who: Origin, hash: B::Hash, number: NumberFor, finality_proof: Vec) { - trace!(target: "sync", "Scheduling finality proof of {}/{} for import", number, hash); - self.worker_sender - .send(BlockImportWorkerMsg::ImportFinalityProof(who, hash, number, finality_proof)) - .expect("1. This is holding a sender to the worker, 2. the worker should not quit while a sender is still held; qed"); + if let Some(ref worker_sender) = self.worker_sender { + trace!(target: "sync", "Scheduling finality proof of {}/{} for import", number, hash); + let _ = worker_sender.send(BlockImportWorkerMsg::ImportFinalityProof(who, hash, number, finality_proof)); + } } fn handle_import_blocks(&mut self, origin: BlockOrigin, blocks: Vec>) { - trace!(target: "sync", "Scheduling {} blocks for import", blocks.len()); - self.worker_sender - .send(BlockImportWorkerMsg::ImportBlocks(origin, blocks)) - .expect("1. This is holding a sender to the worker, 2. the worker should not quit while a sender is still held; qed"); + if let Some(ref worker_sender) = self.worker_sender { + trace!(target: "sync", "Scheduling {} blocks for import", blocks.len()); + let _ = worker_sender.send(BlockImportWorkerMsg::ImportBlocks(origin, blocks)); + } } } @@ -534,6 +554,10 @@ impl> BlockImportWorker { BlockImportWorkerMsg::ImportFinalityProof(who, hash, number, proof) => { worker.import_finality_proof(who, hash, number, proof); }, + BlockImportWorkerMsg::Shutdown(result_sender) => { + let _ = result_sender.send(()); + break; + }, #[cfg(any(test, feature = "test-helpers"))] BlockImportWorkerMsg::Synchronize => { trace!(target: "sync", "Sending sync message"); @@ -550,44 +574,12 @@ impl> BlockImportWorker { } fn import_a_batch_of_blocks(&self, origin: BlockOrigin, blocks: Vec>) { - let count = blocks.len(); - let mut imported = 0; - - let blocks_range = match ( - blocks.first().and_then(|b| b.header.as_ref().map(|h| h.number())), - blocks.last().and_then(|b| b.header.as_ref().map(|h| h.number())), - ) { - (Some(first), Some(last)) if first != last => format!(" ({}..{})", first, last), - (Some(first), Some(_)) => format!(" ({})", first), - _ => Default::default(), - }; - - trace!(target: "sync", "Starting import of {} blocks {}", count, blocks_range); - - let mut results = vec![]; - - let mut has_error = false; - - // Blocks in the response/drain should be in ascending order. - for block in blocks { - let import_result = if has_error { - Err(BlockImportError::Error) - } else { - import_single_block( - &*self.block_import, - origin.clone(), - block.clone(), - self.verifier.clone(), - ) - }; - let was_ok = import_result.is_ok(); - results.push((import_result, block.hash)); - if was_ok { - imported += 1; - } else { - has_error = true; - } - } + let (imported, count, results) = import_many_blocks( + &*self.block_import, + origin, + blocks, + self.verifier.clone(), + ); let _ = self .result_sender @@ -597,24 +589,18 @@ impl> BlockImportWorker { } fn import_finality_proof(&self, who: Origin, hash: B::Hash, number: NumberFor, finality_proof: Vec) { - let result = self.finality_proof_import.as_ref().map(|finality_proof_import| { - finality_proof_import.import_finality_proof(hash, number, finality_proof, &*self.verifier) - .map_err(|e| { - debug!( - "Finality proof import failed with {:?} for hash: {:?} number: {:?} coming from node: {:?}", - e, - hash, - number, - who, - ); - }) - }).unwrap_or(Err(())); + let result = import_single_finality_proof( + &self.finality_proof_import, + &*self.verifier, + &who, + hash, + number, + finality_proof, + ); let _ = self .result_sender .send(BlockImportWorkerMsg::ImportedFinalityProof(who, (hash, number), result)); - - trace!(target: "sync", "Imported finality proof for {}/{}", number, hash); } } @@ -679,9 +665,196 @@ pub enum BlockImportError { Error, } +/// Imports single notification and send notification to the link (if provided). +fn import_single_justification( + link: &Option>>, + justification_import: &Option>, + who: Origin, + hash: B::Hash, + number: NumberFor, + justification: Justification, +) { + let success = justification_import.as_ref().map(|justification_import| { + justification_import.import_justification(hash, number, justification) + .map_err(|e| { + debug!( + target: "sync", + "Justification import failed with {:?} for hash: {:?} number: {:?} coming from node: {:?}", + e, + hash, + number, + who, + ); + e + }).is_ok() + }).unwrap_or(false); + + if let Some(ref link) = link { + link.justification_imported(who, &hash, number, success); + } +} + +/// Imports single finality_proof. +fn import_single_finality_proof>( + finality_proof_import: &Option>, + verifier: &V, + who: &Origin, + hash: B::Hash, + number: NumberFor, + finality_proof: Vec, +) -> Result<(B::Hash, NumberFor), ()> { + let result = finality_proof_import.as_ref().map(|finality_proof_import| { + finality_proof_import.import_finality_proof(hash, number, finality_proof, verifier) + .map_err(|e| { + debug!( + "Finality proof import failed with {:?} for hash: {:?} number: {:?} coming from node: {:?}", + e, + hash, + number, + who, + ); + }) + }).unwrap_or(Err(())); + + trace!(target: "sync", "Imported finality proof for {}/{}", number, hash); + + result +} + +/// Process result of block(s) import. +fn process_import_results( + link: &dyn Link, + results: Vec<( + Result>, BlockImportError>, + B::Hash, + )>, +) +{ + let mut has_error = false; + let mut hashes = vec![]; + for (result, hash) in results { + hashes.push(hash); + + if has_error { + continue; + } + + if result.is_err() { + has_error = true; + } + + match result { + Ok(BlockImportResult::ImportedKnown(number)) => link.block_imported(&hash, number), + Ok(BlockImportResult::ImportedUnknown(number, aux, who)) => { + link.block_imported(&hash, number); + + if aux.clear_justification_requests { + trace!(target: "sync", "Block imported clears all pending justification requests {}: {:?}", number, hash); + link.clear_justification_requests(); + } + + if aux.needs_justification { + trace!(target: "sync", "Block imported but requires justification {}: {:?}", number, hash); + link.request_justification(&hash, number); + } + + if aux.bad_justification { + if let Some(peer) = who { + info!("Sent block with bad justification to import"); + link.report_peer(peer, BAD_JUSTIFICATION_REPUTATION_CHANGE); + } + } + + if aux.needs_finality_proof { + trace!(target: "sync", "Block imported but requires finality proof {}: {:?}", number, hash); + link.request_finality_proof(&hash, number); + } + }, + Err(BlockImportError::IncompleteHeader(who)) => { + if let Some(peer) = who { + info!("Peer sent block with incomplete header to import"); + link.report_peer(peer, INCOMPLETE_HEADER_REPUTATION_CHANGE); + link.restart(); + } + }, + Err(BlockImportError::VerificationFailed(who, e)) => { + if let Some(peer) = who { + info!("Verification failed from peer: {}", e); + link.report_peer(peer, VERIFICATION_FAIL_REPUTATION_CHANGE); + link.restart(); + } + }, + Err(BlockImportError::BadBlock(who)) => { + if let Some(peer) = who { + info!("Bad block"); + link.report_peer(peer, BAD_BLOCK_REPUTATION_CHANGE); + link.restart(); + } + }, + Err(BlockImportError::UnknownParent) | Err(BlockImportError::Error) => { + link.restart(); + }, + }; + } + link.blocks_processed(hashes, has_error); +} + +/// Import several blocks at once, returning import result for each block. +fn import_many_blocks>( + import_handle: &dyn BlockImport, + blocks_origin: BlockOrigin, + blocks: Vec>, + verifier: Arc, +) -> (usize, usize, Vec<( + Result>, BlockImportError>, + B::Hash, +)>) { + let count = blocks.len(); + let mut imported = 0; + + let blocks_range = match ( + blocks.first().and_then(|b| b.header.as_ref().map(|h| h.number())), + blocks.last().and_then(|b| b.header.as_ref().map(|h| h.number())), + ) { + (Some(first), Some(last)) if first != last => format!(" ({}..{})", first, last), + (Some(first), Some(_)) => format!(" ({})", first), + _ => Default::default(), + }; + + trace!(target: "sync", "Starting import of {} blocks {}", count, blocks_range); + + let mut results = vec![]; + + let mut has_error = false; + + // Blocks in the response/drain should be in ascending order. + for block in blocks { + let block_hash = block.hash; + let import_result = if has_error { + Err(BlockImportError::Error) + } else { + import_single_block( + import_handle, + blocks_origin.clone(), + block, + verifier.clone(), + ) + }; + let was_ok = import_result.is_ok(); + results.push((import_result, block_hash)); + if was_ok { + imported += 1; + } else { + has_error = true; + } + } + + (imported, count, results) +} + /// Single block import function. pub fn import_single_block>( - import_handle: &BlockImport, + import_handle: &dyn BlockImport, block_origin: BlockOrigin, block: IncomingBlock, verifier: Arc, @@ -700,6 +873,8 @@ pub fn import_single_block>( }, }; + trace!(target: "sync", "Header {} has {:?} logs", block.hash, header.digest().logs().len()); + let number = header.number().clone(); let hash = header.hash(); let parent = header.parent_hash().clone(); @@ -909,12 +1084,19 @@ mod tests { )).unwrap(); // Wait until this request is redirected to the BlockImportWorker - assert_eq!(worker_receiver.recv(), Ok(BlockImportWorkerMsg::ImportFinalityProof( - who.clone(), - Default::default(), - 1, - vec![42], - ))); + match worker_receiver.recv().unwrap() { + BlockImportWorkerMsg::ImportFinalityProof( + cwho, + chash, + 1, + cproof, + ) => { + assert_eq!(cwho, who); + assert_eq!(chash, Default::default()); + assert_eq!(cproof, vec![42]); + }, + _ => unreachable!("Unexpected work request received"), + } // Send ack of proof import from BlockImportWorker to BlockImporter result_sender.send(BlockImportWorkerMsg::ImportedFinalityProof( diff --git a/core/consensus/common/src/lib.rs b/core/consensus/common/src/lib.rs index 5e308ba8fe9040961d97a6e859d1f0c94451337d..140aa579017d9e9e651b4477315db1c576d1e847 100644 --- a/core/consensus/common/src/lib.rs +++ b/core/consensus/common/src/lib.rs @@ -33,13 +33,13 @@ use std::sync::Arc; use std::time::Duration; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{AuthorityIdFor, Block}; +use runtime_primitives::traits::{AuthorityIdFor, Block, DigestFor}; use futures::prelude::*; pub use inherents::InherentData; pub mod offline_tracker; pub mod error; -mod block_import; +pub mod block_import; mod select_chain; pub mod import_queue; pub mod evaluation; @@ -47,7 +47,7 @@ pub mod evaluation; // block size limit. const MAX_BLOCK_SIZE: usize = 4 * 1024 * 1024 + 512; -pub use self::error::{Error, ErrorKind}; +pub use self::error::Error; pub use block_import::{ BlockImport, BlockOrigin, ForkChoiceStrategy, ImportedAux, ImportBlock, ImportResult, JustificationImport, FinalityProofImport, FinalityProofRequestBuilder, @@ -87,7 +87,12 @@ pub trait Proposer { /// Future that resolves to a committed proposal. type Create: IntoFuture; /// Create a proposal. - fn propose(&self, inherent_data: InherentData, max_duration: Duration) -> Self::Create; + fn propose( + &self, + inherent_data: InherentData, + inherent_digests: DigestFor, + max_duration: Duration, + ) -> Self::Create; } /// An oracle for when major synchronization work is being undertaken. diff --git a/core/consensus/common/src/select_chain.rs b/core/consensus/common/src/select_chain.rs index 47c65d1fe78e530837648160c8d8ba30fd03300e..9ab21cba13ba9a08d5515cbf87b4f4151cecff98 100644 --- a/core/consensus/common/src/select_chain.rs +++ b/core/consensus/common/src/select_chain.rs @@ -19,13 +19,13 @@ use runtime_primitives::traits::{Block as BlockT, NumberFor}; /// The SelectChain trait defines the strategy upon which the head is chosen -/// if multiple forks are present for an opaque definition of "best" in the +/// if multiple forks are present for an opaque definition of "best" in the /// specific chain build. /// /// The Strategy can be customised for the two use cases of authoring new blocks /// upon the best chain or which fork to finalise. Unless implemented differently /// by default finalisation methods fall back to use authoring, so as a minimum -/// `_authoring`-functions must be implemented. +/// `_authoring`-functions must be implemented. /// /// Any particular user must make explicit, however, whether they intend to finalise /// or author through the using the right function call, as these might differ in @@ -51,4 +51,4 @@ pub trait SelectChain: Sync + Send + Clone { ) -> Result::Hash>, Error> { Ok(Some(target_hash)) } -} \ No newline at end of file +} diff --git a/core/consensus/rhd/Cargo.toml b/core/consensus/rhd/Cargo.toml index 8535f3f006e3cec7c6a3796794275e5def10709c..ee1efb8d06a5bcf4737c2891d5c496b3bff8308d 100644 --- a/core/consensus/rhd/Cargo.toml +++ b/core/consensus/rhd/Cargo.toml @@ -6,6 +6,7 @@ description = "Rhododendron Round-Based consensus-algorithm for substrate" edition = "2018" [dependencies] +derive_more = "0.14.0" futures = "0.1.17" codec = { package = "parity-codec", version = "3.2", features = ["derive"] } primitives = { package = "substrate-primitives", path = "../../primitives" } @@ -19,8 +20,7 @@ runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } runtime_version = { package = "sr-version", path = "../../sr-version" } runtime_io = { package = "sr-io", path = "../../sr-io" } tokio = "0.1.7" -parking_lot = "0.7.1" -error-chain = "0.12" +parking_lot = "0.8.0" log = "0.4" rhododendron = { version = "0.5.0", features = ["codec"] } exit-future = "0.1" diff --git a/core/consensus/rhd/src/error.rs b/core/consensus/rhd/src/error.rs index 38081109754555b73c02c48f2c51bb1404425cf7..601cf1c963a586d883de92527818c2721fb644f5 100644 --- a/core/consensus/rhd/src/error.rs +++ b/core/consensus/rhd/src/error.rs @@ -15,45 +15,36 @@ // along with Substrate. If not, see . //! Error types in the rhododendron Consensus service. -use consensus::error::{Error as CommonError, ErrorKind as CommonErrorKind}; +use consensus::error::{Error as CommonError}; use primitives::AuthorityId; use client; -use error_chain::{error_chain, error_chain_processing, impl_error_chain_processed, - impl_extract_backtrace, impl_error_chain_kind}; -error_chain! { - links { - Client(client::error::Error, client::error::ErrorKind); - Common(CommonError, CommonErrorKind); - } - errors { - NotValidator(id: AuthorityId) { - description("Local account ID not a validator at this block."), - display("Local account ID ({:?}) not a validator at this block.", id), - } - PrematureDestruction { - description("Proposer destroyed before finishing proposing or evaluating"), - display("Proposer destroyed before finishing proposing or evaluating"), - } - Timer(e: ::tokio::timer::Error) { - description("Failed to register or resolve async timer."), - display("Timer failed: {}", e), - } - Executor(e: ::futures::future::ExecuteErrorKind) { - description("Unable to dispatch agreement future"), - display("Unable to dispatch agreement future: {:?}", e), - } - } +/// A result alias. +pub type Result = std::result::Result; + +/// A RHD error type. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Client error. + Client(client::error::Error), + /// Consensus error. + Common(CommonError), + /// Local account ID not a validator at this block. + #[display(fmt="Local account ID ({:?}) not a validator at this block.", _0)] + NotValidator(AuthorityId), + /// Proposer destroyed before finishing proposing or evaluating + #[display(fmt="Proposer destroyed before finishing proposing or evaluating")] + PrematureDestruction, + /// Failed to register or resolve async timer. + #[display(fmt="Timer failed: {}", _0)] + Timer(tokio::timer::Error), + /// Unable to dispatch agreement future + #[display(fmt="Unable to dispatch agreement future: {:?}", _0)] + Executor(futures::future::ExecuteErrorKind), } impl From<::rhododendron::InputStreamConcluded> for Error { fn from(_: ::rhododendron::InputStreamConcluded) -> Self { - CommonErrorKind::IoTerminated.into() - } -} - -impl From for Error { - fn from(e: CommonErrorKind) -> Self { - CommonError::from(e).into() + CommonError::IoTerminated.into() } } diff --git a/core/consensus/rhd/src/lib.rs b/core/consensus/rhd/src/lib.rs index 0afe10ffce9f1ee640dbf1bce074b2a09ddf2e44..ca4b9120eb58bb6709f86ed3b92615d899ea98f0 100644 --- a/core/consensus/rhd/src/lib.rs +++ b/core/consensus/rhd/src/lib.rs @@ -45,7 +45,10 @@ use client::{Client as SubstrateClient, CallExecutor}; use client::runtime_api::{Core, BlockBuilder as BlockBuilderAPI, OldTxQueue, BlockBuilderError}; use runtime_primitives::generic::{BlockId, Era, ImportResult, ImportBlock, BlockOrigin}; use runtime_primitives::traits::{Block, Header}; -use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT, As, BlockNumberToHash}; +use runtime_primitives::traits::{ + Block as BlockT, Hash as HashT, Header as HeaderT, + BlockNumberToHash, SaturatedConversion +}; use runtime_primitives::Justification; use primitives::{AuthorityId, ed25519, Blake2Hasher, ed25519::LocalizedSignature}; use srml_system::Trait as SystemT; @@ -1246,7 +1249,7 @@ impl LocalProposer<::Block> for Proposer where for (target, misbehavior) in misbehavior { let report = MisbehaviorReport { parent_hash: self.parent_hash.into(), - parent_number: self.parent_number.as_(), + parent_number: self.parent_number.saturated_into::(), target, misbehavior: match misbehavior { GenericMisbehavior::ProposeOutOfTurn(_, _, _) => continue, diff --git a/core/consensus/slots/Cargo.toml b/core/consensus/slots/Cargo.toml index c02559185f9056b614d4fe4cff6ab9ed6a2b0989..5c187024c9f49f70665c7aa015e306016b0436ee 100644 --- a/core/consensus/slots/Cargo.toml +++ b/core/consensus/slots/Cargo.toml @@ -13,7 +13,9 @@ runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } consensus_common = { package = "substrate-consensus-common", path = "../common" } inherents = { package = "substrate-inherents", path = "../../inherents" } futures = "0.1.17" -tokio = "0.1.7" -parking_lot = "0.7.1" -error-chain = "0.12" +tokio-timer = "0.2.11" +parking_lot = "0.8.0" log = "0.4" + +[dev-dependencies] +test-client = { package = "substrate-test-runtime-client", path = "../../test-runtime/client" } diff --git a/core/consensus/slots/src/aux_schema.rs b/core/consensus/slots/src/aux_schema.rs index 44f4ca59839ed27eb6493c73a2acad96bba5eae7..ed96bf2e22c75877ce21d8a5809714cfd16b5fed 100644 --- a/core/consensus/slots/src/aux_schema.rs +++ b/core/consensus/slots/src/aux_schema.rs @@ -16,7 +16,6 @@ //! Schema for slots in the aux-db. -use std::sync::Arc; use codec::{Encode, Decode}; use client::backend::AuxStore; use client::error::{Result as ClientResult, Error as ClientError}; @@ -30,7 +29,7 @@ pub const MAX_SLOT_CAPACITY: u64 = 1000; /// We prune slots when they reach this number. pub const PRUNING_BOUND: u64 = 2 * MAX_SLOT_CAPACITY; -fn load_decode(backend: Arc, key: &[u8]) -> ClientResult> +fn load_decode(backend: &C, key: &[u8]) -> ClientResult> where C: AuxStore, T: Decode, @@ -74,16 +73,16 @@ impl EquivocationProof { /// /// Note: it detects equivocations only when slot_now - slot <= MAX_SLOT_CAPACITY. pub fn check_equivocation( - backend: &Arc, + backend: &C, slot_now: u64, slot: u64, - header: H, - signer: P, + header: &H, + signer: &P, ) -> ClientResult>> where H: Header, C: AuxStore, - P: Encode + Decode + PartialEq, + P: Clone + Encode + Decode + PartialEq, { // We don't check equivocations for old headers out of our capacity. if slot_now - slot > MAX_SLOT_CAPACITY { @@ -95,18 +94,18 @@ pub fn check_equivocation( slot.using_encoded(|s| curr_slot_key.extend(s)); // Get headers of this slot. - let mut headers_with_sig = load_decode::<_, Vec<(H, P)>>(backend.clone(), &curr_slot_key[..])? + let mut headers_with_sig = load_decode::<_, Vec<(H, P)>>(backend, &curr_slot_key[..])? .unwrap_or_else(Vec::new); // Get first slot saved. let slot_header_start = SLOT_HEADER_START.to_vec(); - let first_saved_slot = load_decode::<_, u64>(backend.clone(), &slot_header_start[..])? + let first_saved_slot = load_decode::<_, u64>(backend, &slot_header_start[..])? .unwrap_or(slot); for (prev_header, prev_signer) in headers_with_sig.iter() { // A proof of equivocation consists of two headers: // 1) signed by the same voter, - if *prev_signer == signer { + if prev_signer == signer { // 2) with different hash if header.hash() != prev_header.hash() { return Ok(Some(EquivocationProof { @@ -137,7 +136,7 @@ pub fn check_equivocation( } } - headers_with_sig.push((header, signer)); + headers_with_sig.push((header.clone(), signer.clone())); backend.insert_aux( &[ @@ -149,3 +148,118 @@ pub fn check_equivocation( Ok(None) } + +#[cfg(test)] +mod test { + use primitives::{sr25519, Pair}; + use primitives::hash::H256; + use runtime_primitives::testing::{Header as HeaderTest, Digest as DigestTest}; + use test_client; + + use super::{MAX_SLOT_CAPACITY, PRUNING_BOUND, check_equivocation}; + + fn create_header(number: u64) -> HeaderTest { + // so that different headers for the same number get different hashes + let parent_hash = H256::random(); + + let header = HeaderTest { + parent_hash, + number, + state_root: Default::default(), + extrinsics_root: Default::default(), + digest: DigestTest { logs: vec![], }, + }; + + header + } + + #[test] + fn check_equivocation_works() { + let client = test_client::new(); + let pair = sr25519::Pair::generate(); + let public = pair.public(); + + let header1 = create_header(1); // @ slot 2 + let header2 = create_header(2); // @ slot 2 + let header3 = create_header(2); // @ slot 4 + let header4 = create_header(3); // @ slot MAX_SLOT_CAPACITY + 4 + let header5 = create_header(4); // @ slot MAX_SLOT_CAPACITY + 4 + let header6 = create_header(3); // @ slot 4 + + // It's ok to sign same headers. + assert!( + check_equivocation( + &client, + 2, + 2, + &header1, + &public, + ).unwrap().is_none(), + ); + + assert!( + check_equivocation( + &client, + 3, + 2, + &header1, + &public, + ).unwrap().is_none(), + ); + + // But not two different headers at the same slot. + assert!( + check_equivocation( + &client, + 4, + 2, + &header2, + &public, + ).unwrap().is_some(), + ); + + // Different slot is ok. + assert!( + check_equivocation( + &client, + 5, + 4, + &header3, + &public, + ).unwrap().is_none(), + ); + + // Here we trigger pruning and save header 4. + assert!( + check_equivocation( + &client, + PRUNING_BOUND + 2, + MAX_SLOT_CAPACITY + 4, + &header4, + &public, + ).unwrap().is_none(), + ); + + // This fails because header 5 is an equivocation of header 4. + assert!( + check_equivocation( + &client, + PRUNING_BOUND + 3, + MAX_SLOT_CAPACITY + 4, + &header5, + &public, + ).unwrap().is_some(), + ); + + // This is ok because we pruned the corresponding header. Shows that we are pruning. + assert!( + check_equivocation( + &client, + PRUNING_BOUND + 4, + 4, + &header6, + &public, + ).unwrap().is_none(), + ); + } +} diff --git a/core/consensus/slots/src/lib.rs b/core/consensus/slots/src/lib.rs index 4ae72fd92a7be43c7fcfcf18b9f596b4467a29f8..18ec2451beba818aa84429c7dc44f7211183a52a 100644 --- a/core/consensus/slots/src/lib.rs +++ b/core/consensus/slots/src/lib.rs @@ -41,8 +41,6 @@ use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{ApiRef, Block, ProvideRuntimeApi}; use std::fmt::Debug; use std::ops::Deref; -use std::sync::{mpsc, Arc}; -use std::thread; /// A worker that should be invoked at every new slot. pub trait SlotWorker { @@ -51,7 +49,8 @@ pub trait SlotWorker { type OnSlot: IntoFuture; /// Called when the proposer starts. - fn on_start(&self, slot_duration: u64) -> Result<(), consensus_common::Error>; + #[deprecated(note = "Not called. Please perform any initialization before calling start_slot_worker.")] + fn on_start(&self, _slot_duration: u64) -> Result<(), consensus_common::Error> { Ok(()) } /// Called when a new slot is triggered. fn on_slot(&self, chain_head: B::Header, slot_info: SlotInfo) -> Self::OnSlot; @@ -65,135 +64,59 @@ pub trait SlotCompatible { ) -> Result<(u64, u64), consensus_common::Error>; } -/// Convert an inherent error to common error. -pub fn inherent_to_common_error(err: inherents::RuntimeString) -> consensus_common::Error { - consensus_common::ErrorKind::InherentData(err.into()).into() -} - -/// Start a new slot worker in a separate thread. -#[deprecated(since = "1.1", note = "Please spawn a thread manually")] -pub fn start_slot_worker_thread( - slot_duration: SlotDuration, - select_chain: C, - worker: Arc, - sync_oracle: SO, - on_exit: OnExit, - inherent_data_providers: InherentDataProviders, -) -> Result<(), consensus_common::Error> -where - B: Block + 'static, - C: SelectChain + Clone + 'static, - W: SlotWorker + Send + Sync + 'static, - SO: SyncOracle + Send + Clone + 'static, - SC: SlotCompatible + 'static, - OnExit: Future + Send + 'static, - T: SlotData + Send + Clone + 'static, -{ - use tokio::runtime::current_thread::Runtime; - - let (result_sender, result_recv) = mpsc::channel(); - - thread::spawn(move || { - let mut runtime = match Runtime::new() { - Ok(r) => r, - Err(e) => { - warn!(target: "slots", "Unable to start authorship: {:?}", e); - return; - } - }; - - let slot_worker_future = match start_slot_worker::<_, _, _, T, _, SC, _>( - slot_duration.clone(), - select_chain, - worker, - sync_oracle, - on_exit, - inherent_data_providers, - ) { - Ok(slot_worker_future) => { - result_sender - .send(Ok(())) - .expect("Receive is not dropped before receiving a result; qed"); - slot_worker_future - } - Err(e) => { - result_sender - .send(Err(e)) - .expect("Receive is not dropped before receiving a result; qed"); - return; - } - }; - - let _ = runtime.block_on(slot_worker_future); - }); - - result_recv - .recv() - .expect("Slots start thread result sender dropped") -} - /// Start a new slot worker. -pub fn start_slot_worker( +/// +/// Every time a new slot is triggered, `worker.on_slot` is called and the future it returns is +/// polled until completion, unless we are major syncing. +pub fn start_slot_worker( slot_duration: SlotDuration, client: C, - worker: Arc, + worker: W, sync_oracle: SO, - on_exit: OnExit, inherent_data_providers: InherentDataProviders, -) -> Result, consensus_common::Error> +) -> impl Future where B: Block, C: SelectChain + Clone, W: SlotWorker, SO: SyncOracle + Send + Clone, SC: SlotCompatible, - OnExit: Future, T: SlotData + Clone, { - worker.on_start(slot_duration.slot_duration())?; - - let make_authorship = move || { - let client = client.clone(); - let worker = worker.clone(); - let sync_oracle = sync_oracle.clone(); - let SlotDuration(slot_duration) = slot_duration.clone(); - let inherent_data_providers = inherent_data_providers.clone(); - - // rather than use a timer interval, we schedule our waits ourselves - Slots::::new(slot_duration.slot_duration(), inherent_data_providers) - .map_err(|e| debug!(target: "slots", "Faulty timer: {:?}", e)) - .for_each(move |slot_info| { - let client = client.clone(); - let worker = worker.clone(); - let sync_oracle = sync_oracle.clone(); - - // only propose when we are not syncing. - if sync_oracle.is_major_syncing() { - debug!(target: "slots", "Skipping proposal slot due to sync."); + let SlotDuration(slot_duration) = slot_duration; + + // rather than use a timer interval, we schedule our waits ourselves + let mut authorship = Slots::::new(slot_duration.slot_duration(), inherent_data_providers) + .map_err(|e| debug!(target: "slots", "Faulty timer: {:?}", e)) + .for_each(move |slot_info| { + // only propose when we are not syncing. + if sync_oracle.is_major_syncing() { + debug!(target: "slots", "Skipping proposal slot due to sync."); + return Either::B(future::ok(())); + } + + let slot_num = slot_info.number; + let chain_head = match client.best_chain() { + Ok(x) => x, + Err(e) => { + warn!(target: "slots", "Unable to author block in slot {}. \ + no best block header: {:?}", slot_num, e); return Either::B(future::ok(())); } - - let slot_num = slot_info.number; - let chain_head = match client.best_chain() { - Ok(x) => x, - Err(e) => { - warn!(target: "slots", "Unable to author block in slot {}. \ - no best block header: {:?}", slot_num, e); - return Either::B(future::ok(())); - } - }; - - Either::A(worker.on_slot(chain_head, slot_info).into_future().map_err( - |e| warn!(target: "slots", "Encountered consensus error: {:?}", e), - )) - }) - }; - - let work = future::loop_fn((), move |()| { - let authorship_task = ::std::panic::AssertUnwindSafe(make_authorship()); - authorship_task.catch_unwind().then(|res| { - match res { - Ok(Ok(())) => (), + }; + + Either::A(worker.on_slot(chain_head, slot_info).into_future().map_err( + |e| warn!(target: "slots", "Encountered consensus error: {:?}", e), + )) + }); + + future::poll_fn(move || + loop { + let mut authorship = std::panic::AssertUnwindSafe(&mut authorship); + match std::panic::catch_unwind(move || authorship.poll()) { + Ok(Ok(Async::Ready(()))) => + warn!(target: "slots", "Slots stream has terminated unexpectedly."), + Ok(Ok(Async::NotReady)) => break Ok(Async::NotReady), Ok(Err(())) => warn!(target: "slots", "Authorship task terminated unexpectedly. Restarting"), Err(e) => { if let Some(s) = e.downcast_ref::<&'static str>() { @@ -203,12 +126,8 @@ where warn!(target: "slots", "Restarting authorship task"); } } - - Ok(future::Loop::Continue(())) - }) - }); - - Ok(work.select(on_exit).then(|_| Ok(()))) + } + ) } /// A header which has been checked diff --git a/core/consensus/slots/src/slots.rs b/core/consensus/slots/src/slots.rs index df21ae9b839ce99c8f58c8bed11cd35457b8b7c8..a848a967629a19de7f469691ba8ac4e51fce1c07 100644 --- a/core/consensus/slots/src/slots.rs +++ b/core/consensus/slots/src/slots.rs @@ -19,14 +19,14 @@ //! This is used instead of `tokio_timer::Interval` because it was unreliable. use super::SlotCompatible; -use consensus_common::{Error, ErrorKind}; +use consensus_common::Error; use futures::prelude::*; use futures::try_ready; use inherents::{InherentData, InherentDataProviders}; use log::warn; use std::marker::PhantomData; use std::time::{Duration, Instant}; -use tokio::timer::Delay; +use tokio_timer::Delay; /// Returns current duration since unix epoch. pub fn duration_now() -> Option { @@ -125,7 +125,7 @@ impl Stream for Slots { if let Some(ref mut inner_delay) = self.inner_delay { try_ready!(inner_delay .poll() - .map_err(|e| Error::from(ErrorKind::FaultyTimer(e)))); + .map_err(Error::FaultyTimer)); } // timeout has fired. @@ -133,7 +133,7 @@ impl Stream for Slots { let inherent_data = self .inherent_data_providers .create_inherent_data() - .map_err(crate::inherent_to_common_error)?; + .map_err(|s| consensus_common::Error::InherentData(s.into_owned()))?; let (timestamp, slot_num) = SC::extract_timestamp_and_slot(&inherent_data)?; // reschedule delay for next slot. diff --git a/core/executor/Cargo.toml b/core/executor/Cargo.toml index 0272ce2f47e8f363b7277cdac959945886473a90..9cc198557da0f1c57657e9a31f051fabca05c42d 100644 --- a/core/executor/Cargo.toml +++ b/core/executor/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -error-chain = "0.12" +derive_more = "0.14.0" parity-codec = "3.3" runtime_io = { package = "sr-io", path = "../sr-io" } primitives = { package = "substrate-primitives", path = "../primitives" } @@ -17,7 +17,7 @@ panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" wasmi = { version = "0.4.3" } byteorder = "1.1" lazy_static = "1.0" -parking_lot = "0.7.1" +parking_lot = "0.8.0" log = "0.4" libsecp256k1 = "0.2.1" tiny-keccak = "1.4.2" diff --git a/core/executor/src/allocator.rs b/core/executor/src/allocator.rs index 4b3f7d32193cffd8d26f80404d5a4954e95b58f7..bf01dd2e90e57edaa3d74b028088f449bd93c0a1 100644 --- a/core/executor/src/allocator.rs +++ b/core/executor/src/allocator.rs @@ -163,8 +163,7 @@ impl FreeingBumpHeapAllocator { } fn le_bytes_to_u32(arr: [u8; 4]) -> u32 { - let bytes = [arr[0], arr[1], arr[2], arr[3]]; - unsafe { std::mem::transmute::<[u8; 4], u32>(bytes) }.to_le() + u32::from_le_bytes(arr) } fn write_u32_into_le_bytes(bytes: u32, slice: &mut [u8]) { diff --git a/core/executor/src/error.rs b/core/executor/src/error.rs index b27ccf01bf4cef520c3e22d0d9ce8923f7456f5c..fdcb6cbc0e30786f1d271c4651858fe3eff05315 100644 --- a/core/executor/src/error.rs +++ b/core/executor/src/error.rs @@ -16,72 +16,57 @@ //! Rust executor possible errors. -// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting` -// https://github.com/paritytech/substrate/issues/1547 -#![allow(deprecated)] - use state_machine; use serializer; use wasmi; -use error_chain::{ - error_chain, error_chain_processing, impl_error_chain_processed, - impl_extract_backtrace, impl_error_chain_kind -}; - -error_chain! { - foreign_links { - InvalidData(serializer::Error) #[doc = "Unserializable Data"]; - Trap(wasmi::Trap) #[doc = "Trap occured during execution"]; - Wasmi(wasmi::Error) #[doc = "Wasmi loading/instantiating error"]; - } - - errors { - /// Method is not found - MethodNotFound(t: String) { - description("method not found"), - display("Method not found: '{}'", t), - } - - /// Code is invalid (expected single byte) - InvalidCode(c: Vec) { - description("invalid code"), - display("Invalid Code: {:?}", c), - } - - /// Could not get runtime version. - VersionInvalid { - description("Runtime version error"), - display("On-chain runtime does not specify version"), - } - /// Externalities have failed. - Externalities { - description("externalities failure"), - display("Externalities error"), - } - - /// Invalid index. - InvalidIndex { - description("index given was not in range"), - display("Invalid index provided"), - } - - /// Invalid return type. - InvalidReturn { - description("u64 was not returned"), - display("Invalid type returned (should be u64)"), - } - - /// Runtime failed. - Runtime { - description("runtime failure"), - display("Runtime error"), - } +/// Result type alias. +pub type Result = std::result::Result; + +/// Error type. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Unserializable Data + InvalidData(serializer::Error), + /// Trap occured during execution + Trap(wasmi::Trap), + /// Wasmi loading/instantiating error + Wasmi(wasmi::Error), + /// Error in the API. Parameter is an error message. + ApiError(String), + /// Method is not found + #[display(fmt="Method not found: '{}'", _0)] + MethodNotFound(String), + /// Code is invalid (expected single byte) + #[display(fmt="Invalid Code: {:?}", _0)] + InvalidCode(Vec), + /// Could not get runtime version. + #[display(fmt="On-chain runtime does not specify version")] + VersionInvalid, + /// Externalities have failed. + #[display(fmt="Externalities error")] + Externalities, + /// Invalid index. + #[display(fmt="Invalid index provided")] + InvalidIndex, + /// Invalid return type. + #[display(fmt="Invalid type returned (should be u64)")] + InvalidReturn, + /// Runtime failed. + #[display(fmt="Runtime error")] + Runtime, + /// Runtime failed. + #[display(fmt="Invalid memory reference")] + InvalidMemoryReference, +} - /// Runtime failed. - InvalidMemoryReference { - description("invalid memory reference"), - display("Invalid memory reference"), +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::InvalidData(ref err) => Some(err), + Error::Trap(ref err) => Some(err), + Error::Wasmi(ref err) => Some(err), + _ => None, } } } diff --git a/core/executor/src/native_executor.rs b/core/executor/src/native_executor.rs index 0a702a5a1b0667878d212cbdc35f93fd9d7f3ced..e4a65c811bf6ae6e5ab49bc9db2fd7c38461a27e 100644 --- a/core/executor/src/native_executor.rs +++ b/core/executor/src/native_executor.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see . use std::{borrow::BorrowMut, result, cell::{RefMut, RefCell}}; -use crate::error::{Error, ErrorKind, Result}; +use crate::error::{Error, Result}; use state_machine::{CodeExecutor, Externalities}; use crate::wasm_executor::WasmExecutor; use wasmi::{Module as WasmModule, ModuleRef as WasmModuleInstanceRef}; @@ -55,7 +55,7 @@ fn fetch_cached_runtime_version<'a, E: Externalities>( ) -> Result<(&'a WasmModuleInstanceRef, &'a Option)> { let code_hash = match ext.original_storage_hash(well_known_keys::CODE) { Some(code_hash) => code_hash, - None => return Err(ErrorKind::InvalidCode(vec![]).into()), + None => return Err(Error::InvalidCode(vec![])), }; let maybe_runtime_preproc = cache.borrow_mut().entry(code_hash.into()) @@ -69,7 +69,7 @@ fn fetch_cached_runtime_version<'a, E: Externalities>( .or(default_heap_pages) .unwrap_or(DEFAULT_HEAP_PAGES); match WasmModule::from_buffer(code) - .map_err(|_| ErrorKind::InvalidCode(vec![]).into()) + .map_err(|_| Error::InvalidCode(vec![])) .and_then(|module| wasm_executor.prepare_module(ext, heap_pages as usize, &module)) { Ok(module) => { @@ -88,7 +88,7 @@ fn fetch_cached_runtime_version<'a, E: Externalities>( match maybe_runtime_preproc { RuntimePreproc::InvalidCode => { let code = ext.original_storage(well_known_keys::CODE).unwrap_or(vec![]); - Err(ErrorKind::InvalidCode(code).into()) + Err(Error::InvalidCode(code)) }, RuntimePreproc::ValidCode(m, v) => { Ok((m, v)) @@ -101,13 +101,13 @@ fn safe_call(f: F) -> Result { // Substrate uses custom panic hook that terminates process on panic. Disable termination for the native call. let _guard = panic_handler::AbortGuard::new(false); - ::std::panic::catch_unwind(f).map_err(|_| ErrorKind::Runtime.into()) + ::std::panic::catch_unwind(f).map_err(|_| Error::Runtime) } /// Set up the externalities and safe calling environment to execute calls to a native runtime. /// /// If the inner closure panics, it will be caught and return an error. -pub fn with_native_environment(ext: &mut Externalities, f: F) -> Result +pub fn with_native_environment(ext: &mut dyn Externalities, f: F) -> Result where F: UnwindSafe + FnOnce() -> U { ::runtime_io::with_externalities(ext, move || safe_call(f)) @@ -121,7 +121,7 @@ pub trait NativeExecutionDispatch: Send + Sync { /// Dispatch a method and input data to be executed natively. Returns `Some` result or `None` /// if the `method` is unknown. Panics if there's an unrecoverable error. // fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result>; - fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result>; + fn dispatch(ext: &mut dyn Externalities, method: &str, data: &[u8]) -> Result>; /// Provide native runtime version. fn native_version() -> NativeVersion; @@ -133,7 +133,7 @@ pub trait NativeExecutionDispatch: Send + Sync { /// A generic `CodeExecutor` implementation that uses a delegate to determine wasm code equivalence /// and dispatch to native code when possible, falling back on `WasmExecutor` when not. #[derive(Debug)] -pub struct NativeExecutor { +pub struct NativeExecutor { /// Dummy field to avoid the compiler complaining about us not using `D`. _dummy: ::std::marker::PhantomData, /// The fallback executor in case native isn't available. @@ -248,7 +248,7 @@ impl CodeExecutor for NativeExecutor { /// A unit struct which implements `NativeExecutionDispatch` feeding in the hard-coded runtime. $pub struct $name; - native_executor_instance!(IMPL $name, $dispatcher, $version, $code); + $crate::native_executor_instance!(IMPL $name, $dispatcher, $version, $code); }; (IMPL $name:ident, $dispatcher:path, $version:path, $code:expr) => { impl $crate::NativeExecutionDispatch for $name { @@ -283,7 +283,7 @@ macro_rules! native_executor_instance { } fn dispatch(ext: &mut $crate::Externalities<$crate::Blake2Hasher>, method: &str, data: &[u8]) -> $crate::error::Result> { $crate::with_native_environment(ext, move || $dispatcher(method, data))? - .ok_or_else(|| $crate::error::ErrorKind::MethodNotFound(method.to_owned()).into()) + .ok_or_else(|| $crate::error::Error::MethodNotFound(method.to_owned())) } fn native_version() -> $crate::NativeVersion { diff --git a/core/executor/src/sandbox.rs b/core/executor/src/sandbox.rs index cc21d762bec11fd13645a5a971640e5ddedd155b..377294f7b12d7be46db401cfe68c7074f2646d11 100644 --- a/core/executor/src/sandbox.rs +++ b/core/executor/src/sandbox.rs @@ -569,9 +569,11 @@ mod tests { use crate::allocator; use crate::sandbox::trap; use crate::wasm_executor::WasmExecutor; - use state_machine::TestExternalities; + use state_machine::TestExternalities as CoreTestExternalities; use wabt; + type TestExternalities = CoreTestExternalities; + #[test] fn sandbox_should_work() { let mut ext = TestExternalities::::default(); @@ -643,9 +645,8 @@ mod tests { let res = WasmExecutor::new().call(&mut ext, 8, &test_code[..], "test_exhaust_heap", &code); assert_eq!(res.is_err(), true); if let Err(err) = res { - let inner_err = err.iter().next().unwrap(); assert_eq!( - format!("{}", inner_err), + format!("{}", err), format!("{}", wasmi::Error::Trap(trap(allocator::OUT_OF_SPACE))) ); } diff --git a/core/executor/src/wasm_executor.rs b/core/executor/src/wasm_executor.rs index 3fe1a1c3cc6a37ccfc6629f6158b4a9c8f221eeb..920639c0a2b053fa5830c81659f288d518de143f 100644 --- a/core/executor/src/wasm_executor.rs +++ b/core/executor/src/wasm_executor.rs @@ -17,6 +17,8 @@ //! Rust implementation of Substrate contracts. use std::collections::HashMap; +use std::convert::TryFrom; +use std::str; use tiny_keccak; use secp256k1; @@ -26,9 +28,10 @@ use wasmi::{ use wasmi::RuntimeValue::{I32, I64, self}; use wasmi::memory_units::{Pages}; use state_machine::{Externalities, ChildStorageKey}; -use crate::error::{Error, ErrorKind, Result}; +use crate::error::{Error, Result}; use crate::wasm_utils::UserError; use primitives::{blake2_128, blake2_256, twox_64, twox_128, twox_256, ed25519, sr25519, Pair}; +use primitives::offchain; use primitives::hexdisplay::HexDisplay; use primitives::sandbox as sandbox_primitives; use primitives::{H256, Blake2Hasher}; @@ -113,6 +116,24 @@ impl ReadPrimitive for MemoryInstance { } } +fn deadline_to_timestamp(deadline: u64) -> Option { + if deadline == 0 { + None + } else { + Some(offchain::Timestamp::from_unix_millis(deadline)) + } +} + +fn u32_to_key(key: u32) -> std::result::Result, ()> { + if key > u16::max_value() as u32 { + Err(()) + } else if key == 0 { + Ok(None) + } else { + Ok(Some(offchain::CryptoKeyId(key as u16))) + } +} + impl_function_executor!(this: FunctionExecutor<'e, E>, ext_print_utf8(utf8_data: *const u8, utf8_len: u32) => { if let Ok(utf8) = this.memory.get(utf8_data, utf8_len as usize) { @@ -414,7 +435,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, .map_err(|_| UserError("Invalid attempt to write written_out in ext_child_storage_root"))?; Ok(offset) }, - ext_storage_changes_root(parent_hash_data: *const u8, parent_hash_len: u32, parent_number: u64, result: *mut u8) -> u32 => { + ext_storage_changes_root(parent_hash_data: *const u8, parent_hash_len: u32, result: *mut u8) -> u32 => { let mut parent_hash = H256::default(); if parent_hash_len != parent_hash.as_ref().len() as u32 { return Err(UserError("Invalid parent_hash_len in ext_storage_changes_root").into()); @@ -422,7 +443,8 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, let raw_parent_hash = this.memory.get(parent_hash_data, parent_hash_len as usize) .map_err(|_| UserError("Invalid attempt to get parent_hash in ext_storage_changes_root"))?; parent_hash.as_mut().copy_from_slice(&raw_parent_hash[..]); - let r = this.ext.storage_changes_root(parent_hash, parent_number); + let r = this.ext.storage_changes_root(parent_hash) + .map_err(|_| UserError("Invaid parent_hash passed to ext_storage_changes_root"))?; if let Some(r) = r { this.memory.set(result, &r[..]).map_err(|_| UserError("Invalid attempt to set memory in ext_storage_changes_root"))?; Ok(1) @@ -458,7 +480,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, let key = this.memory.get(data, len as usize).map_err(|_| UserError("Invalid attempt to get key in ext_twox_64"))?; let hashed_key = twox_64(&key); debug_trace!(target: "xxhash", "XXhash: {} -> {}", - if let Ok(_skey) = ::std::str::from_utf8(&key) { + if let Ok(_skey) = str::from_utf8(&key) { _skey } else { &format!("{}", HexDisplay::from(&key)) @@ -482,10 +504,10 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, let key = this.memory.get(data, len as usize).map_err(|_| UserError("Invalid attempt to get key in ext_twox_128"))?; let hashed_key = twox_128(&key); debug_trace!(target: "xxhash", "XXhash: {} -> {}", - if let Ok(_skey) = ::std::str::from_utf8(&key) { - _skey + &if let Ok(_skey) = str::from_utf8(&key) { + *_skey } else { - &format!("{}", HexDisplay::from(&key)) + format!("{}", HexDisplay::from(&key)) }, HexDisplay::from(&hashed_key) ); @@ -589,15 +611,345 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, Ok(0) }, - ext_submit_extrinsic(msg_data: *const u8, len: u32) => { + ext_submit_transaction(msg_data: *const u8, len: u32) -> u32 => { let extrinsic = this.memory.get(msg_data, len as usize) - .map_err(|_| UserError("OOB while ext_submit_extrinsic: wasm"))?; + .map_err(|_| UserError("OOB while ext_submit_transaction: wasm"))?; + + let res = this.ext.offchain() + .map(|api| api.submit_transaction(extrinsic)) + .ok_or_else(|| UserError("Calling unavailable API ext_submit_transaction: wasm"))?; + + Ok(if res.is_ok() { 0 } else { 1 }) + }, + ext_new_crypto_key(crypto: u32) -> u32 => { + let kind = offchain::CryptoKind::try_from(crypto) + .map_err(|_| UserError("crypto kind OOB while ext_new_crypto_key: wasm"))?; + + let res = this.ext.offchain() + .map(|api| api.new_crypto_key(kind)) + .ok_or_else(|| UserError("Calling unavailable API ext_new_crypto_key: wasm"))?; + + match res { + Ok(key_id) => Ok(key_id.0 as u32), + Err(()) => Ok(u32::max_value()), + } + }, + ext_encrypt(key: u32, data: *const u8, data_len: u32, msg_len: *mut u32) -> *mut u8 => { + let key = u32_to_key(key) + .map_err(|_| UserError("key OOB while ext_encrypt: wasm"))?; + let message = this.memory.get(data, data_len as usize) + .map_err(|_| UserError("OOB while ext_encrypt: wasm"))?; + + let res = this.ext.offchain() + .map(|api| api.encrypt(key, &*message)) + .ok_or_else(|| UserError("Calling unavailable API ext_encrypt: wasm"))?; + + let (offset,len) = match res { + Ok(encrypted) => { + let len = encrypted.len() as u32; + let offset = this.heap.allocate(len)? as u32; + this.memory.set(offset, &encrypted) + .map_err(|_| UserError("Invalid attempt to set memory in ext_encrypt"))?; + (offset, len) + }, + Err(()) => (0, u32::max_value()), + }; + + this.memory.write_primitive(msg_len, len) + .map_err(|_| UserError("Invalid attempt to write msg_len in ext_encrypt"))?; + + Ok(offset) + }, + ext_decrypt(key: u32, data: *const u8, data_len: u32, msg_len: *mut u32) -> *mut u8 => { + let key = u32_to_key(key) + .map_err(|_| UserError("key OOB while ext_decrypt: wasm"))?; + let message = this.memory.get(data, data_len as usize) + .map_err(|_| UserError("OOB while ext_decrypt: wasm"))?; + + let res = this.ext.offchain() + .map(|api| api.decrypt(key, &*message)) + .ok_or_else(|| UserError("Calling unavailable API ext_decrypt: wasm"))?; + + let (offset,len) = match res { + Ok(decrypted) => { + let len = decrypted.len() as u32; + let offset = this.heap.allocate(len)? as u32; + this.memory.set(offset, &decrypted) + .map_err(|_| UserError("Invalid attempt to set memory in ext_decrypt"))?; + (offset, len) + }, + Err(()) => (0, u32::max_value()), + }; + + this.memory.write_primitive(msg_len, len) + .map_err(|_| UserError("Invalid attempt to write msg_len in ext_decrypt"))?; + + Ok(offset) + }, + ext_sign(key: u32, data: *const u8, data_len: u32, sig_data_len: *mut u32) -> *mut u8 => { + let key = u32_to_key(key) + .map_err(|_| UserError("key OOB while ext_sign: wasm"))?; + let message = this.memory.get(data, data_len as usize) + .map_err(|_| UserError("OOB while ext_sign: wasm"))?; + + let res = this.ext.offchain() + .map(|api| api.sign(key, &*message)) + .ok_or_else(|| UserError("Calling unavailable API ext_sign: wasm"))?; + + let (offset,len) = match res { + Ok(signature) => { + let len = signature.len() as u32; + let offset = this.heap.allocate(len)? as u32; + this.memory.set(offset, &signature) + .map_err(|_| UserError("Invalid attempt to set memory in ext_sign"))?; + (offset, len) + }, + Err(()) => (0, u32::max_value()), + }; + + this.memory.write_primitive(sig_data_len, len) + .map_err(|_| UserError("Invalid attempt to write sig_data_len in ext_sign"))?; + + Ok(offset) + }, + ext_verify( + key: u32, + msg: *const u8, + msg_len: u32, + signature: *const u8, + signature_len: u32 + ) -> u32 => { + let key = u32_to_key(key) + .map_err(|_| UserError("key OOB while ext_verify: wasm"))?; + let message = this.memory.get(msg, msg_len as usize) + .map_err(|_| UserError("OOB while ext_verify: wasm"))?; + let signature = this.memory.get(signature, signature_len as usize) + .map_err(|_| UserError("OOB while ext_verify: wasm"))?; + + let res = this.ext.offchain() + .map(|api| api.verify(key, &*message, &*signature)) + .ok_or_else(|| UserError("Calling unavailable API ext_verify: wasm"))?; + + match res { + Ok(true) => Ok(0), + Ok(false) => Ok(1), + Err(()) => Ok(u32::max_value()), + } + }, + ext_timestamp() -> u64 => { + let timestamp = this.ext.offchain() + .map(|api| api.timestamp()) + .ok_or_else(|| UserError("Calling unavailable API ext_timestamp: wasm"))?; + Ok(timestamp.unix_millis()) + }, + ext_sleep_until(deadline: u64) => { + this.ext.offchain() + .map(|api| api.sleep_until(offchain::Timestamp::from_unix_millis(deadline))) + .ok_or_else(|| UserError("Calling unavailable API ext_sleep_until: wasm"))?; + Ok(()) + }, + ext_random_seed(seed_data: *mut u8) => { + // NOTE the runtime as assumptions about seed size. + let seed: [u8; 32] = this.ext.offchain() + .map(|api| api.random_seed()) + .ok_or_else(|| UserError("Calling unavailable API ext_random_seed: wasm"))?; + + this.memory.set(seed_data, &seed) + .map_err(|_| UserError("Invalid attempt to set value in ext_random_seed"))?; + Ok(()) + }, + ext_local_storage_set(key: *const u8, key_len: u32, value: *const u8, value_len: u32) => { + let key = this.memory.get(key, key_len as usize) + .map_err(|_| UserError("OOB while ext_local_storage_set: wasm"))?; + let value = this.memory.get(value, value_len as usize) + .map_err(|_| UserError("OOB while ext_local_storage_set: wasm"))?; + + this.ext.offchain() + .map(|api| api.local_storage_set(&key, &value)) + .ok_or_else(|| UserError("Calling unavailable API ext_local_storage_set: wasm"))?; + + Ok(()) + }, + ext_local_storage_get(key: *const u8, key_len: u32, value_len: *mut u32) -> *mut u8 => { + let key = this.memory.get(key, key_len as usize) + .map_err(|_| UserError("OOB while ext_local_storage_get: wasm"))?; + + let maybe_value = this.ext.offchain() + .map(|api| api.local_storage_get(&key)) + .ok_or_else(|| UserError("Calling unavailable API ext_local_storage_get: wasm"))?; + + let (offset, len) = if let Some(value) = maybe_value { + let offset = this.heap.allocate(value.len() as u32)? as u32; + this.memory.set(offset, &value) + .map_err(|_| UserError("Invalid attempt to set memory in ext_local_storage_get"))?; + (offset, value.len() as u32) + } else { + (0, u32::max_value()) + }; + + this.memory.write_primitive(value_len, len) + .map_err(|_| UserError("Invalid attempt to write value_len in ext_local_storage_get"))?; + + Ok(offset) + }, + ext_http_request_start( + method: *const u8, + method_len: u32, + url: *const u8, + url_len: u32, + meta: *const u8, + meta_len: u32 + ) -> u32 => { + let method = this.memory.get(method, method_len as usize) + .map_err(|_| UserError("OOB while ext_http_request_start: wasm"))?; + let url = this.memory.get(url, url_len as usize) + .map_err(|_| UserError("OOB while ext_http_request_start: wasm"))?; + let meta = this.memory.get(meta, meta_len as usize) + .map_err(|_| UserError("OOB while ext_http_request_start: wasm"))?; + + let method_str = str::from_utf8(&method) + .map_err(|_| UserError("invalid str while ext_http_request_start: wasm"))?; + let url_str = str::from_utf8(&url) + .map_err(|_| UserError("invalid str while ext_http_request_start: wasm"))?; + + let id = this.ext.offchain() + .map(|api| api.http_request_start(method_str, url_str, &*meta)) + .ok_or_else(|| UserError("Calling unavailable API ext_http_request_start: wasm"))?; + + if let Ok(id) = id { + Ok(id.0 as u32) + } else { + Ok(u32::max_value()) + } + }, + ext_http_request_add_header( + request_id: u32, + name: *const u8, + name_len: u32, + value: *const u8, + value_len: u32 + ) -> u32 => { + let name = this.memory.get(name, name_len as usize) + .map_err(|_| UserError("OOB while ext_http_request_add_header: wasm"))?; + let value = this.memory.get(value, value_len as usize) + .map_err(|_| UserError("OOB while ext_http_request_add_header: wasm"))?; + + let name_str = str::from_utf8(&name) + .map_err(|_| UserError("invalid str while ext_http_request_add_header: wasm"))?; + let value_str = str::from_utf8(&value) + .map_err(|_| UserError("invalid str while ext_http_request_add_header: wasm"))?; + + let res = this.ext.offchain() + .map(|api| api.http_request_add_header( + offchain::HttpRequestId(request_id as u16), + &name_str, + &value_str, + )) + .ok_or_else(|| UserError("Calling unavailable API ext_http_request_add_header: wasm"))?; + + Ok(if res.is_ok() { 0 } else { 1 }) + }, + ext_http_request_write_body( + request_id: u32, + chunk: *const u8, + chunk_len: u32, + deadline: u64 + ) -> u32 => { + let chunk = this.memory.get(chunk, chunk_len as usize) + .map_err(|_| UserError("OOB while ext_http_request_write_body: wasm"))?; + + let res = this.ext.offchain() + .map(|api| api.http_request_write_body( + offchain::HttpRequestId(request_id as u16), + &chunk, + deadline_to_timestamp(deadline) + )) + .ok_or_else(|| UserError("Calling unavailable API ext_http_request_write_body: wasm"))?; + + Ok(match res { + Ok(()) => 0, + Err(e) => e as u8 as u32, + }) + }, + ext_http_response_wait( + ids: *const u32, + ids_len: u32, + statuses: *mut u32, + deadline: u64 + ) => { + let ids = (0..ids_len) + .map(|i| + this.memory.read_primitive(ids + i * 4) + .map(|id: u32| offchain::HttpRequestId(id as u16)) + .map_err(|_| UserError("OOB while ext_http_response_wait: wasm")) + ) + .collect::<::std::result::Result, _>>()?; - this.ext.submit_extrinsic(extrinsic) - .map_err(|_| UserError("Calling unavailable API ext_submit_extrinsic: wasm"))?; + let res = this.ext.offchain() + .map(|api| api.http_response_wait(&ids, deadline_to_timestamp(deadline))) + .ok_or_else(|| UserError("Calling unavailable API ext_http_response_wait: wasm"))? + .into_iter() + .map(|status| status.into()) + .enumerate() + // make sure to take up to `ids_len` to avoid exceeding the mem. + .take(ids_len as usize); + + for (i, status) in res { + this.memory.write_primitive(statuses + i as u32 * 4, status) + .map_err(|_| UserError("Invalid attempt to set memory in ext_http_response_wait"))?; + } Ok(()) }, + ext_http_response_headers( + request_id: u32, + written_out: *mut u32 + ) -> *mut u8 => { + use parity_codec::Encode; + + let headers = this.ext.offchain() + .map(|api| api.http_response_headers(offchain::HttpRequestId(request_id as u16))) + .ok_or_else(|| UserError("Calling unavailable API ext_http_response_headers: wasm"))?; + + let encoded = headers.encode(); + let len = encoded.len() as u32; + let offset = this.heap.allocate(len)? as u32; + this.memory.set(offset, &encoded) + .map_err(|_| UserError("Invalid attempt to set memory in ext_http_response_headers"))?; + this.memory.write_primitive(written_out, len) + .map_err(|_| UserError("Invalid attempt to write written_out in ext_http_response_headers"))?; + + Ok(offset) + }, + ext_http_response_read_body( + request_id: u32, + buffer: *mut u8, + buffer_len: u32, + deadline: u64 + ) -> u32 => { + let mut internal_buffer = Vec::with_capacity(buffer_len as usize); + internal_buffer.resize(buffer_len as usize, 0); + + let res = this.ext.offchain() + .map(|api| api.http_response_read_body( + offchain::HttpRequestId(request_id as u16), + &mut internal_buffer, + deadline_to_timestamp(deadline), + )) + .ok_or_else(|| UserError("Calling unavailable API ext_http_response_read_body: wasm"))?; + + Ok(match res { + Ok(read) => { + this.memory.set(buffer, &internal_buffer[..read]) + .map_err(|_| UserError("Invalid attempt to set memory in ext_http_response_read_body"))?; + + read as u32 + }, + Err(err) => { + u32::max_value() - err as u8 as u32 + 1 + } + }) + }, ext_sandbox_instantiate( dispatch_thunk_idx: usize, wasm_ptr: *const u8, @@ -749,7 +1101,7 @@ impl WasmExecutor { /// This should be used for tests only. pub fn call_with_custom_signature< E: Externalities, - F: FnOnce(&mut FnMut(&[u8]) -> Result) -> Result>, + F: FnOnce(&mut dyn FnMut(&[u8]) -> Result) -> Result>, FR: FnOnce(Option, &MemoryRef) -> Result>, R, >( @@ -769,9 +1121,9 @@ impl WasmExecutor { fn get_mem_instance(module: &ModuleRef) -> Result { Ok(module .export_by_name("memory") - .ok_or_else(|| Error::from(ErrorKind::InvalidMemoryReference))? + .ok_or_else(|| Error::InvalidMemoryReference)? .as_memory() - .ok_or_else(|| Error::from(ErrorKind::InvalidMemoryReference))? + .ok_or_else(|| Error::InvalidMemoryReference)? .clone()) } @@ -795,7 +1147,7 @@ impl WasmExecutor { if let Some(I64(r)) = res { let offset = r as u32; let length = (r as u64 >> 32) as usize; - memory.get(offset, length).map_err(|_| ErrorKind::Runtime.into()).map(Some) + memory.get(offset, length).map_err(|_| Error::Runtime).map(Some) } else { Ok(None) } @@ -806,7 +1158,7 @@ impl WasmExecutor { /// Call a given method in the given wasm-module runtime. fn call_in_wasm_module_with_custom_signature< E: Externalities, - F: FnOnce(&mut FnMut(&[u8]) -> Result) -> Result>, + F: FnOnce(&mut dyn FnMut(&[u8]) -> Result) -> Result>, FR: FnOnce(Option, &MemoryRef) -> Result>, R, >( @@ -828,7 +1180,7 @@ impl WasmExecutor { let used_mem = memory.used_size(); let mut fec = FunctionExecutor::new(memory.clone(), table, ext)?; let parameters = create_parameters(&mut |data: &[u8]| { - let offset = fec.heap.allocate(data.len() as u32).map_err(|_| ErrorKind::Runtime)?; + let offset = fec.heap.allocate(data.len() as u32).map_err(|_| Error::Runtime)?; memory.set(offset, &data)?; Ok(offset) })?; @@ -841,7 +1193,7 @@ impl WasmExecutor { let result = match result { Ok(val) => match filter_result(val, &memory)? { Some(val) => Ok(val), - None => Err(ErrorKind::InvalidReturn.into()), + None => Err(Error::InvalidReturn), }, Err(e) => { trace!(target: "wasm-executor", "Failed to execute code with {} pages", memory.current_size().0); @@ -877,7 +1229,7 @@ impl WasmExecutor { // extract a reference to a linear memory, optional reference to a table // and then initialize FunctionExecutor. let memory = Self::get_mem_instance(intermediate_instance.not_started_instance())?; - memory.grow(Pages(heap_pages)).map_err(|_| Error::from(ErrorKind::Runtime))?; + memory.grow(Pages(heap_pages)).map_err(|_| Error::Runtime)?; let table: Option = intermediate_instance .not_started_instance() .export_by_name("__indirect_function_table") @@ -896,10 +1248,12 @@ mod tests { use parity_codec::Encode; - use state_machine::TestExternalities; + use state_machine::TestExternalities as CoreTestExternalities; use hex_literal::hex; use primitives::map; + type TestExternalities = CoreTestExternalities; + #[test] fn returning_should_work() { let mut ext = TestExternalities::default(); diff --git a/core/executor/src/wasm_utils.rs b/core/executor/src/wasm_utils.rs index a9fbca7f6ca4faa6ac1c35616a967e46fa62e5f6..7384f91944c503d7a335d865bc2dcd8b7f03b8ea 100644 --- a/core/executor/src/wasm_utils.rs +++ b/core/executor/src/wasm_utils.rs @@ -174,7 +174,7 @@ macro_rules! impl_function_executor { => $($pre:tt)+ ) => ( impl $( $pre ) + $structname { #[allow(unused)] - fn resolver() -> &'static $crate::wasmi::ModuleImportResolver { + fn resolver() -> &'static dyn $crate::wasmi::ModuleImportResolver { struct Resolver; impl $crate::wasmi::ModuleImportResolver for Resolver { fn resolve_func(&self, name: &str, signature: &$crate::wasmi::Signature) -> ::std::result::Result<$crate::wasmi::FuncRef, $crate::wasmi::Error> { diff --git a/core/executor/wasm/Cargo.lock b/core/executor/wasm/Cargo.lock index b65d8e08694a0021989a33d819649f0230ee844c..34cd17116c3c1708e76d2923a21fc47b15d598ee 100644 --- a/core/executor/wasm/Cargo.lock +++ b/core/executor/wasm/Cargo.lock @@ -2,12 +2,17 @@ # It is not intended for manual editing. [[package]] name = "arrayvec" -version = "0.4.7" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "autocfg" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byteorder" version = "1.3.1" @@ -15,12 +20,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crunchy" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "fixed-hash" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -28,15 +33,15 @@ dependencies = [ [[package]] name = "hash-db" -version = "0.12.0" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hash256-std-hasher" -version = "0.12.0" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -49,15 +54,23 @@ dependencies = [ [[package]] name = "nodrop" -version = "0.1.12" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "num-traits" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "parity-codec" version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -66,33 +79,33 @@ name = "parity-codec-derive" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "primitive-types" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-crate" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro2" -version = "0.4.19" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -100,10 +113,10 @@ dependencies = [ [[package]] name = "quote" -version = "0.6.8" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -143,14 +156,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.79" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "sr-io" version = "2.0.0" dependencies = [ - "hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", @@ -184,39 +197,40 @@ name = "substrate-primitives" version = "2.0.0" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", ] [[package]] name = "syn" -version = "0.15.26" +version = "0.15.34" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "toml" -version = "0.4.10" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "uint" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -226,27 +240,29 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [metadata] -"checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" +"checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" +"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" -"checksum crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c240f247c278fa08a6d4820a6a222bfc6e0d999e51ba67be94f44c905b2161f2" -"checksum fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a557e80084b05c32b455963ff565a9de6f2866da023d6671705c6aff6f65e01c" -"checksum hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07463834729d0ce8d475e7dd6d302e407093ad9a9c02d77eb07fb74b5373829d" -"checksum hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1224388a21c88a80ae7087a2a245ca6d80acc97a9186b75789fb3eeefd0609af" +"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +"checksum fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" +"checksum hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fb417e5c470acdd61068c79767d0e65962e70836cf6c9dfd2409f06345ce0" +"checksum hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b2027c19ec91eb304999abae7307d225cf93be42af53b0039f76e98ed5af86" "checksum impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2050d823639fbeae26b2b5ba09aca8907793117324858070ade0673c49f793b" -"checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" +"checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" +"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb43c05fb71c03b4ea7327bf15694da1e0f23f19d5b1e95bab6c6d74097e336" "checksum parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00a486fd383382ddcb2de928364b1f82571c1e48274fc43b7667a4738ee4056c" -"checksum primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edb92f1ebfc177432c03287b15d48c202e6e2c95993a7af3ba039abb43b1492e" -"checksum proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c6cf4e5b00300d151dfffae39f529dfa5188f42eeb14201229aa420d6aad10c" -"checksum proc-macro2 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)" = "ffe022fb8c8bd254524b0b3305906c1921fa37a84a644e29079a9e62200c3901" -"checksum quote 0.6.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dd636425967c33af890042c483632d33fa7a18f19ad1d7ea72e8998c6ef8dea5" +"checksum primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6e8612a8dc70f26276fed6131c153ca277cf275ee0a5e2a50cd8a69c697beb8f" +"checksum proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" -"checksum serde 1.0.79 (registry+https://github.com/rust-lang/crates.io-index)" = "84257ccd054dc351472528c8587b4de2dbf0dc0fe2e634030c1a90bfdacebaa9" +"checksum serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "a72e9b96fa45ce22a4bc23da3858dfccfd60acd28a25bcd328a98fdd6bea43fd" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" -"checksum syn 0.15.26 (registry+https://github.com/rust-lang/crates.io-index)" = "f92e629aa1d9c827b2bb8297046c1ccffc57c99b947a680d3ccff1f136a3bee9" -"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" -"checksum uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7780bb27fd8a22295e0d9d53ae3be253f715a0dccb1808527f478f1c2603708" +"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" +"checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039" +"checksum uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2143cded94692b156c356508d92888acc824db5bffc0b4089732264c6fcf86d4" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" diff --git a/core/executor/wasm/build.sh b/core/executor/wasm/build.sh index c23ac076e210aa3d00c5550e18e40b4c9d90d09c..9414c8037b57933d2da64d1f562ffbdfdab32e1f 100755 --- a/core/executor/wasm/build.sh +++ b/core/executor/wasm/build.sh @@ -6,7 +6,7 @@ if cargo --version | grep -q "nightly"; then else CARGO_CMD="cargo +nightly" fi -CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release +CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release "$@" for i in test do wasm-gc target/wasm32-unknown-unknown/release/runtime_$i.wasm target/wasm32-unknown-unknown/release/runtime_$i.compact.wasm diff --git a/core/finality-grandpa/Cargo.toml b/core/finality-grandpa/Cargo.toml index 9d44c8ee3eb051fee246c7f2381479c11d557bf6..bbd6297d3576e7048c6fcdabcf01f3ce2f2a51cb 100644 --- a/core/finality-grandpa/Cargo.toml +++ b/core/finality-grandpa/Cargo.toml @@ -8,7 +8,7 @@ edition = "2018" fork-tree = { path = "../../core/util/fork-tree" } futures = "0.1" log = "0.4" -parking_lot = "0.7.1" +parking_lot = "0.8.0" tokio = "0.1.7" rand = "0.6" parity-codec = { version = "3.3", features = ["derive"] } @@ -29,7 +29,7 @@ grandpa = { package = "finality-grandpa", version = "0.7.2", features = ["derive consensus_common = { package = "substrate-consensus-common", path = "../consensus/common", features = ["test-helpers"] } network = { package = "substrate-network", path = "../network", features = ["test-helpers"] } keyring = { package = "substrate-keyring", path = "../keyring" } -test_client = { package = "substrate-test-client", path = "../test-client"} +test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client"} env_logger = "0.6" [features] diff --git a/core/finality-grandpa/src/aux_schema.rs b/core/finality-grandpa/src/aux_schema.rs index 4dd6e75dd946f595a6e1d3a82bc28d9a67a42f4f..824c65b9e61648faa65bad75c7ff13e0914f9278 100644 --- a/core/finality-grandpa/src/aux_schema.rs +++ b/core/finality-grandpa/src/aux_schema.rs @@ -151,16 +151,22 @@ fn migrate_from_version0( None => (0, genesis_round()), }; + let set_id = new_set.current().0; + let base = last_round_state.prevote_ghost .expect("state is for completed round; completed rounds must have a prevote ghost; qed."); let set_state = VoterSetState::Live { - completed_rounds: CompletedRounds::new(CompletedRound { - number: last_round_number, - state: last_round_state, - votes: Vec::new(), - base, - }), + completed_rounds: CompletedRounds::new( + CompletedRound { + number: last_round_number, + state: last_round_state, + votes: Vec::new(), + base, + }, + set_id, + &new_set, + ), current_round: HasVoted::No, }; @@ -189,6 +195,19 @@ fn migrate_from_version1( backend, AUTHORITY_SET_KEY, )? { + let set_id = set.current().0; + + let completed_rounds = |number, state, base| CompletedRounds::new( + CompletedRound { + number, + state, + votes: Vec::new(), + base, + }, + set_id, + &set, + ); + let set_state = match load_decode::<_, V1VoterSetState>>( backend, SET_STATE_KEY, @@ -198,12 +217,7 @@ fn migrate_from_version1( .expect("state is for completed round; completed rounds must have a prevote ghost; qed."); VoterSetState::Paused { - completed_rounds: CompletedRounds::new(CompletedRound { - number: last_round_number, - state: set_state, - votes: Vec::new(), - base, - }), + completed_rounds: completed_rounds(last_round_number, set_state, base), } }, Some(V1VoterSetState::Live(last_round_number, set_state)) => { @@ -211,12 +225,7 @@ fn migrate_from_version1( .expect("state is for completed round; completed rounds must have a prevote ghost; qed."); VoterSetState::Live { - completed_rounds: CompletedRounds::new(CompletedRound { - number: last_round_number, - state: set_state, - votes: Vec::new(), - base, - }), + completed_rounds: completed_rounds(last_round_number, set_state, base), current_round: HasVoted::No, } }, @@ -226,12 +235,7 @@ fn migrate_from_version1( .expect("state is for completed round; completed rounds must have a prevote ghost; qed."); VoterSetState::Live { - completed_rounds: CompletedRounds::new(CompletedRound { - number: 0, - state: set_state, - votes: Vec::new(), - base, - }), + completed_rounds: completed_rounds(0, set_state, base), current_round: HasVoted::No, } }, @@ -298,12 +302,16 @@ pub(crate) fn load_persistent( .expect("state is for completed round; completed rounds must have a prevote ghost; qed."); VoterSetState::Live { - completed_rounds: CompletedRounds::new(CompletedRound { - number: 0, - votes: Vec::new(), - base, - state, - }), + completed_rounds: CompletedRounds::new( + CompletedRound { + number: 0, + votes: Vec::new(), + base, + state, + }, + set.current().0, + &set, + ), current_round: HasVoted::No, } } @@ -325,18 +333,23 @@ pub(crate) fn load_persistent( info!(target: "afg", "Loading GRANDPA authority set \ from genesis on what appears to be first startup."); - let genesis_set = AuthoritySet::genesis(genesis_authorities()?); + let genesis_authorities = genesis_authorities()?; + let genesis_set = AuthoritySet::genesis(genesis_authorities.clone()); let state = make_genesis_round(); let base = state.prevote_ghost .expect("state is for completed round; completed rounds must have a prevote ghost; qed."); let genesis_state = VoterSetState::Live { - completed_rounds: CompletedRounds::new(CompletedRound { - number: 0, - votes: Vec::new(), - state, - base, - }), + completed_rounds: CompletedRounds::new( + CompletedRound { + number: 0, + votes: Vec::new(), + state, + base, + }, + 0, + &genesis_set, + ), current_round: HasVoted::No, }; backend.insert_aux( @@ -355,6 +368,10 @@ pub(crate) fn load_persistent( } /// Update the authority set on disk after a change. +/// +/// If there has just been a handoff, pass a `new_set` parameter that describes the +/// handoff. `set` in all cases should reflect the current authority set, with all +/// changes and handoffs applied. pub(crate) fn update_authority_set( set: &AuthoritySet>, new_set: Option<&NewAuthoritySet>>, @@ -385,12 +402,16 @@ pub(crate) fn update_authority_set( new_set.canon_number.clone(), )); let set_state = VoterSetState::::Live { - completed_rounds: CompletedRounds::new(CompletedRound { - number: 0, - state: round_state, - votes: Vec::new(), - base: (new_set.canon_hash, new_set.canon_number), - }), + completed_rounds: CompletedRounds::new( + CompletedRound { + number: 0, + state: round_state, + votes: Vec::new(), + base: (new_set.canon_hash, new_set.canon_number), + }, + new_set.set_id, + &set, + ), current_round: HasVoted::No, }; let encoded = set_state.encode(); @@ -500,7 +521,7 @@ mod test { assert_eq!( *authority_set.inner().read(), AuthoritySet { - current_authorities: authorities, + current_authorities: authorities.clone(), pending_standard_changes: ForkTree::new(), pending_forced_changes: Vec::new(), set_id, @@ -510,12 +531,16 @@ mod test { assert_eq!( &*set_state.read(), &VoterSetState::Live { - completed_rounds: CompletedRounds::new(CompletedRound { - number: round_number, - state: round_state.clone(), - base: round_state.prevote_ghost.unwrap(), - votes: vec![], - }), + completed_rounds: CompletedRounds::new( + CompletedRound { + number: round_number, + state: round_state.clone(), + base: round_state.prevote_ghost.unwrap(), + votes: vec![], + }, + set_id, + &*authority_set.inner().read(), + ), current_round: HasVoted::No, }, ); @@ -583,7 +608,7 @@ mod test { assert_eq!( *authority_set.inner().read(), AuthoritySet { - current_authorities: authorities, + current_authorities: authorities.clone(), pending_standard_changes: ForkTree::new(), pending_forced_changes: Vec::new(), set_id, @@ -593,12 +618,16 @@ mod test { assert_eq!( &*set_state.read(), &VoterSetState::Live { - completed_rounds: CompletedRounds::new(CompletedRound { - number: round_number, - state: round_state.clone(), - base: round_state.prevote_ghost.unwrap(), - votes: vec![], - }), + completed_rounds: CompletedRounds::new( + CompletedRound { + number: round_number, + state: round_state.clone(), + base: round_state.prevote_ghost.unwrap(), + votes: vec![], + }, + set_id, + &*authority_set.inner().read(), + ), current_round: HasVoted::No, }, ); diff --git a/core/finality-grandpa/src/communication/gossip.rs b/core/finality-grandpa/src/communication/gossip.rs index fd9d30e9519d647e81f5c449e23010fe4ff252af..ca529125ec172bd2c5ed08a51fd904fe8f304fd2 100644 --- a/core/finality-grandpa/src/communication/gossip.rs +++ b/core/finality-grandpa/src/communication/gossip.rs @@ -71,6 +71,7 @@ use runtime_primitives::traits::{NumberFor, Block as BlockT, Zero}; use network::consensus_gossip::{self as network_gossip, MessageIntent, ValidatorContext}; use network::{config::Roles, PeerId}; use parity_codec::{Encode, Decode}; +use crate::ed25519::Public as AuthorityId; use substrate_telemetry::{telemetry, CONSENSUS_DEBUG}; use log::{trace, debug, warn}; @@ -94,6 +95,8 @@ enum Consider { RejectPast, /// Message is from the future. Reject. RejectFuture, + /// Message cannot be evaluated. Reject. + RejectOutOfScope, } /// A view of protocol state. @@ -300,6 +303,10 @@ pub(super) enum Misbehavior { // A message received that's from the future relative to our view. // always misbehavior. FutureMessage, + // A message received that cannot be evaluated relative to our view. + // This happens before we have a view and have sent out neighbor packets. + // always misbehavior. + OutOfScopeMessage, } impl Misbehavior { @@ -319,6 +326,7 @@ impl Misbehavior { (benefit as i32).saturating_add(cost as i32) }, FutureMessage => cost::FUTURE_MESSAGE, + OutOfScopeMessage => cost::OUT_OF_SCOPE_MESSAGE, } } } @@ -407,7 +415,7 @@ impl Peers { } } -#[derive(Debug)] +#[derive(Debug, PartialEq)] pub(super) enum Action { // repropagate under given topic, to the given peers, applying cost/benefit to originator. Keep(H, i32), @@ -418,9 +426,10 @@ pub(super) enum Action { } struct Inner { - local_view: View>, + local_view: Option>>, peers: Peers>, live_topics: KeepTopics, + authorities: Vec, config: crate::Config, next_rebroadcast: Instant, } @@ -430,58 +439,87 @@ type MaybeMessage = Option<(Vec, NeighborPacket> impl Inner { fn new(config: crate::Config) -> Self { Inner { - local_view: View::default(), + local_view: None, peers: Peers::default(), live_topics: KeepTopics::new(), next_rebroadcast: Instant::now() + REBROADCAST_AFTER, + authorities: Vec::new(), config, } } - /// Note a round in a set has started. - fn note_round(&mut self, round: Round, set_id: SetId) -> MaybeMessage { - if self.local_view.round == round && self.local_view.set_id == set_id { - return None; - } + /// Note a round in the current set has started. + fn note_round(&mut self, round: Round) -> MaybeMessage { + { + let local_view = match self.local_view { + None => return None, + Some(ref mut v) => if v.round == round { + return None + } else { + v + }, + }; + + let set_id = local_view.set_id; - debug!(target: "afg", "Voter {} noting beginning of round {:?} to network.", - self.config.name(), (round, set_id)); + debug!(target: "afg", "Voter {} noting beginning of round {:?} to network.", + self.config.name(), (round,set_id)); - self.local_view.round = round; - self.local_view.set_id = set_id; + local_view.round = round; - self.live_topics.push(round, set_id); + self.live_topics.push(round, set_id); + } self.multicast_neighbor_packet() } /// Note that a voter set with given ID has started. Does nothing if the last /// call to the function was with the same `set_id`. - fn note_set(&mut self, set_id: SetId) -> MaybeMessage { - if self.local_view.set_id == set_id { - return None; - } + fn note_set(&mut self, set_id: SetId, authorities: Vec) -> MaybeMessage { + { + let local_view = match self.local_view { + ref mut x @ None => x.get_or_insert(View { + round: Round(0), + set_id, + last_commit: None, + }), + Some(ref mut v) => if v.set_id == set_id { + return None + } else { + v + }, + }; - self.local_view.update_set(set_id); - self.live_topics.push(Round(0), set_id); + local_view.update_set(set_id); + self.live_topics.push(Round(0), set_id); + self.authorities = authorities; + } self.multicast_neighbor_packet() } /// Note that we've imported a commit finalizing a given block. fn note_commit_finalized(&mut self, finalized: NumberFor) -> MaybeMessage { - if self.local_view.last_commit.as_ref() < Some(&finalized) { - self.local_view.last_commit = Some(finalized); - self.multicast_neighbor_packet() - } else { - None + { + match self.local_view { + None => return None, + Some(ref mut v) => if v.last_commit.as_ref() < Some(&finalized) { + v.last_commit = Some(finalized); + } else { + return None + }, + }; } + + self.multicast_neighbor_packet() } fn consider_vote(&self, round: Round, set_id: SetId) -> Consider { - self.local_view.consider_vote(round, set_id) + self.local_view.as_ref().map(|v| v.consider_vote(round, set_id)) + .unwrap_or(Consider::RejectOutOfScope) } fn consider_global(&self, set_id: SetId, number: NumberFor) -> Consider { - self.local_view.consider_global(set_id, number) + self.local_view.as_ref().map(|v| v.consider_global(set_id, number)) + .unwrap_or(Consider::RejectOutOfScope) } fn cost_past_rejection(&self, _who: &PeerId, _round: Round, _set_id: SetId) -> i32 { @@ -494,11 +532,18 @@ impl Inner { { match self.consider_vote(full.round, full.set_id) { Consider::RejectFuture => return Action::Discard(Misbehavior::FutureMessage.cost()), + Consider::RejectOutOfScope => return Action::Discard(Misbehavior::OutOfScopeMessage.cost()), Consider::RejectPast => return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id)), Consider::Accept => {}, } + // ensure authority is part of the set. + if !self.authorities.contains(&full.message.id) { + telemetry!(CONSENSUS_DEBUG; "afg.bad_msg_signature"; "signature" => ?full.message.id); + return Action::Discard(cost::UNKNOWN_VOTER); + } + if let Err(()) = super::check_message_sig::( &full.message.message, &full.message.id, @@ -527,7 +572,9 @@ impl Inner { Consider::RejectFuture => return Action::Discard(Misbehavior::FutureMessage.cost()), Consider::RejectPast => return Action::Discard(self.cost_past_rejection(who, full.round, full.set_id)), + Consider::RejectOutOfScope => return Action::Discard(Misbehavior::OutOfScopeMessage.cost()), Consider::Accept => {}, + } if full.message.precommits.len() != full.message.auth_data.len() || full.message.precommits.is_empty() { @@ -561,14 +608,16 @@ impl Inner { } fn multicast_neighbor_packet(&self) -> MaybeMessage { - let packet = NeighborPacket { - round: self.local_view.round, - set_id: self.local_view.set_id, - commit_finalized_height: self.local_view.last_commit.unwrap_or(Zero::zero()), - }; + self.local_view.as_ref().map(|local_view| { + let packet = NeighborPacket { + round: local_view.round, + set_id: local_view.set_id, + commit_finalized_height: local_view.last_commit.unwrap_or(Zero::zero()), + }; - let peers = self.peers.inner.keys().cloned().collect(); - Some((peers, packet)) + let peers = self.peers.inner.keys().cloned().collect(); + (peers, packet) + }) } } @@ -579,7 +628,7 @@ pub(super) struct GossipValidator { } impl GossipValidator { - /// Create a new gossip-validator. + /// Create a new gossip-validator. This initialized the current set to 0. pub(super) fn new(config: crate::Config) -> (GossipValidator, ReportStream) { let (tx, rx) = mpsc::unbounded(); let val = GossipValidator { @@ -590,21 +639,22 @@ impl GossipValidator { (val, ReportStream { reports: rx }) } - /// Note a round in a set has started. - pub(super) fn note_round(&self, round: Round, set_id: SetId, send_neighbor: F) + /// Note a round in the current set has started. + pub(super) fn note_round(&self, round: Round, send_neighbor: F) where F: FnOnce(Vec, NeighborPacket>) { - let maybe_msg = self.inner.write().note_round(round, set_id); + let maybe_msg = self.inner.write().note_round(round); if let Some((to, msg)) = maybe_msg { send_neighbor(to, msg); } } - /// Note that a voter set with given ID has started. - pub(super) fn note_set(&self, set_id: SetId, send_neighbor: F) + /// Note that a voter set with given ID has started. Updates the current set to given + /// value and initializes the round to 0. + pub(super) fn note_set(&self, set_id: SetId, authorities: Vec, send_neighbor: F) where F: FnOnce(Vec, NeighborPacket>) { - let maybe_msg = self.inner.write().note_set(set_id); + let maybe_msg = self.inner.write().note_set(set_id, authorities); if let Some((to, msg)) = maybe_msg { send_neighbor(to, msg); } @@ -657,27 +707,31 @@ impl GossipValidator { } impl network_gossip::Validator for GossipValidator { - fn new_peer(&self, context: &mut ValidatorContext, who: &PeerId, _roles: Roles) { - let packet_data = { + fn new_peer(&self, context: &mut dyn ValidatorContext, who: &PeerId, _roles: Roles) { + let packet = { let mut inner = self.inner.write(); inner.peers.new_peer(who.clone()); - let packet = NeighborPacket { - round: inner.local_view.round, - set_id: inner.local_view.set_id, - commit_finalized_height: inner.local_view.last_commit.unwrap_or(Zero::zero()), - }; - - GossipMessage::::from(packet).encode() + inner.local_view.as_ref().map(|v| { + NeighborPacket { + round: v.round, + set_id: v.set_id, + commit_finalized_height: v.last_commit.unwrap_or(Zero::zero()), + } + }) }; - context.send_message(who, packet_data); + + if let Some(packet) = packet { + let packet_data = GossipMessage::::from(packet).encode(); + context.send_message(who, packet_data); + } } - fn peer_disconnected(&self, _context: &mut ValidatorContext, who: &PeerId) { + fn peer_disconnected(&self, _context: &mut dyn ValidatorContext, who: &PeerId) { self.inner.write().peers.peer_disconnected(who); } - fn validate(&self, context: &mut ValidatorContext, who: &PeerId, data: &[u8]) + fn validate(&self, context: &mut dyn ValidatorContext, who: &PeerId, data: &[u8]) -> network_gossip::ValidationResult { let (action, broadcast_topics) = self.do_validate(who, data); @@ -690,6 +744,7 @@ impl network_gossip::Validator for GossipValidator match action { Action::Keep(topic, cb) => { self.report(who.clone(), cb); + context.broadcast_message(topic, data.to_vec(), false); network_gossip::ValidationResult::ProcessAndKeep(topic) } Action::ProcessAndDiscard(topic, cb) => { @@ -704,7 +759,7 @@ impl network_gossip::Validator for GossipValidator } fn message_allowed<'a>(&'a self) - -> Box bool + 'a> + -> Box bool + 'a> { let (inner, do_rebroadcast) = { use parking_lot::RwLockWriteGuard; @@ -745,7 +800,12 @@ impl network_gossip::Validator for GossipValidator } // global message. - let our_best_commit = inner.local_view.last_commit; + let local_view = match inner.local_view { + Some(ref v) => v, + None => return false, // cannot evaluate until we have a local view. + }; + + let our_best_commit = local_view.last_commit; let peer_best_commit = peer.view.last_commit; match GossipMessage::::decode(&mut data) { @@ -762,7 +822,7 @@ impl network_gossip::Validator for GossipValidator }) } - fn message_expired<'a>(&'a self) -> Box bool + 'a> { + fn message_expired<'a>(&'a self) -> Box bool + 'a> { let inner = self.inner.read(); Box::new(move |topic, mut data| { // if the topic is not one of the ones that we are keeping at the moment, @@ -773,8 +833,13 @@ impl network_gossip::Validator for GossipValidator Some((None, _)) => {}, }; + let local_view = match inner.local_view { + Some(ref v) => v, + None => return true, // no local view means we can't evaluate or hold any topic. + }; + // global messages -- only keep the best commit. - let best_commit = inner.local_view.last_commit; + let best_commit = local_view.last_commit; match GossipMessage::::decode(&mut data) { None => true, @@ -1003,8 +1068,10 @@ mod tests { let set_id = 1; + val.note_set(SetId(set_id), Vec::new(), |_, _| {}); + for round_num in 1u64..10 { - val.note_round(Round(round_num), SetId(set_id), |_, _| {}); + val.note_round(Round(round_num), |_, _| {}); } { @@ -1024,4 +1091,47 @@ mod tests { } } } + + #[test] + fn message_from_unknown_authority_discarded() { + assert!(cost::UNKNOWN_VOTER != cost::BAD_SIGNATURE); + + let (val, _) = GossipValidator::::new(config()); + let set_id = 1; + let auth = AuthorityId::from_raw([1u8; 32]); + let peer = PeerId::random(); + + val.note_set(SetId(set_id), vec![auth.clone()], |_, _| {}); + val.note_round(Round(0), |_, _| {}); + + let inner = val.inner.read(); + let unknown_voter = inner.validate_round_message(&peer, &VoteOrPrecommitMessage { + round: Round(0), + set_id: SetId(set_id), + message: SignedMessage:: { + message: grandpa::Message::Prevote(grandpa::Prevote { + target_hash: Default::default(), + target_number: 10, + }), + signature: Default::default(), + id: AuthorityId::from_raw([2u8; 32]), + } + }); + + let bad_sig = inner.validate_round_message(&peer, &VoteOrPrecommitMessage { + round: Round(0), + set_id: SetId(set_id), + message: SignedMessage:: { + message: grandpa::Message::Prevote(grandpa::Prevote { + target_hash: Default::default(), + target_number: 10, + }), + signature: Default::default(), + id: auth.clone(), + } + }); + + assert_eq!(unknown_voter, Action::Discard(cost::UNKNOWN_VOTER)); + assert_eq!(bad_sig, Action::Discard(cost::BAD_SIGNATURE)); + } } diff --git a/core/finality-grandpa/src/communication/mod.rs b/core/finality-grandpa/src/communication/mod.rs index 395f8202548cc3b186bc8d62984b565b71667487..58d9cd6421bc8d0627608803a09928767969476f 100644 --- a/core/finality-grandpa/src/communication/mod.rs +++ b/core/finality-grandpa/src/communication/mod.rs @@ -39,7 +39,7 @@ use substrate_primitives::{ed25519, Pair}; use substrate_telemetry::{telemetry, CONSENSUS_DEBUG, CONSENSUS_INFO}; use runtime_primitives::ConsensusEngineId; use runtime_primitives::traits::{Block as BlockT, Hash as HashT, Header as HeaderT}; -use network::{consensus_gossip as network_gossip, Service as NetworkService}; +use network::{consensus_gossip as network_gossip, NetworkService}; use network_gossip::ConsensusMessage; use crate::{Error, Message, SignedMessage, Commit, CompactCommit}; @@ -64,12 +64,14 @@ mod cost { pub(super) const BAD_SIGNATURE: i32 = -100; pub(super) const MALFORMED_COMMIT: i32 = -1000; pub(super) const FUTURE_MESSAGE: i32 = -500; + pub(super) const UNKNOWN_VOTER: i32 = -150; pub(super) const INVALID_VIEW_CHANGE: i32 = -500; pub(super) const PER_UNDECODABLE_BYTE: i32 = -5; pub(super) const PER_SIGNATURE_CHECKED: i32 = -25; pub(super) const PER_BLOCK_LOADED: i32 = -10; pub(super) const INVALID_COMMIT: i32 = -5000; + pub(super) const OUT_OF_SCOPE_MESSAGE: i32 = -500; } // benefit scalars for reporting peers. @@ -99,6 +101,12 @@ pub trait Network: Clone + Send + 'static { /// Only should be used in case of consensus stall. fn gossip_message(&self, topic: Block::Hash, data: Vec, force: bool); + /// Register a message with the gossip service, it isn't broadcast right + /// away to any peers, but may be sent to new peers joining or when asked to + /// broadcast the topic. Useful to register previous messages on node + /// startup. + fn register_gossip_message(&self, topic: Block::Hash, data: Vec); + /// Send a message to a bunch of specific peers, even if they've seen it already. fn send_message(&self, who: Vec, data: Vec); @@ -145,11 +153,21 @@ impl Network for Arc> where engine_id: GRANDPA_ENGINE_ID, data, }; + self.with_gossip( move |gossip, ctx| gossip.multicast(ctx, topic, msg, force) ) } + fn register_gossip_message(&self, topic: B::Hash, data: Vec) { + let msg = ConsensusMessage { + engine_id: GRANDPA_ENGINE_ID, + data, + }; + + self.with_gossip(move |gossip, _| gossip.register_message(topic, msg)) + } + fn send_message(&self, who: Vec, data: Vec) { let msg = ConsensusMessage { engine_id: GRANDPA_ENGINE_ID, @@ -212,9 +230,12 @@ pub(crate) struct NetworkBridge> { impl> NetworkBridge { /// Create a new NetworkBridge to the given NetworkService. Returns the service /// handle and a future that must be polled to completion to finish startup. + /// If a voter set state is given it registers previous round votes with the + /// gossip service. pub(crate) fn new( service: N, config: crate::Config, + set_state: Option<&crate::environment::VoterSetState>, on_exit: impl Future + Clone + Send + 'static, ) -> ( Self, @@ -225,6 +246,44 @@ impl> NetworkBridge { let validator = Arc::new(validator); service.register_validator(validator.clone()); + if let Some(set_state) = set_state { + // register all previous votes with the gossip service so that they're + // available to peers potentially stuck on a previous round. + let completed = set_state.completed_rounds(); + let (set_id, voters) = completed.set_info(); + validator.note_set(SetId(set_id), voters.to_vec(), |_, _| {}); + for round in completed.iter() { + let topic = round_topic::(round.number, set_id); + + // we need to note the round with the gossip validator otherwise + // messages will be ignored. + validator.note_round(Round(round.number), |_, _| {}); + + for signed in round.votes.iter() { + let message = gossip::GossipMessage::VoteOrPrecommit( + gossip::VoteOrPrecommitMessage:: { + message: signed.clone(), + round: Round(round.number), + set_id: SetId(set_id), + } + ); + + service.register_gossip_message( + topic, + message.encode(), + ); + } + + trace!(target: "afg", + "Registered {} messages for topic {:?} (round: {}, set_id: {})", + round.votes.len(), + topic, + round.number, + set_id, + ); + } + } + let (rebroadcast_job, neighbor_sender) = periodic::neighbor_packet_worker(service.clone()); let reporting_job = report_stream.consume(service.clone()); @@ -241,7 +300,7 @@ impl> NetworkBridge { (bridge, startup_work) } - /// Get the round messages for a round in a given set ID. These are signature-checked. + /// Get the round messages for a round in the current set ID. These are signature-checked. pub(crate) fn round_communication( &self, round: Round, @@ -253,9 +312,18 @@ impl> NetworkBridge { impl Stream,Error=Error>, impl Sink,SinkError=Error>, ) { + // is a no-op if currently in that set. + self.validator.note_set( + set_id, + voters.voters().iter().map(|(v, _)| v.clone()).collect(), + |to, neighbor| self.service.send_message( + to, + GossipMessage::::from(neighbor).encode() + ), + ); + self.validator.note_round( round, - set_id, |to, neighbor| self.service.send_message( to, GossipMessage::::from(neighbor).encode() @@ -356,6 +424,7 @@ impl> NetworkBridge { ) { self.validator.note_set( set_id, + voters.voters().iter().map(|(v, _)| v.clone()).collect(), |to, neighbor| self.service.send_message(to, GossipMessage::::from(neighbor).encode()), ); @@ -596,7 +665,7 @@ fn check_compact_commit( let f = voters.total_weight() - voters.threshold(); let full_threshold = voters.total_weight() + f; - // check total weight is not too high. + // check total weight is not out of range. let mut total_weight = 0; for (_, ref id) in &msg.auth_data { if let Some(weight) = voters.info(id).map(|info| info.weight()) { diff --git a/core/finality-grandpa/src/communication/tests.rs b/core/finality-grandpa/src/communication/tests.rs index 2ef6d280646a4214f8564cff99806ce6c50f1db0..f2b50ab80c2b6288db97a6416da27612b67f9a74 100644 --- a/core/finality-grandpa/src/communication/tests.rs +++ b/core/finality-grandpa/src/communication/tests.rs @@ -72,6 +72,15 @@ impl super::Network for TestNetwork { let _ = self.sender.unbounded_send(Event::SendMessage(who, data)); } + /// Register a message with the gossip service, it isn't broadcast right + /// away to any peers, but may be sent to new peers joining or when asked to + /// broadcast the topic. Useful to register previous messages on node + /// startup. + fn register_gossip_message(&self, _topic: Hash, _data: Vec) { + // NOTE: only required to restore previous state on startup + // not required for tests currently + } + /// Report a peer's cost or benefit after some action. fn report(&self, who: network::PeerId, cost_benefit: i32) { let _ = self.sender.unbounded_send(Event::Report(who, cost_benefit)); @@ -136,6 +145,7 @@ fn make_test_network() -> impl Future { let (bridge, startup_work) = super::NetworkBridge::new( net.clone(), config(), + None, Exit, ); diff --git a/core/finality-grandpa/src/environment.rs b/core/finality-grandpa/src/environment.rs index cec64b254ccfe1adcd2786ad19bb5a1783b0388c..690c1011a7f4dddebba7e0a65373176dd03f0328 100644 --- a/core/finality-grandpa/src/environment.rs +++ b/core/finality-grandpa/src/environment.rs @@ -34,7 +34,7 @@ use grandpa::{ }; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{ - As, Block as BlockT, Header as HeaderT, NumberFor, One, Zero, BlockNumberToHash, + Block as BlockT, Header as HeaderT, NumberFor, One, Zero, BlockNumberToHash, }; use substrate_primitives::{Blake2Hasher, ed25519, H256, Pair}; use substrate_telemetry::{telemetry, CONSENSUS_INFO}; @@ -46,7 +46,7 @@ use crate::{ use consensus_common::SelectChain; -use crate::authorities::SharedAuthoritySet; +use crate::authorities::{AuthoritySet, SharedAuthoritySet}; use crate::consensus_changes::SharedConsensusChanges; use crate::justification::GrandpaJustification; use crate::until_imported::UntilVoteTargetImported; @@ -66,11 +66,13 @@ pub struct CompletedRound { pub votes: Vec>, } -// Data about last completed rounds. Stores NUM_LAST_COMPLETED_ROUNDS and always +// Data about last completed rounds within a single voter set. Stores NUM_LAST_COMPLETED_ROUNDS and always // contains data about at least one round (genesis). #[derive(Debug, Clone, PartialEq)] pub struct CompletedRounds { - inner: VecDeque>, + rounds: VecDeque>, + set_id: u64, + voters: Vec, } // NOTE: the current strategy for persisting completed rounds is very naive @@ -80,30 +82,51 @@ const NUM_LAST_COMPLETED_ROUNDS: usize = 2; impl Encode for CompletedRounds { fn encode(&self) -> Vec { - Vec::from_iter(&self.inner).encode() + let v = Vec::from_iter(&self.rounds); + (&v, &self.set_id, &self.voters).encode() } } impl Decode for CompletedRounds { fn decode(value: &mut I) -> Option { - Vec::>::decode(value) - .map(|completed_rounds| CompletedRounds { - inner: completed_rounds.into(), + <(Vec>, u64, Vec)>::decode(value) + .map(|(rounds, set_id, voters)| CompletedRounds { + rounds: rounds.into(), + set_id, + voters, }) } } impl CompletedRounds { /// Create a new completed rounds tracker with NUM_LAST_COMPLETED_ROUNDS capacity. - pub fn new(genesis: CompletedRound) -> CompletedRounds { - let mut inner = VecDeque::with_capacity(NUM_LAST_COMPLETED_ROUNDS); - inner.push_back(genesis); - CompletedRounds { inner } + pub(crate) fn new( + genesis: CompletedRound, + set_id: u64, + voters: &AuthoritySet>, + ) + -> CompletedRounds + { + let mut rounds = VecDeque::with_capacity(NUM_LAST_COMPLETED_ROUNDS); + rounds.push_back(genesis); + + let voters = voters.current().1.iter().map(|(a, _)| a.clone()).collect(); + CompletedRounds { rounds, set_id, voters } + } + + /// Get the set-id and voter set of the completed rounds. + pub fn set_info(&self) -> (u64, &[AuthorityId]) { + (self.set_id, &self.voters[..]) + } + + /// Iterate over all completed rounds. + pub fn iter(&self) -> impl Iterator> { + self.rounds.iter() } /// Returns the last (latest) completed round. pub fn last(&self) -> &CompletedRound { - self.inner.back() + self.rounds.back() .expect("inner is never empty; always contains at least genesis; qed") } @@ -114,11 +137,11 @@ impl CompletedRounds { return false; } - if self.inner.len() == NUM_LAST_COMPLETED_ROUNDS { - self.inner.pop_front(); + if self.rounds.len() == NUM_LAST_COMPLETED_ROUNDS { + self.rounds.pop_front(); } - self.inner.push_back(completed_round); + self.rounds.push_back(completed_round); true } @@ -395,6 +418,7 @@ pub(crate) fn ancestry, E, RA>( if base == block { return Err(GrandpaError::NotDescendent) } let tree_route_res = ::client::blockchain::tree_route( + #[allow(deprecated)] client.backend().blockchain(), BlockId::Hash(block), BlockId::Hash(base), @@ -517,6 +541,7 @@ where current_round: HasVoted::Yes(local_id, Vote::Propose(propose)), }; + #[allow(deprecated)] crate::aux_schema::write_voter_set_state(&**self.inner.backend(), &set_state)?; Ok(Some(set_state)) @@ -558,6 +583,7 @@ where current_round: HasVoted::Yes(local_id, Vote::Prevote(propose.cloned(), prevote)), }; + #[allow(deprecated)] crate::aux_schema::write_voter_set_state(&**self.inner.backend(), &set_state)?; Ok(Some(set_state)) @@ -597,6 +623,7 @@ where current_round: HasVoted::Yes(local_id, Vote::Precommit(propose.clone(), prevote.clone(), precommit)), }; + #[allow(deprecated)] crate::aux_schema::write_voter_set_state(&**self.inner.backend(), &set_state)?; Ok(Some(set_state)) @@ -640,6 +667,7 @@ where current_round: HasVoted::No, }; + #[allow(deprecated)] crate::aux_schema::write_voter_set_state(&**self.inner.backend(), &set_state)?; Ok(Some(set_state)) @@ -651,8 +679,10 @@ where fn finalize_block(&self, hash: Block::Hash, number: NumberFor, round: u64, commit: Commit) -> Result<(), Self::Error> { use client::blockchain::HeaderBackend; - let status = self.inner.backend().blockchain().info()?; - if number <= status.finalized_number && self.inner.backend().blockchain().hash(number)? == Some(hash) { + #[allow(deprecated)] + let blockchain = self.inner.backend().blockchain(); + let status = blockchain.info(); + if number <= status.finalized_number && blockchain.hash(number)? == Some(hash) { // This can happen after a forced change (triggered by the finality tracker when finality is stalled), since // the voter will be restarted at the median last finalized block, which can be lower than the local best // finalized block. @@ -669,7 +699,7 @@ where &*self.inner, &self.authority_set, &self.consensus_changes, - Some(As::sa(self.config.justification_period)), + Some(self.config.justification_period.into()), hash, number, (round, commit).into(), @@ -801,7 +831,7 @@ pub(crate) fn finalize_block, E, RA>( // finalization to remote nodes if !justification_required { if let Some(justification_period) = justification_period { - let last_finalized_number = client.info()?.chain.finalized_number; + let last_finalized_number = client.info().chain.finalized_number; justification_required = (!last_finalized_number.is_zero() || number - last_finalized_number == justification_period) && (last_finalized_number / justification_period != number / justification_period); @@ -970,6 +1000,7 @@ where B: Backend, } let tree_route = client::blockchain::tree_route( + #[allow(deprecated)] client.backend().blockchain(), BlockId::Hash(*hash), BlockId::Hash(*base), diff --git a/core/finality-grandpa/src/finality_proof.rs b/core/finality-grandpa/src/finality_proof.rs index 4cffe0dd981c13ed8ea6aab82a638cf8aaad9066..875a60e8e095fa2080f2701677cee280033ebbd5 100644 --- a/core/finality-grandpa/src/finality_proof.rs +++ b/core/finality-grandpa/src/finality_proof.rs @@ -103,7 +103,7 @@ pub trait AuthoritySetForFinalityChecker: Send + Sync { } /// FetchChecker-based implementation of AuthoritySetForFinalityChecker. -impl AuthoritySetForFinalityChecker for Arc> { +impl AuthoritySetForFinalityChecker for Arc> { fn check_authorities_proof( &self, hash: Block::Hash, @@ -117,7 +117,7 @@ impl AuthoritySetForFinalityChecker for Arc = Decode::decode(&mut &authorities[..]) @@ -132,7 +132,7 @@ impl AuthoritySetForFinalityChecker for Arc, RA> { client: Arc>, - authority_provider: Arc>, + authority_provider: Arc>, } impl, RA> FinalityProofProvider @@ -147,7 +147,7 @@ impl, RA> FinalityProofProvider /// - authority_provider for calling and proving runtime methods. pub fn new( client: Arc>, - authority_provider: Arc>, + authority_provider: Arc>, ) -> Self { FinalityProofProvider { client, authority_provider } } @@ -173,6 +173,7 @@ impl network::FinalityProofProvider for FinalityProofPro })?; match request { FinalityProofRequest::Original(request) => prove_finality::<_, _, GrandpaJustification>( + #[allow(deprecated)] &*self.client.backend().blockchain(), &*self.authority_provider, request.authorities_set_id, @@ -255,7 +256,7 @@ pub(crate) fn make_finality_proof_request(last_finalized: H, /// Returns None if there are no finalized blocks unknown to the caller. pub(crate) fn prove_finality, B: BlockchainBackend, J>( blockchain: &B, - authorities_provider: &AuthoritySetForFinalityProver, + authorities_provider: &dyn AuthoritySetForFinalityProver, authorities_set_id: u64, begin: Block::Hash, end: Block::Hash, @@ -267,7 +268,7 @@ pub(crate) fn prove_finality, B: BlockchainBackend, B>( blockchain: &B, current_set_id: u64, current_authorities: Vec<(AuthorityId, u64)>, - authorities_provider: &AuthoritySetForFinalityChecker, + authorities_provider: &dyn AuthoritySetForFinalityChecker, remote_proof: Vec, ) -> ClientResult> where @@ -434,7 +435,7 @@ fn do_check_finality_proof, B, J>( blockchain: &B, current_set_id: u64, current_authorities: Vec<(AuthorityId, u64)>, - authorities_provider: &AuthoritySetForFinalityChecker, + authorities_provider: &dyn AuthoritySetForFinalityChecker, remote_proof: Vec, ) -> ClientResult> where @@ -488,7 +489,7 @@ fn do_check_finality_proof, B, J>( fn check_finality_proof_fragment, B, J>( blockchain: &B, authority_set: AuthoritiesOrEffects, - authorities_provider: &AuthoritySetForFinalityChecker, + authorities_provider: &dyn AuthoritySetForFinalityChecker, proof_fragment: FinalityProofFragment, ) -> ClientResult> where diff --git a/core/finality-grandpa/src/import.rs b/core/finality-grandpa/src/import.rs index cd5ca02a5b36725d237570da40743e6a4cb5f94e..ed57c68250f013d6ec761a50af9c76efc79f4281 100644 --- a/core/finality-grandpa/src/import.rs +++ b/core/finality-grandpa/src/import.rs @@ -26,7 +26,7 @@ use client::blockchain::HeaderBackend; use client::backend::Backend; use client::runtime_api::ApiExt; use consensus_common::{ - BlockImport, Error as ConsensusError, ErrorKind as ConsensusErrorKind, + BlockImport, Error as ConsensusError, ImportBlock, ImportResult, JustificationImport, well_known_cache_keys, SelectChain, }; @@ -76,11 +76,8 @@ impl, RA, PRA, SC> JustificationImport { type Error = ConsensusError; - fn on_start(&self, link: &::consensus_common::import_queue::Link) { - let chain_info = match self.inner.info() { - Ok(info) => info.chain, - _ => return, - }; + fn on_start(&self, link: &dyn consensus_common::import_queue::Link) { + let chain_info = self.inner.info().chain; // request justifications for all pending changes for which change blocks have already been imported let authorities = self.authority_set.inner().read(); @@ -186,12 +183,12 @@ where ); match maybe_change { - Err(e) => match api.has_api_with::, _>(&at, |v| v >= 2) { - Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), + Err(e) => match api.has_api_with::, _>(&at, |v| v >= 2) { + Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()), Ok(true) => { // API version is high enough to support forced changes // but got error, so it is legitimate. - return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()) + return Err(ConsensusError::ClientImport(e.to_string()).into()) }, Ok(false) => { // API version isn't high enough to support forced changes @@ -216,7 +213,7 @@ where ); match maybe_change { - Err(e) => Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), + Err(e) => Err(ConsensusError::ClientImport(e.to_string()).into()), Ok(Some(change)) => Ok(Some(PendingChange { next_authorities: change.next_authorities, delay: change.delay, @@ -301,12 +298,12 @@ where guard.as_mut().add_pending_change( change, &is_descendent_of, - ).map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))?; + ).map_err(|e| ConsensusError::from(ConsensusError::ClientImport(e.to_string())))?; } let applied_changes = { let forced_change_set = guard.as_mut().apply_forced_changes(hash, number, &is_descendent_of) - .map_err(|e| ConsensusErrorKind::ClientImport(e.to_string())) + .map_err(|e| ConsensusError::ClientImport(e.to_string())) .map_err(ConsensusError::from)?; if let Some((median_last_finalized_number, new_set)) = forced_change_set { @@ -317,15 +314,17 @@ where // for the canon block the new authority set should start // with. we use the minimum between the median and the local // best finalized block. + + #[allow(deprecated)] let best_finalized_number = self.inner.backend().blockchain().info() - .map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()))? .finalized_number; let canon_number = best_finalized_number.min(median_last_finalized_number); + #[allow(deprecated)] let canon_hash = self.inner.backend().blockchain().header(BlockId::Number(canon_number)) - .map_err(|e| ConsensusErrorKind::ClientImport(e.to_string()))? + .map_err(|e| ConsensusError::ClientImport(e.to_string()))? .expect("the given block number is less or equal than the current best finalized number; \ current best finalized number must exist in chain; qed.") .hash(); @@ -343,7 +342,7 @@ where AppliedChanges::Forced(new_authorities) } else { let did_standard = guard.as_mut().enacts_standard_change(hash, number, &is_descendent_of) - .map_err(|e| ConsensusErrorKind::ClientImport(e.to_string())) + .map_err(|e| ConsensusError::ClientImport(e.to_string())) .map_err(ConsensusError::from)?; if let Some(root) = did_standard { @@ -396,10 +395,11 @@ impl, RA, PRA, SC> BlockImport // early exit if block already in chain, otherwise the check for // authority changes will error when trying to re-import a change block + #[allow(deprecated)] match self.inner.backend().blockchain().status(BlockId::Hash(hash)) { Ok(blockchain::BlockStatus::InChain) => return Ok(ImportResult::AlreadyInChain), Ok(blockchain::BlockStatus::Unknown) => {}, - Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), + Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()), } let pending_changes = self.make_authorities_changes(&mut block, hash)?; @@ -420,7 +420,7 @@ impl, RA, PRA, SC> BlockImport Err(e) => { debug!(target: "afg", "Restoring old authority set after block import error: {:?}", e); pending_changes.revert(); - return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()); + return Err(ConsensusError::ClientImport(e.to_string()).into()); }, } }; @@ -509,7 +509,7 @@ impl, RA, PRA, SC> BlockImport } } -impl, RA, PRA, SC> +impl, RA, PRA, SC> GrandpaBlockImport { pub(crate) fn new( @@ -559,7 +559,7 @@ where ); let justification = match justification { - Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), + Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()), Ok(justification) => justification, }; @@ -579,17 +579,17 @@ where command {}, signaling voter.", number, command); if let Err(e) = self.send_voter_commands.unbounded_send(command) { - return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()); + return Err(ConsensusError::ClientImport(e.to_string()).into()); } }, Err(CommandOrError::Error(e)) => { return Err(match e { - Error::Grandpa(error) => ConsensusErrorKind::ClientImport(error.to_string()), - Error::Network(error) => ConsensusErrorKind::ClientImport(error), - Error::Blockchain(error) => ConsensusErrorKind::ClientImport(error), - Error::Client(error) => ConsensusErrorKind::ClientImport(error.to_string()), - Error::Safety(error) => ConsensusErrorKind::ClientImport(error), - Error::Timer(error) => ConsensusErrorKind::ClientImport(error.to_string()), + Error::Grandpa(error) => ConsensusError::ClientImport(error.to_string()), + Error::Network(error) => ConsensusError::ClientImport(error), + Error::Blockchain(error) => ConsensusError::ClientImport(error), + Error::Client(error) => ConsensusError::ClientImport(error.to_string()), + Error::Safety(error) => ConsensusError::ClientImport(error), + Error::Timer(error) => ConsensusError::ClientImport(error.to_string()), }.into()); }, Ok(_) => { diff --git a/core/finality-grandpa/src/justification.rs b/core/finality-grandpa/src/justification.rs index f16824f9246805bce45edbd124a0b0d7a8295adf..fc7f833c750538947133ceb090bda002005e4574 100644 --- a/core/finality-grandpa/src/justification.rs +++ b/core/finality-grandpa/src/justification.rs @@ -72,6 +72,7 @@ impl> GrandpaJustification { loop { if current_hash == commit.target_hash { break; } + #[allow(deprecated)] match client.backend().blockchain().header(BlockId::Hash(current_hash))? { Some(current_header) => { if *current_header.number() <= commit.target_number { diff --git a/core/finality-grandpa/src/lib.rs b/core/finality-grandpa/src/lib.rs index 9d808bf4d512091627258ac1fb66e4e6865ca27a..7e3f19940bfcf2bcd5c62623ea49b8b3e0595bfb 100644 --- a/core/finality-grandpa/src/lib.rs +++ b/core/finality-grandpa/src/lib.rs @@ -52,7 +52,6 @@ //! or prune any signaled changes based on whether the signaling block is //! included in the newly-finalized chain. #![forbid(warnings)] -#![allow(deprecated)] // FIXME #2532: remove once the refactor is done https://github.com/paritytech/substrate/issues/2532 use futures::prelude::*; use log::{debug, info, warn}; @@ -157,7 +156,7 @@ pub struct Config { /// Justification generation period (in blocks). GRANDPA will try to generate justifications /// at least every justification_period blocks. There are some other events which might cause /// justification generation. - pub justification_period: u64, + pub justification_period: u32, /// The local signing key. pub local_key: Option>, /// Some local identifier of the voter. @@ -317,10 +316,11 @@ where { use runtime_primitives::traits::Zero; - let chain_info = client.info()?; + let chain_info = client.info(); let genesis_hash = chain_info.chain.genesis_hash; let persistent_data = aux_schema::load_persistent( + #[allow(deprecated)] &**client.backend(), genesis_hash, >::zero(), @@ -430,18 +430,17 @@ fn register_finality_tracker_inherent_data_provider Err(std::borrow::Cow::Owned(e.to_string())), - Ok(info) => { - telemetry!(CONSENSUS_INFO; "afg.finalized"; - "finalized_number" => ?info.finalized_number, - "finalized_hash" => ?info.finalized_hash, - ); - Ok(info.finalized_number) - }, + #[allow(deprecated)] + { + let info = client.backend().blockchain().info(); + telemetry!(CONSENSUS_INFO; "afg.finalized"; + "finalized_number" => ?info.finalized_number, + "finalized_hash" => ?info.finalized_hash, + ); + Ok(info.finalized_number) } })) - .map_err(|err| consensus_common::ErrorKind::InherentData(err.into()).into()) + .map_err(|err| consensus_common::Error::InherentData(err.into())) } else { Ok(()) } @@ -490,16 +489,22 @@ pub fn run_grandpa_voter, N, RA, SC, X>( use futures::future::{self, Loop as FutureLoop}; - let (network, network_startup) = NetworkBridge::new(network, config.clone(), on_exit.clone()); - let LinkHalf { client, select_chain, persistent_data, voter_commands_rx, } = link; + let PersistentData { authority_set, set_state, consensus_changes } = persistent_data; + let (network, network_startup) = NetworkBridge::new( + network, + config.clone(), + Some(&set_state.read()), + on_exit.clone(), + ); + register_finality_tracker_inherent_data_provider(client.clone(), &inherent_data_providers)?; if let Some(telemetry_on_connect) = telemetry_on_connect { @@ -572,10 +577,7 @@ pub fn run_grandpa_voter, N, RA, SC, X>( let mut maybe_voter = match &*env.voter_set_state.read() { VoterSetState::Live { completed_rounds, .. } => { - let chain_info = match client.info() { - Ok(i) => i, - Err(e) => return future::Either::B(future::err(Error::Client(e))), - }; + let chain_info = client.info(); let last_finalized = ( chain_info.chain.finalized_hash, @@ -638,15 +640,20 @@ pub fn run_grandpa_voter, N, RA, SC, X>( let set_state = VoterSetState::Live { // always start at round 0 when changing sets. - completed_rounds: CompletedRounds::new(CompletedRound { - number: 0, - state: genesis_state, - base: (new.canon_hash, new.canon_number), - votes: Vec::new(), - }), + completed_rounds: CompletedRounds::new( + CompletedRound { + number: 0, + state: genesis_state, + base: (new.canon_hash, new.canon_number), + votes: Vec::new(), + }, + new.set_id, + &*authority_set.inner().read(), + ), current_round: HasVoted::No, }; + #[allow(deprecated)] aux_schema::write_voter_set_state(&**client.backend(), &set_state)?; let set_state: SharedVoterSetState<_> = set_state.into(); @@ -672,6 +679,8 @@ pub fn run_grandpa_voter, N, RA, SC, X>( env.update_voter_set_state(|voter_set_state| { let completed_rounds = voter_set_state.completed_rounds(); let set_state = VoterSetState::Paused { completed_rounds }; + + #[allow(deprecated)] aux_schema::write_voter_set_state(&**client.backend(), &set_state)?; Ok(Some(set_state)) })?; @@ -681,7 +690,7 @@ pub fn run_grandpa_voter, N, RA, SC, X>( } }; - future::Either::A(poll_voter.select2(voter_commands_rx).then(move |res| match res { + poll_voter.select2(voter_commands_rx).then(move |res| match res { Ok(future::Either::A(((), _))) => { // voters don't conclude naturally; this could reasonably be an error. Ok(FutureLoop::Break(())) @@ -706,7 +715,7 @@ pub fn run_grandpa_voter, N, RA, SC, X>( // some command issued internally. handle_voter_command(command, voter_commands_rx) }, - })) + }) }); let voter_work = voter_work diff --git a/core/finality-grandpa/src/light_import.rs b/core/finality-grandpa/src/light_import.rs index f73b41f0ae02ea67d6ae54b703b175414cf00d0a..c70f91d0f3f45c51d5d714a578f9bb71154a51e2 100644 --- a/core/finality-grandpa/src/light_import.rs +++ b/core/finality-grandpa/src/light_import.rs @@ -29,7 +29,7 @@ use parity_codec::{Encode, Decode}; use consensus_common::{ import_queue::{Verifier, SharedFinalityProofRequestBuilder}, well_known_cache_keys, BlockOrigin, BlockImport, FinalityProofImport, ImportBlock, ImportResult, ImportedAux, - Error as ConsensusError, ErrorKind as ConsensusErrorKind, FinalityProofRequestBuilder, + Error as ConsensusError, FinalityProofRequestBuilder, }; use runtime_primitives::Justification; use runtime_primitives::traits::{ @@ -53,7 +53,7 @@ const LIGHT_CONSENSUS_CHANGES_KEY: &[u8] = b"grandpa_consensus_changes"; /// Create light block importer. pub fn light_block_import, RA, PRA>( client: Arc>, - authority_set_provider: Arc>, + authority_set_provider: Arc>, api: Arc, ) -> Result, ClientError> where @@ -63,7 +63,8 @@ pub fn light_block_import, RA, PRA>( PRA: ProvideRuntimeApi, PRA::Api: GrandpaApi, { - let info = client.info()?; + let info = client.info(); + #[allow(deprecated)] let import_data = load_aux_import_data(info.chain.finalized_hash, &**client.backend(), api)?; Ok(GrandpaLightBlockImport { client, @@ -79,7 +80,7 @@ pub fn light_block_import, RA, PRA>( /// - fetching finality proofs for blocks that are enacting consensus changes. pub struct GrandpaLightBlockImport, RA> { client: Arc>, - authority_set_provider: Arc>, + authority_set_provider: Arc>, data: Arc>>, } @@ -119,7 +120,9 @@ impl, RA> BlockImport block: ImportBlock, new_cache: HashMap>, ) -> Result { - do_import_block::<_, _, _, _, GrandpaJustification>(&*self.client, &mut *self.data.write(), block, new_cache) + do_import_block::<_, _, _, _, GrandpaJustification>( + &*self.client, &mut *self.data.write(), block, new_cache + ) } fn check_block( @@ -141,11 +144,8 @@ impl, RA> FinalityProofImport { type Error = ConsensusError; - fn on_start(&self, link: &::consensus_common::import_queue::Link) { - let chain_info = match self.client.info() { - Ok(info) => info.chain, - _ => return, - }; + fn on_start(&self, link: &dyn consensus_common::import_queue::Link) { + let chain_info = self.client.info().chain; let data = self.data.read(); for (pending_number, pending_hash) in data.consensus_changes.pending_changes() { @@ -160,7 +160,7 @@ impl, RA> FinalityProofImport hash: Block::Hash, number: NumberFor, finality_proof: Vec, - verifier: &Verifier, + verifier: &dyn Verifier, ) -> Result<(Block::Hash, NumberFor), Self::Error> { do_import_finality_proof::<_, _, _, _, GrandpaJustification>( &*self.client, @@ -238,7 +238,7 @@ fn do_import_block, RA, J>( let mut imported_aux = match import_result { Ok(ImportResult::Imported(aux)) => aux, Ok(r) => return Ok(r), - Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), + Err(e) => return Err(ConsensusError::ClientImport(e.to_string()).into()), }; match justification { @@ -271,12 +271,12 @@ fn do_import_block, RA, J>( /// Try to import finality proof. fn do_import_finality_proof, RA, J>( client: &Client, - authority_set_provider: &AuthoritySetForFinalityChecker, + authority_set_provider: &dyn AuthoritySetForFinalityChecker, data: &mut LightImportData, _hash: Block::Hash, _number: NumberFor, finality_proof: Vec, - verifier: &Verifier, + verifier: &dyn Verifier, ) -> Result<(Block::Hash, NumberFor), ConsensusError> where B: Backend + 'static, @@ -289,17 +289,19 @@ fn do_import_finality_proof, RA, J>( let authority_set_id = data.authority_set.set_id(); let authorities = data.authority_set.authorities(); let finality_effects = crate::finality_proof::check_finality_proof( + #[allow(deprecated)] &*client.backend().blockchain(), authority_set_id, authorities, authority_set_provider, finality_proof, - ).map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))?; + ).map_err(|e| ConsensusError::ClientImport(e.to_string()))?; // try to import all new headers let block_origin = BlockOrigin::NetworkBroadcast; for header_to_import in finality_effects.headers_to_import { - let (block_to_import, new_authorities) = verifier.verify(block_origin, header_to_import, None, None)?; + let (block_to_import, new_authorities) = verifier.verify(block_origin, header_to_import, None, None) + .map_err(|e| ConsensusError::ClientImport(e))?; assert!(block_to_import.justification.is_none(), "We have passed None as justification to verifier.verify"); let mut cache = HashMap::new(); @@ -311,9 +313,10 @@ fn do_import_finality_proof, RA, J>( // try to import latest justification let finalized_block_hash = finality_effects.block; + #[allow(deprecated)] let finalized_block_number = client.backend().blockchain() .expect_block_number_from_id(&BlockId::Hash(finality_effects.block)) - .map_err(|e| ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())))?; + .map_err(|e| ConsensusError::ClientImport(e.to_string()))?; do_finalize_block( client, data, @@ -383,7 +386,7 @@ fn do_import_justification, RA, J>( hash, ); - return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()); + return Err(ConsensusError::ClientImport(e.to_string()).into()); }, Ok(justification) => { trace!( @@ -417,7 +420,7 @@ fn do_finalize_block, RA>( // finalize the block client.finalize_block(BlockId::Hash(hash), Some(justification), true).map_err(|e| { warn!(target: "finality", "Error applying finality to block {:?}: {:?}", (hash, number), e); - ConsensusError::from(ConsensusErrorKind::ClientImport(e.to_string())) + ConsensusError::ClientImport(e.to_string()) })?; // forget obsoleted consensus changes @@ -499,6 +502,7 @@ fn require_insert_aux, RA>( B: Backend + 'static, E: CallExecutor + 'static + Clone + Send + Sync, { + #[allow(deprecated)] let backend = &**client.backend(); let encoded = value.encode(); let update_res = Backend::insert_aux(backend, &[(key, &encoded[..])], &[]); @@ -513,7 +517,7 @@ fn require_insert_aux, RA>( fn on_post_finalization_error(error: ClientError, value_type: &str) -> ConsensusError { warn!(target: "finality", "Failed to write updated {} to disk. Bailing.", value_type); warn!(target: "finality", "Node is in a potentially inconsistent state."); - ConsensusError::from(ConsensusErrorKind::ClientImport(error.to_string())) + ConsensusError::ClientImport(error.to_string()) } #[cfg(test)] @@ -568,7 +572,7 @@ pub mod tests { { type Error = ConsensusError; - fn on_start(&self, link: &::consensus_common::import_queue::Link) { + fn on_start(&self, link: &dyn consensus_common::import_queue::Link) { self.0.on_start(link) } @@ -577,7 +581,7 @@ pub mod tests { hash: Block::Hash, number: NumberFor, finality_proof: Vec, - verifier: &Verifier, + verifier: &dyn Verifier, ) -> Result<(Block::Hash, NumberFor), Self::Error> { self.0.import_finality_proof(hash, number, finality_proof, verifier) } @@ -586,7 +590,7 @@ pub mod tests { /// Creates light block import that ignores justifications that came outside of finality proofs. pub fn light_block_import_without_justifications, RA, PRA>( client: Arc>, - authority_set_provider: Arc>, + authority_set_provider: Arc>, api: Arc, ) -> Result, ClientError> where @@ -613,7 +617,7 @@ pub mod tests { origin: BlockOrigin::Own, header: Header { number: 1, - parent_hash: client.info().unwrap().chain.best_hash, + parent_hash: client.info().chain.best_hash, state_root: Default::default(), digest: Default::default(), extrinsics_root: Default::default(), diff --git a/core/finality-grandpa/src/observer.rs b/core/finality-grandpa/src/observer.rs index f6d657e1ff1f8676234c474814c250eadc564bd0..9ed1cc8c625213fe51447047510e97b264dfa113 100644 --- a/core/finality-grandpa/src/observer.rs +++ b/core/finality-grandpa/src/observer.rs @@ -31,7 +31,7 @@ use substrate_primitives::{ed25519::Public as AuthorityId, H256, Blake2Hasher}; use crate::{ AuthoritySignature, global_communication, CommandOrError, Config, environment, - Error, LinkHalf, Network, aux_schema::PersistentData, VoterCommand, VoterSetState, + LinkHalf, Network, aux_schema::PersistentData, VoterCommand, VoterSetState, }; use crate::authorities::SharedAuthoritySet; use crate::communication::NetworkBridge; @@ -166,9 +166,15 @@ pub fn run_grandpa_observer, N, RA, SC>( } = link; let PersistentData { authority_set, consensus_changes, set_state } = persistent_data; - let initial_state = (authority_set, consensus_changes, set_state, voter_commands_rx.into_future()); - let (network, network_startup) = NetworkBridge::new(network, config.clone(), on_exit.clone()); + let (network, network_startup) = NetworkBridge::new( + network, + config.clone(), + None, + on_exit.clone(), + ); + + let initial_state = (authority_set, consensus_changes, set_state, voter_commands_rx.into_future()); let observer_work = future::loop_fn(initial_state, move |state| { let (authority_set, consensus_changes, set_state, voter_commands_rx) = state; @@ -185,12 +191,7 @@ pub fn run_grandpa_observer, N, RA, SC>( &network, ); - let chain_info = match client.info() { - Ok(i) => i, - Err(e) => return future::Either::B(future::err(Error::Client(e))), - }; - - let last_finalized_number = chain_info.chain.finalized_number; + let last_finalized_number = client.info().chain.finalized_number; // create observer for the current set let observer = grandpa_observer( @@ -212,6 +213,7 @@ pub fn run_grandpa_observer, N, RA, SC>( let completed_rounds = set_state.read().completed_rounds(); let set_state = VoterSetState::Paused { completed_rounds }; + #[allow(deprecated)] crate::aux_schema::write_voter_set_state(&**client.backend(), &set_state)?; set_state @@ -223,15 +225,20 @@ pub fn run_grandpa_observer, N, RA, SC>( let set_state = VoterSetState::Live:: { // always start at round 0 when changing sets. - completed_rounds: CompletedRounds::new(CompletedRound { - number: 0, - state: genesis_state, - base: (new.canon_hash, new.canon_number), - votes: Vec::new(), - }), + completed_rounds: CompletedRounds::new( + CompletedRound { + number: 0, + state: genesis_state, + base: (new.canon_hash, new.canon_number), + votes: Vec::new(), + }, + new.set_id, + &*authority_set.inner().read(), + ), current_round: HasVoted::No, }; + #[allow(deprecated)] crate::aux_schema::write_voter_set_state(&**client.backend(), &set_state)?; set_state @@ -242,7 +249,7 @@ pub fn run_grandpa_observer, N, RA, SC>( }; // run observer and listen to commands (switch authorities or pause) - future::Either::A(observer.select2(voter_commands_rx).then(move |res| match res { + observer.select2(voter_commands_rx).then(move |res| match res { Ok(future::Either::A((_, _))) => { // observer commit stream doesn't conclude naturally; this could reasonably be an error. Ok(FutureLoop::Break(())) @@ -267,7 +274,7 @@ pub fn run_grandpa_observer, N, RA, SC>( // some command issued internally handle_voter_command(command, voter_commands_rx) }, - })) + }) }); let observer_work = observer_work diff --git a/core/finality-grandpa/src/tests.rs b/core/finality-grandpa/src/tests.rs index 98e4b6d85c08e73ab40c3e3ab3f208982a379974..18342e3a1e3ba9483dda000d0239973d04e1b4f0 100644 --- a/core/finality-grandpa/src/tests.rs +++ b/core/finality-grandpa/src/tests.rs @@ -119,9 +119,9 @@ impl TestNetFactory for GrandpaTestNet { { match client { PeersClient::Full(ref client) => { + #[allow(deprecated)] let select_chain = LongestChain::new( - client.backend().clone(), - client.import_lock().clone() + client.backend().clone() ); let (import, link) = block_import( client.clone(), @@ -149,7 +149,10 @@ impl TestNetFactory for GrandpaTestNet { } } - fn make_finality_proof_provider(&self, client: PeersClient) -> Option>> { + fn make_finality_proof_provider( + &self, + client: PeersClient + ) -> Option>> { match client { PeersClient::Full(ref client) => { let authorities_provider = Arc::new(self.test_config.clone()); @@ -159,6 +162,10 @@ impl TestNetFactory for GrandpaTestNet { } } + fn uses_tokio(&self) -> bool { + true + } + fn peer(&self, i: usize) -> &GrandpaPeer { &self.peers[i] } @@ -196,7 +203,7 @@ impl MessageRouting { } impl Network for MessageRouting { - type In = Box + Send>; + type In = Box + Send>; /// Get a stream of messages for a specific gossip topic. fn messages_for(&self, topic: Hash) -> Self::In { @@ -249,6 +256,11 @@ impl Network for MessageRouting { }) } + fn register_gossip_message(&self, _topic: Hash, _data: Vec) { + // NOTE: only required to restore previous state on startup + // not required for tests currently + } + fn report(&self, _who: network::PeerId, _cost_benefit: i32) { } @@ -329,15 +341,6 @@ impl Core for RuntimeApi { ) -> Result> { unimplemented!("Not required for testing!") } - fn Core_authorities_runtime_api_impl( - &self, - _: &BlockId, - _: ExecutionContext, - _: Option<()>, - _: Vec, - ) -> Result>> { - unimplemented!("Not required for testing!") - } } impl ApiExt for RuntimeApi { @@ -453,7 +456,7 @@ fn run_to_completion_with( peers: &[AuthorityKeyring], with: F, ) -> u64 where - F: FnOnce(current_thread::Handle) -> Option>> + F: FnOnce(current_thread::Handle) -> Option>> { use parking_lot::RwLock; @@ -551,7 +554,7 @@ fn finalize_3_voters_no_observers() { net.sync(); for i in 0..3 { - assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 20, + assert_eq!(net.peer(i).client().info().chain.best_number, 20, "Peer #{} failed to sync", i); } @@ -663,10 +666,11 @@ fn transition_3_voters_twice_1_full_observer() { for (i, peer) in net.lock().peers().iter().enumerate() { let full_client = peer.client().as_full().expect("only full clients are used in test"); - assert_eq!(full_client.info().unwrap().chain.best_number, 1, + assert_eq!(full_client.info().chain.best_number, 1, "Peer #{} failed to sync", i); let set: AuthoritySet = crate::aux_schema::load_authorities( + #[allow(deprecated)] &**full_client.backend() ).unwrap(); @@ -756,6 +760,7 @@ fn transition_3_voters_twice_1_full_observer() { .map(move |()| { let full_client = client.as_full().expect("only full clients are used in test"); let set: AuthoritySet = crate::aux_schema::load_authorities( + #[allow(deprecated)] &**full_client.backend() ).unwrap(); @@ -883,7 +888,7 @@ fn sync_justifications_on_change_blocks() { net.sync(); for i in 0..4 { - assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 25, + assert_eq!(net.peer(i).client().info().chain.best_number, 25, "Peer #{} failed to sync", i); } @@ -954,7 +959,7 @@ fn finalizes_multiple_pending_changes_in_order() { // all peers imported both change blocks for i in 0..6 { - assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 30, + assert_eq!(net.peer(i).client().info().chain.best_number, 30, "Peer #{} failed to sync", i); } @@ -974,7 +979,7 @@ fn doesnt_vote_on_the_tip_of_the_chain() { net.sync(); for i in 0..3 { - assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 100, + assert_eq!(net.peer(i).client().info().chain.best_number, 100, "Peer #{} failed to sync", i); } @@ -1004,7 +1009,7 @@ fn force_change_to_new_set() { { // add a forced transition at block 12. - let parent_hash = net.lock().peer(0).client().info().unwrap().chain.best_hash; + let parent_hash = net.lock().peer(0).client().info().chain.best_hash; forced_transitions.lock().insert(parent_hash, (0, ScheduledChange { next_authorities: voters.clone(), delay: 10, @@ -1021,11 +1026,12 @@ fn force_change_to_new_set() { net.lock().sync(); for (i, peer) in net.lock().peers().iter().enumerate() { - assert_eq!(peer.client().info().unwrap().chain.best_number, 26, + assert_eq!(peer.client().info().chain.best_number, 26, "Peer #{} failed to sync", i); let full_client = peer.client().as_full().expect("only full clients are used in test"); let set: AuthoritySet = crate::aux_schema::load_authorities( + #[allow(deprecated)] &**full_client.backend() ).unwrap(); @@ -1054,7 +1060,7 @@ fn allows_reimporting_change_blocks() { let (block_import, ..) = net.make_block_import(client.clone()); let full_client = client.as_full().unwrap(); - let builder = full_client.new_block_at(&BlockId::Number(0)).unwrap(); + let builder = full_client.new_block_at(&BlockId::Number(0), Default::default()).unwrap(); let block = builder.bake().unwrap(); api.scheduled_changes.lock().insert(*block.header.parent_hash(), ScheduledChange { next_authorities: make_ids(peers_b), @@ -1103,7 +1109,7 @@ fn test_bad_justification() { let (block_import, ..) = net.make_block_import(client.clone()); let full_client = client.as_full().expect("only full clients are used in test"); - let builder = full_client.new_block_at(&BlockId::Number(0)).unwrap(); + let builder = full_client.new_block_at(&BlockId::Number(0), Default::default()).unwrap(); let block = builder.bake().unwrap(); api.scheduled_changes.lock().insert(*block.header.parent_hash(), ScheduledChange { next_authorities: make_ids(peers_b), @@ -1159,7 +1165,7 @@ fn voter_persists_its_votes() { net.peer(0).push_blocks(20, false); net.sync(); - assert_eq!(net.peer(0).client().info().unwrap().chain.best_number, 20, + assert_eq!(net.peer(0).client().info().chain.best_number, 20, "Peer #{} failed to sync", 0); let mut runtime = current_thread::Runtime::new().unwrap(); @@ -1238,7 +1244,12 @@ fn voter_persists_its_votes() { name: Some(format!("peer#{}", 1)), }; let routing = MessageRouting::new(net.clone(), 1); - let (network, routing_work) = communication::NetworkBridge::new(routing, config.clone(), Exit); + let (network, routing_work) = communication::NetworkBridge::new( + routing, + config.clone(), + None, + Exit, + ); runtime.block_on(routing_work).unwrap(); let (round_rx, round_tx) = network.round_communication( @@ -1271,9 +1282,10 @@ fn voter_persists_its_votes() { net.lock().peer(0).push_blocks(20, false); net.lock().sync(); - assert_eq!(net.lock().peer(0).client().info().unwrap().chain.best_number, 40, + assert_eq!(net.lock().peer(0).client().info().chain.best_number, 40, "Peer #{} failed to sync", 0); + #[allow(deprecated)] let block_30_hash = net.lock().peer(0).client().as_full().unwrap().backend().blockchain().hash(30).unwrap().unwrap(); @@ -1347,7 +1359,7 @@ fn finalize_3_voters_1_light_observer() { net.sync(); for i in 0..4 { - assert_eq!(net.peer(i).client().info().unwrap().chain.best_number, 20, + assert_eq!(net.peer(i).client().info().chain.best_number, 20, "Peer #{} failed to sync", i); } @@ -1393,7 +1405,7 @@ fn finality_proof_is_fetched_by_light_client_when_consensus_data_changes() { net.lock().sync_without_disconnects(); // check that the block#1 is finalized on light client - while net.lock().peer(1).client().info().unwrap().chain.finalized_number != 1 { + while net.lock().peer(1).client().info().chain.finalized_number != 1 { net.lock().tick_peer(1); net.lock().sync_without_disconnects(); } @@ -1436,7 +1448,7 @@ fn empty_finality_proof_is_returned_to_light_client_when_authority_set_is_differ // add a forced transition at block 5. if FORCE_CHANGE { - let parent_hash = net.lock().peer(0).client().info().unwrap().chain.best_hash; + let parent_hash = net.lock().peer(0).client().info().chain.best_hash; forced_transitions.lock().insert(parent_hash, (0, ScheduledChange { next_authorities: voters.clone(), delay: 3, @@ -1461,9 +1473,9 @@ fn empty_finality_proof_is_returned_to_light_client_when_authority_set_is_differ runner_net.lock().add_light_peer(&GrandpaTestNet::default_config()); runner_net.lock().sync_without_disconnects(); - // check block, finalized on light client + // check block, finalized on light client assert_eq!( - runner_net.lock().peer(3).client().info().unwrap().chain.finalized_number, + runner_net.lock().peer(3).client().info().chain.finalized_number, if FORCE_CHANGE { 0 } else { 10 }, ); -} \ No newline at end of file +} diff --git a/core/inherents/Cargo.toml b/core/inherents/Cargo.toml index a71661bd1d2b020ac8c2c944556a80b035b75097..606d9c5ae97ba83ade7a633fd7a0f4bf1e3e08a7 100644 --- a/core/inherents/Cargo.toml +++ b/core/inherents/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -parking_lot = { version = "0.7", optional = true } +parking_lot = { version = "0.8.0", optional = true } rstd = { package = "sr-std", path = "../sr-std", default-features = false } parity-codec = { version = "3.3", default-features = false, features = ["derive"] } runtime_primitives = { package = "sr-primitives", path = "../sr-primitives", default-features = false } diff --git a/core/inherents/src/lib.rs b/core/inherents/src/lib.rs index 87fa39fe06e6cc8aed7eb502fc736d0e8c274aca..7b99c7ba526b24d2ba292a64dec2cb37556ffe48 100644 --- a/core/inherents/src/lib.rs +++ b/core/inherents/src/lib.rs @@ -44,16 +44,13 @@ use parking_lot::RwLock; #[cfg(feature = "std")] use std::{sync::Arc, format}; -#[cfg(feature = "std")] -pub mod pool; - pub use runtime_primitives::RuntimeString; /// An identifier for an inherent. pub type InherentIdentifier = [u8; 8]; /// Inherent data to include in a block. -#[derive(Clone, Default)] +#[derive(Clone, Default, Encode, Decode)] pub struct InherentData { /// All inherent data encoded with parity-codec and an identifier. data: BTreeMap> @@ -69,7 +66,7 @@ impl InherentData { /// /// # Return /// - /// Returns `Ok(())` if the data could be inserted an no data for an inherent with the same + /// Returns `Ok(())` if the data could be inserted and no data for an inherent with the same /// identifier existed, otherwise an error is returned. /// /// Inherent identifiers need to be unique, otherwise decoding of these values will not work! @@ -123,33 +120,6 @@ impl InherentData { } } -impl codec::Encode for InherentData { - fn encode(&self) -> Vec { - let keys = self.data.keys().collect::>(); - let values = self.data.values().collect::>(); - - let mut encoded = keys.encode(); - encoded.extend(values.encode()); - encoded - } -} - -impl codec::Decode for InherentData { - fn decode(value: &mut I) -> Option { - Vec::::decode(value) - .and_then(|i| Vec::>::decode(value).map(|v| (i, v))) - .and_then(|(i, v)| { - if i.len() == v.len() { - Some(Self { - data: i.into_iter().zip(v.into_iter()).collect() - }) - } else { - None - } - }) - } -} - /// The result of checking inherents. /// /// It either returns okay for all checks, stores all occurred errors or just one fatal error. diff --git a/core/inherents/src/pool.rs b/core/inherents/src/pool.rs deleted file mode 100644 index 2c7e953696a55ab9d134615a2371bbc48f902628..0000000000000000000000000000000000000000 --- a/core/inherents/src/pool.rs +++ /dev/null @@ -1,75 +0,0 @@ -// 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 . - -//! Inherents Pool - -use std::{fmt, mem, vec}; -use parking_lot::Mutex; - -/// Inherents Pool -/// -/// The pool is responsible to collect inherents asynchronously generated -/// by some other parts of the code and make them ready for the next block production. -pub struct InherentsPool { - data: Mutex>, -} - -impl Default for InherentsPool { - fn default() -> Self { - InherentsPool { - data: Default::default(), - } - } -} - -impl fmt::Debug for InherentsPool { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - let mut builder = fmt.debug_struct("InherentsPool"); - if let Some(data) = self.data.try_lock() { - builder.field("data", &*data); - } - builder.finish() - } -} - -impl InherentsPool { - /// Add inherent extrinsic to the pool. - /// - /// This inherent will be appended to the next produced block. - pub fn add(&self, extrinsic: T) { - self.data.lock().push(extrinsic); - } - - /// Drain all currently queued inherents. - pub fn drain(&self) -> Vec { - mem::replace(&mut *self.data.lock(), vec![]) - } -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn should_drain_inherents_to_given_data() { - let pool = InherentsPool::default(); - pool.add(5); - pool.add(7); - - assert_eq!(pool.drain(), vec![5, 7]); - assert_eq!(pool.drain(), vec![]); - } -} diff --git a/core/keyring/src/sr25519.rs b/core/keyring/src/sr25519.rs index 0097d7b2f9c5c1493dad59cdd0a7d7220550a193..24a83ab798d26442d788b9bc219b1a493bb59496 100644 --- a/core/keyring/src/sr25519.rs +++ b/core/keyring/src/sr25519.rs @@ -68,7 +68,7 @@ impl Keyring { } pub fn to_raw_public_vec(self) -> Vec { - Public::from(self).to_raw_vec() + Public::from(self).into_raw_vec() } pub fn sign(self, msg: &[u8]) -> Signature { diff --git a/core/keystore/Cargo.toml b/core/keystore/Cargo.toml index 4c4a89157b8e35bb52b26c561bc7cc8bc80ea8db..1d4f146b7ed7fc156590dedd4fb825f84deaca8e 100644 --- a/core/keystore/Cargo.toml +++ b/core/keystore/Cargo.toml @@ -5,9 +5,8 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] +derive_more = "0.14.0" substrate-primitives = { path = "../primitives" } -crypto = { package = "parity-crypto", version = "0.3", default-features = false } -error-chain = "0.12" hex = "0.3" rand = "0.6" serde_json = "1.0" diff --git a/core/keystore/src/lib.rs b/core/keystore/src/lib.rs index ff737535f9a7969d671abd99b5b838c45df555b9..67cf2c8d327cd659fb22c75137ff0fe7a0a5702c 100644 --- a/core/keystore/src/lib.rs +++ b/core/keystore/src/lib.rs @@ -16,40 +16,42 @@ //! Keystore (and session key management) for ed25519 based chains like Polkadot. -// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting` -// https://github.com/paritytech/substrate/issues/1547 -#![allow(deprecated)] +#![warn(missing_docs)] use std::collections::HashMap; use std::path::PathBuf; use std::fs::{self, File}; use std::io::{self, Write}; -use error_chain::{bail, error_chain, error_chain_processing, impl_error_chain_processed, - impl_extract_backtrace, impl_error_chain_kind}; - use substrate_primitives::{ed25519::{Pair, Public}, Pair as PairT}; -pub use crypto::KEY_ITERATIONS; +/// Keystore error. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// IO error. + Io(io::Error), + /// JSON error. + Json(serde_json::Error), + /// Invalid password. + #[display(fmt="Invalid password")] + InvalidPassword, + /// Invalid BIP39 phrase + #[display(fmt="Invalid recovery phrase (BIP39) data")] + InvalidPhrase, + /// Invalid seed + #[display(fmt="Invalid seed")] + InvalidSeed, +} -error_chain! { - foreign_links { - Io(io::Error); - Json(serde_json::Error); - } +/// Keystore Result +pub type Result = std::result::Result; - errors { - InvalidPassword { - description("Invalid password"), - display("Invalid password"), - } - InvalidPhrase { - description("Invalid recovery phrase (BIP39) data"), - display("Invalid recovery phrase (BIP39) data"), - } - InvalidSeed { - description("Invalid seed"), - display("Invalid seed"), +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Io(ref err) => Some(err), + Error::Json(ref err) => Some(err), + _ => None, } } } @@ -79,7 +81,7 @@ impl Store { /// Create a new key from seed. Do not place it into the store. pub fn generate_from_seed(&mut self, seed: &str) -> Result { let pair = Pair::from_string(seed, None) - .map_err(|_| Error::from(ErrorKind::InvalidSeed))?; + .ok().ok_or(Error::InvalidSeed)?; self.additional.insert(pair.public(), pair.clone()); Ok(pair) } @@ -94,9 +96,9 @@ impl Store { let phrase: String = ::serde_json::from_reader(&file)?; let pair = Pair::from_phrase(&phrase, Some(password)) - .map_err(|_| Error::from(ErrorKind::InvalidPhrase))?; + .ok().ok_or(Error::InvalidPhrase)?; if &pair.public() != public { - bail!(ErrorKind::InvalidPassword); + return Err(Error::InvalidPassword); } Ok(pair) } diff --git a/core/network-libp2p/Cargo.toml b/core/network-libp2p/Cargo.toml index 8ee8caa06a38671db8cd6e6908826027192b60aa..16978ed02c466a574da214898be0924c4ed96085 100644 --- a/core/network-libp2p/Cargo.toml +++ b/core/network-libp2p/Cargo.toml @@ -10,11 +10,10 @@ edition = "2018" [dependencies] byteorder = "1.3" bytes = "0.4" -error-chain = { version = "0.12", default-features = false } fnv = "1.0" futures = "0.1" -libp2p = { version = "0.7.0", default-features = false, features = ["secio-secp256k1", "libp2p-websocket"] } -parking_lot = "0.7.1" +libp2p = { version = "0.9.1", default-features = false, features = ["secp256k1", "libp2p-websocket"] } +parking_lot = "0.8.0" lazy_static = "1.2" log = "0.4" rand = "0.6" @@ -26,6 +25,7 @@ tokio-io = "0.1" tokio-timer = "0.2" unsigned-varint = { version = "0.2.1", features = ["codec"] } void = "1.0" +zeroize = "0.6.0" slog = { version = "^2", features = ["nested-values"] } slog_derive = "0.1.1" diff --git a/core/network-libp2p/src/behaviour.rs b/core/network-libp2p/src/behaviour.rs index b0eb1a66eb93a82910c260177b1303b6148bcd93..379983a3fbc8753ced25275c960be7bc355a1c71 100644 --- a/core/network-libp2p/src/behaviour.rs +++ b/core/network-libp2p/src/behaviour.rs @@ -67,7 +67,7 @@ impl Behaviour Behaviour impl Iterator { + pub fn known_peers(&mut self) -> impl Iterator { self.discovery.kademlia.kbuckets_entries() } @@ -165,7 +165,7 @@ impl NetworkBehaviourEventProcess NetworkBehaviourEventProcess () + // We never start any other type of query. + KademliaOut::GetProvidersResult { .. } => {} + KademliaOut::GetValueResult(_) => {} + KademliaOut::PutValueResult(_) => {} } } } @@ -355,7 +357,7 @@ where fn inject_new_external_addr(&mut self, addr: &Multiaddr) { let new_addr = addr.clone() .with(Protocol::P2p(self.local_peer_id.clone().into())); - info!(target: "sub-libp2p", "Discovered external node address: {}", new_addr); + info!(target: "sub-libp2p", "Discovered new external address for our node: {}", new_addr); } fn inject_expired_listen_addr(&mut self, addr: &Multiaddr) { diff --git a/core/network-libp2p/src/config.rs b/core/network-libp2p/src/config.rs index 9d74cd73e234308927d3c25a59436ec230f10b8e..b9ccbb642802d6ed734c397ab8eca356ef765a73 100644 --- a/core/network-libp2p/src/config.rs +++ b/core/network-libp2p/src/config.rs @@ -17,9 +17,11 @@ //! Libp2p network configuration. use libp2p::identity::{Keypair, secp256k1, ed25519}; +use libp2p::wasm_ext; use libp2p::{Multiaddr, multiaddr::Protocol}; use std::error::Error; use std::{io::{self, Write}, iter, fs, net::Ipv4Addr, path::{Path, PathBuf}}; +use zeroize::Zeroize; /// Network service configuration. #[derive(Clone)] @@ -51,6 +53,13 @@ pub struct NetworkConfiguration { /// If true, the network will use mDNS to discover other libp2p nodes on the local network /// and connect to them if they support the same chain. pub enable_mdns: bool, + /// Optional external implementation of a libp2p transport. Used in WASM contexts where we need + /// some binding between the networking provided by the operating system or environment and + /// libp2p. + /// + /// This parameter exists whatever the target platform is, but it is expected to be set to + /// `Some` only when compiling for WASM. + pub wasm_external_transport: Option, } impl Default for NetworkConfiguration { @@ -69,6 +78,7 @@ impl Default for NetworkConfiguration { client_version: "unknown".into(), node_name: "unknown".into(), enable_mdns: false, + wasm_external_transport: None, } } } @@ -167,7 +177,8 @@ impl NodeKeyConfig { Secp256k1(Secret::File(f)) => get_secret(f, |mut b| secp256k1::SecretKey::from_bytes(&mut b), - secp256k1::SecretKey::generate) + secp256k1::SecretKey::generate, + |b| b.to_bytes().to_vec()) .map(secp256k1::Keypair::from) .map(Keypair::Secp256k1), @@ -180,7 +191,8 @@ impl NodeKeyConfig { Ed25519(Secret::File(f)) => get_secret(f, |mut b| ed25519::SecretKey::from_bytes(&mut b), - ed25519::SecretKey::generate) + ed25519::SecretKey::generate, + |b| b.as_ref().to_vec()) .map(ed25519::Keypair::from) .map(Keypair::Ed25519), } @@ -190,13 +202,13 @@ impl NodeKeyConfig { /// Load a secret key from a file, if it exists, or generate a /// new secret key and write it to that file. In either case, /// the secret key is returned. -fn get_secret(file: P, parse: F, generate: G) -> io::Result +fn get_secret(file: P, parse: F, generate: G, serialize: W) -> io::Result where P: AsRef, F: for<'r> FnOnce(&'r mut [u8]) -> Result, G: FnOnce() -> K, E: Error + Send + Sync + 'static, - K: AsRef<[u8]> + W: Fn(&K) -> Vec, { std::fs::read(&file) .and_then(|mut sk_bytes| @@ -206,7 +218,9 @@ where if e.kind() == io::ErrorKind::NotFound { file.as_ref().parent().map_or(Ok(()), fs::create_dir_all)?; let sk = generate(); - write_secret_file(file, sk.as_ref())?; + let mut sk_vec = serialize(&sk); + write_secret_file(file, &sk_vec)?; + sk_vec.zeroize(); Ok(sk) } else { Err(e) @@ -257,7 +271,7 @@ mod tests { fn secret_bytes(kp: &Keypair) -> Vec { match kp { Keypair::Ed25519(p) => p.secret().as_ref().iter().cloned().collect(), - Keypair::Secp256k1(p) => p.secret().as_ref().iter().cloned().collect(), + Keypair::Secp256k1(p) => p.secret().to_bytes().to_vec(), _ => panic!("Unexpected keypair.") } } diff --git a/core/network-libp2p/src/custom_proto/behaviour.rs b/core/network-libp2p/src/custom_proto/behaviour.rs index 0aa6ed9544740d61fafee1ffa6a390782d3ff092..41b3b32218b400d32d231ff33eb2f6389e299417 100644 --- a/core/network-libp2p/src/custom_proto/behaviour.rs +++ b/core/network-libp2p/src/custom_proto/behaviour.rs @@ -412,7 +412,7 @@ impl CustomProto { debug!(target: "sub-libp2p", "Handler({:?}) <= Enable", occ_entry.key()); self.events.push(NetworkBehaviourAction::SendEvent { peer_id: occ_entry.key().clone(), - event: CustomProtoHandlerIn::Enable(connected_point.clone().into()), + event: CustomProtoHandlerIn::Enable, }); *occ_entry.into_mut() = PeerState::Enabled { connected_point, open }; }, @@ -430,7 +430,7 @@ impl CustomProto { debug!(target: "sub-libp2p", "Handler({:?}) <= Enable", occ_entry.key()); self.events.push(NetworkBehaviourAction::SendEvent { peer_id: occ_entry.key().clone(), - event: CustomProtoHandlerIn::Enable(connected_point.clone().into()), + event: CustomProtoHandlerIn::Enable, }); *occ_entry.into_mut() = PeerState::Enabled { connected_point, open: false }; }, @@ -551,7 +551,7 @@ impl CustomProto { debug!(target: "sub-libp2p", "Handler({:?}) <= Enable", incoming.peer_id); self.events.push(NetworkBehaviourAction::SendEvent { peer_id: incoming.peer_id, - event: CustomProtoHandlerIn::Enable(connected_point.clone().into()), + event: CustomProtoHandlerIn::Enable, }); *state = PeerState::Enabled { open: false, connected_point }; @@ -634,7 +634,7 @@ where debug!(target: "sub-libp2p", "Handler({:?}) <= Enable", peer_id); self.events.push(NetworkBehaviourAction::SendEvent { peer_id: peer_id.clone(), - event: CustomProtoHandlerIn::Enable(connected_point.clone().into()), + event: CustomProtoHandlerIn::Enable, }); *st = PeerState::Enabled { open: false, connected_point }; } @@ -985,7 +985,7 @@ where debug!(target: "sub-libp2p", "Handler({:?}) <= Enable now that ban has expired", peer_id); self.events.push(NetworkBehaviourAction::SendEvent { peer_id: peer_id.clone(), - event: CustomProtoHandlerIn::Enable(connected_point.clone().into()), + event: CustomProtoHandlerIn::Enable, }); *peer_state = PeerState::Enabled { connected_point, open }; } diff --git a/core/network-libp2p/src/custom_proto/handler.rs b/core/network-libp2p/src/custom_proto/handler.rs index 2cfc1107a96b9b411d040e5a5653a14b5fcaa42a..0400c27f827a8a43532a430f383186cc798576b5 100644 --- a/core/network-libp2p/src/custom_proto/handler.rs +++ b/core/network-libp2p/src/custom_proto/handler.rs @@ -18,7 +18,7 @@ use crate::custom_proto::upgrade::{CustomMessage, RegisteredProtocol}; use crate::custom_proto::upgrade::{RegisteredProtocolEvent, RegisteredProtocolSubstream}; use futures::prelude::*; use libp2p::core::{ - PeerId, Endpoint, ProtocolsHandler, ProtocolsHandlerEvent, + ConnectedPoint, PeerId, Endpoint, ProtocolsHandler, ProtocolsHandlerEvent, protocols_handler::IntoProtocolsHandler, protocols_handler::KeepAlive, protocols_handler::ProtocolsHandlerUpgrErr, @@ -114,10 +114,15 @@ where { type Handler = CustomProtoHandler; - fn into_handler(self, remote_peer_id: &PeerId) -> Self::Handler { + fn inbound_protocol(&self) -> RegisteredProtocol { + self.protocol.clone() + } + + fn into_handler(self, remote_peer_id: &PeerId, connected_point: &ConnectedPoint) -> Self::Handler { let clock = Clock::new(); CustomProtoHandler { protocol: self.protocol, + endpoint: connected_point.to_endpoint(), remote_peer_id: remote_peer_id.clone(), state: ProtocolState::Init { substreams: SmallVec::new(), @@ -141,6 +146,10 @@ pub struct CustomProtoHandler { /// any influence on the behaviour. remote_peer_id: PeerId, + /// Whether we are the connection dialer or listener. Used to determine who, between the local + /// node and the remote node, has priority. + endpoint: Endpoint, + /// Queue of events to send to the outside. /// /// This queue must only ever be modified to insert elements at the back, or remove the first @@ -204,9 +213,8 @@ enum ProtocolState { /// Event that can be received by a `CustomProtoHandler`. #[derive(Debug)] pub enum CustomProtoHandlerIn { - /// The node should start using custom protocols. Contains whether we are the dialer or the - /// listener of the connection. - Enable(Endpoint), + /// The node should start using custom protocols. + Enable, /// The node should stop using custom protocols. Disable, @@ -261,7 +269,7 @@ where TMessage: CustomMessage, { /// Enables the handler. - fn enable(&mut self, endpoint: Endpoint) { + fn enable(&mut self) { self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) { ProtocolState::Poisoned => { error!(target: "sub-libp2p", "Handler with {:?} is in poisoned state", @@ -271,7 +279,7 @@ where ProtocolState::Init { substreams: incoming, .. } => { if incoming.is_empty() { - if let Endpoint::Dialer = endpoint { + if let Endpoint::Dialer = self.endpoint { self.events_queue.push(ProtocolsHandlerEvent::OutboundSubstreamRequest { protocol: SubstreamProtocol::new(self.protocol.clone()), info: (), @@ -553,7 +561,7 @@ where TSubstream: AsyncRead + AsyncWrite, TMessage: CustomMessage { fn inject_event(&mut self, message: CustomProtoHandlerIn) { match message { CustomProtoHandlerIn::Disable => self.disable(), - CustomProtoHandlerIn::Enable(endpoint) => self.enable(endpoint), + CustomProtoHandlerIn::Enable => self.enable(), CustomProtoHandlerIn::SendCustomMessage { message } => self.send_message(message), } diff --git a/core/network-libp2p/src/service_task.rs b/core/network-libp2p/src/service_task.rs index 5a6fb6978cfdb631aa18e5085c4d32082db29c39..e74757e0b1b5aa269b8efc555f7887b2edf4f9d1 100644 --- a/core/network-libp2p/src/service_task.rs +++ b/core/network-libp2p/src/service_task.rs @@ -16,6 +16,7 @@ use crate::{ behaviour::Behaviour, + config::NodeKeyConfig, transport, NetworkState, NetworkStatePeer, NetworkStateNotConnectedPeer }; use crate::custom_proto::{CustomProto, CustomProtoOut, CustomMessage, RegisteredProtocol}; @@ -79,6 +80,9 @@ where TMessage: CustomMessage + Send + 'static { }); // Private and public keys configuration. + if let NodeKeyConfig::Secp256k1(_) = config.node_key { + warn!(target: "sub-libp2p", "Secp256k1 keys are deprecated in favour of ed25519"); + } let local_identity = config.node_key.clone().into_keypair()?; let local_public = local_identity.public(); let local_peer_id = local_public.clone().into_peer_id(); @@ -89,7 +93,10 @@ where TMessage: CustomMessage + Send + 'static { let user_agent = format!("{} ({})", config.client_version, config.node_name); let proto = CustomProto::new(registered_custom, peerset); let behaviour = Behaviour::new(proto, user_agent, local_public, known_addresses, config.enable_mdns); - let (transport, bandwidth) = transport::build_transport(local_identity); + let (transport, bandwidth) = transport::build_transport( + local_identity, + config.wasm_external_transport + ); (Swarm::new(transport, behaviour, local_peer_id.clone()), bandwidth) }; @@ -200,7 +207,7 @@ where TMessage: CustomMessage + Send + 'static { let not_connected_peers = { let swarm = &mut self.swarm; - let list = swarm.known_peers().filter(|p| !open.iter().all(|n| n != *p)) + let list = swarm.known_peers().filter(|p| open.iter().all(|n| n != *p)) .cloned().collect::>(); list.into_iter().map(move |peer_id| { (peer_id.to_base58(), NetworkStateNotConnectedPeer { diff --git a/core/network-libp2p/src/transport.rs b/core/network-libp2p/src/transport.rs index 1e8b280f3b089fd49bca1c6775c998fa5b569794..f6790c98f431dd18669771835555cd41af87c0b8 100644 --- a/core/network-libp2p/src/transport.rs +++ b/core/network-libp2p/src/transport.rs @@ -17,11 +17,11 @@ use futures::prelude::*; use libp2p::{ InboundUpgradeExt, OutboundUpgradeExt, PeerId, Transport, - mplex, identity, secio, yamux, websocket, bandwidth + mplex, identity, secio, yamux, bandwidth, wasm_ext }; #[cfg(not(target_os = "unknown"))] -use libp2p::{tcp, dns}; -use libp2p::core::{self, transport::boxed::Boxed, muxing::StreamMuxerBox}; +use libp2p::{tcp, dns, websocket}; +use libp2p::core::{self, transport::boxed::Boxed, transport::OptionalTransport, muxing::StreamMuxerBox}; use std::{io, sync::Arc, time::Duration, usize}; pub use self::bandwidth::BandwidthSinks; @@ -31,20 +31,26 @@ pub use self::bandwidth::BandwidthSinks; /// Returns a `BandwidthSinks` object that allows querying the average bandwidth produced by all /// the connections spawned with this transport. pub fn build_transport( - keypair: identity::Keypair + keypair: identity::Keypair, + wasm_external_transport: Option ) -> (Boxed<(PeerId, StreamMuxerBox), io::Error>, Arc) { let mut mplex_config = mplex::MplexConfig::new(); mplex_config.max_buffer_len_behaviour(mplex::MaxBufferBehaviour::Block); mplex_config.max_buffer_len(usize::MAX); + let transport = if let Some(t) = wasm_external_transport { + OptionalTransport::some(t) + } else { + OptionalTransport::none() + }; + #[cfg(not(target_os = "unknown"))] let transport = { - let transport = tcp::TcpConfig::new(); - let transport = websocket::WsConfig::new(transport.clone()).or_transport(transport); - dns::DnsConfig::new(transport) + let desktop_trans = tcp::TcpConfig::new(); + let desktop_trans = websocket::WsConfig::new(desktop_trans.clone()) + .or_transport(desktop_trans); + transport.or_transport(dns::DnsConfig::new(desktop_trans)) }; - #[cfg(target_os = "unknown")] - let transport = websocket::BrowserWsConfig::new(); let (transport, sinks) = bandwidth::BandwidthLogging::new(transport, Duration::from_secs(5)); diff --git a/core/network/Cargo.toml b/core/network/Cargo.toml index ca898eea0783cac318080647fedba5c1b7f2be73..1b3a4732881e36531e867b4ea0a6426f296186ff 100644 --- a/core/network/Cargo.toml +++ b/core/network/Cargo.toml @@ -9,10 +9,9 @@ edition = "2018" [lib] [dependencies] -crossbeam-channel = "0.3.6" +derive_more = "0.14.0" log = "0.4" -parking_lot = "0.7.1" -error-chain = "0.12" +parking_lot = "0.8.0" bitflags = "1.0" futures = "0.1.17" linked-hash-map = "0.5" @@ -28,17 +27,19 @@ runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitiv parity-codec = { version = "3.3", features = ["derive"] } network_libp2p = { package = "substrate-network-libp2p", path = "../../core/network-libp2p" } peerset = { package = "substrate-peerset", path = "../../core/peerset" } -tokio = "0.1.11" +tokio-timer = "0.2.11" +tokio = { version = "0.1.11", optional = true } keyring = { package = "substrate-keyring", path = "../../core/keyring", optional = true } -test_client = { package = "substrate-test-client", path = "../../core/test-client", optional = true } +test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client", optional = true } void = "1.0" [dev-dependencies] env_logger = { version = "0.6" } keyring = { package = "substrate-keyring", path = "../../core/keyring" } -test_client = { package = "substrate-test-client", path = "../../core/test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" } consensus = { package = "substrate-consensus-common", path = "../../core/consensus/common", features = ["test-helpers"] } +tokio = "0.1.11" [features] default = [] -test-helpers = ["keyring", "test_client", "consensus/test-helpers"] +test-helpers = ["keyring", "test-client", "consensus/test-helpers", "tokio"] diff --git a/core/network/src/chain.rs b/core/network/src/chain.rs index 9548afc9d1a237b154cab9ee1d0adaed9b4d5b82..76096a44aae6139f08c1489eddf88f9dc338e293 100644 --- a/core/network/src/chain.rs +++ b/core/network/src/chain.rs @@ -28,7 +28,7 @@ use primitives::{H256, Blake2Hasher, storage::StorageKey}; /// Local client abstraction for the network. pub trait Client: Send + Sync { /// Get blockchain info. - fn info(&self) -> Result, Error>; + fn info(&self) -> ClientInfo; /// Get block status. fn block_status(&self, id: &BlockId) -> Result; @@ -81,7 +81,7 @@ impl Client for SubstrateClient where Block: BlockT, RA: Send + Sync { - fn info(&self) -> Result, Error> { + fn info(&self) -> ClientInfo { (self as &SubstrateClient).info() } @@ -134,6 +134,7 @@ impl Client for SubstrateClient where } let tree_route = ::client::blockchain::tree_route( + #[allow(deprecated)] self.backend().blockchain(), BlockId::Hash(*block), BlockId::Hash(*base), diff --git a/core/network/src/config.rs b/core/network/src/config.rs index 965aeba8c9f35c0b54ae1acdcc9c7d2ce7206e05..d8fd0f68c705ac5b3d391ce5ecc9c0b828c795de 100644 --- a/core/network/src/config.rs +++ b/core/network/src/config.rs @@ -16,49 +16,40 @@ //! Configuration for the networking layer of Substrate. -pub use network_libp2p::{NonReservedPeerMode, NetworkConfiguration, NodeKeyConfig, Secret}; +pub use crate::protocol::ProtocolConfig; +pub use network_libp2p::{NonReservedPeerMode, NetworkConfiguration, NodeKeyConfig, ProtocolId, Secret}; use bitflags::bitflags; +use consensus::import_queue::ImportQueue; use crate::chain::{Client, FinalityProofProvider}; use parity_codec; -use crate::on_demand::OnDemandService; +use crate::on_demand_layer::OnDemand; use runtime_primitives::traits::{Block as BlockT}; use crate::service::{ExHashT, TransactionPool}; use std::sync::Arc; /// Service initialization parameters. pub struct Params { - /// Configuration. - pub config: ProtocolConfig, + /// Assigned roles for our node. + pub roles: Roles, /// Network layer configuration. pub network_config: NetworkConfiguration, /// Substrate relay chain access point. - pub chain: Arc>, + pub chain: Arc>, /// Finality proof provider. - pub finality_proof_provider: Option>>, + pub finality_proof_provider: Option>>, /// On-demand service reference. - pub on_demand: Option>>, + pub on_demand: Option>>, /// Transaction pool. - pub transaction_pool: Arc>, + pub transaction_pool: Arc>, + /// Name of the protocol to use on the wire. Should be different for each chain. + pub protocol_id: ProtocolId, + /// Import queue to use. + pub import_queue: Box>, /// Protocol specialization. pub specialization: S, } -/// Configuration for the Substrate-specific part of the networking layer. -#[derive(Clone)] -pub struct ProtocolConfig { - /// Assigned roles. - pub roles: Roles, -} - -impl Default for ProtocolConfig { - fn default() -> ProtocolConfig { - ProtocolConfig { - roles: Roles::FULL, - } - } -} - bitflags! { /// Bitmask of the roles that a node fulfills. pub struct Roles: u8 { diff --git a/core/network/src/error.rs b/core/network/src/error.rs index 87b967765cf226bc9ee1d1131d51173f44c04ee9..95a1dc5abe76b42b450835212ba9b823a2020101 100644 --- a/core/network/src/error.rs +++ b/core/network/src/error.rs @@ -14,22 +14,27 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! Substrate service possible errors. +//! Substrate network possible errors. -// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting` -// https://github.com/paritytech/substrate/issues/1547 -#![allow(deprecated)] - -use error_chain::*; -use std::io::Error as IoError; use client; -error_chain! { - foreign_links { - Io(IoError) #[doc = "IO error."]; - Client(client::error::Error) #[doc="Client error"]; - } +/// Result type alias for the network. +pub type Result = std::result::Result; + +/// Error type for the network. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Io error + Io(std::io::Error), + /// Client error + Client(client::error::Error), +} - errors { +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Io(ref err) => Some(err), + Error::Client(ref err) => Some(err), + } } } diff --git a/core/network/src/lib.rs b/core/network/src/lib.rs index 4d69767c7bdf88784417091661ed8a67d95edb40..a65df59fd8c544586912809c8961096edc07bd5d 100644 --- a/core/network/src/lib.rs +++ b/core/network/src/lib.rs @@ -24,29 +24,23 @@ //! mod service; -mod sync; #[macro_use] mod protocol; mod chain; -mod blocks; -mod on_demand; -mod util; +mod on_demand_layer; pub mod config; -pub mod consensus_gossip; pub mod error; -pub mod message; -pub mod specialization; #[cfg(any(test, feature = "test-helpers"))] pub mod test; pub use chain::{Client as ClientHandle, FinalityProofProvider}; pub use service::{ - Service, FetchFuture, TransactionPool, ManageNetwork, NetworkMsg, - SyncProvider, ExHashT, ReportHandle, + NetworkService, NetworkWorker, FetchFuture, TransactionPool, ManageNetwork, + NetworkMsg, SyncProvider, ExHashT, ReportHandle, }; -pub use protocol::{ProtocolStatus, PeerInfo, Context}; -pub use sync::{Status as SyncStatus, SyncState}; +pub use protocol::{ProtocolStatus, PeerInfo, Context, consensus_gossip, message, specialization}; +pub use protocol::sync::{Status as SyncStatus, SyncState}; pub use network_libp2p::{ identity, multiaddr, ProtocolId, Multiaddr, @@ -56,6 +50,7 @@ pub use network_libp2p::{ }; pub use message::{generic as generic_message, RequestId, Status as StatusMessage}; pub use error::Error; -pub use on_demand::{OnDemand, OnDemandService, RemoteResponse}; +pub use protocol::on_demand::AlwaysBadChecker; +pub use on_demand_layer::{OnDemand, RemoteResponse}; #[doc(hidden)] pub use runtime_primitives::traits::Block as BlockT; diff --git a/core/network/src/on_demand.rs b/core/network/src/on_demand.rs deleted file mode 100644 index aea762eefcce2434004635511f4a143f2fedaf9f..0000000000000000000000000000000000000000 --- a/core/network/src/on_demand.rs +++ /dev/null @@ -1,1169 +0,0 @@ -// Copyright 2017-2019 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -//! On-demand requests service. - -use std::collections::{HashMap, VecDeque}; -use std::sync::{Arc, Weak}; -use std::time::{Instant, Duration}; -use log::{trace, info}; -use futures::{Async, Future, Poll}; -use futures::sync::oneshot::{channel, Receiver, Sender as OneShotSender}; -use linked_hash_map::LinkedHashMap; -use linked_hash_map::Entry; -use parking_lot::Mutex; -use client::error::Error as ClientError; -use client::light::fetcher::{Fetcher, FetchChecker, RemoteHeaderRequest, - RemoteCallRequest, RemoteReadRequest, RemoteChangesRequest, ChangesProof, - RemoteReadChildRequest}; -use crate::message; -use network_libp2p::PeerId; -use crate::config::Roles; -use crate::service::Service as NetworkService; -use crate::specialization::NetworkSpecialization; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor}; - -/// Remote request timeout. -const REQUEST_TIMEOUT: Duration = Duration::from_secs(15); -/// Default request retry count. -const RETRY_COUNT: usize = 1; -/// Reputation change for a peer when a request timed out. -const TIMEOUT_REPUTATION_CHANGE: i32 = -(1 << 8); - -/// On-demand service API. -pub trait OnDemandService: Send + Sync { - /// When new node is connected. - fn on_connect(&self, peer: PeerId, role: Roles, best_number: NumberFor); - - /// When block is announced by the peer. - fn on_block_announce(&self, peer: PeerId, best_number: NumberFor); - - /// When node is disconnected. - fn on_disconnect(&self, peer: PeerId); - - /// Maintain peers requests. - fn maintain_peers(&self); - - /// When header response is received from remote node. - fn on_remote_header_response( - &self, - peer: PeerId, - response: message::RemoteHeaderResponse - ); - - /// When read response is received from remote node. - fn on_remote_read_response(&self, peer: PeerId, response: message::RemoteReadResponse); - - /// When call response is received from remote node. - fn on_remote_call_response(&self, peer: PeerId, response: message::RemoteCallResponse); - - /// When changes response is received from remote node. - fn on_remote_changes_response( - &self, - peer: PeerId, - response: message::RemoteChangesResponse, Block::Hash> - ); -} - -/// Trait used by the `OnDemand` service to communicate messages back to the network. -pub trait OnDemandNetwork { - /// Adjusts the reputation of the given peer. - fn report_peer(&self, who: &PeerId, reputation_change: i32); - - /// Disconnect from the given peer. Used in case of misbehaviour. - fn disconnect_peer(&self, who: &PeerId); - - /// Send a request to a peer. - fn send_request(&self, who: &PeerId, message: message::Message); -} - -impl> OnDemandNetwork for Weak> { - fn report_peer(&self, who: &PeerId, reputation_change: i32) { - if let Some(service) = self.upgrade() { - service.report_peer(who.clone(), reputation_change) - } - } - - fn disconnect_peer(&self, who: &PeerId) { - if let Some(service) = self.upgrade() { - service.disconnect_peer(who.clone()) - } - } - - fn send_request(&self, who: &PeerId, message: message::Message) { - if let Some(service) = self.upgrade() { - service.send_request(who.clone(), message) - } - } -} - -/// On-demand requests service. Dispatches requests to appropriate peers. -pub struct OnDemand { - core: Mutex>, - checker: Arc>, - network_interface: Mutex + Send + Sync + 'static>>>, -} - -/// On-demand remote call response. -pub struct RemoteResponse { - receiver: Receiver>, -} - -#[derive(Default)] -struct OnDemandCore { - next_request_id: u64, - pending_requests: VecDeque>, - active_peers: LinkedHashMap>, - idle_peers: VecDeque, - best_blocks: HashMap>, -} - -struct Request { - id: u64, - timestamp: Instant, - retry_count: usize, - data: RequestData, -} - -enum RequestData { - RemoteHeader(RemoteHeaderRequest, OneShotSender>), - RemoteRead(RemoteReadRequest, OneShotSender>, ClientError>>), - RemoteReadChild( - RemoteReadChildRequest, - OneShotSender>, ClientError>> - ), - RemoteCall(RemoteCallRequest, OneShotSender, ClientError>>), - RemoteChanges(RemoteChangesRequest, OneShotSender, u32)>, ClientError>>), -} - -enum Accept { - Ok, - CheckFailed(ClientError, RequestData), - Unexpected(RequestData), -} - -impl Future for RemoteResponse { - type Item = T; - type Error = ClientError; - - fn poll(&mut self) -> Poll { - self.receiver.poll() - .map_err(|_| ClientError::RemoteFetchCancelled.into()) - .and_then(|r| match r { - Async::Ready(Ok(ready)) => Ok(Async::Ready(ready)), - Async::Ready(Err(error)) => Err(error), - Async::NotReady => Ok(Async::NotReady), - }) - } -} - -impl OnDemand where - B::Header: HeaderT, -{ - /// Creates new on-demand service. - pub fn new(checker: Arc>) -> Self { - OnDemand { - checker, - network_interface: Mutex::new(None), - core: Mutex::new(OnDemandCore { - next_request_id: 0, - pending_requests: VecDeque::new(), - active_peers: LinkedHashMap::new(), - idle_peers: VecDeque::new(), - best_blocks: HashMap::new(), - }) - } - } - - /// Get checker reference. - pub fn checker(&self) -> &Arc> { - &self.checker - } - - /// Sets weak reference to network service. - pub fn set_network_interface(&self, network_interface: Box + Send + Sync + 'static>) { - self.network_interface.lock().replace(network_interface); - } - - fn report_peer(&self, who: &PeerId, reputation_change: i32) { - self.network_interface - .lock() - .as_ref() - .expect("1. OnDemand is passed a network sender upon initialization of the service, 2. it should bet set by now") - .report_peer(who, reputation_change); - } - - fn disconnect_peer(&self, who: &PeerId) { - self.network_interface - .lock() - .as_ref() - .expect("1. OnDemand is passed a network sender upon initialization of the service, 2. it should bet set by now") - .disconnect_peer(who); - } - - fn send_request(&self, who: &PeerId, msg: message::Message) { - self.network_interface - .lock() - .as_ref() - .expect("1. OnDemand is passed a network sender upon initialization of the service, 2. it should bet set by now") - .send_request(who, msg); - } - - /// Schedule && dispatch all scheduled requests. - fn schedule_request(&self, retry_count: Option, data: RequestData, result: R) -> R { - let mut core = self.core.lock(); - core.insert(retry_count.unwrap_or(RETRY_COUNT), data); - core.dispatch(self); - result - } - - /// Try to accept response from given peer. - fn accept_response) -> Accept>(&self, rtype: &str, peer: PeerId, request_id: u64, try_accept: F) { - let mut core = self.core.lock(); - let request = match core.remove(peer.clone(), request_id) { - Some(request) => request, - None => { - info!("Invalid remote {} response from peer {}", rtype, peer); - self.report_peer(&peer, i32::min_value()); - self.disconnect_peer(&peer); - core.remove_peer(peer); - return; - }, - }; - - let retry_count = request.retry_count; - let (retry_count, retry_request_data) = match try_accept(request) { - Accept::Ok => (retry_count, None), - Accept::CheckFailed(error, retry_request_data) => { - info!("Failed to check remote {} response from peer {}: {}", rtype, peer, error); - self.report_peer(&peer, i32::min_value()); - self.disconnect_peer(&peer); - core.remove_peer(peer); - - if retry_count > 0 { - (retry_count - 1, Some(retry_request_data)) - } else { - trace!(target: "sync", "Failed to get remote {} response for given number of retries", rtype); - retry_request_data.fail(ClientError::RemoteFetchFailed.into()); - (0, None) - } - }, - Accept::Unexpected(retry_request_data) => { - info!("Unexpected response to remote {} from peer", rtype); - self.report_peer(&peer, i32::min_value()); - self.disconnect_peer(&peer); - core.remove_peer(peer); - - (retry_count, Some(retry_request_data)) - }, - }; - - if let Some(request_data) = retry_request_data { - core.insert(retry_count, request_data); - } - - core.dispatch(self); - } -} - -impl OnDemandService for OnDemand where - B: BlockT, - B::Header: HeaderT, -{ - fn on_connect(&self, peer: PeerId, role: Roles, best_number: NumberFor) { - if !role.is_full() { - return; - } - - let mut core = self.core.lock(); - core.add_peer(peer, best_number); - core.dispatch(self); - } - - fn on_block_announce(&self, peer: PeerId, best_number: NumberFor) { - let mut core = self.core.lock(); - core.update_peer(peer, best_number); - core.dispatch(self); - } - - fn on_disconnect(&self, peer: PeerId) { - let mut core = self.core.lock(); - core.remove_peer(peer); - core.dispatch(self); - } - - fn maintain_peers(&self) { - let mut core = self.core.lock(); - for bad_peer in core.maintain_peers() { - self.report_peer(&bad_peer, TIMEOUT_REPUTATION_CHANGE); - self.disconnect_peer(&bad_peer); - } - core.dispatch(self); - } - - fn on_remote_header_response(&self, peer: PeerId, response: message::RemoteHeaderResponse) { - self.accept_response("header", peer, response.id, |request| match request.data { - RequestData::RemoteHeader(request, sender) => match self.checker.check_header_proof(&request, response.header, response.proof) { - Ok(response) => { - // we do not bother if receiver has been dropped already - let _ = sender.send(Ok(response)); - Accept::Ok - }, - Err(error) => Accept::CheckFailed(error, RequestData::RemoteHeader(request, sender)), - }, - data => Accept::Unexpected(data), - }) - } - - fn on_remote_read_response(&self, peer: PeerId, response: message::RemoteReadResponse) { - self.accept_response("read", peer, response.id, |request| match request.data { - RequestData::RemoteRead(request, sender) => { - match self.checker.check_read_proof(&request, response.proof) { - Ok(response) => { - // we do not bother if receiver has been dropped already - let _ = sender.send(Ok(response)); - Accept::Ok - }, - Err(error) => Accept::CheckFailed( - error, - RequestData::RemoteRead(request, sender) - ), - }}, - RequestData::RemoteReadChild(request, sender) => { - match self.checker.check_read_child_proof(&request, response.proof) { - Ok(response) => { - // we do not bother if receiver has been dropped already - let _ = sender.send(Ok(response)); - Accept::Ok - }, - Err(error) => Accept::CheckFailed( - error, - RequestData::RemoteReadChild(request, sender) - ), - }}, - data => Accept::Unexpected(data), - }) - } - - fn on_remote_call_response(&self, peer: PeerId, response: message::RemoteCallResponse) { - self.accept_response("call", peer, response.id, |request| match request.data { - RequestData::RemoteCall(request, sender) => match self.checker.check_execution_proof(&request, response.proof) { - Ok(response) => { - // we do not bother if receiver has been dropped already - let _ = sender.send(Ok(response)); - Accept::Ok - }, - Err(error) => Accept::CheckFailed(error, RequestData::RemoteCall(request, sender)), - }, - data => Accept::Unexpected(data), - }) - } - - fn on_remote_changes_response(&self, peer: PeerId, response: message::RemoteChangesResponse, B::Hash>) { - self.accept_response("changes", peer, response.id, |request| match request.data { - RequestData::RemoteChanges(request, sender) => match self.checker.check_changes_proof( - &request, ChangesProof { - max_block: response.max, - proof: response.proof, - roots: response.roots.into_iter().collect(), - roots_proof: response.roots_proof, - }) { - Ok(response) => { - // we do not bother if receiver has been dropped already - let _ = sender.send(Ok(response)); - Accept::Ok - }, - Err(error) => Accept::CheckFailed(error, RequestData::RemoteChanges(request, sender)), - }, - data => Accept::Unexpected(data), - }) - } -} - -impl Fetcher for OnDemand where - B: BlockT, - B::Header: HeaderT, -{ - type RemoteHeaderResult = RemoteResponse; - type RemoteReadResult = RemoteResponse>>; - type RemoteCallResult = RemoteResponse>; - type RemoteChangesResult = RemoteResponse, u32)>>; - - fn remote_header(&self, request: RemoteHeaderRequest) -> Self::RemoteHeaderResult { - let (sender, receiver) = channel(); - self.schedule_request(request.retry_count.clone(), RequestData::RemoteHeader(request, sender), - RemoteResponse { receiver }) - } - - fn remote_read(&self, request: RemoteReadRequest) -> Self::RemoteReadResult { - let (sender, receiver) = channel(); - self.schedule_request( - request.retry_count.clone(), - RequestData::RemoteRead(request, sender), - RemoteResponse { receiver } - ) - } - - fn remote_read_child( - &self, - request: RemoteReadChildRequest - ) -> Self::RemoteReadResult { - let (sender, receiver) = channel(); - self.schedule_request( - request.retry_count.clone(), - RequestData::RemoteReadChild(request, sender), - RemoteResponse { receiver } - ) - } - - fn remote_call(&self, request: RemoteCallRequest) -> Self::RemoteCallResult { - let (sender, receiver) = channel(); - self.schedule_request(request.retry_count.clone(), RequestData::RemoteCall(request, sender), - RemoteResponse { receiver }) - } - - fn remote_changes(&self, request: RemoteChangesRequest) -> Self::RemoteChangesResult { - let (sender, receiver) = channel(); - self.schedule_request(request.retry_count.clone(), RequestData::RemoteChanges(request, sender), - RemoteResponse { receiver }) - } -} - -impl OnDemandCore where - B: BlockT, - B::Header: HeaderT, -{ - pub fn add_peer(&mut self, peer: PeerId, best_number: NumberFor) { - self.idle_peers.push_back(peer.clone()); - self.best_blocks.insert(peer, best_number); - } - - pub fn update_peer(&mut self, peer: PeerId, best_number: NumberFor) { - self.best_blocks.insert(peer, best_number); - } - - pub fn remove_peer(&mut self, peer: PeerId) { - self.best_blocks.remove(&peer); - - if let Some(request) = self.active_peers.remove(&peer) { - self.pending_requests.push_front(request); - return; - } - - if let Some(idle_index) = self.idle_peers.iter().position(|i| *i == peer) { - self.idle_peers.swap_remove_back(idle_index); - } - } - - pub fn maintain_peers(&mut self) -> Vec { - let now = Instant::now(); - let mut bad_peers = Vec::new(); - loop { - match self.active_peers.front() { - Some((_, request)) if now - request.timestamp >= REQUEST_TIMEOUT => (), - _ => return bad_peers, - } - - let (bad_peer, request) = self.active_peers.pop_front().expect("front() is Some as checked above"); - self.pending_requests.push_front(request); - bad_peers.push(bad_peer); - } - } - - pub fn insert(&mut self, retry_count: usize, data: RequestData) { - let request_id = self.next_request_id; - self.next_request_id += 1; - - self.pending_requests.push_back(Request { - id: request_id, - timestamp: Instant::now(), - retry_count, - data, - }); - } - - pub fn remove(&mut self, peer: PeerId, id: u64) -> Option> { - match self.active_peers.entry(peer.clone()) { - Entry::Occupied(entry) => match entry.get().id == id { - true => { - self.idle_peers.push_back(peer); - Some(entry.remove()) - }, - false => None, - }, - Entry::Vacant(_) => None, - } - } - - pub fn dispatch(&mut self, on_demand: &OnDemand) { - - let mut last_peer = self.idle_peers.back().cloned(); - let mut unhandled_requests = VecDeque::new(); - - loop { - let peer = match self.idle_peers.pop_front() { - Some(peer) => peer, - None => break, - }; - - // check if request can (optimistically) be processed by the peer - let can_be_processed_by_peer = { - let request = match self.pending_requests.front() { - Some(r) => r, - None => { - self.idle_peers.push_front(peer); - break; - }, - }; - let peer_best_block = self.best_blocks.get(&peer) - .expect("entries are inserted into best_blocks when peer is connected; - entries are removed from best_blocks when peer is disconnected; - peer is in idle_peers and thus connected; qed"); - request.required_block() <= *peer_best_block - }; - - if !can_be_processed_by_peer { - // return peer to the back of the queue - self.idle_peers.push_back(peer.clone()); - - // we have enumerated all peers and noone can handle request - if Some(peer) == last_peer { - let request = self.pending_requests.pop_front().expect("checked in loop condition; qed"); - unhandled_requests.push_back(request); - last_peer = self.idle_peers.back().cloned(); - } - - continue; - } - - last_peer = self.idle_peers.back().cloned(); - - let mut request = self.pending_requests.pop_front().expect("checked in loop condition; qed"); - request.timestamp = Instant::now(); - trace!(target: "sync", "Dispatching remote request {} to peer {}", request.id, peer); - on_demand.send_request(&peer, request.message()); - self.active_peers.insert(peer, request); - } - - self.pending_requests.append(&mut unhandled_requests); - } -} - -impl Request { - pub fn required_block(&self) -> NumberFor { - match self.data { - RequestData::RemoteHeader(ref data, _) => data.block, - RequestData::RemoteRead(ref data, _) => *data.header.number(), - RequestData::RemoteReadChild(ref data, _) => *data.header.number(), - RequestData::RemoteCall(ref data, _) => *data.header.number(), - RequestData::RemoteChanges(ref data, _) => data.max_block.0, - } - } - - pub fn message(&self) -> message::Message { - match self.data { - RequestData::RemoteHeader(ref data, _) => - message::generic::Message::RemoteHeaderRequest(message::RemoteHeaderRequest { - id: self.id, - block: data.block, - }), - RequestData::RemoteRead(ref data, _) => - message::generic::Message::RemoteReadRequest(message::RemoteReadRequest { - id: self.id, - block: data.block, - key: data.key.clone(), - }), - RequestData::RemoteReadChild(ref data, _) => - message::generic::Message::RemoteReadChildRequest( - message::RemoteReadChildRequest { - id: self.id, - block: data.block, - storage_key: data.storage_key.clone(), - key: data.key.clone(), - }), - RequestData::RemoteCall(ref data, _) => - message::generic::Message::RemoteCallRequest(message::RemoteCallRequest { - id: self.id, - block: data.block, - method: data.method.clone(), - data: data.call_data.clone(), - }), - RequestData::RemoteChanges(ref data, _) => - message::generic::Message::RemoteChangesRequest(message::RemoteChangesRequest { - id: self.id, - first: data.first_block.1.clone(), - last: data.last_block.1.clone(), - min: data.tries_roots.1.clone(), - max: data.max_block.1.clone(), - key: data.key.clone(), - }), - } - } -} - -impl RequestData { - pub fn fail(self, error: ClientError) { - // don't care if anyone is listening - match self { - RequestData::RemoteHeader(_, sender) => { let _ = sender.send(Err(error)); }, - RequestData::RemoteCall(_, sender) => { let _ = sender.send(Err(error)); }, - RequestData::RemoteRead(_, sender) => { let _ = sender.send(Err(error)); }, - RequestData::RemoteReadChild(_, sender) => { let _ = sender.send(Err(error)); }, - RequestData::RemoteChanges(_, sender) => { let _ = sender.send(Err(error)); }, - } - } -} - -#[cfg(test)] -pub mod tests { - use std::collections::HashSet; - use std::sync::{Arc, Mutex}; - use std::time::Instant; - use futures::Future; - use runtime_primitives::traits::{Block as BlockT, NumberFor}; - use client::{error::{Error as ClientError, Result as ClientResult}}; - use client::light::fetcher::{Fetcher, FetchChecker, RemoteHeaderRequest, - ChangesProof, RemoteCallRequest, RemoteReadRequest, - RemoteReadChildRequest, RemoteChangesRequest}; - use crate::config::Roles; - use crate::message; - use network_libp2p::PeerId; - use super::{REQUEST_TIMEOUT, OnDemand, OnDemandNetwork, OnDemandService}; - use test_client::runtime::{changes_trie_config, Block, Header}; - - pub struct DummyExecutor; - struct DummyFetchChecker { ok: bool } - - impl FetchChecker for DummyFetchChecker { - fn check_header_proof( - &self, - _request: &RemoteHeaderRequest

, - header: Option
, - _remote_proof: Vec> - ) -> ClientResult
{ - match self.ok { - true if header.is_some() => Ok(header.unwrap()), - _ => Err(ClientError::Backend("Test error".into())), - } - } - - fn check_read_proof(&self, _: &RemoteReadRequest
, _: Vec>) -> ClientResult>> { - match self.ok { - true => Ok(Some(vec![42])), - false => Err(ClientError::Backend("Test error".into())), - } - } - - fn check_read_child_proof( - &self, - _: &RemoteReadChildRequest
, - _: Vec> - ) -> ClientResult>> { - match self.ok { - true => Ok(Some(vec![42])), - false => Err(ClientError::Backend("Test error".into())), - } - } - - fn check_execution_proof(&self, _: &RemoteCallRequest
, _: Vec>) -> ClientResult> { - match self.ok { - true => Ok(vec![42]), - false => Err(ClientError::Backend("Test error".into())), - } - } - - fn check_changes_proof(&self, _: &RemoteChangesRequest
, _: ChangesProof
) -> ClientResult, u32)>> { - match self.ok { - true => Ok(vec![(100, 2)]), - false => Err(ClientError::Backend("Test error".into())), - } - } - } - - fn dummy(ok: bool) -> (Arc, Arc>) { - let executor = Arc::new(DummyExecutor); - let service = Arc::new(OnDemand::new(Arc::new(DummyFetchChecker { ok }))); - (executor, service) - } - - fn total_peers(on_demand: &OnDemand) -> usize { - let core = on_demand.core.lock(); - core.idle_peers.len() + core.active_peers.len() - } - - fn receive_call_response(on_demand: &OnDemand, peer: PeerId, id: message::RequestId) { - on_demand.on_remote_call_response(peer, message::RemoteCallResponse { - id: id, - proof: vec![vec![2]], - }); - } - - fn dummy_header() -> Header { - Header { - parent_hash: Default::default(), - number: 0, - state_root: Default::default(), - extrinsics_root: Default::default(), - digest: Default::default(), - } - } - - #[derive(Default)] - struct DummyNetwork { - disconnected_peers: Mutex>, - } - - impl OnDemandNetwork for Arc { - fn report_peer(&self, _: &PeerId, _: i32) {} - fn disconnect_peer(&self, who: &PeerId) { - self.disconnected_peers.lock().unwrap().insert(who.clone()); - } - fn send_request(&self, _: &PeerId, _: message::Message) {} - } - - fn assert_disconnected_peer(dummy: Arc) { - assert_eq!(dummy.disconnected_peers.lock().unwrap().len(), 1); - } - - #[test] - fn knows_about_peers_roles() { - let (_, on_demand) = dummy(true); - let peer0 = PeerId::random(); - let peer1 = PeerId::random(); - let peer2 = PeerId::random(); - on_demand.on_connect(peer0, Roles::LIGHT, 1000); - on_demand.on_connect(peer1.clone(), Roles::FULL, 2000); - on_demand.on_connect(peer2.clone(), Roles::AUTHORITY, 3000); - assert_eq!(vec![peer1.clone(), peer2.clone()], on_demand.core.lock().idle_peers.iter().cloned().collect::>()); - assert_eq!(on_demand.core.lock().best_blocks.get(&peer1), Some(&2000)); - assert_eq!(on_demand.core.lock().best_blocks.get(&peer2), Some(&3000)); - } - - #[test] - fn disconnects_from_idle_peer() { - let peer0 = PeerId::random(); - - let (_, on_demand) = dummy(true); - on_demand.on_connect(peer0.clone(), Roles::FULL, 100); - assert_eq!(1, total_peers(&*on_demand)); - assert!(!on_demand.core.lock().best_blocks.is_empty()); - - on_demand.on_disconnect(peer0); - assert_eq!(0, total_peers(&*on_demand)); - assert!(on_demand.core.lock().best_blocks.is_empty()); - } - - #[test] - fn disconnects_from_timeouted_peer() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer0 = PeerId::random(); - let peer1 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - on_demand.on_connect(peer1.clone(), Roles::FULL, 1000); - assert_eq!(vec![peer0.clone(), peer1.clone()], on_demand.core.lock().idle_peers.iter().cloned().collect::>()); - assert!(on_demand.core.lock().active_peers.is_empty()); - - on_demand.remote_call(RemoteCallRequest { - block: Default::default(), - header: dummy_header(), - method: "test".into(), - call_data: vec![], - retry_count: None, - }); - assert_eq!(vec![peer1.clone()], on_demand.core.lock().idle_peers.iter().cloned().collect::>()); - assert_eq!(vec![peer0.clone()], on_demand.core.lock().active_peers.keys().cloned().collect::>()); - - on_demand.core.lock().active_peers[&peer0].timestamp = Instant::now() - REQUEST_TIMEOUT - REQUEST_TIMEOUT; - on_demand.maintain_peers(); - assert!(on_demand.core.lock().idle_peers.is_empty()); - assert_eq!(vec![peer1.clone()], on_demand.core.lock().active_peers.keys().cloned().collect::>()); - assert_disconnected_peer(network_interface); - } - - #[test] - fn disconnects_from_peer_on_response_with_wrong_id() { - let (_x, on_demand) = dummy(true); - let peer0 = PeerId::random(); - let network_interface = Arc::new(DummyNetwork::default()); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - - on_demand.remote_call(RemoteCallRequest { - block: Default::default(), - header: dummy_header(), - method: "test".into(), - call_data: vec![], - retry_count: None, - }); - receive_call_response(&*on_demand, peer0, 1); - assert_disconnected_peer(network_interface); - assert_eq!(on_demand.core.lock().pending_requests.len(), 1); - } - - #[test] - fn disconnects_from_peer_on_incorrect_response() { - let (_x, on_demand) = dummy(false); - let network_interface = Arc::new(DummyNetwork::default()); - let peer0 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.remote_call(RemoteCallRequest { - block: Default::default(), - header: dummy_header(), - method: "test".into(), - call_data: vec![], - retry_count: Some(1), - }); - - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - receive_call_response(&*on_demand, peer0.clone(), 0); - assert_disconnected_peer(network_interface); - assert_eq!(on_demand.core.lock().pending_requests.len(), 1); - } - - #[test] - fn disconnects_from_peer_on_unexpected_response() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer0 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - - receive_call_response(&*on_demand, peer0, 0); - assert_disconnected_peer(network_interface); - } - - #[test] - fn disconnects_from_peer_on_wrong_response_type() { - let (_x, on_demand) = dummy(false); - let peer0 = PeerId::random(); - let network_interface = Arc::new(DummyNetwork::default()); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - - on_demand.remote_call(RemoteCallRequest { - block: Default::default(), - header: dummy_header(), - method: "test".into(), - call_data: vec![], - retry_count: Some(1), - }); - - on_demand.on_remote_read_response(peer0.clone(), message::RemoteReadResponse { - id: 0, - proof: vec![vec![2]], - }); - assert_disconnected_peer(network_interface); - assert_eq!(on_demand.core.lock().pending_requests.len(), 1); - } - - #[test] - fn receives_remote_failure_after_retry_count_failures() { - use parking_lot::{Condvar, Mutex}; - - let retry_count = 2; - let peer_ids = (0 .. retry_count + 1).map(|_| PeerId::random()).collect::>(); - let (_x, on_demand) = dummy(false); - let network_interface = Arc::new(DummyNetwork::default()); - on_demand.set_network_interface(Box::new(network_interface.clone())); - for i in 0..retry_count+1 { - on_demand.on_connect(peer_ids[i].clone(), Roles::FULL, 1000); - } - - let sync = Arc::new((Mutex::new(0), Mutex::new(0), Condvar::new())); - let thread_sync = sync.clone(); - - let response = on_demand.remote_call(RemoteCallRequest { - block: Default::default(), - header: dummy_header(), - method: "test".into(), - call_data: vec![], - retry_count: Some(retry_count) - }); - let thread = ::std::thread::spawn(move || { - let &(ref current, ref finished_at, ref finished) = &*thread_sync; - let _ = response.wait().unwrap_err(); - *finished_at.lock() = *current.lock(); - finished.notify_one(); - }); - - let &(ref current, ref finished_at, ref finished) = &*sync; - for i in 0..retry_count+1 { - let mut current = current.lock(); - *current = *current + 1; - receive_call_response(&*on_demand, peer_ids[i].clone(), i as u64); - } - - let mut finished_at = finished_at.lock(); - assert!(!finished.wait_for(&mut finished_at, ::std::time::Duration::from_millis(1000)).timed_out()); - assert_eq!(*finished_at, retry_count + 1); - - thread.join().unwrap(); - } - - #[test] - fn receives_remote_call_response() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer0 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - - let response = on_demand.remote_call(RemoteCallRequest { - block: Default::default(), - header: dummy_header(), - method: "test".into(), - call_data: vec![], - retry_count: None, - }); - let thread = ::std::thread::spawn(move || { - let result = response.wait().unwrap(); - assert_eq!(result, vec![42]); - }); - - receive_call_response(&*on_demand, peer0.clone(), 0); - thread.join().unwrap(); - } - - #[test] - fn receives_remote_read_response() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer0 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - - let response = on_demand.remote_read(RemoteReadRequest { - header: dummy_header(), - block: Default::default(), - key: b":key".to_vec(), - retry_count: None, - }); - let thread = ::std::thread::spawn(move || { - let result = response.wait().unwrap(); - assert_eq!(result, Some(vec![42])); - }); - - on_demand.on_remote_read_response(peer0.clone(), message::RemoteReadResponse { - id: 0, - proof: vec![vec![2]], - }); - thread.join().unwrap(); - } - - #[test] - fn receives_remote_read_child_response() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer0 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - - let response = on_demand.remote_read_child(RemoteReadChildRequest { - header: dummy_header(), - block: Default::default(), - storage_key: b":child_storage:sub".to_vec(), - key: b":key".to_vec(), - retry_count: None, - }); - let thread = ::std::thread::spawn(move || { - let result = response.wait().unwrap(); - assert_eq!(result, Some(vec![42])); - }); - - on_demand.on_remote_read_response( - peer0.clone(), message::RemoteReadResponse { - id: 0, - proof: vec![vec![2]], - }); - thread.join().unwrap(); - } - - #[test] - fn receives_remote_header_response() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer0 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - - let response = on_demand.remote_header(RemoteHeaderRequest { - cht_root: Default::default(), - block: 1, - retry_count: None, - }); - let thread = ::std::thread::spawn(move || { - let result = response.wait().unwrap(); - assert_eq!( - result.hash(), - "6443a0b46e0412e626363028115a9f2c\ - f963eeed526b8b33e5316f08b50d0dc3".parse().unwrap() - ); - }); - - on_demand.on_remote_header_response(peer0.clone(), message::RemoteHeaderResponse { - id: 0, - header: Some(Header { - parent_hash: Default::default(), - number: 1, - state_root: Default::default(), - extrinsics_root: Default::default(), - digest: Default::default(), - }), - proof: vec![vec![2]], - }); - thread.join().unwrap(); - } - - #[test] - fn receives_remote_changes_response() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer0 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - on_demand.on_connect(peer0.clone(), Roles::FULL, 1000); - - let response = on_demand.remote_changes(RemoteChangesRequest { - changes_trie_config: changes_trie_config(), - first_block: (1, Default::default()), - last_block: (100, Default::default()), - max_block: (100, Default::default()), - tries_roots: (1, Default::default(), vec![]), - key: vec![], - retry_count: None, - }); - let thread = ::std::thread::spawn(move || { - let result = response.wait().unwrap(); - assert_eq!(result, vec![(100, 2)]); - }); - - on_demand.on_remote_changes_response(peer0.clone(), message::RemoteChangesResponse { - id: 0, - max: 1000, - proof: vec![vec![2]], - roots: vec![], - roots_proof: vec![], - }); - thread.join().unwrap(); - } - - #[test] - fn does_not_sends_request_to_peer_who_has_no_required_block() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer1 = PeerId::random(); - let peer2 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - - on_demand.on_connect(peer1.clone(), Roles::FULL, 100); - - on_demand.remote_header(RemoteHeaderRequest { - cht_root: Default::default(), - block: 200, - retry_count: None, - }); - on_demand.remote_header(RemoteHeaderRequest { - cht_root: Default::default(), - block: 250, - retry_count: None, - }); - on_demand.remote_header(RemoteHeaderRequest { - cht_root: Default::default(), - block: 250, - retry_count: None, - }); - - on_demand.on_connect(peer2.clone(), Roles::FULL, 150); - - assert_eq!(vec![peer1.clone(), peer2.clone()], on_demand.core.lock().idle_peers.iter().cloned().collect::>()); - assert_eq!(on_demand.core.lock().pending_requests.len(), 3); - - on_demand.on_block_announce(peer1.clone(), 250); - - assert_eq!(vec![peer2.clone()], on_demand.core.lock().idle_peers.iter().cloned().collect::>()); - assert_eq!(on_demand.core.lock().pending_requests.len(), 2); - - on_demand.on_block_announce(peer2.clone(), 250); - - assert!(!on_demand.core.lock().idle_peers.iter().any(|_| true)); - assert_eq!(on_demand.core.lock().pending_requests.len(), 1); - - on_demand.on_remote_header_response(peer1.clone(), message::RemoteHeaderResponse { - id: 0, - header: Some(dummy_header()), - proof: vec![], - }); - - assert!(!on_demand.core.lock().idle_peers.iter().any(|_| true)); - assert_eq!(on_demand.core.lock().pending_requests.len(), 0); - } - - #[test] - fn does_not_loop_forever_after_dispatching_request_to_last_peer() { - // this test is a regression for a bug where the dispatch function would - // loop forever after dispatching a request to the last peer, since the - // last peer was not updated - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer1 = PeerId::random(); - let peer2 = PeerId::random(); - let peer3 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - - on_demand.remote_header(RemoteHeaderRequest { - cht_root: Default::default(), - block: 250, - retry_count: None, - }); - on_demand.remote_header(RemoteHeaderRequest { - cht_root: Default::default(), - block: 250, - retry_count: None, - }); - - on_demand.on_connect(peer1.clone(), Roles::FULL, 200); - on_demand.on_connect(peer2.clone(), Roles::FULL, 200); - on_demand.on_connect(peer3.clone(), Roles::FULL, 250); - - assert_eq!(vec![peer1.clone(), peer2.clone()], on_demand.core.lock().idle_peers.iter().cloned().collect::>()); - assert_eq!(on_demand.core.lock().pending_requests.len(), 1); - } - - #[test] - fn tries_to_send_all_pending_requests() { - let (_x, on_demand) = dummy(true); - let network_interface = Arc::new(DummyNetwork::default()); - let peer1 = PeerId::random(); - on_demand.set_network_interface(Box::new(network_interface.clone())); - - on_demand.remote_header(RemoteHeaderRequest { - cht_root: Default::default(), - block: 300, - retry_count: None, - }); - on_demand.remote_header(RemoteHeaderRequest { - cht_root: Default::default(), - block: 250, - retry_count: None, - }); - - on_demand.on_connect(peer1.clone(), Roles::FULL, 250); - - assert!(on_demand.core.lock().idle_peers.iter().cloned().collect::>().is_empty()); - assert_eq!(on_demand.core.lock().pending_requests.len(), 1); - } -} diff --git a/core/network/src/on_demand_layer.rs b/core/network/src/on_demand_layer.rs new file mode 100644 index 0000000000000000000000000000000000000000..86b3d6b7f4a12a304420db5f685539a3cb3b0ce4 --- /dev/null +++ b/core/network/src/on_demand_layer.rs @@ -0,0 +1,149 @@ +// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! On-demand requests service. + +use crate::protocol::on_demand::RequestData; +use std::sync::Arc; +use futures::{prelude::*, sync::mpsc, sync::oneshot}; +use parking_lot::Mutex; +use client::error::Error as ClientError; +use client::light::fetcher::{Fetcher, FetchChecker, RemoteHeaderRequest, + RemoteCallRequest, RemoteReadRequest, RemoteChangesRequest, + RemoteReadChildRequest, RemoteBodyRequest}; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor}; + +/// Implements the `Fetcher` trait of the client. Makes it possible for the light client to perform +/// network requests for some state. +/// +/// This implementation stores all the requests in a queue. The network, in parallel, is then +/// responsible for pulling elements out of that queue and fulfilling them. +pub struct OnDemand { + /// Objects that checks whether what has been retrieved is correct. + checker: Arc>, + + /// Queue of requests. Set to `Some` at initialization, then extracted by the network. + /// + /// Note that a better alternative would be to use a MPMC queue here, and add a `poll` method + /// from the `OnDemand`. However there exists no popular implementation of MPMC channels in + /// asynchronous Rust at the moment + requests_queue: Mutex>>>, + + /// Sending side of `requests_queue`. + requests_send: mpsc::UnboundedSender>, +} + +impl OnDemand where + B::Header: HeaderT, +{ + /// Creates new on-demand service. + pub fn new(checker: Arc>) -> Self { + let (requests_send, requests_queue) = mpsc::unbounded(); + let requests_queue = Mutex::new(Some(requests_queue)); + + OnDemand { + checker, + requests_queue, + requests_send, + } + } + + /// Get checker reference. + pub fn checker(&self) -> &Arc> { + &self.checker + } + + /// Extracts the queue of requests. + /// + /// Whenever one of the methods of the `Fetcher` trait is called, an element is pushed on this + /// channel. + /// + /// If this function returns `None`, that means that the receiver has already been extracted in + /// the past, and therefore that something already handles the requests. + pub(crate) fn extract_receiver(&self) -> Option>> { + self.requests_queue.lock().take() + } +} + +impl Fetcher for OnDemand where + B: BlockT, + B::Header: HeaderT, +{ + type RemoteHeaderResult = RemoteResponse; + type RemoteReadResult = RemoteResponse>>; + type RemoteCallResult = RemoteResponse>; + type RemoteChangesResult = RemoteResponse, u32)>>; + type RemoteBodyResult = RemoteResponse>; + + fn remote_header(&self, request: RemoteHeaderRequest) -> Self::RemoteHeaderResult { + let (sender, receiver) = oneshot::channel(); + let _ = self.requests_send.unbounded_send(RequestData::RemoteHeader(request, sender)); + RemoteResponse { receiver } + } + + fn remote_read(&self, request: RemoteReadRequest) -> Self::RemoteReadResult { + let (sender, receiver) = oneshot::channel(); + let _ = self.requests_send.unbounded_send(RequestData::RemoteRead(request, sender)); + RemoteResponse { receiver } + } + + fn remote_read_child( + &self, + request: RemoteReadChildRequest + ) -> Self::RemoteReadResult { + let (sender, receiver) = oneshot::channel(); + let _ = self.requests_send.unbounded_send(RequestData::RemoteReadChild(request, sender)); + RemoteResponse { receiver } + } + + fn remote_call(&self, request: RemoteCallRequest) -> Self::RemoteCallResult { + let (sender, receiver) = oneshot::channel(); + let _ = self.requests_send.unbounded_send(RequestData::RemoteCall(request, sender)); + RemoteResponse { receiver } + } + + fn remote_changes(&self, request: RemoteChangesRequest) -> Self::RemoteChangesResult { + let (sender, receiver) = oneshot::channel(); + let _ = self.requests_send.unbounded_send(RequestData::RemoteChanges(request, sender)); + RemoteResponse { receiver } + } + + fn remote_body(&self, request: RemoteBodyRequest) -> Self::RemoteBodyResult { + let (sender, receiver) = oneshot::channel(); + let _ = self.requests_send.unbounded_send(RequestData::RemoteBody(request, sender)); + RemoteResponse { receiver } + } +} + +/// Future for an on-demand remote call response. +pub struct RemoteResponse { + receiver: oneshot::Receiver>, +} + +impl Future for RemoteResponse { + type Item = T; + type Error = ClientError; + + fn poll(&mut self) -> Poll { + self.receiver.poll() + .map_err(|_| ClientError::RemoteFetchCancelled.into()) + .and_then(|r| match r { + Async::Ready(Ok(ready)) => Ok(Async::Ready(ready)), + Async::Ready(Err(error)) => Err(error), + Async::NotReady => Ok(Async::NotReady), + }) + } +} diff --git a/core/network/src/protocol.rs b/core/network/src/protocol.rs index 33e376aab33b27451826136cbefb7be3f6f98add..576d37a82fac36a8a20f7ccf70d713873a537495 100644 --- a/core/network/src/protocol.rs +++ b/core/network/src/protocol.rs @@ -19,28 +19,39 @@ use network_libp2p::PeerId; use primitives::storage::StorageKey; use consensus::{import_queue::IncomingBlock, import_queue::Origin, BlockOrigin}; use runtime_primitives::{generic::BlockId, ConsensusEngineId, Justification}; -use runtime_primitives::traits::{As, Block as BlockT, Header as HeaderT, NumberFor, Zero}; +use runtime_primitives::traits::{ + Block as BlockT, Header as HeaderT, NumberFor, One, Zero, + CheckedSub, SaturatedConversion +}; use consensus::import_queue::SharedFinalityProofRequestBuilder; -use crate::message::{ - self, BlockRequest as BlockRequestMessage, +use message::{ + BlockRequest as BlockRequestMessage, FinalityProofRequest as FinalityProofRequestMessage, Message, }; -use crate::message::generic::{Message as GenericMessage, ConsensusMessage}; -use crate::consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient}; -use crate::on_demand::OnDemandService; -use crate::specialization::NetworkSpecialization; -use crate::sync::{ChainSync, Context as SyncContext, Status as SyncStatus, SyncState}; -use crate::service::{NetworkChan, NetworkMsg, TransactionPool, ExHashT}; -use crate::config::{ProtocolConfig, Roles}; -use parking_lot::RwLock; +use message::{BlockAttributes, Direction, FromBlock, RequestId}; +use message::generic::{Message as GenericMessage, ConsensusMessage}; +use consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient}; +use on_demand::{OnDemandCore, OnDemandNetwork, RequestData}; +use specialization::NetworkSpecialization; +use sync::{ChainSync, Context as SyncContext, Status as SyncStatus, SyncState}; +use crate::service::{TransactionPool, ExHashT}; +use crate::config::Roles; use rustc_hex::ToHex; use std::collections::{BTreeMap, HashMap}; use std::sync::Arc; use std::{cmp, num::NonZeroUsize, time}; use log::{trace, debug, warn, error}; use crate::chain::{Client, FinalityProofProvider}; -use client::light::fetcher::ChangesProof; -use crate::{error, util::LruHashSet}; +use client::light::fetcher::{FetchChecker, ChangesProof}; +use crate::error; +use util::LruHashSet; + +mod util; +pub mod consensus_gossip; +pub mod message; +pub mod on_demand; +pub mod specialization; +pub mod sync; const REQUEST_TIMEOUT_SEC: u64 = 40; /// Interval at which we perform time based maintenance @@ -76,13 +87,13 @@ const RPC_FAILED_REPUTATION_CHANGE: i32 = -(1 << 12); // Lock must always be taken in order declared here. pub struct Protocol, H: ExHashT> { - network_chan: NetworkChan, /// Interval at which we call `tick`. - tick_timeout: tokio::timer::Interval, + tick_timeout: tokio_timer::Interval, /// Interval at which we call `propagate_extrinsics`. - propagate_timeout: tokio::timer::Interval, + propagate_timeout: tokio_timer::Interval, config: ProtocolConfig, - on_demand: Option>>, + /// Handler for on-demand requests. + on_demand_core: OnDemandCore, genesis_hash: B::Hash, sync: ChainSync, specialization: S, @@ -90,10 +101,6 @@ pub struct Protocol, H: ExHashT> { context_data: ContextData, // Connected peers pending Status message. handshaking_peers: HashMap, - // Connected peers from whom we received a Status message, - // similar to context_data.peers but shared with the SyncProvider. - connected_peers: Arc>>>, - transaction_pool: Arc>, } /// A peer from whom we have received a Status message. @@ -120,7 +127,7 @@ pub struct ProtocolStatus { } /// Peer information -#[derive(Debug)] +#[derive(Debug, Clone)] struct Peer { info: PeerInfo, /// Current block request, if any. @@ -148,6 +155,129 @@ pub struct PeerInfo { pub best_number: ::Number, } +/// Context passed as input to the methods of `protocol.rs` and that is used to communicate back +/// with the network. +pub trait NetworkOut { + /// Adjusts the reputation of the peer. Use this to point out that a peer has been malign or + /// irresponsible or appeared lazy. + fn report_peer(&mut self, who: PeerId, reputation: i32); + + /// Force disconnecting from a peer. + fn disconnect_peer(&mut self, who: PeerId); + + /// Send a message to a peer. + fn send_message(&mut self, who: PeerId, message: Message); +} + +impl<'a, 'b, B: BlockT> OnDemandNetwork for &'a mut &'b mut dyn NetworkOut { + fn report_peer(&mut self, who: &PeerId, reputation: i32) { + NetworkOut::report_peer(**self, who.clone(), reputation) + } + + fn disconnect_peer(&mut self, who: &PeerId) { + NetworkOut::disconnect_peer(**self, who.clone()) + } + + fn send_header_request(&mut self, who: &PeerId, id: RequestId, block: <::Header as HeaderT>::Number) { + let message = message::generic::Message::RemoteHeaderRequest(message::RemoteHeaderRequest { + id, + block, + }); + + NetworkOut::send_message(**self, who.clone(), message) + } + + fn send_read_request(&mut self, who: &PeerId, id: RequestId, block: ::Hash, key: Vec) { + let message = message::generic::Message::RemoteReadRequest(message::RemoteReadRequest { + id, + block, + key, + }); + + NetworkOut::send_message(**self, who.clone(), message) + } + + fn send_read_child_request( + &mut self, + who: &PeerId, + id: RequestId, + block: ::Hash, + storage_key: Vec, + key: Vec + ) { + let message = message::generic::Message::RemoteReadChildRequest(message::RemoteReadChildRequest { + id, + block, + storage_key, + key, + }); + + NetworkOut::send_message(**self, who.clone(), message) + } + + fn send_call_request( + &mut self, + who: &PeerId, + id: RequestId, + block: ::Hash, + method: String, + data: Vec + ) { + let message = message::generic::Message::RemoteCallRequest(message::RemoteCallRequest { + id, + block, + method, + data, + }); + + NetworkOut::send_message(**self, who.clone(), message) + } + + fn send_changes_request( + &mut self, + who: &PeerId, + id: RequestId, + first: ::Hash, + last: ::Hash, + min: ::Hash, + max: ::Hash, + key: Vec + ) { + let message = message::generic::Message::RemoteChangesRequest(message::RemoteChangesRequest { + id, + first, + last, + min, + max, + key, + }); + + NetworkOut::send_message(**self, who.clone(), message) + } + + fn send_body_request( + &mut self, + who: &PeerId, + id: RequestId, + fields: BlockAttributes, + from: FromBlock<::Hash, <::Header as HeaderT>::Number>, + to: Option<::Hash>, + direction: Direction, + max: Option + ) { + let message = message::generic::Message::BlockRequest(message::BlockRequest:: { + id, + fields, + from, + to, + direction, + max, + }); + + NetworkOut::send_message(**self, who.clone(), message) + } +} + /// Context for a network-specific handler. pub trait Context { /// Adjusts the reputation of the peer. Use this to point out that a peer has been malign or @@ -166,29 +296,29 @@ pub trait Context { /// Protocol context. struct ProtocolContext<'a, B: 'a + BlockT, H: 'a + ExHashT> { - network_chan: &'a NetworkChan, + network_out: &'a mut dyn NetworkOut, context_data: &'a mut ContextData, } impl<'a, B: BlockT + 'a, H: 'a + ExHashT> ProtocolContext<'a, B, H> { - fn new(context_data: &'a mut ContextData, network_chan: &'a NetworkChan) -> Self { - ProtocolContext { network_chan, context_data } + fn new(context_data: &'a mut ContextData, network_out: &'a mut dyn NetworkOut) -> Self { + ProtocolContext { network_out, context_data } } } impl<'a, B: BlockT + 'a, H: ExHashT + 'a> Context for ProtocolContext<'a, B, H> { fn report_peer(&mut self, who: PeerId, reputation: i32) { - self.network_chan.send(NetworkMsg::ReportPeer(who, reputation)) + self.network_out.report_peer(who, reputation) } fn disconnect_peer(&mut self, who: PeerId) { - self.network_chan.send(NetworkMsg::DisconnectPeer(who)) + self.network_out.disconnect_peer(who) } fn send_consensus(&mut self, who: PeerId, consensus: ConsensusMessage) { send_message( &mut self.context_data.peers, - &self.network_chan, + self.network_out, who, GenericMessage::Consensus(consensus) ) @@ -197,7 +327,7 @@ impl<'a, B: BlockT + 'a, H: ExHashT + 'a> Context for ProtocolContext<'a, B, fn send_chain_specific(&mut self, who: PeerId, message: Vec) { send_message( &mut self.context_data.peers, - &self.network_chan, + self.network_out, who, GenericMessage::ChainSpecific(message) ) @@ -206,25 +336,21 @@ impl<'a, B: BlockT + 'a, H: ExHashT + 'a> Context for ProtocolContext<'a, B, impl<'a, B: BlockT + 'a, H: ExHashT + 'a> SyncContext for ProtocolContext<'a, B, H> { fn report_peer(&mut self, who: PeerId, reputation: i32) { - self.network_chan.send(NetworkMsg::ReportPeer(who, reputation)) + self.network_out.report_peer(who, reputation) } fn disconnect_peer(&mut self, who: PeerId) { - self.network_chan.send(NetworkMsg::DisconnectPeer(who)) - } - - fn peer_info(&self, who: &PeerId) -> Option> { - self.context_data.peers.get(who).map(|p| p.info.clone()) + self.network_out.disconnect_peer(who) } - fn client(&self) -> &Client { + fn client(&self) -> &dyn Client { &*self.context_data.chain } fn send_finality_proof_request(&mut self, who: PeerId, request: FinalityProofRequestMessage) { send_message( &mut self.context_data.peers, - &self.network_chan, + self.network_out, who, GenericMessage::FinalityProofRequest(request) ) @@ -233,7 +359,7 @@ impl<'a, B: BlockT + 'a, H: ExHashT + 'a> SyncContext for ProtocolContext<'a, fn send_block_request(&mut self, who: PeerId, request: BlockRequestMessage) { send_message( &mut self.context_data.peers, - &self.network_chan, + self.network_out, who, GenericMessage::BlockRequest(request) ) @@ -244,42 +370,48 @@ impl<'a, B: BlockT + 'a, H: ExHashT + 'a> SyncContext for ProtocolContext<'a, struct ContextData { // All connected peers peers: HashMap>, - pub chain: Arc>, - pub finality_proof_provider: Option>>, + pub chain: Arc>, +} + +/// Configuration for the Substrate-specific part of the networking layer. +#[derive(Clone)] +pub struct ProtocolConfig { + /// Assigned roles. + pub roles: Roles, +} + +impl Default for ProtocolConfig { + fn default() -> ProtocolConfig { + ProtocolConfig { + roles: Roles::FULL, + } + } } impl, H: ExHashT> Protocol { /// Create a new instance. pub fn new( - connected_peers: Arc>>>, - network_chan: NetworkChan, config: ProtocolConfig, - chain: Arc>, - finality_proof_provider: Option>>, - on_demand: Option>>, - transaction_pool: Arc>, + chain: Arc>, + checker: Arc>, specialization: S, ) -> error::Result> { - let info = chain.info()?; + let info = chain.info(); let sync = ChainSync::new(config.roles, &info); Ok(Protocol { - network_chan, - tick_timeout: tokio::timer::Interval::new_interval(TICK_TIMEOUT), - propagate_timeout: tokio::timer::Interval::new_interval(PROPAGATE_TIMEOUT), + tick_timeout: tokio_timer::Interval::new_interval(TICK_TIMEOUT), + propagate_timeout: tokio_timer::Interval::new_interval(PROPAGATE_TIMEOUT), config: config, context_data: ContextData { peers: HashMap::new(), chain, - finality_proof_provider, }, - on_demand, + on_demand_core: OnDemandCore::new(checker), genesis_hash: info.chain.genesis_hash, sync, specialization: specialization, consensus_gossip: ConsensusGossip::new(), handshaking_peers: HashMap::new(), - connected_peers, - transaction_pool: transaction_pool, }) } @@ -304,28 +436,37 @@ impl, H: ExHashT> Protocol { pub fn is_offline(&self) -> bool { self.sync.status().is_offline() } -} -impl, H: ExHashT> Future for Protocol { - type Item = (); - type Error = void::Void; + /// Starts a new data demand request. + /// + /// The parameter contains a `Sender` where the result, once received, must be sent. + pub(crate) fn add_on_demand_request(&mut self, mut network_out: &mut dyn NetworkOut, rq: RequestData) { + self.on_demand_core.add_request(&mut network_out, rq); + } - fn poll(&mut self) -> Poll { + pub fn poll( + &mut self, + network_out: &mut dyn NetworkOut, + transaction_pool: &(impl TransactionPool + ?Sized) + ) -> Poll { while let Ok(Async::Ready(_)) = self.tick_timeout.poll() { - self.tick(); + self.tick(network_out); } while let Ok(Async::Ready(_)) = self.propagate_timeout.poll() { - self.propagate_extrinsics(); + self.propagate_extrinsics(network_out, transaction_pool); } Ok(Async::NotReady) } -} -impl, H: ExHashT> Protocol { + fn is_on_demand_response(&self, who: &PeerId, response_id: message::RequestId) -> bool { + self.on_demand_core.is_on_demand_response(&who, response_id) + } + fn handle_response( &mut self, + network_out: &mut dyn NetworkOut, who: PeerId, response: &message::BlockResponse ) -> Option> { @@ -340,8 +481,8 @@ impl, H: ExHashT> Protocol { return request.map(|(_, r)| r) } trace!(target: "sync", "Unexpected response packet from {} ({})", who, response.id); - self.network_chan.send(NetworkMsg::ReportPeer(who.clone(), i32::min_value())); - self.network_chan.send(NetworkMsg::DisconnectPeer(who)); + network_out.report_peer(who.clone(), i32::min_value()); + network_out.disconnect_peer(who); } None } @@ -352,51 +493,74 @@ impl, H: ExHashT> Protocol { peer.info.best_hash = info.best_hash; peer.info.best_number = info.best_number; } - let mut peers = self.connected_peers.write(); - if let Some(ref mut peer) = peers.get_mut(who) { - peer.peer_info.best_hash = info.best_hash; - peer.peer_info.best_number = info.best_number; - } } } - pub fn on_custom_message(&mut self, who: PeerId, message: Message) -> CustomMessageOutcome { + /// Returns information about all the peers we are connected to after the handshake message. + pub fn peers_info(&self) -> impl Iterator)> { + self.context_data.peers.iter().map(|(id, peer)| (id, &peer.info)) + } + + pub fn on_custom_message( + &mut self, + network_out: &mut dyn NetworkOut, + transaction_pool: &(impl TransactionPool + ?Sized), + who: PeerId, + message: Message, + finality_proof_provider: Option<&dyn FinalityProofProvider> + ) -> CustomMessageOutcome { match message { - GenericMessage::Status(s) => self.on_status_message(who, s), - GenericMessage::BlockRequest(r) => self.on_block_request(who, r), + GenericMessage::Status(s) => self.on_status_message(network_out, who, s), + GenericMessage::BlockRequest(r) => self.on_block_request(network_out, who, r), GenericMessage::BlockResponse(r) => { - if let Some(request) = self.handle_response(who.clone(), &r) { - let outcome = self.on_block_response(who.clone(), request, r); - self.update_peer_info(&who); - return outcome + // Note, this is safe because only `ordinary bodies` and `remote bodies` are received in this matter. + if self.is_on_demand_response(&who, r.id) { + self.on_remote_body_response(network_out, who, r); + } else { + if let Some(request) = self.handle_response(network_out, who.clone(), &r) { + let outcome = self.on_block_response(network_out, who.clone(), request, r); + self.update_peer_info(&who); + return outcome + } } }, GenericMessage::BlockAnnounce(announce) => { - self.on_block_announce(who.clone(), announce); + let outcome = self.on_block_announce(network_out, who.clone(), announce); self.update_peer_info(&who); + return outcome; }, - GenericMessage::Transactions(m) => self.on_extrinsics(who, m), - GenericMessage::RemoteCallRequest(request) => self.on_remote_call_request(who, request), - GenericMessage::RemoteCallResponse(response) => self.on_remote_call_response(who, response), - GenericMessage::RemoteReadRequest(request) => self.on_remote_read_request(who, request), - GenericMessage::RemoteReadResponse(response) => self.on_remote_read_response(who, response), - GenericMessage::RemoteHeaderRequest(request) => self.on_remote_header_request(who, request), - GenericMessage::RemoteHeaderResponse(response) => self.on_remote_header_response(who, response), - GenericMessage::RemoteChangesRequest(request) => self.on_remote_changes_request(who, request), - GenericMessage::RemoteChangesResponse(response) => self.on_remote_changes_response(who, response), - GenericMessage::FinalityProofRequest(request) => self.on_finality_proof_request(who, request), - GenericMessage::FinalityProofResponse(response) => return self.on_finality_proof_response(who, response), + GenericMessage::Transactions(m) => + self.on_extrinsics(network_out, transaction_pool, who, m), + GenericMessage::RemoteCallRequest(request) => self.on_remote_call_request(network_out, who, request), + GenericMessage::RemoteCallResponse(response) => + self.on_remote_call_response(network_out, who, response), + GenericMessage::RemoteReadRequest(request) => + self.on_remote_read_request(network_out, who, request), + GenericMessage::RemoteReadResponse(response) => + self.on_remote_read_response(network_out, who, response), + GenericMessage::RemoteHeaderRequest(request) => + self.on_remote_header_request(network_out, who, request), + GenericMessage::RemoteHeaderResponse(response) => + self.on_remote_header_response(network_out, who, response), + GenericMessage::RemoteChangesRequest(request) => + self.on_remote_changes_request(network_out, who, request), + GenericMessage::RemoteChangesResponse(response) => + self.on_remote_changes_response(network_out, who, response), + GenericMessage::FinalityProofRequest(request) => + self.on_finality_proof_request(network_out, who, request, finality_proof_provider), + GenericMessage::FinalityProofResponse(response) => + return self.on_finality_proof_response(network_out, who, response), GenericMessage::Consensus(msg) => { if self.context_data.peers.get(&who).map_or(false, |peer| peer.info.protocol_version > 2) { self.consensus_gossip.on_incoming( - &mut ProtocolContext::new(&mut self.context_data, &self.network_chan), + &mut ProtocolContext::new(&mut self.context_data, network_out), who, msg, ); } } other => self.specialization.on_message( - &mut ProtocolContext::new(&mut self.context_data, &self.network_chan), + &mut ProtocolContext::new(&mut self.context_data, network_out), who, &mut Some(other), ), @@ -405,36 +569,43 @@ impl, H: ExHashT> Protocol { CustomMessageOutcome::None } - fn send_message(&mut self, who: PeerId, message: Message) { + fn send_message(&mut self, network_out: &mut dyn NetworkOut, who: PeerId, message: Message) { send_message::( &mut self.context_data.peers, - &self.network_chan, + network_out, who, message, ); } /// Locks `self` and returns a context plus the `ConsensusGossip` struct. - pub fn consensus_gossip_lock<'a>(&'a mut self) -> (impl Context + 'a, &'a mut ConsensusGossip) { - let context = ProtocolContext::new(&mut self.context_data, &self.network_chan); + pub fn consensus_gossip_lock<'a>( + &'a mut self, + network_out: &'a mut dyn NetworkOut + ) -> (impl Context + 'a, &'a mut ConsensusGossip) { + let context = ProtocolContext::new(&mut self.context_data, network_out); (context, &mut self.consensus_gossip) } /// Locks `self` and returns a context plus the network specialization. - pub fn specialization_lock<'a>(&'a mut self) -> (impl Context + 'a, &'a mut S) { - let context = ProtocolContext::new(&mut self.context_data, &self.network_chan); + pub fn specialization_lock<'a>( + &'a mut self, + network_out: &'a mut dyn NetworkOut + ) -> (impl Context + 'a, &'a mut S) { + let context = ProtocolContext::new(&mut self.context_data, network_out); (context, &mut self.specialization) } /// Gossip a consensus message to the network. pub fn gossip_consensus_message( &mut self, + network_out: &mut dyn NetworkOut, topic: B::Hash, engine_id: ConsensusEngineId, message: Vec, recipient: GossipMessageRecipient, ) { - let mut context = ProtocolContext::new(&mut self.context_data, &self.network_chan); + let mut context = ProtocolContext::new(&mut self.context_data, network_out); let message = ConsensusMessage { data: message, engine_id }; match recipient { GossipMessageRecipient::BroadcastToAll => @@ -442,41 +613,40 @@ impl, H: ExHashT> Protocol { GossipMessageRecipient::BroadcastNew => self.consensus_gossip.multicast(&mut context, topic, message, false), GossipMessageRecipient::Peer(who) => - self.send_message(who, GenericMessage::Consensus(message)), + self.send_message(network_out, who, GenericMessage::Consensus(message)), } } /// Called when a new peer is connected - pub fn on_peer_connected(&mut self, who: PeerId, debug_info: String) { + pub fn on_peer_connected(&mut self, network_out: &mut dyn NetworkOut, who: PeerId, debug_info: String) { trace!(target: "sync", "Connecting {}: {}", who, debug_info); self.handshaking_peers.insert(who.clone(), HandshakingPeer { timestamp: time::Instant::now() }); - self.send_status(who); + self.send_status(network_out, who); } /// Called by peer when it is disconnecting - pub fn on_peer_disconnected(&mut self, peer: PeerId, debug_info: String) { + pub fn on_peer_disconnected(&mut self, mut network_out: &mut dyn NetworkOut, peer: PeerId, debug_info: String) { trace!(target: "sync", "Disconnecting {}: {}", peer, debug_info); // lock all the the peer lists so that add/remove peer events are in order let removed = { self.handshaking_peers.remove(&peer); - self.connected_peers.write().remove(&peer); self.context_data.peers.remove(&peer) }; if let Some(peer_data) = removed { - let mut context = ProtocolContext::new(&mut self.context_data, &self.network_chan); + let mut context = ProtocolContext::new(&mut self.context_data, network_out); if peer_data.info.protocol_version > 2 { self.consensus_gossip.peer_disconnected(&mut context, peer.clone()); } self.sync.peer_disconnected(&mut context, peer.clone()); self.specialization.on_disconnect(&mut context, peer.clone()); - self.on_demand.as_ref().map(|s| s.on_disconnect(peer)); + self.on_demand_core.on_disconnect(&mut network_out, peer); } } /// Called as a back-pressure mechanism if the networking detects that the peer cannot process /// our messaging rate fast enough. - pub fn on_clogged_peer(&self, who: PeerId, _msg: Option>) { - self.network_chan.send(NetworkMsg::ReportPeer(who.clone(), CLOGGED_PEER_REPUTATION_CHANGE)); + pub fn on_clogged_peer(&self, network_out: &mut dyn NetworkOut, who: PeerId, _msg: Option>) { + network_out.report_peer(who.clone(), CLOGGED_PEER_REPUTATION_CHANGE); // Print some diagnostics. if let Some(peer) = self.context_data.peers.get(&who) { @@ -489,13 +659,12 @@ impl, H: ExHashT> Protocol { } } - /// Puts the `Synchronized` message on `network_chan`. - #[cfg(any(test, feature = "test-helpers"))] - pub fn synchronize(&self) { - self.network_chan.send(NetworkMsg::Synchronized); - } - - fn on_block_request(&mut self, peer: PeerId, request: message::BlockRequest) { + fn on_block_request( + &mut self, + network_out: &mut dyn NetworkOut, + peer: PeerId, + request: message::BlockRequest + ) { trace!(target: "sync", "BlockRequest {} from {}: from {:?} to {:?} max {:?}", request.id, peer, @@ -506,8 +675,8 @@ impl, H: ExHashT> Protocol { // sending block requests to the node that is unable to serve it is considered a bad behavior if !self.config.roles.is_full() { trace!(target: "sync", "Peer {} is trying to sync from the light node", peer); - self.network_chan.send(NetworkMsg::DisconnectPeer(peer.clone())); - self.network_chan.send(NetworkMsg::ReportPeer(peer, i32::min_value())); + network_out.disconnect_peer(peer.clone()); + network_out.report_peer(peer, i32::min_value()); return; } @@ -551,9 +720,9 @@ impl, H: ExHashT> Protocol { }; blocks.push(block_data); match request.direction { - message::Direction::Ascending => id = BlockId::Number(number + As::sa(1)), + message::Direction::Ascending => id = BlockId::Number(number + One::one()), message::Direction::Descending => { - if number == As::sa(0) { + if number.is_zero() { break; } id = BlockId::Hash(parent_hash) @@ -565,11 +734,12 @@ impl, H: ExHashT> Protocol { blocks: blocks, }; trace!(target: "sync", "Sending BlockResponse with {} blocks", response.blocks.len()); - self.send_message(peer, GenericMessage::BlockResponse(response)) + self.send_message(network_out, peer, GenericMessage::BlockResponse(response)) } fn on_block_response( &mut self, + network_out: &mut dyn NetworkOut, peer: PeerId, request: message::BlockRequest, response: message::BlockResponse, @@ -593,7 +763,7 @@ impl, H: ExHashT> Protocol { // justifications are imported asynchronously (#1482) if request.fields == message::BlockAttributes::JUSTIFICATION { let outcome = self.sync.on_block_justification_data( - &mut ProtocolContext::new(&mut self.context_data, &self.network_chan), + &mut ProtocolContext::new(&mut self.context_data, network_out), peer, request, response, @@ -607,7 +777,7 @@ impl, H: ExHashT> Protocol { } else { let outcome = self.sync.on_block_data( - &mut ProtocolContext::new(&mut self.context_data, &self.network_chan), + &mut ProtocolContext::new(&mut self.context_data, network_out), peer, request, response @@ -623,16 +793,14 @@ impl, H: ExHashT> Protocol { /// Perform time based maintenance. /// /// > **Note**: This method normally doesn't have to be called except for testing purposes. - pub fn tick(&mut self) { - self.consensus_gossip.tick(&mut ProtocolContext::new(&mut self.context_data, &self.network_chan)); - self.maintain_peers(); - self.sync.tick(&mut ProtocolContext::new(&mut self.context_data, &self.network_chan)); - self.on_demand - .as_ref() - .map(|s| s.maintain_peers()); + pub fn tick(&mut self, mut network_out: &mut dyn NetworkOut) { + self.consensus_gossip.tick(&mut ProtocolContext::new(&mut self.context_data, network_out)); + self.maintain_peers(network_out); + self.sync.tick(&mut ProtocolContext::new(&mut self.context_data, network_out)); + self.on_demand_core.maintain_peers(&mut network_out); } - fn maintain_peers(&mut self) { + fn maintain_peers(&mut self, network_out: &mut dyn NetworkOut) { let tick = time::Instant::now(); let mut aborting = Vec::new(); { @@ -653,20 +821,20 @@ impl, H: ExHashT> Protocol { } } - self.specialization.maintain_peers(&mut ProtocolContext::new(&mut self.context_data, &self.network_chan)); + self.specialization.maintain_peers(&mut ProtocolContext::new(&mut self.context_data, network_out)); for p in aborting { - let _ = self.network_chan.send(NetworkMsg::DisconnectPeer(p.clone())); - let _ = self.network_chan.send(NetworkMsg::ReportPeer(p, TIMEOUT_REPUTATION_CHANGE)); + network_out.disconnect_peer(p.clone()); + network_out.report_peer(p, TIMEOUT_REPUTATION_CHANGE); } } /// Called by peer to report status - fn on_status_message(&mut self, who: PeerId, status: message::Status) { + fn on_status_message(&mut self, mut network_out: &mut dyn NetworkOut, who: PeerId, status: message::Status) { trace!(target: "sync", "New peer {} {:?}", who, status); let protocol_version = { if self.context_data.peers.contains_key(&who) { debug!("Unexpected status packet from {}", who); - self.network_chan.send(NetworkMsg::ReportPeer(who, UNEXPECTED_STATUS_REPUTATION_CHANGE)); + network_out.report_peer(who, UNEXPECTED_STATUS_REPUTATION_CHANGE); return; } if status.genesis_hash != self.genesis_hash { @@ -675,34 +843,40 @@ impl, H: ExHashT> Protocol { "Peer is on different chain (our genesis: {} theirs: {})", self.genesis_hash, status.genesis_hash ); - self.network_chan.send(NetworkMsg::ReportPeer(who.clone(), i32::min_value())); - self.network_chan.send(NetworkMsg::DisconnectPeer(who)); + network_out.report_peer(who.clone(), i32::min_value()); + network_out.disconnect_peer(who); return; } if status.version < MIN_VERSION && CURRENT_VERSION < status.min_supported_version { trace!(target: "protocol", "Peer {:?} using unsupported protocol version {}", who, status.version); - self.network_chan.send(NetworkMsg::ReportPeer(who.clone(), i32::min_value())); - self.network_chan.send(NetworkMsg::DisconnectPeer(who)); + network_out.report_peer(who.clone(), i32::min_value()); + network_out.disconnect_peer(who); return; } + if self.config.roles.is_light() { + // we're not interested in light peers + if status.roles.is_light() { + debug!(target: "sync", "Peer {} is unable to serve light requests", who); + network_out.report_peer(who.clone(), i32::min_value()); + network_out.disconnect_peer(who); + return; + } + + // we don't interested in peers that are far behind us let self_best_block = self .context_data .chain .info() - .ok() - .and_then(|info| info.best_queued_number) - .unwrap_or_else(|| Zero::zero()); + .chain.best_number; let blocks_difference = self_best_block - .as_() - .checked_sub(status.best_number.as_()) - .unwrap_or(0); + .checked_sub(&status.best_number) + .unwrap_or_else(Zero::zero) + .saturated_into::(); if blocks_difference > LIGHT_MAXIMAL_BLOCKS_DIFFERENCE { debug!(target: "sync", "Peer {} is far behind us and will unable to serve light requests", who); - self.network_chan.send( - NetworkMsg::ReportPeer(who.clone(), PEER_BEHIND_US_LIGHT_REPUTATION_CHANGE) - ); - self.network_chan.send(NetworkMsg::DisconnectPeer(who)); + network_out.report_peer(who.clone(), PEER_BEHIND_US_LIGHT_REPUTATION_CHANGE); + network_out.disconnect_peer(who); return; } } @@ -711,16 +885,12 @@ impl, H: ExHashT> Protocol { let info = match self.handshaking_peers.remove(&who) { Some(_handshaking) => { - let peer_info = PeerInfo { + PeerInfo { protocol_version: status.version, roles: status.roles, best_hash: status.best_hash, best_number: status.best_number - }; - self.connected_peers - .write() - .insert(who.clone(), ConnectedPeer { peer_info: peer_info.clone() }); - peer_info + } }, None => { error!(target: "sync", "Received status from previously unconnected node {}", who); @@ -742,11 +912,10 @@ impl, H: ExHashT> Protocol { status.version }; - let mut context = ProtocolContext::new(&mut self.context_data, &self.network_chan); - self.on_demand - .as_ref() - .map(|s| s.on_connect(who.clone(), status.roles, status.best_number)); - self.sync.new_peer(&mut context, who.clone()); + let info = self.context_data.peers.get(&who).expect("We just inserted above; QED").info.clone(); + self.on_demand_core.on_connect(&mut network_out, who.clone(), status.roles, status.best_number); + let mut context = ProtocolContext::new(&mut self.context_data, network_out); + self.sync.new_peer(&mut context, who.clone(), info); if protocol_version > 2 { self.consensus_gossip.new_peer(&mut context, who.clone(), status.roles); } @@ -754,7 +923,13 @@ impl, H: ExHashT> Protocol { } /// Called when peer sends us new extrinsics - fn on_extrinsics(&mut self, who: PeerId, extrinsics: message::Transactions) { + fn on_extrinsics( + &mut self, + network_out: &mut dyn NetworkOut, + transaction_pool: &(impl TransactionPool + ?Sized), + who: PeerId, + extrinsics: message::Transactions + ) { // Accept extrinsics only when fully synced if self.sync.status().state != SyncState::Idle { trace!(target: "sync", "{} Ignoring extrinsics while syncing", who); @@ -763,8 +938,8 @@ impl, H: ExHashT> Protocol { trace!(target: "sync", "Received {} extrinsics from {}", extrinsics.len(), who); if let Some(ref mut peer) = self.context_data.peers.get_mut(&who) { for t in extrinsics { - if let Some(hash) = self.transaction_pool.import(&t) { - self.network_chan.send(NetworkMsg::ReportPeer(who.clone(), NEW_EXTRINSIC_REPUTATION_CHANGE)); + if let Some(hash) = transaction_pool.import(&t) { + network_out.report_peer(who.clone(), NEW_EXTRINSIC_REPUTATION_CHANGE); peer.known_extrinsics.insert(hash); } else { trace!(target: "sync", "Extrinsic rejected"); @@ -774,7 +949,11 @@ impl, H: ExHashT> Protocol { } /// Call when we must propagate ready extrinsics to peers. - pub fn propagate_extrinsics(&mut self) { + pub fn propagate_extrinsics( + &mut self, + network_out: &mut dyn NetworkOut, + transaction_pool: &(impl TransactionPool + ?Sized) + ) { debug!(target: "sync", "Propagating extrinsics"); // Accept transactions only when fully synced @@ -782,7 +961,7 @@ impl, H: ExHashT> Protocol { return; } - let extrinsics = self.transaction_pool.transactions(); + let extrinsics = transaction_pool.transactions(); let mut propagated_to = HashMap::new(); for (who, peer) in self.context_data.peers.iter_mut() { let (hashes, to_send): (Vec<_>, Vec<_>) = extrinsics @@ -799,17 +978,18 @@ impl, H: ExHashT> Protocol { .push(who.to_base58()); } trace!(target: "sync", "Sending {} transactions to {}", to_send.len(), who); - self.network_chan.send(NetworkMsg::Outgoing(who.clone(), GenericMessage::Transactions(to_send))) + network_out.send_message(who.clone(), GenericMessage::Transactions(to_send)) } } - self.transaction_pool.on_broadcasted(propagated_to); + + transaction_pool.on_broadcasted(propagated_to); } /// Make sure an important block is propagated to peers. /// /// In chain-based consensus, we often need to make sure non-best forks are /// at least temporarily synced. - pub fn announce_block(&mut self, hash: B::Hash) { + pub fn announce_block(&mut self, network_out: &mut dyn NetworkOut, hash: B::Hash) { let header = match self.context_data.chain.header(&BlockId::Hash(hash)) { Ok(Some(header)) => header, Ok(None) => { @@ -828,27 +1008,32 @@ impl, H: ExHashT> Protocol { for (who, ref mut peer) in self.context_data.peers.iter_mut() { trace!(target: "sync", "Reannouncing block {:?} to {}", hash, who); peer.known_blocks.insert(hash); - self.network_chan.send(NetworkMsg::Outgoing(who.clone(), message.clone())) + network_out.send_message(who.clone(), message.clone()) } } /// Send Status message - fn send_status(&mut self, who: PeerId) { - if let Ok(info) = self.context_data.chain.info() { - let status = message::generic::Status { - version: CURRENT_VERSION, - min_supported_version: MIN_VERSION, - genesis_hash: info.chain.genesis_hash, - roles: self.config.roles.into(), - best_number: info.chain.best_number, - best_hash: info.chain.best_hash, - chain_status: self.specialization.status(), - }; - self.send_message(who, GenericMessage::Status(status)) - } + fn send_status(&mut self, network_out: &mut dyn NetworkOut, who: PeerId) { + let info = self.context_data.chain.info(); + let status = message::generic::Status { + version: CURRENT_VERSION, + min_supported_version: MIN_VERSION, + genesis_hash: info.chain.genesis_hash, + roles: self.config.roles.into(), + best_number: info.chain.best_number, + best_hash: info.chain.best_hash, + chain_status: self.specialization.status(), + }; + + self.send_message(network_out, who, GenericMessage::Status(status)) } - fn on_block_announce(&mut self, who: PeerId, announce: message::BlockAnnounce) { + fn on_block_announce( + &mut self, + mut network_out: &mut dyn NetworkOut, + who: PeerId, + announce: message::BlockAnnounce + ) -> CustomMessageOutcome { let header = announce.header; let hash = header.hash(); { @@ -856,23 +1041,64 @@ impl, H: ExHashT> Protocol { peer.known_blocks.insert(hash.clone()); } } - self.on_demand - .as_ref() - .map(|s| s.on_block_announce(who.clone(), *header.number())); - self.sync.on_block_announce( - &mut ProtocolContext::new(&mut self.context_data, &self.network_chan), + self.on_demand_core.on_block_announce(&mut network_out, who.clone(), *header.number()); + let try_import = self.sync.on_block_announce( + &mut ProtocolContext::new(&mut self.context_data, network_out), who.clone(), hash, &header, ); + + // try_import is only true when we have all data required to import block + // in the BlockAnnounce message. This is only when: + // 1) we're on light client; + // AND + // - EITHER 2.1) announced block is stale; + // - OR 2.2) announced block is NEW and we normally only want to download this single block (i.e. + // there are no ascendants of this block scheduled for retrieval) + if !try_import { + return CustomMessageOutcome::None; + } + + // to import header from announced block let's construct response to request that normally would have + // been sent over network (but it is not in our case) + let blocks_to_import = self.sync.on_block_data( + &mut ProtocolContext::new(&mut self.context_data, network_out), + who.clone(), + message::generic::BlockRequest { + id: 0, + fields: BlockAttributes::HEADER, + from: message::FromBlock::Hash(hash), + to: None, + direction: message::Direction::Ascending, + max: Some(1), + }, + message::generic::BlockResponse { + id: 0, + blocks: vec![ + message::generic::BlockData { + hash: hash, + header: Some(header), + body: None, + receipt: None, + message_queue: None, + justification: None, + }, + ], + }, + ); + match blocks_to_import { + Some((origin, blocks)) => CustomMessageOutcome::BlockImport(origin, blocks), + None => CustomMessageOutcome::None, + } } /// Call this when a block has been imported in the import queue and we should announce it on /// the network. - pub fn on_block_imported(&mut self, hash: B::Hash, header: &B::Header) { + pub fn on_block_imported(&mut self, network_out: &mut dyn NetworkOut, hash: B::Hash, header: &B::Header) { self.sync.update_chain_info(header); self.specialization.on_block_imported( - &mut ProtocolContext::new(&mut self.context_data, &self.network_chan), + &mut ProtocolContext::new(&mut self.context_data, network_out), hash.clone(), header, ); @@ -889,23 +1115,24 @@ impl, H: ExHashT> Protocol { for (who, ref mut peer) in self.context_data.peers.iter_mut() { if peer.known_blocks.insert(hash.clone()) { trace!(target: "sync", "Announcing block {:?} to {}", hash, who); - self.network_chan.send(NetworkMsg::Outgoing(who.clone(), message.clone())) + network_out.send_message(who.clone(), message.clone()) } } } /// Call this when a block has been finalized. The sync layer may have some additional /// requesting to perform. - pub fn on_block_finalized(&mut self, hash: B::Hash, header: &B::Header) { + pub fn on_block_finalized(&mut self, network_out: &mut dyn NetworkOut, hash: B::Hash, header: &B::Header) { self.sync.on_block_finalized( &hash, *header.number(), - &mut ProtocolContext::new(&mut self.context_data, &self.network_chan), + &mut ProtocolContext::new(&mut self.context_data, network_out), ); } fn on_remote_call_request( &mut self, + network_out: &mut dyn NetworkOut, who: PeerId, request: message::RemoteCallRequest, ) { @@ -929,12 +1156,13 @@ impl, H: ExHashT> Protocol { request.block, error ); - self.network_chan.send(NetworkMsg::ReportPeer(who.clone(), RPC_FAILED_REPUTATION_CHANGE)); + network_out.report_peer(who.clone(), RPC_FAILED_REPUTATION_CHANGE); Default::default() } }; self.send_message( + network_out, who, GenericMessage::RemoteCallResponse(message::RemoteCallResponse { id: request.id, @@ -947,9 +1175,9 @@ impl, H: ExHashT> Protocol { /// /// Uses `protocol` to queue a new justification request and tries to dispatch all pending /// requests. - pub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor) { + pub fn request_justification(&mut self, network_out: &mut dyn NetworkOut, hash: &B::Hash, number: NumberFor) { let mut context = - ProtocolContext::new(&mut self.context_data, &self.network_chan); + ProtocolContext::new(&mut self.context_data, network_out); self.sync.request_justification(&hash, number, &mut context); } @@ -961,17 +1189,21 @@ impl, H: ExHashT> Protocol { /// A batch of blocks have been processed, with or without errors. /// Call this when a batch of blocks have been processed by the import queue, with or without /// errors. - pub fn blocks_processed(&mut self, processed_blocks: Vec, has_error: bool) { - self.sync.blocks_processed(processed_blocks, has_error); - let mut context = - ProtocolContext::new(&mut self.context_data, &self.network_chan); - self.sync.maintain_sync(&mut context); + pub fn blocks_processed( + &mut self, + network_out: &mut dyn NetworkOut, + processed_blocks: Vec, + has_error: bool + ) { + let mut context = ProtocolContext::new(&mut self.context_data, network_out); + self.sync.blocks_processed(&mut context, processed_blocks, has_error); } /// Restart the sync process. - pub fn restart(&mut self) { - let mut context = ProtocolContext::new(&mut self.context_data, &self.network_chan); - self.sync.restart(&mut context); + pub fn restart(&mut self, network_out: &mut dyn NetworkOut) { + let peers = self.context_data.peers.clone(); + let mut context = ProtocolContext::new(&mut self.context_data, network_out); + self.sync.restart(&mut context, |peer_id| peers.get(peer_id).map(|i| i.info.clone())); } /// Notify about successful import of the given block. @@ -992,8 +1224,13 @@ impl, H: ExHashT> Protocol { /// Request a finality proof for the given block. /// /// Queues a new finality proof request and tries to dispatch all pending requests. - pub fn request_finality_proof(&mut self, hash: &B::Hash, number: NumberFor) { - let mut context = ProtocolContext::new(&mut self.context_data, &self.network_chan); + pub fn request_finality_proof( + &mut self, + network_out: &mut dyn NetworkOut, + hash: &B::Hash, + number: NumberFor + ) { + let mut context = ProtocolContext::new(&mut self.context_data, network_out); self.sync.request_finality_proof(&hash, number, &mut context); } @@ -1005,15 +1242,19 @@ impl, H: ExHashT> Protocol { self.sync.finality_proof_import_result(request_block, finalization_result) } - fn on_remote_call_response(&mut self, who: PeerId, response: message::RemoteCallResponse) { + fn on_remote_call_response( + &mut self, + mut network_out: &mut dyn NetworkOut, + who: PeerId, + response: message::RemoteCallResponse + ) { trace!(target: "sync", "Remote call response {} from {}", response.id, who); - self.on_demand - .as_ref() - .map(|s| s.on_remote_call_response(who, response)); + self.on_demand_core.on_remote_call_response(&mut network_out, who, response); } fn on_remote_read_request( &mut self, + network_out: &mut dyn NetworkOut, who: PeerId, request: message::RemoteReadRequest, ) { @@ -1033,6 +1274,7 @@ impl, H: ExHashT> Protocol { } }; self.send_message( + network_out, who, GenericMessage::RemoteReadResponse(message::RemoteReadResponse { id: request.id, @@ -1040,15 +1282,20 @@ impl, H: ExHashT> Protocol { }), ); } - fn on_remote_read_response(&mut self, who: PeerId, response: message::RemoteReadResponse) { + + fn on_remote_read_response( + &mut self, + mut network_out: &mut dyn NetworkOut, + who: PeerId, + response: message::RemoteReadResponse + ) { trace!(target: "sync", "Remote read response {} from {}", response.id, who); - self.on_demand - .as_ref() - .map(|s| s.on_remote_read_response(who, response)); + self.on_demand_core.on_remote_read_response(&mut network_out, who, response); } fn on_remote_header_request( &mut self, + network_out: &mut dyn NetworkOut, who: PeerId, request: message::RemoteHeaderRequest>, ) { @@ -1067,6 +1314,7 @@ impl, H: ExHashT> Protocol { } }; self.send_message( + network_out, who, GenericMessage::RemoteHeaderResponse(message::RemoteHeaderResponse { id: request.id, @@ -1078,17 +1326,17 @@ impl, H: ExHashT> Protocol { fn on_remote_header_response( &mut self, + mut network_out: &mut dyn NetworkOut, who: PeerId, response: message::RemoteHeaderResponse, ) { trace!(target: "sync", "Remote header proof response {} from {}", response.id, who); - self.on_demand - .as_ref() - .map(|s| s.on_remote_header_response(who, response)); + self.on_demand_core.on_remote_header_response(&mut network_out, who, response); } fn on_remote_changes_request( &mut self, + network_out: &mut dyn NetworkOut, who: PeerId, request: message::RemoteChangesRequest, ) { @@ -1126,6 +1374,7 @@ impl, H: ExHashT> Protocol { } }; self.send_message( + network_out, who, GenericMessage::RemoteChangesResponse(message::RemoteChangesResponse { id: request.id, @@ -1139,6 +1388,7 @@ impl, H: ExHashT> Protocol { fn on_remote_changes_response( &mut self, + mut network_out: &mut dyn NetworkOut, who: PeerId, response: message::RemoteChangesResponse, B::Hash>, ) { @@ -1147,18 +1397,18 @@ impl, H: ExHashT> Protocol { who, response.max ); - self.on_demand - .as_ref() - .map(|s| s.on_remote_changes_response(who, response)); + self.on_demand_core.on_remote_changes_response(&mut network_out, who, response); } fn on_finality_proof_request( &mut self, + network_out: &mut dyn NetworkOut, who: PeerId, request: message::FinalityProofRequest, + finality_proof_provider: Option<&dyn FinalityProofProvider> ) { trace!(target: "sync", "Finality proof request from {} for {}", who, request.block); - let finality_proof = self.context_data.finality_proof_provider.as_ref() + let finality_proof = finality_proof_provider.as_ref() .ok_or_else(|| String::from("Finality provider is not configured")) .and_then(|provider| provider.prove_finality(request.block, &request.request).map_err(|e| e.to_string()) @@ -1175,6 +1425,7 @@ impl, H: ExHashT> Protocol { }, }; self.send_message( + network_out, who, GenericMessage::FinalityProofResponse(message::FinalityProofResponse { id: 0, @@ -1186,12 +1437,13 @@ impl, H: ExHashT> Protocol { fn on_finality_proof_response( &mut self, + network_out: &mut dyn NetworkOut, who: PeerId, response: message::FinalityProofResponse, ) -> CustomMessageOutcome { trace!(target: "sync", "Finality proof response from {} for {}", who, response.block); let outcome = self.sync.on_block_finality_proof_data( - &mut ProtocolContext::new(&mut self.context_data, &self.network_chan), + &mut ProtocolContext::new(&mut self.context_data, network_out), who, response, ); @@ -1202,6 +1454,15 @@ impl, H: ExHashT> Protocol { CustomMessageOutcome::None } } + + fn on_remote_body_response( + &mut self, + mut network_out: &mut dyn NetworkOut, + peer: PeerId, + response: message::BlockResponse + ) { + self.on_demand_core.on_remote_body_response(&mut network_out, peer, response); + } } /// Outcome of an incoming custom message. @@ -1215,7 +1476,7 @@ pub enum CustomMessageOutcome { fn send_message( peers: &mut HashMap>, - network_chan: &NetworkChan, + network_out: &mut dyn NetworkOut, who: PeerId, mut message: Message, ) { @@ -1230,5 +1491,5 @@ fn send_message( peer.block_request = Some((time::Instant::now(), r.clone())); } } - network_chan.send(NetworkMsg::Outgoing(who, message)); + network_out.send_message(who, message); } diff --git a/core/network/src/consensus_gossip.rs b/core/network/src/protocol/consensus_gossip.rs similarity index 87% rename from core/network/src/consensus_gossip.rs rename to core/network/src/protocol/consensus_gossip.rs index c7747a91014a8e75c0b9b7d29f1d871aadb5494e..5de6fb26024738cf5bdcfdc2d8e6e6a33253a577 100644 --- a/core/network/src/consensus_gossip.rs +++ b/core/network/src/protocol/consensus_gossip.rs @@ -110,7 +110,7 @@ pub trait ValidatorContext { struct NetworkContext<'g, 'p, B: BlockT> { gossip: &'g mut ConsensusGossip, - protocol: &'p mut Context, + protocol: &'p mut dyn Context, engine_id: ConsensusEngineId, } @@ -145,11 +145,11 @@ impl<'g, 'p, B: BlockT> ValidatorContext for NetworkContext<'g, 'p, B> { } fn propagate<'a, B: BlockT, I>( - protocol: &mut Context, + protocol: &mut dyn Context, messages: I, intent: MessageIntent, peers: &mut HashMap>, - validators: &HashMap>>, + validators: &HashMap>>, ) where I: IntoIterator, // (msg_hash, topic, message) { @@ -200,23 +200,28 @@ fn propagate<'a, B: BlockT, I>( /// Validates consensus messages. pub trait Validator: Send + Sync { /// New peer is connected. - fn new_peer(&self, _context: &mut ValidatorContext, _who: &PeerId, _roles: Roles) { + fn new_peer(&self, _context: &mut dyn ValidatorContext, _who: &PeerId, _roles: Roles) { } /// New connection is dropped. - fn peer_disconnected(&self, _context: &mut ValidatorContext, _who: &PeerId) { + fn peer_disconnected(&self, _context: &mut dyn ValidatorContext, _who: &PeerId) { } /// Validate consensus message. - fn validate(&self, context: &mut ValidatorContext, sender: &PeerId, data: &[u8]) -> ValidationResult; + fn validate( + &self, + context: &mut dyn ValidatorContext, + sender: &PeerId, + data: &[u8] + ) -> ValidationResult; /// Produce a closure for validating messages on a given topic. - fn message_expired<'a>(&'a self) -> Box bool + 'a> { + fn message_expired<'a>(&'a self) -> Box bool + 'a> { Box::new(move |_topic, _data| false) } /// Produce a closure for filtering egress messages. - fn message_allowed<'a>(&'a self) -> Box bool + 'a> { + fn message_allowed<'a>(&'a self) -> Box bool + 'a> { Box::new(move |_who, _intent, _topic, _data| true) } } @@ -227,7 +232,7 @@ pub struct ConsensusGossip { live_message_sinks: HashMap<(ConsensusEngineId, B::Hash), Vec>>, messages: Vec>, known_messages: LruCache, - validators: HashMap>>, + validators: HashMap>>, next_broadcast: time::Instant, } @@ -250,7 +255,12 @@ impl ConsensusGossip { } /// Register message validator for a message type. - pub fn register_validator(&mut self, protocol: &mut Context, engine_id: ConsensusEngineId, validator: Arc>) { + pub fn register_validator( + &mut self, + protocol: &mut dyn Context, + engine_id: ConsensusEngineId, + validator: Arc> + ) { self.register_validator_internal(engine_id, validator.clone()); let peers: Vec<_> = self.peers.iter().map(|(id, peer)| (id.clone(), peer.roles)).collect(); for (id, roles) in peers { @@ -259,12 +269,12 @@ impl ConsensusGossip { } } - fn register_validator_internal(&mut self, engine_id: ConsensusEngineId, validator: Arc>) { + fn register_validator_internal(&mut self, engine_id: ConsensusEngineId, validator: Arc>) { self.validators.insert(engine_id, validator.clone()); } /// Handle new connected peer. - pub fn new_peer(&mut self, protocol: &mut Context, who: PeerId, roles: Roles) { + pub fn new_peer(&mut self, protocol: &mut dyn Context, who: PeerId, roles: Roles) { // light nodes are not valid targets for consensus gossip messages if !roles.is_full() { return; @@ -281,7 +291,7 @@ impl ConsensusGossip { } } - fn register_message( + fn register_message_hashed( &mut self, message_hash: B::Hash, topic: B::Hash, @@ -296,8 +306,22 @@ impl ConsensusGossip { } } + /// Registers a message without propagating it to any peers. The message + /// becomes available to new peers or when the service is asked to gossip + /// the message's topic. No validation is performed on the message, if the + /// message is already expired it should be dropped on the next garbage + /// collection. + pub fn register_message( + &mut self, + topic: B::Hash, + message: ConsensusMessage, + ) { + let message_hash = HashFor::::hash(&message.data[..]); + self.register_message_hashed(message_hash, topic, message); + } + /// Call when a peer has been disconnected to stop tracking gossip status. - pub fn peer_disconnected(&mut self, protocol: &mut Context, who: PeerId) { + pub fn peer_disconnected(&mut self, protocol: &mut dyn Context, who: PeerId) { for (engine_id, v) in self.validators.clone() { let mut context = NetworkContext { gossip: self, protocol, engine_id: engine_id.clone() }; v.peer_disconnected(&mut context, &who); @@ -305,7 +329,7 @@ impl ConsensusGossip { } /// Perform periodic maintenance - pub fn tick(&mut self, protocol: &mut Context) { + pub fn tick(&mut self, protocol: &mut dyn Context) { self.collect_garbage(); if time::Instant::now() >= self.next_broadcast { self.rebroadcast(protocol); @@ -314,14 +338,14 @@ impl ConsensusGossip { } /// Rebroadcast all messages to all peers. - fn rebroadcast(&mut self, protocol: &mut Context) { + fn rebroadcast(&mut self, protocol: &mut dyn Context) { let messages = self.messages.iter() .map(|entry| (&entry.message_hash, &entry.topic, &entry.message)); propagate(protocol, messages, MessageIntent::PeriodicRebroadcast, &mut self.peers, &self.validators); } /// Broadcast all messages with given topic. - pub fn broadcast_topic(&mut self, protocol: &mut Context, topic: B::Hash, force: bool) { + pub fn broadcast_topic(&mut self, protocol: &mut dyn Context, topic: B::Hash, force: bool) { let messages = self.messages.iter() .filter_map(|entry| if entry.topic == topic { Some((&entry.message_hash, &entry.topic, &entry.message)) } else { None } @@ -395,7 +419,7 @@ impl ConsensusGossip { /// in all other cases. pub fn on_incoming( &mut self, - protocol: &mut Context, + protocol: &mut dyn Context, who: PeerId, message: ConsensusMessage, ) { @@ -447,7 +471,7 @@ impl ConsensusGossip { } } if keep { - self.register_message(message_hash, topic, message); + self.register_message_hashed(message_hash, topic, message); } } else { trace!(target:"gossip", "Ignored statement from unregistered peer {}", who); @@ -459,7 +483,14 @@ impl ConsensusGossip { } /// Send all messages with given topic to a peer. - pub fn send_topic(&mut self, protocol: &mut Context, who: &PeerId, topic: B::Hash, engine_id: ConsensusEngineId, force: bool) { + pub fn send_topic( + &mut self, + protocol: &mut dyn Context, + who: &PeerId, + topic: B::Hash, + engine_id: ConsensusEngineId, + force: bool + ) { let validator = self.validators.get(&engine_id); let mut message_allowed = match validator { None => return, // treat all messages with no validator as not allowed @@ -489,13 +520,13 @@ impl ConsensusGossip { /// Multicast a message to all peers. pub fn multicast( &mut self, - protocol: &mut Context, + protocol: &mut dyn Context, topic: B::Hash, message: ConsensusMessage, force: bool, ) { let message_hash = HashFor::::hash(&message.data); - self.register_message(message_hash, topic, message.clone()); + self.register_message_hashed(message_hash, topic, message.clone()); let intent = if force { MessageIntent::ForcedBroadcast } else { MessageIntent::Broadcast }; propagate(protocol, iter::once((&message_hash, &topic, &message)), intent, &mut self.peers, &self.validators); } @@ -504,7 +535,7 @@ impl ConsensusGossip { /// later on. pub fn send_message( &mut self, - protocol: &mut Context, + protocol: &mut dyn Context, who: &PeerId, message: ConsensusMessage, ) { @@ -545,7 +576,12 @@ mod tests { struct AllowAll; impl Validator for AllowAll { - fn validate(&self, _context: &mut ValidatorContext, _sender: &PeerId, _data: &[u8]) -> ValidationResult { + fn validate( + &self, + _context: &mut dyn ValidatorContext, + _sender: &PeerId, + _data: &[u8], + ) -> ValidationResult { ValidationResult::ProcessAndKeep(H256::default()) } } @@ -554,7 +590,12 @@ mod tests { fn collects_garbage() { struct AllowOne; impl Validator for AllowOne { - fn validate(&self, _context: &mut ValidatorContext, _sender: &PeerId, data: &[u8]) -> ValidationResult { + fn validate( + &self, + _context: &mut dyn ValidatorContext, + _sender: &PeerId, + data: &[u8], + ) -> ValidationResult { if data[0] == 1 { ValidationResult::ProcessAndKeep(H256::default()) } else { @@ -562,7 +603,7 @@ mod tests { } } - fn message_expired<'a>(&'a self) -> Box bool + 'a> { + fn message_expired<'a>(&'a self) -> Box bool + 'a> { Box::new(move |_topic, data| data[0] != 1 ) } } @@ -604,11 +645,9 @@ mod tests { consensus.register_validator_internal([0, 0, 0, 0], Arc::new(AllowAll)); let message = ConsensusMessage { data: vec![4, 5, 6], engine_id: [0, 0, 0, 0] }; - - let message_hash = HashFor::::hash(&message.data); let topic = HashFor::::hash(&[1,2,3]); - consensus.register_message(message_hash, topic, message.clone()); + consensus.register_message(topic, message.clone()); let stream = consensus.messages_for([0, 0, 0, 0], topic); assert_eq!(stream.wait().next(), Some(Ok(TopicNotification { message: message.data, sender: None }))); @@ -622,8 +661,8 @@ mod tests { let msg_a = ConsensusMessage { data: vec![1, 2, 3], engine_id: [0, 0, 0, 0] }; let msg_b = ConsensusMessage { data: vec![4, 5, 6], engine_id: [0, 0, 0, 0] }; - consensus.register_message(HashFor::::hash(&msg_a.data), topic,msg_a); - consensus.register_message(HashFor::::hash(&msg_b.data), topic,msg_b); + consensus.register_message(topic, msg_a); + consensus.register_message(topic, msg_b); assert_eq!(consensus.messages.len(), 2); } @@ -634,11 +673,9 @@ mod tests { consensus.register_validator_internal([0, 0, 0, 0], Arc::new(AllowAll)); let message = ConsensusMessage { data: vec![4, 5, 6], engine_id: [0, 0, 0, 0] }; - - let message_hash = HashFor::::hash(&message.data); let topic = HashFor::::hash(&[1,2,3]); - consensus.register_message(message_hash, topic, message.clone()); + consensus.register_message(topic, message.clone()); let stream1 = consensus.messages_for([0, 0, 0, 0], topic); let stream2 = consensus.messages_for([0, 0, 0, 0], topic); @@ -656,8 +693,8 @@ mod tests { let msg_a = ConsensusMessage { data: vec![1, 2, 3], engine_id: [0, 0, 0, 0] }; let msg_b = ConsensusMessage { data: vec![4, 5, 6], engine_id: [0, 0, 0, 1] }; - consensus.register_message(HashFor::::hash(&msg_a.data), topic, msg_a); - consensus.register_message(HashFor::::hash(&msg_b.data), topic, msg_b); + consensus.register_message(topic, msg_a); + consensus.register_message(topic, msg_b); let mut stream = consensus.messages_for([0, 0, 0, 0], topic).wait(); diff --git a/core/network/src/message.rs b/core/network/src/protocol/message.rs similarity index 99% rename from core/network/src/message.rs rename to core/network/src/protocol/message.rs index 31667033890ddbeafcc7b6c98f9d3b1931e2ef6f..6a38c106b7342525f310adea514b7180a3d9ad01 100644 --- a/core/network/src/message.rs +++ b/core/network/src/protocol/message.rs @@ -205,7 +205,7 @@ pub mod generic { FinalityProofRequest(FinalityProofRequest), /// Finality proof reponse. FinalityProofResponse(FinalityProofResponse), - /// Chain-specific message + /// Chain-specific message. #[codec(index = "255")] ChainSpecific(Vec), } diff --git a/core/network/src/protocol/on_demand.rs b/core/network/src/protocol/on_demand.rs new file mode 100644 index 0000000000000000000000000000000000000000..90051e9cafb3e9b099ac3b2dadc069adfbc31ee2 --- /dev/null +++ b/core/network/src/protocol/on_demand.rs @@ -0,0 +1,1266 @@ +// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! On-demand requests service. + +use std::collections::{HashMap, VecDeque}; +use std::sync::Arc; +use std::time::{Instant, Duration}; +use log::{trace, info}; +use futures::sync::oneshot::{Sender as OneShotSender}; +use linked_hash_map::{Entry, LinkedHashMap}; +use client::error::Error as ClientError; +use client::light::fetcher::{FetchChecker, RemoteHeaderRequest, + RemoteCallRequest, RemoteReadRequest, RemoteChangesRequest, ChangesProof, + RemoteReadChildRequest, RemoteBodyRequest}; +use crate::message::{self, BlockAttributes, Direction, FromBlock, RequestId}; +use network_libp2p::PeerId; +use crate::config::Roles; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, NumberFor}; + +/// Remote request timeout. +const REQUEST_TIMEOUT: Duration = Duration::from_secs(15); +/// Default request retry count. +const RETRY_COUNT: usize = 1; +/// Reputation change for a peer when a request timed out. +const TIMEOUT_REPUTATION_CHANGE: i32 = -(1 << 8); + +/// Trait used by the `OnDemandCore` service to communicate messages back to the network. +pub trait OnDemandNetwork { + /// Adjusts the reputation of the given peer. + fn report_peer(&mut self, who: &PeerId, reputation_change: i32); + + /// Disconnect from the given peer. Used in case of misbehaviour. + fn disconnect_peer(&mut self, who: &PeerId); + + /// Send to `who` a request for a header. + fn send_header_request(&mut self, who: &PeerId, id: RequestId, block: <::Header as HeaderT>::Number); + + /// Send to `who` a read request. + fn send_read_request(&mut self, who: &PeerId, id: RequestId, block: ::Hash, key: Vec); + + /// Send to `who` a child read request. + fn send_read_child_request( + &mut self, + who: &PeerId, + id: RequestId, + block: ::Hash, + storage_key: Vec, + key: Vec + ); + + /// Send to `who` a call request. + fn send_call_request( + &mut self, + who: &PeerId, + id: RequestId, + block: ::Hash, + method: String, + data: Vec + ); + + /// Send to `who` a changes request. + fn send_changes_request( + &mut self, + who: &PeerId, + id: RequestId, + first: ::Hash, + last: ::Hash, + min: ::Hash, + max: ::Hash, + key: Vec + ); + + /// Send to `who` a body request. + fn send_body_request( + &mut self, + who: &PeerId, + id: RequestId, + fields: BlockAttributes, + from: FromBlock<::Hash, <::Header as HeaderT>::Number>, + to: Option, + direction: Direction, + max: Option + ); +} + +/// On-demand requests service. Dispatches requests to appropriate peers. +pub struct OnDemandCore { + checker: Arc>, + next_request_id: u64, + pending_requests: VecDeque>, + active_peers: LinkedHashMap>, + idle_peers: VecDeque, + best_blocks: HashMap>, +} + +struct Request { + id: u64, + timestamp: Instant, + retry_count: usize, + data: RequestData, +} + +/// One request for data made by the `Client`. +/// +/// Contains a `Sender` where to send the result. +pub(crate) enum RequestData { + RemoteBody(RemoteBodyRequest, OneShotSender, ClientError>>), + RemoteHeader(RemoteHeaderRequest, OneShotSender>), + RemoteRead(RemoteReadRequest, OneShotSender>, ClientError>>), + RemoteReadChild( + RemoteReadChildRequest, + OneShotSender>, ClientError>> + ), + RemoteCall(RemoteCallRequest, OneShotSender, ClientError>>), + RemoteChanges( + RemoteChangesRequest, + OneShotSender, u32)>, ClientError>> + ), +} + +enum Accept { + Ok, + CheckFailed(ClientError, RequestData), + Unexpected(RequestData), +} + +/// Dummy implementation of `FetchChecker` that always assumes that responses are bad. +/// +/// Considering that it is the responsibility of the client to build the fetcher, it can use this +/// implementation if it knows that it will never perform any request. +#[derive(Default, Clone)] +pub struct AlwaysBadChecker; + +impl FetchChecker for AlwaysBadChecker { + fn check_header_proof( + &self, + _request: &RemoteHeaderRequest, + _remote_header: Option, + _remote_proof: Vec> + ) -> Result { + Err(ClientError::Msg("AlwaysBadChecker".into())) + } + + fn check_read_proof( + &self, + _request: &RemoteReadRequest, + _remote_proof: Vec> + ) -> Result>, ClientError> { + Err(ClientError::Msg("AlwaysBadChecker".into())) + } + + fn check_read_child_proof( + &self, + _request: &RemoteReadChildRequest, + _remote_proof: Vec> + ) -> Result>, ClientError> { + Err(ClientError::Msg("AlwaysBadChecker".into())) + } + + fn check_execution_proof( + &self, + _request: &RemoteCallRequest, + _remote_proof: Vec> + ) -> Result, ClientError> { + Err(ClientError::Msg("AlwaysBadChecker".into())) + } + + fn check_changes_proof( + &self, + _request: &RemoteChangesRequest, + _remote_proof: ChangesProof + ) -> Result, u32)>, ClientError> { + Err(ClientError::Msg("AlwaysBadChecker".into())) + } + + fn check_body_proof( + &self, + _request: &RemoteBodyRequest, + _body: Vec + ) -> Result, ClientError> { + Err(ClientError::Msg("AlwaysBadChecker".into())) + } +} + +impl OnDemandCore where + B::Header: HeaderT, +{ + /// Creates new on-demand requests processer. + pub fn new(checker: Arc>) -> Self { + OnDemandCore { + checker, + next_request_id: 0, + pending_requests: VecDeque::new(), + active_peers: LinkedHashMap::new(), + idle_peers: VecDeque::new(), + best_blocks: HashMap::new(), + } + } + + /// Inserts a new request in the list of requests to execute. + pub(crate) fn add_request(&mut self, network: impl OnDemandNetwork, data: RequestData) { + self.insert(RETRY_COUNT, data); + self.dispatch(network); + } + + /// Inserts a new request in the list of requests to execute. + fn insert(&mut self, retry_count: usize, data: RequestData) { + let request_id = self.next_request_id; + self.next_request_id += 1; + + self.pending_requests.push_back(Request { + id: request_id, + timestamp: Instant::now(), + retry_count, + data, + }); + } + + /// Try to accept response from given peer. + fn accept_response( + &mut self, + rtype: &str, + mut network: impl OnDemandNetwork, + peer: PeerId, + request_id: u64, + try_accept: impl FnOnce(Request, &Arc>) -> Accept + ) { + let request = match self.remove(peer.clone(), request_id) { + Some(request) => request, + None => { + info!("Invalid remote {} response from peer {}", rtype, peer); + network.report_peer(&peer, i32::min_value()); + network.disconnect_peer(&peer); + self.remove_peer(peer); + return; + }, + }; + + let retry_count = request.retry_count; + let (retry_count, retry_request_data) = match try_accept(request, &self.checker) { + Accept::Ok => (retry_count, None), + Accept::CheckFailed(error, retry_request_data) => { + info!("Failed to check remote {} response from peer {}: {}", rtype, peer, error); + network.report_peer(&peer, i32::min_value()); + network.disconnect_peer(&peer); + self.remove_peer(peer); + + if retry_count > 0 { + (retry_count - 1, Some(retry_request_data)) + } else { + trace!(target: "sync", "Failed to get remote {} response for given number of retries", rtype); + retry_request_data.fail(ClientError::RemoteFetchFailed.into()); + (0, None) + } + }, + Accept::Unexpected(retry_request_data) => { + info!("Unexpected response to remote {} from peer", rtype); + network.report_peer(&peer, i32::min_value()); + network.disconnect_peer(&peer); + self.remove_peer(peer); + + (retry_count, Some(retry_request_data)) + }, + }; + + if let Some(request_data) = retry_request_data { + self.insert(retry_count, request_data); + } + + self.dispatch(network); + } + + pub fn on_connect( + &mut self, + network: impl OnDemandNetwork, + peer: PeerId, + role: Roles, + best_number: NumberFor + ) { + if !role.is_full() { + return; + } + + self.idle_peers.push_back(peer.clone()); + self.best_blocks.insert(peer, best_number); + + self.dispatch(network); + } + + pub fn on_block_announce(&mut self, network: impl OnDemandNetwork, peer: PeerId, best_number: NumberFor) { + self.best_blocks.insert(peer, best_number); + self.dispatch(network); + } + + pub fn on_disconnect(&mut self, network: impl OnDemandNetwork, peer: PeerId) { + self.remove_peer(peer); + self.dispatch(network); + } + + pub fn maintain_peers(&mut self, mut network: impl OnDemandNetwork) { + let now = Instant::now(); + + loop { + match self.active_peers.front() { + Some((_, request)) if now - request.timestamp >= REQUEST_TIMEOUT => (), + _ => break, + } + + let (bad_peer, request) = self.active_peers.pop_front().expect("front() is Some as checked above"); + self.pending_requests.push_front(request); + network.report_peer(&bad_peer, TIMEOUT_REPUTATION_CHANGE); + network.disconnect_peer(&bad_peer); + } + + self.dispatch(network); + } + + pub fn on_remote_header_response( + &mut self, + network: impl OnDemandNetwork, + peer: PeerId, + response: message::RemoteHeaderResponse + ) { + self.accept_response("header", network, peer, response.id, |request, checker| match request.data { + RequestData::RemoteHeader(request, sender) => match checker.check_header_proof( + &request, + response.header, + response.proof + ) { + Ok(response) => { + // we do not bother if receiver has been dropped already + let _ = sender.send(Ok(response)); + Accept::Ok + }, + Err(error) => Accept::CheckFailed(error, RequestData::RemoteHeader(request, sender)), + }, + data => Accept::Unexpected(data), + }) + } + + pub fn on_remote_read_response( + &mut self, + network: impl OnDemandNetwork, + peer: PeerId, + response: message::RemoteReadResponse + ) { + self.accept_response("read", network, peer, response.id, |request, checker| match request.data { + RequestData::RemoteRead(request, sender) => { + match checker.check_read_proof(&request, response.proof) { + Ok(response) => { + // we do not bother if receiver has been dropped already + let _ = sender.send(Ok(response)); + Accept::Ok + }, + Err(error) => Accept::CheckFailed( + error, + RequestData::RemoteRead(request, sender) + ), + }}, + RequestData::RemoteReadChild(request, sender) => { + match checker.check_read_child_proof(&request, response.proof) { + Ok(response) => { + // we do not bother if receiver has been dropped already + let _ = sender.send(Ok(response)); + Accept::Ok + }, + Err(error) => Accept::CheckFailed( + error, + RequestData::RemoteReadChild(request, sender) + ), + }}, + data => Accept::Unexpected(data), + }) + } + + pub fn on_remote_call_response( + &mut self, + network: impl OnDemandNetwork, + peer: PeerId, + response: message::RemoteCallResponse + ) { + self.accept_response("call", network, peer, response.id, |request, checker| match request.data { + RequestData::RemoteCall(request, sender) => match checker.check_execution_proof(&request, response.proof) { + Ok(response) => { + // we do not bother if receiver has been dropped already + let _ = sender.send(Ok(response)); + Accept::Ok + }, + Err(error) => Accept::CheckFailed(error, RequestData::RemoteCall(request, sender)), + }, + data => Accept::Unexpected(data), + }) + } + + pub fn on_remote_changes_response( + &mut self, + network: impl OnDemandNetwork, + peer: PeerId, + response: message::RemoteChangesResponse, B::Hash> + ) { + self.accept_response("changes", network, peer, response.id, |request, checker| match request.data { + RequestData::RemoteChanges(request, sender) => match checker.check_changes_proof( + &request, ChangesProof { + max_block: response.max, + proof: response.proof, + roots: response.roots.into_iter().collect(), + roots_proof: response.roots_proof, + }) { + Ok(response) => { + // we do not bother if receiver has been dropped already + let _ = sender.send(Ok(response)); + Accept::Ok + }, + Err(error) => Accept::CheckFailed(error, RequestData::RemoteChanges(request, sender)), + }, + data => Accept::Unexpected(data), + }) + } + + pub fn on_remote_body_response( + &mut self, + network: impl OnDemandNetwork, + peer: PeerId, + response: message::BlockResponse + ) { + self.accept_response("body", network, peer, response.id, |request, checker| match request.data { + RequestData::RemoteBody(request, sender) => { + let mut bodies: Vec<_> = response + .blocks + .into_iter() + .filter_map(|b| b.body) + .collect(); + + // Number of bodies are hardcoded to 1 for valid `RemoteBodyResponses` + if bodies.len() != 1 { + return Accept::CheckFailed( + "RemoteBodyResponse: invalid number of blocks".into(), + RequestData::RemoteBody(request, sender), + ) + } + let body = bodies.remove(0); + + match checker.check_body_proof(&request, body) { + Ok(body) => { + let _ = sender.send(Ok(body)); + Accept::Ok + } + Err(error) => Accept::CheckFailed(error, RequestData::RemoteBody(request, sender)), + } + } + other => Accept::Unexpected(other), + }) + } + + pub fn is_on_demand_response(&self, peer: &PeerId, request_id: message::RequestId) -> bool { + self.active_peers.get(&peer).map_or(false, |r| r.id == request_id) + } + + fn remove(&mut self, peer: PeerId, id: u64) -> Option> { + match self.active_peers.entry(peer.clone()) { + Entry::Occupied(entry) => match entry.get().id == id { + true => { + self.idle_peers.push_back(peer); + Some(entry.remove()) + }, + false => None, + }, + Entry::Vacant(_) => None, + } + } + + pub fn remove_peer(&mut self, peer: PeerId) { + self.best_blocks.remove(&peer); + + if let Some(request) = self.active_peers.remove(&peer) { + self.pending_requests.push_front(request); + return; + } + + if let Some(idle_index) = self.idle_peers.iter().position(|i| *i == peer) { + self.idle_peers.swap_remove_back(idle_index); + } + } + + /// Dispatches pending requests. + fn dispatch(&mut self, mut network: impl OnDemandNetwork) { + let mut last_peer = self.idle_peers.back().cloned(); + let mut unhandled_requests = VecDeque::new(); + + loop { + let peer = match self.idle_peers.pop_front() { + Some(peer) => peer, + None => break, + }; + + // check if request can (optimistically) be processed by the peer + let can_be_processed_by_peer = { + let request = match self.pending_requests.front() { + Some(r) => r, + None => { + self.idle_peers.push_front(peer); + break; + }, + }; + let peer_best_block = self.best_blocks.get(&peer) + .expect("entries are inserted into best_blocks when peer is connected; + entries are removed from best_blocks when peer is disconnected; + peer is in idle_peers and thus connected; qed"); + request.required_block() <= *peer_best_block + }; + + if !can_be_processed_by_peer { + // return peer to the back of the queue + self.idle_peers.push_back(peer.clone()); + + // we have enumerated all peers and noone can handle request + if Some(peer) == last_peer { + let request = self.pending_requests.pop_front().expect("checked in loop condition; qed"); + unhandled_requests.push_back(request); + last_peer = self.idle_peers.back().cloned(); + } + + continue; + } + + last_peer = self.idle_peers.back().cloned(); + + let mut request = self.pending_requests.pop_front().expect("checked in loop condition; qed"); + request.timestamp = Instant::now(); + trace!(target: "sync", "Dispatching remote request {} to peer {}", request.id, peer); + request.send_to(&mut network, &peer); + self.active_peers.insert(peer, request); + } + + self.pending_requests.append(&mut unhandled_requests); + } +} + +impl Request { + fn required_block(&self) -> NumberFor { + match self.data { + RequestData::RemoteHeader(ref data, _) => data.block, + RequestData::RemoteRead(ref data, _) => *data.header.number(), + RequestData::RemoteReadChild(ref data, _) => *data.header.number(), + RequestData::RemoteCall(ref data, _) => *data.header.number(), + RequestData::RemoteChanges(ref data, _) => data.max_block.0, + RequestData::RemoteBody(ref data, _) => *data.header.number(), + } + } + + fn send_to(&self, out: &mut impl OnDemandNetwork, peer: &PeerId) { + match self.data { + RequestData::RemoteHeader(ref data, _) => + out.send_header_request( + peer, + self.id, + data.block, + ), + RequestData::RemoteRead(ref data, _) => + out.send_read_request( + peer, + self.id, + data.block, + data.key.clone(), + ), + RequestData::RemoteReadChild(ref data, _) => + out.send_read_child_request( + peer, + self.id, + data.block, + data.storage_key.clone(), + data.key.clone(), + ), + RequestData::RemoteCall(ref data, _) => + out.send_call_request( + peer, + self.id, + data.block, + data.method.clone(), + data.call_data.clone(), + ), + RequestData::RemoteChanges(ref data, _) => + out.send_changes_request( + peer, + self.id, + data.first_block.1.clone(), + data.last_block.1.clone(), + data.tries_roots.1.clone(), + data.max_block.1.clone(), + data.key.clone(), + ), + RequestData::RemoteBody(ref data, _) => + out.send_body_request( + peer, + self.id, + message::BlockAttributes::BODY, + message::FromBlock::Hash(data.header.hash()), + None, + message::Direction::Ascending, + Some(1) + ), + } + } +} + +impl RequestData { + fn fail(self, error: ClientError) { + // don't care if anyone is listening + match self { + RequestData::RemoteHeader(_, sender) => { let _ = sender.send(Err(error)); }, + RequestData::RemoteCall(_, sender) => { let _ = sender.send(Err(error)); }, + RequestData::RemoteRead(_, sender) => { let _ = sender.send(Err(error)); }, + RequestData::RemoteReadChild(_, sender) => { let _ = sender.send(Err(error)); }, + RequestData::RemoteChanges(_, sender) => { let _ = sender.send(Err(error)); }, + RequestData::RemoteBody(_, sender) => { let _ = sender.send(Err(error)); }, + } + } +} + +#[cfg(test)] +pub mod tests { + use std::collections::HashSet; + use std::sync::Arc; + use std::time::Instant; + use futures::{Future, sync::oneshot}; + use runtime_primitives::traits::{Block as BlockT, NumberFor, Header as HeaderT}; + use client::{error::{Error as ClientError, Result as ClientResult}}; + use client::light::fetcher::{FetchChecker, RemoteHeaderRequest, + ChangesProof, RemoteCallRequest, RemoteReadRequest, + RemoteReadChildRequest, RemoteChangesRequest, RemoteBodyRequest}; + use crate::config::Roles; + use crate::message::{self, BlockAttributes, Direction, FromBlock, RequestId}; + use network_libp2p::PeerId; + use super::{REQUEST_TIMEOUT, OnDemandCore, OnDemandNetwork, RequestData}; + use test_client::runtime::{changes_trie_config, Block, Extrinsic, Header}; + + struct DummyFetchChecker { ok: bool } + + impl FetchChecker for DummyFetchChecker { + fn check_header_proof( + &self, + _request: &RemoteHeaderRequest
, + header: Option
, + _remote_proof: Vec> + ) -> ClientResult
{ + match self.ok { + true if header.is_some() => Ok(header.unwrap()), + _ => Err(ClientError::Backend("Test error".into())), + } + } + + fn check_read_proof(&self, _: &RemoteReadRequest
, _: Vec>) -> ClientResult>> { + match self.ok { + true => Ok(Some(vec![42])), + false => Err(ClientError::Backend("Test error".into())), + } + } + + fn check_read_child_proof( + &self, + _: &RemoteReadChildRequest
, + _: Vec> + ) -> ClientResult>> { + match self.ok { + true => Ok(Some(vec![42])), + false => Err(ClientError::Backend("Test error".into())), + } + } + + fn check_execution_proof(&self, _: &RemoteCallRequest
, _: Vec>) -> ClientResult> { + match self.ok { + true => Ok(vec![42]), + false => Err(ClientError::Backend("Test error".into())), + } + } + + fn check_changes_proof( + &self, + _: &RemoteChangesRequest
, + _: ChangesProof
+ ) -> ClientResult, u32)>> { + match self.ok { + true => Ok(vec![(100, 2)]), + false => Err(ClientError::Backend("Test error".into())), + } + } + + fn check_body_proof( + &self, + _: &RemoteBodyRequest
, + body: Vec + ) -> ClientResult> { + match self.ok { + true => Ok(body), + false => Err(ClientError::Backend("Test error".into())), + } + } + } + + fn dummy(ok: bool) -> OnDemandCore { + OnDemandCore::new(Arc::new(DummyFetchChecker { ok })) + } + + fn total_peers(on_demand: &OnDemandCore) -> usize { + on_demand.idle_peers.len() + on_demand.active_peers.len() + } + + fn receive_call_response( + network_interface: impl OnDemandNetwork, + on_demand: &mut OnDemandCore, + peer: PeerId, + id: message::RequestId + ) { + on_demand.on_remote_call_response(network_interface, peer, message::RemoteCallResponse { + id: id, + proof: vec![vec![2]], + }); + } + + fn dummy_header() -> Header { + Header { + parent_hash: Default::default(), + number: 0, + state_root: Default::default(), + extrinsics_root: Default::default(), + digest: Default::default(), + } + } + + #[derive(Default)] + struct DummyNetwork { + disconnected_peers: HashSet, + } + + impl<'a, B: BlockT> OnDemandNetwork for &'a mut DummyNetwork { + fn report_peer(&mut self, _: &PeerId, _: i32) {} + fn disconnect_peer(&mut self, who: &PeerId) { + self.disconnected_peers.insert(who.clone()); + } + fn send_header_request(&mut self, _: &PeerId, _: RequestId, _: <::Header as HeaderT>::Number) {} + fn send_read_request(&mut self, _: &PeerId, _: RequestId, _: ::Hash, _: Vec) {} + fn send_read_child_request(&mut self, _: &PeerId, _: RequestId, _: ::Hash, _: Vec, + _: Vec) {} + fn send_call_request(&mut self, _: &PeerId, _: RequestId, _: ::Hash, _: String, _: Vec) {} + fn send_changes_request(&mut self, _: &PeerId, _: RequestId, _: ::Hash, _: ::Hash, + _: ::Hash, _: ::Hash, _: Vec) {} + fn send_body_request(&mut self, _: &PeerId, _: RequestId, _: BlockAttributes, _: FromBlock<::Hash, + <::Header as HeaderT>::Number>, _: Option, _: Direction, _: Option) {} + } + + fn assert_disconnected_peer(dummy: &DummyNetwork) { + assert_eq!(dummy.disconnected_peers.len(), 1); + } + + #[test] + fn knows_about_peers_roles() { + let mut network_interface = DummyNetwork::default(); + let mut on_demand = dummy(true); + let peer0 = PeerId::random(); + let peer1 = PeerId::random(); + let peer2 = PeerId::random(); + on_demand.on_connect(&mut network_interface, peer0, Roles::LIGHT, 1000); + on_demand.on_connect(&mut network_interface, peer1.clone(), Roles::FULL, 2000); + on_demand.on_connect(&mut network_interface, peer2.clone(), Roles::AUTHORITY, 3000); + assert_eq!(vec![peer1.clone(), peer2.clone()], on_demand.idle_peers.iter().cloned().collect::>()); + assert_eq!(on_demand.best_blocks.get(&peer1), Some(&2000)); + assert_eq!(on_demand.best_blocks.get(&peer2), Some(&3000)); + } + + #[test] + fn disconnects_from_idle_peer() { + let peer0 = PeerId::random(); + + let mut network_interface = DummyNetwork::default(); + let mut on_demand = dummy(true); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 100); + assert_eq!(1, total_peers(&on_demand)); + assert!(!on_demand.best_blocks.is_empty()); + + on_demand.on_disconnect(&mut network_interface, peer0); + assert_eq!(0, total_peers(&on_demand)); + assert!(on_demand.best_blocks.is_empty()); + } + + #[test] + fn disconnects_from_timeouted_peer() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer0 = PeerId::random(); + let peer1 = PeerId::random(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + on_demand.on_connect(&mut network_interface, peer1.clone(), Roles::FULL, 1000); + assert_eq!(vec![peer0.clone(), peer1.clone()], on_demand.idle_peers.iter().cloned().collect::>()); + assert!(on_demand.active_peers.is_empty()); + + on_demand.add_request(&mut network_interface, RequestData::RemoteCall(RemoteCallRequest { + block: Default::default(), + header: dummy_header(), + method: "test".into(), + call_data: vec![], + retry_count: None, + }, oneshot::channel().0)); + assert_eq!(vec![peer1.clone()], on_demand.idle_peers.iter().cloned().collect::>()); + assert_eq!(vec![peer0.clone()], on_demand.active_peers.keys().cloned().collect::>()); + + on_demand.active_peers[&peer0].timestamp = Instant::now() - REQUEST_TIMEOUT - REQUEST_TIMEOUT; + on_demand.maintain_peers(&mut network_interface); + assert!(on_demand.idle_peers.is_empty()); + assert_eq!(vec![peer1.clone()], on_demand.active_peers.keys().cloned().collect::>()); + assert_disconnected_peer(&network_interface); + } + + #[test] + fn disconnects_from_peer_on_response_with_wrong_id() { + let mut on_demand = dummy(true); + let peer0 = PeerId::random(); + let mut network_interface = DummyNetwork::default(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + + on_demand.add_request(&mut network_interface, RequestData::RemoteCall(RemoteCallRequest { + block: Default::default(), + header: dummy_header(), + method: "test".into(), + call_data: vec![], + retry_count: None, + }, oneshot::channel().0)); + receive_call_response(&mut network_interface, &mut on_demand, peer0, 1); + assert_disconnected_peer(&network_interface); + assert_eq!(on_demand.pending_requests.len(), 1); + } + + #[test] + fn disconnects_from_peer_on_incorrect_response() { + let mut on_demand = dummy(false); + let mut network_interface = DummyNetwork::default(); + let peer0 = PeerId::random(); + on_demand.add_request(&mut network_interface, RequestData::RemoteCall(RemoteCallRequest { + block: Default::default(), + header: dummy_header(), + method: "test".into(), + call_data: vec![], + retry_count: Some(1), + }, oneshot::channel().0)); + + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + receive_call_response(&mut network_interface, &mut on_demand, peer0.clone(), 0); + assert_disconnected_peer(&network_interface); + assert_eq!(on_demand.pending_requests.len(), 1); + } + + #[test] + fn disconnects_from_peer_on_unexpected_response() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer0 = PeerId::random(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + + receive_call_response(&mut network_interface, &mut on_demand, peer0, 0); + assert_disconnected_peer(&network_interface); + } + + #[test] + fn disconnects_from_peer_on_wrong_response_type() { + let mut on_demand = dummy(false); + let peer0 = PeerId::random(); + let mut network_interface = DummyNetwork::default(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + + on_demand.add_request(&mut network_interface, RequestData::RemoteCall(RemoteCallRequest { + block: Default::default(), + header: dummy_header(), + method: "test".into(), + call_data: vec![], + retry_count: Some(1), + }, oneshot::channel().0)); + + on_demand.on_remote_read_response(&mut network_interface, peer0.clone(), message::RemoteReadResponse { + id: 0, + proof: vec![vec![2]], + }); + assert_disconnected_peer(&network_interface); + assert_eq!(on_demand.pending_requests.len(), 1); + } + + #[test] + fn receives_remote_failure_after_retry_count_failures() { + use parking_lot::{Condvar, Mutex}; + + let retry_count = 2; + let peer_ids = (0 .. retry_count + 1).map(|_| PeerId::random()).collect::>(); + let mut on_demand = dummy(false); + let mut network_interface = DummyNetwork::default(); + for i in 0..retry_count+1 { + on_demand.on_connect(&mut network_interface, peer_ids[i].clone(), Roles::FULL, 1000); + } + + let sync = Arc::new((Mutex::new(0), Mutex::new(0), Condvar::new())); + let thread_sync = sync.clone(); + + let (tx, response) = oneshot::channel(); + on_demand.add_request(&mut network_interface, RequestData::RemoteCall(RemoteCallRequest { + block: Default::default(), + header: dummy_header(), + method: "test".into(), + call_data: vec![], + retry_count: Some(retry_count) + }, tx)); + let thread = ::std::thread::spawn(move || { + let &(ref current, ref finished_at, ref finished) = &*thread_sync; + let _ = response.wait().unwrap().unwrap_err(); + *finished_at.lock() = *current.lock(); + finished.notify_one(); + }); + + let &(ref current, ref finished_at, ref finished) = &*sync; + for i in 0..retry_count+1 { + let mut current = current.lock(); + *current = *current + 1; + receive_call_response(&mut network_interface, &mut on_demand, peer_ids[i].clone(), i as u64); + } + + let mut finished_at = finished_at.lock(); + assert!(!finished.wait_for(&mut finished_at, ::std::time::Duration::from_millis(1000)).timed_out()); + assert_eq!(*finished_at, retry_count + 1); + + thread.join().unwrap(); + } + + #[test] + fn receives_remote_call_response() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer0 = PeerId::random(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + + let (tx, response) = oneshot::channel(); + on_demand.add_request(&mut network_interface, RequestData::RemoteCall(RemoteCallRequest { + block: Default::default(), + header: dummy_header(), + method: "test".into(), + call_data: vec![], + retry_count: None, + }, tx)); + let thread = ::std::thread::spawn(move || { + let result = response.wait().unwrap().unwrap(); + assert_eq!(result, vec![42]); + }); + + receive_call_response(&mut network_interface, &mut on_demand, peer0.clone(), 0); + thread.join().unwrap(); + } + + #[test] + fn receives_remote_read_response() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer0 = PeerId::random(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + + let (tx, response) = oneshot::channel(); + on_demand.add_request(&mut network_interface, RequestData::RemoteRead(RemoteReadRequest { + header: dummy_header(), + block: Default::default(), + key: b":key".to_vec(), + retry_count: None, + }, tx)); + let thread = ::std::thread::spawn(move || { + let result = response.wait().unwrap().unwrap(); + assert_eq!(result, Some(vec![42])); + }); + + on_demand.on_remote_read_response(&mut network_interface, peer0.clone(), message::RemoteReadResponse { + id: 0, + proof: vec![vec![2]], + }); + thread.join().unwrap(); + } + + #[test] + fn receives_remote_read_child_response() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer0 = PeerId::random(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + + let (tx, response) = oneshot::channel(); + on_demand.add_request(&mut network_interface, RequestData::RemoteReadChild(RemoteReadChildRequest { + header: dummy_header(), + block: Default::default(), + storage_key: b":child_storage:sub".to_vec(), + key: b":key".to_vec(), + retry_count: None, + }, tx)); + let thread = ::std::thread::spawn(move || { + let result = response.wait().unwrap().unwrap(); + assert_eq!(result, Some(vec![42])); + }); + + on_demand.on_remote_read_response(&mut network_interface, + peer0.clone(), message::RemoteReadResponse { + id: 0, + proof: vec![vec![2]], + }); + thread.join().unwrap(); + } + + #[test] + fn receives_remote_header_response() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer0 = PeerId::random(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + + let (tx, response) = oneshot::channel(); + on_demand.add_request(&mut network_interface, RequestData::RemoteHeader(RemoteHeaderRequest { + cht_root: Default::default(), + block: 1, + retry_count: None, + }, tx)); + let thread = ::std::thread::spawn(move || { + let result = response.wait().unwrap().unwrap(); + assert_eq!( + result.hash(), + "6443a0b46e0412e626363028115a9f2c\ + f963eeed526b8b33e5316f08b50d0dc3".parse().unwrap() + ); + }); + + on_demand.on_remote_header_response(&mut network_interface, peer0.clone(), message::RemoteHeaderResponse { + id: 0, + header: Some(Header { + parent_hash: Default::default(), + number: 1, + state_root: Default::default(), + extrinsics_root: Default::default(), + digest: Default::default(), + }), + proof: vec![vec![2]], + }); + thread.join().unwrap(); + } + + #[test] + fn receives_remote_changes_response() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer0 = PeerId::random(); + on_demand.on_connect(&mut network_interface, peer0.clone(), Roles::FULL, 1000); + + let (tx, response) = oneshot::channel(); + on_demand.add_request(&mut network_interface, RequestData::RemoteChanges(RemoteChangesRequest { + changes_trie_config: changes_trie_config(), + first_block: (1, Default::default()), + last_block: (100, Default::default()), + max_block: (100, Default::default()), + tries_roots: (1, Default::default(), vec![]), + key: vec![], + retry_count: None, + }, tx)); + let thread = ::std::thread::spawn(move || { + let result = response.wait().unwrap().unwrap(); + assert_eq!(result, vec![(100, 2)]); + }); + + on_demand.on_remote_changes_response(&mut network_interface, peer0.clone(), message::RemoteChangesResponse { + id: 0, + max: 1000, + proof: vec![vec![2]], + roots: vec![], + roots_proof: vec![], + }); + thread.join().unwrap(); + } + + #[test] + fn does_not_sends_request_to_peer_who_has_no_required_block() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer1 = PeerId::random(); + let peer2 = PeerId::random(); + + on_demand.on_connect(&mut network_interface, peer1.clone(), Roles::FULL, 100); + + on_demand.add_request(&mut network_interface, RequestData::RemoteHeader(RemoteHeaderRequest { + cht_root: Default::default(), + block: 200, + retry_count: None, + }, oneshot::channel().0)); + on_demand.add_request(&mut network_interface, RequestData::RemoteHeader(RemoteHeaderRequest { + cht_root: Default::default(), + block: 250, + retry_count: None, + }, oneshot::channel().0)); + on_demand.add_request(&mut network_interface, RequestData::RemoteHeader(RemoteHeaderRequest { + cht_root: Default::default(), + block: 250, + retry_count: None, + }, oneshot::channel().0)); + + on_demand.on_connect(&mut network_interface, peer2.clone(), Roles::FULL, 150); + + assert_eq!(vec![peer1.clone(), peer2.clone()], on_demand.idle_peers.iter().cloned().collect::>()); + assert_eq!(on_demand.pending_requests.len(), 3); + + on_demand.on_block_announce(&mut network_interface, peer1.clone(), 250); + + assert_eq!(vec![peer2.clone()], on_demand.idle_peers.iter().cloned().collect::>()); + assert_eq!(on_demand.pending_requests.len(), 2); + + on_demand.on_block_announce(&mut network_interface, peer2.clone(), 250); + + assert!(!on_demand.idle_peers.iter().any(|_| true)); + assert_eq!(on_demand.pending_requests.len(), 1); + + on_demand.on_remote_header_response(&mut network_interface, peer1.clone(), message::RemoteHeaderResponse { + id: 0, + header: Some(dummy_header()), + proof: vec![], + }); + + assert!(!on_demand.idle_peers.iter().any(|_| true)); + assert_eq!(on_demand.pending_requests.len(), 0); + } + + #[test] + fn does_not_loop_forever_after_dispatching_request_to_last_peer() { + // this test is a regression for a bug where the dispatch function would + // loop forever after dispatching a request to the last peer, since the + // last peer was not updated + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer1 = PeerId::random(); + let peer2 = PeerId::random(); + let peer3 = PeerId::random(); + + on_demand.add_request(&mut network_interface, RequestData::RemoteHeader(RemoteHeaderRequest { + cht_root: Default::default(), + block: 250, + retry_count: None, + }, oneshot::channel().0)); + on_demand.add_request(&mut network_interface, RequestData::RemoteHeader(RemoteHeaderRequest { + cht_root: Default::default(), + block: 250, + retry_count: None, + }, oneshot::channel().0)); + + on_demand.on_connect(&mut network_interface, peer1.clone(), Roles::FULL, 200); + on_demand.on_connect(&mut network_interface, peer2.clone(), Roles::FULL, 200); + on_demand.on_connect(&mut network_interface, peer3.clone(), Roles::FULL, 250); + + assert_eq!(vec![peer1.clone(), peer2.clone()], on_demand.idle_peers.iter().cloned().collect::>()); + assert_eq!(on_demand.pending_requests.len(), 1); + } + + #[test] + fn tries_to_send_all_pending_requests() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer1 = PeerId::random(); + + on_demand.add_request(&mut network_interface, RequestData::RemoteHeader(RemoteHeaderRequest { + cht_root: Default::default(), + block: 300, + retry_count: None, + }, oneshot::channel().0)); + on_demand.add_request(&mut network_interface, RequestData::RemoteHeader(RemoteHeaderRequest { + cht_root: Default::default(), + block: 250, + retry_count: None, + }, oneshot::channel().0)); + + on_demand.on_connect(&mut network_interface, peer1.clone(), Roles::FULL, 250); + + assert!(on_demand.idle_peers.iter().cloned().collect::>().is_empty()); + assert_eq!(on_demand.pending_requests.len(), 1); + } + + #[test] + fn remote_body_with_one_block_body_should_succeed() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer1 = PeerId::random(); + + let header = dummy_header(); + on_demand.on_connect(&mut network_interface, peer1.clone(), Roles::FULL, 250); + + on_demand.add_request(&mut network_interface, RequestData::RemoteBody(RemoteBodyRequest { + header: header.clone(), + retry_count: None, + }, oneshot::channel().0)); + + assert!(on_demand.pending_requests.is_empty()); + assert_eq!(on_demand.active_peers.len(), 1); + + let block = message::BlockData:: { + hash: primitives::H256::random(), + header: None, + body: Some(Vec::new()), + message_queue: None, + receipt: None, + justification: None, + }; + + let response = message::generic::BlockResponse { + id: 0, + blocks: vec![block], + }; + + on_demand.on_remote_body_response(&mut network_interface, peer1.clone(), response); + + assert!(on_demand.active_peers.is_empty()); + assert_eq!(on_demand.idle_peers.len(), 1); + } + + #[test] + fn remote_body_with_three_bodies_should_fail() { + let mut on_demand = dummy(true); + let mut network_interface = DummyNetwork::default(); + let peer1 = PeerId::random(); + + let header = dummy_header(); + on_demand.on_connect(&mut network_interface, peer1.clone(), Roles::FULL, 250); + + on_demand.add_request(&mut network_interface, RequestData::RemoteBody(RemoteBodyRequest { + header: header.clone(), + retry_count: None, + }, oneshot::channel().0)); + + assert!(on_demand.pending_requests.is_empty()); + assert_eq!(on_demand.active_peers.len(), 1); + + let response = { + let blocks: Vec<_> = (0..3).map(|_| message::BlockData:: { + hash: primitives::H256::random(), + header: None, + body: Some(Vec::new()), + message_queue: None, + receipt: None, + justification: None, + }).collect(); + + message::generic::BlockResponse { + id: 0, + blocks, + } + }; + + on_demand.on_remote_body_response(&mut network_interface, peer1.clone(), response); + assert!(on_demand.active_peers.is_empty()); + assert!(on_demand.idle_peers.is_empty(), "peer should be disconnected after bad response"); + } +} diff --git a/core/network/src/specialization.rs b/core/network/src/protocol/specialization.rs similarity index 88% rename from core/network/src/specialization.rs rename to core/network/src/protocol/specialization.rs index 58a63bb7a3b53b7357399bab99880769ca28bdd9..e8a0a0c9491116ada17a7920fb53c1b90f797af1 100644 --- a/core/network/src/specialization.rs +++ b/core/network/src/protocol/specialization.rs @@ -26,23 +26,29 @@ pub trait NetworkSpecialization: Send + Sync + 'static { fn status(&self) -> Vec; /// Called when a peer successfully handshakes. - fn on_connect(&mut self, ctx: &mut Context, who: PeerId, status: crate::message::Status); + fn on_connect(&mut self, ctx: &mut dyn Context, who: PeerId, status: crate::message::Status); /// Called when a peer is disconnected. If the peer ID is unknown, it should be ignored. - fn on_disconnect(&mut self, ctx: &mut Context, who: PeerId); + fn on_disconnect(&mut self, ctx: &mut dyn Context, who: PeerId); /// Called when a network-specific message arrives. - fn on_message(&mut self, ctx: &mut Context, who: PeerId, message: &mut Option>); + fn on_message( + &mut self, + ctx: &mut dyn Context, + who: PeerId, + message: &mut Option> + ); /// Called on abort. + #[deprecated(note = "This method is never called; aborting corresponds to dropping the object")] fn on_abort(&mut self) { } /// Called periodically to maintain peers and handle timeouts. - fn maintain_peers(&mut self, _ctx: &mut Context) { } + fn maintain_peers(&mut self, _ctx: &mut dyn Context) { } /// Called when a block is _imported_ at the head of the chain (not during major sync). /// Not guaranteed to be called for every block, but will be most of the after major sync. - fn on_block_imported(&mut self, _ctx: &mut Context, _hash: B::Hash, _header: &B::Header) { } + fn on_block_imported(&mut self, _ctx: &mut dyn Context, _hash: B::Hash, _header: &B::Header) { } } /// Construct a simple protocol that is composed of several sub protocols. diff --git a/core/network/src/sync.rs b/core/network/src/protocol/sync.rs similarity index 60% rename from core/network/src/sync.rs rename to core/network/src/protocol/sync.rs index 73586722310ab40cb92f721c298f63ac5d851fca..4ec8f18e355b4d4bed05c3de7296e3334bfae94d 100644 --- a/core/network/src/sync.rs +++ b/core/network/src/protocol/sync.rs @@ -31,21 +31,26 @@ //! use std::cmp::max; +use std::ops::Range; use std::collections::{HashMap, VecDeque}; -use log::{debug, trace, warn, info}; +use log::{debug, trace, warn, info, error}; use crate::protocol::PeerInfo as ProtocolPeerInfo; use network_libp2p::PeerId; use client::{BlockStatus, ClientInfo}; use consensus::{BlockOrigin, import_queue::{IncomingBlock, SharedFinalityProofRequestBuilder}}; use client::error::Error as ClientError; -use crate::blocks::BlockCollection; -use crate::sync::extra_requests::ExtraRequestsAggregator; -use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, NumberFor, Zero, CheckedSub}; +use blocks::BlockCollection; +use extra_requests::ExtraRequestsAggregator; +use runtime_primitives::traits::{ + Block as BlockT, Header as HeaderT, NumberFor, Zero, One, + CheckedSub, SaturatedConversion +}; use runtime_primitives::{Justification, generic::BlockId}; use crate::message; use crate::config::Roles; use std::collections::HashSet; +mod blocks; mod extra_requests; // Maximum blocks to request in a single packet. @@ -68,7 +73,7 @@ const GENESIS_MISMATCH_REPUTATION_CHANGE: i32 = i32::min_value() + 1; /// Context for a network-specific handler. pub trait Context { /// Get a reference to the client. - fn client(&self) -> &crate::chain::Client; + fn client(&self) -> &dyn crate::chain::Client; /// Adjusts the reputation of the peer. Use this to point out that a peer has been malign or /// irresponsible or appeared lazy. @@ -77,9 +82,6 @@ pub trait Context { /// Force disconnecting from a peer. Use this when a peer misbehaved. fn disconnect_peer(&mut self, who: PeerId); - /// Get peer info. - fn peer_info(&self, peer: &PeerId) -> Option>; - /// Request a finality proof from a peer. fn send_finality_proof_request(&mut self, who: PeerId, request: message::FinalityProofRequest); @@ -127,11 +129,12 @@ pub(crate) enum PeerSyncState { /// Relay chain sync strategy. pub struct ChainSync { - genesis_hash: B::Hash, + _genesis_hash: B::Hash, peers: HashMap>, blocks: BlockCollection, best_queued_number: NumberFor, best_queued_hash: B::Hash, + role: Roles, required_block_attributes: message::BlockAttributes, extra_requests: ExtraRequestsAggregator, queue_blocks: HashSet, @@ -186,12 +189,13 @@ impl ChainSync { } ChainSync { - genesis_hash: info.chain.genesis_hash, + _genesis_hash: info.chain.genesis_hash, peers: HashMap::new(), blocks: BlockCollection::new(), - best_queued_hash: info.best_queued_hash.unwrap_or(info.chain.best_hash), - best_queued_number: info.best_queued_number.unwrap_or(info.chain.best_number), + best_queued_hash: info.chain.best_hash, + best_queued_number: info.chain.best_number, extra_requests: ExtraRequestsAggregator::new(), + role, required_block_attributes, queue_blocks: Default::default(), best_importing_number: Zero::zero(), @@ -204,7 +208,7 @@ impl ChainSync { fn state(&self, best_seen: &Option>) -> SyncState { match best_seen { - &Some(n) if n > self.best_queued_number && n - self.best_queued_number > As::sa(5) => SyncState::Downloading, + &Some(n) if n > self.best_queued_number && n - self.best_queued_number > 5.into() => SyncState::Downloading, _ => SyncState::Idle, } } @@ -224,85 +228,102 @@ impl ChainSync { let best_seen = self.best_seen_block(); let state = self.state(&best_seen); Status { - state: state, + state, best_seen_block: best_seen, num_peers: self.peers.len() as u32, } } /// Handle new connected peer. Call this method whenever we connect to a new peer. - pub(crate) fn new_peer(&mut self, protocol: &mut Context, who: PeerId) { - if let Some(info) = protocol.peer_info(&who) { - // there's nothing sync can get from the node that has no blockchain data - // (the opposite is not true, but all requests are served at protocol level) - if !info.roles.is_full() { - return; - } + pub(crate) fn new_peer( + &mut self, + protocol: &mut dyn Context, + who: PeerId, + info: ProtocolPeerInfo + ) { + // there's nothing sync can get from the node that has no blockchain data + // (the opposite is not true, but all requests are served at protocol level) + if !info.roles.is_full() { + return; + } - let status = block_status(&*protocol.client(), &self.queue_blocks, info.best_hash); - match (status, info.best_number) { - (Err(e), _) => { - debug!(target:"sync", "Error reading blockchain: {:?}", e); - protocol.report_peer(who.clone(), BLOCKCHAIN_STATUS_READ_ERROR_REPUTATION_CHANGE); - protocol.disconnect_peer(who); - }, - (Ok(BlockStatus::KnownBad), _) => { - info!("New peer with known bad best block {} ({}).", info.best_hash, info.best_number); - protocol.report_peer(who.clone(), i32::min_value()); - protocol.disconnect_peer(who); - }, - (Ok(BlockStatus::Unknown), b) if b == As::sa(0) => { - info!("New peer with unknown genesis hash {} ({}).", info.best_hash, info.best_number); - protocol.report_peer(who.clone(), i32::min_value()); - protocol.disconnect_peer(who); - }, - (Ok(BlockStatus::Unknown), _) if self.queue_blocks.len() > MAJOR_SYNC_BLOCKS => { - // when actively syncing the common point moves too fast. - debug!(target:"sync", "New peer with unknown best hash {} ({}), assuming common block.", self.best_queued_hash, self.best_queued_number); - self.peers.insert(who, PeerSync { - common_number: self.best_queued_number, + let status = block_status(&*protocol.client(), &self.queue_blocks, info.best_hash); + match (status, info.best_number) { + (Err(e), _) => { + debug!(target:"sync", "Error reading blockchain: {:?}", e); + protocol.report_peer(who.clone(), BLOCKCHAIN_STATUS_READ_ERROR_REPUTATION_CHANGE); + protocol.disconnect_peer(who); + }, + (Ok(BlockStatus::KnownBad), _) => { + info!("New peer with known bad best block {} ({}).", info.best_hash, info.best_number); + protocol.report_peer(who.clone(), i32::min_value()); + protocol.disconnect_peer(who); + }, + (Ok(BlockStatus::Unknown), b) if b.is_zero() => { + info!("New peer with unknown genesis hash {} ({}).", info.best_hash, info.best_number); + protocol.report_peer(who.clone(), i32::min_value()); + protocol.disconnect_peer(who); + }, + (Ok(BlockStatus::Unknown), _) if self.queue_blocks.len() > MAJOR_SYNC_BLOCKS => { + // when actively syncing the common point moves too fast. + debug!( + target:"sync", + "New peer with unknown best hash {} ({}), assuming common block.", + self.best_queued_hash, + self.best_queued_number + ); + self.peers.insert(who, PeerSync { + common_number: self.best_queued_number, + best_hash: info.best_hash, + best_number: info.best_number, + state: PeerSyncState::Available, + recently_announced: Default::default(), + }); + } + (Ok(BlockStatus::Unknown), _) => { + let our_best = self.best_queued_number; + if our_best.is_zero() { + // We are at genesis, just start downloading + debug!(target:"sync", "New peer with best hash {} ({}).", info.best_hash, info.best_number); + self.peers.insert(who.clone(), PeerSync { + common_number: Zero::zero(), best_hash: info.best_hash, best_number: info.best_number, state: PeerSyncState::Available, recently_announced: Default::default(), }); - } - (Ok(BlockStatus::Unknown), _) => { - let our_best = self.best_queued_number; - if our_best > As::sa(0) { - let common_best = ::std::cmp::min(our_best, info.best_number); - debug!(target:"sync", "New peer with unknown best hash {} ({}), searching for common ancestor.", info.best_hash, info.best_number); - self.peers.insert(who.clone(), PeerSync { - common_number: As::sa(0), - best_hash: info.best_hash, - best_number: info.best_number, - state: PeerSyncState::AncestorSearch(common_best, AncestorSearchState::ExponentialBackoff(As::sa(1))), - recently_announced: Default::default(), - }); - Self::request_ancestry(protocol, who, common_best) - } else { - // We are at genesis, just start downloading - debug!(target:"sync", "New peer with best hash {} ({}).", info.best_hash, info.best_number); - self.peers.insert(who.clone(), PeerSync { - common_number: As::sa(0), - best_hash: info.best_hash, - best_number: info.best_number, - state: PeerSyncState::Available, - recently_announced: Default::default(), - }); - self.download_new(protocol, who) - } - }, - (Ok(BlockStatus::Queued), _) | (Ok(BlockStatus::InChainWithState), _) | (Ok(BlockStatus::InChainPruned), _) => { - debug!(target:"sync", "New peer with known best hash {} ({}).", info.best_hash, info.best_number); + self.download_new(protocol, who) + } else { + let common_best = ::std::cmp::min(our_best, info.best_number); + debug!(target:"sync", + "New peer with unknown best hash {} ({}), searching for common ancestor.", + info.best_hash, + info.best_number + ); self.peers.insert(who.clone(), PeerSync { - common_number: info.best_number, + common_number: Zero::zero(), best_hash: info.best_hash, best_number: info.best_number, - state: PeerSyncState::Available, + state: PeerSyncState::AncestorSearch( + common_best, + AncestorSearchState::ExponentialBackoff(One::one()) + ), recently_announced: Default::default(), }); + Self::request_ancestry(protocol, who, common_best) } + }, + (Ok(BlockStatus::Queued), _) | + (Ok(BlockStatus::InChainWithState), _) | + (Ok(BlockStatus::InChainPruned), _) => { + debug!(target:"sync", "New peer with known best hash {} ({}).", info.best_hash, info.best_number); + self.peers.insert(who.clone(), PeerSync { + common_number: info.best_number, + best_hash: info.best_hash, + best_number: info.best_number, + state: PeerSyncState::Available, + recently_announced: Default::default(), + }); } } } @@ -312,20 +333,22 @@ impl ChainSync { curr_block_num: NumberFor, block_hash_match: bool, ) -> Option<(AncestorSearchState, NumberFor)> { + let two = >::one() + >::one(); match state { AncestorSearchState::ExponentialBackoff(next_distance_to_tip) => { - if block_hash_match && next_distance_to_tip == As::sa(1) { + if block_hash_match && next_distance_to_tip == One::one() { // We found the ancestor in the first step so there is no need to execute binary search. return None; } if block_hash_match { let left = curr_block_num; - let right = left + next_distance_to_tip / As::sa(2); - let middle = left + (right - left) / As::sa(2); + let right = left + next_distance_to_tip / two; + let middle = left + (right - left) / two; Some((AncestorSearchState::BinarySearch(left, right), middle)) } else { - let next_block_num = curr_block_num.checked_sub(&next_distance_to_tip).unwrap_or(As::sa(0)); - let next_distance_to_tip = next_distance_to_tip * As::sa(2); + let next_block_num = curr_block_num.checked_sub(&next_distance_to_tip) + .unwrap_or_else(Zero::zero); + let next_distance_to_tip = next_distance_to_tip * two; Some((AncestorSearchState::ExponentialBackoff(next_distance_to_tip), next_block_num)) } }, @@ -339,7 +362,7 @@ impl ChainSync { right = curr_block_num; } assert!(right >= left); - let middle = left + (right - left) / As::sa(2); + let middle = left + (right - left) / two; Some((AncestorSearchState::BinarySearch(left, right), middle)) }, } @@ -354,7 +377,7 @@ impl ChainSync { #[must_use] pub(crate) fn on_block_data( &mut self, - protocol: &mut Context, + protocol: &mut dyn Context, who: PeerId, request: message::BlockRequest, response: message::BlockResponse @@ -372,7 +395,7 @@ impl ChainSync { peer.state = PeerSyncState::Available; self.blocks.insert(start_block, blocks, who); self.blocks - .drain(self.best_queued_number + As::sa(1)) + .drain(self.best_queued_number + One::one()) .into_iter() .map(|block_data| { IncomingBlock { @@ -418,13 +441,14 @@ impl ChainSync { if block_hash_match && peer.common_number < num { peer.common_number = num; } - if !block_hash_match && num == As::sa(0) { + if !block_hash_match && num.is_zero() { trace!(target:"sync", "Ancestry search: genesis mismatch for peer {}", who); protocol.report_peer(who.clone(), GENESIS_MISMATCH_REPUTATION_CHANGE); protocol.disconnect_peer(who); return None } - if let Some((next_state, next_block_num)) = Self::handle_ancestor_search_state(state, num, block_hash_match) { + if let Some((next_state, next_block_num)) = + Self::handle_ancestor_search_state(state, num, block_hash_match) { peer.state = PeerSyncState::AncestorSearch(next_block_num, next_state); Self::request_ancestry(protocol, who, next_block_num); return None @@ -433,7 +457,9 @@ impl ChainSync { vec![] } }, - PeerSyncState::Available | PeerSyncState::DownloadingJustification(..) | PeerSyncState::DownloadingFinalityProof(..) => Vec::new(), + PeerSyncState::Available | + PeerSyncState::DownloadingJustification(..) | + PeerSyncState::DownloadingFinalityProof(..) => Vec::new(), } } else { Vec::new() @@ -471,41 +497,46 @@ impl ChainSync { #[must_use] pub(crate) fn on_block_justification_data( &mut self, - protocol: &mut Context, + protocol: &mut dyn Context, who: PeerId, _request: message::BlockRequest, response: message::BlockResponse, ) -> Option<(PeerId, B::Hash, NumberFor, Justification)> { - if let Some(ref mut peer) = self.peers.get_mut(&who) { - if let PeerSyncState::DownloadingJustification(hash) = peer.state { - peer.state = PeerSyncState::Available; + let peer = if let Some(peer) = self.peers.get_mut(&who) { + peer + } else { + error!(target: "sync", "Called on_block_justification_data with a bad peer ID"); + return None; + }; - // we only request one justification at a time - match response.blocks.into_iter().next() { - Some(response) => { - if hash != response.hash { - info!("Invalid block justification provided by {}: requested: {:?} got: {:?}", - who, hash, response.hash); - protocol.report_peer(who.clone(), i32::min_value()); - protocol.disconnect_peer(who); - return None; - } + if let PeerSyncState::DownloadingJustification(hash) = peer.state { + peer.state = PeerSyncState::Available; - return self.extra_requests.justifications().on_response( - who, - response.justification, - ); - }, - None => { - // we might have asked the peer for a justification on a block that we thought it had - // (regardless of whether it had a justification for it or not). - trace!(target: "sync", "Peer {:?} provided empty response for justification request {:?}", - who, - hash, - ); + // we only request one justification at a time + match response.blocks.into_iter().next() { + Some(response) => { + if hash != response.hash { + info!("Invalid block justification provided by {}: requested: {:?} got: {:?}", + who, hash, response.hash); + protocol.report_peer(who.clone(), i32::min_value()); + protocol.disconnect_peer(who); return None; - }, - } + } + + return self.extra_requests.justifications().on_response( + who, + response.justification, + ); + }, + None => { + // we might have asked the peer for a justification on a block that we thought it had + // (regardless of whether it had a justification for it or not). + trace!(target: "sync", "Peer {:?} provided empty response for justification request {:?}", + who, + hash, + ); + return None; + }, } } @@ -516,32 +547,37 @@ impl ChainSync { /// Handle new finality proof data. pub(crate) fn on_block_finality_proof_data( &mut self, - protocol: &mut Context, + protocol: &mut dyn Context, who: PeerId, response: message::FinalityProofResponse, ) -> Option<(PeerId, B::Hash, NumberFor, Vec)> { - if let Some(ref mut peer) = self.peers.get_mut(&who) { - if let PeerSyncState::DownloadingFinalityProof(hash) = peer.state { - peer.state = PeerSyncState::Available; - - // we only request one finality proof at a time - if hash != response.block { - info!( - "Invalid block finality proof provided: requested: {:?} got: {:?}", - hash, - response.block, - ); + let peer = if let Some(peer) = self.peers.get_mut(&who) { + peer + } else { + error!(target: "sync", "Called on_block_finality_proof_data with a bad peer ID"); + return None; + }; - protocol.report_peer(who.clone(), i32::min_value()); - protocol.disconnect_peer(who); - return None; - } + if let PeerSyncState::DownloadingFinalityProof(hash) = peer.state { + peer.state = PeerSyncState::Available; - return self.extra_requests.finality_proofs().on_response( - who, - response.proof, + // we only request one finality proof at a time + if hash != response.block { + info!( + "Invalid block finality proof provided: requested: {:?} got: {:?}", + hash, + response.block, ); + + protocol.report_peer(who.clone(), i32::min_value()); + protocol.disconnect_peer(who); + return None; } + + return self.extra_requests.finality_proofs().on_response( + who, + response.proof, + ); } self.maintain_sync(protocol); @@ -551,17 +587,18 @@ impl ChainSync { /// A batch of blocks have been processed, with or without errors. /// Call this when a batch of blocks have been processed by the import queue, with or without /// errors. - pub fn blocks_processed(&mut self, processed_blocks: Vec, has_error: bool) { + pub fn blocks_processed(&mut self, protocol: &mut Context, processed_blocks: Vec, has_error: bool) { for hash in processed_blocks { self.queue_blocks.remove(&hash); } if has_error { self.best_importing_number = Zero::zero(); } + self.maintain_sync(protocol) } /// Maintain the sync process (download new blocks, fetch justifications). - pub fn maintain_sync(&mut self, protocol: &mut Context) { + fn maintain_sync(&mut self, protocol: &mut dyn Context) { let peers: Vec = self.peers.keys().map(|p| p.clone()).collect(); for peer in peers { self.download_new(protocol, peer); @@ -571,7 +608,7 @@ impl ChainSync { /// Called periodically to perform any time-based actions. Must be called at a regular /// interval. - pub fn tick(&mut self, protocol: &mut Context) { + pub fn tick(&mut self, protocol: &mut dyn Context) { self.extra_requests.dispatch(&mut self.peers, protocol); } @@ -579,7 +616,7 @@ impl ChainSync { /// /// Uses `protocol` to queue a new justification request and tries to dispatch all pending /// requests. - pub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor, protocol: &mut Context) { + pub fn request_justification(&mut self, hash: &B::Hash, number: NumberFor, protocol: &mut dyn Context) { self.extra_requests.justifications().queue_request( (*hash, number), |base, block| protocol.client().is_descendent_of(base, block), @@ -608,7 +645,7 @@ impl ChainSync { /// Request a finality proof for the given block. /// /// Queues a new finality proof request and tries to dispatch all pending requests. - pub fn request_finality_proof(&mut self, hash: &B::Hash, number: NumberFor, protocol: &mut Context) { + pub fn request_finality_proof(&mut self, hash: &B::Hash, number: NumberFor, protocol: &mut dyn Context) { self.extra_requests.finality_proofs().queue_request( (*hash, number), |base, block| protocol.client().is_descendent_of(base, block), @@ -635,7 +672,7 @@ impl ChainSync { } /// Notify about finalization of the given block. - pub fn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor, protocol: &mut Context) { + pub fn on_block_finalized(&mut self, hash: &B::Hash, number: NumberFor, protocol: &mut dyn Context) { if let Err(err) = self.extra_requests.on_block_finalized( hash, number, @@ -656,12 +693,21 @@ impl ChainSync { // Abort search. peer.state = PeerSyncState::Available; } - trace!(target: "sync", "Updating peer {} info, ours={}, common={}, their best={}", n, number, peer.common_number, peer.best_number); - if peer.best_number >= number { - peer.common_number = number; + let new_common_number = if peer.best_number >= number { + number } else { - peer.common_number = peer.best_number; - } + peer.best_number + }; + trace!( + target: "sync", + "Updating peer {} info, ours={}, common={}->{}, their best={}", + n, + number, + peer.common_number, + new_common_number, + peer.best_number, + ); + peer.common_number = new_common_number; } } @@ -672,12 +718,22 @@ impl ChainSync { } /// Call when a node announces a new block. - pub(crate) fn on_block_announce(&mut self, protocol: &mut Context, who: PeerId, hash: B::Hash, header: &B::Header) { + /// + /// If true is returned, then the caller MUST try to import passed header (call `on_block_data). + /// The network request isn't sent in this case. + #[must_use] + pub(crate) fn on_block_announce( + &mut self, + protocol: &mut dyn Context, + who: PeerId, + hash: B::Hash, + header: &B::Header, + ) -> bool { let number = *header.number(); debug!(target: "sync", "Received block announcement with number {:?}", number); - if number <= As::sa(0) { + if number.is_zero() { warn!(target: "sync", "Ignored invalid block announcement from {}: {}", who, hash); - return; + return false; } let parent_status = block_status(&*protocol.client(), &self.queue_blocks, header.parent_hash().clone()).ok() .unwrap_or(BlockStatus::Unknown); @@ -685,70 +741,122 @@ impl ChainSync { let ancient_parent = parent_status == BlockStatus::InChainPruned; let known = self.is_known(protocol, &hash); - if let Some(ref mut peer) = self.peers.get_mut(&who) { - while peer.recently_announced.len() >= ANNOUNCE_HISTORY_SIZE { - peer.recently_announced.pop_front(); - } - peer.recently_announced.push_back(hash.clone()); - if number > peer.best_number { - // update their best block - peer.best_number = number; - peer.best_hash = hash; - } - if let PeerSyncState::AncestorSearch(_, _) = peer.state { - return; - } - if header.parent_hash() == &self.best_queued_hash || known_parent { - peer.common_number = number - As::sa(1); - } else if known { - peer.common_number = number - } + let peer = if let Some(peer) = self.peers.get_mut(&who) { + peer } else { - return; + error!(target: "sync", "Called on_block_announce with a bad peer ID"); + return false; + }; + while peer.recently_announced.len() >= ANNOUNCE_HISTORY_SIZE { + peer.recently_announced.pop_front(); + } + peer.recently_announced.push_back(hash.clone()); + if number > peer.best_number { + // update their best block + peer.best_number = number; + peer.best_hash = hash; + } + if let PeerSyncState::AncestorSearch(_, _) = peer.state { + return false; + } + if header.parent_hash() == &self.best_queued_hash || known_parent { + peer.common_number = number - One::one(); + } else if known { + peer.common_number = number } - if !(known || self.is_already_downloading(&hash)) { - let stale = number <= self.best_queued_number; - if stale { - if !(known_parent || self.is_already_downloading(header.parent_hash())) { - if protocol.client().block_status(&BlockId::Number(*header.number())) - .unwrap_or(BlockStatus::Unknown) == BlockStatus::InChainPruned - { - trace!(target: "sync", "Ignored unknown ancient block announced from {}: {} {:?}", who, hash, header); - } else { - trace!(target: "sync", "Considering new unknown stale block announced from {}: {} {:?}", who, hash, header); - self.download_unknown_stale(protocol, who, &hash); - } - } else { - if ancient_parent { - trace!(target: "sync", "Ignored ancient stale block announced from {}: {} {:?}", who, hash, header); + // known block case + if known || self.is_already_downloading(&hash) { + trace!(target: "sync", "Known block announce from {}: {}", who, hash); + return false; + } + + // stale block case + let requires_additional_data = !self.role.is_light(); + let stale = number <= self.best_queued_number; + if stale { + if !(known_parent || self.is_already_downloading(header.parent_hash())) { + if protocol.client().block_status(&BlockId::Number(*header.number())) + .unwrap_or(BlockStatus::Unknown) == BlockStatus::InChainPruned + { + trace!( + target: "sync", + "Ignored unknown ancient block announced from {}: {} {:?}", + who, hash, header + ); + return false; + } + + trace!( + target: "sync", + "Considering new unknown stale block announced from {}: {} {:?}", + who, hash, header + ); + let request = self.download_unknown_stale(&who, &hash); + match request { + Some(request) => if requires_additional_data { + protocol.send_block_request(who, request); + return false; } else { - self.download_stale(protocol, who, &hash); - } + return true; + }, + None => return false, } } else { if ancient_parent { - trace!(target: "sync", "Ignored ancient block announced from {}: {} {:?}", who, hash, header); - } else { - trace!(target: "sync", "Considering new block announced from {}: {} {:?}", who, hash, header); - self.download_new(protocol, who); + trace!( + target: "sync", + "Ignored ancient stale block announced from {}: {} {:?}", + who, hash, header + ); + return false; + } + + let request = self.download_stale(&who, &hash); + match request { + Some(request) => if requires_additional_data { + protocol.send_block_request(who, request); + return false; + } else { + return true; + }, + None => return false, } } - } else { - trace!(target: "sync", "Known block announce from {}: {}", who, hash); } + + if ancient_parent { + trace!(target: "sync", "Ignored ancient block announced from {}: {} {:?}", who, hash, header); + return false; + } + + trace!(target: "sync", "Considering new block announced from {}: {} {:?}", who, hash, header); + let (range, request) = match self.select_new_blocks(who.clone()) { + Some((range, request)) => (range, request), + None => return false, + }; + let is_required_data_available = + !requires_additional_data && + range.end - range.start == One::one() && + range.start == *header.number(); + if !is_required_data_available { + protocol.send_block_request(who, request); + return false; + } + + true } fn is_already_downloading(&self, hash: &B::Hash) -> bool { self.peers.iter().any(|(_, p)| p.state == PeerSyncState::DownloadingStale(*hash)) } - fn is_known(&self, protocol: &mut Context, hash: &B::Hash) -> bool { + fn is_known(&self, protocol: &mut dyn Context, hash: &B::Hash) -> bool { block_status(&*protocol.client(), &self.queue_blocks, *hash).ok().map_or(false, |s| s != BlockStatus::Unknown) } /// Call when a peer has disconnected. - pub(crate) fn peer_disconnected(&mut self, protocol: &mut Context, who: PeerId) { + pub(crate) fn peer_disconnected(&mut self, protocol: &mut dyn Context, who: PeerId) { self.blocks.clear_peer_download(&who); self.peers.remove(&who); self.extra_requests.peer_disconnected(who); @@ -756,103 +864,135 @@ impl ChainSync { } /// Restart the sync process. - pub(crate) fn restart(&mut self, protocol: &mut Context) { + pub(crate) fn restart( + &mut self, + protocol: &mut dyn Context, + mut peer_info: impl FnMut(&PeerId) -> Option> + ) { self.queue_blocks.clear(); self.best_importing_number = Zero::zero(); self.blocks.clear(); - match protocol.client().info() { - Ok(info) => { - self.best_queued_hash = info.best_queued_hash.unwrap_or(info.chain.best_hash); - self.best_queued_number = info.best_queued_number.unwrap_or(info.chain.best_number); - debug!(target:"sync", "Restarted with {} ({})", self.best_queued_number, self.best_queued_hash); - }, - Err(e) => { - debug!(target:"sync", "Error reading blockchain: {:?}", e); - self.best_queued_hash = self.genesis_hash; - self.best_queued_number = As::sa(0); - } - } + let info = protocol.client().info(); + self.best_queued_hash = info.chain.best_hash; + self.best_queued_number = info.chain.best_number; + debug!(target:"sync", "Restarted with {} ({})", self.best_queued_number, self.best_queued_hash); let ids: Vec = self.peers.drain().map(|(id, _)| id).collect(); for id in ids { - self.new_peer(protocol, id); + if let Some(info) = peer_info(&id) { + self.new_peer(protocol, id, info); + } } } // Download old block with known parent. - fn download_stale(&mut self, protocol: &mut Context, who: PeerId, hash: &B::Hash) { - if let Some(ref mut peer) = self.peers.get_mut(&who) { - match peer.state { - PeerSyncState::Available => { - let request = message::generic::BlockRequest { - id: 0, - fields: self.required_block_attributes.clone(), - from: message::FromBlock::Hash(*hash), - to: None, - direction: message::Direction::Ascending, - max: Some(1), - }; - peer.state = PeerSyncState::DownloadingStale(*hash); - protocol.send_block_request(who, request); - }, - _ => (), - } + fn download_stale( + &mut self, + who: &PeerId, + hash: &B::Hash, + ) -> Option> { + let peer = self.peers.get_mut(who)?; + match peer.state { + PeerSyncState::Available => { + peer.state = PeerSyncState::DownloadingStale(*hash); + Some(message::generic::BlockRequest { + id: 0, + fields: self.required_block_attributes.clone(), + from: message::FromBlock::Hash(*hash), + to: None, + direction: message::Direction::Ascending, + max: Some(1), + }) + }, + _ => None, } } // Download old block with unknown parent. - fn download_unknown_stale(&mut self, protocol: &mut Context, who: PeerId, hash: &B::Hash) { - if let Some(ref mut peer) = self.peers.get_mut(&who) { - match peer.state { - PeerSyncState::Available => { - let request = message::generic::BlockRequest { - id: 0, - fields: self.required_block_attributes.clone(), - from: message::FromBlock::Hash(*hash), - to: None, - direction: message::Direction::Descending, - max: Some(MAX_UNKNOWN_FORK_DOWNLOAD_LEN), - }; - peer.state = PeerSyncState::DownloadingStale(*hash); - protocol.send_block_request(who, request); - }, - _ => (), - } + fn download_unknown_stale( + &mut self, + who: &PeerId, + hash: &B::Hash, + ) -> Option> { + let peer = self.peers.get_mut(who)?; + match peer.state { + PeerSyncState::Available => { + peer.state = PeerSyncState::DownloadingStale(*hash); + Some(message::generic::BlockRequest { + id: 0, + fields: self.required_block_attributes.clone(), + from: message::FromBlock::Hash(*hash), + to: None, + direction: message::Direction::Descending, + max: Some(MAX_UNKNOWN_FORK_DOWNLOAD_LEN), + }) + }, + _ => None, } } - // Issue a request for a peer to download new blocks, if any are available - fn download_new(&mut self, protocol: &mut Context, who: PeerId) { - if let Some(ref mut peer) = self.peers.get_mut(&who) { - // when there are too many blocks in the queue => do not try to download new blocks - if self.queue_blocks.len() > MAX_IMPORTING_BLOCKS { - trace!(target: "sync", "Too many blocks in the queue."); - return; - } - match peer.state { - PeerSyncState::Available => { - trace!(target: "sync", "Considering new block download from {}, common block is {}, best is {:?}", who, peer.common_number, peer.best_number); - if let Some(range) = self.blocks.needed_blocks(who.clone(), MAX_BLOCKS_TO_REQUEST, peer.best_number, peer.common_number) { + // Issue a request for a peer to download new blocks, if any are available. + fn download_new(&mut self, protocol: &mut dyn Context, who: PeerId) { + if let Some((_, request)) = self.select_new_blocks(who.clone()) { + protocol.send_block_request(who, request); + } + } + + // Select a range of NEW blocks to download from peer. + fn select_new_blocks(&mut self, who: PeerId) -> Option<(Range>, message::BlockRequest)> { + // when there are too many blocks in the queue => do not try to download new blocks + if self.queue_blocks.len() > MAX_IMPORTING_BLOCKS { + trace!(target: "sync", "Too many blocks in the queue."); + return None; + } + + let peer = self.peers.get_mut(&who)?; + match peer.state { + PeerSyncState::Available => { + trace!( + target: "sync", + "Considering new block download from {}, common block is {}, best is {:?}", + who, + peer.common_number, + peer.best_number, + ); + let range = self.blocks.needed_blocks( + who.clone(), + MAX_BLOCKS_TO_REQUEST, + peer.best_number, + peer.common_number + ); + match range { + Some(range) => { trace!(target: "sync", "Requesting blocks from {}, ({} to {})", who, range.start, range.end); - let request = message::generic::BlockRequest { - id: 0, - fields: self.required_block_attributes.clone(), - from: message::FromBlock::Number(range.start), - to: None, - direction: message::Direction::Ascending, - max: Some((range.end - range.start).as_() as u32), - }; + let from = message::FromBlock::Number(range.start); + let max = Some((range.end - range.start).saturated_into::()); peer.state = PeerSyncState::DownloadingNew(range.start); - protocol.send_block_request(who, request); - } else { + Some(( + range, + message::generic::BlockRequest { + id: 0, + fields: self.required_block_attributes.clone(), + from, + to: None, + direction: message::Direction::Ascending, + max, + }, + )) + }, + None => { trace!(target: "sync", "Nothing to request"); - } - }, - _ => trace!(target: "sync", "Peer {} is busy", who), - } + None + }, + } + }, + _ => { + trace!(target: "sync", "Peer {} is busy", who); + None + }, } } - fn request_ancestry(protocol: &mut Context, who: PeerId, block: NumberFor) { + fn request_ancestry(protocol: &mut dyn Context, who: PeerId, block: NumberFor) { trace!(target: "sync", "Requesting ancestry block #{} from {}", block, who); let request = message::generic::BlockRequest { id: 0, @@ -868,7 +1008,7 @@ impl ChainSync { /// Get block status, taking into account import queue. fn block_status( - chain: &crate::chain::Client, + chain: &dyn crate::chain::Client, queue_blocks: &HashSet, hash: B::Hash) -> Result { diff --git a/core/network/src/blocks.rs b/core/network/src/protocol/sync/blocks.rs similarity index 85% rename from core/network/src/blocks.rs rename to core/network/src/protocol/sync/blocks.rs index 60c6886f09f27c210876825bcc4fa364235676e2..66730fcc3ee5246da6d5d2a13aa814d48af97367 100644 --- a/core/network/src/blocks.rs +++ b/core/network/src/protocol/sync/blocks.rs @@ -21,7 +21,7 @@ use std::collections::{HashMap, BTreeMap}; use std::collections::hash_map::Entry; use log::trace; use network_libp2p::PeerId; -use runtime_primitives::traits::{Block as BlockT, NumberFor, As}; +use runtime_primitives::traits::{Block as BlockT, NumberFor, One}; use crate::message; const MAX_PARALLEL_DOWNLOADS: u32 = 1; @@ -48,7 +48,7 @@ impl BlockRangeState { pub fn len(&self) -> NumberFor { match *self { BlockRangeState::Downloading { len, .. } => len, - BlockRangeState::Complete(ref blocks) => As::sa(blocks.len() as u64), + BlockRangeState::Complete(ref blocks) => (blocks.len() as u32).into(), } } } @@ -100,17 +100,19 @@ impl BlockCollection { } /// Returns a set of block hashes that require a header download. The returned set is marked as being downloaded. - pub fn needed_blocks(&mut self, who: PeerId, count: usize, peer_best: NumberFor, common: NumberFor) -> Option>> { + pub fn needed_blocks(&mut self, who: PeerId, count: usize, peer_best: NumberFor, common: NumberFor) + -> Option>> { // First block number that we need to download - let first_different = common + As::sa(1); - let count = As::sa(count as u64); + let first_different = common + >::one(); + let count = (count as u32).into(); let (mut range, downloading) = { let mut downloading_iter = self.blocks.iter().peekable(); let mut prev: Option<(&NumberFor, &BlockRangeState)> = None; loop { let next = downloading_iter.next(); break match &(prev, next) { - &(Some((start, &BlockRangeState::Downloading { ref len, downloading })), _) if downloading < MAX_PARALLEL_DOWNLOADS => + &(Some((start, &BlockRangeState::Downloading { ref len, downloading })), _) + if downloading < MAX_PARALLEL_DOWNLOADS => (*start .. *start + *len, downloading), &(Some((start, r)), Some((next_start, _))) if *start + r.len() < *next_start => (*start + r.len() .. cmp::min(*next_start, *start + r.len() + count), 0), // gap @@ -132,11 +134,15 @@ impl BlockCollection { trace!(target: "sync", "Out of range for peer {} ({} vs {})", who, range.start, peer_best); return None; } - range.end = cmp::min(peer_best + As::sa(1), range.end); + range.end = cmp::min(peer_best + One::one(), range.end); self.peer_requests.insert(who, range.start); - self.blocks.insert(range.start, BlockRangeState::Downloading { len: range.end - range.start, downloading: downloading + 1 }); + self.blocks.insert(range.start, BlockRangeState::Downloading { + len: range.end - range.start, + downloading: downloading + 1 + }); if range.end <= range.start { - panic!("Empty range {:?}, count={}, peer_best={}, common={}, blocks={:?}", range, count, peer_best, common, self.blocks); + panic!("Empty range {:?}, count={}, peer_best={}, common={}, blocks={:?}", + range, count, peer_best, common, self.blocks); } Some(range) } @@ -150,7 +156,7 @@ impl BlockCollection { for (start, range_data) in &mut self.blocks { match range_data { &mut BlockRangeState::Complete(ref mut blocks) if *start <= prev => { - prev = *start + As::sa(blocks.len() as u64); + prev = *start + (blocks.len() as u32).into(); let mut blocks = mem::replace(blocks, Vec::new()); drained.append(&mut blocks); ranges.push(*start); @@ -248,14 +254,17 @@ mod test { bc.insert(1, blocks[1..11].to_vec(), peer0.clone()); assert_eq!(bc.needed_blocks(peer0.clone(), 40, 150, 0), Some(11 .. 41)); - assert_eq!(bc.drain(1), blocks[1..11].iter().map(|b| BlockData { block: b.clone(), origin: Some(peer0.clone()) }).collect::>()); + assert_eq!(bc.drain(1), blocks[1..11].iter() + .map(|b| BlockData { block: b.clone(), origin: Some(peer0.clone()) }).collect::>()); bc.clear_peer_download(&peer0); bc.insert(11, blocks[11..41].to_vec(), peer0.clone()); let drained = bc.drain(12); - assert_eq!(drained[..30], blocks[11..41].iter().map(|b| BlockData { block: b.clone(), origin: Some(peer0.clone()) }).collect::>()[..]); - assert_eq!(drained[30..], blocks[41..81].iter().map(|b| BlockData { block: b.clone(), origin: Some(peer1.clone()) }).collect::>()[..]); + assert_eq!(drained[..30], blocks[11..41].iter() + .map(|b| BlockData { block: b.clone(), origin: Some(peer0.clone()) }).collect::>()[..]); + assert_eq!(drained[30..], blocks[41..81].iter() + .map(|b| BlockData { block: b.clone(), origin: Some(peer1.clone()) }).collect::>()[..]); bc.clear_peer_download(&peer2); assert_eq!(bc.needed_blocks(peer2.clone(), 40, 150, 80), Some(81 .. 121)); @@ -266,8 +275,10 @@ mod test { assert_eq!(bc.drain(80), vec![]); let drained = bc.drain(81); - assert_eq!(drained[..40], blocks[81..121].iter().map(|b| BlockData { block: b.clone(), origin: Some(peer2.clone()) }).collect::>()[..]); - assert_eq!(drained[40..], blocks[121..150].iter().map(|b| BlockData { block: b.clone(), origin: Some(peer1.clone()) }).collect::>()[..]); + assert_eq!(drained[..40], blocks[81..121].iter() + .map(|b| BlockData { block: b.clone(), origin: Some(peer2.clone()) }).collect::>()[..]); + assert_eq!(drained[40..], blocks[121..150].iter() + .map(|b| BlockData { block: b.clone(), origin: Some(peer1.clone()) }).collect::>()[..]); } #[test] diff --git a/core/network/src/sync/extra_requests.rs b/core/network/src/protocol/sync/extra_requests.rs similarity index 96% rename from core/network/src/sync/extra_requests.rs rename to core/network/src/protocol/sync/extra_requests.rs index 3ebf2b2509bab994c360e29627c03ca9d255403c..f41997a05ce9e8f98c8364201fab86d96ad730ee 100644 --- a/core/network/src/sync/extra_requests.rs +++ b/core/network/src/protocol/sync/extra_requests.rs @@ -23,8 +23,8 @@ use fork_tree::ForkTree; use network_libp2p::PeerId; use runtime_primitives::Justification; use runtime_primitives::traits::{Block as BlockT, NumberFor}; -use crate::message; -use crate::sync::{Context, PeerSync, PeerSyncState}; +use crate::protocol::message; +use crate::protocol::sync::{Context, PeerSync, PeerSyncState}; // Time to wait before trying to get the same extra data from the same peer. const EXTRA_RETRY_WAIT: Duration = Duration::from_secs(10); @@ -39,7 +39,7 @@ pub(crate) trait ExtraRequestsEssence { /// Name of request type to display in logs. fn type_name(&self) -> &'static str; /// Send network message corresponding to the request. - fn send_network_request(&self, protocol: &mut Context, peer: PeerId, request: ExtraRequest); + fn send_network_request(&self, protocol: &mut dyn Context, peer: PeerId, request: ExtraRequest); /// Create peer state for peer that is downloading extra data. fn peer_downloading_state(&self, block: B::Hash) -> PeerSyncState; } @@ -69,7 +69,7 @@ impl ExtraRequestsAggregator { } /// Dispatches all possible pending requests to the given peers. - pub(crate) fn dispatch(&mut self, peers: &mut HashMap>, protocol: &mut Context) { + pub(crate) fn dispatch(&mut self, peers: &mut HashMap>, protocol: &mut dyn Context) { self.justifications.dispatch(peers, protocol); self.finality_proofs.dispatch(peers, protocol); } @@ -132,7 +132,7 @@ impl> ExtraRequests { /// extra request for block #10 to a peer at block #2), and we also /// throttle requests to the same peer if a previous justification request /// yielded no results. - pub(crate) fn dispatch(&mut self, peers: &mut HashMap>, protocol: &mut Context) { + pub(crate) fn dispatch(&mut self, peers: &mut HashMap>, protocol: &mut dyn Context) { if self.pending_requests.is_empty() { return; } @@ -373,7 +373,7 @@ impl ExtraRequestsEssence for JustificationsRequestsEssence { "justification" } - fn send_network_request(&self, protocol: &mut Context, peer: PeerId, request: ExtraRequest) { + fn send_network_request(&self, protocol: &mut dyn Context, peer: PeerId, request: ExtraRequest) { protocol.send_block_request(peer, message::generic::BlockRequest { id: 0, fields: message::BlockAttributes::JUSTIFICATION, @@ -398,7 +398,7 @@ impl ExtraRequestsEssence for FinalityProofRequestsEssence { "finality proof" } - fn send_network_request(&self, protocol: &mut Context, peer: PeerId, request: ExtraRequest) { + fn send_network_request(&self, protocol: &mut dyn Context, peer: PeerId, request: ExtraRequest) { protocol.send_finality_proof_request(peer, message::generic::FinalityProofRequest { id: 0, block: request.0, diff --git a/core/network/src/util.rs b/core/network/src/protocol/util.rs similarity index 100% rename from core/network/src/util.rs rename to core/network/src/protocol/util.rs diff --git a/core/network/src/service.rs b/core/network/src/service.rs index e63ce4037f8cbd093fd3a0969dd1eccf5a5b915c..6a328e854d8cbf48df06c3f026661c9770a22ede 100644 --- a/core/network/src/service.rs +++ b/core/network/src/service.rs @@ -15,33 +15,35 @@ // along with Substrate. If not, see . use std::collections::HashMap; +use std::io; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; -use std::{io, thread, time::Duration}; +use std::time::Duration; use log::{warn, debug, error, info}; -use futures::{Async, Future, Stream, sync::oneshot, sync::mpsc}; +use futures::{prelude::*, sync::oneshot, sync::mpsc}; use parking_lot::{Mutex, RwLock}; -use network_libp2p::{ProtocolId, NetworkConfiguration}; -use network_libp2p::{start_service, parse_str_addr, Service as NetworkService, ServiceEvent as NetworkServiceEvent}; +use network_libp2p::{start_service, parse_str_addr, Service as Libp2pNetService, ServiceEvent as Libp2pNetServiceEvent}; use network_libp2p::{RegisteredProtocol, NetworkState}; use peerset::PeersetHandle; use consensus::import_queue::{ImportQueue, Link, SharedFinalityProofRequestBuilder}; use runtime_primitives::{traits::{Block as BlockT, NumberFor}, ConsensusEngineId}; -use crate::consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient}; -use crate::message::Message; -use crate::protocol::{self, Context, CustomMessageOutcome, Protocol, ConnectedPeer, ProtocolStatus, PeerInfo}; +use crate::AlwaysBadChecker; +use crate::chain::FinalityProofProvider; +use crate::protocol::consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient}; +use crate::protocol::message::Message; +use crate::protocol::on_demand::RequestData; +use crate::protocol::{self, Context, CustomMessageOutcome, Protocol, ConnectedPeer}; +use crate::protocol::{ProtocolStatus, PeerInfo, NetworkOut}; use crate::config::Params; use crate::error::Error; -use crate::specialization::NetworkSpecialization; - -use crossbeam_channel::{self as channel, Receiver, Sender, TryRecvError}; -use tokio::prelude::task::AtomicTask; -use tokio::runtime::Builder as RuntimeBuilder; +use crate::protocol::specialization::NetworkSpecialization; /// Interval at which we send status updates on the SyncProvider status stream. const STATUS_INTERVAL: Duration = Duration::from_millis(5000); +/// Interval at which we update the `peers` field on the main thread. +const CONNECTED_PEERS_INTERVAL: Duration = Duration::from_millis(500); pub use network_libp2p::PeerId; @@ -54,8 +56,13 @@ pub trait SyncProvider: Send + Sync { fn status(&self) -> mpsc::UnboundedReceiver>; /// Get network state. fn network_state(&self) -> NetworkState; - /// Get currently connected peers - fn peers(&self) -> Vec<(PeerId, PeerInfo)>; + + /// Get currently connected peers. + /// + /// > **Warning**: This method can return outdated information and should only ever be used + /// > when obtaining outdated information is acceptable. + fn peers_debug_info(&self) -> Vec<(PeerId, PeerInfo)>; + /// Are we in the process of downloading the chain? fn is_major_syncing(&self) -> bool; } @@ -86,7 +93,7 @@ pub struct NetworkLink> { /// The protocol sender pub(crate) protocol_sender: mpsc::UnboundedSender>, /// The network sender - pub(crate) network_sender: NetworkChan, + pub(crate) network_sender: mpsc::UnboundedSender>, } impl> Link for NetworkLink { @@ -102,8 +109,8 @@ impl> Link for NetworkLink { let _ = self.protocol_sender.unbounded_send(ProtocolMsg::JustificationImportResult(hash.clone(), number, success)); if !success { info!("Invalid justification provided by {} for #{}", who, hash); - let _ = self.network_sender.send(NetworkMsg::ReportPeer(who.clone(), i32::min_value())); - let _ = self.network_sender.send(NetworkMsg::DisconnectPeer(who.clone())); + let _ = self.network_sender.unbounded_send(NetworkMsg::ReportPeer(who.clone(), i32::min_value())); + let _ = self.network_sender.unbounded_send(NetworkMsg::DisconnectPeer(who.clone())); } } @@ -135,13 +142,13 @@ impl> Link for NetworkLink { )); if !success { info!("Invalid finality proof provided by {} for #{}", who, request_block.0); - let _ = self.network_sender.send(NetworkMsg::ReportPeer(who.clone(), i32::min_value())); - let _ = self.network_sender.send(NetworkMsg::DisconnectPeer(who.clone())); + let _ = self.network_sender.unbounded_send(NetworkMsg::ReportPeer(who.clone(), i32::min_value())); + let _ = self.network_sender.unbounded_send(NetworkMsg::DisconnectPeer(who.clone())); } } fn report_peer(&self, who: PeerId, reputation_change: i32) { - self.network_sender.send(NetworkMsg::ReportPeer(who, reputation_change)); + let _ = self.network_sender.unbounded_send(NetworkMsg::ReportPeer(who, reputation_change)); } fn restart(&self) { @@ -168,7 +175,7 @@ impl ReportHandle { } /// Substrate network service. Handles network IO and manages connectivity. -pub struct Service> { +pub struct NetworkService> { /// Sinks to propagate status updates. status_sinks: Arc>>>>, /// Are we connected to any peer? @@ -178,81 +185,98 @@ pub struct Service> { /// Peers whom we are connected with. peers: Arc>>>, /// Channel for networking messages processed by the background thread. - network_chan: NetworkChan, + network_chan: mpsc::UnboundedSender>, /// Network service - network: Arc>>>, + network: Arc>>>, /// Peerset manager (PSM); manages the reputation of nodes and indicates the network which /// nodes it should be connected to or not. peerset: PeersetHandle, /// Protocol sender protocol_sender: mpsc::UnboundedSender>, - /// Sender for messages to the background service task, and handle for the background thread. - /// Dropping the sender should close the task and the thread. - /// This is an `Option` because we need to extract it in the destructor. - bg_thread: Option<(oneshot::Sender<()>, thread::JoinHandle<()>)>, } -impl> Service { - /// Creates and register protocol with the network service - pub fn new( +impl, H: ExHashT> NetworkWorker { + /// Creates the network service. + /// + /// Returns a `NetworkWorker` that implements `Future` and must be regularly polled in order + /// for the network processing to advance. From it, you can extract a `NetworkService` using + /// `worker.service()`. The `NetworkService` can be shared through the codebase. + pub fn new( params: Params, - protocol_id: ProtocolId, - import_queue: Box>, - ) -> Result>, Error> { - let (network_chan, network_port) = network_channel(); + ) -> Result, Error> { + let (network_chan, network_port) = mpsc::unbounded(); let (protocol_sender, protocol_rx) = mpsc::unbounded(); let status_sinks = Arc::new(Mutex::new(Vec::new())); + + // connect the import-queue to the network service. + let link = NetworkLink { + protocol_sender: protocol_sender.clone(), + network_sender: network_chan.clone(), + }; + params.import_queue.start(Box::new(link))?; + // Start in off-line mode, since we're not connected to any nodes yet. let is_offline = Arc::new(AtomicBool::new(true)); let is_major_syncing = Arc::new(AtomicBool::new(false)); let peers: Arc>>> = Arc::new(Default::default()); let protocol = Protocol::new( - peers.clone(), - network_chan.clone(), - params.config, + protocol::ProtocolConfig { roles: params.roles }, params.chain, - params.finality_proof_provider, - params.on_demand, - params.transaction_pool, + params.on_demand.as_ref().map(|od| od.checker().clone()) + .unwrap_or(Arc::new(AlwaysBadChecker)), params.specialization, )?; let versions: Vec<_> = ((protocol::MIN_VERSION as u8)..=(protocol::CURRENT_VERSION as u8)).collect(); - let registered = RegisteredProtocol::new(protocol_id, &versions); - let (thread, network, peerset) = start_thread( - is_offline.clone(), - is_major_syncing.clone(), - protocol, - import_queue.clone(), - network_port, - protocol_rx, - status_sinks.clone(), - params.network_config, - registered, - )?; + let registered = RegisteredProtocol::new(params.protocol_id, &versions); + + // Start the main service. + let (network, peerset) = match start_service(params.network_config, registered) { + Ok((network, peerset)) => (Arc::new(Mutex::new(network)), peerset), + Err(err) => { + warn!("Error starting network: {}", err); + return Err(err.into()) + }, + }; - let service = Arc::new(Service { - status_sinks, - is_offline, - is_major_syncing, - network_chan: network_chan.clone(), - peers, - peerset, - network, + let service = Arc::new(NetworkService { + status_sinks: status_sinks.clone(), + is_offline: is_offline.clone(), + is_major_syncing: is_major_syncing.clone(), + network_chan, + peers: peers.clone(), + peerset: peerset.clone(), + network: network.clone(), protocol_sender: protocol_sender.clone(), - bg_thread: Some(thread), }); - // connect the import-queue to the network service. - let link = NetworkLink { - protocol_sender, - network_sender: network_chan, - }; - - import_queue.start(Box::new(link))?; + Ok(NetworkWorker { + is_offline, + is_major_syncing, + network_service: network, + peerset, + service, + protocol, + peers, + import_queue: params.import_queue, + transaction_pool: params.transaction_pool, + finality_proof_provider: params.finality_proof_provider, + network_port, + protocol_rx, + status_sinks, + on_demand_in: params.on_demand.and_then(|od| od.extract_receiver()), + status_interval: tokio_timer::Interval::new_interval(STATUS_INTERVAL), + connected_peers_interval: tokio_timer::Interval::new_interval(CONNECTED_PEERS_INTERVAL), + }) + } - Ok(service) + /// Return a `NetworkService` that can be shared through the code base and can be used to + /// manipulate the worker. + pub fn service(&self) -> &Arc> { + &self.service } +} +impl> NetworkService { /// Returns the downloaded bytes per second averaged over the past few seconds. #[inline] pub fn average_download_per_sec(&self) -> u64 { @@ -322,19 +346,19 @@ impl> Service { /// /// This method is extremely poor in terms of API and should be eventually removed. pub fn disconnect_peer(&self, who: PeerId) { - let _ = self.network_chan.send(NetworkMsg::DisconnectPeer(who)); + let _ = self.network_chan.unbounded_send(NetworkMsg::DisconnectPeer(who)); } /// Send a message to the given peer. Has no effect if we're not connected to this peer. /// /// This method is extremely poor in terms of API and should be eventually removed. pub fn send_request(&self, who: PeerId, message: Message) { - let _ = self.network_chan.send(NetworkMsg::Outgoing(who, message)); + let _ = self.network_chan.unbounded_send(NetworkMsg::Outgoing(who, message)); } /// Execute a closure with the chain-specific network specialization. pub fn with_spec(&self, f: F) - where F: FnOnce(&mut S, &mut Context) + Send + 'static + where F: FnOnce(&mut S, &mut dyn Context) + Send + 'static { let _ = self .protocol_sender @@ -343,7 +367,7 @@ impl> Service { /// Execute a closure with the consensus gossip. pub fn with_gossip(&self, f: F) - where F: FnOnce(&mut ConsensusGossip, &mut Context) + Send + 'static + where F: FnOnce(&mut ConsensusGossip, &mut dyn Context) + Send + 'static { let _ = self .protocol_sender @@ -357,7 +381,7 @@ impl> Service { } } -impl> ::consensus::SyncOracle for Service { +impl> ::consensus::SyncOracle for NetworkService { fn is_major_syncing(&self) -> bool { self.is_major_syncing() } @@ -367,18 +391,7 @@ impl> ::consensus::SyncOracle f } } -impl> Drop for Service { - fn drop(&mut self) { - if let Some((sender, join)) = self.bg_thread.take() { - let _ = sender.send(()); - if let Err(e) = join.join() { - error!("Error while waiting on background thread: {:?}", e); - } - } - } -} - -impl> SyncProvider for Service { +impl> SyncProvider for NetworkService { fn is_major_syncing(&self) -> bool { self.is_major_syncing() } @@ -394,7 +407,7 @@ impl> SyncProvider for Servi self.network.lock().state() } - fn peers(&self) -> Vec<(PeerId, PeerInfo)> { + fn peers_debug_info(&self) -> Vec<(PeerId, PeerInfo)> { let peers = (*self.peers.read()).clone(); peers.into_iter().map(|(idx, connected)| (idx, connected.peer_info)).collect() } @@ -412,7 +425,7 @@ pub trait ManageNetwork { fn add_reserved_peer(&self, peer: String) -> Result<(), String>; } -impl> ManageNetwork for Service { +impl> ManageNetwork for NetworkService { fn accept_unreserved_peers(&self) { self.peerset.set_reserved_only(false); } @@ -433,82 +446,7 @@ impl> ManageNetwork for Service } } - -/// Create a NetworkPort/Chan pair. -pub fn network_channel() -> (NetworkChan, NetworkPort) { - let (network_sender, network_receiver) = channel::unbounded(); - let task_notify = Arc::new(AtomicTask::new()); - let network_port = NetworkPort::new(network_receiver, task_notify.clone()); - let network_chan = NetworkChan::new(network_sender, task_notify); - (network_chan, network_port) -} - - -/// A sender of NetworkMsg that notifies a task when a message has been sent. -#[derive(Clone)] -pub struct NetworkChan { - sender: Sender>, - task_notify: Arc, -} - -impl NetworkChan { - /// Create a new network chan. - pub fn new(sender: Sender>, task_notify: Arc) -> Self { - NetworkChan { - sender, - task_notify, - } - } - - /// Send a messaging, to be handled on a stream. Notify the task handling the stream. - pub fn send(&self, msg: NetworkMsg) { - let _ = self.sender.send(msg); - self.task_notify.notify(); - } -} - -impl Drop for NetworkChan { - /// Notifying the task when a sender is dropped(when all are dropped, the stream is finished). - fn drop(&mut self) { - self.task_notify.notify(); - } -} - - -/// A receiver of NetworkMsg that makes the protocol-id available with each message. -pub struct NetworkPort { - receiver: Receiver>, - task_notify: Arc, -} - -impl NetworkPort { - /// Create a new network port for a given protocol-id. - pub fn new(receiver: Receiver>, task_notify: Arc) -> Self { - Self { - receiver, - task_notify, - } - } - - /// Receive a message, if any is currently-enqueued. - /// Register the current tokio task for notification when a new message is available. - pub fn take_one_message(&self) -> Result>, ()> { - self.task_notify.register(); - match self.receiver.try_recv() { - Ok(msg) => Ok(Some(msg)), - Err(TryRecvError::Empty) => Ok(None), - Err(TryRecvError::Disconnected) => Err(()), - } - } - - /// Get a reference to the underlying crossbeam receiver. - #[cfg(any(test, feature = "test-helpers"))] - pub fn receiver(&self) -> &Receiver> { - &self.receiver - } -} - -/// Messages to be handled by NetworkService. +/// Messages to be handled by Libp2pNetService. #[derive(Debug)] pub enum NetworkMsg { /// Send an outgoing custom message. @@ -551,9 +489,9 @@ pub enum ProtocolMsg> { /// A block has been finalized (sent by the client). BlockFinalized(B::Hash, B::Header), /// Execute a closure with the chain-specific network specialization. - ExecuteWithSpec(Box + Send + 'static>), + ExecuteWithSpec(Box + Send + 'static>), /// Execute a closure with the consensus gossip. - ExecuteWithGossip(Box + Send + 'static>), + ExecuteWithGossip(Box + Send + 'static>), /// Incoming gossip consensus message. GossipConsensusMessage(B::Hash, ConsensusEngineId, Vec, GossipMessageRecipient), /// Tell protocol to perform regular maintenance. @@ -566,193 +504,199 @@ pub enum ProtocolMsg> { /// A task, consisting of a user-provided closure, to be executed on the Protocol thread. pub trait SpecTask> { - fn call_box(self: Box, spec: &mut S, context: &mut Context); + fn call_box(self: Box, spec: &mut S, context: &mut dyn Context); } -impl, F: FnOnce(&mut S, &mut Context)> SpecTask for F { - fn call_box(self: Box, spec: &mut S, context: &mut Context) { +impl, F: FnOnce(&mut S, &mut dyn Context)> SpecTask for F { + fn call_box(self: Box, spec: &mut S, context: &mut dyn Context) { (*self)(spec, context) } } /// A task, consisting of a user-provided closure, to be executed on the Protocol thread. pub trait GossipTask { - fn call_box(self: Box, gossip: &mut ConsensusGossip, context: &mut Context); + fn call_box(self: Box, gossip: &mut ConsensusGossip, context: &mut dyn Context); } -impl, &mut Context)> GossipTask for F { - fn call_box(self: Box, gossip: &mut ConsensusGossip, context: &mut Context) { +impl, &mut dyn Context)> GossipTask for F { + fn call_box(self: Box, gossip: &mut ConsensusGossip, context: &mut dyn Context) { (*self)(gossip, context) } } -/// Starts the background thread that handles the networking. -fn start_thread, H: ExHashT>( +/// Future tied to the `Network` service and that must be polled in order for the network to +/// advance. +#[must_use = "The NetworkWorker must be polled in order for the network to work"] +pub struct NetworkWorker, H: ExHashT> { is_offline: Arc, is_major_syncing: Arc, protocol: Protocol, - import_queue: Box>, - network_port: NetworkPort, + /// The network service that can be extracted and shared through the codebase. + service: Arc>, + network_service: Arc>>>, + peers: Arc>>>, + import_queue: Box>, + transaction_pool: Arc>, + finality_proof_provider: Option>>, + network_port: mpsc::UnboundedReceiver>, protocol_rx: mpsc::UnboundedReceiver>, status_sinks: Arc>>>>, - config: NetworkConfiguration, - registered: RegisteredProtocol>, -) -> Result<((oneshot::Sender<()>, thread::JoinHandle<()>), Arc>>>, PeersetHandle), Error> { - // Start the main service. - let (service, peerset) = match start_service(config, registered) { - Ok((service, peerset)) => (Arc::new(Mutex::new(service)), peerset), - Err(err) => { - warn!("Error starting network: {}", err); - return Err(err.into()) - }, - }; - - let (close_tx, close_rx) = oneshot::channel(); - let service_clone = service.clone(); - let mut runtime = RuntimeBuilder::new().name_prefix("libp2p-").build()?; - let peerset_clone = peerset.clone(); - let thread = thread::Builder::new().name("network".to_string()).spawn(move || { - let fut = run_thread( - is_offline, - is_major_syncing, - protocol, - service_clone, - import_queue, - network_port, - protocol_rx, - status_sinks, - peerset_clone - ) - .select(close_rx.then(|_| Ok(()))) - .map(|(val, _)| val) - .map_err(|(err,_ )| err); - - // Note that we use `block_on` and not `block_on_all` because we want to kill the thread - // instantly if `close_rx` receives something. - match runtime.block_on(fut) { - Ok(()) => debug!(target: "sub-libp2p", "Networking thread finished"), - Err(err) => error!(target: "sub-libp2p", "Error while running libp2p: {:?}", err), - }; - })?; + peerset: PeersetHandle, + on_demand_in: Option>>, - Ok(((close_tx, thread), service, peerset)) + /// Interval at which we send status updates on the `status_sinks`. + status_interval: tokio_timer::Interval, + /// Interval at which we update the `connected_peers` Arc. + connected_peers_interval: tokio_timer::Interval, } -/// Runs the background thread that handles the networking. -fn run_thread, H: ExHashT>( - is_offline: Arc, - is_major_syncing: Arc, - mut protocol: Protocol, - network_service: Arc>>>, - import_queue: Box>, - network_port: NetworkPort, - mut protocol_rx: mpsc::UnboundedReceiver>, - status_sinks: Arc>>>>, - peerset: PeersetHandle, -) -> impl Future { - // Interval at which we send status updates on the `status_sinks`. - let mut status_interval = tokio::timer::Interval::new_interval(STATUS_INTERVAL); - - futures::future::poll_fn(move || { - while let Ok(Async::Ready(_)) = status_interval.poll() { - let status = protocol.status(); - status_sinks.lock().retain(|sink| sink.unbounded_send(status.clone()).is_ok()); +impl, H: ExHashT> Future for NetworkWorker { + type Item = (); + type Error = io::Error; + + fn poll(&mut self) -> Poll { + // Implementation of `protocol::NetworkOut` using the available local variables. + struct Context<'a, B: BlockT>(&'a mut Libp2pNetService>, &'a PeersetHandle); + impl<'a, B: BlockT> NetworkOut for Context<'a, B> { + fn report_peer(&mut self, who: PeerId, reputation: i32) { + self.1.report_peer(who, reputation) + } + fn disconnect_peer(&mut self, who: PeerId) { + self.0.drop_node(&who) + } + fn send_message(&mut self, who: PeerId, message: Message) { + self.0.send_custom_message(&who, message) + } + } + + while let Ok(Async::Ready(_)) = self.status_interval.poll() { + let status = self.protocol.status(); + self.status_sinks.lock().retain(|sink| sink.unbounded_send(status.clone()).is_ok()); + } + + while let Ok(Async::Ready(_)) = self.connected_peers_interval.poll() { + let infos = self.protocol.peers_info().map(|(id, info)| { + (id.clone(), ConnectedPeer { peer_info: info.clone() }) + }).collect(); + *self.peers.write() = infos; } - match protocol.poll() { - Ok(Async::Ready(())) => return Ok(Async::Ready(())), + match self.protocol.poll(&mut Context(&mut self.network_service.lock(), &self.peerset), &*self.transaction_pool) { + Ok(Async::Ready(v)) => void::unreachable(v), Ok(Async::NotReady) => {} Err(err) => void::unreachable(err), } + // Check for new incoming on-demand requests. + if let Some(on_demand_in) = self.on_demand_in.as_mut() { + while let Ok(Async::Ready(Some(rq))) = on_demand_in.poll() { + self.protocol.add_on_demand_request(&mut Context(&mut self.network_service.lock(), &self.peerset), rq); + } + } + loop { - match network_port.take_one_message() { - Ok(None) => break, - Ok(Some(NetworkMsg::Outgoing(who, outgoing_message))) => - network_service.lock().send_custom_message(&who, outgoing_message), - Ok(Some(NetworkMsg::ReportPeer(who, reputation))) => - peerset.report_peer(who, reputation), - Ok(Some(NetworkMsg::DisconnectPeer(who))) => - network_service.lock().drop_node(&who), + match self.network_port.poll() { + Ok(Async::NotReady) => break, + Ok(Async::Ready(Some(NetworkMsg::Outgoing(who, outgoing_message)))) => + self.network_service.lock().send_custom_message(&who, outgoing_message), + Ok(Async::Ready(Some(NetworkMsg::ReportPeer(who, reputation)))) => + self.peerset.report_peer(who, reputation), + Ok(Async::Ready(Some(NetworkMsg::DisconnectPeer(who)))) => + self.network_service.lock().drop_node(&who), + #[cfg(any(test, feature = "test-helpers"))] - Ok(Some(NetworkMsg::Synchronized)) => {} + Ok(Async::Ready(Some(NetworkMsg::Synchronized))) => {} - Err(_) => return Ok(Async::Ready(())), + Ok(Async::Ready(None)) | Err(_) => return Ok(Async::Ready(())), } } loop { - let msg = match protocol_rx.poll() { + let msg = match self.protocol_rx.poll() { Ok(Async::Ready(Some(msg))) => msg, Ok(Async::Ready(None)) | Err(_) => return Ok(Async::Ready(())), Ok(Async::NotReady) => break, }; + let mut network_service = self.network_service.lock(); + let mut network_out = Context(&mut network_service, &self.peerset); + match msg { ProtocolMsg::BlockImported(hash, header) => - protocol.on_block_imported(hash, &header), + self.protocol.on_block_imported(&mut network_out, hash, &header), ProtocolMsg::BlockFinalized(hash, header) => - protocol.on_block_finalized(hash, &header), + self.protocol.on_block_finalized(&mut network_out, hash, &header), ProtocolMsg::ExecuteWithSpec(task) => { - let (mut context, spec) = protocol.specialization_lock(); + let (mut context, spec) = self.protocol.specialization_lock(&mut network_out); task.call_box(spec, &mut context); }, ProtocolMsg::ExecuteWithGossip(task) => { - let (mut context, gossip) = protocol.consensus_gossip_lock(); + let (mut context, gossip) = self.protocol.consensus_gossip_lock(&mut network_out); task.call_box(gossip, &mut context); } ProtocolMsg::GossipConsensusMessage(topic, engine_id, message, recipient) => - protocol.gossip_consensus_message(topic, engine_id, message, recipient), + self.protocol.gossip_consensus_message(&mut network_out, topic, engine_id, message, recipient), ProtocolMsg::BlocksProcessed(hashes, has_error) => - protocol.blocks_processed(hashes, has_error), - ProtocolMsg::RestartSync => - protocol.restart(), + self.protocol.blocks_processed(&mut network_out, hashes, has_error), + ProtocolMsg::RestartSync => + self.protocol.restart(&mut network_out), ProtocolMsg::AnnounceBlock(hash) => - protocol.announce_block(hash), + self.protocol.announce_block(&mut network_out, hash), ProtocolMsg::BlockImportedSync(hash, number) => - protocol.block_imported(&hash, number), + self.protocol.block_imported(&hash, number), ProtocolMsg::ClearJustificationRequests => - protocol.clear_justification_requests(), + self.protocol.clear_justification_requests(), ProtocolMsg::RequestJustification(hash, number) => - protocol.request_justification(&hash, number), + self.protocol.request_justification(&mut network_out, &hash, number), ProtocolMsg::JustificationImportResult(hash, number, success) => - protocol.justification_import_result(hash, number, success), + self.protocol.justification_import_result(hash, number, success), ProtocolMsg::SetFinalityProofRequestBuilder(builder) => - protocol.set_finality_proof_request_builder(builder), + self.protocol.set_finality_proof_request_builder(builder), ProtocolMsg::RequestFinalityProof(hash, number) => - protocol.request_finality_proof(&hash, number), + self.protocol.request_finality_proof(&mut network_out, &hash, number), ProtocolMsg::FinalityProofImportResult(requested_block, finalziation_result) => - protocol.finality_proof_import_result(requested_block, finalziation_result), - ProtocolMsg::PropagateExtrinsics => protocol.propagate_extrinsics(), + self.protocol.finality_proof_import_result(requested_block, finalziation_result), + ProtocolMsg::PropagateExtrinsics => + self.protocol.propagate_extrinsics(&mut network_out, &*self.transaction_pool), #[cfg(any(test, feature = "test-helpers"))] - ProtocolMsg::Tick => protocol.tick(), + ProtocolMsg::Tick => self.protocol.tick(&mut network_out), #[cfg(any(test, feature = "test-helpers"))] - ProtocolMsg::Synchronize => protocol.synchronize(), + ProtocolMsg::Synchronize => {}, } } loop { - let outcome = match network_service.lock().poll() { + let mut network_service = self.network_service.lock(); + let poll_value = network_service.poll(); + let mut network_out = Context(&mut network_service, &self.peerset); + + let outcome = match poll_value { Ok(Async::NotReady) => break, - Ok(Async::Ready(Some(NetworkServiceEvent::OpenedCustomProtocol { peer_id, version, debug_info, .. }))) => { + Ok(Async::Ready(Some(Libp2pNetServiceEvent::OpenedCustomProtocol { peer_id, version, debug_info, .. }))) => { debug_assert!( version <= protocol::CURRENT_VERSION as u8 && version >= protocol::MIN_VERSION as u8 ); - protocol.on_peer_connected(peer_id, debug_info); + self.protocol.on_peer_connected(&mut network_out, peer_id, debug_info); CustomMessageOutcome::None } - Ok(Async::Ready(Some(NetworkServiceEvent::ClosedCustomProtocol { peer_id, debug_info, .. }))) => { - protocol.on_peer_disconnected(peer_id, debug_info); + Ok(Async::Ready(Some(Libp2pNetServiceEvent::ClosedCustomProtocol { peer_id, debug_info, .. }))) => { + self.protocol.on_peer_disconnected(&mut network_out, peer_id, debug_info); CustomMessageOutcome::None }, - Ok(Async::Ready(Some(NetworkServiceEvent::CustomMessage { peer_id, message, .. }))) => - protocol.on_custom_message(peer_id, message), - Ok(Async::Ready(Some(NetworkServiceEvent::Clogged { peer_id, messages, .. }))) => { + Ok(Async::Ready(Some(Libp2pNetServiceEvent::CustomMessage { peer_id, message, .. }))) => + self.protocol.on_custom_message( + &mut network_out, + &*self.transaction_pool, + peer_id, + message, + self.finality_proof_provider.as_ref().map(|p| &**p) + ), + Ok(Async::Ready(Some(Libp2pNetServiceEvent::Clogged { peer_id, messages, .. }))) => { debug!(target: "sync", "{} clogging messages:", messages.len()); for msg in messages.into_iter().take(5) { debug!(target: "sync", "{:?}", msg); - protocol.on_clogged_peer(peer_id.clone(), Some(msg)); + self.protocol.on_clogged_peer(&mut network_out, peer_id.clone(), Some(msg)); } CustomMessageOutcome::None } @@ -765,18 +709,18 @@ fn run_thread, H: ExHashT>( match outcome { CustomMessageOutcome::BlockImport(origin, blocks) => - import_queue.import_blocks(origin, blocks), + self.import_queue.import_blocks(origin, blocks), CustomMessageOutcome::JustificationImport(origin, hash, nb, justification) => - import_queue.import_justification(origin, hash, nb, justification), + self.import_queue.import_justification(origin, hash, nb, justification), CustomMessageOutcome::FinalityProofImport(origin, hash, nb, proof) => - import_queue.import_finality_proof(origin, hash, nb, proof), + self.import_queue.import_finality_proof(origin, hash, nb, proof), CustomMessageOutcome::None => {} } } - is_offline.store(protocol.is_offline(), Ordering::Relaxed); - is_major_syncing.store(protocol.is_major_syncing(), Ordering::Relaxed); + self.is_offline.store(self.protocol.is_offline(), Ordering::Relaxed); + self.is_major_syncing.store(self.protocol.is_major_syncing(), Ordering::Relaxed); Ok(Async::NotReady) - }) + } } diff --git a/core/network/src/test/block_import.rs b/core/network/src/test/block_import.rs index 550d3c75ed0ef9815d67fe1cc770317a1c485386..f10338a62d72c2cf155992cd709a32b49854e13f 100644 --- a/core/network/src/test/block_import.rs +++ b/core/network/src/test/block_import.rs @@ -17,7 +17,7 @@ //! Testing block import logic. use consensus::import_queue::{import_single_block, BasicQueue, BlockImportError, BlockImportResult}; -use test_client::{self, TestClient}; +use test_client::{self, prelude::*}; use test_client::runtime::{Block, Hash}; use runtime_primitives::generic::BlockId; use super::*; @@ -26,9 +26,9 @@ struct TestLink {} impl Link for TestLink {} -fn prepare_good_block() -> (client::Client, Hash, u64, PeerId, IncomingBlock) { +fn prepare_good_block() -> (TestClient, Hash, u64, PeerId, IncomingBlock) { let client = test_client::new(); - let block = client.new_block().unwrap().bake().unwrap(); + let block = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::File, block).unwrap(); let (hash, number) = (client.block_hash(1).unwrap().unwrap(), 1); diff --git a/core/network/src/test/mod.rs b/core/network/src/test/mod.rs index 44e0eafd9127fa46bfb9910abcef811f526ec1a1..b27214d07b0af1c25ec5523c17dad0a3a71c1e37 100644 --- a/core/network/src/test/mod.rs +++ b/core/network/src/test/mod.rs @@ -24,31 +24,32 @@ mod sync; use std::collections::{HashMap, HashSet, VecDeque}; use std::sync::Arc; +use crate::AlwaysBadChecker; use log::trace; use crate::chain::FinalityProofProvider; -use client::{self, ClientInfo, BlockchainEvents, FinalityNotifications, in_mem::Backend as InMemoryBackend, error::Result as ClientResult}; +use client::{self, ClientInfo, BlockchainEvents, FinalityNotifications}; +use client::{in_mem::Backend as InMemoryBackend, error::Result as ClientResult}; use client::block_builder::BlockBuilder; use client::backend::AuxStore; -use crate::config::{ProtocolConfig, Roles}; +use crate::config::Roles; use consensus::import_queue::{BasicQueue, ImportQueue, IncomingBlock}; use consensus::import_queue::{ Link, SharedBlockImport, SharedJustificationImport, Verifier, SharedFinalityProofImport, SharedFinalityProofRequestBuilder, }; -use consensus::{Error as ConsensusError, ErrorKind as ConsensusErrorKind}; +use consensus::{Error as ConsensusError}; use consensus::{BlockOrigin, ForkChoiceStrategy, ImportBlock, JustificationImport}; use crate::consensus_gossip::{ConsensusGossip, MessageRecipient as GossipMessageRecipient, TopicNotification}; -use crossbeam_channel::RecvError; use futures::{prelude::*, sync::{mpsc, oneshot}}; use crate::message::Message; use network_libp2p::PeerId; use parking_lot::{Mutex, RwLock}; use primitives::{H256, sr25519::Public as AuthorityId, Blake2Hasher}; -use crate::protocol::{ConnectedPeer, Context, Protocol, ProtocolStatus, CustomMessageOutcome}; +use crate::protocol::{Context, Protocol, ProtocolConfig, ProtocolStatus, CustomMessageOutcome, NetworkOut}; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{AuthorityIdFor, Block as BlockT, Digest, DigestItem, Header, NumberFor}; use runtime_primitives::{Justification, ConsensusEngineId}; -use crate::service::{network_channel, NetworkChan, NetworkLink, NetworkMsg, NetworkPort, ProtocolMsg, TransactionPool}; +use crate::service::{NetworkLink, NetworkMsg, ProtocolMsg, TransactionPool}; use crate::specialization::NetworkSpecialization; use test_client::{self, AccountKeyring}; @@ -100,23 +101,27 @@ impl NetworkSpecialization for DummySpecialization { vec![] } - fn on_connect(&mut self, _ctx: &mut Context, _peer_id: PeerId, _status: crate::message::Status) { - } + fn on_connect( + &mut self, + _ctx: &mut dyn Context, + _peer_id: PeerId, + _status: crate::message::Status + ) {} - fn on_disconnect(&mut self, _ctx: &mut Context, _peer_id: PeerId) { - } + fn on_disconnect(&mut self, _ctx: &mut dyn Context, _peer_id: PeerId) {} fn on_message( &mut self, - _ctx: &mut Context, + _ctx: &mut dyn Context, _peer_id: PeerId, _message: &mut Option>, - ) { - } + ) {} } -pub type PeersFullClient = client::Client; -pub type PeersLightClient = client::Client; +pub type PeersFullClient = + client::Client; +pub type PeersLightClient = + client::Client; #[derive(Clone)] pub enum PeersClient { @@ -140,6 +145,7 @@ impl PeersClient { } pub fn as_in_memory_backend(&self) -> InMemoryBackend { + #[allow(deprecated)] match *self { PeersClient::Full(ref client) => client.backend().as_in_memory(), PeersClient::Light(_) => unimplemented!("TODO"), @@ -147,13 +153,14 @@ impl PeersClient { } pub fn get_aux(&self, key: &[u8]) -> ClientResult>> { + #[allow(deprecated)] match *self { PeersClient::Full(ref client) => client.backend().get_aux(key), PeersClient::Light(ref client) => client.backend().get_aux(key), } } - pub fn info(&self) -> ClientResult> { + pub fn info(&self) -> ClientInfo { match *self { PeersClient::Full(ref client) => client.info(), PeersClient::Light(ref client) => client.info(), @@ -181,7 +188,12 @@ impl PeersClient { } } - pub fn finalize_block(&self, id: BlockId, justification: Option, notify: bool) -> ClientResult<()> { + pub fn finalize_block( + &self, + id: BlockId, + justification: Option, + notify: bool + ) -> ClientResult<()> { match *self { PeersClient::Full(ref client) => client.finalize_block(id, justification, notify), PeersClient::Light(ref client) => client.finalize_block(id, justification, notify), @@ -201,7 +213,7 @@ impl> TestLink { fn new( protocol_sender: mpsc::UnboundedSender>, _network_to_protocol_sender: mpsc::UnboundedSender>, - network_sender: NetworkChan + network_sender: mpsc::UnboundedSender> ) -> TestLink { TestLink { #[cfg(any(test, feature = "test-helpers"))] @@ -267,18 +279,21 @@ impl> Link for TestLink { } pub struct Peer> { - pub peers: Arc>>>, - pub peer_id: PeerId, + peer_id: PeerId, client: PeersClient, net_proto_channel: ProtocolChannel, + /// This field is used only in test code, but maintaining different + /// instantiation paths or field names is too much hassle, hence + /// we allow it to be unused. + #[cfg_attr(not(test), allow(unused))] protocol_status: Arc>>, - pub import_queue: Box>, + import_queue: Box>, pub data: D, best_hash: Mutex>, finalized_hash: Mutex>, } -type MessageFilter = Fn(&NetworkMsg) -> bool; +type MessageFilter = dyn Fn(&NetworkMsg) -> bool; pub enum FromNetworkMsg { /// A peer connected, with debug info. @@ -292,24 +307,28 @@ pub enum FromNetworkMsg { } struct ProtocolChannel> { + /// If true, we expect a tokio executor to be available. If false, we spawn our own. + use_tokio: bool, buffered_messages: Mutex>>, network_to_protocol_sender: mpsc::UnboundedSender>, client_to_protocol_sender: mpsc::UnboundedSender>, - protocol_to_network_receiver: NetworkPort, + protocol_to_network_receiver: Mutex>>, } impl> ProtocolChannel { /// Create new buffered network port. pub fn new( + use_tokio: bool, network_to_protocol_sender: mpsc::UnboundedSender>, client_to_protocol_sender: mpsc::UnboundedSender>, - protocol_to_network_receiver: NetworkPort, + protocol_to_network_receiver: mpsc::UnboundedReceiver>, ) -> Self { ProtocolChannel { + use_tokio, buffered_messages: Mutex::new(VecDeque::new()), network_to_protocol_sender, client_to_protocol_sender, - protocol_to_network_receiver, + protocol_to_network_receiver: Mutex::new(protocol_to_network_receiver), } } @@ -330,13 +349,23 @@ impl> ProtocolChannel { } /// Wait until synchronization response is generated by the protocol. - pub fn wait_sync(&self) -> Result<(), RecvError> { - loop { - match self.protocol_to_network_receiver.receiver().recv() { - Ok(NetworkMsg::Synchronized) => return Ok(()), - Err(error) => return Err(error), - Ok(msg) => self.buffered_messages.lock().push_back(msg), + pub fn wait_sync(&self) -> Result<(), ()> { + let fut = futures::future::poll_fn(|| { + loop { + let mut protocol_to_network_receiver = self.protocol_to_network_receiver.lock(); + match protocol_to_network_receiver.poll() { + Ok(Async::Ready(Some(NetworkMsg::Synchronized))) => return Ok(Async::Ready(())), + Ok(Async::Ready(None)) | Err(_) => return Err(()), + Ok(Async::NotReady) => return Ok(Async::NotReady), + Ok(Async::Ready(Some(msg))) => self.buffered_messages.lock().push_back(msg), + } } + }); + + if self.use_tokio { + fut.wait() + } else { + tokio::runtime::current_thread::block_on_all(fut) } } @@ -359,8 +388,13 @@ impl> ProtocolChannel { /// Whether this peer is done syncing (has no messages to send). fn is_done(&self) -> bool { - self.buffered_messages.lock().is_empty() - && self.protocol_to_network_receiver.receiver().is_empty() + let mut buffered_messages = self.buffered_messages.lock(); + if let Some(msg) = self.channel_message() { + buffered_messages.push_back(msg); + false + } else { + buffered_messages.is_empty() + } } /// Return oldest buffered message if it exists. @@ -377,23 +411,37 @@ impl> ProtocolChannel { /// Receive message from the channel. fn channel_message(&self) -> Option> { - self.protocol_to_network_receiver.receiver().try_recv().ok() + let fut = futures::future::poll_fn(|| -> Result<_, ()> { + Ok(Async::Ready(match self.protocol_to_network_receiver.lock().poll() { + Ok(Async::Ready(Some(m))) => Some(m), + Ok(Async::NotReady) => None, + Err(_) => None, + Ok(Async::Ready(None)) => None, + })) + }); + + if self.use_tokio { + fut.wait() + } else { + tokio::runtime::current_thread::block_on_all(fut) + }.ok().and_then(|a| a) } } impl> Peer { fn new( protocol_status: Arc>>, - peers: Arc>>>, client: PeersClient, import_queue: Box>, + use_tokio: bool, network_to_protocol_sender: mpsc::UnboundedSender>, protocol_sender: mpsc::UnboundedSender>, - network_sender: NetworkChan, - network_port: NetworkPort, + network_sender: mpsc::UnboundedSender>, + network_port: mpsc::UnboundedReceiver>, data: D, ) -> Self { let net_proto_channel = ProtocolChannel::new( + use_tokio, network_to_protocol_sender.clone(), protocol_sender.clone(), network_port, @@ -406,7 +454,6 @@ impl> Peer { import_queue.start(Box::new(network_link)).expect("Test ImportQueue always starts"); Peer { protocol_status, - peers, peer_id: PeerId::random(), client, import_queue, @@ -417,9 +464,9 @@ impl> Peer { } } /// Called after blockchain has been populated to updated current state. - pub fn start(&self) { + fn start(&self) { // Update the sync state to the latest chain state. - let info = self.client.info().expect("In-mem client does not fail"); + let info = self.client.info(); let header = self .client .header(&BlockId::Hash(info.chain.best_hash)) @@ -428,7 +475,8 @@ impl> Peer { self.net_proto_channel.send_from_client(ProtocolMsg::BlockImported(info.chain.best_hash, header)); } - pub fn on_block_imported( + #[cfg(test)] + fn on_block_imported( &self, hash: ::Hash, header: &::Header, @@ -438,18 +486,19 @@ impl> Peer { /// SyncOracle: are we connected to any peer? #[cfg(test)] - pub fn is_offline(&self) -> bool { + fn is_offline(&self) -> bool { self.protocol_status.read().sync.is_offline() } /// SyncOracle: are we in the process of catching-up with the chain? #[cfg(test)] - pub fn is_major_syncing(&self) -> bool { + fn is_major_syncing(&self) -> bool { self.protocol_status.read().sync.is_major_syncing() } /// Get protocol status. - pub fn protocol_status(&self) -> ProtocolStatus { + #[cfg(test)] + fn protocol_status(&self) -> ProtocolStatus { self.protocol_status.read().clone() } @@ -480,7 +529,7 @@ impl> Peer { /// Synchronize with import queue. #[cfg(any(test, feature = "test-helpers"))] - fn import_queue_sync(&self) { + pub fn import_queue_sync(&self) { self.import_queue.synchronize(); let _ = self.net_proto_channel.wait_sync(); } @@ -492,7 +541,7 @@ impl> Peer { /// Send block import notifications. fn send_import_notifications(&self) { - let info = self.client.info().expect("In-mem client does not fail"); + let info = self.client.info(); let mut best_hash = self.best_hash.lock(); match *best_hash { @@ -507,8 +556,8 @@ impl> Peer { } /// Send block finalization notifications. - pub fn send_finality_notifications(&self) { - let info = self.client.info().expect("In-mem client does not fail"); + fn send_finality_notifications(&self) { + let info = self.client.info(); let mut finalized_hash = self.finalized_hash.lock(); match *finalized_hash { @@ -543,10 +592,6 @@ impl> Peer { ); } - pub fn consensus_gossip_collect_garbage_for_topic(&self, _topic: ::Hash) { - self.with_gossip(move |gossip, _| gossip.collect_garbage()) - } - /// access the underlying consensus gossip handler pub fn consensus_gossip_messages_for( &self, @@ -563,13 +608,14 @@ impl> Peer { /// Execute a closure with the consensus gossip. pub fn with_gossip(&self, f: F) - where F: FnOnce(&mut ConsensusGossip, &mut Context) + Send + 'static + where F: FnOnce(&mut ConsensusGossip, &mut dyn Context) + Send + 'static { self.net_proto_channel.send_from_client(ProtocolMsg::ExecuteWithGossip(Box::new(f))); } /// Announce a block to peers. - pub fn announce_block(&self, block: Hash) { + #[cfg(test)] + fn announce_block(&self, block: Hash) { self.net_proto_channel.send_from_client(ProtocolMsg::AnnounceBlock(block)); } @@ -583,19 +629,24 @@ impl> Peer { pub fn generate_blocks(&self, count: usize, origin: BlockOrigin, edit_block: F) -> H256 where F: FnMut(BlockBuilder) -> Block { - let best_hash = self.client.info().unwrap().chain.best_hash; + let best_hash = self.client.info().chain.best_hash; self.generate_blocks_at(BlockId::Hash(best_hash), count, origin, edit_block) } /// Add blocks to the peer -- edit the block before adding. The chain will /// start at the given block iD. - pub fn generate_blocks_at(&self, at: BlockId, count: usize, origin: BlockOrigin, mut edit_block: F) -> H256 - where F: FnMut(BlockBuilder) -> Block - { + fn generate_blocks_at( + &self, + at: BlockId, + count: usize, + origin: BlockOrigin, + mut edit_block: F + ) -> H256 where F: FnMut(BlockBuilder) -> Block { let full_client = self.client.as_full().expect("blocks could only be generated by full clients"); let mut at = full_client.header(&at).unwrap().unwrap().hash(); for _ in 0..count { - let builder = full_client.new_block_at(&BlockId::Hash(at)).unwrap(); + let builder = full_client.new_block_at(&BlockId::Hash(at), Default::default() + ).unwrap(); let block = edit_block(builder); let hash = block.header.hash(); trace!( @@ -627,7 +678,7 @@ impl> Peer { /// Push blocks to the peer (simplified: with or without a TX) pub fn push_blocks(&self, count: usize, with_tx: bool) -> H256 { - let best_hash = self.client.info().unwrap().chain.best_hash; + let best_hash = self.client.info().chain.best_hash; self.push_blocks_at(BlockId::Hash(best_hash), count, with_tx) } @@ -720,7 +771,7 @@ pub trait TestNetFactory: Sized { } /// Get finality proof provider (if supported). - fn make_finality_proof_provider(&self, _client: PeersClient) -> Option>> { + fn make_finality_proof_provider(&self, _client: PeersClient) -> Option>> { None } @@ -728,6 +779,11 @@ pub trait TestNetFactory: Sized { ProtocolConfig::default() } + /// Must return true if the testnet is going to be used from within a tokio context. + fn uses_tokio(&self) -> bool { + false + } + /// Create new test network with this many peers. fn new(n: usize) -> Self { trace!(target: "test_network", "Creating test network"); @@ -746,27 +802,50 @@ pub trait TestNetFactory: Sized { &mut self, protocol_status: Arc>>, import_queue: Box>, + tx_pool: EmptyTransactionPool, + finality_proof_provider: Option>>, mut protocol: Protocol, + network_sender: mpsc::UnboundedSender>, mut network_to_protocol_rx: mpsc::UnboundedReceiver>, mut protocol_rx: mpsc::UnboundedReceiver>, peer: Arc>, ) { std::thread::spawn(move || { + // Implementation of `protocol::NetworkOut` using the available local variables. + struct Ctxt<'a, B: BlockT>(&'a mpsc::UnboundedSender>); + impl<'a, B: BlockT> NetworkOut for Ctxt<'a, B> { + fn report_peer(&mut self, who: PeerId, reputation: i32) { + let _ = self.0.unbounded_send(NetworkMsg::ReportPeer(who, reputation)); + } + fn disconnect_peer(&mut self, who: PeerId) { + let _ = self.0.unbounded_send(NetworkMsg::DisconnectPeer(who)); + } + fn send_message(&mut self, who: PeerId, message: Message) { + let _ = self.0.unbounded_send(NetworkMsg::Outgoing(who, message)); + } + } + tokio::runtime::current_thread::run(futures::future::poll_fn(move || { while let Async::Ready(msg) = network_to_protocol_rx.poll().unwrap() { let outcome = match msg { Some(FromNetworkMsg::PeerConnected(peer_id, debug_msg)) => { - protocol.on_peer_connected(peer_id, debug_msg); + protocol.on_peer_connected(&mut Ctxt(&network_sender), peer_id, debug_msg); CustomMessageOutcome::None }, Some(FromNetworkMsg::PeerDisconnected(peer_id, debug_msg)) => { - protocol.on_peer_disconnected(peer_id, debug_msg); + protocol.on_peer_disconnected(&mut Ctxt(&network_sender), peer_id, debug_msg); CustomMessageOutcome::None }, Some(FromNetworkMsg::CustomMessage(peer_id, message)) => - protocol.on_custom_message(peer_id, message), + protocol.on_custom_message( + &mut Ctxt(&network_sender), + &tx_pool, + peer_id, + message, + finality_proof_provider.as_ref().map(|p| &**p) + ), Some(FromNetworkMsg::Synchronize) => { - protocol.synchronize(); + let _ = network_sender.unbounded_send(NetworkMsg::Synchronized); CustomMessageOutcome::None }, None => return Ok(Async::Ready(())), @@ -792,51 +871,60 @@ pub trait TestNetFactory: Sized { match msg { ProtocolMsg::BlockImported(hash, header) => - protocol.on_block_imported(hash, &header), + protocol.on_block_imported(&mut Ctxt(&network_sender), hash, &header), ProtocolMsg::BlockFinalized(hash, header) => - protocol.on_block_finalized(hash, &header), + protocol.on_block_finalized(&mut Ctxt(&network_sender), hash, &header), ProtocolMsg::ExecuteWithSpec(task) => { - let (mut context, spec) = protocol.specialization_lock(); + let mut ctxt = Ctxt(&network_sender); + let (mut context, spec) = protocol.specialization_lock(&mut ctxt); task.call_box(spec, &mut context); }, ProtocolMsg::ExecuteWithGossip(task) => { - let (mut context, gossip) = protocol.consensus_gossip_lock(); + let mut ctxt = Ctxt(&network_sender); + let (mut context, gossip) = protocol.consensus_gossip_lock(&mut ctxt); task.call_box(gossip, &mut context); } ProtocolMsg::GossipConsensusMessage(topic, engine_id, message, recipient) => - protocol.gossip_consensus_message(topic, engine_id, message, recipient), + protocol.gossip_consensus_message( + &mut Ctxt(&network_sender), + topic, + engine_id, + message, + recipient + ), ProtocolMsg::BlocksProcessed(hashes, has_error) => - protocol.blocks_processed(hashes, has_error), - ProtocolMsg::RestartSync => - protocol.restart(), + protocol.blocks_processed(&mut Ctxt(&network_sender), hashes, has_error), + ProtocolMsg::RestartSync => + protocol.restart(&mut Ctxt(&network_sender)), ProtocolMsg::AnnounceBlock(hash) => - protocol.announce_block(hash), + protocol.announce_block(&mut Ctxt(&network_sender), hash), ProtocolMsg::BlockImportedSync(hash, number) => protocol.block_imported(&hash, number), ProtocolMsg::ClearJustificationRequests => protocol.clear_justification_requests(), ProtocolMsg::RequestJustification(hash, number) => - protocol.request_justification(&hash, number), + protocol.request_justification(&mut Ctxt(&network_sender), &hash, number), ProtocolMsg::JustificationImportResult(hash, number, success) => protocol.justification_import_result(hash, number, success), ProtocolMsg::SetFinalityProofRequestBuilder(builder) => protocol.set_finality_proof_request_builder(builder), ProtocolMsg::RequestFinalityProof(hash, number) => - protocol.request_finality_proof(&hash, number), + protocol.request_finality_proof(&mut Ctxt(&network_sender), &hash, number), ProtocolMsg::FinalityProofImportResult(requested_block, finalziation_result) => protocol.finality_proof_import_result(requested_block, finalziation_result), - ProtocolMsg::PropagateExtrinsics => protocol.propagate_extrinsics(), + ProtocolMsg::PropagateExtrinsics => + protocol.propagate_extrinsics(&mut Ctxt(&network_sender), &tx_pool), #[cfg(any(test, feature = "test-helpers"))] - ProtocolMsg::Tick => protocol.tick(), + ProtocolMsg::Tick => protocol.tick(&mut Ctxt(&network_sender)), #[cfg(any(test, feature = "test-helpers"))] ProtocolMsg::Synchronize => { trace!(target: "sync", "handle_client_msg: received Synchronize msg"); - protocol.synchronize(); + let _ = network_sender.unbounded_send(NetworkMsg::Synchronized); } } } - if let Async::Ready(_) = protocol.poll().unwrap() { + if let Async::Ready(_) = protocol.poll(&mut Ctxt(&network_sender), &tx_pool).unwrap() { return Ok(Async::Ready(())) } @@ -861,11 +949,10 @@ pub trait TestNetFactory: Sized { /// Add a full peer. fn add_full_peer(&mut self, config: &ProtocolConfig) { let client = Arc::new(test_client::new()); - let tx_pool = Arc::new(EmptyTransactionPool); let verifier = self.make_verifier(PeersClient::Full(client.clone()), config); let (block_import, justification_import, finality_proof_import, finality_proof_request_builder, data) = self.make_block_import(PeersClient::Full(client.clone())); - let (network_sender, network_port) = network_channel(); + let (network_sender, network_port) = mpsc::unbounded(); let import_queue = Box::new(BasicQueue::new( verifier, @@ -875,19 +962,14 @@ pub trait TestNetFactory: Sized { finality_proof_request_builder, )); let specialization = self::SpecializationFactory::create(); - let peers: Arc>>> = Arc::new(Default::default()); let (network_to_protocol_sender, network_to_protocol_rx) = mpsc::unbounded(); let (protocol_sender, protocol_rx) = mpsc::unbounded(); let protocol = Protocol::new( - peers.clone(), - network_sender.clone(), config.clone(), client.clone(), - self.make_finality_proof_provider(PeersClient::Full(client.clone())), - None, - tx_pool, + Arc::new(AlwaysBadChecker), specialization, ).unwrap(); @@ -895,14 +977,17 @@ pub trait TestNetFactory: Sized { self.add_peer( protocol_status.clone(), import_queue.clone(), + EmptyTransactionPool, + self.make_finality_proof_provider(PeersClient::Full(client.clone())), protocol, + network_sender.clone(), network_to_protocol_rx, protocol_rx, Arc::new(Peer::new( protocol_status, - peers, PeersClient::Full(client), import_queue, + self.uses_tokio(), network_to_protocol_sender, protocol_sender, network_sender, @@ -918,11 +1003,10 @@ pub trait TestNetFactory: Sized { config.roles = Roles::LIGHT; let client = Arc::new(test_client::new_light()); - let tx_pool = Arc::new(EmptyTransactionPool); let verifier = self.make_verifier(PeersClient::Light(client.clone()), &config); let (block_import, justification_import, finality_proof_import, finality_proof_request_builder, data) = self.make_block_import(PeersClient::Light(client.clone())); - let (network_sender, network_port) = network_channel(); + let (network_sender, network_port) = mpsc::unbounded(); let import_queue = Box::new(BasicQueue::new( verifier, @@ -932,19 +1016,14 @@ pub trait TestNetFactory: Sized { finality_proof_request_builder, )); let specialization = self::SpecializationFactory::create(); - let peers: Arc>>> = Arc::new(Default::default()); let (network_to_protocol_sender, network_to_protocol_rx) = mpsc::unbounded(); let (protocol_sender, protocol_rx) = mpsc::unbounded(); let protocol = Protocol::new( - peers.clone(), - network_sender.clone(), config, client.clone(), - self.make_finality_proof_provider(PeersClient::Light(client.clone())), - None, - tx_pool, + Arc::new(AlwaysBadChecker), specialization, ).unwrap(); @@ -952,14 +1031,17 @@ pub trait TestNetFactory: Sized { self.add_peer( protocol_status.clone(), import_queue.clone(), + EmptyTransactionPool, + self.make_finality_proof_provider(PeersClient::Light(client.clone())), protocol, + network_sender.clone(), network_to_protocol_rx, protocol_rx, Arc::new(Peer::new( protocol_status, - peers, PeersClient::Light(client), import_queue, + self.uses_tokio(), network_to_protocol_sender, protocol_sender, network_sender, @@ -1158,7 +1240,7 @@ impl JustificationImport for ForceFinalized { justification: Justification, ) -> Result<(), Self::Error> { self.0.finalize_block(BlockId::Hash(hash), Some(justification), true) - .map_err(|_| ConsensusErrorKind::InvalidJustification.into()) + .map_err(|_| ConsensusError::InvalidJustification.into()) } } @@ -1187,7 +1269,7 @@ impl TestNetFactory for JustificationTestNet { self.0.peers() } - fn mut_peers>>)>(&mut self, closure: F ) { + fn mut_peers>>)>(&mut self, closure: F) { self.0.mut_peers(closure) } diff --git a/core/network/src/test/sync.rs b/core/network/src/test/sync.rs index da42ae47582f1aa20f6862405c5bbaa1eb51f5d4..1e9e2948f3a1cf7b1761a2d29838b41849ca1df1 100644 --- a/core/network/src/test/sync.rs +++ b/core/network/src/test/sync.rs @@ -45,7 +45,7 @@ fn sync_peers_works() { net.sync(); for peer in 0..3 { // Assert peers is up to date. - assert_eq!(net.peer(peer).peers.read().len(), 2); + assert_eq!(net.peer(peer).protocol_status.read().num_peers, 2); // And then disconnect. for other in 0..3 { if other != peer { @@ -56,8 +56,8 @@ fn sync_peers_works() { net.sync(); // Now peers are disconnected. for peer in 0..3 { - let peers = net.peer(peer).peers.read(); - assert_eq!(peers.len(), 0); + let status = net.peer(peer).protocol_status.read(); + assert_eq!(status.num_peers, 0); } } @@ -320,8 +320,8 @@ fn own_blocks_are_announced() { net.peer(0).on_block_imported(header.hash(), &header); net.sync(); - assert_eq!(net.peer(0).client.as_in_memory_backend().blockchain().info().unwrap().best_number, 1); - assert_eq!(net.peer(1).client.as_in_memory_backend().blockchain().info().unwrap().best_number, 1); + assert_eq!(net.peer(0).client.as_in_memory_backend().blockchain().info().best_number, 1); + assert_eq!(net.peer(1).client.as_in_memory_backend().blockchain().info().best_number, 1); let peer0_chain = net.peer(0).client.as_in_memory_backend().blockchain().clone(); assert!(net.peer(1).client.as_in_memory_backend().blockchain().canon_equals_to(&peer0_chain)); assert!(net.peer(2).client.as_in_memory_backend().blockchain().canon_equals_to(&peer0_chain)); @@ -356,9 +356,9 @@ fn blocks_are_not_announced_by_light_nodes() { // peer 0 has the best chain // peer 1 has the best chain // peer 2 has genesis-chain only - assert_eq!(net.peer(0).client.info().unwrap().chain.best_number, 1); - assert_eq!(net.peer(1).client.info().unwrap().chain.best_number, 1); - assert_eq!(net.peer(2).client.info().unwrap().chain.best_number, 0); + assert_eq!(net.peer(0).client.info().chain.best_number, 1); + assert_eq!(net.peer(1).client.info().chain.best_number, 1); + assert_eq!(net.peer(2).client.info().chain.best_number, 0); } #[test] @@ -371,13 +371,13 @@ fn can_sync_small_non_best_forks() { // small fork + reorg on peer 1. net.peer(0).push_blocks_at(BlockId::Number(30), 2, true); - let small_hash = net.peer(0).client().info().unwrap().chain.best_hash; + let small_hash = net.peer(0).client().info().chain.best_hash; net.peer(0).push_blocks_at(BlockId::Number(30), 10, false); - assert_eq!(net.peer(0).client().info().unwrap().chain.best_number, 40); + assert_eq!(net.peer(0).client().info().chain.best_number, 40); // peer 1 only ever had the long fork. net.peer(1).push_blocks(10, false); - assert_eq!(net.peer(1).client().info().unwrap().chain.best_number, 40); + assert_eq!(net.peer(1).client().info().chain.best_number, 40); assert!(net.peer(0).client().header(&BlockId::Hash(small_hash)).unwrap().is_some()); assert!(net.peer(1).client().header(&BlockId::Hash(small_hash)).unwrap().is_none()); @@ -386,7 +386,7 @@ fn can_sync_small_non_best_forks() { // synchronization: 0 synced to longer chain and 1 didn't sync to small chain. - assert_eq!(net.peer(0).client().info().unwrap().chain.best_number, 40); + assert_eq!(net.peer(0).client().info().chain.best_number, 40); assert!(net.peer(0).client().header(&BlockId::Hash(small_hash)).unwrap().is_some()); assert!(!net.peer(1).client().header(&BlockId::Hash(small_hash)).unwrap().is_some()); @@ -416,8 +416,8 @@ fn can_not_sync_from_light_peer() { net.sync(); // ensure #0 && #1 have the same best block - let full0_info = net.peer(0).client.info().unwrap().chain; - let light_info = net.peer(1).client.info().unwrap().chain; + let full0_info = net.peer(0).client.info().chain; + let light_info = net.peer(1).client.info().chain; assert_eq!(full0_info.best_number, 1); assert_eq!(light_info.best_number, 1); assert_eq!(light_info.best_hash, full0_info.best_hash); @@ -430,7 +430,7 @@ fn can_not_sync_from_light_peer() { net.sync_with(true, Some(vec![0].into_iter().collect())); // ensure that the #2 has failed to sync block #1 - assert_eq!(net.peer(2).client.info().unwrap().chain.best_number, 0); + assert_eq!(net.peer(2).client.info().chain.best_number, 0); // and that the #1 is still connected to #2 // (because #2 has not tried to fetch block data from the #1 light node) assert_eq!(net.peer(1).protocol_status().num_peers, 2); @@ -452,3 +452,36 @@ fn can_not_sync_from_light_peer() { // check that light #1 has disconnected from #2 assert_eq!(net.peer(1).protocol_status().num_peers, 1); } + +#[test] +fn light_peer_imports_header_from_announce() { + let _ = ::env_logger::try_init(); + + fn import_with_announce(net: &mut TestNet, hash: H256) { + let header = net.peer(0).client().header(&BlockId::Hash(hash)).unwrap().unwrap(); + net.peer(1).receive_message( + &net.peer(0).peer_id, + message::generic::Message::BlockAnnounce(message::generic::BlockAnnounce { + header, + }), + ); + + net.peer(1).import_queue_sync(); + assert!(net.peer(1).client().header(&BlockId::Hash(hash)).unwrap().is_some()); + } + + // given the network with 1 full nodes (#0) and 1 light node (#1) + let mut net = TestNet::new(1); + net.add_light_peer(&Default::default()); + + // let them connect to each other + net.sync(); + + // check that NEW block is imported from announce message + let new_hash = net.peer(0).push_blocks(1, false); + import_with_announce(&mut net, new_hash); + + // check that KNOWN STALE block is imported from announce message + let known_stale_hash = net.peer(0).push_blocks_at(BlockId::Number(0), 1, true); + import_with_announce(&mut net, known_stale_hash); +} diff --git a/core/offchain/Cargo.toml b/core/offchain/Cargo.toml index 241edfea9f4d1e8e108463fb748152f79a043009..a7b94bdc567e81c797dafe055d85a8d161e0393f 100644 --- a/core/offchain/Cargo.toml +++ b/core/offchain/Cargo.toml @@ -10,10 +10,10 @@ edition = "2018" client = { package = "substrate-client", path = "../../core/client" } consensus = { package = "substrate-consensus-common", path = "../../core/consensus/common" } futures = "0.1.25" -inherents = { package = "substrate-inherents", path = "../../core/inherents" } log = "0.4" offchain-primitives = { package = "substrate-offchain-primitives", path = "./primitives" } parity-codec = { version = "3.3", features = ["derive"] } +parking_lot = "0.8.0" primitives = { package = "substrate-primitives", path = "../../core/primitives" } runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitives" } tokio = "0.1.7" @@ -21,7 +21,7 @@ transaction_pool = { package = "substrate-transaction-pool", path = "../../core/ [dev-dependencies] env_logger = "0.6" -test_client = { package = "substrate-test-client", path = "../../core/test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" } [features] default = [] diff --git a/core/offchain/src/api.rs b/core/offchain/src/api.rs index 5d2a636be3924d82a18453750ae94130fdc95aa5..d2c7630c249d8adaebd770899b5d0a802e85f5c6 100644 --- a/core/offchain/src/api.rs +++ b/core/offchain/src/api.rs @@ -16,10 +16,13 @@ use std::sync::Arc; use futures::{Stream, Future, sync::mpsc}; -use inherents::pool::InherentsPool; -use log::{info, debug, warn}; +use log::{info, debug, warn, error}; use parity_codec::Decode; -use primitives::OffchainExt; +use primitives::offchain::{ + Timestamp, HttpRequestId, HttpRequestStatus, HttpError, + Externalities as OffchainExt, + CryptoKind, CryptoKeyId, +}; use runtime_primitives::{ generic::BlockId, traits::{self, Extrinsic}, @@ -36,9 +39,122 @@ enum ExtMessage { /// NOTE this is done to prevent recursive calls into the runtime (which are not supported currently). pub(crate) struct AsyncApi(mpsc::UnboundedSender); +fn unavailable_yet(name: &str) -> R { + error!("This {:?} API is not available for offchain workers yet. Follow + https://github.com/paritytech/substrate/issues/1458 for details", name); + Default::default() +} + impl OffchainExt for AsyncApi { - fn submit_extrinsic(&mut self, ext: Vec) { - let _ = self.0.unbounded_send(ExtMessage::SubmitExtrinsic(ext)); + fn submit_transaction(&mut self, ext: Vec) -> Result<(), ()> { + self.0.unbounded_send(ExtMessage::SubmitExtrinsic(ext)) + .map(|_| ()) + .map_err(|_| ()) + } + + fn new_crypto_key(&mut self, _crypto: CryptoKind) -> Result { + unavailable_yet::<()>("new_crypto_key"); + Err(()) + } + + fn encrypt(&mut self, _key: Option, _data: &[u8]) -> Result, ()> { + unavailable_yet::<()>("encrypt"); + Err(()) + } + + fn decrypt(&mut self, _key: Option, _data: &[u8]) -> Result, ()> { + unavailable_yet::<()>("decrypt"); + Err(()) + } + + fn sign(&mut self, _key: Option, _data: &[u8]) -> Result, ()> { + unavailable_yet::<()>("sign"); + Err(()) + } + + fn verify(&mut self, _key: Option, _msg: &[u8], _signature: &[u8]) -> Result { + unavailable_yet::<()>("verify"); + Err(()) + } + + fn timestamp(&mut self) -> Timestamp { + unavailable_yet("timestamp") + } + + fn sleep_until(&mut self, _deadline: Timestamp) { + unavailable_yet::<()>("sleep_until") + } + + fn random_seed(&mut self) -> [u8; 32] { + unavailable_yet("random_seed") + } + + fn local_storage_set(&mut self, _key: &[u8], _value: &[u8]) { + unavailable_yet("local_storage_set") + } + + fn local_storage_compare_and_set(&mut self, _key: &[u8], _old_value: &[u8], _new_value: &[u8]) { + unavailable_yet("local_storage_compare_and_set") + } + + fn local_storage_get(&mut self, _key: &[u8]) -> Option> { + unavailable_yet("local_storage_get") + } + + fn http_request_start( + &mut self, + _method: &str, + _uri: &str, + _meta: &[u8] + ) -> Result { + unavailable_yet::<()>("http_request_start"); + Err(()) + } + + fn http_request_add_header( + &mut self, + _request_id: HttpRequestId, + _name: &str, + _value: &str + ) -> Result<(), ()> { + unavailable_yet::<()>("http_request_add_header"); + Err(()) + } + + fn http_request_write_body( + &mut self, + _request_id: HttpRequestId, + _chunk: &[u8], + _deadline: Option + ) -> Result<(), HttpError> { + unavailable_yet::<()>("http_request_write_body"); + Err(HttpError::IoError) + } + + fn http_response_wait( + &mut self, + ids: &[HttpRequestId], + _deadline: Option + ) -> Vec { + unavailable_yet::<()>("http_response_wait"); + ids.iter().map(|_| HttpRequestStatus::Unknown).collect() + } + + fn http_response_headers( + &mut self, + _request_id: HttpRequestId + ) -> Vec<(Vec, Vec)> { + unavailable_yet("http_response_headers") + } + + fn http_response_read_body( + &mut self, + _request_id: HttpRequestId, + _buffer: &mut [u8], + _deadline: Option + ) -> Result { + unavailable_yet::<()>("http_response_read_body"); + Err(HttpError::IoError) } } @@ -46,21 +162,18 @@ impl OffchainExt for AsyncApi { pub(crate) struct Api { receiver: Option>, transaction_pool: Arc>, - inherents_pool: Arc::Extrinsic>>, at: BlockId, } impl Api { pub fn new( transaction_pool: Arc>, - inherents_pool: Arc::Extrinsic>>, at: BlockId, ) -> (AsyncApi, Self) { let (tx, rx) = mpsc::unbounded(); let api = Self { receiver: Some(rx), transaction_pool, - inherents_pool, at, }; (AsyncApi(tx), api) @@ -90,9 +203,8 @@ impl Api { info!("Submitting to the pool: {:?} (isSigned: {:?})", xt, xt.is_signed()); match self.transaction_pool.submit_one(&self.at, xt.clone()) { Ok(hash) => debug!("[{:?}] Offchain transaction added to the pool.", hash), - Err(_) => { - debug!("Offchain inherent added to the pool."); - self.inherents_pool.add(xt); + Err(e) => { + debug!("Couldn't submit transaction: {:?}", e); }, } } diff --git a/core/offchain/src/lib.rs b/core/offchain/src/lib.rs index cac960f2506f26ec409791065b68efdd8d565407..081ae61a5bcaeecc975bab74f911a4f2cfa7a41f 100644 --- a/core/offchain/src/lib.rs +++ b/core/offchain/src/lib.rs @@ -19,8 +19,8 @@ //! The offchain workers is a special function of the runtime that //! gets executed after block is imported. During execution //! it's able to asynchronously submit extrinsics that will either -//! be propagated to other nodes (transactions) or will be -//! added to the next block produced by the node as inherents. +//! be propagated to other nodes added to the next block +//! produced by the node as unsigned transactions. //! //! Offchain workers can be used for computation-heavy tasks //! that are not feasible for execution during regular block processing. @@ -39,7 +39,6 @@ use std::{ }; use client::runtime_api::ApiExt; -use inherents::pool::InherentsPool; use log::{debug, warn}; use primitives::ExecutionContext; use runtime_primitives::{ @@ -51,13 +50,14 @@ use transaction_pool::txpool::{Pool, ChainApi}; mod api; +pub mod testing; + pub use offchain_primitives::OffchainWorkerApi; /// An offchain workers manager. #[derive(Debug)] pub struct OffchainWorkers { client: Arc, - inherents_pool: Arc::Extrinsic>>, executor: TaskExecutor, _block: PhantomData, } @@ -66,12 +66,10 @@ impl OffchainWorkers { /// Creates new `OffchainWorkers`. pub fn new( client: Arc, - inherents_pool: Arc::Extrinsic>>, executor: TaskExecutor, ) -> Self { Self { client, - inherents_pool, executor, _block: PhantomData, } @@ -93,11 +91,11 @@ impl OffchainWorkers where { let runtime = self.client.runtime_api(); let at = BlockId::number(*number); - let has_api = runtime.has_api::>(&at); + let has_api = runtime.has_api::>(&at); debug!("Checking offchain workers at {:?}: {:?}", at, has_api); if has_api.unwrap_or(false) { - let (api, runner) = api::Api::new(pool.clone(), self.inherents_pool.clone(), at.clone()); + let (api, runner) = api::Api::new(pool.clone(), at.clone()); self.executor.spawn(runner.process()); debug!("Running offchain workers at {:?}", at); @@ -119,14 +117,14 @@ mod tests { let runtime = tokio::runtime::Runtime::new().unwrap(); let client = Arc::new(test_client::new()); let pool = Arc::new(Pool::new(Default::default(), ::transaction_pool::ChainApi::new(client.clone()))); - let inherents = Arc::new(InherentsPool::default()); // when - let offchain = OffchainWorkers::new(client, inherents.clone(), runtime.executor()); + let offchain = OffchainWorkers::new(client, runtime.executor()); offchain.on_block_imported(&0u64, &pool); // then runtime.shutdown_on_idle().wait().unwrap(); - assert_eq!(inherents.drain().len(), 1); + assert_eq!(pool.status().ready, 1); + assert_eq!(pool.ready().next().unwrap().is_propagateable(), false); } } diff --git a/core/offchain/src/testing.rs b/core/offchain/src/testing.rs new file mode 100644 index 0000000000000000000000000000000000000000..3419665d0a2f2873693168d89950eceb7eb363d8 --- /dev/null +++ b/core/offchain/src/testing.rs @@ -0,0 +1,244 @@ +// 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 . + +//! Offchain Externalities implementation for tests. + +use std::{ + collections::BTreeMap, + sync::Arc, +}; +use parking_lot::RwLock; +use primitives::offchain::{ + self, + HttpError, + HttpRequestId as RequestId, + HttpRequestStatus as RequestStatus, + Timestamp, + CryptoKind, + CryptoKeyId, +}; + +/// Pending request. +#[derive(Debug, Default, PartialEq, Eq)] +pub struct PendingRequest { + /// HTTP method + pub method: String, + /// URI + pub uri: String, + /// Encoded Metadata + pub meta: Vec, + /// Request headers + pub headers: Vec<(String, String)>, + /// Request body + pub body: Vec, + /// Has the request been sent already. + pub sent: bool, + /// Response body + pub response: Vec, + /// Number of bytes already read from the response body. + pub read: usize, + /// Response headers + pub response_headers: Vec<(String, String)>, +} + +/// Internal state of the externalities. +/// +/// This can be used in tests to respond or assert stuff about interactions. +#[derive(Debug, Default)] +pub struct State { + /// A list of pending requests. + pub requests: BTreeMap, +} + +impl State { + /// Asserts that pending request has been submitted and fills it's response. + pub fn fulfill_pending_request( + &mut self, + id: u16, + expected: PendingRequest, + response: impl Into>, + response_headers: impl IntoIterator, + ) { + match self.requests.get_mut(&RequestId(id)) { + None => { + panic!("Missing expected request: {:?}.\n\nAll: {:?}", id, self.requests); + } + Some(req) => { + assert_eq!( + *req, + expected, + ); + req.response = response.into(); + req.response_headers = response_headers.into_iter().collect(); + } + } + } +} + +/// Implementation of offchain externalities used for tests. +#[derive(Clone, Default, Debug)] +pub struct TestOffchainExt(pub Arc>); + +impl offchain::Externalities for TestOffchainExt { + fn submit_transaction(&mut self, _ex: Vec) -> Result<(), ()> { + unimplemented!("not needed in tests so far") + } + + fn new_crypto_key(&mut self, _crypto: CryptoKind) -> Result { + unimplemented!("not needed in tests so far") + } + + fn encrypt(&mut self, _key: Option, _data: &[u8]) -> Result, ()> { + unimplemented!("not needed in tests so far") + } + + fn decrypt(&mut self, _key: Option, _data: &[u8]) -> Result, ()> { + unimplemented!("not needed in tests so far") + } + + fn sign(&mut self, _key: Option, _data: &[u8]) -> Result, ()> { + unimplemented!("not needed in tests so far") + } + + fn verify(&mut self, _key: Option, _msg: &[u8], _signature: &[u8]) -> Result { + unimplemented!("not needed in tests so far") + } + + fn timestamp(&mut self) -> Timestamp { + unimplemented!("not needed in tests so far") + } + + fn sleep_until(&mut self, _deadline: Timestamp) { + unimplemented!("not needed in tests so far") + } + + fn random_seed(&mut self) -> [u8; 32] { + unimplemented!("not needed in tests so far") + } + + fn local_storage_set(&mut self, _key: &[u8], _value: &[u8]) { + unimplemented!("not needed in tests so far") + } + + fn local_storage_compare_and_set( + &mut self, + _key: &[u8], + _old_value: &[u8], + _new_value: &[u8] + ) { + unimplemented!("not needed in tests so far") + } + + fn local_storage_get(&mut self, _key: &[u8]) -> Option> { + unimplemented!("not needed in tests so far") + } + + fn http_request_start(&mut self, method: &str, uri: &str, meta: &[u8]) -> Result { + let mut state = self.0.write(); + let id = RequestId(state.requests.len() as u16); + state.requests.insert(id.clone(), PendingRequest { + method: method.into(), + uri: uri.into(), + meta: meta.into(), + ..Default::default() + }); + Ok(id) + } + + fn http_request_add_header( + &mut self, + request_id: RequestId, + name: &str, + value: &str, + ) -> Result<(), ()> { + let mut state = self.0.write(); + if let Some(req) = state.requests.get_mut(&request_id) { + req.headers.push((name.into(), value.into())); + Ok(()) + } else { + Err(()) + } + } + + fn http_request_write_body( + &mut self, + request_id: RequestId, + chunk: &[u8], + _deadline: Option + ) -> Result<(), HttpError> { + let mut state = self.0.write(); + if let Some(req) = state.requests.get_mut(&request_id) { + if chunk.is_empty() { + req.sent = true; + } + req.body.extend(chunk); + Ok(()) + } else { + Err(HttpError::IoError) + } + } + + fn http_response_wait( + &mut self, + ids: &[RequestId], + _deadline: Option, + ) -> Vec { + let state = self.0.read(); + + ids.iter().map(|id| match state.requests.get(id) { + Some(req) if req.response.is_empty() => RequestStatus::DeadlineReached, + None => RequestStatus::Unknown, + _ => RequestStatus::Finished(200), + }).collect() + } + + fn http_response_headers(&mut self, request_id: RequestId) -> Vec<(Vec, Vec)> { + let state = self.0.read(); + if let Some(req) = state.requests.get(&request_id) { + req.response_headers + .clone() + .into_iter() + .map(|(k, v)| (k.into_bytes(), v.into_bytes())) + .collect() + } else { + Default::default() + } + } + + fn http_response_read_body( + &mut self, + request_id: RequestId, + buffer: &mut [u8], + _deadline: Option + ) -> Result { + let mut state = self.0.write(); + if let Some(req) = state.requests.get_mut(&request_id) { + if req.read >= req.response.len() { + // Remove the pending request as per spec. + state.requests.remove(&request_id); + Ok(0) + } else { + let read = std::cmp::min(buffer.len(), req.response[req.read..].len()); + buffer[0..read].copy_from_slice(&req.response[req.read..read]); + req.read += read; + Ok(read) + } + } else { + Err(HttpError::IoError) + } + } +} + diff --git a/core/peerset/Cargo.toml b/core/peerset/Cargo.toml index dfe68154804aa9a4735a37c333e23fa1747fb775..aa08c8ca997a5d32546567bbb806cf778bac6d7a 100644 --- a/core/peerset/Cargo.toml +++ b/core/peerset/Cargo.toml @@ -9,7 +9,7 @@ edition = "2018" [dependencies] futures = "0.1" -libp2p = { version = "0.7.0", default-features = false } +libp2p = { version = "0.9.0", default-features = false } linked-hash-map = "0.5" log = "0.4" lru-cache = "0.1.2" diff --git a/core/peerset/src/lib.rs b/core/peerset/src/lib.rs index ac076be4b51f33f3248ff0907fb4dea668ef1f8e..aa3ce02076d56d5cf42605d6a8aa76cd444df581 100644 --- a/core/peerset/src/lib.rs +++ b/core/peerset/src/lib.rs @@ -19,14 +19,18 @@ mod peersstate; -use std::{collections::HashMap, collections::VecDeque, time::Instant}; +use std::{collections::{HashSet, HashMap}, collections::VecDeque, time::Instant}; use futures::{prelude::*, sync::mpsc, try_ready}; use libp2p::PeerId; use log::{debug, error, trace}; use serde_json::json; +/// We don't accept nodes whose reputation is under this value. +const BANNED_THRESHOLD: i32 = 82 * (i32::min_value() / 100); /// Reputation change for a node when we get disconnected from it. const DISCONNECT_REPUTATION_CHANGE: i32 = -10; +/// Reserved peers group ID +const RESERVED_NODES: &'static str = "reserved"; #[derive(Debug)] enum Action { @@ -34,6 +38,9 @@ enum Action { RemoveReservedPeer(PeerId), SetReservedOnly(bool), ReportPeer(PeerId, i32), + SetPriorityGroup(String, HashSet), + AddToPriorityGroup(String, PeerId), + RemoveFromPriorityGroup(String, PeerId), } /// Shared handle to the peer set manager (PSM). Distributed around the code. @@ -70,6 +77,21 @@ impl PeersetHandle { pub fn report_peer(&self, peer_id: PeerId, score_diff: i32) { let _ = self.tx.unbounded_send(Action::ReportPeer(peer_id, score_diff)); } + + /// Modify a priority group. + pub fn set_priority_group(&self, group_id: String, peers: HashSet) { + let _ = self.tx.unbounded_send(Action::SetPriorityGroup(group_id, peers)); + } + + /// Add a peer to a priority group. + pub fn add_to_priority_group(&self, group_id: String, peer_id: PeerId) { + let _ = self.tx.unbounded_send(Action::AddToPriorityGroup(group_id, peer_id)); + } + + /// Remove a peer from a priority group. + pub fn remove_from_priority_group(&self, group_id: String, peer_id: PeerId) { + let _ = self.tx.unbounded_send(Action::RemoveFromPriorityGroup(group_id, peer_id)); + } } /// Message that can be sent by the peer set manager (PSM). @@ -159,14 +181,7 @@ impl Peerset { latest_time_update: Instant::now(), }; - for peer_id in config.reserved_nodes { - if let peersstate::Peer::Unknown(entry) = peerset.data.peer(&peer_id) { - entry.discover().set_reserved(true); - } else { - debug!(target: "peerset", "Duplicate reserved node in config: {:?}", peer_id); - } - } - + peerset.data.set_priority_group(RESERVED_NODES, config.reserved_nodes.into_iter().collect()); for peer_id in config.bootnodes { if let peersstate::Peer::Unknown(entry) = peerset.data.peer(&peer_id) { entry.discover(); @@ -180,32 +195,25 @@ impl Peerset { } fn on_add_reserved_peer(&mut self, peer_id: PeerId) { - let mut entry = match self.data.peer(&peer_id) { - peersstate::Peer::Connected(mut connected) => { - connected.set_reserved(true); - return - } - peersstate::Peer::NotConnected(entry) => entry, - peersstate::Peer::Unknown(entry) => entry.discover(), - }; - - // We reach this point if and only if we were not connected to the node. - entry.set_reserved(true); - entry.force_outgoing(); - self.message_queue.push_back(Message::Connect(peer_id)); + let mut reserved = self.data.get_priority_group(RESERVED_NODES).unwrap_or_default(); + reserved.insert(peer_id); + self.data.set_priority_group(RESERVED_NODES, reserved); + self.alloc_slots(); } fn on_remove_reserved_peer(&mut self, peer_id: PeerId) { + let mut reserved = self.data.get_priority_group(RESERVED_NODES).unwrap_or_default(); + reserved.remove(&peer_id); + self.data.set_priority_group(RESERVED_NODES, reserved); match self.data.peer(&peer_id) { - peersstate::Peer::Connected(mut peer) => { - peer.set_reserved(false); + peersstate::Peer::Connected(peer) => { if self.reserved_only { peer.disconnect(); self.message_queue.push_back(Message::Drop(peer_id)); } } - peersstate::Peer::NotConnected(mut peer) => peer.set_reserved(false), - peersstate::Peer::Unknown(_) => {} + peersstate::Peer::NotConnected(_) => {}, + peersstate::Peer::Unknown(_) => {}, } } @@ -213,26 +221,47 @@ impl Peerset { // Disconnect non-reserved nodes. self.reserved_only = reserved_only; if self.reserved_only { + let reserved = self.data.get_priority_group(RESERVED_NODES).unwrap_or_default(); for peer_id in self.data.connected_peers().cloned().collect::>().into_iter() { let peer = self.data.peer(&peer_id).into_connected() .expect("We are enumerating connected peers, therefore the peer is connected; qed"); - if !peer.is_reserved() { + if !reserved.contains(&peer_id) { peer.disconnect(); self.message_queue.push_back(Message::Drop(peer_id)); } } - } else { self.alloc_slots(); } } + fn on_set_priority_group(&mut self, group_id: &str, peers: HashSet) { + self.data.set_priority_group(group_id, peers); + self.alloc_slots(); + } + + fn on_add_to_priority_group(&mut self, group_id: &str, peer_id: PeerId) { + self.data.add_to_priority_group(group_id, peer_id); + self.alloc_slots(); + } + + fn on_remove_from_priority_group(&mut self, group_id: &str, peer_id: PeerId) { + self.data.remove_from_priority_group(group_id, &peer_id); + self.alloc_slots(); + } + fn on_report_peer(&mut self, peer_id: PeerId, score_diff: i32) { // We want reputations to be up-to-date before adjusting them. self.update_time(); match self.data.peer(&peer_id) { - peersstate::Peer::Connected(mut peer) => peer.add_reputation(score_diff), + peersstate::Peer::Connected(mut peer) => { + peer.add_reputation(score_diff); + if peer.reputation() < BANNED_THRESHOLD { + peer.disconnect(); + self.message_queue.push_back(Message::Drop(peer_id)); + } + }, peersstate::Peer::NotConnected(mut peer) => peer.add_reputation(score_diff), peersstate::Peer::Unknown(peer) => peer.discover().add_reputation(score_diff), } @@ -283,22 +312,33 @@ impl Peerset { fn alloc_slots(&mut self) { self.update_time(); + // Try to grab the next node to attempt to connect to. + while let Some(next) = { + if self.reserved_only { + self.data.priority_not_connected_peer_from_group(RESERVED_NODES) + } else { + self.data.priority_not_connected_peer() + } + } { + match next.try_outgoing() { + Ok(conn) => self.message_queue.push_back(Message::Connect(conn.into_peer_id())), + Err(_) => break, // No more slots available. + } + } + loop { + if self.reserved_only { + break + } + // Try to grab the next node to attempt to connect to. - let next = match self.data.reserved_not_connected_peer() { + let next = match self.data.highest_not_connected_peer() { Some(p) => p, - None => if self.reserved_only { - break // No known node to add. - } else { - match self.data.highest_not_connected_peer() { - Some(p) => p, - None => break, // No known node to add. - } - } + None => break, // No known node to add. }; // Don't connect to nodes with an abysmal reputation. - if next.reputation() == i32::min_value() { + if next.reputation() < BANNED_THRESHOLD { break; } @@ -321,6 +361,7 @@ impl Peerset { // `PeerId` before that message has been read by the user. In this situation we must not answer. pub fn incoming(&mut self, peer_id: PeerId, index: IncomingIndex) { trace!(target: "peerset", "Incoming {:?}", peer_id); + self.update_time(); let not_connected = match self.data.peer(&peer_id) { // If we're already connected, don't answer, as the docs mention. @@ -329,6 +370,11 @@ impl Peerset { peersstate::Peer::Unknown(entry) => entry.discover(), }; + if not_connected.reputation() < BANNED_THRESHOLD { + self.message_queue.push_back(Message::Reject(index)); + return + } + match not_connected.try_accept_incoming() { Ok(_) => self.message_queue.push_back(Message::Accept(index)), Err(_) => self.message_queue.push_back(Message::Reject(index)), @@ -402,6 +448,11 @@ impl Peerset { "message_queue": self.message_queue.len(), }) } + + /// Returns priority group by id. + pub fn get_priority_group(&self, group_id: &str) -> Option> { + self.data.get_priority_group(group_id) + } } impl Stream for Peerset { @@ -414,12 +465,15 @@ impl Stream for Peerset { return Ok(Async::Ready(Some(message))); } match try_ready!(self.rx.poll()) { - None => return Ok(Async::Ready(None)), + None => return Ok(Async::NotReady), Some(action) => match action { Action::AddReservedPeer(peer_id) => self.on_add_reserved_peer(peer_id), Action::RemoveReservedPeer(peer_id) => self.on_remove_reserved_peer(peer_id), Action::SetReservedOnly(reserved) => self.on_set_reserved_only(reserved), Action::ReportPeer(peer_id, score_diff) => self.on_report_peer(peer_id, score_diff), + Action::SetPriorityGroup(group_id, peers) => self.on_set_priority_group(&group_id, peers), + Action::AddToPriorityGroup(group_id, peer_id) => self.on_add_to_priority_group(&group_id, peer_id), + Action::RemoveFromPriorityGroup(group_id, peer_id) => self.on_remove_from_priority_group(&group_id, peer_id), } } } @@ -430,7 +484,8 @@ impl Stream for Peerset { mod tests { use libp2p::PeerId; use futures::prelude::*; - use super::{PeersetConfig, Peerset, Message, IncomingIndex}; + use super::{PeersetConfig, Peerset, Message, IncomingIndex, BANNED_THRESHOLD}; + use std::{thread, time::Duration}; fn assert_messages(mut peerset: Peerset, messages: Vec) -> Peerset { for expected_message in messages { @@ -528,4 +583,46 @@ mod tests { Message::Connect(discovered), ]); } + + #[test] + fn test_peerset_banned() { + let (mut peerset, handle) = Peerset::from_config(PeersetConfig { + in_peers: 25, + out_peers: 25, + bootnodes: vec![], + reserved_only: false, + reserved_nodes: vec![], + }); + + // We ban a node by setting its reputation under the threshold. + let peer_id = PeerId::random(); + handle.report_peer(peer_id.clone(), BANNED_THRESHOLD - 1); + + let fut = futures::future::poll_fn(move || -> Result<_, ()> { + // We need one polling for the message to be processed. + assert_eq!(peerset.poll().unwrap(), Async::NotReady); + + // Check that an incoming connection from that node gets refused. + peerset.incoming(peer_id.clone(), IncomingIndex(1)); + if let Async::Ready(msg) = peerset.poll().unwrap() { + assert_eq!(msg.unwrap(), Message::Reject(IncomingIndex(1))); + } else { + panic!() + } + + // Wait a bit for the node's reputation to go above the threshold. + thread::sleep(Duration::from_millis(1500)); + + // Try again. This time the node should be accepted. + peerset.incoming(peer_id.clone(), IncomingIndex(2)); + while let Async::Ready(msg) = peerset.poll().unwrap() { + assert_eq!(msg.unwrap(), Message::Accept(IncomingIndex(2))); + } + + Ok(Async::Ready(())) + }); + + tokio::runtime::current_thread::Runtime::new().unwrap().block_on(fut).unwrap(); + } } + diff --git a/core/peerset/src/peersstate.rs b/core/peerset/src/peersstate.rs index c02b1daf62d787040c82b7689b42456bd0fc93c1..e02d6304046bc6f74b9a69e8a1cfbc2dc322f5ab 100644 --- a/core/peerset/src/peersstate.rs +++ b/core/peerset/src/peersstate.rs @@ -17,7 +17,8 @@ //! Contains the state storage behind the peerset. use libp2p::PeerId; -use std::{borrow::Cow, collections::HashMap}; +use std::{borrow::Cow, collections::{HashSet, HashMap}}; +use log::warn; /// State storage behind the peerset. /// @@ -35,17 +36,20 @@ pub struct PeersState { /// sort, to make the logic easier. nodes: HashMap, - /// Number of non-reserved nodes for which the `ConnectionState` is `In`. + /// Number of non-priority nodes for which the `ConnectionState` is `In`. num_in: u32, - /// Number of non-reserved nodes for which the `ConnectionState` is `In`. + /// Number of non-priority nodes for which the `ConnectionState` is `In`. num_out: u32, - /// Maximum allowed number of non-reserved nodes for which the `ConnectionState` is `In`. + /// Maximum allowed number of non-priority nodes for which the `ConnectionState` is `In`. max_in: u32, - /// Maximum allowed number of non-reserved nodes for which the `ConnectionState` is `Out`. + /// Maximum allowed number of non-priority nodes for which the `ConnectionState` is `Out`. max_out: u32, + + /// Priority groups. Each group is identified by a string ID and contains a set of peer IDs. + priority_nodes: HashMap>, } /// State of a single node that we know about. @@ -54,14 +58,20 @@ struct Node { /// Whether we are connected to this node. connection_state: ConnectionState, - /// If true, this node is reserved and should always be connected to. - reserved: bool, - /// Reputation value of the node, between `i32::min_value` (we hate that node) and /// `i32::max_value` (we love that node). reputation: i32, } +impl Default for Node { + fn default() -> Node { + Node { + connection_state: ConnectionState::NotConnected, + reputation: 0, + } + } +} + /// Whether we are connected to a node. #[derive(Debug, Copy, Clone, PartialEq, Eq)] enum ConnectionState { @@ -93,42 +103,30 @@ impl PeersState { num_out: 0, max_in: in_peers, max_out: out_peers, + priority_nodes: HashMap::new(), } } /// Returns an object that grants access to the state of a peer. pub fn peer<'a>(&'a mut self, peer_id: &'a PeerId) -> Peer<'a> { - // Note: the Rust borrow checker still has some issues. In particular, we can't put this - // block as an `else` below (as the obvious solution would be here), or it will complain - // that we borrow `self` while it is already borrowed. - if !self.nodes.contains_key(peer_id) { - return Peer::Unknown(UnknownPeer { + match self.nodes.get_mut(peer_id) { + None => return Peer::Unknown(UnknownPeer { parent: self, peer_id: Cow::Borrowed(peer_id), - }); - } - - let state = self.nodes.get_mut(peer_id) - .expect("We check that the value is present right above; QED"); - - if state.connection_state.is_connected() { - Peer::Connected(ConnectedPeer { - state, - peer_id: Cow::Borrowed(peer_id), - num_in: &mut self.num_in, - num_out: &mut self.num_out, - max_in: self.max_in, - max_out: self.max_out, - }) - } else { - Peer::NotConnected(NotConnectedPeer { - state, - peer_id: Cow::Borrowed(peer_id), - num_in: &mut self.num_in, - num_out: &mut self.num_out, - max_in: self.max_in, - max_out: self.max_out, - }) + }), + Some(peer) => { + if peer.connection_state.is_connected() { + Peer::Connected(ConnectedPeer { + state: self, + peer_id: Cow::Borrowed(peer_id), + }) + } else { + Peer::NotConnected(NotConnectedPeer { + state: self, + peer_id: Cow::Borrowed(peer_id), + }) + } + } } } @@ -148,28 +146,32 @@ impl PeersState { .map(|(p, _)| p) } - /// Returns the first reserved peer that we are not connected to. + /// Returns the first priority peer that we are not connected to. /// - /// If multiple nodes are reserved, which one is returned is unspecified. - pub fn reserved_not_connected_peer(&mut self) -> Option { - let outcome = self.nodes.iter_mut() - .find(|(_, &mut Node { connection_state, reserved, .. })| { - reserved && !connection_state.is_connected() - }) - .map(|(peer_id, node)| (peer_id.clone(), node)); - - if let Some((peer_id, state)) = outcome { - Some(NotConnectedPeer { - state, - peer_id: Cow::Owned(peer_id), - num_in: &mut self.num_in, - num_out: &mut self.num_out, - max_in: self.max_in, - max_out: self.max_out, - }) - } else { - None - } + /// If multiple nodes are prioritized, which one is returned is unspecified. + pub fn priority_not_connected_peer(&mut self) -> Option { + let id = self.priority_nodes.values() + .flatten() + .find(|id| self.nodes.get(id).map_or(false, |node| !node.connection_state.is_connected())) + .cloned(); + id.map(move |id| NotConnectedPeer { + state: self, + peer_id: Cow::Owned(id), + }) + } + + /// Returns the first priority peer that we are not connected to. + /// + /// If multiple nodes are prioritized, which one is returned is unspecified. + pub fn priority_not_connected_peer_from_group(&mut self, group_id: &str) -> Option { + let id = self.priority_nodes.get(group_id) + .and_then(|group| group.iter() + .find(|id| self.nodes.get(id).map_or(false, |node| !node.connection_state.is_connected())) + .cloned()); + id.map(move |id| NotConnectedPeer { + state: self, + peer_id: Cow::Owned(id), + }) } /// Returns the peer with the highest reputation and that we are not connected to. @@ -187,21 +189,160 @@ impl PeersState { } Some(to_try) }) - .map(|(peer_id, state)| (peer_id.clone(), state)); + .map(|(peer_id, _)| peer_id.clone()); - if let Some((peer_id, state)) = outcome { + if let Some(peer_id) = outcome { Some(NotConnectedPeer { - state, + state: self, peer_id: Cow::Owned(peer_id), - num_in: &mut self.num_in, - num_out: &mut self.num_out, - max_in: self.max_in, - max_out: self.max_out, }) } else { None } } + + fn disconnect(&mut self, peer_id: &PeerId) { + let is_priority = self.is_priority(peer_id); + if let Some(mut node) = self.nodes.get_mut(peer_id) { + if !is_priority { + match node.connection_state { + ConnectionState::In => self.num_in -= 1, + ConnectionState::Out => self.num_out -= 1, + ConnectionState::NotConnected => + debug_assert!(false, "State inconsistency: disconnecting a disconnected node") + } + } + node.connection_state = ConnectionState::NotConnected; + } else { + warn!(target: "peerset", "Attempting to disconnect unknown peer {}", peer_id); + } + } + + /// Sets the peer as connected with an outgoing connection. + fn try_outgoing(&mut self, peer_id: &PeerId) -> bool { + // Note that it is possible for num_out to be strictly superior to the max, in case we were + // connected to reserved node then marked them as not reserved. + let is_priority = self.is_priority(peer_id); + if self.num_out >= self.max_out && !is_priority { + return false; + } + + if let Some(mut peer) = self.nodes.get_mut(peer_id) { + peer.connection_state = ConnectionState::Out; + if !is_priority { + self.num_out += 1; + } + return true; + } + false + } + + /// Tries to accept the peer as an incoming connection. + /// + /// If there are enough slots available, switches the node to "connected" and returns `Ok`. If + /// the slots are full, the node stays "not connected" and we return `Err`. + /// + /// Note that reserved nodes don't count towards the number of slots. + fn try_accept_incoming(&mut self, peer_id: &PeerId) -> bool { + let is_priority = self.is_priority(peer_id); + // Note that it is possible for num_in to be strictly superior to the max, in case we were + // connected to reserved node then marked them as not reserved. + if self.num_in >= self.max_in && !is_priority { + return false; + } + if let Some(mut peer) = self.nodes.get_mut(peer_id) { + peer.connection_state = ConnectionState::In; + if !is_priority { + self.num_in += 1; + } + return true; + } + false + } + + /// Sets priority group + pub fn set_priority_group(&mut self, group_id: &str, peers: HashSet) { + // update slot counters + let all_other_groups: HashSet<_> = self.priority_nodes + .iter() + .filter(|(g, _)| *g != group_id) + .flat_map(|(_, id)| id.clone()) + .collect(); + let existing_group = self.priority_nodes.remove(group_id).unwrap_or_default(); + for id in existing_group { + // update slots for nodes that are no longer priority + if !all_other_groups.contains(&id) { + if let Some(peer) = self.nodes.get_mut(&id) { + match peer.connection_state { + ConnectionState::In => self.num_in += 1, + ConnectionState::Out => self.num_out += 1, + ConnectionState::NotConnected => {}, + } + } + } + } + + for id in &peers { + // update slots for nodes that become priority + if !all_other_groups.contains(&id) { + let peer = self.nodes.entry(id.clone()).or_default(); + match peer.connection_state { + ConnectionState::In => self.num_in -= 1, + ConnectionState::Out => self.num_out -= 1, + ConnectionState::NotConnected => {}, + } + } + } + self.priority_nodes.insert(group_id.into(), peers); + } + + /// Add a peer to a priority group. + pub fn add_to_priority_group(&mut self, group_id: &str, peer_id: PeerId) { + let mut peers = self.priority_nodes.get(group_id).cloned().unwrap_or_default(); + peers.insert(peer_id); + self.set_priority_group(group_id, peers); + } + + /// Remove a peer from a priority group. + pub fn remove_from_priority_group(&mut self, group_id: &str, peer_id: &PeerId) { + let mut peers = self.priority_nodes.get(group_id).cloned().unwrap_or_default(); + peers.remove(&peer_id); + self.set_priority_group(group_id, peers); + } + + /// Get priority group content. + pub fn get_priority_group(&self, group_id: &str) -> Option> { + self.priority_nodes.get(group_id).cloned() + } + + /// Check that node is any priority group. + fn is_priority(&self, peer_id: &PeerId) -> bool { + self.priority_nodes.iter().any(|(_, group)| group.contains(peer_id)) + } + + /// Returns the reputation value of the node. + fn reputation(&self, peer_id: &PeerId) -> i32 { + self.nodes.get(peer_id).map_or(0, |p| p.reputation) + } + + /// Sets the reputation of the peer. + fn set_reputation(&mut self, peer_id: &PeerId, value: i32) { + let node = self.nodes + .entry(peer_id.clone()) + .or_default(); + node.reputation = value; + } + + /// Performs an arithmetic addition on the reputation score of that peer. + /// + /// In case of overflow, the value will be capped. + /// If the peer is unknown to us, we insert it and consider that it has a reputation of 0. + fn add_reputation(&mut self, peer_id: &PeerId, modifier: i32) { + let node = self.nodes + .entry(peer_id.clone()) + .or_default(); + node.reputation = node.reputation.saturating_add(modifier); + } } /// Grants access to the state of a peer in the `PeersState`. @@ -250,12 +391,8 @@ impl<'a> Peer<'a> { /// A peer that is connected to us. pub struct ConnectedPeer<'a> { - state: &'a mut Node, + state: &'a mut PeersState, peer_id: Cow<'a, PeerId>, - num_in: &'a mut u32, - num_out: &'a mut u32, - max_in: u32, - max_out: u32, } impl<'a> ConnectedPeer<'a> { @@ -266,83 +403,36 @@ impl<'a> ConnectedPeer<'a> { /// Switches the peer to "not connected". pub fn disconnect(self) -> NotConnectedPeer<'a> { - let connec_state = &mut self.state.connection_state; - - if !self.state.reserved { - match *connec_state { - ConnectionState::In => *self.num_in -= 1, - ConnectionState::Out => *self.num_out -= 1, - ConnectionState::NotConnected => - debug_assert!(false, "State inconsistency: disconnecting a disconnected node") - } - } - - *connec_state = ConnectionState::NotConnected; - + self.state.disconnect(&self.peer_id); NotConnectedPeer { state: self.state, peer_id: self.peer_id, - num_in: self.num_in, - num_out: self.num_out, - max_in: self.max_in, - max_out: self.max_out, - } - } - - /// Sets whether or not the node is reserved. - pub fn set_reserved(&mut self, reserved: bool) { - if reserved { - self.state.reserved = true; - match self.state.connection_state { - ConnectionState::In => *self.num_in -= 1, - ConnectionState::Out => *self.num_out -= 1, - ConnectionState::NotConnected => debug_assert!(false, "State inconsistency: \ - connected node is in fact not connected"), - } - - } else { - self.state.reserved = false; - match self.state.connection_state { - ConnectionState::In => *self.num_in += 1, - ConnectionState::Out => *self.num_out += 1, - ConnectionState::NotConnected => debug_assert!(false, "State inconsistency: \ - connected node is in fact not connected"), - } } } - /// Returns whether or not the node is reserved. - pub fn is_reserved(&self) -> bool { - self.state.reserved - } - /// Returns the reputation value of the node. pub fn reputation(&self) -> i32 { - self.state.reputation + self.state.reputation(&self.peer_id) } /// Sets the reputation of the peer. pub fn set_reputation(&mut self, value: i32) { - self.state.reputation = value; + self.state.set_reputation(&self.peer_id, value) } /// Performs an arithmetic addition on the reputation score of that peer. /// /// In case of overflow, the value will be capped. pub fn add_reputation(&mut self, modifier: i32) { - let reputation = &mut self.state.reputation; - *reputation = reputation.saturating_add(modifier); + self.state.add_reputation(&self.peer_id, modifier) } } /// A peer that is not connected to us. +#[derive(Debug)] pub struct NotConnectedPeer<'a> { - state: &'a mut Node, + state: &'a mut PeersState, peer_id: Cow<'a, PeerId>, - num_in: &'a mut u32, - num_out: &'a mut u32, - max_in: u32, - max_out: u32, } impl<'a> NotConnectedPeer<'a> { @@ -356,41 +446,16 @@ impl<'a> NotConnectedPeer<'a> { /// /// If there are enough slots available, switches the node to "connected" and returns `Ok`. If /// the slots are full, the node stays "not connected" and we return `Err`. - /// If the node is reserved, this method always succeeds. /// - /// Note that reserved nodes don't count towards the number of slots. + /// Note that priority nodes don't count towards the number of slots. pub fn try_outgoing(self) -> Result, NotConnectedPeer<'a>> { - if self.is_reserved() { - return Ok(self.force_outgoing()) - } - - // Note that it is possible for num_out to be strictly superior to the max, in case we were - // connected to reserved node then marked them as not reserved, or if the user used - // `force_outgoing`. - if *self.num_out >= self.max_out { - return Err(self); - } - - Ok(self.force_outgoing()) - } - - /// Sets the peer as connected as an outgoing connection. - pub fn force_outgoing(self) -> ConnectedPeer<'a> { - let connec_state = &mut self.state.connection_state; - debug_assert!(!connec_state.is_connected()); - *connec_state = ConnectionState::Out; - - if !self.state.reserved { - *self.num_out += 1; - } - - ConnectedPeer { - state: self.state, - peer_id: self.peer_id, - num_in: self.num_in, - num_out: self.num_out, - max_in: self.max_in, - max_out: self.max_out, + if self.state.try_outgoing(&self.peer_id) { + Ok(ConnectedPeer { + state: self.state, + peer_id: self.peer_id, + }) + } else { + Err(self) } } @@ -399,59 +464,26 @@ impl<'a> NotConnectedPeer<'a> { /// If there are enough slots available, switches the node to "connected" and returns `Ok`. If /// the slots are full, the node stays "not connected" and we return `Err`. /// - /// Note that reserved nodes don't count towards the number of slots. + /// Note that priority nodes don't count towards the number of slots. pub fn try_accept_incoming(self) -> Result, NotConnectedPeer<'a>> { - if self.is_reserved() { - return Ok(self.force_ingoing()) - } - - // Note that it is possible for num_in to be strictly superior to the max, in case we were - // connected to reserved node then marked them as not reserved. - if *self.num_in >= self.max_in { - return Err(self); - } - - Ok(self.force_ingoing()) - } - - /// Sets the peer as connected as an ingoing connection. - pub fn force_ingoing(self) -> ConnectedPeer<'a> { - let connec_state = &mut self.state.connection_state; - debug_assert!(!connec_state.is_connected()); - *connec_state = ConnectionState::In; - - if !self.state.reserved { - *self.num_in += 1; - } - - ConnectedPeer { - state: self.state, - peer_id: self.peer_id, - num_in: self.num_in, - num_out: self.num_out, - max_in: self.max_in, - max_out: self.max_out, + if self.state.try_accept_incoming(&self.peer_id) { + Ok(ConnectedPeer { + state: self.state, + peer_id: self.peer_id, + }) + } else { + Err(self) } } - /// Sets whether or not the node is reserved. - pub fn set_reserved(&mut self, reserved: bool) { - self.state.reserved = reserved; - } - - /// Returns true if the the node is reserved. - pub fn is_reserved(&self) -> bool { - self.state.reserved - } - /// Returns the reputation value of the node. pub fn reputation(&self) -> i32 { - self.state.reputation + self.state.reputation(&self.peer_id) } /// Sets the reputation of the peer. pub fn set_reputation(&mut self, value: i32) { - self.state.reputation = value; + self.state.set_reputation(&self.peer_id, value) } /// Performs an arithmetic addition on the reputation score of that peer. @@ -459,8 +491,7 @@ impl<'a> NotConnectedPeer<'a> { /// In case of overflow, the value will be capped. /// If the peer is unknown to us, we insert it and consider that it has a reputation of 0. pub fn add_reputation(&mut self, modifier: i32) { - let reputation = &mut self.state.reputation; - *reputation = reputation.saturating_add(modifier); + self.state.add_reputation(&self.peer_id, modifier) } } @@ -473,25 +504,18 @@ pub struct UnknownPeer<'a> { impl<'a> UnknownPeer<'a> { /// Inserts the peer identity in our list. /// - /// The node is not reserved and starts with a reputation of 0. You can adjust these default + /// The node starts with a reputation of 0. You can adjust these default /// values using the `NotConnectedPeer` that this method returns. pub fn discover(self) -> NotConnectedPeer<'a> { self.parent.nodes.insert(self.peer_id.clone().into_owned(), Node { connection_state: ConnectionState::NotConnected, reputation: 0, - reserved: false, }); - let state = self.parent.nodes.get_mut(&self.peer_id) - .expect("We insert that key into the HashMap right above; QED"); - + let state = self.parent; NotConnectedPeer { state, peer_id: self.peer_id, - num_in: &mut self.parent.num_in, - num_out: &mut self.parent.num_out, - max_in: self.parent.max_in, - max_out: self.parent.max_out, } } } @@ -517,14 +541,13 @@ mod tests { } #[test] - fn reserved_node_doesnt_use_slot() { + fn priority_node_doesnt_use_slot() { let mut peers_state = PeersState::new(1, 1); let id1 = PeerId::random(); let id2 = PeerId::random(); - if let Peer::Unknown(e) = peers_state.peer(&id1) { - let mut p = e.discover(); - p.set_reserved(true); + peers_state.set_priority_group("test", vec![id1.clone()].into_iter().collect()); + if let Peer::NotConnected(p) = peers_state.peer(&id1) { assert!(p.try_accept_incoming().is_ok()); } else { panic!() } @@ -546,23 +569,22 @@ mod tests { } #[test] - fn reserved_not_connected_peer() { + fn priority_not_connected_peer() { let mut peers_state = PeersState::new(25, 25); let id1 = PeerId::random(); let id2 = PeerId::random(); - assert!(peers_state.reserved_not_connected_peer().is_none()); + assert!(peers_state.priority_not_connected_peer().is_none()); peers_state.peer(&id1).into_unknown().unwrap().discover(); peers_state.peer(&id2).into_unknown().unwrap().discover(); - assert!(peers_state.reserved_not_connected_peer().is_none()); - peers_state.peer(&id1).into_not_connected().unwrap().set_reserved(true); - assert!(peers_state.reserved_not_connected_peer().is_some()); - peers_state.peer(&id2).into_not_connected().unwrap().set_reserved(true); - peers_state.peer(&id1).into_not_connected().unwrap().set_reserved(false); - assert!(peers_state.reserved_not_connected_peer().is_some()); - peers_state.peer(&id2).into_not_connected().unwrap().set_reserved(false); - assert!(peers_state.reserved_not_connected_peer().is_none()); + assert!(peers_state.priority_not_connected_peer().is_none()); + peers_state.set_priority_group("test", vec![id1.clone()].into_iter().collect()); + assert!(peers_state.priority_not_connected_peer().is_some()); + peers_state.set_priority_group("test", vec![id2.clone(), id2.clone()].into_iter().collect()); + assert!(peers_state.priority_not_connected_peer().is_some()); + peers_state.set_priority_group("test", vec![].into_iter().collect()); + assert!(peers_state.priority_not_connected_peer().is_none()); } #[test] @@ -577,7 +599,7 @@ mod tests { assert_eq!(peers_state.highest_not_connected_peer().map(|p| p.into_peer_id()), Some(id1.clone())); peers_state.peer(&id2).into_not_connected().unwrap().set_reputation(75); assert_eq!(peers_state.highest_not_connected_peer().map(|p| p.into_peer_id()), Some(id2.clone())); - peers_state.peer(&id2).into_not_connected().unwrap().force_ingoing(); + peers_state.peer(&id2).into_not_connected().unwrap().try_accept_incoming().unwrap(); assert_eq!(peers_state.highest_not_connected_peer().map(|p| p.into_peer_id()), Some(id1.clone())); peers_state.peer(&id1).into_not_connected().unwrap().set_reputation(100); peers_state.peer(&id2).into_connected().unwrap().disconnect(); @@ -587,12 +609,31 @@ mod tests { } #[test] - fn disconnect_reserved_doesnt_panic() { + fn disconnect_priority_doesnt_panic() { let mut peers_state = PeersState::new(1, 1); let id = PeerId::random(); - let mut peer = peers_state.peer(&id).into_unknown().unwrap().discover() - .force_outgoing(); - peer.set_reserved(true); + peers_state.set_priority_group("test", vec![id.clone()].into_iter().collect()); + let peer = peers_state.peer(&id).into_not_connected().unwrap().try_outgoing().unwrap(); peer.disconnect(); } + + #[test] + fn multiple_priority_groups_slot_count() { + let mut peers_state = PeersState::new(1, 1); + let id = PeerId::random(); + + if let Peer::Unknown(p) = peers_state.peer(&id) { + assert!(p.discover().try_accept_incoming().is_ok()); + } else { panic!() } + + assert_eq!(peers_state.num_in, 1); + peers_state.set_priority_group("test1", vec![id.clone()].into_iter().collect()); + assert_eq!(peers_state.num_in, 0); + peers_state.set_priority_group("test2", vec![id.clone()].into_iter().collect()); + assert_eq!(peers_state.num_in, 0); + peers_state.set_priority_group("test1", vec![].into_iter().collect()); + assert_eq!(peers_state.num_in, 0); + peers_state.set_priority_group("test2", vec![].into_iter().collect()); + assert_eq!(peers_state.num_in, 1); + } } diff --git a/core/primitives/Cargo.toml b/core/primitives/Cargo.toml index 8eb62ddf8431ba755029b69d94e7173130767f5d..ab34cfcd1336081448f37778d98e888931c248af 100644 --- a/core/primitives/Cargo.toml +++ b/core/primitives/Cargo.toml @@ -11,7 +11,7 @@ rustc-hex = { version = "2.0", default-features = false } serde = { version = "1.0", optional = true, features = ["derive"] } twox-hash = { version = "1.2.0", optional = true } byteorder = { version = "1.3.1", default-features = false } -primitive-types = { version = "0.2", default-features = false, features = ["codec"] } +primitive-types = { version = "0.2.3", default-features = false, features = ["codec"] } impl-serde = { version = "0.1", optional = true } wasmi = { version = "0.4.3", optional = true } hash-db = { version = "0.12", default-features = false } @@ -25,7 +25,8 @@ sha2 = { version = "0.8", optional = true } substrate-bip39 = { git = "https://github.com/paritytech/substrate-bip39", optional = true } tiny-bip39 = { version = "0.6.1", optional = true } hex = { version = "0.3", optional = true } -regex = {version = "1.1", optional = true } +regex = { version = "1.1", optional = true } +num-traits = { version = "0.2", default-features = false } [dev-dependencies] substrate-serializer = { path = "../serializer" } @@ -71,4 +72,5 @@ std = [ "sha2", "schnorrkel", "regex", + "num-traits/std", ] diff --git a/core/primitives/src/changes_trie.rs b/core/primitives/src/changes_trie.rs index 2fa11f5641d59090673a618f04a97cee958ca560..eb6a75454fe41d3ebd9fd5d363e20ac920dad630 100644 --- a/core/primitives/src/changes_trie.rs +++ b/core/primitives/src/changes_trie.rs @@ -19,6 +19,7 @@ #[cfg(any(feature = "std", test))] use serde::{Serialize, Deserialize}; use parity_codec::{Encode, Decode}; +use num_traits::Zero; /// Substrate changes trie configuration. #[cfg_attr(any(feature = "std", test), derive(Serialize, Deserialize))] @@ -26,10 +27,14 @@ use parity_codec::{Encode, Decode}; pub struct ChangesTrieConfiguration { /// Interval (in blocks) at which level1-digests are created. Digests are not /// created when this is less or equal to 1. - pub digest_interval: u64, + pub digest_interval: u32, /// Maximal number of digest levels in hierarchy. 0 means that digests are not /// created at all (even level1 digests). 1 means only level1-digests are created. /// 2 means that every digest_interval^2 there will be a level2-digest, and so on. + /// Please ensure that maximum digest interval (i.e. digest_interval^digest_levels) + /// is within `u32` limits. Otherwise you'll never see digests covering such intervals + /// && maximal digests interval will be truncated to the last interval that fits + /// `u32` limits. pub digest_levels: u32, } @@ -40,20 +45,30 @@ impl ChangesTrieConfiguration { } /// Do we need to build digest at given block? - pub fn is_digest_build_required_at_block(&self, block: u64) -> bool { - block != 0 + pub fn is_digest_build_required_at_block(&self, block: Number) -> bool + where + Number: From + PartialEq + ::rstd::ops::Rem + Zero, + { + block != 0.into() && self.is_digest_build_enabled() - && block % self.digest_interval == 0 + && (block % self.digest_interval.into()).is_zero() } /// Returns max digest interval. One if digests are not created at all. - /// Returns ::std::u64::MAX instead of panic in the case of overflow. - pub fn max_digest_interval(&self) -> u64 { + pub fn max_digest_interval(&self) -> u32 { if !self.is_digest_build_enabled() { return 1; } - self.digest_interval.saturating_pow(self.digest_levels) + // we'll get >1 loop iteration only when bad configuration parameters are selected + let mut current_level = self.digest_levels; + loop { + if let Some(max_digest_interval) = self.digest_interval.checked_pow(current_level) { + return max_digest_interval; + } + + current_level = current_level - 1; + } } /// Returns Some if digest must be built at given block number. @@ -63,17 +78,21 @@ impl ChangesTrieConfiguration { /// digest interval (in blocks) /// step between blocks we're interested in when digest is built /// ) - pub fn digest_level_at_block(&self, block: u64) -> Option<(u32, u64, u64)> { - if !self.is_digest_build_required_at_block(block) { + pub fn digest_level_at_block(&self, block: Number) -> Option<(u32, u32, u32)> + where + Number: Clone + From + PartialEq + ::rstd::ops::Rem + Zero, + { + if !self.is_digest_build_required_at_block(block.clone()) { return None; } let mut digest_interval = self.digest_interval; let mut current_level = 1u32; - let mut digest_step = 1u64; + let mut digest_step = 1u32; while current_level < self.digest_levels { let new_digest_interval = match digest_interval.checked_mul(self.digest_interval) { - Some(new_digest_interval) if block % new_digest_interval == 0 => new_digest_interval, + Some(new_digest_interval) if (block.clone() % new_digest_interval.into()).is_zero() + => new_digest_interval, _ => break, }; @@ -94,7 +113,7 @@ impl ChangesTrieConfiguration { mod tests { use super::ChangesTrieConfiguration; - fn config(interval: u64, levels: u32) -> ChangesTrieConfiguration { + fn config(interval: u32, levels: u32) -> ChangesTrieConfiguration { ChangesTrieConfiguration { digest_interval: interval, digest_levels: levels, @@ -112,31 +131,31 @@ mod tests { #[test] fn is_digest_build_required_at_block_works() { - assert!(!config(8, 4).is_digest_build_required_at_block(0)); - assert!(!config(8, 4).is_digest_build_required_at_block(1)); - assert!(!config(8, 4).is_digest_build_required_at_block(2)); - assert!(!config(8, 4).is_digest_build_required_at_block(4)); - assert!(config(8, 4).is_digest_build_required_at_block(8)); - assert!(!config(8, 4).is_digest_build_required_at_block(9)); - assert!(config(8, 4).is_digest_build_required_at_block(64)); - assert!(config(8, 4).is_digest_build_required_at_block(64)); - assert!(config(8, 4).is_digest_build_required_at_block(512)); - assert!(config(8, 4).is_digest_build_required_at_block(4096)); - assert!(!config(8, 4).is_digest_build_required_at_block(4103)); - assert!(config(8, 4).is_digest_build_required_at_block(4104)); - assert!(!config(8, 4).is_digest_build_required_at_block(4108)); + assert!(!config(8, 4).is_digest_build_required_at_block(0u64)); + assert!(!config(8, 4).is_digest_build_required_at_block(1u64)); + assert!(!config(8, 4).is_digest_build_required_at_block(2u64)); + assert!(!config(8, 4).is_digest_build_required_at_block(4u64)); + assert!(config(8, 4).is_digest_build_required_at_block(8u64)); + assert!(!config(8, 4).is_digest_build_required_at_block(9u64)); + assert!(config(8, 4).is_digest_build_required_at_block(64u64)); + assert!(config(8, 4).is_digest_build_required_at_block(64u64)); + assert!(config(8, 4).is_digest_build_required_at_block(512u64)); + assert!(config(8, 4).is_digest_build_required_at_block(4096u64)); + assert!(!config(8, 4).is_digest_build_required_at_block(4103u64)); + assert!(config(8, 4).is_digest_build_required_at_block(4104u64)); + assert!(!config(8, 4).is_digest_build_required_at_block(4108u64)); } #[test] fn digest_level_at_block_works() { - assert_eq!(config(8, 4).digest_level_at_block(0), None); - assert_eq!(config(8, 4).digest_level_at_block(7), None); - assert_eq!(config(8, 4).digest_level_at_block(63), None); - assert_eq!(config(8, 4).digest_level_at_block(8), Some((1, 8, 1))); - assert_eq!(config(8, 4).digest_level_at_block(64), Some((2, 64, 8))); - assert_eq!(config(8, 4).digest_level_at_block(512), Some((3, 512, 64))); - assert_eq!(config(8, 4).digest_level_at_block(4096), Some((4, 4096, 512))); - assert_eq!(config(8, 4).digest_level_at_block(4112), Some((1, 8, 1))); + assert_eq!(config(8, 4).digest_level_at_block(0u64), None); + assert_eq!(config(8, 4).digest_level_at_block(7u64), None); + assert_eq!(config(8, 4).digest_level_at_block(63u64), None); + assert_eq!(config(8, 4).digest_level_at_block(8u64), Some((1, 8, 1))); + assert_eq!(config(8, 4).digest_level_at_block(64u64), Some((2, 64, 8))); + assert_eq!(config(8, 4).digest_level_at_block(512u64), Some((3, 512, 64))); + assert_eq!(config(8, 4).digest_level_at_block(4096u64), Some((4, 4096, 512))); + assert_eq!(config(8, 4).digest_level_at_block(4112u64), Some((1, 8, 1))); } #[test] @@ -144,6 +163,6 @@ mod tests { assert_eq!(config(0, 0).max_digest_interval(), 1); assert_eq!(config(2, 2).max_digest_interval(), 4); assert_eq!(config(8, 4).max_digest_interval(), 4096); - assert_eq!(config(::std::u64::MAX, 1024).max_digest_interval(), ::std::u64::MAX); + assert_eq!(config(::std::u32::MAX, 1024).max_digest_interval(), ::std::u32::MAX); } } diff --git a/core/primitives/src/ed25519.rs b/core/primitives/src/ed25519.rs index 135c551e454b794f3358982e1a9a0e012992ae21..e593e997a41c8effbff7627993072829ee75b02b 100644 --- a/core/primitives/src/ed25519.rs +++ b/core/primitives/src/ed25519.rs @@ -413,7 +413,7 @@ impl TraitPair for Pair { /// Derive a child key from a series of given junctions. fn derive>(&self, path: Iter) -> Result { - let mut acc = self.0.public.to_bytes(); + let mut acc = self.0.secret.to_bytes(); for j in path { match j { DeriveJunction::Soft(_cc) => return Err(DeriveError::SoftKeyInPath), @@ -473,7 +473,7 @@ impl TraitPair for Pair { impl Pair { /// Get the seed for this key. pub fn seed(&self) -> &Seed { - self.0.public.as_bytes() + self.0.secret.as_bytes() } /// Exactly as `from_string` except that if no matches are found then, the the first 32 @@ -502,6 +502,16 @@ mod test { ); } + #[test] + fn seed_and_derive_should_work() { + let seed = hex!("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60"); + let pair = Pair::from_seed(seed); + assert_eq!(pair.seed(), &seed); + let path = vec![DeriveJunction::Hard([0u8; 32])]; + let derived = pair.derive(path.into_iter()).ok().unwrap(); + assert_eq!(derived.seed(), &hex!("ede3354e133f9c8e337ddd6ee5415ed4b4ffe5fc7d21e933f4930a3730e5b21c")); + } + #[test] fn test_vector_should_work() { let pair: Pair = Pair::from_seed(hex!("9d61b19deffd5a60ba844af492ec2cc44449c5697b326919703bac031cae7f60")); diff --git a/core/primitives/src/hexdisplay.rs b/core/primitives/src/hexdisplay.rs index d748208d0e09ff911be9245a4588ece343191d59..cd2b6c18cb7fed04ecb08a2a6ac936c7853a1762 100644 --- a/core/primitives/src/hexdisplay.rs +++ b/core/primitives/src/hexdisplay.rs @@ -21,7 +21,7 @@ pub struct HexDisplay<'a>(&'a [u8]); impl<'a> HexDisplay<'a> { /// Create new instance that will display `d` as a hex string when displayed. - pub fn from(d: &'a AsBytesRef) -> Self { HexDisplay(d.as_bytes_ref()) } + pub fn from(d: &'a dyn AsBytesRef) -> Self { HexDisplay(d.as_bytes_ref()) } } impl<'a> ::core::fmt::Display for HexDisplay<'a> { @@ -79,7 +79,7 @@ pub fn ascii_format(asciish: &[u8]) -> String { let mut latch = false; for c in asciish { match (latch, *c) { - (false, 32...127) => r.push(*c as char), + (false, 32..=127) => r.push(*c as char), _ => { if !latch { r.push('#'); diff --git a/core/primitives/src/lib.rs b/core/primitives/src/lib.rs index c9008171df94376893596b39790d15db3d8bffe4..7c0fd324fe0e1aaa25403dd6a920f2f526205d19 100644 --- a/core/primitives/src/lib.rs +++ b/core/primitives/src/lib.rs @@ -56,6 +56,7 @@ pub mod ed25519; pub mod sr25519; pub mod hash; mod hasher; +pub mod offchain; pub mod sandbox; pub mod storage; pub mod uint; @@ -85,25 +86,11 @@ pub enum ExecutionContext { /// Context used for block construction. BlockConstruction, /// Offchain worker context. - OffchainWorker(Box), + OffchainWorker(Box), /// Context used for other calls. Other, } -/// An extended externalities for offchain workers. -pub trait OffchainExt { - /// Submits an extrinsics. - /// - /// The extrinsic will either go to the pool (signed) - /// or to the next produced block (inherent). - fn submit_extrinsic(&mut self, extrinsic: Vec); -} -impl OffchainExt for Box { - fn submit_extrinsic(&mut self, ex: Vec) { - (&mut **self).submit_extrinsic(ex) - } -} - /// Hex-serialized shim for `Vec`. #[derive(PartialEq, Eq, Clone)] #[cfg_attr(feature = "std", derive(Serialize, Deserialize, Debug, Hash, PartialOrd, Ord))] diff --git a/core/primitives/src/offchain.rs b/core/primitives/src/offchain.rs new file mode 100644 index 0000000000000000000000000000000000000000..7d54c9d61eb31d47d8e3bca8232544ca915203b2 --- /dev/null +++ b/core/primitives/src/offchain.rs @@ -0,0 +1,410 @@ +// 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 . + +//! Offchain workers types + +use rstd::prelude::{Vec, Box}; +use rstd::convert::TryFrom; + +/// A type of supported crypto. +#[derive(Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +#[repr(C)] +pub enum CryptoKind { + /// SR25519 crypto (Schnorrkel) + Sr25519 = 1, + /// ED25519 crypto (Edwards) + Ed25519 = 2, +} + +impl TryFrom for CryptoKind { + type Error = (); + + fn try_from(kind: u32) -> Result { + match kind { + e if e == u32::from(CryptoKind::Sr25519 as u8) => Ok(CryptoKind::Sr25519), + e if e == u32::from(CryptoKind::Ed25519 as u8) => Ok(CryptoKind::Ed25519), + _ => Err(()) + } + } +} + +/// Opaque type for created crypto keys. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct CryptoKeyId(pub u16); + +/// Opaque type for offchain http requests. +#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct HttpRequestId(pub u16); + +/// An error enum returned by some http methods. +#[derive(Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +#[repr(C)] +pub enum HttpError { + /// The requested action couldn't been completed within a deadline. + DeadlineReached = 1, + /// There was an IO Error while processing the request. + IoError = 2, +} + +impl TryFrom for HttpError { + type Error = (); + + fn try_from(error: u32) -> Result { + match error { + e if e == HttpError::DeadlineReached as u8 as u32 => Ok(HttpError::DeadlineReached), + e if e == HttpError::IoError as u8 as u32 => Ok(HttpError::IoError), + _ => Err(()) + } + } +} + +/// Status of the HTTP request +#[derive(Clone, Copy, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub enum HttpRequestStatus { + /// Deadline was reached while we waited for this request to finish. + /// + /// Note the deadline is controlled by the calling part, it not necessarily means + /// that the request has timed out. + DeadlineReached, + /// Request timed out. + /// + /// This means that the request couldn't be completed by the host environment + /// within a reasonable time (according to the host), has now been terminated + /// and is considered finished. + /// To retry the request you need to construct it again. + Timeout, + /// Request status of this ID is not known. + Unknown, + /// The request has finished with given status code. + Finished(u16), +} + +impl From for u32 { + fn from(status: HttpRequestStatus) -> Self { + match status { + HttpRequestStatus::Unknown => 0, + HttpRequestStatus::DeadlineReached => 10, + HttpRequestStatus::Timeout => 20, + HttpRequestStatus::Finished(code) => u32::from(code), + } + } +} + +impl TryFrom for HttpRequestStatus { + type Error = (); + + fn try_from(status: u32) -> Result { + match status { + 0 => Ok(HttpRequestStatus::Unknown), + 10 => Ok(HttpRequestStatus::DeadlineReached), + 20 => Ok(HttpRequestStatus::Timeout), + 100..=999 => u16::try_from(status).map(HttpRequestStatus::Finished).map_err(|_| ()), + _ => Err(()), + } + } +} + +/// Opaque timestamp type +#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Default)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct Timestamp(u64); + +/// Duration type +#[derive(Clone, Copy, PartialEq, Eq, Ord, PartialOrd, Default)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct Duration(u64); + +impl Duration { + /// Create new duration representing given number of milliseconds. + pub fn from_millis(millis: u64) -> Self { + Duration(millis) + } + + /// Returns number of milliseconds this Duration represents. + pub fn millis(&self) -> u64 { + self.0 + } +} + +impl Timestamp { + /// Creates new `Timestamp` given unix timestamp in miliseconds. + pub fn from_unix_millis(millis: u64) -> Self { + Timestamp(millis) + } + + /// Increase the timestamp by given `Duration`. + pub fn add(&self, duration: Duration) -> Timestamp { + Timestamp(self.0.saturating_add(duration.0)) + } + + /// Decrease the timestamp by given `Duration` + pub fn sub(&self, duration: Duration) -> Timestamp { + Timestamp(self.0.saturating_sub(duration.0)) + } + + /// Returns a saturated difference (Duration) between two Timestamps. + pub fn diff(&self, other: &Self) -> Duration { + Duration(self.0.saturating_sub(other.0)) + } + + /// Return number of milliseconds since UNIX epoch. + pub fn unix_millis(&self) -> u64 { + self.0 + } +} + +/// An extended externalities for offchain workers. +pub trait Externalities { + /// Submit transaction. + /// + /// The transaction will end up in the pool and be propagated to others. + fn submit_transaction(&mut self, extrinsic: Vec) -> Result<(), ()>; + + /// Create new key(pair) for signing/encryption/decryption. + /// + /// Returns an error if given crypto kind is not supported. + fn new_crypto_key(&mut self, crypto: CryptoKind) -> Result; + + /// Encrypt a piece of data using given crypto key. + /// + /// If `key` is `None`, it will attempt to use current authority key. + /// + /// Returns an error if `key` is not available or does not exist. + fn encrypt(&mut self, key: Option, data: &[u8]) -> Result, ()>; + + /// Decrypt a piece of data using given crypto key. + /// + /// If `key` is `None`, it will attempt to use current authority key. + /// + /// Returns an error if data cannot be decrypted or the `key` is not available or does not exist. + fn decrypt(&mut self, key: Option, data: &[u8]) -> Result, ()>; + + /// Sign a piece of data using given crypto key. + /// + /// If `key` is `None`, it will attempt to use current authority key. + /// + /// Returns an error if `key` is not available or does not exist. + fn sign(&mut self, key: Option, data: &[u8]) -> Result, ()>; + + /// Verifies that `signature` for `msg` matches given `key`. + /// + /// Returns an `Ok` with `true` in case it does, `false` in case it doesn't. + /// Returns an error in case the key is not available or does not exist or the parameters + /// lengths are incorrect. + fn verify(&mut self, key: Option, msg: &[u8], signature: &[u8]) -> Result; + + /// Returns current UNIX timestamp (in millis) + fn timestamp(&mut self) -> Timestamp; + + /// Pause the execution until `deadline` is reached. + fn sleep_until(&mut self, deadline: Timestamp); + + /// Returns a random seed. + /// + /// This is a trully random non deterministic seed generated by host environment. + /// Obviously fine in the off-chain worker context. + fn random_seed(&mut self) -> [u8; 32]; + + /// Sets a value in the local storage. + /// + /// Note this storage is not part of the consensus, it's only accessible by + /// offchain worker tasks running on the same machine. It IS persisted between runs. + fn local_storage_set(&mut self, key: &[u8], value: &[u8]); + + /// Sets a value in the local storage if it matches current value. + /// + /// Since multiple offchain workers may be running concurrently, to prevent + /// data races use CAS to coordinate between them. + /// + /// Note this storage is not part of the consensus, it's only accessible by + /// offchain worker tasks running on the same machine. It IS persisted between runs. + fn local_storage_compare_and_set(&mut self, key: &[u8], old_value: &[u8], new_value: &[u8]); + + /// Gets a value from the local storage. + /// + /// If the value does not exist in the storage `None` will be returned. + /// Note this storage is not part of the consensus, it's only accessible by + /// offchain worker tasks running on the same machine. It IS persisted between runs. + fn local_storage_get(&mut self, key: &[u8]) -> Option>; + + /// Initiaties a http request given HTTP verb and the URL. + /// + /// Meta is a future-reserved field containing additional, parity-codec encoded parameters. + /// Returns the id of newly started request. + fn http_request_start( + &mut self, + method: &str, + uri: &str, + meta: &[u8] + ) -> Result; + + /// Append header to the request. + fn http_request_add_header( + &mut self, + request_id: HttpRequestId, + name: &str, + value: &str + ) -> Result<(), ()>; + + /// Write a chunk of request body. + /// + /// Writing an empty chunks finalises the request. + /// Passing `None` as deadline blocks forever. + /// + /// Returns an error in case deadline is reached or the chunk couldn't be written. + fn http_request_write_body( + &mut self, + request_id: HttpRequestId, + chunk: &[u8], + deadline: Option + ) -> Result<(), HttpError>; + + /// Block and wait for the responses for given requests. + /// + /// Returns a vector of request statuses (the len is the same as ids). + /// Note that if deadline is not provided the method will block indefinitely, + /// otherwise unready responses will produce `DeadlineReached` status. + /// + /// Passing `None` as deadline blocks forever. + fn http_response_wait( + &mut self, + ids: &[HttpRequestId], + deadline: Option + ) -> Vec; + + /// Read all response headers. + /// + /// Returns a vector of pairs `(HeaderKey, HeaderValue)`. + fn http_response_headers( + &mut self, + request_id: HttpRequestId + ) -> Vec<(Vec, Vec)>; + + /// Read a chunk of body response to given buffer. + /// + /// Returns the number of bytes written or an error in case a deadline + /// is reached or server closed the connection. + /// Passing `None` as a deadline blocks forever. + fn http_response_read_body( + &mut self, + request_id: HttpRequestId, + buffer: &mut [u8], + deadline: Option + ) -> Result; + +} +impl Externalities for Box { + fn submit_transaction(&mut self, ex: Vec) -> Result<(), ()> { + (&mut **self).submit_transaction(ex) + } + + fn new_crypto_key(&mut self, crypto: CryptoKind) -> Result { + (&mut **self).new_crypto_key(crypto) + } + + fn encrypt(&mut self, key: Option, data: &[u8]) -> Result, ()> { + (&mut **self).encrypt(key, data) + } + + fn decrypt(&mut self, key: Option, data: &[u8]) -> Result, ()> { + (&mut **self).decrypt(key, data) + } + + fn sign(&mut self, key: Option, data: &[u8]) -> Result, ()> { + (&mut **self).sign(key, data) + } + + fn verify(&mut self, key: Option, msg: &[u8], signature: &[u8]) -> Result { + (&mut **self).verify(key, msg, signature) + } + + fn timestamp(&mut self) -> Timestamp { + (&mut **self).timestamp() + } + + fn sleep_until(&mut self, deadline: Timestamp) { + (&mut **self).sleep_until(deadline) + } + + fn random_seed(&mut self) -> [u8; 32] { + (&mut **self).random_seed() + } + + fn local_storage_set(&mut self, key: &[u8], value: &[u8]) { + (&mut **self).local_storage_set(key, value) + } + + fn local_storage_compare_and_set(&mut self, key: &[u8], old_value: &[u8], new_value: &[u8]) { + (&mut **self).local_storage_compare_and_set(key, old_value, new_value) + } + + fn local_storage_get(&mut self, key: &[u8]) -> Option> { + (&mut **self).local_storage_get(key) + } + + fn http_request_start(&mut self, method: &str, uri: &str, meta: &[u8]) -> Result { + (&mut **self).http_request_start(method, uri, meta) + } + + fn http_request_add_header(&mut self, request_id: HttpRequestId, name: &str, value: &str) -> Result<(), ()> { + (&mut **self).http_request_add_header(request_id, name, value) + } + + fn http_request_write_body( + &mut self, + request_id: HttpRequestId, + chunk: &[u8], + deadline: Option + ) -> Result<(), HttpError> { + (&mut **self).http_request_write_body(request_id, chunk, deadline) + } + + fn http_response_wait(&mut self, ids: &[HttpRequestId], deadline: Option) -> Vec { + (&mut **self).http_response_wait(ids, deadline) + } + + fn http_response_headers(&mut self, request_id: HttpRequestId) -> Vec<(Vec, Vec)> { + (&mut **self).http_response_headers(request_id) + } + + fn http_response_read_body( + &mut self, + request_id: HttpRequestId, + buffer: &mut [u8], + deadline: Option + ) -> Result { + (&mut **self).http_response_read_body(request_id, buffer, deadline) + } +} + + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn timestamp_ops() { + let t = Timestamp(5); + assert_eq!(t.add(Duration::from_millis(10)), Timestamp(15)); + assert_eq!(t.sub(Duration::from_millis(10)), Timestamp(0)); + assert_eq!(t.diff(&Timestamp(3)), Duration(2)); + } +} diff --git a/core/primitives/src/sr25519.rs b/core/primitives/src/sr25519.rs index 8f309ec0306a1523ae9223efc3df8976c94f6e74..876dcb707832487b67b25d127f5cb331c7cf8848 100644 --- a/core/primitives/src/sr25519.rs +++ b/core/primitives/src/sr25519.rs @@ -204,16 +204,16 @@ impl From for Signature { } #[cfg(feature = "std")] -impl ::std::fmt::Debug for Signature { +impl std::fmt::Debug for Signature { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { write!(f, "{}", crate::hexdisplay::HexDisplay::from(&self.0)) } } #[cfg(feature = "std")] -impl ::std::hash::Hash for Signature { - fn hash(&self, state: &mut H) { - ::std::hash::Hash::hash(&self.0[..], state); +impl std::hash::Hash for Signature { + fn hash(&self, state: &mut H) { + std::hash::Hash::hash(&self.0[..], state); } } @@ -304,15 +304,13 @@ impl Public { /// Return a `Vec` filled with raw data. #[cfg(feature = "std")] - pub fn to_raw_vec(self) -> Vec { - let r: &[u8; 32] = self.as_ref(); - r.to_vec() + pub fn into_raw_vec(self) -> Vec { + self.0.to_vec() } /// Return a slice filled with raw data. pub fn as_slice(&self) -> &[u8] { - let r: &[u8; 32] = self.as_ref(); - &r[..] + &self.0 } /// Return a slice filled with raw data. @@ -637,7 +635,7 @@ mod test { #[test] fn verify_from_wasm_works() { // The values in this test case are compared to the output of `node-test.js` in schnorrkel-js. - // + // // This is to make sure that the wasm library is compatible. let pk = Pair::from_seed(hex!("0000000000000000000000000000000000000000000000000000000000000000")); let public = pk.public(); diff --git a/core/primitives/src/u32_trait.rs b/core/primitives/src/u32_trait.rs index 3fcdceac4cbbfacea532c498648ccee980a0e36c..d8fac34c301ab4ee78417c1d8c8755e89b53795a 100644 --- a/core/primitives/src/u32_trait.rs +++ b/core/primitives/src/u32_trait.rs @@ -21,6 +21,7 @@ pub trait Value { /// The actual value represented by the impl'ing type. const VALUE: u32; } + /// Type representing the value 0 for the `Value` trait. pub struct _0; impl Value for _0 { const VALUE: u32 = 0; } /// Type representing the value 1 for the `Value` trait. @@ -55,22 +56,174 @@ pub struct _14; impl Value for _14 { const VALUE: u32 = 14; } pub struct _15; impl Value for _15 { const VALUE: u32 = 15; } /// Type representing the value 16 for the `Value` trait. pub struct _16; impl Value for _16 { const VALUE: u32 = 16; } +/// Type representing the value 17 for the `Value` trait. +pub struct _17; impl Value for _17 { const VALUE: u32 = 17; } +/// Type representing the value 18 for the `Value` trait. +pub struct _18; impl Value for _18 { const VALUE: u32 = 18; } +/// Type representing the value 19 for the `Value` trait. +pub struct _19; impl Value for _19 { const VALUE: u32 = 19; } +/// Type representing the value 20 for the `Value` trait. +pub struct _20; impl Value for _20 { const VALUE: u32 = 20; } +/// Type representing the value 21 for the `Value` trait. +pub struct _21; impl Value for _21 { const VALUE: u32 = 21; } +/// Type representing the value 22 for the `Value` trait. +pub struct _22; impl Value for _22 { const VALUE: u32 = 22; } +/// Type representing the value 23 for the `Value` trait. +pub struct _23; impl Value for _23 { const VALUE: u32 = 23; } /// Type representing the value 24 for the `Value` trait. pub struct _24; impl Value for _24 { const VALUE: u32 = 24; } +/// Type representing the value 25 for the `Value` trait. +pub struct _25; impl Value for _25 { const VALUE: u32 = 25; } +/// Type representing the value 26 for the `Value` trait. +pub struct _26; impl Value for _26 { const VALUE: u32 = 26; } +/// Type representing the value 27 for the `Value` trait. +pub struct _27; impl Value for _27 { const VALUE: u32 = 27; } +/// Type representing the value 28 for the `Value` trait. +pub struct _28; impl Value for _28 { const VALUE: u32 = 28; } +/// Type representing the value 29 for the `Value` trait. +pub struct _29; impl Value for _29 { const VALUE: u32 = 29; } +/// Type representing the value 30 for the `Value` trait. +pub struct _30; impl Value for _30 { const VALUE: u32 = 30; } +/// Type representing the value 31 for the `Value` trait. +pub struct _31; impl Value for _31 { const VALUE: u32 = 31; } /// Type representing the value 32 for the `Value` trait. pub struct _32; impl Value for _32 { const VALUE: u32 = 32; } +/// Type representing the value 33 for the `Value` trait. +pub struct _33; impl Value for _33 { const VALUE: u32 = 33; } +/// Type representing the value 34 for the `Value` trait. +pub struct _34; impl Value for _34 { const VALUE: u32 = 34; } +/// Type representing the value 35 for the `Value` trait. +pub struct _35; impl Value for _35 { const VALUE: u32 = 35; } +/// Type representing the value 36 for the `Value` trait. +pub struct _36; impl Value for _36 { const VALUE: u32 = 36; } +/// Type representing the value 37 for the `Value` trait. +pub struct _37; impl Value for _37 { const VALUE: u32 = 37; } +/// Type representing the value 38 for the `Value` trait. +pub struct _38; impl Value for _38 { const VALUE: u32 = 38; } +/// Type representing the value 39 for the `Value` trait. +pub struct _39; impl Value for _39 { const VALUE: u32 = 39; } /// Type representing the value 40 for the `Value` trait. pub struct _40; impl Value for _40 { const VALUE: u32 = 40; } +/// Type representing the value 41 for the `Value` trait. +pub struct _41; impl Value for _41 { const VALUE: u32 = 41; } +/// Type representing the value 42 for the `Value` trait. +pub struct _42; impl Value for _42 { const VALUE: u32 = 42; } +/// Type representing the value 43 for the `Value` trait. +pub struct _43; impl Value for _43 { const VALUE: u32 = 43; } +/// Type representing the value 44 for the `Value` trait. +pub struct _44; impl Value for _44 { const VALUE: u32 = 44; } +/// Type representing the value 45 for the `Value` trait. +pub struct _45; impl Value for _45 { const VALUE: u32 = 45; } +/// Type representing the value 46 for the `Value` trait. +pub struct _46; impl Value for _46 { const VALUE: u32 = 46; } +/// Type representing the value 47 for the `Value` trait. +pub struct _47; impl Value for _47 { const VALUE: u32 = 47; } /// Type representing the value 48 for the `Value` trait. pub struct _48; impl Value for _48 { const VALUE: u32 = 48; } +/// Type representing the value 49 for the `Value` trait. +pub struct _49; impl Value for _49 { const VALUE: u32 = 49; } +/// Type representing the value 50 for the `Value` trait. +pub struct _50; impl Value for _50 { const VALUE: u32 = 50; } +/// Type representing the value 51 for the `Value` trait. +pub struct _51; impl Value for _51 { const VALUE: u32 = 51; } +/// Type representing the value 52 for the `Value` trait. +pub struct _52; impl Value for _52 { const VALUE: u32 = 52; } +/// Type representing the value 53 for the `Value` trait. +pub struct _53; impl Value for _53 { const VALUE: u32 = 53; } +/// Type representing the value 54 for the `Value` trait. +pub struct _54; impl Value for _54 { const VALUE: u32 = 54; } +/// Type representing the value 55 for the `Value` trait. +pub struct _55; impl Value for _55 { const VALUE: u32 = 55; } /// Type representing the value 56 for the `Value` trait. pub struct _56; impl Value for _56 { const VALUE: u32 = 56; } +/// Type representing the value 57 for the `Value` trait. +pub struct _57; impl Value for _57 { const VALUE: u32 = 57; } +/// Type representing the value 58 for the `Value` trait. +pub struct _58; impl Value for _58 { const VALUE: u32 = 58; } +/// Type representing the value 59 for the `Value` trait. +pub struct _59; impl Value for _59 { const VALUE: u32 = 59; } +/// Type representing the value 60 for the `Value` trait. +pub struct _60; impl Value for _60 { const VALUE: u32 = 60; } +/// Type representing the value 61 for the `Value` trait. +pub struct _61; impl Value for _61 { const VALUE: u32 = 61; } +/// Type representing the value 62 for the `Value` trait. +pub struct _62; impl Value for _62 { const VALUE: u32 = 62; } +/// Type representing the value 63 for the `Value` trait. +pub struct _63; impl Value for _63 { const VALUE: u32 = 63; } /// Type representing the value 64 for the `Value` trait. pub struct _64; impl Value for _64 { const VALUE: u32 = 64; } +/// Type representing the value 65 for the `Value` trait. +pub struct _65; impl Value for _65 { const VALUE: u32 = 65; } +/// Type representing the value 66 for the `Value` trait. +pub struct _66; impl Value for _66 { const VALUE: u32 = 66; } +/// Type representing the value 67 for the `Value` trait. +pub struct _67; impl Value for _67 { const VALUE: u32 = 67; } +/// Type representing the value 68 for the `Value` trait. +pub struct _68; impl Value for _68 { const VALUE: u32 = 68; } +/// Type representing the value 69 for the `Value` trait. +pub struct _69; impl Value for _69 { const VALUE: u32 = 69; } +/// Type representing the value 70 for the `Value` trait. +pub struct _70; impl Value for _70 { const VALUE: u32 = 70; } +/// Type representing the value 71 for the `Value` trait. +pub struct _71; impl Value for _71 { const VALUE: u32 = 71; } +/// Type representing the value 72 for the `Value` trait. +pub struct _72; impl Value for _72 { const VALUE: u32 = 72; } +/// Type representing the value 73 for the `Value` trait. +pub struct _73; impl Value for _73 { const VALUE: u32 = 73; } +/// Type representing the value 74 for the `Value` trait. +pub struct _74; impl Value for _74 { const VALUE: u32 = 74; } +/// Type representing the value 75 for the `Value` trait. +pub struct _75; impl Value for _75 { const VALUE: u32 = 75; } +/// Type representing the value 76 for the `Value` trait. +pub struct _76; impl Value for _76 { const VALUE: u32 = 76; } +/// Type representing the value 77 for the `Value` trait. +pub struct _77; impl Value for _77 { const VALUE: u32 = 77; } +/// Type representing the value 78 for the `Value` trait. +pub struct _78; impl Value for _78 { const VALUE: u32 = 78; } +/// Type representing the value 79 for the `Value` trait. +pub struct _79; impl Value for _79 { const VALUE: u32 = 79; } /// Type representing the value 80 for the `Value` trait. pub struct _80; impl Value for _80 { const VALUE: u32 = 80; } +/// Type representing the value 81 for the `Value` trait. +pub struct _81; impl Value for _81 { const VALUE: u32 = 81; } +/// Type representing the value 82 for the `Value` trait. +pub struct _82; impl Value for _82 { const VALUE: u32 = 82; } +/// Type representing the value 83 for the `Value` trait. +pub struct _83; impl Value for _83 { const VALUE: u32 = 83; } +/// Type representing the value 84 for the `Value` trait. +pub struct _84; impl Value for _84 { const VALUE: u32 = 84; } +/// Type representing the value 85 for the `Value` trait. +pub struct _85; impl Value for _85 { const VALUE: u32 = 85; } +/// Type representing the value 86 for the `Value` trait. +pub struct _86; impl Value for _86 { const VALUE: u32 = 86; } +/// Type representing the value 87 for the `Value` trait. +pub struct _87; impl Value for _87 { const VALUE: u32 = 87; } +/// Type representing the value 88 for the `Value` trait. +pub struct _88; impl Value for _88 { const VALUE: u32 = 88; } +/// Type representing the value 89 for the `Value` trait. +pub struct _89; impl Value for _89 { const VALUE: u32 = 89; } +/// Type representing the value 90 for the `Value` trait. +pub struct _90; impl Value for _90 { const VALUE: u32 = 90; } +/// Type representing the value 91 for the `Value` trait. +pub struct _91; impl Value for _91 { const VALUE: u32 = 91; } +/// Type representing the value 92 for the `Value` trait. +pub struct _92; impl Value for _92 { const VALUE: u32 = 92; } +/// Type representing the value 93 for the `Value` trait. +pub struct _93; impl Value for _93 { const VALUE: u32 = 93; } +/// Type representing the value 94 for the `Value` trait. +pub struct _94; impl Value for _94 { const VALUE: u32 = 94; } +/// Type representing the value 95 for the `Value` trait. +pub struct _95; impl Value for _95 { const VALUE: u32 = 95; } /// Type representing the value 96 for the `Value` trait. pub struct _96; impl Value for _96 { const VALUE: u32 = 96; } +/// Type representing the value 97 for the `Value` trait. +pub struct _97; impl Value for _97 { const VALUE: u32 = 97; } +/// Type representing the value 98 for the `Value` trait. +pub struct _98; impl Value for _98 { const VALUE: u32 = 98; } +/// Type representing the value 99 for the `Value` trait. +pub struct _99; impl Value for _99 { const VALUE: u32 = 99; } +/// Type representing the value 100 for the `Value` trait. +pub struct _100; impl Value for _100 { const VALUE: u32 = 100; } /// Type representing the value 112 for the `Value` trait. pub struct _112; impl Value for _112 { const VALUE: u32 = 112; } /// Type representing the value 128 for the `Value` trait. @@ -87,3 +240,4 @@ pub struct _256; impl Value for _256 { const VALUE: u32 = 256; } pub struct _384; impl Value for _384 { const VALUE: u32 = 384; } /// Type representing the value 512 for the `Value` trait. pub struct _512; impl Value for _512 { const VALUE: u32 = 512; } + diff --git a/core/rpc-servers/Cargo.toml b/core/rpc-servers/Cargo.toml index 41cfb6aeea15f6a6de3720254ebf88b986621059..bca094b572d5f1d6ed6f5a143f8eaa27d1168bed 100644 --- a/core/rpc-servers/Cargo.toml +++ b/core/rpc-servers/Cargo.toml @@ -5,9 +5,9 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -http = { package = "jsonrpc-http-server", version = "10.0.1" } -pubsub = { package = "jsonrpc-pubsub", version = "10.0.1" } -ws = { package = "jsonrpc-ws-server", version = "10.0.1" } +http = { package = "jsonrpc-http-server", version = "12.0.0" } +pubsub = { package = "jsonrpc-pubsub", version = "12.0.0" } +ws = { package = "jsonrpc-ws-server", version = "12.0.0" } log = "0.4" serde = "1.0" substrate-rpc = { path = "../rpc" } diff --git a/core/rpc-servers/src/lib.rs b/core/rpc-servers/src/lib.rs index b37895c503f22cc3d1e1486528005948e0a11e01..adf560ce5a6375eeee780ecace7ef6c42908959a 100644 --- a/core/rpc-servers/src/lib.rs +++ b/core/rpc-servers/src/lib.rs @@ -24,9 +24,12 @@ use std::io; use log::error; use sr_primitives::{traits::{Block as BlockT, NumberFor}, generic::SignedBlock}; -/// Maximal payload accepted by RPC servers +/// Maximal payload accepted by RPC servers. const MAX_PAYLOAD: usize = 15 * 1024 * 1024; +/// Default maximum number of connections for WS RPC servers. +const WS_MAX_CONNECTIONS: usize = 100; + type Metadata = apis::metadata::Metadata; type RpcHandler = pubsub::PubSubHandler; pub type HttpServer = http::Server; @@ -76,17 +79,19 @@ pub fn start_http( /// Start WS server listening on given address. pub fn start_ws( addr: &std::net::SocketAddr, + max_connections: Option, cors: Option<&Vec>, io: RpcHandler, ) -> io::Result { ws::ServerBuilder::with_meta_extractor(io, |context: &ws::RequestContext| Metadata::new(context.sender())) .max_payload(MAX_PAYLOAD) + .max_connections(max_connections.unwrap_or(WS_MAX_CONNECTIONS)) .allowed_origins(map_cors(cors)) .start(addr) .map_err(|err| match err { - ws::Error(ws::ErrorKind::Io(io), _) => io, - ws::Error(ws::ErrorKind::ConnectionClosed, _) => io::ErrorKind::BrokenPipe.into(), - ws::Error(e, _) => { + ws::Error::Io(io) => io, + ws::Error::ConnectionClosed => io::ErrorKind::BrokenPipe.into(), + e => { error!("{}", e); io::ErrorKind::Other.into() } diff --git a/core/rpc/Cargo.toml b/core/rpc/Cargo.toml index d0ead8224e93720ce3f4bf9a53d4ddd0bc956e09..6ef9af2a0ad63a7fa58265c1006a0f441d4ab4d1 100644 --- a/core/rpc/Cargo.toml +++ b/core/rpc/Cargo.toml @@ -5,12 +5,13 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -error-chain = "0.12" -jsonrpc-core = "10.0.1" -jsonrpc-pubsub = "10.0.1" -jsonrpc-derive = "10.0.2" +derive_more = "0.14.0" +jsonrpc-core = "12.0.0" +jsonrpc-core-client = "12.0.0" +jsonrpc-pubsub = "12.0.0" +jsonrpc-derive = "12.0.0" log = "0.4" -parking_lot = "0.7.1" +parking_lot = "0.8.0" parity-codec = "3.3" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" @@ -28,7 +29,5 @@ tokio = "0.1.7" assert_matches = "1.1" futures = "0.1.17" sr-io = { path = "../sr-io" } -test_client = { package = "substrate-test-client", path = "../test-client" } -test_runtime = { package = "substrate-test-runtime", path = "../test-runtime" } -consensus = { package = "substrate-consensus-common", path = "../consensus/common" } +test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" } rustc-hex = "2.0" diff --git a/core/rpc/src/author/error.rs b/core/rpc/src/author/error.rs index 0084c4da8fc0e0b7473244d2adb85e7f841a8d13..008a70b6744b9358248261716f030bc16822516a 100644 --- a/core/rpc/src/author/error.rs +++ b/core/rpc/src/author/error.rs @@ -16,35 +16,37 @@ //! Authoring RPC module errors. -use error_chain::*; use client; use transaction_pool::txpool; use crate::rpc; use crate::errors; -error_chain! { - foreign_links { - Client(client::error::Error) #[doc = "Client error"]; - } - links { - Pool(txpool::error::Error, txpool::error::ErrorKind) #[doc = "Pool error"]; - } - errors { - /// Not implemented yet - Unimplemented { - description("not yet implemented"), - display("Method Not Implemented"), - } - /// Incorrect extrinsic format. - BadFormat { - description("bad format"), - display("Invalid extrinsic format"), - } - /// Verification error - Verification(e: Box<::std::error::Error + Send>) { - description("extrinsic verification error"), - display("Extrinsic verification error: {}", e.description()), +/// Author RPC Result type. +pub type Result = std::result::Result; + +/// Author RPC errors. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Client error. + Client(client::error::Error), + /// Transaction pool error, + Pool(txpool::error::Error), + /// Verification error + #[display(fmt="Extrinsic verification error: {}", "_0.description()")] + Verification(Box), + /// Incorrect extrinsic format. + #[display(fmt="Invalid extrinsic format")] + BadFormat, +} + +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Client(ref err) => Some(err), + Error::Pool(ref err) => Some(err), + Error::Verification(ref err) => Some(&**err), + _ => None, } } } @@ -73,49 +75,50 @@ const POOL_IMMEDIATELY_DROPPED: i64 = POOL_INVALID_TX + 6; impl From for rpc::Error { fn from(e: Error) -> Self { + use txpool::error::{Error as PoolError}; + match e { - Error(ErrorKind::Unimplemented, _) => errors::unimplemented(), - Error(ErrorKind::BadFormat, _) => rpc::Error { + Error::BadFormat => rpc::Error { code: rpc::ErrorCode::ServerError(BAD_FORMAT), message: "Extrinsic has invalid format.".into(), data: None, }, - Error(ErrorKind::Verification(e), _) => rpc::Error { + Error::Verification(e) => rpc::Error { code: rpc::ErrorCode::ServerError(VERIFICATION_ERROR), message: e.description().into(), data: Some(format!("{:?}", e).into()), }, - Error(ErrorKind::Pool(txpool::error::ErrorKind::InvalidTransaction(code)), _) => rpc::Error { + Error::Pool(PoolError::InvalidTransaction(code)) => rpc::Error { code: rpc::ErrorCode::ServerError(POOL_INVALID_TX), message: "Invalid Transaction".into(), data: Some(code.into()), }, - Error(ErrorKind::Pool(txpool::error::ErrorKind::UnknownTransactionValidity(code)), _) => rpc::Error { + Error::Pool(PoolError::UnknownTransactionValidity(code)) => rpc::Error { code: rpc::ErrorCode::ServerError(POOL_UNKNOWN_VALIDITY), message: "Unknown Transaction Validity".into(), data: Some(code.into()), }, - Error(ErrorKind::Pool(txpool::error::ErrorKind::TemporarilyBanned), _) => rpc::Error { + Error::Pool(PoolError::TemporarilyBanned) => rpc::Error { code: rpc::ErrorCode::ServerError(POOL_TEMPORARILY_BANNED), message: "Transaction is temporarily banned".into(), data: None, }, - Error(ErrorKind::Pool(txpool::error::ErrorKind::AlreadyImported(hash)), _) => rpc::Error { + Error::Pool(PoolError::AlreadyImported(hash)) => rpc::Error { code: rpc::ErrorCode::ServerError(POOL_ALREADY_IMPORTED), message: "Transaction Already Imported".into(), data: Some(format!("{:?}", hash).into()), }, - Error(ErrorKind::Pool(txpool::error::ErrorKind::TooLowPriority(old, new)), _) => rpc::Error { + Error::Pool(PoolError::TooLowPriority { old, new }) => rpc::Error { code: rpc::ErrorCode::ServerError(POOL_TOO_LOW_PRIORITY), message: format!("Priority is too low: ({} vs {})", old, new), data: Some("The transaction has too low priority to replace another transaction already in the pool.".into()), }, - Error(ErrorKind::Pool(txpool::error::ErrorKind::CycleDetected), _) => rpc::Error { + Error::Pool(PoolError::CycleDetected) => rpc::Error { code: rpc::ErrorCode::ServerError(POOL_CYCLE_DETECTED), message: "Cycle Detected".into(), data: None, }, - Error(ErrorKind::Pool(txpool::error::ErrorKind::ImmediatelyDropped), _) => rpc::Error { + Error::Pool(PoolError::ImmediatelyDropped) => rpc::Error { code: rpc::ErrorCode::ServerError(POOL_IMMEDIATELY_DROPPED), message: "Immediately Dropped" .into(), data: Some("The transaction couldn't enter the pool because of the limit".into()), diff --git a/core/rpc/src/author/hash.rs b/core/rpc/src/author/hash.rs new file mode 100644 index 0000000000000000000000000000000000000000..a01e26de3c94b27c269c6dc6e65dbc780ac5cc05 --- /dev/null +++ b/core/rpc/src/author/hash.rs @@ -0,0 +1,32 @@ +// 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 . + +//! Extrinsic helpers for author RPC module. + +use primitives::Bytes; +use serde::{Serialize, Deserialize}; + +/// RPC Extrinsic or hash +/// +/// Allows to refer to extrinsic either by its raw representation or its hash. +#[derive(Debug, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub enum ExtrinsicOrHash { + /// The hash of the extrinsic. + Hash(Hash), + /// Raw extrinsic bytes. + Extrinsic(Bytes), +} diff --git a/core/rpc/src/author/mod.rs b/core/rpc/src/author/mod.rs index acd500ba0bfe309ddec5c36c698f0cb5a71473e0..5594984d0ea7f016461f49b507e8d65b783a1f50 100644 --- a/core/rpc/src/author/mod.rs +++ b/core/rpc/src/author/mod.rs @@ -16,11 +16,24 @@ //! Substrate block-author/full-node API. +pub mod error; +pub mod hash; + +#[cfg(test)] +mod tests; + use std::sync::Arc; -use log::warn; use client::{self, Client}; +use crate::rpc::futures::{Sink, Stream, Future}; +use crate::subscriptions::Subscriptions; +use jsonrpc_derive::rpc; +use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; +use log::warn; use parity_codec::{Encode, Decode}; +use primitives::{Bytes, Blake2Hasher, H256}; +use runtime_primitives::{generic, traits}; +use self::error::Result; use transaction_pool::{ txpool::{ ChainApi as PoolChainApi, @@ -31,19 +44,8 @@ use transaction_pool::{ watcher::Status, }, }; -use jsonrpc_derive::rpc; -use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; -use primitives::{Bytes, Blake2Hasher, H256}; -use crate::rpc::futures::{Sink, Stream, Future}; -use runtime_primitives::{generic, traits}; -use crate::subscriptions::Subscriptions; - -pub mod error; -#[cfg(test)] -mod tests; - -use self::error::Result; +pub use self::gen_client::Client as AuthorClient; /// Substrate authoring RPC API #[rpc] @@ -59,6 +61,10 @@ pub trait AuthorApi { #[rpc(name = "author_pendingExtrinsics")] fn pending_extrinsics(&self) -> Result>; + /// Remove given extrinsic from the pool and temporarily ban it to prevent reimporting. + #[rpc(name = "author_removeExtrinsic")] + fn remove_extrinsic(&self, bytes_or_hash: Vec>) -> Result>; + /// Submit an extrinsic to watch. #[pubsub(subscription = "author_extrinsicUpdate", subscribe, name = "author_submitAndWatchExtrinsic")] fn watch_extrinsic(&self, metadata: Self::Metadata, subscriber: Subscriber>, bytes: Bytes); @@ -72,7 +78,7 @@ pub trait AuthorApi { pub struct Author where P: PoolChainApi + Sync + Send + 'static { /// Substrate client client: Arc::Block, RA>>, - /// Extrinsic pool + /// Transactions pool pool: Arc>, /// Subscriptions manager subscriptions: Subscriptions, @@ -104,13 +110,13 @@ impl AuthorApi, BlockHash

> for Author whe type Metadata = crate::metadata::Metadata; fn submit_extrinsic(&self, ext: Bytes) -> Result> { - let xt = Decode::decode(&mut &ext[..]).ok_or(error::Error::from(error::ErrorKind::BadFormat))?; - let best_block_hash = self.client.info()?.chain.best_hash; + let xt = Decode::decode(&mut &ext[..]).ok_or(error::Error::BadFormat)?; + let best_block_hash = self.client.info().chain.best_hash; self.pool .submit_one(&generic::BlockId::hash(best_block_hash), xt) .map_err(|e| e.into_pool_error() .map(Into::into) - .unwrap_or_else(|e| error::ErrorKind::Verification(Box::new(e)).into()) + .unwrap_or_else(|e| error::Error::Verification(Box::new(e)).into()) ) } @@ -118,15 +124,35 @@ impl AuthorApi, BlockHash

> for Author whe Ok(self.pool.ready().map(|tx| tx.data.encode().into()).collect()) } + fn remove_extrinsic(&self, bytes_or_hash: Vec>>) -> Result>> { + let hashes = bytes_or_hash.into_iter() + .map(|x| match x { + hash::ExtrinsicOrHash::Hash(h) => Ok(h), + hash::ExtrinsicOrHash::Extrinsic(bytes) => { + let xt = Decode::decode(&mut &bytes[..]).ok_or(error::Error::BadFormat)?; + Ok(self.pool.hash_of(&xt)) + }, + }) + .collect::>>()?; + + Ok( + self.pool.remove_invalid(&hashes) + .into_iter() + .map(|tx| tx.hash.clone()) + .collect() + ) + } + fn watch_extrinsic(&self, _metadata: Self::Metadata, subscriber: Subscriber, BlockHash

>>, xt: Bytes) { let submit = || -> Result<_> { - let best_block_hash = self.client.info()?.chain.best_hash; - let dxt = <

::Block as traits::Block>::Extrinsic::decode(&mut &xt[..]).ok_or(error::Error::from(error::ErrorKind::BadFormat))?; + let best_block_hash = self.client.info().chain.best_hash; + let dxt = <

::Block as traits::Block>::Extrinsic::decode(&mut &xt[..]) + .ok_or(error::Error::BadFormat)?; self.pool .submit_and_watch(&generic::BlockId::hash(best_block_hash), dxt) .map_err(|e| e.into_pool_error() .map(Into::into) - .unwrap_or_else(|e| error::ErrorKind::Verification(Box::new(e)).into()) + .unwrap_or_else(|e| error::Error::Verification(Box::new(e)).into()) ) }; diff --git a/core/rpc/src/author/tests.rs b/core/rpc/src/author/tests.rs index 4d0277f7d656a2ec770dbdb8d84df8f23133181d..4c6a724acd5ae35bbf4ccbfbe71e7999a7d684e6 100644 --- a/core/rpc/src/author/tests.rs +++ b/core/rpc/src/author/tests.rs @@ -137,3 +137,31 @@ fn should_return_pending_extrinsics() { Ok(ref expected) if *expected == vec![Bytes(ex.encode())] ); } + +#[test] +fn should_remove_extrinsics() { + let runtime = runtime::Runtime::new().unwrap(); + let client = Arc::new(test_client::new()); + let pool = Arc::new(Pool::new(Default::default(), ChainApi::new(client.clone()))); + let p = Author { + client, + pool: pool.clone(), + subscriptions: Subscriptions::new(runtime.executor()), + }; + let ex1 = uxt(AccountKeyring::Alice, 0); + p.submit_extrinsic(ex1.encode().into()).unwrap(); + let ex2 = uxt(AccountKeyring::Alice, 1); + p.submit_extrinsic(ex2.encode().into()).unwrap(); + let ex3 = uxt(AccountKeyring::Bob, 0); + let hash3 = p.submit_extrinsic(ex3.encode().into()).unwrap(); + assert_eq!(pool.status().ready, 3); + + // now remove all 3 + let removed = p.remove_extrinsic(vec![ + hash::ExtrinsicOrHash::Hash(hash3), + // Removing this one will also remove ex2 + hash::ExtrinsicOrHash::Extrinsic(ex1.encode().into()), + ]).unwrap(); + + assert_eq!(removed.len(), 3); +} diff --git a/core/rpc/src/chain/error.rs b/core/rpc/src/chain/error.rs index 723a21d7732b7848277a964e37dfa21a0a831035..ad63af9add0510731df2083916551555b4df105a 100644 --- a/core/rpc/src/chain/error.rs +++ b/core/rpc/src/chain/error.rs @@ -14,33 +14,45 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use error_chain::*; + +//! Error helpers for Chain RPC module. + use client; use crate::rpc; use crate::errors; -pub use internal_errors::*; - -#[allow(deprecated)] -mod internal_errors { - use super::*; - error_chain! { - foreign_links { - Client(client::error::Error) #[doc = "Client error"]; - } - errors { - /// Not implemented yet - Unimplemented { - description("not yet implemented"), - display("Method Not Implemented"), - } + +/// Chain RPC Result type. +pub type Result = std::result::Result; + +/// Chain RPC errors. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Client error. + Client(client::error::Error), + /// Other error type. + Other(String), +} + +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Client(ref err) => Some(err), + _ => None, } } } +/// Base error code for all chain errors. +const BASE_ERROR: i64 = 3000; + impl From for rpc::Error { fn from(e: Error) -> Self { match e { - Error(ErrorKind::Unimplemented, _) => errors::unimplemented(), + Error::Other(message) => rpc::Error { + code: rpc::ErrorCode::ServerError(BASE_ERROR + 1), + message, + data: None, + }, e => errors::internal(e), } } diff --git a/core/rpc/src/chain/mod.rs b/core/rpc/src/chain/mod.rs index ab930d00763ff623ab96d7f312e2be990ba6c7e8..3594ed48e3aaf990919131c3779c096c400cb779 100644 --- a/core/rpc/src/chain/mod.rs +++ b/core/rpc/src/chain/mod.rs @@ -16,27 +16,28 @@ //! Substrate blockchain API. +pub mod error; +pub mod number; + +#[cfg(test)] +mod tests; + use std::sync::Arc; -use log::warn; use client::{self, Client, BlockchainEvents}; +use crate::rpc::Result as RpcResult; +use crate::rpc::futures::{stream, Future, Sink, Stream}; +use crate::subscriptions::Subscriptions; use jsonrpc_derive::rpc; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; +use log::warn; use primitives::{H256, Blake2Hasher}; -use crate::rpc::Result as RpcResult; -use crate::rpc::futures::{stream, Future, Sink, Stream}; use runtime_primitives::generic::{BlockId, SignedBlock}; use runtime_primitives::traits::{Block as BlockT, Header, NumberFor}; - -use crate::subscriptions::Subscriptions; - -mod error; -#[cfg(test)] -mod tests; -mod number; - use self::error::Result; +pub use self::gen_client::Client as ChainClient; + /// Substrate blockchain API #[rpc] pub trait ChainApi { @@ -124,7 +125,7 @@ impl Chain where { fn unwrap_or_best(&self, hash: Option) -> Result { Ok(match hash.into() { - None => self.client.info()?.chain.best_hash, + None => self.client.info().chain.best_hash, Some(hash) => hash, }) } @@ -145,7 +146,7 @@ impl Chain where let header = best_block_hash() .and_then(|hash| self.header(hash.into())) .and_then(|header| { - header.ok_or_else(|| self::error::ErrorKind::Unimplemented.into()) + header.ok_or_else(|| "Best header missing.".to_owned().into()) }) .map_err(Into::into); @@ -188,13 +189,13 @@ impl ChainApi, Block::Hash, Block::Header, Sig fn block_hash(&self, number: Option>>) -> Result> { Ok(match number { - None => Some(self.client.info()?.chain.best_hash), + None => Some(self.client.info().chain.best_hash), Some(num_or_hex) => self.client.header(&BlockId::number(num_or_hex.to_number()?))?.map(|h| h.hash()), }) } fn finalized_head(&self) -> Result { - Ok(self.client.info()?.chain.finalized_hash) + Ok(self.client.info().chain.finalized_hash) } fn subscribe_new_head(&self, _metadata: Self::Metadata, subscriber: Subscriber) { @@ -214,7 +215,7 @@ impl ChainApi, Block::Hash, Block::Header, Sig fn subscribe_finalized_heads(&self, _meta: Self::Metadata, subscriber: Subscriber) { self.subscribe_headers( subscriber, - || Ok(Some(self.client.info()?.chain.finalized_hash)), + || Ok(Some(self.client.info().chain.finalized_hash)), || self.client.finality_notification_stream() .map(|notification| notification.header), ) diff --git a/core/rpc/src/chain/number.rs b/core/rpc/src/chain/number.rs index 2e5af190ea94f36bd38b890242696e9c575861a4..df796d5e6d9911c2f952dc344cd69b23eef0a3b9 100644 --- a/core/rpc/src/chain/number.rs +++ b/core/rpc/src/chain/number.rs @@ -14,9 +14,11 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use serde::Deserialize; +//! Chain RPC Block number type. + +use serde::{Serialize, Deserialize}; +use std::{convert::TryFrom, fmt::Debug}; use primitives::U256; -use runtime_primitives::traits; /// RPC Block number type /// @@ -25,7 +27,7 @@ use runtime_primitives::traits; /// or we attempt to parse given hex value. /// We do that for consistency with the returned type, default generic header /// serializes block number as hex to avoid overflows in JavaScript. -#[derive(Deserialize)] +#[derive(Serialize, Deserialize)] #[serde(untagged)] pub enum NumberOrHex { /// The original header number type of block. @@ -34,30 +36,28 @@ pub enum NumberOrHex { Hex(U256), } -impl> NumberOrHex { +impl + From + Debug + PartialOrd> NumberOrHex { /// Attempts to convert into concrete block number. /// /// Fails in case hex number is too big. pub fn to_number(self) -> Result { - let num: u64 = match self { - NumberOrHex::Number(n) => n.as_(), + let num = match self { + NumberOrHex::Number(n) => n, NumberOrHex::Hex(h) => { - // FIXME #1377 this only supports `u64` since `BlockNumber` - // is `As` we could possibly go with `u128`. let l = h.low_u64(); if U256::from(l) != h { - return Err(format!("`{}` does not fit into the block number type.", h)); + return Err(format!("`{}` does not fit into u64 type; unsupported for now.", h)) } else { - l + Number::try_from(l) + .map_err(|_| format!("`{}` does not fit into block number type.", h))? } }, }; // FIXME <2329>: Database seems to limit the block number to u32 for no reason - if num > u32::max_value() as u64 { - Err(format!("`{}` > u32::max_value(), the max block number is u32.", num)) - } else { - Ok(traits::As::sa(num)) + if num > Number::from(u32::max_value()) { + return Err(format!("`{:?}` > u32::max_value(), the max block number is u32.", num)) } + Ok(num) } } diff --git a/core/rpc/src/chain/tests.rs b/core/rpc/src/chain/tests.rs index 26b7202305b16745ba0d516cb442765085e97ac5..eed9ae836b8b5cbdb88da859cb58a54b9ae16207 100644 --- a/core/rpc/src/chain/tests.rs +++ b/core/rpc/src/chain/tests.rs @@ -16,9 +16,11 @@ use super::*; use assert_matches::assert_matches; -use test_client::{self, TestClient}; -use test_client::runtime::{H256, Block, Header}; -use consensus::BlockOrigin; +use test_client::{ + prelude::*, + consensus::BlockOrigin, + runtime::{H256, Block, Header}, +}; #[test] fn should_return_header() { @@ -68,7 +70,7 @@ fn should_return_a_block() { subscriptions: Subscriptions::new(remote), }; - let block = api.client.new_block().unwrap().bake().unwrap(); + let block = api.client.new_block(Default::default()).unwrap().bake().unwrap(); let block_hash = block.hash(); api.client.import(BlockOrigin::Own, block).unwrap(); @@ -138,7 +140,7 @@ fn should_return_block_hash() { Ok(None) ); - let block = client.client.new_block().unwrap().bake().unwrap(); + let block = client.client.new_block(Default::default()).unwrap().bake().unwrap(); client.client.import(BlockOrigin::Own, block.clone()).unwrap(); assert_matches!( @@ -172,7 +174,7 @@ fn should_return_finalized_hash() { ); // import new block - let builder = client.client.new_block().unwrap(); + let builder = client.client.new_block(Default::default()).unwrap(); client.client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap(); // no finalization yet assert_matches!( @@ -205,7 +207,7 @@ fn should_notify_about_latest_block() { // assert id assigned assert_eq!(core.block_on(id), Ok(Ok(SubscriptionId::Number(1)))); - let builder = api.client.new_block().unwrap(); + let builder = api.client.new_block(Default::default()).unwrap(); api.client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap(); } @@ -236,7 +238,7 @@ fn should_notify_about_finalized_block() { // assert id assigned assert_eq!(core.block_on(id), Ok(Ok(SubscriptionId::Number(1)))); - let builder = api.client.new_block().unwrap(); + let builder = api.client.new_block(Default::default()).unwrap(); api.client.import(BlockOrigin::Own, builder.bake().unwrap()).unwrap(); api.client.finalize_block(BlockId::number(1), None, true).unwrap(); } diff --git a/core/rpc/src/errors.rs b/core/rpc/src/errors.rs index a709013ad26801a471f7dd99d94c6ed10390b78b..da910de76215ae18339f942a40394b5cdbae7404 100644 --- a/core/rpc/src/errors.rs +++ b/core/rpc/src/errors.rs @@ -17,14 +17,6 @@ use crate::rpc; use log::warn; -pub fn unimplemented() -> rpc::Error { - rpc::Error { - code: rpc::ErrorCode::ServerError(1), - message: "Not implemented yet".into(), - data: None, - } -} - pub fn internal(e: E) -> rpc::Error { warn!("Unknown error: {:?}", e); rpc::Error { diff --git a/core/rpc/src/state/error.rs b/core/rpc/src/state/error.rs index d4b3013abb2c079d2e3d1e7267f80c0a04ce1ee0..4b9d30b36b2043ef130492db91eb74004d12aba5 100644 --- a/core/rpc/src/state/error.rs +++ b/core/rpc/src/state/error.rs @@ -14,34 +14,52 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use error_chain::*; +//! State RPC errors. + use client; use crate::rpc; use crate::errors; -error_chain! { - foreign_links { - Client(client::error::Error) #[doc = "Client error"]; - } +/// State RPC Result type. +pub type Result = std::result::Result; - errors { - /// Provided block range couldn't be resolved to a list of blocks. - InvalidBlockRange(from: String, to: String, details: String) { - description("Invalid block range"), - display("Cannot resolve a block range ['{:?}' ... '{:?}]. {}", from, to, details), - } - /// Not implemented yet - Unimplemented { - description("not implemented yet"), - display("Method Not Implemented"), +/// State RPC errors. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Client error. + Client(client::error::Error), + /// Provided block range couldn't be resolved to a list of blocks. + #[display(fmt = "Cannot resolve a block range ['{:?}' ... '{:?}]. {}", from, to, details)] + InvalidBlockRange { + /// Beginning of the block range. + from: String, + /// End of the block range. + to: String, + /// Details of the error message. + details: String, + }, +} + +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Client(ref err) => Some(err), + _ => None, } } } +/// Base code for all state errors. +const BASE_ERROR: i64 = 4000; + impl From for rpc::Error { fn from(e: Error) -> Self { match e { - Error(ErrorKind::Unimplemented, _) => errors::unimplemented(), + Error::InvalidBlockRange { .. } => rpc::Error { + code: rpc::ErrorCode::ServerError(BASE_ERROR + 1), + message: format!("{}", e), + data: None, + }, e => errors::internal(e), } } diff --git a/core/rpc/src/state/mod.rs b/core/rpc/src/state/mod.rs index 168c0bd692732dbc564f04a511f11d0f288da3ec..e52d318d9f09887ce5f1c81e0a8374331bda83f0 100644 --- a/core/rpc/src/state/mod.rs +++ b/core/rpc/src/state/mod.rs @@ -16,34 +16,37 @@ //! Substrate state API. +pub mod error; + +#[cfg(test)] +mod tests; + use std::{ collections::{BTreeMap, HashMap}, ops::Range, sync::Arc, }; -use error_chain::bail; -use log::{warn, trace}; use client::{self, Client, CallExecutor, BlockchainEvents, runtime_api::Metadata}; +use crate::rpc::Result as RpcResult; +use crate::rpc::futures::{stream, Future, Sink, Stream}; +use crate::subscriptions::Subscriptions; use jsonrpc_derive::rpc; use jsonrpc_pubsub::{typed::Subscriber, SubscriptionId}; -use primitives::{H256, Blake2Hasher, Bytes}; +use log::{warn, trace}; use primitives::hexdisplay::HexDisplay; use primitives::storage::{self, StorageKey, StorageData, StorageChangeSet}; -use crate::rpc::Result as RpcResult; -use crate::rpc::futures::{stream, Future, Sink, Stream}; +use primitives::{H256, Blake2Hasher, Bytes}; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{Block as BlockT, Header, ProvideRuntimeApi, As, NumberFor}; +use runtime_primitives::traits::{ + Block as BlockT, Header, ProvideRuntimeApi, NumberFor, + SaturatedConversion +}; use runtime_version::RuntimeVersion; +use self::error::Result; use state_machine::{self, ExecutionStrategy}; -use crate::subscriptions::Subscriptions; - -mod error; -#[cfg(test)] -mod tests; - -use self::error::Result; +pub use self::gen_client::Client as StateClient; /// Substrate state API #[rpc] @@ -57,7 +60,7 @@ pub trait StateApi { /// Returns the keys with prefix, leave empty to get all the keys #[rpc(name = "state_getKeys")] - fn storage_keys(&self, key: StorageKey, hash: Option) -> Result>; + fn storage_keys(&self, prefix: StorageKey, hash: Option) -> Result>; /// Returns a storage entry at a specific block's state. #[rpc(name = "state_getStorage", alias("state_getStorageAt"))] @@ -71,6 +74,40 @@ pub trait StateApi { #[rpc(name = "state_getStorageSize", alias("state_getStorageSizeAt"))] fn storage_size(&self, key: StorageKey, hash: Option) -> Result>; + /// Returns the keys with prefix from a child storage, leave empty to get all the keys + #[rpc(name = "state_getChildKeys")] + fn child_storage_keys( + &self, + child_storage_key: StorageKey, + prefix: StorageKey, + hash: Option + ) -> Result>; + + /// Returns a child storage entry at a specific block's state. + #[rpc(name = "state_getChildStorage")] + fn child_storage( + &self, + child_storage_key: StorageKey, + key: StorageKey, hash: Option + ) -> Result>; + + /// Returns the hash of a child storage entry at a block's state. + #[rpc(name = "state_getChildStorageHash")] + fn child_storage_hash( + &self, + child_storage_key: StorageKey, + key: StorageKey, hash: Option + ) -> Result>; + + /// Returns the size of a child storage entry at a block's state. + #[rpc(name = "state_getChildStorageSize")] + fn child_storage_size( + &self, + child_storage_key: StorageKey, + key: StorageKey, + hash: Option + ) -> Result>; + /// Returns the runtime metadata as an opaque blob. #[rpc(name = "state_getMetadata")] fn metadata(&self, hash: Option) -> Result; @@ -84,7 +121,12 @@ pub trait StateApi { /// NOTE This first returned result contains the initial state of storage for all keys. /// Subsequent values in the vector represent changes to the previous state (diffs). #[rpc(name = "state_queryStorage")] - fn query_storage(&self, keys: Vec, block: Hash, hash: Option) -> Result>>; + fn query_storage( + &self, + keys: Vec, + block: Hash, + hash: Option + ) -> Result>>; /// New runtime version subscription #[pubsub( @@ -106,11 +148,15 @@ pub trait StateApi { /// New storage subscription #[pubsub(subscription = "state_storage", subscribe, name = "state_subscribeStorage")] - fn subscribe_storage(&self, metadata: Self::Metadata, subscriber: Subscriber>, keys: Option>); + fn subscribe_storage( + &self, metadata: Self::Metadata, subscriber: Subscriber>, keys: Option> + ); /// Unsubscribe from storage subscription #[pubsub(subscription = "state_storage", unsubscribe, name = "state_unsubscribeStorage")] - fn unsubscribe_storage(&self, metadata: Option, id: SubscriptionId) -> RpcResult; + fn unsubscribe_storage( + &self, metadata: Option, id: SubscriptionId + ) -> RpcResult; } /// State API with subscriptions support. @@ -171,7 +217,7 @@ impl State where blocks.push(hdr.hash()); last = hdr; } else { - bail!(invalid_block_range( + return Err(invalid_block_range( Some(from), Some(to), format!("Parent of {} ({}) not found", last.number(), last.hash()), @@ -179,7 +225,7 @@ impl State where } } if last.hash() != from.hash() { - bail!(invalid_block_range( + return Err(invalid_block_range( Some(from), Some(to), format!("Expected to reach `from`, got {} ({})", last.number(), last.hash()), @@ -190,7 +236,7 @@ impl State where }; // check if we can filter blocks-with-changes from some (sub)range using changes tries let changes_trie_range = self.client.max_key_changes_range(from_number, BlockId::Hash(to.hash()))?; - let filtered_range_begin = changes_trie_range.map(|(begin, _)| (begin - from_number).as_() as usize); + let filtered_range_begin = changes_trie_range.map(|(begin, _)| (begin - from_number).saturated_into::()); let (unfiltered_range, filtered_range) = split_range(blocks.len(), filtered_range_begin); Ok(QueryStorageRange { hashes: blocks, @@ -199,7 +245,7 @@ impl State where filtered_range, }) }, - (from, to) => bail!( + (from, to) => Err( invalid_block_range(from.as_ref(), to.as_ref(), "Invalid range or unknown block".into()) ), } @@ -242,7 +288,7 @@ impl State where ) -> Result<()> { let (begin, end) = match range.filtered_range { Some(ref filtered_range) => ( - range.first_number + As::sa(filtered_range.start as u64), + range.first_number + filtered_range.start.saturated_into(), BlockId::Hash(range.hashes[filtered_range.end - 1].clone()) ), None => return Ok(()), @@ -254,7 +300,7 @@ impl State where if last_block == Some(block) { continue; } - let block_hash = range.hashes[(block - range.first_number).as_() as usize].clone(); + let block_hash = range.hashes[(block - range.first_number).saturated_into::()].clone(); let id = BlockId::Hash(block_hash); let value_at_block = self.client.storage(&id, key)?; changes_map.entry(block) @@ -277,7 +323,7 @@ impl State where E: CallExecutor, { fn unwrap_or_best(&self, hash: Option) -> Result { - crate::helpers::unwrap_or_else(|| Ok(self.client.info()?.chain.best_hash), hash) + crate::helpers::unwrap_or_else(|| Ok(self.client.info().chain.best_hash), hash) } } @@ -324,6 +370,50 @@ impl StateApi for State where Ok(self.storage(key, block)?.map(|x| x.0.len() as u64)) } + fn child_storage( + &self, + child_storage_key: StorageKey, + key: StorageKey, + block: Option + ) -> Result> { + let block = self.unwrap_or_best(block)?; + trace!(target: "rpc", "Querying child storage at {:?} for key {}", block, HexDisplay::from(&key.0)); + Ok(self.client.child_storage(&BlockId::Hash(block), &child_storage_key, &key)?) + } + + fn child_storage_keys( + &self, + child_storage_key: StorageKey, + key_prefix: StorageKey, + block: Option + ) -> Result> { + let block = self.unwrap_or_best(block)?; + trace!(target: "rpc", "Querying child storage keys at {:?}", block); + Ok(self.client.child_storage_keys(&BlockId::Hash(block), &child_storage_key, &key_prefix)?) + } + + fn child_storage_hash( + &self, + child_storage_key: StorageKey, + key: StorageKey, + block: Option + ) -> Result> { + use runtime_primitives::traits::{Hash, Header as HeaderT}; + Ok( + self.child_storage(child_storage_key, key, block)? + .map(|x| ::Hashing::hash(&x.0)) + ) + } + + fn child_storage_size( + &self, + child_storage_key: StorageKey, + key: StorageKey, + block: Option + ) -> Result> { + Ok(self.child_storage(child_storage_key, key, block)?.map(|x| x.0.len() as u64)) + } + fn metadata(&self, block: Option) -> Result { let block = self.unwrap_or_best(block)?; self.client.runtime_api().metadata(&BlockId::Hash(block)).map(Into::into).map_err(Into::into) @@ -360,7 +450,7 @@ impl StateApi for State where // initial values let initial = stream::iter_result(keys .map(|keys| { - let block = self.client.info().map(|info| info.chain.best_hash).unwrap_or_default(); + let block = self.client.info().chain.best_hash; let changes = keys .into_iter() .map(|key| self.storage(key.clone(), Some(block.clone()).into()) @@ -397,7 +487,9 @@ impl StateApi for State where } fn subscribe_runtime_version(&self, _meta: Self::Metadata, subscriber: Subscriber) { - let stream = match self.client.storage_changes_notification_stream(Some(&[StorageKey(storage::well_known_keys::CODE.to_vec())])) { + let stream = match self.client.storage_changes_notification_stream( + Some(&[StorageKey(storage::well_known_keys::CODE.to_vec())]) + ) { Ok(stream) => stream, Err(err) => { let _ = subscriber.reject(error::Error::from(err).into()); @@ -415,9 +507,9 @@ impl StateApi for State where let stream = stream .map_err(|e| warn!("Error creating storage notification stream: {:?}", e)) .filter_map(move |_| { - let version = client.info().and_then(|info| { - client.runtime_version_at(&BlockId::hash(info.chain.best_hash)) - }) + let info = client.info(); + let version = client + .runtime_version_at(&BlockId::hash(info.chain.best_hash)) .map_err(error::Error::from) .map_err(Into::into); if previous_version != version { @@ -465,11 +557,15 @@ pub(crate) fn split_range(size: usize, middle: Option) -> (Range, (range1, range2) } -fn invalid_block_range(from: Option<&H>, to: Option<&H>, reason: String) -> error::ErrorKind { +fn invalid_block_range(from: Option<&H>, to: Option<&H>, reason: String) -> error::Error { let to_string = |x: Option<&H>| match x { None => "unknown hash".into(), Some(h) => format!("{} ({})", h.number(), h.hash()), }; - error::ErrorKind::InvalidBlockRange(to_string(from), to_string(to), reason) + error::Error::InvalidBlockRange { + from: to_string(from), + to: to_string(to), + details: reason, + } } diff --git a/core/rpc/src/state/tests.rs b/core/rpc/src/state/tests.rs index 5321116c95267b65b93424ae06ded3b782f7edc9..498b58b40ba4bd92dbd12a5873e370dbf8905601 100644 --- a/core/rpc/src/state/tests.rs +++ b/core/rpc/src/state/tests.rs @@ -15,42 +15,84 @@ // along with Substrate. If not, see . use super::*; -use self::error::{Error, ErrorKind}; +use self::error::Error; -use sr_io::blake2_256; use assert_matches::assert_matches; -use consensus::BlockOrigin; -use test_client::{self, runtime, AccountKeyring, TestClient, BlockBuilderExt}; +use primitives::storage::well_known_keys; +use sr_io::blake2_256; +use test_client::{ + prelude::*, + consensus::BlockOrigin, + runtime, +}; +use substrate_executor::NativeExecutionDispatch; #[test] fn should_return_storage() { - let core = ::tokio::runtime::Runtime::new().unwrap(); + let core = tokio::runtime::Runtime::new().unwrap(); let client = Arc::new(test_client::new()); let genesis_hash = client.genesis_hash(); let client = State::new(client, Subscriptions::new(core.executor())); + let key = StorageKey(b":code".to_vec()); + assert_eq!( + client.storage(key.clone(), Some(genesis_hash).into()) + .map(|x| x.map(|x| x.0.len())).unwrap().unwrap() as usize, + LocalExecutor::native_equivalent().len(), + ); assert_matches!( - client.storage(StorageKey(vec![10]), Some(genesis_hash).into()), - Ok(None) - ) + client.storage_hash(key.clone(), Some(genesis_hash).into()).map(|x| x.is_some()), + Ok(true) + ); + assert_eq!( + client.storage_size(key.clone(), None).unwrap().unwrap() as usize, + LocalExecutor::native_equivalent().len(), + ); +} + +#[test] +fn should_return_child_storage() { + let core = tokio::runtime::Runtime::new().unwrap(); + let client = Arc::new(test_client::TestClientBuilder::new() + .add_child_storage("test", "key", vec![42_u8]) + .build()); + let genesis_hash = client.genesis_hash(); + let client = State::new(client, Subscriptions::new(core.executor())); + let child_key = StorageKey(well_known_keys::CHILD_STORAGE_KEY_PREFIX.iter().chain(b"test").cloned().collect()); + let key = StorageKey(b"key".to_vec()); + + + assert_matches!( + client.child_storage(child_key.clone(), key.clone(), Some(genesis_hash).into()), + Ok(Some(StorageData(ref d))) if d[0] == 42 && d.len() == 1 + ); + assert_matches!( + client.child_storage_hash(child_key.clone(), key.clone(), Some(genesis_hash).into()) + .map(|x| x.is_some()), + Ok(true) + ); + assert_matches!( + client.child_storage_size(child_key.clone(), key.clone(), None), + Ok(Some(1)) + ); } #[test] fn should_call_contract() { - let core = ::tokio::runtime::Runtime::new().unwrap(); + let core = tokio::runtime::Runtime::new().unwrap(); let client = Arc::new(test_client::new()); let genesis_hash = client.genesis_hash(); let client = State::new(client, Subscriptions::new(core.executor())); assert_matches!( client.call("balanceOf".into(), Bytes(vec![1,2,3]), Some(genesis_hash).into()), - Err(Error(ErrorKind::Client(client::error::Error::Execution(_)), _)) + Err(Error::Client(client::error::Error::Execution(_))) ) } #[test] fn should_notify_about_storage_changes() { - let mut core = ::tokio::runtime::Runtime::new().unwrap(); + let mut core = tokio::runtime::Runtime::new().unwrap(); let remote = core.executor(); let (subscriber, id, transport) = Subscriber::new_test("test"); @@ -62,7 +104,7 @@ fn should_notify_about_storage_changes() { // assert id assigned assert_eq!(core.block_on(id), Ok(Ok(SubscriptionId::Number(1)))); - let mut builder = api.client.new_block().unwrap(); + let mut builder = api.client.new_block(Default::default()).unwrap(); builder.push_transfer(runtime::Transfer { from: AccountKeyring::Alice.into(), to: AccountKeyring::Ferdie.into(), @@ -81,14 +123,14 @@ fn should_notify_about_storage_changes() { #[test] fn should_send_initial_storage_changes_and_notifications() { - let mut core = ::tokio::runtime::Runtime::new().unwrap(); + let mut core = tokio::runtime::Runtime::new().unwrap(); let remote = core.executor(); let (subscriber, id, transport) = Subscriber::new_test("test"); { let api = State::new(Arc::new(test_client::new()), Subscriptions::new(remote)); - let alice_balance_key = blake2_256(&test_runtime::system::balance_of_key(AccountKeyring::Alice.into())); + let alice_balance_key = blake2_256(&runtime::system::balance_of_key(AccountKeyring::Alice.into())); api.subscribe_storage(Default::default(), subscriber, Some(vec![ StorageKey(alice_balance_key.to_vec()), @@ -97,7 +139,7 @@ fn should_send_initial_storage_changes_and_notifications() { // assert id assigned assert_eq!(core.block_on(id), Ok(Ok(SubscriptionId::Number(1)))); - let mut builder = api.client.new_block().unwrap(); + let mut builder = api.client.new_block(Default::default()).unwrap(); builder.push_transfer(runtime::Transfer { from: AccountKeyring::Alice.into(), to: AccountKeyring::Ferdie.into(), @@ -119,19 +161,12 @@ fn should_send_initial_storage_changes_and_notifications() { #[test] fn should_query_storage() { - type TestClient = test_client::client::Client< - test_client::Backend, - test_client::Executor, - runtime::Block, - runtime::RuntimeApi - >; - fn run_tests(client: Arc) { - let core = ::tokio::runtime::Runtime::new().unwrap(); + let core = tokio::runtime::Runtime::new().unwrap(); let api = State::new(client.clone(), Subscriptions::new(core.executor())); let add_block = |nonce| { - let mut builder = client.new_block().unwrap(); + let mut builder = client.new_block(Default::default()).unwrap(); builder.push_transfer(runtime::Transfer { from: AccountKeyring::Alice.into(), to: AccountKeyring::Ferdie.into(), @@ -147,7 +182,7 @@ fn should_query_storage() { let block2_hash = add_block(1); let genesis_hash = client.genesis_hash(); - let alice_balance_key = blake2_256(&test_runtime::system::balance_of_key(AccountKeyring::Alice.into())); + let alice_balance_key = blake2_256(&runtime::system::balance_of_key(AccountKeyring::Alice.into())); let mut expected = vec![ StorageChangeSet { @@ -199,7 +234,7 @@ fn should_query_storage() { } run_tests(Arc::new(test_client::new())); - run_tests(Arc::new(test_client::new_with_changes_trie())); + run_tests(Arc::new(TestClientBuilder::new().set_support_changes_trie(true).build())); } #[test] @@ -214,20 +249,20 @@ fn should_split_ranges() { #[test] fn should_return_runtime_version() { - let core = ::tokio::runtime::Runtime::new().unwrap(); + let core = tokio::runtime::Runtime::new().unwrap(); let client = Arc::new(test_client::new()); let api = State::new(client.clone(), Subscriptions::new(core.executor())); assert_eq!( - ::serde_json::to_string(&api.runtime_version(None.into()).unwrap()).unwrap(), + serde_json::to_string(&api.runtime_version(None.into()).unwrap()).unwrap(), r#"{"specName":"test","implName":"parity-test","authoringVersion":1,"specVersion":1,"implVersion":1,"apis":[["0xdf6acb689907609b",2],["0x37e397fc7c91f5e4",1],["0xd2bc9897eed08f15",1],["0x40fe3ad401f8959a",3],["0xc6e9a76309f39b09",1],["0xdd718d5cc53262d4",1],["0xcbca25e39f142387",1],["0xf78b278be53f454c",1],["0x7801759919ee83e5",1]]}"# ); } #[test] fn should_notify_on_runtime_version_initially() { - let mut core = ::tokio::runtime::Runtime::new().unwrap(); + let mut core = tokio::runtime::Runtime::new().unwrap(); let (subscriber, id, transport) = Subscriber::new_test("test"); { diff --git a/core/rpc/src/system/error.rs b/core/rpc/src/system/error.rs index d3c7e8b33387048385abcad3e620a615646f0dc5..bdd4cbe667e59a084d3b83f41b62e88f1518d5cd 100644 --- a/core/rpc/src/system/error.rs +++ b/core/rpc/src/system/error.rs @@ -16,40 +16,33 @@ //! System RPC module errors. -use error_chain::*; - use crate::rpc; -use crate::errors; use crate::system::helpers::Health; -error_chain! { - errors { - /// Node is not fully functional - NotHealthy(h: Health) { - description("node is not healthy"), - display("Node is not fully functional: {}", h) - } +/// System RPC Result type. +pub type Result = std::result::Result; - /// Not implemented yet - Unimplemented { - description("not yet implemented"), - display("Method Not Implemented"), - } - } +/// System RPC errors. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Provided block range couldn't be resolved to a list of blocks. + #[display(fmt = "Node is not fully functional: {}", _0)] + NotHealthy(Health), } -const ERROR: i64 = 2000; +impl std::error::Error for Error {} + +/// Base code for all system errors. +const BASE_ERROR: i64 = 2000; impl From for rpc::Error { fn from(e: Error) -> Self { match e { - Error(ErrorKind::Unimplemented, _) => errors::unimplemented(), - Error(ErrorKind::NotHealthy(h), _) => rpc::Error { - code: rpc::ErrorCode::ServerError(ERROR + 1), - message: "node is not healthy".into(), - data:serde_json::to_value(h).ok(), + Error::NotHealthy(ref h) => rpc::Error { + code: rpc::ErrorCode::ServerError(BASE_ERROR + 1), + message: format!("{}", e), + data: serde_json::to_value(h).ok(), }, - e => errors::internal(e), } } } diff --git a/core/rpc/src/system/helpers.rs b/core/rpc/src/system/helpers.rs index 82c7773b5b919ed152559a857f4288b8cbe6672d..00e2ba9f408b7658ccb45a10d62642bbfed1209c 100644 --- a/core/rpc/src/system/helpers.rs +++ b/core/rpc/src/system/helpers.rs @@ -17,7 +17,7 @@ //! Substrate system API helpers. use std::fmt; -use serde::Serialize; +use serde::{Serialize, Deserialize}; use serde_json::{Value, map::Map}; /// Node properties @@ -37,7 +37,7 @@ pub struct SystemInfo { } /// Health struct returned by the RPC -#[derive(Debug, PartialEq, Serialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct Health { /// Number of connected peers @@ -51,7 +51,7 @@ pub struct Health { } /// Network Peer information -#[derive(Debug, PartialEq, Serialize)] +#[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")] pub struct PeerInfo { /// Peer ID diff --git a/core/rpc/src/system/mod.rs b/core/rpc/src/system/mod.rs index 331d9cd85ba61739c3833c5ec2497f2cf2331988..d6f2b755159f702d01c5c5baedfee61723d89d4a 100644 --- a/core/rpc/src/system/mod.rs +++ b/core/rpc/src/system/mod.rs @@ -17,8 +17,8 @@ //! Substrate system API. pub mod error; +pub mod helpers; -mod helpers; #[cfg(test)] mod tests; @@ -30,6 +30,8 @@ use runtime_primitives::traits::{self, Header as HeaderT}; use self::error::Result; pub use self::helpers::{Properties, SystemInfo, Health, PeerInfo}; +pub use self::gen_client::Client as SystemClient; + /// Substrate system RPC API #[rpc] pub trait SystemApi { @@ -72,7 +74,7 @@ pub trait SystemApi { /// System API implementation pub struct System { info: SystemInfo, - sync: Arc>, + sync: Arc>, should_have_peers: bool, } @@ -80,7 +82,7 @@ impl System { /// Creates new `System` given the `SystemInfo`. pub fn new( info: SystemInfo, - sync: Arc>, + sync: Arc>, should_have_peers: bool, ) -> Self { System { @@ -110,14 +112,14 @@ impl SystemApi::Number> for Sy fn system_health(&self) -> Result { Ok(Health { - peers: self.sync.peers().len(), + peers: self.sync.peers_debug_info().len(), is_syncing: self.sync.is_major_syncing(), should_have_peers: self.should_have_peers, }) } fn system_peers(&self) -> Result::Number>>> { - Ok(self.sync.peers().into_iter().map(|(peer_id, p)| PeerInfo { + Ok(self.sync.peers_debug_info().into_iter().map(|(peer_id, p)| PeerInfo { peer_id: peer_id.to_base58(), roles: format!("{:?}", p.roles), protocol_version: p.protocol_version, diff --git a/core/rpc/src/system/tests.rs b/core/rpc/src/system/tests.rs index b4b71a7937af16e988e6e156a1bdecde1b05ecca..14cd421fd19e2770ab00d781a31344dc7f802e21 100644 --- a/core/rpc/src/system/tests.rs +++ b/core/rpc/src/system/tests.rs @@ -59,7 +59,7 @@ impl network::SyncProvider for Status { } } - fn peers(&self) -> Vec<(PeerId, NetworkPeerInfo)> { + fn peers_debug_info(&self) -> Vec<(PeerId, NetworkPeerInfo)> { let mut peers = vec![]; for _peer in 0..self.peers { peers.push( diff --git a/core/service/Cargo.toml b/core/service/Cargo.toml index 89708683d0d0e812506c090c840c35df06cecafe..471594aad88c5e72a76eeba498933804ccad3f6e 100644 --- a/core/service/Cargo.toml +++ b/core/service/Cargo.toml @@ -5,9 +5,9 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] +derive_more = "0.14.0" futures = "0.1.17" -parking_lot = "0.7.1" -error-chain = "0.12" +parking_lot = "0.8.0" lazy_static = "1.0" log = "0.4" slog = {version = "^2", features = ["nested-values"]} @@ -16,7 +16,6 @@ exit-future = "0.1" serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" target_info = "0.1" -inherents = { package = "substrate-inherents", path = "../../core/inherents" } keystore = { package = "substrate-keystore", path = "../../core/keystore" } sr-io = { path = "../../core/sr-io" } runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitives" } @@ -24,7 +23,7 @@ primitives = { package = "substrate-primitives", path = "../../core/primitives" consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } network = { package = "substrate-network", path = "../../core/network" } client = { package = "substrate-client", path = "../../core/client" } -client_db = { package = "substrate-client-db", path = "../../core/client/db" } +client_db = { package = "substrate-client-db", path = "../../core/client/db", features = ["kvdb-rocksdb"] } parity-codec = "3.3" substrate-executor = { path = "../../core/executor" } transaction_pool = { package = "substrate-transaction-pool", path = "../../core/transaction-pool" } @@ -33,7 +32,7 @@ tel = { package = "substrate-telemetry", path = "../../core/telemetry" } offchain = { package = "substrate-offchain", path = "../../core/offchain" } [dev-dependencies] -substrate-test-client = { path = "../test-client" } +substrate-test-runtime-client = { path = "../test-runtime/client" } node-executor = { path = "../../node/executor" } node-primitives = { path = "../../node/primitives" } node-runtime = { path = "../../node/runtime" } diff --git a/core/service/src/chain_ops.rs b/core/service/src/chain_ops.rs index 9f39e8088e7f8074b57383b0be9e4477480d6eb4..83f103ec8fe0248a41c8710fe53b9ad1d909987d 100644 --- a/core/service/src/chain_ops.rs +++ b/core/service/src/chain_ops.rs @@ -21,7 +21,7 @@ use futures::Future; use log::{info, warn}; use runtime_primitives::generic::{SignedBlock, BlockId}; -use runtime_primitives::traits::{As, Block, Header, NumberFor}; +use runtime_primitives::traits::{SaturatedConversion, Zero, One, Block, Header, NumberFor}; use consensus_common::import_queue::{ImportQueue, IncomingBlock, Link}; use network::message; @@ -50,9 +50,9 @@ pub fn export_blocks( let mut block = from; let last = match to { - Some(v) if v == As::sa(0) => As::sa(1), + Some(v) if v.is_zero() => One::one(), Some(v) => v, - None => client.info()?.chain.best_number, + None => client.info().chain.best_number, }; if last < block { @@ -66,8 +66,8 @@ pub fn export_blocks( }); info!("Exporting blocks from #{} to #{}", block, last); if !json { - let last_: u64 = last.as_(); - let block_: u64 = block.as_(); + let last_: u64 = last.saturated_into::(); + let block_: u64 = block.saturated_into::(); let len: u64 = last_ - block_ + 1; output.write(&len.encode())?; } @@ -87,13 +87,13 @@ pub fn export_blocks( }, None => break, } - if block.as_() % 10000 == 0 { + if (block % 10000.into()).is_zero() { info!("#{}", block); } if block == last { break; } - block += As::sa(1); + block += One::one(); } Ok(()) } @@ -151,7 +151,7 @@ pub fn import_blocks( let (header, extrinsics) = signed.block.deconstruct(); let hash = header.hash(); let block = message::BlockData:: { - hash: hash, + hash, justification: signed.justification, header: Some(header), body: Some(extrinsics), @@ -186,7 +186,7 @@ pub fn import_blocks( blocks_imported += 1; } - info!("Imported {} blocks. Best: #{}", block_count, client.info()?.chain.best_number); + info!("Imported {} blocks. Best: #{}", block_count, client.info().chain.best_number); Ok(()) } @@ -200,9 +200,9 @@ pub fn revert_chain( { let client = new_client::(&config)?; let reverted = client.revert(blocks)?; - let info = client.info()?.chain; + let info = client.info().chain; - if reverted.as_() == 0 { + if reverted.is_zero() { info!("There aren't any non-finalized blocks to revert."); } else { info!("Reverted {} blocks. Best: #{} ({})", reverted, info.best_number, info.best_hash); diff --git a/core/service/src/components.rs b/core/service/src/components.rs index 48ea9777bdbf81c50e7aa25ad0ee5e2858910b91..0f5afb77729c27622e9b548c0309362efcfd7c44 100644 --- a/core/service/src/components.rs +++ b/core/service/src/components.rs @@ -38,7 +38,8 @@ use parking_lot::Mutex; // Type aliases. // These exist mainly to avoid typing `::Foo` all over the code. /// Network service type for a factory. -pub type NetworkService = network::Service<::Block, ::NetworkProtocol>; +pub type NetworkService = + network::NetworkService<::Block, ::NetworkProtocol>; /// Code executor type for a factory. pub type CodeExecutor = NativeExecutor<::RuntimeDispatch>; @@ -138,11 +139,12 @@ pub trait StartRPC { fn start_rpc( client: Arc>, - network: Arc>>, + network: Arc>>, should_have_peers: bool, system_info: SystemInfo, rpc_http: Option, rpc_ws: Option, + rpc_ws_max_connections: Option, rpc_cors: Option>, task_executor: TaskExecutor, transaction_pool: Arc>, @@ -157,11 +159,12 @@ impl StartRPC for C where fn start_rpc( client: Arc>, - network: Arc>>, + network: Arc>>, should_have_peers: bool, rpc_system_info: SystemInfo, rpc_http: Option, rpc_ws: Option, + rpc_ws_max_connections: Option, rpc_cors: Option>, task_executor: TaskExecutor, transaction_pool: Arc>, @@ -186,8 +189,19 @@ impl StartRPC for C where }; Ok(( - maybe_start_server(rpc_http, |address| rpc::start_http(address, rpc_cors.as_ref(), handler()))?, - maybe_start_server(rpc_ws, |address| rpc::start_ws(address, rpc_cors.as_ref(), handler()))?.map(Mutex::new), + maybe_start_server( + rpc_http, + |address| rpc::start_http(address, rpc_cors.as_ref(), handler()), + )?, + maybe_start_server( + rpc_ws, + |address| rpc::start_ws( + address, + rpc_ws_max_connections, + rpc_cors.as_ref(), + handler(), + ), + )?.map(Mutex::new), )) } } @@ -325,12 +339,12 @@ pub trait ServiceFactory: 'static + Sized { /// Build finality proof provider for serving network requests on full node. fn build_finality_proof_provider( client: Arc> - ) -> Result>>, error::Error>; + ) -> Result>>, error::Error>; /// Build the Fork Choice algorithm for full client fn build_select_chain( config: &mut FactoryFullConfiguration, - client: Arc>, + client: Arc>, ) -> Result; /// Build full service. @@ -421,7 +435,7 @@ pub trait Components: Sized + 'static { /// Finality proof provider for serving network requests. fn build_finality_proof_provider( client: Arc> - ) -> Result::Block>>>, error::Error>; + ) -> Result::Block>>>, error::Error>; /// Build fork choice selector fn build_select_chain( @@ -497,7 +511,7 @@ impl Components for FullComponents { } fn build_transaction_pool( - config: TransactionPoolOptions, + config: TransactionPoolOptions, client: Arc> ) -> Result, error::Error> { Factory::build_full_transaction_pool(config, client) @@ -509,7 +523,7 @@ impl Components for FullComponents { select_chain: Option, ) -> Result { let select_chain = select_chain - .ok_or_else(|| error::Error::from(error::ErrorKind::SelectChainRequired))?; + .ok_or(error::Error::SelectChainRequired)?; Factory::build_full_import_queue(config, client, select_chain) } @@ -522,7 +536,7 @@ impl Components for FullComponents { fn build_finality_proof_provider( client: Arc> - ) -> Result::Block>>>, error::Error> { + ) -> Result::Block>>>, error::Error> { Factory::build_finality_proof_provider(client) } } @@ -605,7 +619,7 @@ impl Components for LightComponents { fn build_finality_proof_provider( _client: Arc> - ) -> Result::Block>>>, error::Error> { + ) -> Result::Block>>>, error::Error> { Ok(None) } fn build_select_chain( @@ -620,12 +634,12 @@ impl Components for LightComponents { mod tests { use super::*; use consensus_common::BlockOrigin; - use client::LongestChain; - use substrate_test_client::{self, TestClient, AccountKeyring, runtime::Transfer}; + use substrate_test_runtime_client::{prelude::*, runtime::Transfer}; #[test] fn should_remove_transactions_from_the_pool() { - let client = Arc::new(substrate_test_client::new()); + let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain(); + let client = Arc::new(client); let pool = TransactionPool::new(Default::default(), ::transaction_pool::ChainApi::new(client.clone())); let transaction = Transfer { amount: 5, @@ -633,14 +647,13 @@ mod tests { from: AccountKeyring::Alice.into(), to: Default::default(), }.into_signed_tx(); - let best = LongestChain::new(client.backend().clone(), client.import_lock()) - .best_chain().unwrap(); + let best = longest_chain.best_chain().unwrap(); // store the transaction in the pool pool.submit_one(&BlockId::hash(best.hash()), transaction.clone()).unwrap(); // import the block - let mut builder = client.new_block().unwrap(); + let mut builder = client.new_block(Default::default()).unwrap(); builder.push(transaction.clone()).unwrap(); let block = builder.bake().unwrap(); let id = BlockId::hash(block.header().hash()); diff --git a/core/service/src/config.rs b/core/service/src/config.rs index c9e8e4662dbb2771616e780e7195a2f3e00d2fa5..5996ec837d38ea707bb3bcec9a92b6b515ca14b6 100644 --- a/core/service/src/config.rs +++ b/core/service/src/config.rs @@ -66,6 +66,8 @@ pub struct Configuration { pub rpc_http: Option, /// RPC over Websockets binding address. `None` if disabled. pub rpc_ws: Option, + /// Maximum number of connections for WebSockets RPC server. `None` if default. + pub rpc_ws_max_connections: Option, /// CORS settings for HTTP & WS servers. `None` if all origins are allowed. pub rpc_cors: Option>, /// Telemetry service URL. `None` if disabled. @@ -104,6 +106,7 @@ impl Configuration = std::result::Result; - links { - Consensus(consensus_common::Error, consensus_common::ErrorKind) #[doc="Consensus error"]; - Network(network::error::Error, network::error::ErrorKind) #[doc="Network error"]; - Keystore(keystore::Error, keystore::ErrorKind) #[doc="Keystore error"]; +/// Service errors. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Client error. + Client(client::error::Error), + /// IO error. + Io(std::io::Error), + /// Consensus error. + Consensus(consensus_common::Error), + /// Network error. + Network(network::error::Error), + /// Keystore error. + Keystore(keystore::Error), + /// Best chain selection strategy is missing. + #[display(fmt="Best chain selection strategy (SelectChain) is not provided.")] + SelectChainRequired, + /// Other error. + Other(String), +} + +impl<'a> From<&'a str> for Error { + fn from(s: &'a str) -> Self { + Error::Other(s.into()) } +} - errors { - SelectChainRequired { - description("Best chain selection strategy (SelectChain) must be provided when starting full node or authority."), - display("Best chain selection strategy (SelectChain) is not provided."), +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Client(ref err) => Some(err), + Error::Io(ref err) => Some(err), + Error::Consensus(ref err) => Some(err), + Error::Network(ref err) => Some(err), + Error::Keystore(ref err) => Some(err), + _ => None, } } } diff --git a/core/service/src/lib.rs b/core/service/src/lib.rs index 2ed9348e52c364ee1b7fcd3da2c62367d54ae830..92ddcd0b58a61532165a36dd038f5cbcdd40e7cd 100644 --- a/core/service/src/lib.rs +++ b/core/service/src/lib.rs @@ -34,17 +34,16 @@ use parking_lot::Mutex; use client::BlockchainEvents; use exit_future::Signal; use futures::prelude::*; -use inherents::pool::InherentsPool; use keystore::Store as Keystore; use log::{info, warn, debug}; use parity_codec::{Encode, Decode}; use primitives::Pair; use runtime_primitives::generic::BlockId; -use runtime_primitives::traits::{Header, As}; +use runtime_primitives::traits::{Header, SaturatedConversion}; use substrate_executor::NativeExecutor; use tel::{telemetry, SUBSTRATE_INFO}; -pub use self::error::{ErrorKind, Error}; +pub use self::error::Error; pub use config::{Configuration, Roles, PruningMode}; pub use chain_spec::{ChainSpec, Properties}; pub use transaction_pool::txpool::{ @@ -76,14 +75,13 @@ pub struct Service { select_chain: Option<::SelectChain>, network: Option>>, transaction_pool: Arc>, - inherents_pool: Arc>>, keystore: Keystore, exit: ::exit_future::Exit, signal: Option, /// Configuration of this Service pub config: FactoryFullConfiguration, - _rpc: Box<::std::any::Any + Send + Sync>, - _telemetry: Option>, + _rpc: Box, + _telemetry: Option, _offchain_workers: Option, ComponentBlock>>>, _telemetry_on_connect_sinks: Arc>>>, } @@ -106,7 +104,7 @@ pub type TelemetryOnConnectNotifications = mpsc::UnboundedReceiver<()>; /// Used to hook on telemetry connection established events. pub struct TelemetryOnConnect<'a> { /// Handle to a future that will resolve on exit. - pub on_exit: Box + Send + 'static>, + pub on_exit: Box + Send + 'static>, /// Event stream. pub telemetry_connection_sinks: TelemetryOnConnectNotifications, /// Executor to which the hook is spawned. @@ -158,11 +156,14 @@ impl Service { select_chain.clone(), )?); let finality_proof_provider = Components::build_finality_proof_provider(client.clone())?; - let chain_info = client.info()?.chain; + let chain_info = client.info().chain; let version = config.full_version(); info!("Highest known block at #{}", chain_info.best_number); - telemetry!(SUBSTRATE_INFO; "node.start"; "height" => chain_info.best_number.as_(), "best" => ?chain_info.best_hash); + telemetry!(SUBSTRATE_INFO; "node.start"; + "height" => chain_info.best_number.saturated_into::(), + "best" => ?chain_info.best_hash + ); let network_protocol = ::build_network_protocol(&config)?; let transaction_pool = Arc::new( @@ -174,16 +175,6 @@ impl Service { client: client.clone(), }); - let network_params = network::config::Params { - config: network::config::ProtocolConfig { roles: config.roles }, - network_config: config.network.clone(), - chain: client.clone(), - finality_proof_provider, - on_demand: on_demand.as_ref().map(|d| d.clone() as _), - transaction_pool: transaction_pool_adapter.clone() as _, - specialization: network_protocol, - }; - let protocol_id = { let protocol_id_full = match config.chain_spec.protocol_id() { Some(pid) => pid, @@ -197,17 +188,30 @@ impl Service { network::ProtocolId::from(protocol_id_full) }; + let network_params = network::config::Params { + roles: config.roles, + network_config: config.network.clone(), + chain: client.clone(), + finality_proof_provider, + on_demand, + transaction_pool: transaction_pool_adapter.clone() as _, + import_queue, + protocol_id, + specialization: network_protocol, + }; + let has_bootnodes = !network_params.network_config.boot_nodes.is_empty(); - let network = network::Service::new(network_params, protocol_id, import_queue)?; - if let Some(on_demand) = on_demand.as_ref() { - on_demand.set_network_interface(Box::new(Arc::downgrade(&network))); - } + let network_mut = network::NetworkWorker::new(network_params)?; + let network = network_mut.service().clone(); + + task_executor.spawn(network_mut + .map_err(|_| ()) + .select(exit.clone()) + .then(|_| Ok(()))); - let inherents_pool = Arc::new(InherentsPool::default()); let offchain_workers = if config.offchain_worker { Some(Arc::new(offchain::OffchainWorkers::new( client.clone(), - inherents_pool.clone(), task_executor.clone(), ))) } else { @@ -323,8 +327,16 @@ impl Service { properties: config.chain_spec.properties(), }; let rpc = Components::RuntimeServices::start_rpc( - client.clone(), network.clone(), has_bootnodes, system_info, config.rpc_http, - config.rpc_ws, config.rpc_cors.clone(), task_executor.clone(), transaction_pool.clone(), + client.clone(), + network.clone(), + has_bootnodes, + system_info, + config.rpc_http, + config.rpc_ws, + config.rpc_ws_max_connections, + config.rpc_cors.clone(), + task_executor.clone(), + transaction_pool.clone(), )?; let telemetry_connection_sinks: Arc>>> = Default::default(); @@ -339,8 +351,9 @@ impl Service { let version = version.clone(); let chain_name = config.chain_spec.name().to_owned(); let telemetry_connection_sinks_ = telemetry_connection_sinks.clone(); - Arc::new(tel::init_telemetry(tel::TelemetryConfig { + let telemetry = tel::init_telemetry(tel::TelemetryConfig { endpoints, + wasm_external_transport: None, on_connect: Box::new(move || { telemetry!(SUBSTRATE_INFO; "system.connected"; "name" => name.clone(), @@ -357,7 +370,11 @@ impl Service { sink.unbounded_send(()).is_ok() }); }), - })) + }); + task_executor.spawn(telemetry.clone() + .select(exit.clone()) + .then(|_| Ok(()))); + telemetry }); Ok(Service { @@ -365,7 +382,6 @@ impl Service { network: Some(network), select_chain, transaction_pool, - inherents_pool, signal: Some(signal), keystore, config, @@ -391,7 +407,7 @@ impl Service { } /// return a shared instance of Telemetry (if enabled) - pub fn telemetry(&self) -> Option> { + pub fn telemetry(&self) -> Option { self._telemetry.as_ref().map(|t| t.clone()) } } @@ -417,11 +433,6 @@ impl Service where Components: components::Components { self.transaction_pool.clone() } - /// Get shared inherents pool instance. - pub fn inherents_pool(&self) -> Arc>> { - self.inherents_pool.clone() - } - /// Get shared keystore. pub fn keystore(&self) -> &Keystore { &self.keystore @@ -473,26 +484,36 @@ pub struct TransactionPoolAdapter { impl TransactionPoolAdapter { fn best_block_id(&self) -> Option>> { - self.client.info() - .map(|info| BlockId::hash(info.chain.best_hash)) - .map_err(|e| { - debug!("Error getting best block: {:?}", e); - }) - .ok() + Some(BlockId::hash(self.client.info().chain.best_hash)) } } +/// Get transactions for propagation. +/// +/// Function extracted to simplify the test and prevent creating `ServiceFactory`. +fn transactions_to_propagate(pool: &TransactionPool) + -> Vec<(H, B::Extrinsic)> +where + PoolApi: ChainApi, + B: BlockT, + H: std::hash::Hash + Eq + runtime_primitives::traits::Member + serde::Serialize, + E: txpool::error::IntoPoolError + From, +{ + pool.ready() + .filter(|t| t.is_propagateable()) + .map(|t| { + let hash = t.hash.clone(); + let ex: B::Extrinsic = t.data.clone(); + (hash, ex) + }) + .collect() +} + impl network::TransactionPool, ComponentBlock> for TransactionPoolAdapter where ::RuntimeApi: Send + Sync { fn transactions(&self) -> Vec<(ComponentExHash, ComponentExtrinsic)> { - self.pool.ready() - .map(|t| { - let hash = t.hash.clone(); - let ex: ComponentExtrinsic = t.data.clone(); - (hash, ex) - }) - .collect() + transactions_to_propagate(&self.pool) } fn import(&self, transaction: &ComponentExtrinsic) -> Option> { @@ -507,7 +528,7 @@ impl network::TransactionPool, ComponentBlock< match self.pool.submit_one(&best_block_id, uxt) { Ok(hash) => Some(hash), Err(e) => match e.into_pool_error() { - Ok(txpool::error::Error(txpool::error::ErrorKind::AlreadyImported(hash), _)) => { + Ok(txpool::error::Error::AlreadyImported(hash)) => { hash.downcast::>().ok() .map(|x| x.as_ref().clone()) }, @@ -606,7 +627,8 @@ impl network::TransactionPool, ComponentBlock< /// { |_, client| Ok(BasicQueue::new(Arc::new(MyVerifier), client, None, None, None)) }, /// SelectChain = LongestChain, Self::Block> /// { |config: &FactoryFullConfiguration, client: Arc>| { -/// Ok(LongestChain::new(client.backend().clone(), client.import_lock())) +/// #[allow(deprecated)] +/// Ok(LongestChain::new(client.backend().clone())) /// }}, /// FinalityProofProvider = { |client: Arc>| { /// Ok(Some(Arc::new(grandpa::FinalityProofProvider::new(client.clone(), client)) as _)) @@ -729,3 +751,41 @@ macro_rules! construct_service_factory { } } } + +#[cfg(test)] +mod tests { + use super::*; + use consensus_common::SelectChain; + use runtime_primitives::traits::BlindCheckable; + use substrate_test_runtime_client::{prelude::*, runtime::{Extrinsic, Transfer}}; + + #[test] + fn should_not_propagate_transactions_that_are_marked_as_such() { + // given + let (client, longest_chain) = TestClientBuilder::new().build_with_longest_chain(); + let client = Arc::new(client); + let pool = Arc::new(TransactionPool::new( + Default::default(), + transaction_pool::ChainApi::new(client.clone()) + )); + let best = longest_chain.best_chain().unwrap(); + let transaction = Transfer { + amount: 5, + nonce: 0, + from: AccountKeyring::Alice.into(), + to: Default::default(), + }.into_signed_tx(); + pool.submit_one(&BlockId::hash(best.hash()), transaction.clone()).unwrap(); + pool.submit_one(&BlockId::hash(best.hash()), Extrinsic::IncludeData(vec![1])).unwrap(); + assert_eq!(pool.status().ready, 2); + + // when + let transactions = transactions_to_propagate(&pool); + + // then + assert_eq!(transactions.len(), 1); + assert!(transactions[0].1.clone().check().is_ok()); + // this should not panic + let _ = transactions[0].1.transfer(); + } +} diff --git a/core/service/test/src/lib.rs b/core/service/test/src/lib.rs index b0ed0c0fc11ce14149cce175b423337794f08a64..c31196af97ff34ba04cdd50394a2bc99c8882ffc 100644 --- a/core/service/test/src/lib.rs +++ b/core/service/test/src/lib.rs @@ -24,7 +24,7 @@ use std::collections::HashMap; use log::info; use futures::{Future, Stream}; use tempdir::TempDir; -use tokio::runtime::Runtime; +use tokio::{runtime::Runtime, prelude::FutureExt}; use tokio::timer::Interval; use service::{ ServiceFactory, @@ -36,31 +36,56 @@ use service::{ }; use network::{multiaddr, Multiaddr, SyncProvider, ManageNetwork}; use network::config::{NetworkConfiguration, NodeKeyConfig, Secret, NonReservedPeerMode}; -use sr_primitives::traits::As; use sr_primitives::generic::BlockId; use consensus::{ImportBlock, BlockImport}; +/// Maximum duration of single wait call. +const MAX_WAIT_TIME: Duration = Duration::from_secs(60 * 3); + struct TestNet { runtime: Runtime, authority_nodes: Vec<(u32, Arc, Multiaddr)>, full_nodes: Vec<(u32, Arc, Multiaddr)>, - _light_nodes: Vec<(u32, Arc)>, + light_nodes: Vec<(u32, Arc, Multiaddr)>, chain_spec: FactoryChainSpec, base_port: u16, nodes: usize, } impl TestNet { - pub fn run_until_all_full bool + 'static>(&mut self, predicate: P) { + pub fn run_until_all_full( + &mut self, + full_predicate: FP, + light_predicate: LP, + ) + where + FP: Send + Sync + Fn(u32, &F::FullService) -> bool + 'static, + LP: Send + Sync + Fn(u32, &F::LightService) -> bool + 'static, + { let full_nodes = self.full_nodes.clone(); - let interval = Interval::new_interval(Duration::from_millis(100)).map_err(|_| ()).for_each(move |_| { - if full_nodes.iter().all(|&(ref id, ref service, _)| predicate(*id, service)) { + let light_nodes = self.light_nodes.clone(); + let interval = Interval::new_interval(Duration::from_millis(100)) + .map_err(|_| ()) + .for_each(move |_| { + let full_ready = full_nodes.iter().all(|&(ref id, ref service, _)| full_predicate(*id, service)); + if !full_ready { + return Ok(()); + } + + let light_ready = light_nodes.iter().all(|&(ref id, ref service, _)| light_predicate(*id, service)); + if !light_ready { + return Ok(()); + } + Err(()) - } else { - Ok(()) - } - }); - self.runtime.block_on(interval).ok(); + }) + .timeout(MAX_WAIT_TIME); + + match self.runtime.block_on(interval) { + Ok(()) => unreachable!("interval always fails; qed"), + Err(ref err) if err.is_inner() => (), + Err(_) => panic!("Waited for too long"), + } } } @@ -100,6 +125,7 @@ fn node_config ( client_version: "network/test/0.1".to_owned(), node_name: "unknown".to_owned(), enable_mdns: false, + wasm_external_transport: None, }; Configuration { @@ -121,6 +147,7 @@ fn node_config ( execution_strategies: Default::default(), rpc_http: None, rpc_ws: None, + rpc_ws_max_connections: None, rpc_cors: None, telemetry_endpoints: None, default_heap_pages: None, @@ -140,7 +167,7 @@ impl TestNet { runtime, authority_nodes: Default::default(), full_nodes: Default::default(), - _light_nodes: Default::default(), + light_nodes: Default::default(), chain_spec: spec.clone(), base_port, nodes: 0, @@ -174,28 +201,46 @@ impl TestNet { })); nodes += full as usize; - self._light_nodes.extend((nodes..nodes + light as usize).map(|index| (index as u32, - Arc::new(F::new_light(node_config::(index as u32, &spec, Roles::LIGHT, None, base_port, &temp), executor.clone()) - .expect("Error creating test node service"))) - )); + self.light_nodes.extend((nodes..nodes + light as usize).map(|index| { + let node_config = node_config::(index as u32, &spec, Roles::LIGHT, None, base_port, &temp); + let addr = node_config.network.listen_addresses.iter().next().unwrap().clone(); + let service = Arc::new(F::new_light(node_config, executor.clone()) + .expect("Error creating test node service")); + let addr = addr.with(multiaddr::Protocol::P2p(service.network().local_peer_id().into())); + (index as u32, service, addr) + })); nodes += light as usize; + self.nodes = nodes; } } pub fn connectivity(spec: FactoryChainSpec) { - const NUM_NODES: u32 = 10; + const NUM_FULL_NODES: u32 = 5; + const NUM_LIGHT_NODES: u32 = 5; { let temp = TempDir::new("substrate-connectivity-test").expect("Error creating test dir"); let runtime = { - let mut network = TestNet::::new(&temp, spec.clone(), NUM_NODES, 0, vec![], 30400); + let mut network = TestNet::::new( + &temp, + spec.clone(), + NUM_FULL_NODES, + NUM_LIGHT_NODES, + vec![], + 30400, + ); info!("Checking star topology"); let first_address = network.full_nodes[0].2.clone(); for (_, service, _) in network.full_nodes.iter().skip(1) { service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); } - network.run_until_all_full(|_index, service| - service.network().peers().len() == NUM_NODES as usize - 1 + for (_, service, _) in network.light_nodes.iter() { + service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); + } + network.run_until_all_full( + |_index, service| service.network().peers_debug_info().len() == NUM_FULL_NODES as usize - 1 + + NUM_LIGHT_NODES as usize, + |_index, service| service.network().peers_debug_info().len() == NUM_FULL_NODES as usize, ); network.runtime }; @@ -207,31 +252,62 @@ pub fn connectivity(spec: FactoryChainSpec) { { let temp = TempDir::new("substrate-connectivity-test").expect("Error creating test dir"); { - let mut network = TestNet::::new(&temp, spec, NUM_NODES, 0, vec![], 30400); + let mut network = TestNet::::new( + &temp, + spec, + NUM_FULL_NODES, + NUM_LIGHT_NODES, + vec![], + 30400, + ); info!("Checking linked topology"); let mut address = network.full_nodes[0].2.clone(); - for (_, service, node_id) in network.full_nodes.iter().skip(1) { - service.network().add_reserved_peer(address.to_string()).expect("Error adding reserved peer"); - address = node_id.clone(); + let max_nodes = ::std::cmp::max(NUM_FULL_NODES, NUM_LIGHT_NODES); + for i in 0..max_nodes { + if i != 0 { + if let Some((_, service, node_id)) = network.full_nodes.get(i as usize) { + service.network().add_reserved_peer(address.to_string()).expect("Error adding reserved peer"); + address = node_id.clone(); + } + } + + if let Some((_, service, node_id)) = network.light_nodes.get(i as usize) { + service.network().add_reserved_peer(address.to_string()).expect("Error adding reserved peer"); + address = node_id.clone(); + } } - network.run_until_all_full(|_index, service| { - service.network().peers().len() == NUM_NODES as usize - 1 - }); + network.run_until_all_full( + |_index, service| service.network().peers_debug_info().len() == NUM_FULL_NODES as usize - 1 + + NUM_LIGHT_NODES as usize, + |_index, service| service.network().peers_debug_info().len() == NUM_FULL_NODES as usize, + ); } temp.close().expect("Error removing temp dir"); } } -pub fn sync(spec: FactoryChainSpec, block_factory: B, extrinsic_factory: E) +pub fn sync( + spec: FactoryChainSpec, + mut block_factory: B, + mut extrinsic_factory: E, +) where F: ServiceFactory, - B: Fn(&F::FullService) -> ImportBlock, - E: Fn(&F::FullService) -> FactoryExtrinsic, + B: FnMut(&F::FullService) -> ImportBlock, + E: FnMut(&F::FullService) -> FactoryExtrinsic, { - const NUM_NODES: u32 = 10; - const NUM_BLOCKS: usize = 512; + const NUM_FULL_NODES: u32 = 10; + const NUM_LIGHT_NODES: u32 = 10; + const NUM_BLOCKS: u32 = 512; let temp = TempDir::new("substrate-sync-test").expect("Error creating test dir"); - let mut network = TestNet::::new(&temp, spec.clone(), NUM_NODES, 0, vec![], 30500); + let mut network = TestNet::::new( + &temp, + spec.clone(), + NUM_FULL_NODES, + NUM_LIGHT_NODES, + vec![], + 30500, + ); info!("Checking block sync"); let first_address = { let first_service = &network.full_nodes[0].1; @@ -248,15 +324,22 @@ where for (_, service, _) in network.full_nodes.iter().skip(1) { service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); } - network.run_until_all_full(|_index, service| - service.client().info().unwrap().chain.best_number == As::sa(NUM_BLOCKS as u64) + for (_, service, _) in network.light_nodes.iter() { + service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); + } + network.run_until_all_full( + |_index, service| + service.client().info().chain.best_number == NUM_BLOCKS.into(), + |_index, service| + service.client().info().chain.best_number == NUM_BLOCKS.into(), ); info!("Checking extrinsic propagation"); let first_service = network.full_nodes[0].1.clone(); - let best_block = BlockId::number(first_service.client().info().unwrap().chain.best_number); + let best_block = BlockId::number(first_service.client().info().chain.best_number); first_service.transaction_pool().submit_one(&best_block, extrinsic_factory(&first_service)).unwrap(); - network.run_until_all_full(|_index, service| - service.transaction_pool().ready().count() == 1 + network.run_until_all_full( + |_index, service| service.transaction_pool().ready().count() == 1, + |_index, _service| true, ); } @@ -264,27 +347,47 @@ pub fn consensus(spec: FactoryChainSpec, authorities: Vec) where F: ServiceFactory, { - const NUM_NODES: u32 = 20; - const NUM_BLOCKS: u64 = 200; + const NUM_FULL_NODES: u32 = 10; + const NUM_LIGHT_NODES: u32 = 0; + const NUM_BLOCKS: u32 = 10; // 10 * 2 sec block production time = ~20 seconds let temp = TempDir::new("substrate-conensus-test").expect("Error creating test dir"); - let mut network = TestNet::::new(&temp, spec.clone(), NUM_NODES / 2, 0, authorities, 30600); + let mut network = TestNet::::new( + &temp, + spec.clone(), + NUM_FULL_NODES / 2, + NUM_LIGHT_NODES / 2, + authorities, + 30600, + ); info!("Checking consensus"); let first_address = network.authority_nodes[0].2.clone(); for (_, service, _) in network.full_nodes.iter() { service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); } + for (_, service, _) in network.light_nodes.iter() { + service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); + } for (_, service, _) in network.authority_nodes.iter().skip(1) { service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); } - network.run_until_all_full(|_index, service| { - service.client().info().unwrap().chain.finalized_number >= As::sa(NUM_BLOCKS / 2) - }); + network.run_until_all_full( + |_index, service| + service.client().info().chain.finalized_number >= (NUM_BLOCKS / 2).into(), + |_index, service| + service.client().info().chain.best_number >= (NUM_BLOCKS / 2).into(), + ); info!("Adding more peers"); - network.insert_nodes(&temp, NUM_NODES / 2, 0, vec![]); + network.insert_nodes(&temp, NUM_FULL_NODES / 2, NUM_LIGHT_NODES / 2, vec![]); for (_, service, _) in network.full_nodes.iter() { service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); } - network.run_until_all_full(|_index, service| - service.client().info().unwrap().chain.finalized_number >= As::sa(NUM_BLOCKS) + for (_, service, _) in network.light_nodes.iter() { + service.network().add_reserved_peer(first_address.to_string()).expect("Error adding reserved peer"); + } + network.run_until_all_full( + |_index, service| + service.client().info().chain.finalized_number >= NUM_BLOCKS.into(), + |_index, service| + service.client().info().chain.best_number >= NUM_BLOCKS.into(), ); } diff --git a/core/sr-api-macros/Cargo.toml b/core/sr-api-macros/Cargo.toml index a87b53b7327ae831e7e28e0e2e015b4d8dd039ee..9f2145d958eee31d72bc3817ff1f2c14991ae4bb 100644 --- a/core/sr-api-macros/Cargo.toml +++ b/core/sr-api-macros/Cargo.toml @@ -16,7 +16,7 @@ proc-macro-crate = "0.1.3" [dev-dependencies] client = { package = "substrate-client", path = "../client" } -test_client = { package = "substrate-test-client", path = "../test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../test-runtime/client" } state_machine = { package = "substrate-state-machine", path = "../state-machine" } runtime_primitives = { package = "sr-primitives", path = "../sr-primitives" } sr-version = { path = "../sr-version" } diff --git a/core/sr-api-macros/benches/bench.rs b/core/sr-api-macros/benches/bench.rs index f4677217897924ef532adca0f2bac520f569c2ee..55399fb4d8b1fef2b40ec30a93041cb08b777e1d 100644 --- a/core/sr-api-macros/benches/bench.rs +++ b/core/sr-api-macros/benches/bench.rs @@ -23,14 +23,14 @@ fn sr_api_benchmark(c: &mut Criterion) { c.bench_function("add one with same runtime api", |b| { let client = test_client::new(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); b.iter(|| runtime_api.benchmark_add_one(&block_id, &1)) }); c.bench_function("add one with recreating runtime api", |b| { let client = test_client::new(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); b.iter(|| client.runtime_api().benchmark_add_one(&block_id, &1)) }); @@ -38,7 +38,7 @@ fn sr_api_benchmark(c: &mut Criterion) { c.bench_function("vector add one with same runtime api", |b| { let client = test_client::new(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); let data = vec![0; 1000]; b.iter_with_large_drop(|| runtime_api.benchmark_vector_add_one(&block_id, &data)) @@ -46,7 +46,7 @@ fn sr_api_benchmark(c: &mut Criterion) { c.bench_function("vector add one with recreating runtime api", |b| { let client = test_client::new(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); let data = vec![0; 1000]; b.iter_with_large_drop(|| client.runtime_api().benchmark_vector_add_one(&block_id, &data)) @@ -54,13 +54,13 @@ fn sr_api_benchmark(c: &mut Criterion) { c.bench_function("calling function by function pointer in wasm", |b| { let client = test_client::new_with_execution_strategy(ExecutionStrategy::AlwaysWasm); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); b.iter(|| client.runtime_api().benchmark_indirect_call(&block_id).unwrap()) }); c.bench_function("calling function in wasm", |b| { let client = test_client::new_with_execution_strategy(ExecutionStrategy::AlwaysWasm); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); b.iter(|| client.runtime_api().benchmark_direct_call(&block_id).unwrap()) }); } diff --git a/core/sr-api-macros/src/lib.rs b/core/sr-api-macros/src/lib.rs index c5f894100219361cd852b116747981ebde5da745..1a315f44ddd5d37e40f82e66da2fd5a121543d4a 100644 --- a/core/sr-api-macros/src/lib.rs +++ b/core/sr-api-macros/src/lib.rs @@ -54,11 +54,11 @@ mod utils; /// # extern crate substrate_primitives; /// # /// # use runtime_primitives::traits::GetNodeBlockType; -/// # use test_client::runtime::Block; +/// # use test_client::runtime::{Block, Header}; /// # /// # /// The declaration of the `Runtime` type and the implementation of the `GetNodeBlockType` /// # /// trait are done by the `construct_runtime!` macro in a real runtime. -/// # struct Runtime {} +/// # pub struct Runtime {} /// # impl GetNodeBlockType for Runtime { /// # type NodeBlock = Block; /// # } @@ -78,6 +78,14 @@ mod utils; /// /// /// All runtime api implementations need to be done in one call of the macro! /// impl_runtime_apis! { +/// # impl client::runtime_api::Core for Runtime { +/// # fn version() -> client::runtime_api::RuntimeVersion { +/// # unimplemented!() +/// # } +/// # fn execute_block(_block: Block) {} +/// # fn initialize_block(_header: &Header) {} +/// # } +/// /// impl self::Balance for Runtime { /// fn get_balance() -> u64 { /// 1 @@ -176,7 +184,7 @@ pub fn impl_runtime_apis(input: TokenStream) -> TokenStream { /// /// /// /// Is callable by `set_balance_before_version_2`. /// #[changed_in(2)] -/// fn set_balance(val: u8); +/// fn set_balance(val: u16); /// /// In version 2, we added this new function. /// fn increase_balance(val: u64); /// } diff --git a/core/sr-api-macros/tests/decl_and_impl.rs b/core/sr-api-macros/tests/decl_and_impl.rs index 51f95d51b16dd6be173af59806c459f2c6ecc2ce..ba7ef23b99c983c16e9850da0c8317887aa2e181 100644 --- a/core/sr-api-macros/tests/decl_and_impl.rs +++ b/core/sr-api-macros/tests/decl_and_impl.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -use runtime_primitives::traits::{GetNodeBlockType, Block as BlockT, AuthorityIdFor}; +use runtime_primitives::traits::{GetNodeBlockType, Block as BlockT}; use runtime_primitives::generic::BlockId; use client::runtime_api::{self, RuntimeApiInfo}; use client::{error::Result, decl_runtime_apis, impl_runtime_apis}; @@ -74,9 +74,6 @@ impl_runtime_apis! { fn initialize_block(_: &::Header) { unimplemented!() } - fn authorities() -> Vec> { - unimplemented!() - } } } @@ -122,7 +119,7 @@ fn check_runtime_api_versions_contains() { #[test] fn check_runtime_api_versions() { - check_runtime_api_versions_contains::>(); - check_runtime_api_versions_contains::>(); - check_runtime_api_versions_contains::>(); + check_runtime_api_versions_contains::>(); + check_runtime_api_versions_contains::>(); + check_runtime_api_versions_contains::>(); } diff --git a/core/sr-api-macros/tests/runtime_calls.rs b/core/sr-api-macros/tests/runtime_calls.rs index fb3cad3238e6ff7247f4c94d64b631bfa6ffb94c..6fa155437b83371ce29abe52b2f97c1ffd7631a8 100644 --- a/core/sr-api-macros/tests/runtime_calls.rs +++ b/core/sr-api-macros/tests/runtime_calls.rs @@ -15,8 +15,8 @@ // along with Substrate. If not, see . use test_client::{ - AccountKeyring, runtime::{TestAPI, DecodeFails, Transfer, Header}, - NativeExecutor, LocalExecutor, + prelude::*, + runtime::{TestAPI, DecodeFails, Transfer, Header}, }; use runtime_primitives::{ generic::BlockId, @@ -27,14 +27,13 @@ use state_machine::{ execution_proof_check_on_trie_backend, }; -use client::LongestChain; use consensus_common::SelectChain; use codec::Encode; fn calling_function_with_strat(strat: ExecutionStrategy) { - let client = test_client::new_with_execution_strategy(strat); + let client = TestClientBuilder::new().set_execution_strategy(strat).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert_eq!(runtime_api.benchmark_add_one(&block_id, &1).unwrap(), 2); } @@ -52,35 +51,35 @@ fn calling_wasm_runtime_function() { #[test] #[should_panic(expected = "Could not convert parameter `param` between node and runtime!")] fn calling_native_runtime_function_with_non_decodable_parameter() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::NativeWhenPossible); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeWhenPossible).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); runtime_api.fail_convert_parameter(&block_id, DecodeFails::new()).unwrap(); } #[test] #[should_panic(expected = "Could not convert return value from runtime to node!")] fn calling_native_runtime_function_with_non_decodable_return_value() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::NativeWhenPossible); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeWhenPossible).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); runtime_api.fail_convert_return_value(&block_id).unwrap(); } #[test] fn calling_native_runtime_signature_changed_function() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::NativeWhenPossible); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeWhenPossible).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert_eq!(runtime_api.function_signature_changed(&block_id).unwrap(), 1); } #[test] fn calling_wasm_runtime_signature_changed_old_function() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::AlwaysWasm); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::AlwaysWasm).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); #[allow(deprecated)] let res = runtime_api.function_signature_changed_before_version_2(&block_id).unwrap(); @@ -89,77 +88,78 @@ fn calling_wasm_runtime_signature_changed_old_function() { #[test] fn calling_with_both_strategy_and_fail_on_wasm_should_return_error() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::Both); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert!(runtime_api.fail_on_wasm(&block_id).is_err()); } #[test] fn calling_with_both_strategy_and_fail_on_native_should_work() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::Both); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1); } #[test] fn calling_with_native_else_wasm_and_faild_on_wasm_should_work() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::NativeElseWasm); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeElseWasm).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert_eq!(runtime_api.fail_on_wasm(&block_id).unwrap(), 1); } #[test] fn calling_with_native_else_wasm_and_fail_on_native_should_work() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::NativeElseWasm); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::NativeElseWasm).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1); } #[test] fn use_trie_function() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::AlwaysWasm); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::AlwaysWasm).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert_eq!(runtime_api.use_trie(&block_id).unwrap(), 2); } #[test] fn initialize_block_works() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::Both); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert_eq!(runtime_api.get_block_number(&block_id).unwrap(), 1); } #[test] fn initialize_block_is_called_only_once() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::Both); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert_eq!(runtime_api.take_block_number(&block_id).unwrap(), Some(1)); assert_eq!(runtime_api.take_block_number(&block_id).unwrap(), None); } #[test] fn initialize_block_is_skipped() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::Both); + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build(); let runtime_api = client.runtime_api(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); + let block_id = BlockId::Number(client.info().chain.best_number); assert!(runtime_api.without_initialize_block(&block_id).unwrap()); } #[test] fn record_proof_works() { - let client = test_client::new_with_execution_strategy(ExecutionStrategy::Both); + let (client, longest_chain) = TestClientBuilder::new() + .set_execution_strategy(ExecutionStrategy::Both) + .build_with_longest_chain(); - let block_id = BlockId::Number(client.info().unwrap().chain.best_number); - let storage_root = LongestChain::new(client.backend().clone(), client.import_lock()) - .best_chain().unwrap().state_root().clone(); + let block_id = BlockId::Number(client.info().chain.best_number); + let storage_root = longest_chain.best_chain().unwrap().state_root().clone(); let transaction = Transfer { amount: 1000, @@ -170,7 +170,7 @@ fn record_proof_works() { // Build the block and record proof let mut builder = client - .new_block_at_with_proof_recording(&block_id) + .new_block_at_with_proof_recording(&block_id, Default::default()) .expect("Creates block builder"); builder.push(transaction.clone()).unwrap(); let (block, proof) = builder.bake_and_extract_proof().expect("Bake block"); @@ -190,4 +190,4 @@ fn record_proof_works() { "Core_execute_block", &block.encode(), ).expect("Executes block while using the proof backend"); -} \ No newline at end of file +} diff --git a/core/sr-api-macros/tests/ui/invalid_api_version_2.rs b/core/sr-api-macros/tests/ui/invalid_api_version_2.rs index 71586307933fb45943af1dcbdc76e5b843d47abd..b8870838009bf2132318ebd7b2a97b547f63b9dc 100644 --- a/core/sr-api-macros/tests/ui/invalid_api_version_2.rs +++ b/core/sr-api-macros/tests/ui/invalid_api_version_2.rs @@ -8,4 +8,3 @@ decl_runtime_apis! { } fn main() {} - diff --git a/core/sr-io/Cargo.toml b/core/sr-io/Cargo.toml index dbe699b4b5ec2c197126505642e91e81ae4cfa82..0c97ba8050d2d8f9990ee540f40dfca4ceef7da9 100644 --- a/core/sr-io/Cargo.toml +++ b/core/sr-io/Cargo.toml @@ -19,6 +19,9 @@ environmental = { version = "1.0.1", optional = true } substrate-state-machine = { path = "../state-machine", optional = true } trie = { package = "substrate-trie", path = "../trie", optional = true } +[dev-dependencies] +substrate-offchain = { path = "../offchain" } + [features] default = ["std"] std = [ diff --git a/core/sr-io/src/lib.rs b/core/sr-io/src/lib.rs index 47af4de98ba642133a0069ceccf0e97a90114daa..cd9b43798b3d1d7f59ea13ed2e1464ef949fb0de 100644 --- a/core/sr-io/src/lib.rs +++ b/core/sr-io/src/lib.rs @@ -33,6 +33,7 @@ use rstd::vec::Vec; pub use codec; pub use primitives::Blake2Hasher; +use primitives::offchain::{Timestamp, HttpRequestId, HttpRequestStatus, HttpError, CryptoKind, CryptoKeyId}; /// Error verifying ECDSA signature pub enum EcdsaVerifyError { @@ -44,6 +45,8 @@ pub enum EcdsaVerifyError { BadSignature, } +pub mod offchain; + /// Trait for things which can be printed. pub trait Printable { /// Print the object. @@ -138,7 +141,7 @@ export_api! { fn child_storage_root(storage_key: &[u8]) -> Vec; /// "Commit" all existing operations and get the resultant storage change root. - fn storage_changes_root(parent_hash: [u8; 32], parent_num: u64) -> Option<[u8; 32]>; + fn storage_changes_root(parent_hash: [u8; 32]) -> Option<[u8; 32]>; /// A trie root formed from the enumerated items. /// TODO [#2382] remove (just use `ordered_trie_root` (NOTE currently not implemented for without_std)) @@ -226,12 +229,140 @@ export_api! { export_api! { pub(crate) trait OffchainApi { - /// Submit extrinsic from the runtime. + /// Submit transaction to the pool. + /// + /// The transaction will end up in the pool. + fn submit_transaction(data: &T) -> Result<(), ()>; + + /// Create new key(pair) for signing/encryption/decryption. + /// + /// Returns an error if given crypto kind is not supported. + fn new_crypto_key(crypto: CryptoKind) -> Result; + + /// Encrypt a piece of data using given crypto key. /// - /// Depending on the kind of extrinsic it will either be: - /// 1. scheduled to be included in the next produced block (inherent) - /// 2. added to the pool and propagated (transaction) - fn submit_extrinsic(data: &T); + /// If `key` is `None`, it will attempt to use current authority key. + /// + /// Returns an error if `key` is not available or does not exist. + fn encrypt(key: Option, data: &[u8]) -> Result, ()>; + + /// Decrypt a piece of data using given crypto key. + /// + /// If `key` is `None`, it will attempt to use current authority key. + /// + /// Returns an error if data cannot be decrypted or the `key` is not available or does not exist. + fn decrypt(key: Option, data: &[u8]) -> Result, ()>; + + /// Sign a piece of data using given crypto key. + /// + /// If `key` is `None`, it will attempt to use current authority key. + /// + /// Returns an error if `key` is not available or does not exist. + fn sign(key: Option, data: &[u8]) -> Result, ()>; + + /// Verifies that `signature` for `msg` matches given `key`. + /// + /// Returns an `Ok` with `true` in case it does, `false` in case it doesn't. + /// Returns an error in case the key is not available or does not exist or the parameters + /// lengths are incorrect. + fn verify(key: Option, msg: &[u8], signature: &[u8]) -> Result; + + /// Returns current UNIX timestamp (in millis) + fn timestamp() -> Timestamp; + + /// Pause the execution until `deadline` is reached. + fn sleep_until(deadline: Timestamp); + + /// Returns a random seed. + /// + /// This is a trully random non deterministic seed generated by host environment. + /// Obviously fine in the off-chain worker context. + fn random_seed() -> [u8; 32]; + + /// Sets a value in the local storage. + /// + /// Note this storage is not part of the consensus, it's only accessible by + /// offchain worker tasks running on the same machine. It IS persisted between runs. + fn local_storage_set(key: &[u8], value: &[u8]); + + /// Sets a value in the local storage if it matches current value. + /// + /// Since multiple offchain workers may be running concurrently, to prevent + /// data races use CAS to coordinate between them. + /// + /// Note this storage is not part of the consensus, it's only accessible by + /// offchain worker tasks running on the same machine. It IS persisted between runs. + fn local_storage_compare_and_set(key: &[u8], old_value: &[u8], new_value: &[u8]); + + /// Gets a value from the local storage. + /// + /// If the value does not exist in the storage `None` will be returned. + /// Note this storage is not part of the consensus, it's only accessible by + /// offchain worker tasks running on the same machine. It IS persisted between runs. + fn local_storage_get(key: &[u8]) -> Option>; + + /// Initiaties a http request given HTTP verb and the URL. + /// + /// Meta is a future-reserved field containing additional, parity-codec encoded parameters. + /// Returns the id of newly started request. + fn http_request_start( + method: &str, + uri: &str, + meta: &[u8] + ) -> Result; + + /// Append header to the request. + fn http_request_add_header( + request_id: HttpRequestId, + name: &str, + value: &str + ) -> Result<(), ()>; + + /// Write a chunk of request body. + /// + /// Writing an empty chunks finalises the request. + /// Passing `None` as deadline blocks forever. + /// + /// Returns an error in case deadline is reached or the chunk couldn't be written. + fn http_request_write_body( + request_id: HttpRequestId, + chunk: &[u8], + deadline: Option + ) -> Result<(), HttpError>; + + /// Block and wait for the responses for given requests. + /// + /// Returns a vector of request statuses (the len is the same as ids). + /// Note that if deadline is not provided the method will block indefinitely, + /// otherwise unready responses will produce `DeadlineReached` status. + /// + /// Passing `None` as deadline blocks forever. + fn http_response_wait( + ids: &[HttpRequestId], + deadline: Option + ) -> Vec; + + /// Read all response headers. + /// + /// Returns a vector of pairs `(HeaderKey, HeaderValue)`. + /// NOTE response headers have to be read before response body. + fn http_response_headers( + request_id: HttpRequestId + ) -> Vec<(Vec, Vec)>; + + /// Read a chunk of body response to given buffer. + /// + /// Returns the number of bytes written or an error in case a deadline + /// is reached or server closed the connection. + /// If `0` is returned it means that the response has been fully consumed + /// and the `request_id` is now invalid. + /// NOTE this implies that response headers must be read before draining the body. + /// Passing `None` as a deadline blocks forever. + fn http_response_read_body( + request_id: HttpRequestId, + buffer: &mut [u8], + deadline: Option + ) -> Result; } } @@ -251,6 +382,10 @@ mod imp { } #[cfg(feature = "std")] -pub use self::imp::{StorageOverlay, ChildrenStorageOverlay, with_storage, with_externalities, TestExternalities}; +pub use self::imp::{StorageOverlay, ChildrenStorageOverlay, with_storage, with_externalities}; #[cfg(not(feature = "std"))] pub use self::imp::ext::*; + +/// Type alias for Externalities implementation used in tests. +#[cfg(feature = "std")] +pub type TestExternalities = self::imp::TestExternalities; diff --git a/core/sr-io/src/offchain/http.rs b/core/sr-io/src/offchain/http.rs new file mode 100644 index 0000000000000000000000000000000000000000..0708f837179ed3072001e5308050dd318c9fe0ad --- /dev/null +++ b/core/sr-io/src/offchain/http.rs @@ -0,0 +1,571 @@ +// 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 . + +//! A non-std set of HTTP types. + +use rstd::str; +use rstd::prelude::Vec; +#[cfg(not(feature = "std"))] +use rstd::prelude::vec; +use primitives::offchain::{ + Timestamp, + HttpRequestId as RequestId, + HttpRequestStatus as RequestStatus, + HttpError, +}; + +/// Request method (HTTP verb) +#[derive(Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub enum Method { + /// GET request + Get, + /// POST request + Post, + /// PUT request + Put, + /// PATCH request + Patch, + /// DELETE request + Delete, + /// Custom verb + Other(&'static str), +} + +impl AsRef for Method { + fn as_ref(&self) -> &str { + match *self { + Method::Get => "GET", + Method::Post => "POST", + Method::Put => "PUT", + Method::Patch => "PATCH", + Method::Delete => "DELETE", + Method::Other(m) => m, + } + } +} + +mod header { + use super::*; + + /// A header type. + #[derive(Clone, PartialEq, Eq)] + #[cfg_attr(feature = "std", derive(Debug))] + pub struct Header { + name: Vec, + value: Vec, + } + + impl Header { + /// Creates new header given it's name and value. + pub fn new(name: &str, value: &str) -> Self { + Header { + name: name.as_bytes().to_vec(), + value: value.as_bytes().to_vec(), + } + } + + /// Returns the name of this header. + pub fn name(&self) -> &str { + // Header keys are always produced from `&str` so this is safe. + // we don't store them as `Strings` to avoid bringing `alloc::String` to rstd + // or here. + unsafe { str::from_utf8_unchecked(&self.name) } + } + + /// Returns the value of this header. + pub fn value(&self) -> &str { + // Header values are always produced from `&str` so this is safe. + // we don't store them as `Strings` to avoid bringing `alloc::String` to rstd + // or here. + unsafe { str::from_utf8_unchecked(&self.value) } + } + } +} + +/// An HTTP request builder. +#[derive(Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct Request<'a, T = Vec<&'static [u8]>> { + /// Request method + pub method: Method, + /// Request URL + pub url: &'a str, + /// Body of the request + pub body: T, + /// Deadline to finish sending the request + pub deadline: Option, + /// Request list of headers. + headers: Vec, +} + +impl Default for Request<'static, T> { + fn default() -> Self { + Request { + method: Method::Get, + url: "http://localhost", + headers: Vec::new(), + body: Default::default(), + deadline: None, + } + } +} + +impl<'a> Request<'a> { + /// Start a simple GET request + pub fn get(url: &'a str) -> Self { + Self::new(url) + } +} + +impl<'a, T> Request<'a, T> { + /// Create new POST request with given body. + pub fn post(url: &'a str, body: T) -> Self { + let req: Request = Request::default(); + + Request { + url, + body, + method: Method::Post, + headers: req.headers, + deadline: req.deadline, + } + } +} + +impl<'a, T: Default> Request<'a, T> { + /// Create new Request builder with given URL and body. + pub fn new(url: &'a str) -> Self { + Request::default().url(url) + } + + /// Change the method of the request + pub fn method(mut self, method: Method) -> Self { + self.method = method; + self + } + + /// Change the URL of the request. + pub fn url(mut self, url: &'a str) -> Self { + self.url = url; + self + } + + /// Set the body of the request. + pub fn body(mut self, body: T) -> Self { + self.body = body; + self + } + + /// Add a header. + pub fn add_header(mut self, name: &str, value: &str) -> Self { + self.headers.push(header::Header::new(name, value)); + self + } + + /// Set the deadline of the request. + pub fn deadline(mut self, deadline: Timestamp) -> Self { + self.deadline = Some(deadline); + self + } +} + +impl<'a, I: AsRef<[u8]>, T: IntoIterator> Request<'a, T> { + /// Send the request and return a handle. + /// + /// Err is returned in case the deadline is reached + /// or the request timeouts. + pub fn send(self) -> Result { + let meta = &[]; + + // start an http request. + let id = crate::http_request_start(self.method.as_ref(), self.url, meta).map_err(|_| HttpError::IoError)?; + + // add custom headers + for header in &self.headers { + crate::http_request_add_header( + id, + header.name(), + header.value(), + ).map_err(|_| HttpError::IoError)? + } + + // write body + for chunk in self.body { + crate::http_request_write_body(id, chunk.as_ref(), self.deadline)?; + } + + // finalise the request + crate::http_request_write_body(id, &[], self.deadline)?; + + Ok(PendingRequest { + id, + }) + } +} + +/// A request error +#[derive(Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub enum Error { + /// Deadline has been reached. + DeadlineReached, + /// Request had timed out. + Timeout, + /// Unknown error has been ecountered. + Unknown, +} + +/// A struct representing an uncompleted http request. +#[derive(PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct PendingRequest { + /// Request ID + pub id: RequestId, +} + +/// A result of waiting for a pending request. +pub type HttpResult = Result; + +impl PendingRequest { + /// Wait for the request to complete. + /// + /// NOTE this waits for the request indefinitely. + pub fn wait(self) -> HttpResult { + match self.try_wait(None) { + Ok(res) => res, + Err(_) => panic!("Since `None` is passed we will never get a deadline error; qed"), + } + } + + /// Attempts to wait for the request to finish, + /// but will return `Err` in case the deadline is reached. + pub fn try_wait(self, deadline: impl Into>) -> Result { + Self::try_wait_all(vec![self], deadline).pop().expect("One request passed, one status received; qed") + } + + /// Wait for all provided requests. + pub fn wait_all(requests: Vec) -> Vec { + Self::try_wait_all(requests, None) + .into_iter() + .map(|r| match r { + Ok(r) => r, + Err(_) => panic!("Since `None` is passed we will never get a deadline error; qed"), + }) + .collect() + } + + /// Attempt to wait for all provided requests, but up to given deadline. + /// + /// Requests that are complete will resolve to an `Ok` others will return a `DeadlineReached` error. + pub fn try_wait_all( + requests: Vec, + deadline: impl Into> + ) -> Vec> { + let ids = requests.iter().map(|r| r.id).collect::>(); + let statuses = crate::http_response_wait(&ids, deadline.into()); + + statuses + .into_iter() + .zip(requests.into_iter()) + .map(|(status, req)| match status { + RequestStatus::DeadlineReached => Err(req), + RequestStatus::Timeout => Ok(Err(Error::Timeout)), + RequestStatus::Unknown => Ok(Err(Error::Unknown)), + RequestStatus::Finished(code) => Ok(Ok(Response::new(req.id, code))), + }) + .collect() + } +} + +/// A HTTP response. +#[cfg_attr(feature = "std", derive(Debug))] +pub struct Response { + /// Request id + pub id: RequestId, + /// Response status code + pub code: u16, + /// A collection of headers. + headers: Option, +} + +impl Response { + fn new(id: RequestId, code: u16) -> Self { + Self { + id, + code, + headers: None, + } + } + + /// Retrieve the headers for this response. + pub fn headers(&mut self) -> &Headers { + if self.headers.is_none() { + self.headers = Some(Headers { raw: crate::http_response_headers(self.id) }); + } + self.headers.as_ref().expect("Headers were just set; qed") + } + + /// Retrieve the body of this response. + pub fn body(&self) -> ResponseBody { + ResponseBody::new(self.id) + } +} + +/// A buffered byte iterator over response body. +/// +/// Note that reading the body may return `None` in following cases: +/// 1. Either the deadline you've set is reached (check via `#error`; +/// In such case you can resume the reader by setting a new deadline) +/// 2. Or because of IOError. In such case the reader is not resumable and will keep +/// returning `None`. +/// 3. The body has been returned. The reader will keep returning `None`. +#[derive(Clone)] +pub struct ResponseBody { + id: RequestId, + error: Option, + buffer: [u8; 4096], + filled_up_to: Option, + position: usize, + deadline: Option, +} + +#[cfg(feature = "std")] +impl std::fmt::Debug for ResponseBody { + fn fmt(&self, fmt: &mut std::fmt::Formatter) -> std::fmt::Result { + fmt.debug_struct("ResponseBody") + .field("id", &self.id) + .field("error", &self.error) + .field("buffer", &self.buffer.len()) + .field("filled_up_to", &self.filled_up_to) + .field("position", &self.position) + .field("deadline", &self.deadline) + .finish() + } +} + +impl ResponseBody { + fn new(id: RequestId) -> Self { + ResponseBody { + id, + error: None, + buffer: [0_u8; 4096], + filled_up_to: None, + position: 0, + deadline: None, + } + } + + /// Set the deadline for reading the body. + pub fn deadline(&mut self, deadline: impl Into>) { + self.deadline = deadline.into(); + self.error = None; + } + + /// Return an error that caused the iterator to return `None`. + /// + /// If the error is `DeadlineReached` you can resume the iterator by setting + /// a new deadline. + pub fn error(&self) -> &Option { + &self.error + } +} + +impl Iterator for ResponseBody { + type Item = u8; + + fn next(&mut self) -> Option { + if self.error.is_some() { + return None; + } + + if self.filled_up_to.is_none() { + let result = crate::http_response_read_body(self.id, &mut self.buffer, self.deadline); + match result { + Err(e) => { + self.error = Some(e); + return None; + } + Ok(0) => { + return None; + } + Ok(size) => { + self.position = 0; + self.filled_up_to = Some(size); + } + } + } + + if Some(self.position) == self.filled_up_to { + self.filled_up_to = None; + return self.next(); + } + + let result = self.buffer[self.position]; + self.position += 1; + Some(result) + } +} + +/// A collection of Headers in the response. +#[derive(Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct Headers { + /// Raw headers + pub raw: Vec<(Vec, Vec)>, +} + +impl Headers { + /// Retrieve a single header from the list of headers. + /// + /// Note this method is linearly looking from all the headers + /// comparing them with the needle byte-by-byte. + /// If you want to consume multiple headers it's better to iterate + /// and collect them on your own. + pub fn find(&self, name: &str) -> Option<&str> { + let raw = name.as_bytes(); + for &(ref key, ref val) in &self.raw { + if &**key == raw { + return str::from_utf8(&val).ok() + } + } + None + } + + /// Convert this headers into an iterator. + pub fn into_iter(&self) -> HeadersIterator { + HeadersIterator { collection: &self.raw, index: None } + } +} + +/// A custom iterator traversing all the headers. +#[derive(Clone)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct HeadersIterator<'a> { + collection: &'a [(Vec, Vec)], + index: Option, +} + +impl<'a> HeadersIterator<'a> { + /// Move the iterator to the next position. + /// + /// Returns `true` is `current` has been set by this call. + pub fn next(&mut self) -> bool { + let index = self.index.map(|x| x + 1).unwrap_or(0); + self.index = Some(index); + index < self.collection.len() + } + + /// Returns current element (if any). + /// + /// Note that you have to call `next` prior to calling this + pub fn current(&self) -> Option<(&str, &str)> { + self.collection.get(self.index?) + .map(|val| (str::from_utf8(&val.0).unwrap_or(""), str::from_utf8(&val.1).unwrap_or(""))) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{TestExternalities, with_externalities}; + use substrate_offchain::testing; + + #[test] + fn should_send_a_basic_request_and_get_response() { + let offchain = testing::TestOffchainExt::default(); + let mut t = TestExternalities::default(); + let state = offchain.0.clone(); + t.set_offchain_externalities(offchain); + + with_externalities(&mut t, || { + let request: Request = Request::get("http://localhost:1234"); + let pending = request + .add_header("X-Auth", "hunter2") + .send() + .unwrap(); + // make sure it's sent correctly + state.write().fulfill_pending_request( + 0, + testing::PendingRequest { + method: "GET".into(), + uri: "http://localhost:1234".into(), + headers: vec![("X-Auth".into(), "hunter2".into())], + sent: true, + ..Default::default() + }, + b"1234".to_vec(), + None, + ); + + // wait + let mut response = pending.wait().unwrap(); + + // then check the response + let mut headers = response.headers().into_iter(); + assert_eq!(headers.current(), None); + assert_eq!(headers.next(), false); + assert_eq!(headers.current(), None); + + let body = response.body(); + assert_eq!(body.clone().collect::>(), b"1234".to_vec()); + assert_eq!(body.error(), &None); + }) + } + + #[test] + fn should_send_a_post_request() { + let offchain = testing::TestOffchainExt::default(); + let mut t = TestExternalities::default(); + let state = offchain.0.clone(); + t.set_offchain_externalities(offchain); + + with_externalities(&mut t, || { + let pending = Request::default() + .method(Method::Post) + .url("http://localhost:1234") + .body(vec![b"1234"]) + .send() + .unwrap(); + // make sure it's sent correctly + state.write().fulfill_pending_request( + 0, + testing::PendingRequest { + method: "POST".into(), + uri: "http://localhost:1234".into(), + body: b"1234".to_vec(), + sent: true, + ..Default::default() + }, + b"1234".to_vec(), + Some(("Test".to_owned(), "Header".to_owned())), + ); + + // wait + let mut response = pending.wait().unwrap(); + + // then check the response + let mut headers = response.headers().into_iter(); + assert_eq!(headers.current(), None); + assert_eq!(headers.next(), true); + assert_eq!(headers.current(), Some(("Test", "Header"))); + + let body = response.body(); + assert_eq!(body.clone().collect::>(), b"1234".to_vec()); + assert_eq!(body.error(), &None); + }) + } +} diff --git a/node/cli/src/error.rs b/core/sr-io/src/offchain/mod.rs similarity index 63% rename from node/cli/src/error.rs rename to core/sr-io/src/offchain/mod.rs index dd5448ac8ad6366813387e7694a4f69872117ff7..6b82f771119997afd17924dc93e23122a9c5cd79 100644 --- a/node/cli/src/error.rs +++ b/core/sr-io/src/offchain/mod.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2019 Parity Technologies (UK) Ltd. +// Copyright 2019 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify @@ -14,19 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! Initialization errors. +//! A collection of higher lever helpers for offchain workers. -use client; -use error_chain::{ - error_chain, error_chain_processing, impl_error_chain_processed -}; - -error_chain! { - foreign_links { - Io(::std::io::Error) #[doc="IO error"]; - Cli(::clap::Error) #[doc="CLI error"]; - } - links { - Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"]; - } -} +pub mod http; diff --git a/core/sr-io/with_std.rs b/core/sr-io/with_std.rs index d73ccf4b6615c1eaaf05fdb23bb4dfa7109bb1b7..0ba833bd9f6026b49f2445edff41498d187e2e15 100644 --- a/core/sr-io/with_std.rs +++ b/core/sr-io/with_std.rs @@ -28,7 +28,7 @@ pub use substrate_state_machine::{ }; use environmental::environmental; -use primitives::{hexdisplay::HexDisplay, H256}; +use primitives::{offchain, hexdisplay::HexDisplay, H256}; #[cfg(feature = "std")] use std::collections::HashMap; @@ -158,10 +158,10 @@ impl StorageApi for () { }).expect("child_storage_root cannot be called outside of an Externalities-provided environment.") } - fn storage_changes_root(parent_hash: [u8; 32], parent_num: u64) -> Option<[u8; 32]> { + fn storage_changes_root(parent_hash: [u8; 32]) -> Option<[u8; 32]> { ext::with(|ext| - ext.storage_changes_root(parent_hash.into(), parent_num).map(Into::into) - ).unwrap_or(None) + ext.storage_changes_root(parent_hash.into()).map(|h| h.map(|h| h.into())) + ).unwrap_or(Ok(None)).expect("Invalid parent hash passed to storage_changes_root") } fn enumerated_trie_root(input: &[&[u8]]) -> H::Out @@ -251,12 +251,142 @@ impl HashingApi for () { } } +fn with_offchain(f: impl FnOnce(&mut dyn offchain::Externalities) -> R, msg: &'static str) -> R { + ext::with(|ext| ext + .offchain() + .map(|ext| f(ext)) + .expect(msg) + ).expect("offchain-worker functions cannot be called outside of an Externalities-provided environment.") +} + impl OffchainApi for () { - fn submit_extrinsic(data: &T) { - ext::with(|ext| ext - .submit_extrinsic(codec::Encode::encode(data)) - .expect("submit_extrinsic can be called only in offchain worker context") - ).expect("submit_extrinsic cannot be called outside of an Externalities-provided environment.") + fn submit_transaction(data: &T) -> Result<(), ()> { + with_offchain(|ext| { + ext.submit_transaction(codec::Encode::encode(data)) + }, "submit_transaction can be called only in the offchain worker context") + } + + fn new_crypto_key(crypto: offchain::CryptoKind) -> Result { + with_offchain(|ext| { + ext.new_crypto_key(crypto) + }, "new_crypto_key can be called only in the offchain worker context") + } + + fn encrypt(key: Option, data: &[u8]) -> Result, ()> { + with_offchain(|ext| { + ext.encrypt(key, data) + }, "encrypt can be called only in the offchain worker context") + } + + fn decrypt(key: Option, data: &[u8]) -> Result, ()> { + with_offchain(|ext| { + ext.decrypt(key, data) + }, "decrypt can be called only in the offchain worker context") + } + + fn sign(key: Option, data: &[u8]) -> Result, ()> { + with_offchain(|ext| { + ext.sign(key, data) + }, "sign can be called only in the offchain worker context") + } + + fn verify(key: Option, msg: &[u8], signature: &[u8]) -> Result { + with_offchain(|ext| { + ext.verify(key, msg, signature) + }, "verify can be called only in the offchain worker context") + } + + fn timestamp() -> offchain::Timestamp { + with_offchain(|ext| { + ext.timestamp() + }, "timestamp can be called only in the offchain worker context") + } + + fn sleep_until(deadline: Timestamp) { + with_offchain(|ext| { + ext.sleep_until(deadline) + }, "sleep_until can be called only in the offchain worker context") + } + + fn random_seed() -> [u8; 32] { + with_offchain(|ext| { + ext.random_seed() + }, "random_seed can be called only in the offchain worker context") + } + + fn local_storage_set(key: &[u8], value: &[u8]) { + with_offchain(|ext| { + ext.local_storage_set(key, value) + }, "local_storage_set can be called only in the offchain worker context") + } + + fn local_storage_compare_and_set(key: &[u8], old_value: &[u8], new_value: &[u8]) { + with_offchain(|ext| { + ext.local_storage_compare_and_set(key, old_value, new_value) + }, "local_storage_compare_and_set can be called only in the offchain worker context") + } + + fn local_storage_get(key: &[u8]) -> Option> { + with_offchain(|ext| { + ext.local_storage_get(key) + }, "local_storage_get can be called only in the offchain worker context") + } + + fn http_request_start( + method: &str, + uri: &str, + meta: &[u8] + ) -> Result { + with_offchain(|ext| { + ext.http_request_start(method, uri, meta) + }, "http_request_start can be called only in the offchain worker context") + } + + fn http_request_add_header( + request_id: offchain::HttpRequestId, + name: &str, + value: &str + ) -> Result<(), ()> { + with_offchain(|ext| { + ext.http_request_add_header(request_id, name, value) + }, "http_request_add_header can be called only in the offchain worker context") + } + + fn http_request_write_body( + request_id: offchain::HttpRequestId, + chunk: &[u8], + deadline: Option + ) -> Result<(), offchain::HttpError> { + with_offchain(|ext| { + ext.http_request_write_body(request_id, chunk, deadline) + }, "http_request_write_body can be called only in the offchain worker context") + } + + fn http_response_wait( + ids: &[offchain::HttpRequestId], + deadline: Option + ) -> Vec { + with_offchain(|ext| { + ext.http_response_wait(ids, deadline) + }, "http_response_wait can be called only in the offchain worker context") + } + + fn http_response_headers( + request_id: offchain::HttpRequestId + ) -> Vec<(Vec, Vec)> { + with_offchain(|ext| { + ext.http_response_headers(request_id) + }, "http_response_headers can be called only in the offchain worker context") + } + + fn http_response_read_body( + request_id: offchain::HttpRequestId, + buffer: &mut [u8], + deadline: Option + ) -> Result { + with_offchain(|ext| { + ext.http_response_read_body(request_id, buffer, deadline) + }, "http_response_read_body can be called only in the offchain worker context") } } @@ -265,7 +395,7 @@ impl Api for () {} /// Execute the given closure with global function available whose functionality routes into the /// externalities `ext`. Forwards the value that the closure returns. // NOTE: need a concrete hasher here due to limitations of the `environmental!` macro, otherwise a type param would have been fine I think. -pub fn with_externalities R>(ext: &mut Externalities, f: F) -> R { +pub fn with_externalities R>(ext: &mut dyn Externalities, f: F) -> R { ext::using(ext, f) } diff --git a/core/sr-io/without_std.rs b/core/sr-io/without_std.rs index 2f2b482f5e0cdb4f2282603e15e00e4a0a85367b..84e717ffaea08b15212ce989ec2c030f477262a5 100644 --- a/core/sr-io/without_std.rs +++ b/core/sr-io/without_std.rs @@ -19,8 +19,8 @@ pub use rstd; pub use rstd::{mem, slice}; use core::{intrinsics, panic::PanicInfo}; -use rstd::{vec::Vec, cell::Cell}; -use primitives::Blake2Hasher; +use rstd::{vec::Vec, cell::Cell, convert::TryInto}; +use primitives::{offchain, Blake2Hasher}; #[cfg(not(feature = "no_panic_handler"))] #[panic_handler] @@ -219,7 +219,6 @@ pub mod ext { /// # Returns /// /// - `0` if no value exists to the given key. `written_out` is set to `u32::max_value()`. - /// /// - Otherwise, pointer to the value in memory. `written_out` contains the length of the value. fn ext_get_allocated_storage(key_data: *const u8, key_len: u32, written_out: *mut u32) -> *mut u8; /// Gets the value of the given key from storage. @@ -242,7 +241,7 @@ pub mod ext { /// /// - `1` if the change trie root was found. /// - `0` if the change trie root was not found. - fn ext_storage_changes_root(parent_hash_data: *const u8, parent_hash_len: u32, parent_num: u64, result: *mut u8) -> u32; + fn ext_storage_changes_root(parent_hash_data: *const u8, parent_hash_len: u32, result: *mut u8) -> u32; /// A child storage function. /// @@ -331,8 +330,206 @@ pub mod ext { // Offchain-worker Context //================================ - /// Submit extrinsic. - fn ext_submit_extrinsic(data: *const u8, len: u32); + /// Submit transaction. + /// + /// # Returns + /// + /// - 0 if it was successfuly added to the pool + /// - nonzero otherwise. + fn ext_submit_transaction(data: *const u8, len: u32) -> u32; + + /// Create new key(pair) for signing/encryption/decryption. + /// + /// # Returns + /// + /// - A crypto key id (if the value is less than u16::max_value) + /// - `u32::max_value` in case the crypto is not supported + fn ext_new_crypto_key(crypto: u32) -> u32; + + /// Encrypt a piece of data using given crypto key. + /// + /// If `key` is `0`, it will attempt to use current authority key. + /// + /// # Returns + /// + /// - `0` in case the key is invalid, `msg_len` is set to `u32::max_value` + /// - Otherwise, pointer to the encrypted message in memory, + /// `msg_len` contains the length of the message. + fn ext_encrypt(key: u32, data: *const u8, data_len: u32, msg_len: *mut u32) -> *mut u8; + + /// Decrypt a piece of data using given crypto key. + /// + /// If `key `is `0`, it will attempt to use current authority key. + /// + /// # Returns + /// + /// - `0` in case the key is invalid or data couldn't be decrypted, + /// `msg_len` is set to `u32::max_value` + /// - Otherwise, pointer to the decrypted message in memory, + /// `msg_len` contains the length of the message. + fn ext_decrypt(key: u32, data: *const u8, data_len: u32, msg_len: *mut u32) -> *mut u8; + + /// Sign a piece of data using given crypto key. + /// + /// If `key` is `0`, it will attempt to use current authority key. + /// + /// # Returns + /// + /// - `0` in case the key is invalid, + /// `sig_data_len` is set to `u32::max_value` + /// - Otherwise, pointer to the signature in memory, + /// `sig_data_len` contains the length of the signature. + fn ext_sign(key: u32, data: *const u8, data_len: u32, sig_data_len: *mut u32) -> *mut u8; + + /// Verifies that `signature` for `msg` matches given `key`. + /// + /// If `key` is `0`, it will attempt to use current authority key. + /// + /// # Returns + /// - `0` in case the signature is correct + /// - `1` in case it doesn't match the key + /// - `u32::max_value` if the key is invalid. + fn ext_verify( + key: u32, + msg: *const u8, + msg_len: u32, + signature: *const u8, + signature_len: u32 + ) -> u32; + + /// Returns current UNIX timestamp (milliseconds) + fn ext_timestamp() -> u64; + + /// Pause execution until given timestamp (milliseconds; `deadline`) is reached. + /// + /// The deadline is obtained by querying the current timestamp via `ext_timestamp` + /// and then adding some time to it. + fn ext_sleep_until(deadline: u64); + + /// Generate a random seed + /// + /// `data` has to be a pointer to a slice of 32 bytes. + fn ext_random_seed(data: *mut u8); + + /// Write a value to local storage. + fn ext_local_storage_set(key: *const u8, key_len: u32, value: *const u8, value_len: u32); + + /// Write a value to local storage in atomic fashion. + fn ext_local_storage_compare_and_set( + key: *const u8, + key_len: u32, + old_value: *const u8, + old_value_len: u32, + new_value: *const u8, + new_value_len: u32 + ); + + /// Read a value from local storage. + /// + /// + /// # Returns + /// + /// - 0 if the value has not been found, the `value_len` is set to `u32::max_value`. + /// - Otherwise, pointer to the value in memory. `value_len` contains the length of the value. + fn ext_local_storage_get(key: *const u8, key_len: u32, value_len: *mut u32) -> *mut u8; + + /// Initiaties a http request. + /// + /// `meta` is parity-codec encoded additional parameters to the request (like redirection policy, + /// timeouts, certificates policy, etc). The format is not yet specified and the field is currently + /// only reserved for future use. + /// + /// # Returns + /// + /// `RequestId(u16)` of initiated request, any value beyond `u16::max_value` + /// signifies an error. + fn ext_http_request_start( + method: *const u8, + method_len: u32, + url: *const u8, + url_len: u32, + meta: *const u8, + meta_len: u32 + ) -> u32; + + /// Add a header to the request. + /// + /// # Returns + /// + /// - `0` if successful (and the request id exists) + /// - nonzero otherwise + fn ext_http_request_add_header( + request_id: u32, + name: *const u8, + name_len: u32, + value: *const u8, + value_len: u32 + ) -> u32; + + /// Write a chunk of request body. + /// + /// Writing an empty chunks finalises the request. + /// Passing `0` as deadline blocks forever. + /// + /// # Returns + /// + /// - `0` if successful, + /// - nonzero otherwise (see HttpError for the codes) + fn ext_http_request_write_body( + request_id: u32, + chunk: *const u8, + chunk_len: u32, + deadline: u64 + ) -> u32; + + /// Block and wait for the responses for given requests. + /// + /// Note that if deadline is 0 the method will block indefinitely, + /// otherwise unready responses will produce `DeadlineReached` status. + /// (see #primitives::offchain::HttpRequestStatus) + /// + /// Make sure that `statuses` have the same length as ids. + fn ext_http_response_wait( + ids: *const u32, + ids_len: u32, + statuses: *mut u32, + deadline: u64 + ); + + /// Read all response headers. + /// + /// Note the headers are only available before response body is fully consumed. + /// + /// # Returns + /// + /// - A pointer to parity-codec encoded vector of pairs `(HeaderKey, HeaderValue)`. + /// - In case invalid `id` is passed it returns a pointer to parity-encoded empty vector. + fn ext_http_response_headers( + id: u32, + written_out: *mut u32 + ) -> *mut u8; + + /// Read a chunk of body response to given buffer. + /// + /// Passing `0` as deadline blocks forever. + /// + /// # Returns + /// + /// The number of bytes written if successful, + /// - if it's `0` it means response has been fully consumed, + /// - if it's greater than `u32::max_value() - 255` it means reading body failed. + /// + /// In case of failure, the error code should be mapped to `HttpError` + /// in a following manner: + /// - `u32::max_value()` HttpError code 1 (DeadlineReached) + /// - `u32::max_value() - 1` HttpError code 2 (IoError) + /// The rest is reserved for potential future errors. + fn ext_http_response_read_body( + id: u32, + buffer: *mut u8, + buffer_len: u32, + deadline: u64 + ) -> u32; } } @@ -343,14 +540,7 @@ impl StorageApi for () { let mut length: u32 = 0; unsafe { let ptr = ext_get_allocated_storage.get()(key.as_ptr(), key.len() as u32, &mut length); - if length == u32::max_value() { - None - } else { - // Invariants required by Vec::from_raw_parts are not formally fulfilled. - // We don't allocate via String/Vec, but use a custom allocator instead. - // See #300 for more details. - Some(>::from_raw_parts(ptr, length as usize, length as usize)) - } + from_raw_parts(ptr, length) } } @@ -364,14 +554,7 @@ impl StorageApi for () { key.len() as u32, &mut length ); - if length == u32::max_value() { - None - } else { - // Invariants required by Vec::from_raw_parts are not formally fulfilled. - // We don't allocate via String/Vec, but use a custom allocator instead. - // See #300 for more details. - Some(>::from_raw_parts(ptr, length as usize, length as usize)) - } + from_raw_parts(ptr, length) } } @@ -491,17 +674,14 @@ impl StorageApi for () { storage_key.len() as u32, &mut length ); - // Invariants required by Vec::from_raw_parts are not formally fulfilled. - // We don't allocate via String/Vec, but use a custom allocator instead. - // See #300 for more details. - >::from_raw_parts(ptr, length as usize, length as usize) + from_raw_parts(ptr, length).expect("ext_child_storage_root never returns u32::max_value; qed") } } - fn storage_changes_root(parent_hash: [u8; 32], parent_num: u64) -> Option<[u8; 32]> { + fn storage_changes_root(parent_hash: [u8; 32]) -> Option<[u8; 32]> { let mut result: [u8; 32] = Default::default(); let is_set = unsafe { - ext_storage_changes_root.get()(parent_hash.as_ptr(), parent_hash.len() as u32, parent_num, result.as_mut_ptr()) + ext_storage_changes_root.get()(parent_hash.as_ptr(), parent_hash.len() as u32, result.as_mut_ptr()) }; if is_set != 0 { @@ -624,12 +804,273 @@ impl CryptoApi for () { } impl OffchainApi for () { - fn submit_extrinsic(data: &T) { + fn submit_transaction(data: &T) -> Result<(), ()> { let encoded_data = codec::Encode::encode(data); + let ret = unsafe { + ext_submit_transaction.get()(encoded_data.as_ptr(), encoded_data.len() as u32) + }; + + if ret == 0 { + Ok(()) + } else { + Err(()) + } + } + + fn new_crypto_key(crypto: offchain::CryptoKind) -> Result { + let crypto = crypto as u8 as u32; + let ret = unsafe { + ext_new_crypto_key.get()(crypto) + }; + + if ret > u16::max_value() as u32 { + Err(()) + } else { + Ok(offchain::CryptoKeyId(ret as u16)) + } + } + + fn encrypt(key: Option, data: &[u8]) -> Result, ()> { + let key = key.map(|x| x.0 as u32).unwrap_or(0); + let mut len = 0_u32; + unsafe { + let ptr = ext_encrypt.get()(key, data.as_ptr(), data.len() as u32, &mut len); + + from_raw_parts(ptr, len).ok_or(()) + } + } + + fn decrypt(key: Option, data: &[u8]) -> Result, ()> { + let key = key.map(|x| x.0 as u32).unwrap_or(0); + let mut len = 0_u32; + unsafe { + let ptr = ext_decrypt.get()(key, data.as_ptr(), data.len() as u32, &mut len); + + from_raw_parts(ptr, len).ok_or(()) + } + } + + fn sign(key: Option, data: &[u8]) -> Result, ()> { + let key = key.map(|x| x.0 as u32).unwrap_or(0); + let mut len = 0_u32; + unsafe { + let ptr = ext_sign.get()(key, data.as_ptr(), data.len() as u32, &mut len); + + from_raw_parts(ptr, len).ok_or(()) + } + } + + fn verify(key: Option, msg: &[u8], signature: &[u8]) -> Result { + let key = key.map(|x| x.0 as u32).unwrap_or(0); + let val = unsafe { + ext_verify.get()( + key, + msg.as_ptr(), + msg.len() as u32, + signature.as_ptr(), + signature.len() as u32, + ) + }; + + match val { + 0 => Ok(true), + 1 => Ok(false), + _ => Err(()), + } + } + + fn timestamp() -> offchain::Timestamp { + offchain::Timestamp::from_unix_millis(unsafe { + ext_timestamp.get()() + }) + } + + fn sleep_until(deadline: Timestamp) { + unsafe { + ext_sleep_until.get()(deadline.unix_millis()) + } + } + + fn random_seed() -> [u8; 32] { + let mut result = [0_u8; 32]; + unsafe { + ext_random_seed.get()(result.as_mut_ptr()) + } + result + } + + fn local_storage_set(key: &[u8], value: &[u8]) { + unsafe { + ext_local_storage_set.get()( + key.as_ptr(), + key.len() as u32, + value.as_ptr(), + value.len() as u32, + ) + } + } + + fn local_storage_compare_and_set(key: &[u8], old_value: &[u8], new_value: &[u8]) { unsafe { - ext_submit_extrinsic.get()(encoded_data.as_ptr(), encoded_data.len() as u32) + ext_local_storage_compare_and_set.get()( + key.as_ptr(), + key.len() as u32, + old_value.as_ptr(), + old_value.len() as u32, + new_value.as_ptr(), + new_value.len() as u32, + ) } } + + fn local_storage_get(key: &[u8]) -> Option> { + let mut len = 0u32; + unsafe { + let ptr = ext_local_storage_get.get()( + key.as_ptr(), + key.len() as u32, + &mut len, + ); + + from_raw_parts(ptr, len) + } + } + + fn http_request_start(method: &str, url: &str, meta: &[u8]) -> Result { + let method = method.as_bytes(); + let url = url.as_bytes(); + + let result = unsafe { + ext_http_request_start.get()( + method.as_ptr(), + method.len() as u32, + url.as_ptr(), + url.len() as u32, + meta.as_ptr(), + meta.len() as u32, + ) + }; + + if result > u16::max_value() as u32 { + Err(()) + } else { + Ok(offchain::HttpRequestId(result as u16)) + } + } + + fn http_request_add_header(request_id: offchain::HttpRequestId, name: &str, value: &str) -> Result<(), ()> { + let name = name.as_bytes(); + let value = value.as_bytes(); + + let result = unsafe { + ext_http_request_add_header.get()( + request_id.0 as u32, + name.as_ptr(), + name.len() as u32, + value.as_ptr(), + value.len() as u32, + ) + }; + + if result == 0 { + Ok(()) + } else { + Err(()) + } + } + + fn http_request_write_body( + request_id: offchain::HttpRequestId, + chunk: &[u8], + deadline: Option + ) -> Result<(), offchain::HttpError> { + let res = unsafe { + ext_http_request_write_body.get()( + request_id.0 as u32, + chunk.as_ptr(), + chunk.len() as u32, + deadline.map_or(0, |x| x.unix_millis()), + ) + }; + + if res == 0 { + Ok(()) + } else { + Err(res.try_into().unwrap_or(offchain::HttpError::IoError)) + } + } + + fn http_response_wait( + ids: &[offchain::HttpRequestId], + deadline: Option + ) -> Vec { + let ids = ids.iter().map(|x| x.0 as u32).collect::>(); + let mut statuses = Vec::new(); + statuses.resize(ids.len(), 0u32); + + unsafe { + ext_http_response_wait.get()( + ids.as_ptr(), + ids.len() as u32, + statuses.as_mut_ptr(), + deadline.map_or(0, |x| x.unix_millis()), + ) + } + + statuses + .into_iter() + .map(|status| status.try_into().unwrap_or(offchain::HttpRequestStatus::Unknown)) + .collect() + } + + fn http_response_headers( + request_id: offchain::HttpRequestId, + ) -> Vec<(Vec, Vec)> { + let mut len = 0u32; + let raw_result = unsafe { + let ptr = ext_http_response_headers.get()( + request_id.0 as u32, + &mut len, + ); + + from_raw_parts(ptr, len).expect("ext_http_response_headers never return u32::max_value; qed") + }; + + codec::Decode::decode(&mut &*raw_result).unwrap_or_default() + } + + fn http_response_read_body( + request_id: offchain::HttpRequestId, + buffer: &mut [u8], + deadline: Option, + ) -> Result { + let res = unsafe { + ext_http_response_read_body.get()( + request_id.0 as u32, + buffer.as_mut_ptr(), + buffer.len() as u32, + deadline.map_or(0, |x| x.unix_millis()), + ) + }; + + if res >= u32::max_value() - 255 { + let code = (u32::max_value() - res) + 1; + code.try_into().map_err(|_| offchain::HttpError::IoError) + } else { + Ok(res as usize) + } + } +} + +unsafe fn from_raw_parts(ptr: *mut u8, len: u32) -> Option> { + if len == u32::max_value() { + None + } else { + // Invariants required by Vec::from_raw_parts are not formally fulfilled. + // We don't allocate via String/Vec, but use a custom allocator instead. + // See #300 for more details. + Some(>::from_raw_parts(ptr, len as usize, len as usize)) + } } impl Api for () {} diff --git a/core/sr-primitives/src/generic/digest.rs b/core/sr-primitives/src/generic/digest.rs index 265ceb5941a3d71ae30278dff781c467ebabb542..c0724bb134e7a2f50f4540050a11afc7972f0d04 100644 --- a/core/sr-primitives/src/generic/digest.rs +++ b/core/sr-primitives/src/generic/digest.rs @@ -58,29 +58,151 @@ impl traits::Digest for Digest where } } -/// Digest item that is able to encode/decode 'system' digest items and -/// provide opaque access to other items. -#[derive(PartialEq, Eq, Clone)] -#[cfg_attr(feature = "std", derive(Debug))] -#[allow(deprecated)] -pub enum DigestItem { - /// System digest item announcing that authorities set has been changed - /// in the block. Contains the new set of authorities. - AuthoritiesChange(Vec), - /// System digest item that contains the root of changes trie at given - /// block. It is created for every block iff runtime supports changes - /// trie creation. - ChangesTrieRoot(Hash), - /// The old way to put a Seal on it. Deprecated. - #[deprecated( - since = "1.0", - note = "New versions of Substrate will never generate this, and it will be rejected on new blockchains.", - )] - Seal(u64, SealSignature), - /// Put a Seal on it - Consensus(ConsensusEngineId, Vec), - /// Any 'non-system' digest item, opaque to the native code. - Other(Vec), +// Macro black magic. +macro_rules! gen_digest_type { + ( + $( #[doc = $main_docs:tt] )* + pub enum $main:ident $(<$($main_params: tt),+>)? { } + $( + $( #[doc = $doc_attr:tt] )* + pub enum $n:ident $(<$($t: tt),+>)? { + $( + $( #[doc = $variant_doc:tt] )* + $variant:ident(($($interior: ty),*), $q: tt), + )* + } + )+ + ) => { + $( #[doc = $main_docs] )* + #[derive(PartialEq, Eq, Clone)] + #[cfg_attr(feature = "std", derive(Debug))] + pub enum $main $(<$($main_params),+>)? { + $( + $( + $( #[doc = $variant_doc] )* + $variant($($interior),*), + )* + )* + } + + gen_digest_type! { + @internal + $main : $main $(<$($main_params),+>)? => $( + $( #[doc = $doc_attr] )* + pub enum $n $(<$($t),+>)? { + $( + $( #[doc = $variant_doc] )* + $variant(($($interior),*), $q), + )* + } + )+ + } + }; + ( + @internal + $main_id:tt : $main:ty => $( + $( #[doc = $doc_attr:tt] )* + pub enum $n:ident $(<$($t: tt),+>)? { + $( + $( #[doc = $variant_doc:tt] )* + $variant:ident(($($interior: ty),*), $q: tt), + )* + } + )+ + ) => { + $( + $( #[doc = $doc_attr] )* + #[derive(PartialEq, Eq, Clone)] + #[cfg_attr(feature = "std", derive(Debug))] + pub enum $n $(<$($t),+>)? { + $( + $( #[doc = $variant_doc] )* + $variant($($interior),*), + )* + } + + impl From<$n $(<$($t),*>)?> + for $main { + fn from(digest: $n $(<$($t),+>)?) -> Self { + match digest { + $( + $n::$variant $q => $main_id::$variant $q, + )* + } + } + } + )* + }; +} + +gen_digest_type! { + /// Digest item that is able to encode/decode 'system' digest items and + /// provide opaque access to other items. + /// + /// For all variants that include a `ConsensusEngineId`, consensus engine + /// implementations **MUST** ignore digests that have a `ConsensusEngineId` + /// that is not theirs. Node implementations **MUST** reject digests that + /// have a `ConsensusEngineId` that corresponds to a consensus engine not in + /// use. Node implementations **MUST** reject blocks as malformed if they + /// reject any of the block’s digest. If the runtime supports this, the + /// node that issued the block **SHOULD** be reported as having committed + /// severe misbehavior and punished accordingly. The invalid block, or its + /// hash, **SHOULD** constitute adequate proof of such misbehavior. + pub enum DigestItem {} + + /// A digest item that can be produced by consensus engines. Consensus + /// engine implementations **MUST NOT** push digests not in this variant. + /// This **SHOULD** be detected at compile time. If it is not, the behavior + /// of the blockchain is undefined. + pub enum ConsensusDigest { + /// Put a Seal on it. This **MUST** come after all other `DigestItem` + /// variants. There **MUST** be exactly one `Seal` per consensus engine, + /// and its `ConsensusEngineId` **MUST** be that of the consensus engine + /// that produced it. Runtimes will not see this variant. + Seal((ConsensusEngineId, SealSignature), (a, b)), + /// An inherent digest. + /// + /// These are messages from the consensus engine to the runtime, + /// although the consensus engine can (and should) read them itself to + /// avoid code and state duplication. It is erroneous for a runtime to + /// produce these, but this is checked at compile time. Runtimes can + /// (and should) trust these, as with any other inherent. Consensus + /// engines MUST verify them. + PreRuntime((ConsensusEngineId, Vec), (a, b)), + } + + /// A digest item that can be produced by runtimes. Runtime mplementations + /// **MUST NOT** push digests not in this variant. This **SHOULD** be + /// detected at compile time. If it is not, the behavior of the blockchain + /// is undefined. + pub enum RuntimeDigest { + /// A message from the runtime to the consensus engine. This MUST NOT be + /// generated by the native code of any consensus engine, but this is + /// caught at compile time. The `ConsensusEngineId` is that of the + /// consensus engine for which this digest is intended. Consensus + /// engines MUST ignore digests with `ConsensusEngineId`s other than + /// their own. + Consensus((ConsensusEngineId, Vec), (a, b)), + /// Any 'non-system' digest item, opaque to the native code. Runtimes + /// MUST verify these, and reject any they did not produce. These MUST + /// NOT be produced by native code. + Other((Vec), (a)), + } + + /// A digest item that is reserved for the SRML. Only the SRML is allowed to + /// push these digests. Consensus engines and third-party runtime code + /// **MUST NOT** push digests in this variant. This **SHOULD** be detected + /// at compile time. If it is not, the behavior of the blockchain is + /// undefined. + pub enum SystemDigest { + /// System digest item announcing that authorities set has been changed + /// in the block. Contains the new set of authorities. + AuthoritiesChange((Vec), (a)), + /// System digest item that contains the root of changes trie at given + /// block. It is created for every block iff runtime supports changes + /// trie creation. + ChangesTrieRoot((Hash), (a)), + } } #[cfg(feature = "std")] @@ -97,20 +219,27 @@ impl ::serde::Serializ /// final runtime implementations for encoding/decoding its log items. #[derive(PartialEq, Eq, Clone)] #[cfg_attr(feature = "std", derive(Debug))] -#[allow(deprecated)] pub enum DigestItemRef<'a, Hash: 'a, AuthorityId: 'a, SealSignature: 'a> { /// Reference to `DigestItem::AuthoritiesChange`. AuthoritiesChange(&'a [AuthorityId]), /// Reference to `DigestItem::ChangesTrieRoot`. ChangesTrieRoot(&'a Hash), - /// A deprecated sealed signature for testing - #[deprecated] - Seal(&'a u64, &'a SealSignature), - /// A sealed signature for testing - Consensus(&'a ConsensusEngineId, &'a [u8]), + /// A message from the runtime to the consensus engine. This should *never* + /// be generated by the native code of any consensus engine, but this is not + /// checked (yet). + Consensus(&'a ConsensusEngineId, &'a Vec), + /// Put a Seal on it. This is only used by native code, and is never seen + /// by runtimes. + Seal(&'a ConsensusEngineId, &'a SealSignature), + /// A pre-runtime digest. + /// + /// These are messages from the consensus engine to the runtime, although + /// the consensus engine can (and should) read them itself to avoid + /// code and state duplication. It is erroneous for a runtime to produce + /// these, but this is not (yet) checked. + PreRuntime(&'a ConsensusEngineId, &'a Vec), /// Any 'non-system' digest item, opaque to the native code. - /// Reference to `DigestItem::Other`. - Other(&'a [u8]), + Other(&'a Vec), } /// Type of the digest item. Used to gain explicit control over `DigestItem` encoding @@ -123,8 +252,9 @@ enum DigestItemType { Other = 0, AuthoritiesChange = 1, ChangesTrieRoot = 2, - Seal = 3, Consensus = 4, + Seal = 5, + PreRuntime = 6, } impl DigestItem { @@ -137,13 +267,13 @@ impl DigestItem(&'a self) -> DigestItemRef<'a, Hash, AuthorityId, SealSignature> { match *self { DigestItem::AuthoritiesChange(ref v) => DigestItemRef::AuthoritiesChange(v), DigestItem::ChangesTrieRoot(ref v) => DigestItemRef::ChangesTrieRoot(v), - DigestItem::Seal(ref v, ref s) => DigestItemRef::Seal(v, s), DigestItem::Consensus(ref v, ref s) => DigestItemRef::Consensus(v, s), + DigestItem::Seal(ref v, ref s) => DigestItemRef::Seal(v, s), + DigestItem::PreRuntime(ref v, ref s) => DigestItemRef::PreRuntime(v, s), DigestItem::Other(ref v) => DigestItemRef::Other(v), } } @@ -164,6 +294,10 @@ impl< fn as_changes_trie_root(&self) -> Option<&Self::Hash> { self.dref().as_changes_trie_root() } + + fn as_pre_runtime(&self) -> Option<(ConsensusEngineId, &[u8])> { + self.dref().as_pre_runtime() + } } impl Encode for DigestItem { @@ -183,14 +317,18 @@ impl Decode for Digest DigestItemType::ChangesTrieRoot => Some(DigestItem::ChangesTrieRoot( Decode::decode(input)?, )), - DigestItemType::Seal => { - let vals: (u64, SealSignature) = Decode::decode(input)?; - Some(DigestItem::Seal(vals.0, vals.1)) - }, DigestItemType::Consensus => { let vals: (ConsensusEngineId, Vec) = Decode::decode(input)?; Some(DigestItem::Consensus(vals.0, vals.1)) } + DigestItemType::Seal => { + let vals: (ConsensusEngineId, SealSignature) = Decode::decode(input)?; + Some(DigestItem::Seal(vals.0, vals.1)) + }, + DigestItemType::PreRuntime => { + let vals: (ConsensusEngineId, Vec) = Decode::decode(input)?; + Some(DigestItem::PreRuntime(vals.0, vals.1)) + }, DigestItemType::Other => Some(DigestItem::Other( Decode::decode(input)?, )), @@ -214,9 +352,16 @@ impl<'a, Hash: Codec + Member, AuthorityId: Codec + Member, SealSignature: Codec _ => None, } } + + /// Cast this digest item into `PreRuntime` + pub fn as_pre_runtime(&self) -> Option<(ConsensusEngineId, &'a [u8])> { + match *self { + DigestItemRef::PreRuntime(consensus_engine_id, ref data) => Some((*consensus_engine_id, data)), + _ => None, + } + } } -#[allow(deprecated)] impl<'a, Hash: Encode, AuthorityId: Encode, SealSignature: Encode> Encode for DigestItemRef<'a, Hash, AuthorityId, SealSignature> { fn encode(&self) -> Vec { let mut v = Vec::new(); @@ -230,13 +375,17 @@ impl<'a, Hash: Encode, AuthorityId: Encode, SealSignature: Encode> Encode for Di DigestItemType::ChangesTrieRoot.encode_to(&mut v); changes_trie_root.encode_to(&mut v); }, + DigestItemRef::Consensus(val, data) => { + DigestItemType::Consensus.encode_to(&mut v); + (val, data).encode_to(&mut v); + }, DigestItemRef::Seal(val, sig) => { DigestItemType::Seal.encode_to(&mut v); (val, sig).encode_to(&mut v); }, - DigestItemRef::Consensus(val, sig) => { - DigestItemType::Consensus.encode_to(&mut v); - (val, sig).encode_to(&mut v); + DigestItemRef::PreRuntime(val, data) => { + DigestItemType::PreRuntime.encode_to(&mut v); + (val, data).encode_to(&mut v); }, DigestItemRef::Other(val) => { DigestItemType::Other.encode_to(&mut v); @@ -254,20 +403,19 @@ mod tests { use substrate_primitives::hash::H512 as Signature; #[test] - #[allow(deprecated)] fn should_serialize_digest() { let digest = Digest { logs: vec![ DigestItem::AuthoritiesChange(vec![1]), DigestItem::ChangesTrieRoot(4), - DigestItem::Seal(1, Signature::from_low_u64_be(15)), DigestItem::Other(vec![1, 2, 3]), + DigestItem::Seal(Default::default(), Signature::default()) ], }; assert_eq!( ::serde_json::to_string(&digest).unwrap(), - r#"{"logs":["0x010401000000","0x0204000000","0x0301000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f","0x000c010203"]}"# + "{\"logs\":[\"0x010401000000\",\"0x0204000000\",\"0x000c010203\",\"0x050000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\"]}", ); } } diff --git a/core/sr-primitives/src/generic/era.rs b/core/sr-primitives/src/generic/era.rs index 22f47b6769df403549da754d50c115065b892367..c41d3eedfc24ecb7c64906ce67778618e87faad8 100644 --- a/core/sr-primitives/src/generic/era.rs +++ b/core/sr-primitives/src/generic/era.rs @@ -21,7 +21,10 @@ use serde::{Serialize, Deserialize}; use crate::codec::{Decode, Encode, Input, Output}; +/// Era period pub type Period = u64; + +/// Era phase pub type Phase = u64; /// An era to describe the longevity of a transaction. diff --git a/core/sr-primitives/src/generic/header.rs b/core/sr-primitives/src/generic/header.rs index efcc7614ed7c8e725f57796691b2ba3bf5c5ed4a..fa94d97c64c4cd25562955ef3d8444d0482c4bb9 100644 --- a/core/sr-primitives/src/generic/header.rs +++ b/core/sr-primitives/src/generic/header.rs @@ -18,9 +18,12 @@ #[cfg(feature = "std")] use serde::Serialize; +#[cfg(feature = "std")] +use log::debug; use crate::codec::{Decode, Encode, Codec, Input, Output, HasCompact, EncodeAsRef}; use crate::traits::{self, Member, SimpleArithmetic, SimpleBitOps, MaybeDisplay, - Hash as HashT, DigestItem as DigestItemT, MaybeSerializeDebug, MaybeSerializeDebugButNotDeserialize}; + Hash as HashT, DigestItem as DigestItemT, MaybeSerializeDebug, + MaybeSerializeDebugButNotDeserialize}; use crate::generic::Digest; /// Abstraction over a block header for a substrate chain. @@ -107,22 +110,29 @@ impl traits::Header for Header &Self::Digest { &self.digest } + + #[cfg(feature = "std")] + fn digest_mut(&mut self) -> &mut Self::Digest { + debug!(target: "header", "Retrieving mutable reference to digest"); + &mut self.digest + } + + #[cfg(not(feature = "std"))] fn digest_mut(&mut self) -> &mut Self::Digest { &mut self.digest } - fn set_digest(&mut self, digest: Self::Digest) { self.digest = digest } fn new( number: Self::Number, extrinsics_root: Self::Hash, state_root: Self::Hash, parent_hash: Self::Hash, - digest: Self::Digest + digest: Self::Digest, ) -> Self { Header { number, extrinsics_root, state_root, parent_hash, - digest + digest, } } } diff --git a/core/sr-primitives/src/generic/mod.rs b/core/sr-primitives/src/generic/mod.rs index b0f86f959fe6285b037826dd7e27da1d50ee8adb..d9c53c5fd4b27f344920e7a42baa5578256a30e4 100644 --- a/core/sr-primitives/src/generic/mod.rs +++ b/core/sr-primitives/src/generic/mod.rs @@ -32,11 +32,13 @@ mod tests; pub use self::unchecked_extrinsic::UncheckedExtrinsic; pub use self::unchecked_mortal_extrinsic::UncheckedMortalExtrinsic; pub use self::unchecked_mortal_compact_extrinsic::UncheckedMortalCompactExtrinsic; -pub use self::era::Era; +pub use self::era::{Era, Phase}; pub use self::checked_extrinsic::CheckedExtrinsic; pub use self::header::Header; pub use self::block::{Block, SignedBlock, BlockId}; -pub use self::digest::{Digest, DigestItem, DigestItemRef}; +pub use self::digest::{ + Digest, DigestItem, DigestItemRef, ConsensusDigest, RuntimeDigest, SystemDigest, +}; use crate::codec::Encode; use rstd::prelude::*; @@ -44,8 +46,8 @@ use rstd::prelude::*; fn encode_with_vec_prefix)>(encoder: F) -> Vec { let size = ::rstd::mem::size_of::(); let reserve = match size { - 0...0b00111111 => 1, - 0...0b00111111_11111111 => 2, + 0..=0b00111111 => 1, + 0..=0b00111111_11111111 => 2, _ => 4, }; let mut v = Vec::with_capacity(reserve + size); diff --git a/core/sr-primitives/src/generic/unchecked_mortal_compact_extrinsic.rs b/core/sr-primitives/src/generic/unchecked_mortal_compact_extrinsic.rs index ea9dad2a5023b5f09eb4b2cfe5a99d39848a61e6..36e17fc277cdeed0ef742cb1da20e3203263739e 100644 --- a/core/sr-primitives/src/generic/unchecked_mortal_compact_extrinsic.rs +++ b/core/sr-primitives/src/generic/unchecked_mortal_compact_extrinsic.rs @@ -22,8 +22,8 @@ use std::fmt; use rstd::prelude::*; use runtime_io::blake2_256; use crate::codec::{Decode, Encode, Input, Compact}; -use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, Lookup, - Checkable, Extrinsic}; +use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, + Lookup, Checkable, Extrinsic, SaturatedConversion}; use super::{CheckedExtrinsic, Era}; const TRANSACTION_VERSION: u8 = 1; @@ -84,7 +84,8 @@ where fn check(self, context: &Context) -> Result { Ok(match self.signature { Some((signed, signature, index, era)) => { - let h = context.block_number_to_hash(BlockNumber::sa(era.birth(context.current_height().as_()))) + let current_u64 = context.current_height().saturated_into::(); + let h = context.block_number_to_hash(era.birth(current_u64).saturated_into()) .ok_or("transaction birth block ancient")?; let signed = context.lookup(signed)?; let raw_payload = (index, self.function, era, h); diff --git a/core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs b/core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs index a91f4461fffa2796942524e4087c45ceec06b161..7f92b20edd0c3143e3b35d1dc47327d9f575ec62 100644 --- a/core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs +++ b/core/sr-primitives/src/generic/unchecked_mortal_extrinsic.rs @@ -22,8 +22,10 @@ use std::fmt; use rstd::prelude::*; use runtime_io::blake2_256; use crate::codec::{Decode, Encode, Input}; -use crate::traits::{self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, Lookup, - Checkable, Extrinsic}; +use crate::traits::{ + self, Member, SimpleArithmetic, MaybeDisplay, CurrentHeight, BlockNumberToHash, + Lookup, Checkable, Extrinsic, SaturatedConversion +}; use super::{CheckedExtrinsic, Era}; const TRANSACTION_VERSION: u8 = 1; @@ -83,7 +85,8 @@ where fn check(self, context: &Context) -> Result { Ok(match self.signature { Some((signed, signature, index, era)) => { - let h = context.block_number_to_hash(BlockNumber::sa(era.birth(context.current_height().as_()))) + let current_u64 = context.current_height().saturated_into::(); + let h = context.block_number_to_hash(era.birth(current_u64).saturated_into()) .ok_or("transaction birth block ancient")?; let signed = context.lookup(signed)?; let raw_payload = (index, self.function, era, h); diff --git a/core/sr-primitives/src/lib.rs b/core/sr-primitives/src/lib.rs index 65a4f3d8229dc2e5e8f551cfb50fd88d98d16d26..55e03e47f3168b71b70d82fb7b9b8f3a33464ee4 100644 --- a/core/sr-primitives/src/lib.rs +++ b/core/sr-primitives/src/lib.rs @@ -25,12 +25,13 @@ pub use parity_codec as codec; #[cfg(feature = "std")] #[doc(hidden)] pub use serde; +#[doc(hidden)] +pub use rstd; #[cfg(feature = "std")] pub use runtime_io::{StorageOverlay, ChildrenStorageOverlay}; -use rstd::prelude::*; -use rstd::ops; +use rstd::{prelude::*, ops}; use substrate_primitives::{crypto, ed25519, sr25519, hash::{H256, H512}}; use codec::{Encode, Decode}; @@ -38,6 +39,8 @@ use codec::{Encode, Decode}; pub mod testing; pub mod traits; +use traits::{SaturatedConversion, UniqueSaturatedInto}; + pub mod generic; pub mod transaction_validity; @@ -102,12 +105,32 @@ impl BuildStorage for StorageOverlay { fn build_storage(self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String> { Ok((self, Default::default())) } - fn assimilate_storage(self, storage: &mut StorageOverlay, _child_storage: &mut ChildrenStorageOverlay) -> Result<(), String> { + fn assimilate_storage( + self, + storage: &mut StorageOverlay, + _child_storage: &mut ChildrenStorageOverlay + ) -> Result<(), String> { storage.extend(self); Ok(()) } } +#[cfg(feature = "std")] +impl BuildStorage for (StorageOverlay, ChildrenStorageOverlay) { + fn build_storage(self) -> Result<(StorageOverlay, ChildrenStorageOverlay), String> { + Ok(self) + } + fn assimilate_storage( + self, + storage: &mut StorageOverlay, + child_storage: &mut ChildrenStorageOverlay + )-> Result<(), String> { + storage.extend(self.0); + child_storage.extend(self.1); + Ok(()) + } +} + /// Consensus engine unique ID. pub type ConsensusEngineId = [u8; 4]; @@ -139,27 +162,30 @@ impl Permill { impl ops::Mul for Permill where - N: Clone + traits::As + ops::Rem + ops::Div - + ops::Mul + ops::Add, + N: Clone + From + UniqueSaturatedInto + ops::Rem + + ops::Div + ops::Mul + ops::Add, { type Output = N; fn mul(self, b: N) -> Self::Output { - let million = >::sa(1_000_000); - let part = >::sa(self.0 as u64); + let million: N = 1_000_000.into(); + let part: N = self.0.into(); let rem_multiplied_divided = { let rem = b.clone().rem(million.clone()); - // `rem` is inferior to one million, thus it fits into u64 - let rem_u64: u64 = rem.as_(); + // `rem` is inferior to one million, thus it fits into u32 + let rem_u32 = rem.saturated_into::(); - // `self` and `rem` are inferior to one million, thus the product fits into u64 - let rem_multiplied_u64 = rem_u64 * self.0 as u64; + // `self` and `rem` are inferior to one million, thus the product is less than 10^12 + // and fits into u64 + let rem_multiplied_u64 = rem_u32 as u64 * self.0 as u64; - let rem_multiplied_divided_u64 = rem_multiplied_u64 / 1_000_000; + // `rem_multiplied_u64` is less than 10^12 therefore divided by a million it fits into + // u32 + let rem_multiplied_divided_u32 = (rem_multiplied_u64 / 1_000_000) as u32; // `rem_multiplied_divided` is inferior to b, thus it can be converted back to N type - traits::As::sa(rem_multiplied_divided_u64) + rem_multiplied_divided_u32.into() }; (b / million) * part + rem_multiplied_divided @@ -228,27 +254,30 @@ impl Perbill { impl ops::Mul for Perbill where - N: Clone + traits::As + ops::Rem + ops::Div - + ops::Mul + ops::Add + N: Clone + From + UniqueSaturatedInto + ops::Rem + + ops::Div + ops::Mul + ops::Add, { type Output = N; fn mul(self, b: N) -> Self::Output { - let billion = >::sa(1_000_000_000); - let part = >::sa(self.0 as u64); + let billion: N = 1_000_000_000.into(); + let part: N = self.0.into(); let rem_multiplied_divided = { let rem = b.clone().rem(billion.clone()); - // `rem` is inferior to one billion, thus it fits into u64 - let rem_u64: u64 = rem.as_(); + // `rem` is inferior to one billion, thus it fits into u32 + let rem_u32 = rem.saturated_into::(); - // `self` and `rem` are inferior to one billion, thus the product fits into u64 - let rem_multiplied_u64 = rem_u64 * self.0 as u64; + // `self` and `rem` are inferior to one billion, thus the product is less than 10^18 + // and fits into u64 + let rem_multiplied_u64 = rem_u32 as u64 * self.0 as u64; - let rem_multiplied_divided_u64 = rem_multiplied_u64 / 1_000_000_000; + // `rem_multiplied_u64` is less than 10^18 therefore divided by a billion it fits into + // u32 + let rem_multiplied_divided_u32 = (rem_multiplied_u64 / 1_000_000_000) as u32; // `rem_multiplied_divided` is inferior to b, thus it can be converted back to N type - traits::As::sa(rem_multiplied_divided_u64) + rem_multiplied_divided_u32.into() }; (b / billion) * part + rem_multiplied_divided @@ -314,8 +343,8 @@ impl ::rstd::ops::Deref for PerU128 { type Target = u128; fn deref(&self) -> &u128 { - &self.0 - } + &self.0 + } } impl codec::CompactAs for PerU128 { @@ -584,6 +613,69 @@ macro_rules! impl_outer_config { } } +// NOTE [`PreRuntime` and `Consensus` are special] +// +// We MUST treat `PreRuntime` and `Consensus` variants specially, as they: +// +// * have more parameters (both in `generic::DigestItem` and in runtimes) +// * have a `PhantomData` parameter in the runtime, but not in `generic::DigestItem` + +#[macro_export] +#[doc(hidden)] +macro_rules! __parse_pattern_2 { + (PreRuntime $module:ident $internal:ident $v1:ident $v2:ident) => { + $internal::$module($module::RawLog::PreRuntime(ref $v1, ref $v2, $crate::rstd::marker::PhantomData)) + }; + (Consensus $module:ident $internal:ident $v1:ident $v2:ident) => { + $internal::$module($module::RawLog::Consensus(ref $v1, ref $v2, $crate::rstd::marker::PhantomData)) + }; + ($name:ident $module:ident $internal:ident $v1:ident $v2:ident) => { + $internal::$module($module::RawLog::$name(ref $v1)) + }; +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __parse_pattern { + (PreRuntime $engine_id:pat, $binder:pat) => { + $crate::generic::DigestItem::PreRuntime($engine_id, $binder) + }; + (Consensus $engine_id:pat, $binder:pat) => { + $crate::generic::DigestItem::Consensus($engine_id, $binder) + }; + ($name:ident $engine_id:pat, $binder:pat) => { + $crate::generic::DigestItem::$name($binder) + }; +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __parse_expr { + (PreRuntime $engine_id:expr, $module:ident $internal:ident $binder:expr) => { + $internal::$module($module::RawLog::PreRuntime($engine_id, $binder, Default::default())) + }; + (Consensus $engine_id:expr, $module:ident $internal:ident $binder:expr) => { + $internal::$module($module::RawLog::Consensus($engine_id, $binder, Default::default())) + }; + ($name:ident $engine_id:expr, $module:ident $internal:ident $binder:expr) => { + $internal::$module($module::RawLog::$name($binder)) + }; +} + +#[macro_export] +#[doc(hidden)] +macro_rules! __parse_expr_2 { + (PreRuntime $module:ident $internal:ident $v1:ident $v2:ident) => { + $crate::generic::DigestItemRef::PreRuntime($v1, $v2) + }; + (Consensus $module:ident $internal:ident $v1:ident $v2:ident) => { + $crate::generic::DigestItemRef::Consensus($v1, $v2) + }; + ($name:ident $module:ident $internal:ident $v1:ident $v2:ident) => { + $crate::generic::DigestItemRef::$name($v1) + }; +} + /// Generates enum that contains all possible log entries for the runtime. /// Every individual module of the runtime that is mentioned, must /// expose a `Log` and `RawLog` enums. @@ -604,7 +696,7 @@ macro_rules! impl_outer_log { ( $(#[$attr:meta])* pub enum $name:ident ($internal:ident: DigestItem<$( $genarg:ty ),*>) for $trait:ident { - $( $module:ident $(<$instance:path>)? ( $( $sitem:ident ),* ) ),* + $( $module:ident $(<$instance:path>)? ( $( $sitem:tt ),* ) ),* } ) => { /// Wrapper for all possible log entries for the `$trait` runtime. Provides binary-compatible @@ -623,7 +715,7 @@ macro_rules! impl_outer_log { #[allow(non_camel_case_types)] pub enum InternalLog { $( - $module($module::Log<$trait $(, $instance)? >), + $module($module::Log <$trait $(, $instance)?>), )* } @@ -635,8 +727,8 @@ macro_rules! impl_outer_log { fn dref<'a>(&'a self) -> Option<$crate::generic::DigestItemRef<'a, $($genarg),*>> { match self.0 { $($( - $internal::$module($module::RawLog::$sitem(ref v)) => - Some($crate::generic::DigestItemRef::$sitem(v)), + $crate::__parse_pattern_2!($sitem $module $internal a b) => + Some($crate::__parse_expr_2!($sitem $module $internal a b)), )*)* _ => None, } @@ -654,25 +746,38 @@ macro_rules! impl_outer_log { fn as_changes_trie_root(&self) -> Option<&Self::Hash> { self.dref().and_then(|dref| dref.as_changes_trie_root()) } + + fn as_pre_runtime(&self) -> Option<($crate::ConsensusEngineId, &[u8])> { + self.dref().and_then(|dref| dref.as_pre_runtime()) + } } impl From<$crate::generic::DigestItem<$($genarg),*>> for $name { - /// Converts `generic::DigestItem` into `$name`. If `generic::DigestItem` represents - /// a system item which is supported by the runtime, it is returned. - /// Otherwise we expect a `Other` log item. Trying to convert from anything other - /// will lead to panic in runtime, since the runtime does not supports this 'system' - /// log item. + /// Converts `generic::DigestItem` into `$name`. If + /// `generic::DigestItem` represents a system item which is + /// supported by the runtime, it is returned. Otherwise we expect a + /// `Other`, `PreDigest`, or `Consensus` log item. Trying to convert + /// from anything else will lead to panic at runtime, since the + /// runtime does not supports this 'system' log item. #[allow(unreachable_patterns)] fn from(gen: $crate::generic::DigestItem<$($genarg),*>) -> Self { match gen { $($( - $crate::generic::DigestItem::$sitem(value) => - $name($internal::$module($module::RawLog::$sitem(value))), + $crate::__parse_pattern!($sitem b, a) => + $name($crate::__parse_expr!($sitem b, $module $internal a)), )*)* - _ => gen.as_other() - .and_then(|value| $crate::codec::Decode::decode(&mut &value[..])) - .map($name) - .expect("not allowed to fail in runtime"), + _ => { + if let Some(s) = gen.as_other() + .and_then(|value| $crate::codec::Decode::decode(&mut &value[..])) + .map($name) + { + s + } else { + panic!("we only reach here if the runtime did not handle a digest; \ + runtimes are required to handle all digests they receive; qed" + ) + } + } } } } @@ -701,16 +806,16 @@ macro_rules! impl_outer_log { } $( - impl From<$module::Log<$trait $(, $instance)? >> for $name { + impl From<$module::Log<$trait $(, $instance)?>> for $name { /// Converts single module log item into `$name`. fn from(x: $module::Log<$trait $(, $instance)? >) -> Self { $name(x.into()) } } - impl From<$module::Log<$trait $(, $instance)? >> for InternalLog { + impl From<$module::Log<$trait $(, $instance)?>> for InternalLog { /// Converts single module log item into `$internal`. - fn from(x: $module::Log<$trait $(, $instance)? >) -> Self { + fn from(x: $module::Log<$trait $(, $instance)?>) -> Self { InternalLog::$module(x) } } @@ -898,13 +1003,8 @@ mod tests { } #[test] - #[should_panic] fn per_things_operate_in_output_type() { - use super::Perbill; - - assert_eq!(Perbill::one() * 255_u64, 255); - // panics - assert_ne!(Perbill::one() * 255_u8, 255); + assert_eq!(super::Perbill::one() * 255_u64, 255); } #[test] diff --git a/core/sr-primitives/src/testing.rs b/core/sr-primitives/src/testing.rs index e8e5aa20b46fe6351014860f8eea982a0123a85d..18c65d011e657804401a374717b355e8af1616ae 100644 --- a/core/sr-primitives/src/testing.rs +++ b/core/sr-primitives/src/testing.rs @@ -107,21 +107,20 @@ impl traits::Header for Header { fn digest(&self) -> &Self::Digest { &self.digest } fn digest_mut(&mut self) -> &mut Self::Digest { &mut self.digest } - fn set_digest(&mut self, digest: Self::Digest) { self.digest = digest } fn new( number: Self::Number, extrinsics_root: Self::Hash, state_root: Self::Hash, parent_hash: Self::Hash, - digest: Self::Digest + digest: Self::Digest, ) -> Self { Header { number, - extrinsics_root: extrinsics_root, + extrinsics_root, state_root, parent_hash, - digest + digest, } } } diff --git a/core/sr-primitives/src/traits.rs b/core/sr-primitives/src/traits.rs index 92c8026340bf466f63e40e085309264558ece5a7..f412ede0afb9bf1bbf5591b471c4c97c73d51f3c 100644 --- a/core/sr-primitives/src/traits.rs +++ b/core/sr-primitives/src/traits.rs @@ -17,7 +17,7 @@ //! Primitives for the runtime modules. use rstd::prelude::*; -use rstd::{self, result, marker::PhantomData}; +use rstd::{self, result, marker::PhantomData, convert::{TryFrom, TryInto}}; use runtime_io; #[cfg(feature = "std")] use std::fmt::{Debug, Display}; #[cfg(feature = "std")] use serde::{Serialize, Deserialize, de::DeserializeOwned}; @@ -27,7 +27,7 @@ use crate::transaction_validity::TransactionValidity; pub use integer_sqrt::IntegerSquareRoot; pub use num_traits::{ Zero, One, Bounded, CheckedAdd, CheckedSub, CheckedMul, CheckedDiv, - CheckedShl, CheckedShr, Saturating + CheckedShl, CheckedShr }; use rstd::ops::{ Add, Sub, Mul, Div, Rem, AddAssign, SubAssign, MulAssign, DivAssign, @@ -73,7 +73,11 @@ pub trait EnsureOrigin { /// A return type. type Success; /// Perform the origin check. - fn ensure_origin(o: OuterOrigin) -> result::Result; + fn ensure_origin(o: OuterOrigin) -> result::Result { + Self::try_origin(o).map_err(|_| "Invalid origin") + } + /// Perform the origin check. + fn try_origin(o: OuterOrigin) -> result::Result; } /// Means of changing one type into another in a manner dependent on the source type. @@ -157,71 +161,143 @@ impl Convert for Identity { fn convert(a: T) -> T { a } } -/// Simple trait similar to `Into`, except that it can be used to convert numerics between each -/// other. -pub trait As { - /// Convert forward (ala `Into::into`). - fn as_(self) -> T; - /// Convert backward (ala `From::from`). - fn sa(_: T) -> Self; -} - -macro_rules! impl_numerics { - ( $( $t:ty ),* ) => { - $( - impl_numerics!($t: u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize,); - )* - }; - ( $f:ty : $t:ty, $( $rest:ty, )* ) => { - impl As<$t> for $f { - fn as_(self) -> $t { self as $t } - fn sa(t: $t) -> Self { t as Self } - } - impl_numerics!($f: $( $rest, )*); - }; - ( $f:ty : ) => {} -} - -impl_numerics!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); - /// A meta trait for arithmetic. +/// +/// Arithmetic types do all the usual stuff you'd expect numbers to do. They are guaranteed to +/// be able to represent at least `u32` values without loss, hence the trait implies `From` +/// and smaller ints. All other conversions are fallible. pub trait SimpleArithmetic: - Zero + One + IntegerSquareRoot + As + + Zero + One + IntegerSquareRoot + + From + From + From + TryInto + TryInto + TryInto + + TryFrom + TryInto + TryFrom + TryInto + TryFrom + TryInto + + UniqueSaturatedInto + UniqueSaturatedInto + UniqueSaturatedInto + + UniqueSaturatedFrom + UniqueSaturatedInto + UniqueSaturatedFrom + UniqueSaturatedInto + Add + AddAssign + Sub + SubAssign + Mul + MulAssign + Div + DivAssign + Rem + RemAssign + Shl + Shr + - CheckedShl + - CheckedShr + - CheckedAdd + - CheckedSub + - CheckedMul + - CheckedDiv + - Saturating + - PartialOrd + Ord + Bounded + - HasCompact + CheckedShl + CheckedShr + CheckedAdd + CheckedSub + CheckedMul + CheckedDiv + + Saturating + PartialOrd + Ord + Bounded + + HasCompact + Sized {} impl + + Zero + One + IntegerSquareRoot + + From + From + From + TryInto + TryInto + TryInto + + TryFrom + TryInto + TryFrom + TryInto + TryFrom + TryInto + + UniqueSaturatedInto + UniqueSaturatedInto + UniqueSaturatedInto + + UniqueSaturatedFrom + UniqueSaturatedInto + UniqueSaturatedFrom + + UniqueSaturatedInto + UniqueSaturatedFrom + UniqueSaturatedInto + Add + AddAssign + Sub + SubAssign + Mul + MulAssign + Div + DivAssign + Rem + RemAssign + Shl + Shr + - CheckedShl + - CheckedShr + - CheckedAdd + - CheckedSub + - CheckedMul + - CheckedDiv + - Saturating + - PartialOrd + Ord + Bounded + - HasCompact + CheckedShl + CheckedShr + CheckedAdd + CheckedSub + CheckedMul + CheckedDiv + + Saturating + PartialOrd + Ord + Bounded + + HasCompact + Sized > SimpleArithmetic for T {} +/// Just like `From` except that if the source value is too big to fit into the destination type +/// then it'll saturate the destination. +pub trait UniqueSaturatedFrom: Sized { + /// Convert from a value of `T` into an equivalent instance of `Self`. + fn unique_saturated_from(t: T) -> Self; +} + +/// Just like `Into` except that if the source value is too big to fit into the destination type +/// then it'll saturate the destination. +pub trait UniqueSaturatedInto: Sized { + /// Consume self to return an equivalent value of `T`. + fn unique_saturated_into(self) -> T; +} + +impl + Bounded + Sized> UniqueSaturatedFrom for S { + fn unique_saturated_from(t: T) -> Self { + S::try_from(t).unwrap_or_else(|_| Bounded::max_value()) + } +} + +impl + Sized> UniqueSaturatedInto for S { + fn unique_saturated_into(self) -> T { + self.try_into().unwrap_or_else(|_| Bounded::max_value()) + } +} + +/// Simple trait to use checked mul and max value to give a saturated mul operation over +/// supported types. +pub trait Saturating { + /// Saturated addition - if the product can't fit in the type then just use max-value. + fn saturating_add(self, o: Self) -> Self; + + /// Saturated subtraction - if the product can't fit in the type then just use max-value. + fn saturating_sub(self, o: Self) -> Self; + + /// Saturated multiply - if the product can't fit in the type then just use max-value. + fn saturating_mul(self, o: Self) -> Self; +} + +impl Saturating for T { + fn saturating_add(self, o: Self) -> Self { + ::saturating_add(self, o) + } + fn saturating_sub(self, o: Self) -> Self { + ::saturating_sub(self, o) + } + fn saturating_mul(self, o: Self) -> Self { + self.checked_mul(&o).unwrap_or_else(Bounded::max_value) + } +} + +/// Convenience type to work around the highly unergonomic syntax needed +/// to invoke the functions of overloaded generic traits, in this case +/// `SaturatedFrom` and `SaturatedInto`. +pub trait SaturatedConversion { + /// Convert from a value of `T` into an equivalent instance of `Self`. + /// + /// This just uses `UniqueSaturatedFrom` internally but with this + /// variant you can provide the destination type using turbofish syntax + /// in case Rust happens not to assume the correct type. + fn saturated_from(t: T) -> Self where Self: UniqueSaturatedFrom { + >::unique_saturated_from(t) + } + + /// Consume self to return an equivalent value of `T`. + /// + /// This just uses `UniqueSaturatedInto` internally but with this + /// variant you can provide the destination type using turbofish syntax + /// in case Rust happens not to assume the correct type. + fn saturated_into(self) -> T where Self: UniqueSaturatedInto { + >::unique_saturated_into(self) + } +} +impl SaturatedConversion for T {} + +/// Convenience type to work around the highly unergonomic syntax needed +/// to invoke the functions of overloaded generic traits, in this case +/// `TryFrom` and `TryInto`. +pub trait CheckedConversion { + /// Convert from a value of `T` into an equivalent instance of `Option`. + /// + /// This just uses `TryFrom` internally but with this + /// variant you can provide the destination type using turbofish syntax + /// in case Rust happens not to assume the correct type. + fn checked_from(t: T) -> Option where Self: TryFrom { + >::try_from(t).ok() + } + /// Consume self to return `Some` equivalent value of `Option`. + /// + /// This just uses `TryInto` internally but with this + /// variant you can provide the destination type using turbofish syntax + /// in case Rust happens not to assume the correct type. + fn checked_into(self) -> Option where Self: TryInto { + >::try_into(self).ok() + } +} +impl CheckedConversion for T {} + /// Trait for things that can be clear (have no bits set). For numeric types, essentially the same /// as `Zero`. pub trait Clear { @@ -363,7 +439,7 @@ pub trait Hash: 'static + MaybeSerializeDebug + Clone + Eq + PartialEq { // Stup fn storage_root() -> Self::Output; /// Acquire the global storage changes root. - fn storage_changes_root(parent_hash: Self::Output, parent_number: u64) -> Option; + fn storage_changes_root(parent_hash: Self::Output) -> Option; } /// Blake2-256 Hash implementation. @@ -396,8 +472,8 @@ impl Hash for BlakeTwo256 { fn storage_root() -> Self::Output { runtime_io::storage_root().into() } - fn storage_changes_root(parent_hash: Self::Output, parent_number: u64) -> Option { - runtime_io::storage_changes_root(parent_hash.into(), parent_number).map(Into::into) + fn storage_changes_root(parent_hash: Self::Output) -> Option { + runtime_io::storage_changes_root(parent_hash.into()).map(Into::into) } } @@ -569,8 +645,6 @@ pub trait Header: Clone + Send + Sync + Codec + Eq + MaybeSerializeDebugButNotDe fn digest(&self) -> &Self::Digest; /// Get a mutable reference to the digest. fn digest_mut(&mut self) -> &mut Self::Digest; - /// Sets the digest. - fn set_digest(&mut self, digest: Self::Digest); /// Returns the hash of the header. fn hash(&self) -> Self::Hash { @@ -708,11 +782,14 @@ pub trait DigestItem: Codec + Member + MaybeSerializeDebugButNotDeserialize { /// `AuthorityChange` payload. type AuthorityId: Member + MaybeHash + crate::codec::Encode + crate::codec::Decode; - /// Returns Some if the entry is the `AuthoritiesChange` entry. + /// Returns `Some` if the entry is the `AuthoritiesChange` entry. fn as_authorities_change(&self) -> Option<&[Self::AuthorityId]>; - /// Returns Some if the entry is the `ChangesTrieRoot` entry. + /// Returns `Some` if the entry is the `ChangesTrieRoot` entry. fn as_changes_trie_root(&self) -> Option<&Self::Hash>; + + /// Returns `Some` if this entry is the `PreRuntime` entry. + fn as_pre_runtime(&self) -> Option<(super::ConsensusEngineId, &[u8])>; } /// Auxiliary wrapper that holds an api instance and binds it to the given lifetime. diff --git a/core/sr-primitives/src/transaction_validity.rs b/core/sr-primitives/src/transaction_validity.rs index d927bd74e452a5b894ce23c96a2bdb2e8712e938..f36599b67b42c35c52752ed9e9dfd3dee6e22e27 100644 --- a/core/sr-primitives/src/transaction_validity.rs +++ b/core/sr-primitives/src/transaction_validity.rs @@ -30,7 +30,7 @@ pub type TransactionLongevity = u64; pub type TransactionTag = Vec; /// Information on a transaction's validity and, if valid, on how it relates to other transactions. -#[derive(Clone, PartialEq, Eq, Encode, Decode)] +#[derive(Clone, PartialEq, Eq, Encode)] #[cfg_attr(feature = "std", derive(Debug))] pub enum TransactionValidity { /// Transaction is invalid. Details are described by the error code. @@ -51,7 +51,7 @@ pub enum TransactionValidity { /// /// A list of tags this transaction provides. Successfully importing the transaction /// will enable other transactions that depend on (require) those tags to be included as well. - /// Provided and requried tags allow Substrate to build a dependency graph of transactions + /// Provided and required tags allow Substrate to build a dependency graph of transactions /// and import them in the right (linear) order. provides: Vec, /// Transaction longevity @@ -59,7 +59,74 @@ pub enum TransactionValidity { /// Longevity describes minimum number of blocks the validity is correct. /// After this period transaction should be removed from the pool or revalidated. longevity: TransactionLongevity, + /// A flag indicating if the transaction should be propagated to other peers. + /// + /// By setting `false` here the transaction will still be considered for + /// including in blocks that are authored on the current node, but will + /// never be sent to other peers. + propagate: bool, }, /// Transaction validity can't be determined. Unknown(i8), } + +impl Decode for TransactionValidity { + fn decode(value: &mut I) -> Option { + match value.read_byte()? { + 0 => Some(TransactionValidity::Invalid(i8::decode(value)?)), + 1 => { + let priority = TransactionPriority::decode(value)?; + let requires = Vec::decode(value)?; + let provides = Vec::decode(value)?; + let longevity = TransactionLongevity::decode(value)?; + let propagate = bool::decode(value).unwrap_or(true); + + Some(TransactionValidity::Valid { + priority, requires, provides, longevity, propagate, + }) + }, + 2 => Some(TransactionValidity::Unknown(i8::decode(value)?)), + _ => None, + } + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn should_decode_with_backward_compat() { + let old_encoding = vec![ + 1, 5, 0, 0, 0, 0, 0, 0, 0, 4, 16, 1, 2, 3, 4, 4, 12, 4, 5, 6, 42, 0, 0, 0, 0, 0, 0, 0 + ]; + + assert_eq!(TransactionValidity::decode(&mut &*old_encoding), Some(TransactionValidity::Valid { + priority: 5, + requires: vec![vec![1, 2, 3, 4]], + provides: vec![vec![4, 5, 6]], + longevity: 42, + propagate: true, + })); + } + + #[test] + fn should_encode_and_decode() { + let v = TransactionValidity::Valid { + priority: 5, + requires: vec![vec![1, 2, 3, 4]], + provides: vec![vec![4, 5, 6]], + longevity: 42, + propagate: false, + }; + + let encoded = v.encode(); + assert_eq!( + encoded, + vec![1, 5, 0, 0, 0, 0, 0, 0, 0, 4, 16, 1, 2, 3, 4, 4, 12, 4, 5, 6, 42, 0, 0, 0, 0, 0, 0, 0, 0] + ); + + // decode back + assert_eq!(TransactionValidity::decode(&mut &*encoded), Some(v)); + } +} diff --git a/core/sr-sandbox/without_std.rs b/core/sr-sandbox/without_std.rs index 070ca1ddf15cfd9f08e9275f57cea6567c8b3e11..894ba43eb0ccc39795ef89590835591fcfd4d50d 100755 --- a/core/sr-sandbox/without_std.rs +++ b/core/sr-sandbox/without_std.rs @@ -15,7 +15,7 @@ // along with Substrate. If not, see . use rstd::prelude::*; -use rstd::{slice, marker, mem}; +use rstd::{slice, marker, mem, vec}; use rstd::rc::Rc; use codec::{Decode, Encode}; use primitives::sandbox as sandbox_primitives; diff --git a/core/sr-std/with_std.rs b/core/sr-std/with_std.rs index d71b9dcb69ce81a33c97336dec4094cbbdd20690..5824e26241675e80336a96bf7570f128b909ed88 100644 --- a/core/sr-std/with_std.rs +++ b/core/sr-std/with_std.rs @@ -19,6 +19,8 @@ pub use std::boxed; pub use std::cell; pub use std::clone; pub use std::cmp; +pub use std::convert; +pub use std::default; pub use std::fmt; pub use std::hash; pub use std::iter; @@ -28,11 +30,10 @@ pub use std::num; pub use std::ops; pub use std::ptr; pub use std::rc; +pub use std::result; pub use std::slice; +pub use std::str; pub use std::vec; -pub use std::default; -pub use std::result; -pub use std::convert; pub mod collections { pub use std::collections::btree_map; diff --git a/core/sr-std/without_std.rs b/core/sr-std/without_std.rs index 9214a0ed2f8fdb18d9a5f20218c7101ae81e4264..db81372c2f0708e6f8e86ea171860f06efd2b539 100755 --- a/core/sr-std/without_std.rs +++ b/core/sr-std/without_std.rs @@ -53,6 +53,8 @@ pub use core::borrow; pub use core::cell; pub use core::clone; pub use core::cmp; +pub use core::convert; +pub use core::default; pub use core::hash; pub use core::intrinsics; pub use core::iter; @@ -61,10 +63,10 @@ pub use core::mem; pub use core::num; pub use core::ops; pub use core::ptr; -pub use core::slice; -pub use core::default; pub use core::result; -pub use core::convert; +pub use core::slice; +// Allow intepreting vectors of bytes as strings, but not constructing them. +pub use core::str; // We are trying to avoid certain things here, such as `core::string` // (if you need `String` you most probably doing something wrong, since // runtime doesn't require anything human readable). diff --git a/core/sr-version/src/lib.rs b/core/sr-version/src/lib.rs index 071b8934040609c4ef6d1fcd9556039064b66e74..179146cc8464d110cb0fab6d4cc53a0c63e0bc9d 100644 --- a/core/sr-version/src/lib.rs +++ b/core/sr-version/src/lib.rs @@ -19,7 +19,7 @@ #![cfg_attr(not(feature = "std"), no_std)] #[cfg(feature = "std")] -use serde::Serialize; +use serde::{Serialize, Deserialize}; #[cfg(feature = "std")] use std::fmt; #[cfg(feature = "std")] @@ -63,7 +63,7 @@ macro_rules! create_apis_vec { /// In particular: bug fixes should result in an increment of `spec_version` and possibly `authoring_version`, /// absolutely not `impl_version` since they change the semantics of the runtime. #[derive(Clone, PartialEq, Eq, Encode)] -#[cfg_attr(feature = "std", derive(Debug, Serialize, Decode))] +#[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize, Decode))] #[cfg_attr(feature = "std", serde(rename_all = "camelCase"))] pub struct RuntimeVersion { /// Identifies the different Substrate runtimes. There'll be at least polkadot and node. diff --git a/core/state-db/Cargo.toml b/core/state-db/Cargo.toml index 6f2ac70a303d3019a92935c1d688c7c4173ec284..8c02dbc450fb82989e45f864ca710611d30ed0d5 100644 --- a/core/state-db/Cargo.toml +++ b/core/state-db/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -parking_lot = "0.7.1" +parking_lot = "0.8.0" log = "0.4" primitives = { package = "substrate-primitives", path = "../../core/primitives" } parity-codec = { version = "3.3", features = ["derive"] } diff --git a/core/state-db/src/lib.rs b/core/state-db/src/lib.rs index 8d9cf9c965f5a21d1a9b0064de4c5ce1dc846055..8986dda32d7ca007a3c2e678e62faebf288ee0d5 100644 --- a/core/state-db/src/lib.rs +++ b/core/state-db/src/lib.rs @@ -37,7 +37,7 @@ use std::fmt; use parking_lot::RwLock; use parity_codec as codec; use codec::Codec; -use std::collections::HashSet; +use std::collections::{VecDeque, HashMap, hash_map::Entry}; use noncanonical::NonCanonicalOverlay; use pruning::RefWindow; use log::trace; @@ -78,6 +78,8 @@ pub enum Error { InvalidBlockNumber, /// Trying to insert block with unknown parent. InvalidParent, + /// Canonicalization would discard pinned state. + DiscardingPinned, } impl fmt::Debug for Error { @@ -88,6 +90,7 @@ impl fmt::Debug for Error { Error::InvalidBlock => write!(f, "Trying to canonicalize invalid block"), Error::InvalidBlockNumber => write!(f, "Trying to insert block with invalid number"), Error::InvalidParent => write!(f, "Trying to insert block with unknown parent"), + Error::DiscardingPinned => write!(f, "Trying to discard pinned state"), } } } @@ -112,7 +115,7 @@ pub struct CommitSet { } /// Pruning constraints. If none are specified pruning is -#[derive(Default, Debug, Clone)] +#[derive(Default, Debug, Clone, Eq, PartialEq)] pub struct Constraints { /// Maximum blocks. Defaults to 0 when unspecified, effectively keeping only non-canonical states. pub max_blocks: Option, @@ -121,7 +124,7 @@ pub struct Constraints { } /// Pruning mode. -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Eq, PartialEq)] pub enum PruningMode { /// Maintain a pruning window. Constrained(Constraints), @@ -165,13 +168,14 @@ fn to_meta_key(suffix: &[u8], data: &S) -> Vec { struct StateDbSync { mode: PruningMode, non_canonical: NonCanonicalOverlay, + canonicalization_queue: VecDeque, pruning: Option>, - pinned: HashSet, + pinned: HashMap, } impl StateDbSync { pub fn new(mode: PruningMode, db: &D) -> Result, Error> { - trace!("StateDb settings: {:?}", mode); + trace!(target: "state-db", "StateDb settings: {:?}", mode); let non_canonical: NonCanonicalOverlay = NonCanonicalOverlay::new(db)?; let pruning: Option> = match mode { PruningMode::Constrained(Constraints { @@ -186,6 +190,7 @@ impl StateDbSync { non_canonical, pruning, pinned: Default::default(), + canonicalization_queue: Default::default(), }) } @@ -206,21 +211,30 @@ impl StateDbSync { } pub fn canonicalize_block(&mut self, hash: &BlockHash) -> Result, Error> { - let mut commit = match self.mode { - PruningMode::ArchiveAll => { - CommitSet::default() - }, - PruningMode::ArchiveCanonical => { - let mut commit = self.non_canonical.canonicalize(hash)?; - commit.data.deleted.clear(); - commit - }, - PruningMode::Constrained(_) => { - self.non_canonical.canonicalize(hash)? - }, - }; - if let Some(ref mut pruning) = self.pruning { - pruning.note_canonical(hash, &mut commit); + let mut commit = CommitSet::default(); + if self.mode == PruningMode::ArchiveAll { + return Ok(commit) + } + self.canonicalization_queue.push_back(hash.clone()); + while let Some(hash) = self.canonicalization_queue.front().cloned() { + if self.pinned.contains_key(&hash) { + break; + } + match self.non_canonical.canonicalize(&hash, &self.pinned, &mut commit) { + Ok(()) => { + self.canonicalization_queue.pop_front(); + if self.mode == PruningMode::ArchiveCanonical { + commit.data.deleted.clear(); + } + } + Err(Error::DiscardingPinned) => { + break; + } + Err(e) => return Err(e), + }; + if let Some(ref mut pruning) = self.pruning { + pruning.note_canonical(&hash, &mut commit); + } } self.prune(&mut commit); Ok(commit) @@ -255,7 +269,7 @@ impl StateDbSync { } let pinned = &self.pinned; - if pruning.next_hash().map_or(false, |h| pinned.contains(&h)) { + if pruning.next_hash().map_or(false, |h| pinned.contains_key(&h)) { break; } pruning.prune_one(commit); @@ -278,11 +292,23 @@ impl StateDbSync { } pub fn pin(&mut self, hash: &BlockHash) { - self.pinned.insert(hash.clone()); + trace!(target: "state-db", "Pinned block: {:?}", hash); + *self.pinned.entry(hash.clone()).or_default() += 1; } pub fn unpin(&mut self, hash: &BlockHash) { - self.pinned.remove(hash); + match self.pinned.entry(hash.clone()) { + Entry::Occupied(mut entry) => { + *entry.get_mut() -= 1; + if *entry.get() == 0 { + trace!(target: "state-db", "Unpinned block: {:?}", hash); + entry.remove(); + } else { + trace!(target: "state-db", "Releasing reference for {:?}", hash); + } + }, + Entry::Vacant(_) => {}, + } } pub fn get(&self, key: &Key, db: &D) -> Result, Error> diff --git a/core/state-db/src/noncanonical.rs b/core/state-db/src/noncanonical.rs index da957335ba30f4e7d59e5fe7f5eda6613b9943d7..0d43389a0be975f1f7b502536aedb0edc622d6ef 100644 --- a/core/state-db/src/noncanonical.rs +++ b/core/state-db/src/noncanonical.rs @@ -230,13 +230,20 @@ impl NonCanonicalOverlay { Ok(commit) } - fn discard_journals(&self, level_index: usize, discarded_journals: &mut Vec>, hash: &BlockHash) { + fn discard_journals( + &self, + level_index: usize, + discarded_journals: &mut Vec>, + discarded_blocks: &mut Vec, + hash: &BlockHash + ) { if let Some(level) = self.levels.get(level_index) { level.iter().for_each(|overlay| { let parent = self.parents.get(&overlay.hash).expect("there is a parent entry for each entry in levels; qed").clone(); if parent == *hash { discarded_journals.push(overlay.journal_key.clone()); - self.discard_journals(level_index + 1, discarded_journals, &overlay.hash); + discarded_blocks.push(overlay.hash.clone()); + self.discard_journals(level_index + 1, discarded_journals, discarded_blocks, &overlay.hash); } }); } @@ -268,7 +275,12 @@ impl NonCanonicalOverlay { /// Select a top-level root and canonicalized it. Discards all sibling subtrees and the root. /// Returns a set of changes that need to be added to the DB. - pub fn canonicalize(&mut self, hash: &BlockHash) -> Result, Error> { + pub fn canonicalize( + &mut self, + hash: &BlockHash, + pinned: &HashMap, + commit: &mut CommitSet, + ) -> Result<(), Error> { trace!(target: "state-db", "Canonicalizing {:?}", hash); let level = self.levels.get(self.pending_canonicalizations.len()).ok_or_else(|| Error::InvalidBlock)?; let index = level @@ -276,26 +288,40 @@ impl NonCanonicalOverlay { .position(|overlay| overlay.hash == *hash) .ok_or_else(|| Error::InvalidBlock)?; - let mut commit = CommitSet::default(); let mut discarded_journals = Vec::new(); - for (i, overlay) in level.into_iter().enumerate() { - if i == index { - // that's the one we need to canonicalize - commit.data.inserted = overlay.inserted.iter() - .map(|k| (k.clone(), self.values.get(k).expect("For each key in verlays there's a value in values").1.clone())) - .collect(); - commit.data.deleted = overlay.deleted.clone(); - } else { - self.discard_journals(self.pending_canonicalizations.len() + 1, &mut discarded_journals, &overlay.hash); + let mut discarded_blocks = Vec::new(); + for (i, overlay) in level.iter().enumerate() { + if i != index { + self.discard_journals( + self.pending_canonicalizations.len() + 1, + &mut discarded_journals, + &mut discarded_blocks, + &overlay.hash + ); } discarded_journals.push(overlay.journal_key.clone()); + discarded_blocks.push(overlay.hash.clone()); } + + for hash in discarded_blocks.into_iter() { + if pinned.contains_key(&hash) { + trace!(target: "state-db", "Refusing to discard pinned state {:?}", hash); + return Err(Error::DiscardingPinned) + } + } + + // get the one we need to canonicalize + let overlay = &level[index]; + commit.data.inserted.extend(overlay.inserted.iter() + .map(|k| (k.clone(), self.values.get(k).expect("For each key in overlays there's a value in values").1.clone()))); + commit.data.deleted.extend(overlay.deleted.clone()); + commit.meta.deleted.append(&mut discarded_journals); let canonicalized = (hash.clone(), self.front_block_number() + self.pending_canonicalizations.len() as u64); commit.meta.inserted.push((to_meta_key(LAST_CANONICAL, &()), canonicalized.encode())); trace!(target: "state-db", "Discarding {} records", commit.meta.deleted.len()); self.pending_canonicalizations.push(hash.clone()); - Ok(commit) + Ok(()) } fn apply_canonicalizations(&mut self) { @@ -385,10 +411,10 @@ impl NonCanonicalOverlay { #[cfg(test)] mod tests { - use std::io; + use std::{collections::HashMap, io}; use primitives::H256; use super::{NonCanonicalOverlay, to_journal_key}; - use crate::ChangeSet; + use crate::{ChangeSet, CommitSet}; use crate::test::{make_db, make_changeset}; fn contains(overlay: &NonCanonicalOverlay, key: u64) -> bool { @@ -409,7 +435,8 @@ mod tests { fn canonicalize_empty_panics() { let db = make_db(&[]); let mut overlay = NonCanonicalOverlay::::new(&db).unwrap(); - overlay.canonicalize::(&H256::default()).unwrap(); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&H256::default(), &HashMap::default(), &mut commit).unwrap(); } #[test] @@ -453,7 +480,8 @@ mod tests { let db = make_db(&[]); let mut overlay = NonCanonicalOverlay::::new(&db).unwrap(); overlay.insert::(&h1, 1, &H256::default(), ChangeSet::default()).unwrap(); - overlay.canonicalize::(&h2).unwrap(); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h2, &HashMap::default(), &mut commit).unwrap(); } #[test] @@ -468,7 +496,8 @@ mod tests { assert_eq!(insertion.meta.inserted.len(), 2); assert_eq!(insertion.meta.deleted.len(), 0); db.commit(&insertion); - let finalization = overlay.canonicalize::(&h1).unwrap(); + let mut finalization = CommitSet::default(); + overlay.canonicalize::(&h1, &HashMap::default(), &mut finalization).unwrap(); assert_eq!(finalization.data.inserted.len(), changeset.inserted.len()); assert_eq!(finalization.data.deleted.len(), changeset.deleted.len()); assert_eq!(finalization.meta.inserted.len(), 1); @@ -501,7 +530,9 @@ mod tests { let mut overlay = NonCanonicalOverlay::::new(&db).unwrap(); db.commit(&overlay.insert::(&h1, 10, &H256::default(), make_changeset(&[3, 4], &[2])).unwrap()); db.commit(&overlay.insert::(&h2, 11, &h1, make_changeset(&[5], &[3])).unwrap()); - db.commit(&overlay.canonicalize::(&h1).unwrap()); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h1, &HashMap::default(), &mut commit).unwrap(); + db.commit(&commit); overlay.apply_pending(); assert_eq!(overlay.levels.len(), 1); @@ -526,7 +557,9 @@ mod tests { assert!(contains(&overlay, 5)); assert_eq!(overlay.levels.len(), 2); assert_eq!(overlay.parents.len(), 2); - db.commit(&overlay.canonicalize::(&h1).unwrap()); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h1, &HashMap::default(), &mut commit).unwrap(); + db.commit(&commit); assert!(contains(&overlay, 5)); assert_eq!(overlay.levels.len(), 2); assert_eq!(overlay.parents.len(), 2); @@ -535,7 +568,9 @@ mod tests { assert_eq!(overlay.parents.len(), 1); assert!(!contains(&overlay, 5)); assert!(contains(&overlay, 7)); - db.commit(&overlay.canonicalize::(&h2).unwrap()); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h2, &HashMap::default(), &mut commit).unwrap(); + db.commit(&commit); overlay.apply_pending(); assert_eq!(overlay.levels.len(), 0); assert_eq!(overlay.parents.len(), 0); @@ -552,7 +587,9 @@ mod tests { db.commit(&overlay.insert::(&h_1, 1, &H256::default(), c_1).unwrap()); db.commit(&overlay.insert::(&h_2, 1, &H256::default(), c_2).unwrap()); assert!(contains(&overlay, 1)); - db.commit(&overlay.canonicalize::(&h_1).unwrap()); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h_1, &HashMap::default(), &mut commit).unwrap(); + db.commit(&commit); assert!(contains(&overlay, 1)); overlay.apply_pending(); assert!(!contains(&overlay, 1)); @@ -569,8 +606,10 @@ mod tests { db.commit(&overlay.insert::(&h1, 1, &H256::default(), changeset.clone()).unwrap()); db.commit(&overlay.insert::(&h2, 2, &h1, changeset.clone()).unwrap()); overlay.apply_pending(); - db.commit(&overlay.canonicalize::(&h1).unwrap()); - db.commit(&overlay.canonicalize::(&h2).unwrap()); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h1, &HashMap::default(), &mut commit).unwrap(); + overlay.canonicalize::(&h2, &HashMap::default(), &mut commit).unwrap(); + db.commit(&commit); db.commit(&overlay.insert::(&h3, 3, &h2, changeset.clone()).unwrap()); overlay.apply_pending(); assert_eq!(overlay.levels.len(), 1); @@ -639,7 +678,9 @@ mod tests { assert_eq!(overlay.last_canonicalized, overlay2.last_canonicalized); // canonicalize 1. 2 and all its children should be discarded - db.commit(&overlay.canonicalize::(&h_1).unwrap()); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h_1, &HashMap::default(), &mut commit).unwrap(); + db.commit(&commit); overlay.apply_pending(); assert_eq!(overlay.levels.len(), 2); assert_eq!(overlay.parents.len(), 6); @@ -657,8 +698,15 @@ mod tests { assert!(db.get_meta(&to_journal_key(2, 2)).unwrap().is_none()); assert!(db.get_meta(&to_journal_key(2, 3)).unwrap().is_none()); + // check that discarding pinned state produces an error. + let mut commit = CommitSet::default(); + let pinned = vec![(h_1_1_1, 1)].into_iter().collect(); + assert!(overlay.canonicalize::(&h_1_2, &pinned, &mut commit).is_err()); + // canonicalize 1_2. 1_1 and all its children should be discarded - db.commit(&overlay.canonicalize::(&h_1_2).unwrap()); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h_1_2, &HashMap::default(), &mut commit).unwrap(); + db.commit(&commit); overlay.apply_pending(); assert_eq!(overlay.levels.len(), 1); assert_eq!(overlay.parents.len(), 3); @@ -673,7 +721,9 @@ mod tests { assert!(!overlay.have_block(&h_1_1_1)); // canonicalize 1_2_2 - db.commit(&overlay.canonicalize::(&h_1_2_2).unwrap()); + let mut commit = CommitSet::default(); + overlay.canonicalize::(&h_1_2_2, &HashMap::default(), &mut commit).unwrap(); + db.commit(&commit); overlay.apply_pending(); assert_eq!(overlay.levels.len(), 0); assert_eq!(overlay.parents.len(), 0); diff --git a/core/state-machine/Cargo.toml b/core/state-machine/Cargo.toml index 405e62baccf9d136dea0ce7235ab3f1d85924846..b1cb98ae808875bd8a9d28fc6a38063979c361f3 100644 --- a/core/state-machine/Cargo.toml +++ b/core/state-machine/Cargo.toml @@ -7,7 +7,7 @@ edition = "2018" [dependencies] log = "0.4" -parking_lot = "0.7.1" +parking_lot = "0.8.0" hash-db = "0.12" trie-db = "0.12" trie-root = "0.12" @@ -15,6 +15,7 @@ trie = { package = "substrate-trie", path = "../trie" } primitives = { package = "substrate-primitives", path = "../primitives" } panic-handler = { package = "substrate-panic-handler", path = "../panic-handler" } parity-codec = "3.3" +num-traits = "0.2" [dev-dependencies] hex-literal = "0.2.0" diff --git a/core/state-machine/src/backend.rs b/core/state-machine/src/backend.rs index 895a805e436d012e9408a321f4d3eb007bbd7a92..81529c6da3beac67342c0fc185d6aff5d0973c48 100644 --- a/core/state-machine/src/backend.rs +++ b/core/state-machine/src/backend.rs @@ -88,10 +88,25 @@ pub trait Backend { fn pairs(&self) -> Vec<(Vec, Vec)>; /// Get all keys with given prefix - fn keys(&self, prefix: &Vec) -> Vec>; + fn keys(&self, prefix: &[u8]) -> Vec> { + let mut all = Vec::new(); + self.for_keys_with_prefix(prefix, |k| all.push(k.to_vec())); + all + } + + /// Get all keys of child storage with given prefix + fn child_keys(&self, child_storage_key: &[u8], prefix: &[u8]) -> Vec> { + let mut all = Vec::new(); + self.for_keys_in_child_storage(child_storage_key, |k| { + if k.starts_with(prefix) { + all.push(k.to_vec()); + } + }); + all + } /// Try convert into trie backend. - fn try_into_trie_backend(self) -> Option>; + fn as_trie_backend(&mut self) -> Option<&TrieBackend>; /// Calculate the storage root, with given delta over what is already stored /// in the backend, and produce a "transaction" that can be used to commit. @@ -170,31 +185,33 @@ impl error::Error for Void { /// In-memory backend. Fully recomputes tries on each commit but useful for /// tests. -#[derive(Eq)] -pub struct InMemory { +pub struct InMemory { inner: HashMap>, HashMap, Vec>>, + trie: Option, H>>, _hasher: PhantomData, } -impl Default for InMemory { +impl Default for InMemory { fn default() -> Self { InMemory { inner: Default::default(), + trie: None, _hasher: PhantomData, } } } -impl Clone for InMemory { +impl Clone for InMemory { fn clone(&self) -> Self { InMemory { inner: self.inner.clone(), + trie: None, _hasher: PhantomData, } } } -impl PartialEq for InMemory { +impl PartialEq for InMemory { fn eq(&self, other: &Self) -> bool { self.inner.eq(&other.inner) } @@ -215,27 +232,29 @@ impl InMemory { } } -impl From>, HashMap, Vec>>> for InMemory { +impl From>, HashMap, Vec>>> for InMemory { fn from(inner: HashMap>, HashMap, Vec>>) -> Self { InMemory { inner: inner, + trie: None, _hasher: PhantomData, } } } -impl From, Vec>> for InMemory { +impl From, Vec>> for InMemory { fn from(inner: HashMap, Vec>) -> Self { let mut expanded = HashMap::new(); expanded.insert(None, inner); InMemory { inner: expanded, + trie: None, _hasher: PhantomData, } } } -impl From>, Vec, Option>)>> for InMemory { +impl From>, Vec, Option>)>> for InMemory { fn from(inner: Vec<(Option>, Vec, Option>)>) -> Self { let mut expanded: HashMap>, HashMap, Vec>> = HashMap::new(); for (child_key, key, value) in inner { @@ -286,7 +305,9 @@ impl Backend for InMemory { I: IntoIterator, Option>)>, ::Out: Ord, { - let existing_pairs = self.inner.get(&None).into_iter().flat_map(|map| map.iter().map(|(k, v)| (k.clone(), Some(v.clone())))); + let existing_pairs = self.inner.get(&None) + .into_iter() + .flat_map(|map| map.iter().map(|(k, v)| (k.clone(), Some(v.clone())))); let transaction: Vec<_> = delta.into_iter().collect(); let root = trie_root::(existing_pairs.chain(transaction.iter().cloned()) @@ -307,7 +328,9 @@ impl Backend for InMemory { { let storage_key = storage_key.to_vec(); - let existing_pairs = self.inner.get(&Some(storage_key.clone())).into_iter().flat_map(|map| map.iter().map(|(k, v)| (k.clone(), Some(v.clone())))); + let existing_pairs = self.inner.get(&Some(storage_key.clone())) + .into_iter() + .flat_map(|map| map.iter().map(|(k, v)| (k.clone(), Some(v.clone())))); let transaction: Vec<_> = delta.into_iter().collect(); let root = child_trie_root::( @@ -326,23 +349,34 @@ impl Backend for InMemory { } fn pairs(&self) -> Vec<(Vec, Vec)> { - self.inner.get(&None).into_iter().flat_map(|map| map.iter().map(|(k, v)| (k.clone(), v.clone()))).collect() + self.inner.get(&None) + .into_iter() + .flat_map(|map| map.iter().map(|(k, v)| (k.clone(), v.clone()))) + .collect() } - fn keys(&self, prefix: &Vec) -> Vec> { - self.inner.get(&None).into_iter().flat_map(|map| map.keys().filter(|k| k.starts_with(prefix)).cloned()).collect() + fn keys(&self, prefix: &[u8]) -> Vec> { + self.inner.get(&None) + .into_iter() + .flat_map(|map| map.keys().filter(|k| k.starts_with(prefix)).cloned()) + .collect() + } + + fn child_keys(&self, storage_key: &[u8], prefix: &[u8]) -> Vec> { + self.inner.get(&Some(storage_key.to_vec())) + .into_iter() + .flat_map(|map| map.keys().filter(|k| k.starts_with(prefix)).cloned()) + .collect() } - fn try_into_trie_backend( - self - )-> Option> { + fn as_trie_backend(&mut self)-> Option<&TrieBackend> { let mut mdb = MemoryDB::default(); let mut root = None; let mut new_child_roots = Vec::new(); let mut root_map = None; - for (storage_key, map) in self.inner { + for (storage_key, map) in &self.inner { if let Some(storage_key) = storage_key.as_ref() { - let ch = insert_into_memory_db::(&mut mdb, map.into_iter())?; + let ch = insert_into_memory_db::(&mut mdb, map.clone().into_iter())?; new_child_roots.push((storage_key.clone(), ch.as_ref().into())); } else { root_map = Some(map); @@ -352,14 +386,15 @@ impl Backend for InMemory { if let Some(map) = root_map.take() { root = Some(insert_into_memory_db::( &mut mdb, - map.into_iter().chain(new_child_roots.into_iter()) + map.clone().into_iter().chain(new_child_roots.into_iter()) )?); } let root = match root { Some(root) => root, None => insert_into_memory_db::(&mut mdb, ::std::iter::empty())?, }; - Some(TrieBackend::new(mdb, root)) + self.trie = Some(TrieBackend::new(mdb, root)); + self.trie.as_ref() } } diff --git a/core/state-machine/src/basic.rs b/core/state-machine/src/basic.rs index 3021ddfd28dee459e682d5f06df1f3aaa10078dd..e9939711f1e47e9d86c5f751ab4ee2389046113c 100644 --- a/core/state-machine/src/basic.rs +++ b/core/state-machine/src/basic.rs @@ -20,6 +20,7 @@ use std::collections::HashMap; use std::iter::FromIterator; use hash_db::Hasher; use trie::trie_root; +use primitives::offchain; use primitives::storage::well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES}; use parity_codec::Encode; use super::{ChildStorageKey, Externalities, OverlayedChanges}; @@ -151,13 +152,13 @@ impl Externalities for BasicExternalities where H::Out: Ord { vec![42] } - fn storage_changes_root(&mut self, _parent: H::Out, _parent_num: u64) -> Option { - None + fn storage_changes_root(&mut self, _parent: H::Out) -> Result, ()> { + Ok(None) } - fn submit_extrinsic(&mut self, _extrinsic: Vec) -> Result<(), ()> { - warn!("Call to submit_extrinsic without offchain externalities set."); - Err(()) + fn offchain(&mut self) -> Option<&mut dyn offchain::Externalities> { + warn!("Call to non-existent out offchain externalities set."); + None } } @@ -170,7 +171,7 @@ mod tests { #[test] fn commit_should_work() { let mut ext = BasicExternalities::default(); - let ext = &mut ext as &mut Externalities; + let ext = &mut ext as &mut dyn Externalities; ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec()); ext.set_storage(b"dog".to_vec(), b"puppy".to_vec()); ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec()); @@ -181,7 +182,7 @@ mod tests { #[test] fn set_and_retrieve_code() { let mut ext = BasicExternalities::default(); - let ext = &mut ext as &mut Externalities; + let ext = &mut ext as &mut dyn Externalities; let code = vec![1, 2, 3]; ext.set_storage(CODE.to_vec(), code.clone()); diff --git a/core/state-machine/src/changes_trie/build.rs b/core/state-machine/src/changes_trie/build.rs index 9af058515aca886b47680a5046435c7c2e888c91..487fde2e3528c434c23303126a22ab1aca1a06a0 100644 --- a/core/state-machine/src/changes_trie/build.rs +++ b/core/state-machine/src/changes_trie/build.rs @@ -19,12 +19,13 @@ use std::collections::{BTreeMap, BTreeSet}; use parity_codec::Decode; use hash_db::Hasher; +use num_traits::One; use crate::backend::Backend; use crate::overlayed_changes::OverlayedChanges; -use crate::trie_backend_essence::{TrieBackendStorage, TrieBackendEssence}; +use crate::trie_backend_essence::TrieBackendEssence; use crate::changes_trie::build_iterator::digest_build_iterator; use crate::changes_trie::input::{InputKey, InputPair, DigestIndex, ExtrinsicIndex}; -use crate::changes_trie::{AnchorBlockId, Configuration, Storage}; +use crate::changes_trie::{AnchorBlockId, Configuration, Storage, BlockNumber}; /// Prepare input pairs for building a changes trie of given block. /// @@ -32,29 +33,25 @@ use crate::changes_trie::{AnchorBlockId, Configuration, Storage}; /// required data. /// Returns Ok(None) data required to prepare input pairs is not collected /// or storage is not provided. -pub fn prepare_input<'a, B, S, H>( +pub fn prepare_input<'a, B, S, H, Number>( backend: &B, - storage: Option<&'a S>, + storage: &'a S, + config: &'a Configuration, changes: &OverlayedChanges, - parent: &'a AnchorBlockId, -) -> Result>, String> + parent: &'a AnchorBlockId, +) -> Result>>, String> where B: Backend, - S: Storage, - &'a S: TrieBackendStorage, + S: Storage, H: Hasher, + Number: BlockNumber, { - let (storage, config) = match (storage, changes.changes_trie_config.as_ref()) { - (Some(storage), Some(config)) => (storage, config), - _ => return Ok(None), - }; - let mut input = Vec::new(); input.extend(prepare_extrinsics_input( backend, - parent.number + 1, + parent.number.clone() + 1.into(), changes)?); - input.extend(prepare_digest_input::<_, H>( + input.extend(prepare_digest_input::<_, H, Number>( parent, config, storage)?); @@ -63,14 +60,15 @@ pub fn prepare_input<'a, B, S, H>( } /// Prepare ExtrinsicIndex input pairs. -fn prepare_extrinsics_input( +fn prepare_extrinsics_input( backend: &B, - block: u64, + block: Number, changes: &OverlayedChanges, -) -> Result, String> +) -> Result>, String> where B: Backend, H: Hasher, + Number: BlockNumber, { let mut extrinsic_map = BTreeMap::, BTreeSet>::new(); for (key, val) in changes.prospective.top.iter().chain(changes.committed.top.iter()) { @@ -93,47 +91,50 @@ fn prepare_extrinsics_input( Ok(extrinsic_map.into_iter() .map(move |(key, extrinsics)| InputPair::ExtrinsicIndex(ExtrinsicIndex { - block, + block: block.clone(), key, }, extrinsics.iter().cloned().collect()))) } /// Prepare DigestIndex input pairs. -fn prepare_digest_input<'a, S, H>( - parent: &'a AnchorBlockId, +fn prepare_digest_input<'a, S, H, Number>( + parent: &'a AnchorBlockId, config: &Configuration, storage: &'a S -) -> Result + 'a, String> +) -> Result> + 'a, String> where - S: Storage, - &'a S: TrieBackendStorage, + S: Storage, H: Hasher, H::Out: 'a, + Number: BlockNumber, { - let mut digest_map = BTreeMap::, BTreeSet>::new(); - for digest_build_block in digest_build_iterator(config, parent.number + 1) { - let trie_root = storage.root(parent, digest_build_block)?; - let trie_root = trie_root.ok_or_else(|| format!("No changes trie root for block {}", digest_build_block))?; - let trie_storage = TrieBackendEssence::<_, H>::new(storage, trie_root); + let mut digest_map = BTreeMap::, BTreeSet>::new(); + for digest_build_block in digest_build_iterator(config, parent.number.clone() + One::one()) { + let trie_root = storage.root(parent, digest_build_block.clone())?; + let trie_root = trie_root.ok_or_else(|| format!("No changes trie root for block {}", digest_build_block.clone()))?; + let trie_storage = TrieBackendEssence::<_, H>::new( + crate::changes_trie::TrieBackendStorageAdapter(storage), + trie_root, + ); - let extrinsic_prefix = ExtrinsicIndex::key_neutral_prefix(digest_build_block); + let extrinsic_prefix = ExtrinsicIndex::key_neutral_prefix(digest_build_block.clone()); trie_storage.for_keys_with_prefix(&extrinsic_prefix, |key| - if let Some(InputKey::ExtrinsicIndex(trie_key)) = Decode::decode(&mut &key[..]) { + if let Some(InputKey::ExtrinsicIndex::(trie_key)) = Decode::decode(&mut &key[..]) { digest_map.entry(trie_key.key).or_default() - .insert(digest_build_block); + .insert(digest_build_block.clone()); }); - let digest_prefix = DigestIndex::key_neutral_prefix(digest_build_block); + let digest_prefix = DigestIndex::key_neutral_prefix(digest_build_block.clone()); trie_storage.for_keys_with_prefix(&digest_prefix, |key| - if let Some(InputKey::DigestIndex(trie_key)) = Decode::decode(&mut &key[..]) { + if let Some(InputKey::DigestIndex::(trie_key)) = Decode::decode(&mut &key[..]) { digest_map.entry(trie_key.key).or_default() - .insert(digest_build_block); + .insert(digest_build_block.clone()); }); } Ok(digest_map.into_iter() .map(move |(key, set)| InputPair::DigestIndex(DigestIndex { - block: parent.number + 1, + block: parent.number.clone() + One::one(), key }, set.into_iter().collect()))) } @@ -148,7 +149,7 @@ mod test { use crate::overlayed_changes::OverlayedValue; use super::*; - fn prepare_for_build() -> (InMemory, InMemoryStorage, OverlayedChanges) { + fn prepare_for_build() -> (InMemory, InMemoryStorage, OverlayedChanges) { let backend: InMemory<_> = vec![ (vec![100], vec![255]), (vec![101], vec![255]), @@ -225,7 +226,14 @@ mod test { #[test] fn build_changes_trie_nodes_on_non_digest_block() { let (backend, storage, changes) = prepare_for_build(); - let changes_trie_nodes = prepare_input(&backend, Some(&storage), &changes, &AnchorBlockId { hash: Default::default(), number: 4 }).unwrap(); + let config = changes.changes_trie_config.as_ref().unwrap(); + let changes_trie_nodes = prepare_input( + &backend, + &storage, + config, + &changes, + &AnchorBlockId { hash: Default::default(), number: 4 }, + ).unwrap(); assert_eq!(changes_trie_nodes, Some(vec![ InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 5, key: vec![100] }, vec![0, 2, 3]), InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 5, key: vec![101] }, vec![1]), @@ -236,7 +244,14 @@ mod test { #[test] fn build_changes_trie_nodes_on_digest_block_l1() { let (backend, storage, changes) = prepare_for_build(); - let changes_trie_nodes = prepare_input(&backend, Some(&storage), &changes, &AnchorBlockId { hash: Default::default(), number: 3 }).unwrap(); + let config = changes.changes_trie_config.as_ref().unwrap(); + let changes_trie_nodes = prepare_input( + &backend, + &storage, + config, + &changes, + &AnchorBlockId { hash: Default::default(), number: 3 }, + ).unwrap(); assert_eq!(changes_trie_nodes, Some(vec![ InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![100] }, vec![0, 2, 3]), InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![101] }, vec![1]), @@ -252,7 +267,14 @@ mod test { #[test] fn build_changes_trie_nodes_on_digest_block_l2() { let (backend, storage, changes) = prepare_for_build(); - let changes_trie_nodes = prepare_input(&backend, Some(&storage), &changes, &AnchorBlockId { hash: Default::default(), number: 15 }).unwrap(); + let config = changes.changes_trie_config.as_ref().unwrap(); + let changes_trie_nodes = prepare_input( + &backend, + &storage, + config, + &changes, + &AnchorBlockId { hash: Default::default(), number: 15 }, + ).unwrap(); assert_eq!(changes_trie_nodes, Some(vec![ InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 16, key: vec![100] }, vec![0, 2, 3]), InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 16, key: vec![101] }, vec![1]), @@ -276,7 +298,14 @@ mod test { extrinsics: Some(vec![1].into_iter().collect()) }); - let changes_trie_nodes = prepare_input(&backend, Some(&storage), &changes, &AnchorBlockId { hash: Default::default(), number: 3 }).unwrap(); + let config = changes.changes_trie_config.as_ref().unwrap(); + let changes_trie_nodes = prepare_input( + &backend, + &storage, + config, + &changes, + &AnchorBlockId { hash: Default::default(), number: 3 }, + ).unwrap(); assert_eq!(changes_trie_nodes, Some(vec![ InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![100] }, vec![0, 2, 3]), InputPair::ExtrinsicIndex(ExtrinsicIndex { block: 4, key: vec![101] }, vec![1]), diff --git a/core/state-machine/src/changes_trie/build_iterator.rs b/core/state-machine/src/changes_trie/build_iterator.rs index f9c6ba6e7b397021ca0c856499de012217815867..5d8a8318abf849739be1f94290bac006165e7677 100644 --- a/core/state-machine/src/changes_trie/build_iterator.rs +++ b/core/state-machine/src/changes_trie/build_iterator.rs @@ -17,13 +17,16 @@ //! Structures and functions to return blocks whose changes are to be included //! in given block' changes trie. -use crate::changes_trie::Configuration; +use crate::changes_trie::{Configuration, BlockNumber}; /// Returns iterator of OTHER blocks that are required for inclusion into /// changes trie of given block. -pub fn digest_build_iterator(config: &Configuration, block: u64) -> DigestBuildIterator { +pub fn digest_build_iterator( + config: &Configuration, + block: Number, +) -> DigestBuildIterator { // prepare digest build parameters - let (_, _, digest_step) = match config.digest_level_at_block(block) { + let (_, _, digest_step) = match config.digest_level_at_block(block.clone()) { Some((current_level, digest_interval, digest_step)) => (current_level, digest_interval, digest_step), None => return DigestBuildIterator::empty(), @@ -35,24 +38,26 @@ pub fn digest_build_iterator(config: &Configuration, block: u64) -> DigestBuildI /// Changes trie build iterator that returns numbers of OTHER blocks that are /// required for inclusion into changes trie of given block. #[derive(Debug)] -pub struct DigestBuildIterator { +pub struct DigestBuildIterator { /// Block we're building changes trie for. - block: u64, + block: Number, /// Interval for creation digest blocks. - digest_interval: u64, + digest_interval: u32, + /// Max step of blocks range. + max_step: u32, /// Step of current blocks range. - current_step: u64, + current_step: u32, /// Current blocks range. - current_range: Option<::std::iter::StepBy<::std::ops::Range>>, - /// Max step of blocks range. - max_step: u64, + current_range: Option>, } -impl DigestBuildIterator { +impl DigestBuildIterator { /// Create new digest build iterator. - pub fn new(block: u64, digest_interval: u64, max_step: u64) -> Self { + pub fn new(block: Number, digest_interval: u32, max_step: u32) -> Self { DigestBuildIterator { - block, digest_interval, max_step, + block, + digest_interval, + max_step, current_step: 0, current_range: None, } @@ -60,12 +65,12 @@ impl DigestBuildIterator { /// Create empty digest build iterator. pub fn empty() -> Self { - Self::new(0, 0, 0) + Self::new(0.into(), 0, 0) } } -impl Iterator for DigestBuildIterator { - type Item = u64; +impl Iterator for DigestBuildIterator { + type Item = Number; fn next(&mut self) -> Option { if let Some(next) = self.current_range.as_mut().and_then(|iter| iter.next()) { @@ -82,10 +87,11 @@ impl Iterator for DigestBuildIterator { } self.current_step = next_step; - self.current_range = Some( - ((self.block - self.current_step * self.digest_interval + self.current_step)..self.block) - .step_by(self.current_step as usize) - ); + self.current_range = Some(BlocksRange::new( + self.block.clone() - (self.current_step * self.digest_interval - self.current_step).into(), + self.block.clone(), + self.current_step.into(), + )); Some(self.current_range.as_mut() .expect("assigned one line above; qed") @@ -94,20 +100,52 @@ impl Iterator for DigestBuildIterator { } } +/// Blocks range iterator with builtin step_by support. +#[derive(Debug)] +struct BlocksRange { + current: Number, + end: Number, + step: Number, +} + +impl BlocksRange { + pub fn new(begin: Number, end: Number, step: Number) -> Self { + BlocksRange { + current: begin, + end, + step, + } + } +} + +impl Iterator for BlocksRange { + type Item = Number; + + fn next(&mut self) -> Option { + if self.current >= self.end { + return None; + } + + let current = Some(self.current.clone()); + self.current += self.step.clone(); + current + } +} + #[cfg(test)] mod tests { use super::*; - fn digest_build_iterator(digest_interval: u64, digest_levels: u32, block: u64) -> DigestBuildIterator { + fn digest_build_iterator(digest_interval: u32, digest_levels: u32, block: u64) -> DigestBuildIterator { super::digest_build_iterator(&Configuration { digest_interval, digest_levels }, block) } - fn digest_build_iterator_basic(digest_interval: u64, digest_levels: u32, block: u64) -> (u64, u64, u64) { + fn digest_build_iterator_basic(digest_interval: u32, digest_levels: u32, block: u64) -> (u64, u32, u32) { let iter = digest_build_iterator(digest_interval, digest_levels, block); (iter.block, iter.digest_interval, iter.max_step) } - fn digest_build_iterator_blocks(digest_interval: u64, digest_levels: u32, block: u64) -> Vec { + fn digest_build_iterator_blocks(digest_interval: u32, digest_levels: u32, block: u64) -> Vec { digest_build_iterator(digest_interval, digest_levels, block).collect() } @@ -122,7 +160,11 @@ mod tests { assert_eq!(digest_build_iterator_basic(4, 16, 2), empty, "digest is not required for this block"); assert_eq!(digest_build_iterator_basic(4, 16, 15), empty, "digest is not required for this block"); assert_eq!(digest_build_iterator_basic(4, 16, 17), empty, "digest is not required for this block"); - assert_eq!(digest_build_iterator_basic(::std::u64::MAX / 2 + 1, 16, ::std::u64::MAX), empty, "digest_interval * 2 is greater than u64::MAX"); + assert_eq!(digest_build_iterator_basic( + ::std::u32::MAX / 2 + 1, + 16, + ::std::u64::MAX, + ), empty, "digest_interval * 2 is greater than u64::MAX"); } #[test] diff --git a/core/state-machine/src/changes_trie/changes_iterator.rs b/core/state-machine/src/changes_trie/changes_iterator.rs index c8d6216926a1997990f6f4db9fc6774fed209494..0e4716ccab98a44028d44aa104ac9cc98ae3b8fb 100644 --- a/core/state-machine/src/changes_trie/changes_iterator.rs +++ b/core/state-machine/src/changes_trie/changes_iterator.rs @@ -21,8 +21,9 @@ use std::cell::RefCell; use std::collections::VecDeque; use parity_codec::{Decode, Encode}; use hash_db::{HashDB, Hasher}; +use num_traits::One; use trie::{Recorder, MemoryDB}; -use crate::changes_trie::{AnchorBlockId, Configuration, RootsStorage, Storage}; +use crate::changes_trie::{AnchorBlockId, Configuration, RootsStorage, Storage, BlockNumber}; use crate::changes_trie::input::{DigestIndex, ExtrinsicIndex, DigestIndexValue, ExtrinsicIndexValue}; use crate::changes_trie::storage::{TrieBackendAdapter, InMemoryStorage}; use crate::proving_backend::ProvingBackendEssence; @@ -31,25 +32,25 @@ use crate::trie_backend_essence::{TrieBackendEssence}; /// Return changes of given key at given blocks range. /// `max` is the number of best known block. /// Changes are returned in descending order (i.e. last block comes first). -pub fn key_changes<'a, S: Storage, H: Hasher>( +pub fn key_changes<'a, S: Storage, H: Hasher, Number: BlockNumber>( config: &'a Configuration, storage: &'a S, - begin: u64, - end: &'a AnchorBlockId, - max: u64, + begin: Number, + end: &'a AnchorBlockId, + max: Number, key: &'a [u8], -) -> Result, String> { +) -> Result, String> { // we can't query any roots before root - let max = ::std::cmp::min(max, end.number); + let max = ::std::cmp::min(max.clone(), end.number.clone()); Ok(DrilldownIterator { essence: DrilldownIteratorEssence { key, roots_storage: storage, storage, - begin, + begin: begin.clone(), end, - surface: surface_iterator(config, max, begin, end.number)?, + surface: surface_iterator(config, max, begin, end.number.clone())?, extrinsics: Default::default(), blocks: Default::default(), @@ -61,25 +62,25 @@ pub fn key_changes<'a, S: Storage, H: Hasher>( /// Returns proof of changes of given key at given blocks range. /// `max` is the number of best known block. -pub fn key_changes_proof, H: Hasher>( +pub fn key_changes_proof, H: Hasher, Number: BlockNumber>( config: &Configuration, storage: &S, - begin: u64, - end: &AnchorBlockId, - max: u64, + begin: Number, + end: &AnchorBlockId, + max: Number, key: &[u8], ) -> Result>, String> { // we can't query any roots before root - let max = ::std::cmp::min(max, end.number); + let max = ::std::cmp::min(max.clone(), end.number.clone()); let mut iter = ProvingDrilldownIterator { essence: DrilldownIteratorEssence { key, roots_storage: storage.clone(), storage, - begin, + begin: begin.clone(), end, - surface: surface_iterator(config, max, begin, end.number)?, + surface: surface_iterator(config, max, begin, end.number.clone())?, extrinsics: Default::default(), blocks: Default::default(), @@ -100,17 +101,17 @@ pub fn key_changes_proof, H: Hasher>( /// Check key changes proog and return changes of the key at given blocks range. /// `max` is the number of best known block. /// Changes are returned in descending order (i.e. last block comes first). -pub fn key_changes_proof_check, H: Hasher>( +pub fn key_changes_proof_check, H: Hasher, Number: BlockNumber>( config: &Configuration, roots_storage: &S, proof: Vec>, - begin: u64, - end: &AnchorBlockId, - max: u64, + begin: Number, + end: &AnchorBlockId, + max: Number, key: &[u8] -) -> Result, String> { +) -> Result, String> { // we can't query any roots before root - let max = ::std::cmp::min(max, end.number); + let max = ::std::cmp::min(max.clone(), end.number.clone()); let mut proof_db = MemoryDB::::default(); for item in proof { @@ -123,9 +124,9 @@ pub fn key_changes_proof_check, H: Hasher>( key, roots_storage, storage: &proof_db, - begin, + begin: begin.clone(), end, - surface: surface_iterator(config, max, begin, end.number)?, + surface: surface_iterator(config, max, begin, end.number.clone())?, extrinsics: Default::default(), blocks: Default::default(), @@ -137,36 +138,36 @@ pub fn key_changes_proof_check, H: Hasher>( /// Surface iterator - only traverses top-level digests from given range and tries to find /// all digest changes for the key. -pub struct SurfaceIterator<'a> { +pub struct SurfaceIterator<'a, Number: BlockNumber> { config: &'a Configuration, - begin: u64, - max: u64, - current: Option, - current_begin: u64, - digest_step: u64, + begin: Number, + max: Number, + current: Option, + current_begin: Number, + digest_step: u32, digest_level: u32, } -impl<'a> Iterator for SurfaceIterator<'a> { - type Item = Result<(u64, u32), String>; +impl<'a, Number: BlockNumber> Iterator for SurfaceIterator<'a, Number> { + type Item = Result<(Number, u32), String>; fn next(&mut self) -> Option { - let current = self.current?; + let current = self.current.clone()?; let digest_level = self.digest_level; - if current < self.digest_step { + if current < self.digest_step.into() { self.current = None; } else { - let next = current - self.digest_step; - if next == 0 || next < self.begin { + let next = current.clone() - self.digest_step.into(); + if next.is_zero() || next < self.begin { self.current = None; } else if next > self.current_begin { self.current = Some(next); } else { let (current, current_begin, digest_step, digest_level) = match - lower_bound_max_digest(self.config, self.max, self.begin, next) { + lower_bound_max_digest(self.config, self.max.clone(), self.begin.clone(), next) { Err(err) => return Some(Err(err)), Ok(range) => range, }; @@ -184,22 +185,36 @@ impl<'a> Iterator for SurfaceIterator<'a> { /// Drilldown iterator - receives 'digest points' from surface iterator and explores /// every point until extrinsic is found. -pub struct DrilldownIteratorEssence<'a, RS: 'a + RootsStorage, S: 'a + Storage, H: Hasher> where H::Out: 'a { +pub struct DrilldownIteratorEssence<'a, RS, S, H, Number> + where + RS: 'a + RootsStorage, + S: 'a + Storage, + H: Hasher, + Number: BlockNumber, + H::Out: 'a, +{ key: &'a [u8], roots_storage: &'a RS, storage: &'a S, - begin: u64, - end: &'a AnchorBlockId, - surface: SurfaceIterator<'a>, + begin: Number, + end: &'a AnchorBlockId, + surface: SurfaceIterator<'a, Number>, - extrinsics: VecDeque<(u64, u32)>, - blocks: VecDeque<(u64, u32)>, + extrinsics: VecDeque<(Number, u32)>, + blocks: VecDeque<(Number, u32)>, _hasher: ::std::marker::PhantomData, } -impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> DrilldownIteratorEssence<'a, RS, S, H> { - pub fn next(&mut self, trie_reader: F) -> Option> +impl<'a, RS, S, H, Number> DrilldownIteratorEssence<'a, RS, S, H, Number> + where + RS: 'a + RootsStorage, + S: 'a + Storage, + H: Hasher, + Number: BlockNumber, + H::Out: 'a, +{ + pub fn next(&mut self, trie_reader: F) -> Option> where F: FnMut(&S, H::Out, &[u8]) -> Result>, String>, { @@ -210,7 +225,7 @@ impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> DrilldownIteratorEs } } - fn do_next(&mut self, mut trie_reader: F) -> Result, String> + fn do_next(&mut self, mut trie_reader: F) -> Result, String> where F: FnMut(&S, H::Out, &[u8]) -> Result>, String>, { @@ -223,33 +238,33 @@ impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> DrilldownIteratorEs // not having a changes trie root is an error because: // we never query roots for future blocks // AND trie roots for old blocks are known (both on full + light node) - let trie_root = self.roots_storage.root(&self.end, block)? - .ok_or_else(|| format!("Changes trie root for block {} is not found", block))?; + let trie_root = self.roots_storage.root(&self.end, block.clone())? + .ok_or_else(|| format!("Changes trie root for block {} is not found", block.clone()))?; // only return extrinsics for blocks before self.max // most of blocks will be filtered out before pushing to `self.blocks` // here we just throwing away changes at digest blocks we're processing debug_assert!(block >= self.begin, "We shall not touch digests earlier than a range' begin"); if block <= self.end.number { - let extrinsics_key = ExtrinsicIndex { block, key: self.key.to_vec() }.encode(); + let extrinsics_key = ExtrinsicIndex { block: block.clone(), key: self.key.to_vec() }.encode(); let extrinsics = trie_reader(&self.storage, trie_root, &extrinsics_key); if let Some(extrinsics) = extrinsics? { let extrinsics: Option = Decode::decode(&mut &extrinsics[..]); if let Some(extrinsics) = extrinsics { - self.extrinsics.extend(extrinsics.into_iter().rev().map(|e| (block, e))); + self.extrinsics.extend(extrinsics.into_iter().rev().map(|e| (block.clone(), e))); } } } - let blocks_key = DigestIndex { block, key: self.key.to_vec() }.encode(); + let blocks_key = DigestIndex { block: block.clone(), key: self.key.to_vec() }.encode(); let blocks = trie_reader(&self.storage, trie_root, &blocks_key); if let Some(blocks) = blocks? { - let blocks: Option = Decode::decode(&mut &blocks[..]); + let blocks: Option> = Decode::decode(&mut &blocks[..]); if let Some(blocks) = blocks { // filter level0 blocks here because we tend to use digest blocks, // AND digest block changes could also include changes for out-of-range blocks - let begin = self.begin; - let end = self.end.number; + let begin = self.begin.clone(); + let end = self.end.number.clone(); self.blocks.extend(blocks.into_iter() .rev() .filter(|b| level > 1 || (*b >= begin && *b <= end)) @@ -271,14 +286,21 @@ impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> DrilldownIteratorEs } /// Exploring drilldown operator. -pub struct DrilldownIterator<'a, RS: 'a + RootsStorage, S: 'a + Storage, H: Hasher> where H::Out: 'a { - essence: DrilldownIteratorEssence<'a, RS, S, H>, +pub struct DrilldownIterator<'a, RS, S, H, Number> + where + Number: BlockNumber, + H: Hasher, + S: 'a + Storage, + RS: 'a + RootsStorage, + H::Out: 'a, +{ + essence: DrilldownIteratorEssence<'a, RS, S, H, Number>, } -impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> Iterator - for DrilldownIterator<'a, RS, S, H> +impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher, Number: BlockNumber> Iterator + for DrilldownIterator<'a, RS, S, H, Number> { - type Item = Result<(u64, u32), String>; + type Item = Result<(Number, u32), String>; fn next(&mut self) -> Option { self.essence.next(|storage, root, key| @@ -287,12 +309,26 @@ impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> Iterator } /// Proving drilldown iterator. -struct ProvingDrilldownIterator<'a, RS: 'a + RootsStorage, S: 'a + Storage, H: Hasher> where H::Out: 'a { - essence: DrilldownIteratorEssence<'a, RS, S, H>, +struct ProvingDrilldownIterator<'a, RS, S, H, Number> + where + Number: BlockNumber, + H: Hasher, + S: 'a + Storage, + RS: 'a + RootsStorage, + H::Out: 'a, +{ + essence: DrilldownIteratorEssence<'a, RS, S, H, Number>, proof_recorder: RefCell>, } -impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> ProvingDrilldownIterator<'a, RS, S, H> { +impl<'a, RS, S, H, Number> ProvingDrilldownIterator<'a, RS, S, H, Number> + where + Number: BlockNumber, + H: Hasher, + S: 'a + Storage, + RS: 'a + RootsStorage, + H::Out: 'a, +{ /// Consume the iterator, extracting the gathered proof in lexicographical order /// by value. pub fn extract_proof(self) -> Vec> { @@ -303,8 +339,15 @@ impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> ProvingDrilldownIte } } -impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> Iterator for ProvingDrilldownIterator<'a, RS, S, H> { - type Item = Result<(u64, u32), String>; +impl<'a, RS, S, H, Number> Iterator for ProvingDrilldownIterator<'a, RS, S, H, Number> + where + Number: BlockNumber, + H: Hasher, + S: 'a + Storage, + RS: 'a + RootsStorage, + H::Out: 'a, +{ + type Item = Result<(Number, u32), String>; fn next(&mut self) -> Option { let proof_recorder = &mut *self.proof_recorder.try_borrow_mut() @@ -318,8 +361,18 @@ impl<'a, RS: 'a + RootsStorage, S: Storage, H: Hasher> Iterator for Provin } /// Returns surface iterator for given range of blocks. -fn surface_iterator<'a>(config: &'a Configuration, max: u64, begin: u64, end: u64) -> Result, String> { - let (current, current_begin, digest_step, digest_level) = lower_bound_max_digest(config, max, begin, end)?; +fn surface_iterator<'a, Number: BlockNumber>( + config: &'a Configuration, + max: Number, + begin: Number, + end: Number, +) -> Result, String> { + let (current, current_begin, digest_step, digest_level) = lower_bound_max_digest( + config, + max.clone(), + begin.clone(), + end, + )?; Ok(SurfaceIterator { config, begin, @@ -333,31 +386,32 @@ fn surface_iterator<'a>(config: &'a Configuration, max: u64, begin: u64, end: u6 /// Returns parameters of highest level digest block that includes the end of given range /// and tends to include the whole range. -fn lower_bound_max_digest( +fn lower_bound_max_digest( config: &Configuration, - max: u64, - begin: u64, - end: u64, -) -> Result<(u64, u64, u64, u32), String> { + max: Number, + begin: Number, + end: Number, +) -> Result<(Number, Number, u32, u32), String> { if end > max || begin > end { return Err("invalid changes range".into()); } let mut digest_level = 0u32; - let mut digest_step = 1u64; - let mut digest_interval = 0u64; - let mut current = end; - let mut current_begin = begin; - if begin != end { + let mut digest_step = 1u32; + let mut digest_interval = 0u32; + let mut current = end.clone(); + let mut current_begin = begin.clone(); + if current_begin != current { while digest_level != config.digest_levels { let new_digest_level = digest_level + 1; let new_digest_step = digest_step * config.digest_interval; let new_digest_interval = config.digest_interval * { if digest_interval == 0 { 1 } else { digest_interval } }; - let new_digest_begin = ((current - 1) / new_digest_interval) * new_digest_interval; - let new_digest_end = new_digest_begin + new_digest_interval; - let new_current = new_digest_begin + new_digest_interval; + let new_digest_begin = ((current.clone() - One::one()) + / new_digest_interval.into()) * new_digest_interval.into(); + let new_digest_end = new_digest_begin.clone() + new_digest_interval.into(); + let new_current = new_digest_begin.clone() + new_digest_interval.into(); if new_digest_end > max { if begin < new_digest_begin { @@ -372,7 +426,7 @@ fn lower_bound_max_digest( current = new_current; current_begin = new_digest_begin; - if new_digest_begin <= begin && new_digest_end >= end { + if current_begin <= begin && new_digest_end >= end { break; } } @@ -394,7 +448,7 @@ mod tests { use crate::changes_trie::storage::InMemoryStorage; use super::*; - fn prepare_for_drilldown() -> (Configuration, InMemoryStorage) { + fn prepare_for_drilldown() -> (Configuration, InMemoryStorage) { let config = Configuration { digest_interval: 4, digest_levels: 2 }; let backend = InMemoryStorage::with_inputs(vec![ // digest: 1..4 => [(3, 0)] @@ -436,27 +490,27 @@ mod tests { #[test] fn drilldown_iterator_works() { let (config, storage) = prepare_for_drilldown(); - let drilldown_result = key_changes::, Blake2Hasher>( + let drilldown_result = key_changes::, Blake2Hasher, u64>( &config, &storage, 0, &AnchorBlockId { hash: Default::default(), number: 16 }, 16, &[42]) .and_then(Result::from_iter); assert_eq!(drilldown_result, Ok(vec![(8, 2), (8, 1), (6, 3), (3, 0)])); - let drilldown_result = key_changes::, Blake2Hasher>( + let drilldown_result = key_changes::, Blake2Hasher, u64>( &config, &storage, 0, &AnchorBlockId { hash: Default::default(), number: 2 }, 4, &[42]) .and_then(Result::from_iter); assert_eq!(drilldown_result, Ok(vec![])); - let drilldown_result = key_changes::, Blake2Hasher>( + let drilldown_result = key_changes::, Blake2Hasher, u64>( &config, &storage, 0, &AnchorBlockId { hash: Default::default(), number: 3 }, 4, &[42]) .and_then(Result::from_iter); assert_eq!(drilldown_result, Ok(vec![(3, 0)])); - let drilldown_result = key_changes::, Blake2Hasher>( + let drilldown_result = key_changes::, Blake2Hasher, u64>( &config, &storage, 7, &AnchorBlockId { hash: Default::default(), number: 8 }, 8, &[42]) .and_then(Result::from_iter); assert_eq!(drilldown_result, Ok(vec![(8, 2), (8, 1)])); - let drilldown_result = key_changes::, Blake2Hasher>( + let drilldown_result = key_changes::, Blake2Hasher, u64>( &config, &storage, 5, &AnchorBlockId { hash: Default::default(), number: 7 }, 8, &[42]) .and_then(Result::from_iter); assert_eq!(drilldown_result, Ok(vec![(6, 3)])); @@ -467,7 +521,7 @@ mod tests { let (config, storage) = prepare_for_drilldown(); storage.clear_storage(); - assert!(key_changes::, Blake2Hasher>( + assert!(key_changes::, Blake2Hasher, u64>( &config, &storage, 0, &AnchorBlockId { hash: Default::default(), number: 100 }, 1000, &[42]) .and_then(|i| i.collect::, _>>()).is_err()); } @@ -475,9 +529,9 @@ mod tests { #[test] fn drilldown_iterator_fails_when_range_is_invalid() { let (config, storage) = prepare_for_drilldown(); - assert!(key_changes::, Blake2Hasher>( + assert!(key_changes::, Blake2Hasher, u64>( &config, &storage, 0, &AnchorBlockId { hash: Default::default(), number: 100 }, 50, &[42]).is_err()); - assert!(key_changes::, Blake2Hasher>( + assert!(key_changes::, Blake2Hasher, u64>( &config, &storage, 20, &AnchorBlockId { hash: Default::default(), number: 10 }, 100, &[42]).is_err()); } @@ -488,7 +542,7 @@ mod tests { // create drilldown iterator that records all trie nodes during drilldown let (remote_config, remote_storage) = prepare_for_drilldown(); - let remote_proof = key_changes_proof::, Blake2Hasher>( + let remote_proof = key_changes_proof::, Blake2Hasher, u64>( &remote_config, &remote_storage, 0, &AnchorBlockId { hash: Default::default(), number: 16 }, 16, &[42]).unwrap(); @@ -497,7 +551,7 @@ mod tests { // create drilldown iterator that works the same, but only depends on trie let (local_config, local_storage) = prepare_for_drilldown(); local_storage.clear_storage(); - let local_result = key_changes_proof_check::, Blake2Hasher>( + let local_result = key_changes_proof_check::, Blake2Hasher, u64>( &local_config, &local_storage, remote_proof, 0, &AnchorBlockId { hash: Default::default(), number: 16 }, 16, &[42]); diff --git a/core/state-machine/src/changes_trie/input.rs b/core/state-machine/src/changes_trie/input.rs index 3154aff715c2ba79070b6ecd6dd3c49a77c0729b..ae939c028b3e1e02aaf4e504eb5e8db3820a459e 100644 --- a/core/state-machine/src/changes_trie/input.rs +++ b/core/state-machine/src/changes_trie/input.rs @@ -17,12 +17,13 @@ //! Different types of changes trie input pairs. use parity_codec::{Decode, Encode, Input, Output}; +use crate::changes_trie::BlockNumber; /// Key of { changed key => set of extrinsic indices } mapping. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct ExtrinsicIndex { +pub struct ExtrinsicIndex { /// Block at which this key has been inserted in the trie. - pub block: u64, + pub block: Number, /// Storage key this node is responsible for. pub key: Vec, } @@ -32,35 +33,35 @@ pub type ExtrinsicIndexValue = Vec; /// Key of { changed key => block/digest block numbers } mapping. #[derive(Clone, Debug, PartialEq, Eq)] -pub struct DigestIndex { +pub struct DigestIndex { /// Block at which this key has been inserted in the trie. - pub block: u64, + pub block: Number, /// Storage key this node is responsible for. pub key: Vec, } /// Value of { changed key => block/digest block numbers } mapping. -pub type DigestIndexValue = Vec; +pub type DigestIndexValue = Vec; /// Single input pair of changes trie. #[derive(Clone, Debug, PartialEq, Eq)] -pub enum InputPair { +pub enum InputPair { /// Element of { key => set of extrinsics where key has been changed } element mapping. - ExtrinsicIndex(ExtrinsicIndex, ExtrinsicIndexValue), + ExtrinsicIndex(ExtrinsicIndex, ExtrinsicIndexValue), /// Element of { key => set of blocks/digest blocks where key has been changed } element mapping. - DigestIndex(DigestIndex, DigestIndexValue), + DigestIndex(DigestIndex, DigestIndexValue), } /// Single input key of changes trie. #[derive(Clone, Debug, PartialEq, Eq)] -pub enum InputKey { +pub enum InputKey { /// Key of { key => set of extrinsics where key has been changed } element mapping. - ExtrinsicIndex(ExtrinsicIndex), + ExtrinsicIndex(ExtrinsicIndex), /// Key of { key => set of blocks/digest blocks where key has been changed } element mapping. - DigestIndex(DigestIndex), + DigestIndex(DigestIndex), } -impl Into<(Vec, Vec)> for InputPair { +impl Into<(Vec, Vec)> for InputPair { fn into(self) -> (Vec, Vec) { match self { InputPair::ExtrinsicIndex(key, value) => (key.encode(), value.encode()), @@ -69,8 +70,8 @@ impl Into<(Vec, Vec)> for InputPair { } } -impl Into for InputPair { - fn into(self) -> InputKey { +impl Into> for InputPair { + fn into(self) -> InputKey { match self { InputPair::ExtrinsicIndex(key, _) => InputKey::ExtrinsicIndex(key), InputPair::DigestIndex(key, _) => InputKey::DigestIndex(key), @@ -78,15 +79,15 @@ impl Into for InputPair { } } -impl ExtrinsicIndex { - pub fn key_neutral_prefix(block: u64) -> Vec { +impl ExtrinsicIndex { + pub fn key_neutral_prefix(block: Number) -> Vec { let mut prefix = vec![1]; prefix.extend(block.encode()); prefix } } -impl Encode for ExtrinsicIndex { +impl Encode for ExtrinsicIndex { fn encode_to(&self, dest: &mut W) { dest.push_byte(1); self.block.encode_to(dest); @@ -94,8 +95,8 @@ impl Encode for ExtrinsicIndex { } } -impl DigestIndex { - pub fn key_neutral_prefix(block: u64) -> Vec { +impl DigestIndex { + pub fn key_neutral_prefix(block: Number) -> Vec { let mut prefix = vec![2]; prefix.extend(block.encode()); prefix @@ -103,7 +104,7 @@ impl DigestIndex { } -impl Encode for DigestIndex { +impl Encode for DigestIndex { fn encode_to(&self, dest: &mut W) { dest.push_byte(2); self.block.encode_to(dest); @@ -111,7 +112,7 @@ impl Encode for DigestIndex { } } -impl Decode for InputKey { +impl Decode for InputKey { fn decode(input: &mut I) -> Option { match input.read_byte()? { 1 => Some(InputKey::ExtrinsicIndex(ExtrinsicIndex { @@ -133,17 +134,17 @@ mod tests { #[test] fn extrinsic_index_serialized_and_deserialized() { - let original = ExtrinsicIndex { block: 777, key: vec![42] }; + let original = ExtrinsicIndex { block: 777u64, key: vec![42] }; let serialized = original.encode(); - let deserialized: InputKey = Decode::decode(&mut &serialized[..]).unwrap(); + let deserialized: InputKey = Decode::decode(&mut &serialized[..]).unwrap(); assert_eq!(InputKey::ExtrinsicIndex(original), deserialized); } #[test] fn digest_index_serialized_and_deserialized() { - let original = DigestIndex { block: 777, key: vec![42] }; + let original = DigestIndex { block: 777u64, key: vec![42] }; let serialized = original.encode(); - let deserialized: InputKey = Decode::decode(&mut &serialized[..]).unwrap(); + let deserialized: InputKey = Decode::decode(&mut &serialized[..]).unwrap(); assert_eq!(InputKey::DigestIndex(original), deserialized); } } diff --git a/core/state-machine/src/changes_trie/mod.rs b/core/state-machine/src/changes_trie/mod.rs index f82d8b33df3c5192864738b742df94cf1a07b21b..7dc95fb5a7ba7350e930d93366ceb5cd1d695cfb 100644 --- a/core/state-machine/src/changes_trie/mod.rs +++ b/core/state-machine/src/changes_trie/mod.rs @@ -48,58 +48,116 @@ pub use self::prune::{prune, oldest_non_pruned_trie}; use hash_db::Hasher; use crate::backend::Backend; +use num_traits::{One, Zero}; +use parity_codec::{Decode, Encode}; use primitives; use crate::changes_trie::build::prepare_input; use crate::overlayed_changes::OverlayedChanges; -use crate::trie_backend_essence::TrieBackendStorage; use trie::{DBValue, trie_root}; /// Changes that are made outside of extrinsics are marked with this index; pub const NO_EXTRINSIC_INDEX: u32 = 0xffffffff; +/// Requirements for block number that can be used with changes tries. +pub trait BlockNumber: + Send + Sync + 'static + + ::std::fmt::Display + + Clone + + From + One + Zero + + PartialEq + Ord + + ::std::ops::Add + ::std::ops::Sub + + ::std::ops::Mul + ::std::ops::Div + + ::std::ops::Rem + + ::std::ops::AddAssign + + num_traits::CheckedMul + num_traits::CheckedSub + + Decode + Encode +{} + +impl BlockNumber for T where T: + Send + Sync + 'static + + ::std::fmt::Display + + Clone + + From + One + Zero + + PartialEq + Ord + + ::std::ops::Add + ::std::ops::Sub + + ::std::ops::Mul + ::std::ops::Div + + ::std::ops::Rem + + ::std::ops::AddAssign + + num_traits::CheckedMul + num_traits::CheckedSub + + Decode + Encode, +{} + /// Block identifier that could be used to determine fork of this block. #[derive(Debug)] -pub struct AnchorBlockId { +pub struct AnchorBlockId { /// Hash of this block. pub hash: Hash, /// Number of this block. - pub number: u64, + pub number: Number, } /// Changes trie storage. Provides access to trie roots and trie nodes. -pub trait RootsStorage: Send + Sync { +pub trait RootsStorage: Send + Sync { + /// Resolve hash of the block into anchor. + fn build_anchor(&self, hash: H::Out) -> Result, String>; /// Get changes trie root for the block with given number which is an ancestor (or the block /// itself) of the anchor_block (i.e. anchor_block.number >= block). - fn root(&self, anchor: &AnchorBlockId, block: u64) -> Result, String>; + fn root(&self, anchor: &AnchorBlockId, block: Number) -> Result, String>; } /// Changes trie storage. Provides access to trie roots and trie nodes. -pub trait Storage: RootsStorage { +pub trait Storage: RootsStorage { /// Get a trie node. fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String>; } +/// Changes trie storage -> trie backend essence adapter. +pub struct TrieBackendStorageAdapter<'a, H: Hasher, Number: BlockNumber>(pub &'a dyn Storage); + +impl<'a, H: Hasher, N: BlockNumber> crate::TrieBackendStorage for TrieBackendStorageAdapter<'a, H, N> { + type Overlay = trie::MemoryDB; + + fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String> { + self.0.get(key, prefix) + } +} + /// Changes trie configuration. pub type Configuration = primitives::ChangesTrieConfiguration; /// Compute the changes trie root and transaction for given block. -/// Returns None if there's no data to perform computation. -pub fn compute_changes_trie_root<'a, B: Backend, S: Storage, H: Hasher>( +/// Returns Err(()) if unknown `parent_hash` has been passed. +/// Returns Ok(None) if there's no data to perform computation. +/// Panics if background storage returns an error. +pub fn compute_changes_trie_root<'a, B: Backend, S: Storage, H: Hasher, Number: BlockNumber>( backend: &B, storage: Option<&'a S>, changes: &OverlayedChanges, - parent: &'a AnchorBlockId, -) -> Option<(H::Out, Vec<(Vec, Vec)>)> + parent_hash: H::Out, +) -> Result, Vec)>)>, ()> where - &'a S: TrieBackendStorage, - H::Out: Ord, + H::Out: Ord + 'static, { - let input_pairs = prepare_input::(backend, storage, changes, parent) - .expect("storage is not allowed to fail within runtime")?; - let transaction = input_pairs.into_iter() - .map(Into::into) - .collect::>(); - let root = trie_root::(transaction.iter().map(|(k, v)| (&*k, &*v))); - - Some((root, transaction)) + let (storage, config) = match (storage, changes.changes_trie_config.as_ref()) { + (Some(storage), Some(config)) => (storage, config), + _ => return Ok(None), + }; + + // build_anchor error should not be considered fatal + let parent = storage.build_anchor(parent_hash).map_err(|_| ())?; + + // storage errors are considered fatal (similar to situations when runtime fetches values from storage) + let input_pairs = prepare_input::(backend, storage, config, changes, &parent) + .expect("storage is not allowed to fail within runtime"); + match input_pairs { + Some(input_pairs) => { + let transaction = input_pairs.into_iter() + .map(Into::into) + .collect::>(); + let root = trie_root::(transaction.iter().map(|(k, v)| (&*k, &*v))); + + Ok(Some((root, transaction))) + }, + None => Ok(None), + } } diff --git a/core/state-machine/src/changes_trie/prune.rs b/core/state-machine/src/changes_trie/prune.rs index bbe5bb573b347c3ec17fb1716a3e295bfed5ce71..3aedf66f757129081c7c2417598ead6219968c96 100644 --- a/core/state-machine/src/changes_trie/prune.rs +++ b/core/state-machine/src/changes_trie/prune.rs @@ -19,24 +19,26 @@ use hash_db::Hasher; use trie::Recorder; use log::warn; +use num_traits::One; use crate::proving_backend::ProvingBackendEssence; use crate::trie_backend_essence::TrieBackendEssence; -use crate::changes_trie::{AnchorBlockId, Configuration, Storage}; +use crate::changes_trie::{AnchorBlockId, Configuration, Storage, BlockNumber}; use crate::changes_trie::storage::TrieBackendAdapter; /// Get number of oldest block for which changes trie is not pruned /// given changes trie configuration, pruning parameter and number of /// best finalized block. -pub fn oldest_non_pruned_trie( +pub fn oldest_non_pruned_trie( config: &Configuration, - min_blocks_to_keep: u64, - best_finalized_block: u64, -) -> u64 { + min_blocks_to_keep: Number, + best_finalized_block: Number, +) -> Number { let max_digest_interval = config.max_digest_interval(); - let max_digest_block = best_finalized_block - best_finalized_block % max_digest_interval; + let best_finalized_block_rem = best_finalized_block.clone() % max_digest_interval.into(); + let max_digest_block = best_finalized_block - best_finalized_block_rem; match pruning_range(config, min_blocks_to_keep, max_digest_block) { - Some((_, last_pruned_block)) => last_pruned_block + 1, - None => 1, + Some((_, last_pruned_block)) => last_pruned_block + One::one(), + None => One::one(), } } @@ -45,24 +47,32 @@ pub fn oldest_non_pruned_trie( /// `min_blocks_to_keep` blocks. We only prune changes tries at `max_digest_interval` /// ranges. /// Returns MemoryDB that contains all deleted changes tries nodes. -pub fn prune, H: Hasher, F: FnMut(H::Out)>( +pub fn prune, H: Hasher, Number: BlockNumber, F: FnMut(H::Out)>( config: &Configuration, storage: &S, - min_blocks_to_keep: u64, - current_block: &AnchorBlockId, + min_blocks_to_keep: Number, + current_block: &AnchorBlockId, mut remove_trie_node: F, -) -{ +) { // select range for pruning - let (first, last) = match pruning_range(config, min_blocks_to_keep, current_block.number) { + let (first, last) = match pruning_range(config, min_blocks_to_keep, current_block.number.clone()) { Some((first, last)) => (first, last), None => return, }; // delete changes trie for every block in range // FIXME: limit `max_digest_interval` so that this cycle won't involve huge ranges - for block in first..last+1 { - let root = match storage.root(current_block, block) { + let mut block = first; + loop { + if block >= last.clone() + One::one() { + break; + } + + let prev_block = block.clone(); + block += One::one(); + + let block = prev_block; + let root = match storage.root(current_block, block.clone()) { Ok(Some(root)) => root, Ok(None) => continue, Err(error) => { @@ -92,11 +102,15 @@ pub fn prune, H: Hasher, F: FnMut(H::Out)>( } /// Select blocks range (inclusive from both ends) for pruning changes tries in. -fn pruning_range(config: &Configuration, min_blocks_to_keep: u64, block: u64) -> Option<(u64, u64)> { +fn pruning_range( + config: &Configuration, + min_blocks_to_keep: Number, + block: Number, +) -> Option<(Number, Number)> { // compute number of changes tries we actually want to keep let (prune_interval, blocks_to_keep) = if config.is_digest_build_enabled() { // we only CAN prune at block where max-level-digest is created - let max_digest_interval = match config.digest_level_at_block(block) { + let max_digest_interval = match config.digest_level_at_block(block.clone()) { Some((digest_level, digest_interval, _)) if digest_level == config.digest_levels => digest_interval, _ => return None, @@ -108,7 +122,7 @@ fn pruning_range(config: &Configuration, min_blocks_to_keep: u64, block: u64) -> // number of blocks BEFORE current block where changes tries are not pruned ( max_digest_interval, - max_digest_intervals_to_keep.checked_mul(max_digest_interval) + max_digest_intervals_to_keep.checked_mul(&max_digest_interval.into()) ) } else { ( @@ -118,11 +132,11 @@ fn pruning_range(config: &Configuration, min_blocks_to_keep: u64, block: u64) -> }; // last block for which changes trie is pruned - let last_block_to_prune = blocks_to_keep.and_then(|b| block.checked_sub(b)); - let first_block_to_prune = last_block_to_prune.clone().and_then(|b| b.checked_sub(prune_interval)); + let last_block_to_prune = blocks_to_keep.and_then(|b| block.checked_sub(&b)); + let first_block_to_prune = last_block_to_prune.clone().and_then(|b| b.checked_sub(&prune_interval.into())); last_block_to_prune - .and_then(|last| first_block_to_prune.map(|first| (first + 1, last))) + .and_then(|last| first_block_to_prune.map(|first| (first + One::one(), last))) } /// Select pruning delay for the changes tries. To make sure we could build a changes @@ -133,13 +147,16 @@ fn pruning_range(config: &Configuration, min_blocks_to_keep: u64, block: u64) -> /// 0 or 1: means that only last changes trie is guaranteed to exists; /// 2: the last chnages trie + previous changes trie /// ... -fn max_digest_intervals_to_keep(min_blocks_to_keep: u64, max_digest_interval: u64) -> u64 { +fn max_digest_intervals_to_keep( + min_blocks_to_keep: Number, + max_digest_interval: u32, +) -> Number { // config.digest_level_at_block ensures that it is not zero debug_assert!(max_digest_interval != 0); - let max_digest_intervals_to_keep = min_blocks_to_keep / max_digest_interval; - if max_digest_intervals_to_keep == 0 { - 1 + let max_digest_intervals_to_keep = min_blocks_to_keep / max_digest_interval.into(); + if max_digest_intervals_to_keep.is_zero() { + One::one() } else { max_digest_intervals_to_keep } @@ -154,14 +171,14 @@ mod tests { use crate::changes_trie::storage::InMemoryStorage; use super::*; - fn config(interval: u64, levels: u32) -> Configuration { + fn config(interval: u32, levels: u32) -> Configuration { Configuration { digest_interval: interval, digest_levels: levels, } } - fn prune_by_collect, H: Hasher>( + fn prune_by_collect, H: Hasher>( config: &Configuration, storage: &S, min_blocks_to_keep: u64, @@ -175,7 +192,7 @@ mod tests { #[test] fn prune_works() { - fn prepare_storage() -> InMemoryStorage { + fn prepare_storage() -> InMemoryStorage { let mut mdb1 = MemoryDB::::default(); let root1 = insert_into_memory_db::(&mut mdb1, vec![(vec![10], vec![20])]).unwrap(); let mut mdb2 = MemoryDB::::default(); @@ -242,60 +259,60 @@ mod tests { #[test] fn pruning_range_works() { // DIGESTS ARE NOT CREATED + NO TRIES ARE PRUNED - assert_eq!(pruning_range(&config(10, 0), 2, 2), None); + assert_eq!(pruning_range(&config(10, 0), 2u64, 2u64), None); // DIGESTS ARE NOT CREATED + SOME TRIES ARE PRUNED - assert_eq!(pruning_range(&config(10, 0), 100, 110), Some((10, 10))); - assert_eq!(pruning_range(&config(10, 0), 100, 210), Some((110, 110))); + assert_eq!(pruning_range(&config(10, 0), 100u64, 110u64), Some((10, 10))); + assert_eq!(pruning_range(&config(10, 0), 100u64, 210u64), Some((110, 110))); // DIGESTS ARE CREATED + NO TRIES ARE PRUNED - assert_eq!(pruning_range(&config(10, 2), 2, 0), None); - assert_eq!(pruning_range(&config(10, 2), 30, 100), None); - assert_eq!(pruning_range(&config(::std::u64::MAX, 2), 1, 1024), None); - assert_eq!(pruning_range(&config(::std::u64::MAX, 2), ::std::u64::MAX, 1024), None); - assert_eq!(pruning_range(&config(32, 2), 2048, 512), None); - assert_eq!(pruning_range(&config(32, 2), 2048, 1024), None); + assert_eq!(pruning_range(&config(10, 2), 2u64, 0u64), None); + assert_eq!(pruning_range(&config(10, 2), 30u64, 100u64), None); + assert_eq!(pruning_range(&config(::std::u32::MAX, 2), 1u64, 1024u64), None); + assert_eq!(pruning_range(&config(::std::u32::MAX, 2), ::std::u64::MAX, 1024u64), None); + assert_eq!(pruning_range(&config(32, 2), 2048u64, 512u64), None); + assert_eq!(pruning_range(&config(32, 2), 2048u64, 1024u64), None); // DIGESTS ARE CREATED + SOME TRIES ARE PRUNED // when we do not want to keep any highest-level-digests // (system forces to keep at least one) - assert_eq!(pruning_range(&config(4, 2), 0, 32), Some((1, 16))); - assert_eq!(pruning_range(&config(4, 2), 0, 64), Some((33, 48))); + assert_eq!(pruning_range(&config(4, 2), 0u64, 32u64), Some((1, 16))); + assert_eq!(pruning_range(&config(4, 2), 0u64, 64u64), Some((33, 48))); // when we want to keep 1 (last) highest-level-digest - assert_eq!(pruning_range(&config(4, 2), 16, 32), Some((1, 16))); - assert_eq!(pruning_range(&config(4, 2), 16, 64), Some((33, 48))); + assert_eq!(pruning_range(&config(4, 2), 16u64, 32u64), Some((1, 16))); + assert_eq!(pruning_range(&config(4, 2), 16u64, 64u64), Some((33, 48))); // when we want to keep 1 (last) + 1 additional level digests - assert_eq!(pruning_range(&config(32, 2), 4096, 5120), Some((1, 1024))); - assert_eq!(pruning_range(&config(32, 2), 4096, 6144), Some((1025, 2048))); + assert_eq!(pruning_range(&config(32, 2), 4096u64, 5120u64), Some((1, 1024))); + assert_eq!(pruning_range(&config(32, 2), 4096u64, 6144u64), Some((1025, 2048))); } #[test] fn max_digest_intervals_to_keep_works() { - assert_eq!(max_digest_intervals_to_keep(1024, 1025), 1); - assert_eq!(max_digest_intervals_to_keep(1024, 1023), 1); - assert_eq!(max_digest_intervals_to_keep(1024, 512), 2); - assert_eq!(max_digest_intervals_to_keep(1024, 511), 2); - assert_eq!(max_digest_intervals_to_keep(1024, 100), 10); + assert_eq!(max_digest_intervals_to_keep(1024u64, 1025), 1u64); + assert_eq!(max_digest_intervals_to_keep(1024u64, 1023), 1u64); + assert_eq!(max_digest_intervals_to_keep(1024u64, 512), 2u64); + assert_eq!(max_digest_intervals_to_keep(1024u64, 511), 2u64); + assert_eq!(max_digest_intervals_to_keep(1024u64, 100), 10u64); } #[test] fn oldest_non_pruned_trie_works() { // when digests are not created at all - assert_eq!(oldest_non_pruned_trie(&config(0, 0), 100, 10), 1); - assert_eq!(oldest_non_pruned_trie(&config(0, 0), 100, 110), 11); + assert_eq!(oldest_non_pruned_trie(&config(0, 0), 100u64, 10u64), 1); + assert_eq!(oldest_non_pruned_trie(&config(0, 0), 100u64, 110u64), 11); // when only l1 digests are created - assert_eq!(oldest_non_pruned_trie(&config(100, 1), 100, 50), 1); - assert_eq!(oldest_non_pruned_trie(&config(100, 1), 100, 110), 1); - assert_eq!(oldest_non_pruned_trie(&config(100, 1), 100, 210), 101); + assert_eq!(oldest_non_pruned_trie(&config(100, 1), 100u64, 50u64), 1); + assert_eq!(oldest_non_pruned_trie(&config(100, 1), 100u64, 110u64), 1); + assert_eq!(oldest_non_pruned_trie(&config(100, 1), 100u64, 210u64), 101); // when l2 digests are created - assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100, 50), 1); - assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100, 110), 1); - assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100, 210), 1); - assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100, 10110), 1); - assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100, 20110), 10001); + assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100u64, 50u64), 1); + assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100u64, 110u64), 1); + assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100u64, 210u64), 1); + assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100u64, 10110u64), 1); + assert_eq!(oldest_non_pruned_trie(&config(100, 2), 100u64, 20110u64), 10001); } } diff --git a/core/state-machine/src/changes_trie/storage.rs b/core/state-machine/src/changes_trie/storage.rs index 8363ae422108a0fca727ba4ff7256cfa6ba0f559..8da205251532c595b986a71d54f65873f12382f9 100644 --- a/core/state-machine/src/changes_trie/storage.rs +++ b/core/state-machine/src/changes_trie/storage.rs @@ -16,12 +16,12 @@ //! Changes trie storage utilities. -use std::collections::HashMap; +use std::collections::BTreeMap; use hash_db::Hasher; use trie::DBValue; use trie::MemoryDB; use parking_lot::RwLock; -use crate::changes_trie::{AnchorBlockId, RootsStorage, Storage}; +use crate::changes_trie::{RootsStorage, Storage, AnchorBlockId, BlockNumber}; use crate::trie_backend_essence::TrieBackendStorage; #[cfg(test)] @@ -32,27 +32,27 @@ use crate::backend::insert_into_memory_db; use crate::changes_trie::input::InputPair; /// In-memory implementation of changes trie storage. -pub struct InMemoryStorage { - data: RwLock>, +pub struct InMemoryStorage { + data: RwLock>, } /// Adapter for using changes trie storage as a TrieBackendEssence' storage. -pub struct TrieBackendAdapter<'a, H: Hasher, S: 'a + Storage> { +pub struct TrieBackendAdapter<'a, H: Hasher, Number: BlockNumber, S: 'a + Storage> { storage: &'a S, - _hasher: ::std::marker::PhantomData, + _hasher: ::std::marker::PhantomData<(H, Number)>, } -struct InMemoryStorageData { - roots: HashMap, +struct InMemoryStorageData { + roots: BTreeMap, mdb: MemoryDB, } -impl InMemoryStorage { +impl InMemoryStorage { /// Create the storage from given in-memory database. pub fn with_db(mdb: MemoryDB) -> Self { Self { data: RwLock::new(InMemoryStorageData { - roots: HashMap::new(), + roots: BTreeMap::new(), mdb, }), } @@ -63,10 +63,20 @@ impl InMemoryStorage { Self::with_db(Default::default()) } + /// Create the storage with given blocks. + pub fn with_blocks(blocks: Vec<(Number, H::Out)>) -> Self { + Self { + data: RwLock::new(InMemoryStorageData { + roots: blocks.into_iter().collect(), + mdb: MemoryDB::default(), + }), + } + } + #[cfg(test)] - pub fn with_inputs(inputs: Vec<(u64, Vec)>) -> Self { + pub fn with_inputs(inputs: Vec<(Number, Vec>)>) -> Self { let mut mdb = MemoryDB::default(); - let mut roots = HashMap::new(); + let mut roots = BTreeMap::new(); for (block, pairs) in inputs { let root = insert_into_memory_db::(&mut mdb, pairs.into_iter().map(Into::into)); if let Some(root) = root { @@ -101,32 +111,44 @@ impl InMemoryStorage { } /// Insert changes trie for given block. - pub fn insert(&self, block: u64, changes_trie_root: H::Out, trie: MemoryDB) { + pub fn insert(&self, block: Number, changes_trie_root: H::Out, trie: MemoryDB) { let mut data = self.data.write(); data.roots.insert(block, changes_trie_root); data.mdb.consolidate(trie); } } -impl RootsStorage for InMemoryStorage { - fn root(&self, _anchor_block: &AnchorBlockId, block: u64) -> Result, String> { +impl RootsStorage for InMemoryStorage { + fn build_anchor(&self, parent_hash: H::Out) -> Result, String> { + self.data.read().roots.iter() + .find(|(_, v)| **v == parent_hash) + .map(|(k, _)| AnchorBlockId { hash: parent_hash, number: k.clone() }) + .ok_or_else(|| format!("Can't find associated number for block {:?}", parent_hash)) + } + + fn root(&self, _anchor_block: &AnchorBlockId, block: Number) -> Result, String> { Ok(self.data.read().roots.get(&block).cloned()) } } -impl Storage for InMemoryStorage { +impl Storage for InMemoryStorage { fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String> { MemoryDB::::get(&self.data.read().mdb, key, prefix) } } -impl<'a, H: Hasher, S: 'a + Storage> TrieBackendAdapter<'a, H, S> { +impl<'a, H: Hasher, Number: BlockNumber, S: 'a + Storage> TrieBackendAdapter<'a, H, Number, S> { pub fn new(storage: &'a S) -> Self { Self { storage, _hasher: Default::default() } } } -impl<'a, H: Hasher, S: 'a + Storage> TrieBackendStorage for TrieBackendAdapter<'a, H, S> { +impl<'a, H, Number, S> TrieBackendStorage for TrieBackendAdapter<'a, H, Number, S> + where + S: 'a + Storage, + Number: BlockNumber, + H: Hasher, +{ type Overlay = MemoryDB; fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String> { diff --git a/core/state-machine/src/ext.rs b/core/state-machine/src/ext.rs index 0f5a4e2ed55fdd675705cb95eebc7842ac93377c..5a0daeb3488b9179345b9c5c09b92bf4e71e1aaa 100644 --- a/core/state-machine/src/ext.rs +++ b/core/state-machine/src/ext.rs @@ -19,9 +19,10 @@ use std::{error, fmt, cmp::Ord}; use log::warn; use crate::backend::Backend; -use crate::changes_trie::{AnchorBlockId, Storage as ChangesTrieStorage, compute_changes_trie_root}; -use crate::{Externalities, OverlayedChanges, OffchainExt, ChildStorageKey}; +use crate::changes_trie::{Storage as ChangesTrieStorage, compute_changes_trie_root}; +use crate::{Externalities, OverlayedChanges, ChildStorageKey}; use hash_db::Hasher; +use primitives::offchain; use primitives::storage::well_known_keys::is_child_storage_key; use trie::{MemoryDB, TrieDBMut, TrieMut, default_child_trie_root}; @@ -57,10 +58,9 @@ impl error::Error for Error { } /// Wraps a read-only backend, call executor, and current overlayed changes. -pub struct Ext<'a, H, B, T, O> +pub struct Ext<'a, H, N, B, T, O> where H: Hasher, - B: 'a + Backend, { /// The overlayed changes to write to. @@ -78,20 +78,23 @@ where /// This differs from `storage_transaction` behavior, because the moment when /// `storage_changes_root` is called matters + we need to remember additional /// data at this moment (block number). - changes_trie_transaction: Option<(u64, MemoryDB, H::Out)>, + changes_trie_transaction: Option<(MemoryDB, H::Out)>, /// Additional externalities for offchain workers. /// /// If None, some methods from the trait might not supported. offchain_externalities: Option<&'a mut O>, + /// Dummy usage of N arg. + _phantom: ::std::marker::PhantomData, } -impl<'a, H, B, T, O> Ext<'a, H, B, T, O> +impl<'a, H, N, B, T, O> Ext<'a, H, N, B, T, O> where H: Hasher, B: 'a + Backend, - T: 'a + ChangesTrieStorage, - O: 'a + OffchainExt, - H::Out: Ord, + T: 'a + ChangesTrieStorage, + O: 'a + offchain::Externalities, + H::Out: Ord + 'static, + N: crate::changes_trie::BlockNumber, { /// Create a new `Ext` from overlayed changes and read-only backend pub fn new( @@ -107,6 +110,7 @@ where changes_trie_storage, changes_trie_transaction: None, offchain_externalities, + _phantom: Default::default(), } } @@ -118,7 +122,7 @@ where self.storage_transaction .expect("storage_transaction always set after calling storage root; qed"), self.changes_trie_transaction - .map(|(_, tx, _)| tx), + .map(|(tx, _)| tx), ); ( @@ -137,13 +141,13 @@ where } #[cfg(test)] -impl<'a, H, B, T, O> Ext<'a, H, B, T, O> +impl<'a, H, N, B, T, O> Ext<'a, H, N, B, T, O> where H: Hasher, - B: 'a + Backend, - T: 'a + ChangesTrieStorage, - O: 'a + OffchainExt, + T: 'a + ChangesTrieStorage, + O: 'a + offchain::Externalities, + N: crate::changes_trie::BlockNumber, { pub fn storage_pairs(&self) -> Vec<(Vec, Vec)> { use std::collections::HashMap; @@ -159,13 +163,14 @@ where } } -impl<'a, B, T, H, O> Externalities for Ext<'a, H, B, T, O> +impl<'a, B, T, H, N, O> Externalities for Ext<'a, H, N, B, T, O> where H: Hasher, B: 'a + Backend, - T: 'a + ChangesTrieStorage, - O: 'a + OffchainExt, - H::Out: Ord, + T: 'a + ChangesTrieStorage, + O: 'a + offchain::Externalities, + H::Out: Ord + 'static, + N: crate::changes_trie::BlockNumber, { fn storage(&self, key: &[u8]) -> Option> { let _guard = panic_handler::AbortGuard::new(true); @@ -302,7 +307,7 @@ where .flat_map(|map| map.1.iter().map(|(k, v)| (k.clone(), v.clone()))) .chain(self.overlay.prospective.children.get(storage_key) .into_iter() - .flat_map(|map| map.1.iter().map(|(k, v)| (k.clone(), v.clone())))); + .flat_map(|map| map.1.clone().into_iter())); let root = self.backend.child_storage_root(storage_key, delta).0; @@ -313,14 +318,14 @@ where } } - fn storage_changes_root(&mut self, parent: H::Out, parent_num: u64) -> Option { + fn storage_changes_root(&mut self, parent_hash: H::Out) -> Result, ()> { let _guard = panic_handler::AbortGuard::new(true); - let root_and_tx = compute_changes_trie_root::<_, T, H>( + let root_and_tx = compute_changes_trie_root::<_, T, H, N>( self.backend, self.changes_trie_storage.clone(), self.overlay, - &AnchorBlockId { hash: parent, number: parent_num }, - ); + parent_hash, + )?; let root_and_tx = root_and_tx.map(|(root, changes)| { let mut calculated_root = Default::default(); let mut mdb = MemoryDB::default(); @@ -331,22 +336,15 @@ where } } - (parent_num + 1, mdb, root) + (mdb, root) }); - let root = root_and_tx.as_ref().map(|(_, _, root)| root.clone()); + let root = root_and_tx.as_ref().map(|(_, root)| root.clone()); self.changes_trie_transaction = root_and_tx; - root + Ok(root) } - fn submit_extrinsic(&mut self, extrinsic: Vec) -> Result<(), ()> { - let _guard = panic_handler::AbortGuard::new(true); - if let Some(ext) = self.offchain_externalities.as_mut() { - ext.submit_extrinsic(extrinsic); - Ok(()) - } else { - warn!("Call to submit_extrinsic without offchain externalities set."); - Err(()) - } + fn offchain(&mut self) -> Option<&mut dyn offchain::Externalities> { + self.offchain_externalities.as_mut().map(|x| &mut **x as _) } } @@ -363,8 +361,8 @@ mod tests { use super::*; type TestBackend = InMemory; - type TestChangesTrieStorage = InMemoryChangesTrieStorage; - type TestExt<'a> = Ext<'a, Blake2Hasher, TestBackend, TestChangesTrieStorage, crate::NeverOffchainExt>; + type TestChangesTrieStorage = InMemoryChangesTrieStorage; + type TestExt<'a> = Ext<'a, Blake2Hasher, u64, TestBackend, TestChangesTrieStorage, crate::NeverOffchainExt>; fn prepare_overlay_with_changes() -> OverlayedChanges { OverlayedChanges { @@ -391,26 +389,26 @@ mod tests { let mut overlay = prepare_overlay_with_changes(); let backend = TestBackend::default(); let mut ext = TestExt::new(&mut overlay, &backend, None, None); - assert_eq!(ext.storage_changes_root(Default::default(), 100), None); + assert_eq!(ext.storage_changes_root(Default::default()).unwrap(), None); } #[test] fn storage_changes_root_is_none_when_extrinsic_changes_are_none() { let mut overlay = prepare_overlay_with_changes(); overlay.changes_trie_config = None; - let storage = TestChangesTrieStorage::new(); + let storage = TestChangesTrieStorage::with_blocks(vec![(100, Default::default())]); let backend = TestBackend::default(); let mut ext = TestExt::new(&mut overlay, &backend, Some(&storage), None); - assert_eq!(ext.storage_changes_root(Default::default(), 100), None); + assert_eq!(ext.storage_changes_root(Default::default()).unwrap(), None); } #[test] fn storage_changes_root_is_some_when_extrinsic_changes_are_non_empty() { let mut overlay = prepare_overlay_with_changes(); - let storage = TestChangesTrieStorage::new(); + let storage = TestChangesTrieStorage::with_blocks(vec![(99, Default::default())]); let backend = TestBackend::default(); let mut ext = TestExt::new(&mut overlay, &backend, Some(&storage), None); - assert_eq!(ext.storage_changes_root(Default::default(), 99), + assert_eq!(ext.storage_changes_root(Default::default()).unwrap(), Some(hex!("5b829920b9c8d554a19ee2a1ba593c4f2ee6fc32822d083e04236d693e8358d5").into())); } @@ -418,10 +416,10 @@ mod tests { fn storage_changes_root_is_some_when_extrinsic_changes_are_empty() { let mut overlay = prepare_overlay_with_changes(); overlay.prospective.top.get_mut(&vec![1]).unwrap().value = None; - let storage = TestChangesTrieStorage::new(); + let storage = TestChangesTrieStorage::with_blocks(vec![(99, Default::default())]); let backend = TestBackend::default(); let mut ext = TestExt::new(&mut overlay, &backend, Some(&storage), None); - assert_eq!(ext.storage_changes_root(Default::default(), 99), + assert_eq!(ext.storage_changes_root(Default::default()).unwrap(), Some(hex!("bcf494e41e29a15c9ae5caa053fe3cb8b446ee3e02a254efbdec7a19235b76e4").into())); } } diff --git a/core/state-machine/src/lib.rs b/core/state-machine/src/lib.rs index daf8f915a1167fc30b9984158e6643fbc2bdba02..93d70423d5f3fa57ebe73468816a7f6eb54b0ea4 100644 --- a/core/state-machine/src/lib.rs +++ b/core/state-machine/src/lib.rs @@ -24,7 +24,7 @@ use log::warn; use hash_db::Hasher; use parity_codec::{Decode, Encode}; use primitives::{ - storage::well_known_keys, NativeOrEncoded, NeverNativeValue, OffchainExt + storage::well_known_keys, NativeOrEncoded, NeverNativeValue, offchain }; pub mod backend; @@ -219,12 +219,10 @@ pub trait Externalities { fn child_storage_root(&mut self, storage_key: ChildStorageKey) -> Vec; /// Get the change trie root of the current storage overlay at a block with given parent. - fn storage_changes_root(&mut self, parent: H::Out, parent_num: u64) -> Option where H::Out: Ord; + fn storage_changes_root(&mut self, parent: H::Out) -> Result, ()> where H::Out: Ord; - /// Submit extrinsic. - /// - /// Returns an error in case the API is not available. - fn submit_extrinsic(&mut self, extrinsic: Vec) -> Result<(), ()>; + /// Returns offchain externalities extension if present. + fn offchain(&mut self) -> Option<&mut dyn offchain::Externalities>; } /// An implementation of offchain extensions that should never be triggered. @@ -237,8 +235,121 @@ impl NeverOffchainExt { } } -impl OffchainExt for NeverOffchainExt { - fn submit_extrinsic(&mut self, _extrinsic: Vec) { unreachable!() } +impl offchain::Externalities for NeverOffchainExt { + fn submit_transaction(&mut self, _extrinsic: Vec) -> Result<(), ()> { + unreachable!() + } + + fn new_crypto_key( + &mut self, + _crypto: offchain::CryptoKind, + ) -> Result { + unreachable!() + } + + fn encrypt( + &mut self, + _key: Option, + _data: &[u8], + ) -> Result, ()> { + unreachable!() + } + + fn decrypt( + &mut self, + _key: Option, + _data: &[u8], + ) -> Result, ()> { + unreachable!() + } + + fn sign(&mut self, _key: Option, _data: &[u8]) -> Result, ()> { + unreachable!() + } + + fn verify( + &mut self, + _key: Option, + _msg: &[u8], + _signature: &[u8], + ) -> Result { + unreachable!() + } + + fn timestamp(&mut self) -> offchain::Timestamp { + unreachable!() + } + + fn sleep_until(&mut self, _deadline: offchain::Timestamp) { + unreachable!() + } + + fn random_seed(&mut self) -> [u8; 32] { + unreachable!() + } + + fn local_storage_set(&mut self, _key: &[u8], _value: &[u8]) { + unreachable!() + } + + fn local_storage_compare_and_set(&mut self, _key: &[u8], _old_value: &[u8], _new_value: &[u8]) { + unreachable!() + } + + fn local_storage_get(&mut self, _key: &[u8]) -> Option> { + unreachable!() + } + + fn http_request_start( + &mut self, + _method: &str, + _uri: &str, + _meta: &[u8] + ) -> Result { + unreachable!() + } + + fn http_request_add_header( + &mut self, + _request_id: offchain::HttpRequestId, + _name: &str, + _value: &str + ) -> Result<(), ()> { + unreachable!() + } + + fn http_request_write_body( + &mut self, + _request_id: offchain::HttpRequestId, + _chunk: &[u8], + _deadline: Option + ) -> Result<(), offchain::HttpError> { + unreachable!() + } + + fn http_response_wait( + &mut self, + _ids: &[offchain::HttpRequestId], + _deadline: Option + ) -> Vec { + unreachable!() + } + + fn http_response_headers( + &mut self, + _request_id: offchain::HttpRequestId + ) -> Vec<(Vec, Vec)> { + unreachable!() + } + + fn http_response_read_body( + &mut self, + _request_id: offchain::HttpRequestId, + _buffer: &mut [u8], + _deadline: Option + ) -> Result { + unreachable!() + } } /// Code execution engine. @@ -338,7 +449,7 @@ pub fn always_wasm() -> ExecutionManager> { } /// Creates new substrate state machine. -pub fn new<'a, H, B, T, O, Exec>( +pub fn new<'a, H, N, B, T, O, Exec>( backend: &'a B, changes_trie_storage: Option<&'a T>, offchain_ext: Option<&'a mut O>, @@ -346,7 +457,7 @@ pub fn new<'a, H, B, T, O, Exec>( exec: &'a Exec, method: &'a str, call_data: &'a [u8], -) -> StateMachine<'a, H, B, T, O, Exec> { +) -> StateMachine<'a, H, N, B, T, O, Exec> { StateMachine { backend, changes_trie_storage, @@ -360,7 +471,7 @@ pub fn new<'a, H, B, T, O, Exec>( } /// The substrate state machine. -pub struct StateMachine<'a, H, B, T, O, Exec> { +pub struct StateMachine<'a, H, N, B, T, O, Exec> { backend: &'a B, changes_trie_storage: Option<&'a T>, offchain_ext: Option<&'a mut O>, @@ -368,16 +479,17 @@ pub struct StateMachine<'a, H, B, T, O, Exec> { exec: &'a Exec, method: &'a str, call_data: &'a [u8], - _hasher: PhantomData, + _hasher: PhantomData<(H, N)>, } -impl<'a, H, B, T, O, Exec> StateMachine<'a, H, B, T, O, Exec> where +impl<'a, H, N, B, T, O, Exec> StateMachine<'a, H, N, B, T, O, Exec> where H: Hasher, Exec: CodeExecutor, B: Backend, - T: ChangesTrieStorage, - O: OffchainExt, - H::Out: Ord, + T: ChangesTrieStorage, + O: offchain::Externalities, + H::Out: Ord + 'static, + N: crate::changes_trie::BlockNumber, { /// Execute a call using the given state backend, overlayed changes, and call executor. /// Produces a state-backend-specific "transaction" which can be used to apply the changes @@ -390,7 +502,7 @@ impl<'a, H, B, T, O, Exec> StateMachine<'a, H, B, T, O, Exec> where pub fn execute( &mut self, strategy: ExecutionStrategy, - ) -> Result<(Vec, B::Transaction, Option>), Box> { + ) -> Result<(Vec, B::Transaction, Option>), Box> { // We are not giving a native call and thus we are sure that the result can never be a native // value. self.execute_using_consensus_failure_handler::<_, NeverNativeValue, fn() -> _>( @@ -414,12 +526,11 @@ impl<'a, H, B, T, O, Exec> StateMachine<'a, H, B, T, O, Exec> where R: Decode + Encode + PartialEq, NC: FnOnce() -> result::Result + UnwindSafe, { - let offchain = self.offchain_ext.as_mut(); let mut externalities = ext::Ext::new( self.overlay, self.backend, self.changes_trie_storage, - offchain.map(|x| &mut **x), + self.offchain_ext.as_mut().map(|x| &mut **x), ); let (result, was_native) = self.exec.call( &mut externalities, @@ -502,7 +613,7 @@ impl<'a, H, B, T, O, Exec> StateMachine<'a, H, B, T, O, Exec> where manager: ExecutionManager, compute_tx: bool, mut native_call: Option, - ) -> Result<(NativeOrEncoded, Option, Option>), Box> where + ) -> Result<(NativeOrEncoded, Option, Option>), Box> where R: Decode + Encode + PartialEq, NC: FnOnce() -> result::Result + UnwindSafe, Handler: FnOnce( @@ -558,21 +669,21 @@ impl<'a, H, B, T, O, Exec> StateMachine<'a, H, B, T, O, Exec> where /// Prove execution using the given state backend, overlayed changes, and call executor. pub fn prove_execution( - backend: B, + mut backend: B, overlay: &mut OverlayedChanges, exec: &Exec, method: &str, call_data: &[u8], -) -> Result<(Vec, Vec>), Box> +) -> Result<(Vec, Vec>), Box> where B: Backend, H: Hasher, Exec: CodeExecutor, - H::Out: Ord, + H::Out: Ord + 'static, { - let trie_backend = backend.try_into_trie_backend() - .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; - prove_execution_on_trie_backend(&trie_backend, overlay, exec, method, call_data) + let trie_backend = backend.as_trie_backend() + .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; + prove_execution_on_trie_backend(trie_backend, overlay, exec, method, call_data) } /// Prove execution using the given trie backend, overlayed changes, and call executor. @@ -590,17 +701,17 @@ pub fn prove_execution_on_trie_backend( exec: &Exec, method: &str, call_data: &[u8], -) -> Result<(Vec, Vec>), Box> +) -> Result<(Vec, Vec>), Box> where S: trie_backend_essence::TrieBackendStorage, H: Hasher, Exec: CodeExecutor, - H::Out: Ord, + H::Out: Ord + 'static, { let proving_backend = proving_backend::ProvingBackend::new(trie_backend); let mut sm = StateMachine { backend: &proving_backend, - changes_trie_storage: None as Option<&changes_trie::InMemoryStorage>, + changes_trie_storage: None as Option<&changes_trie::InMemoryStorage>, offchain_ext: NeverOffchainExt::new(), overlay, exec, @@ -625,11 +736,11 @@ pub fn execution_proof_check( exec: &Exec, method: &str, call_data: &[u8], -) -> Result, Box> +) -> Result, Box> where H: Hasher, Exec: CodeExecutor, - H::Out: Ord, + H::Out: Ord + 'static, { let trie_backend = create_proof_check_backend::(root.into(), proof)?; execution_proof_check_on_trie_backend(&trie_backend, overlay, exec, method, call_data) @@ -642,15 +753,15 @@ pub fn execution_proof_check_on_trie_backend( exec: &Exec, method: &str, call_data: &[u8], -) -> Result, Box> +) -> Result, Box> where H: Hasher, Exec: CodeExecutor, - H::Out: Ord, + H::Out: Ord + 'static, { let mut sm = StateMachine { backend: trie_backend, - changes_trie_storage: None as Option<&changes_trie::InMemoryStorage>, + changes_trie_storage: None as Option<&changes_trie::InMemoryStorage>, offchain_ext: NeverOffchainExt::new(), overlay, exec, @@ -667,35 +778,35 @@ where /// Generate storage read proof. pub fn prove_read( - backend: B, + mut backend: B, key: &[u8] -) -> Result<(Option>, Vec>), Box> +) -> Result<(Option>, Vec>), Box> where B: Backend, H: Hasher, H::Out: Ord { - let trie_backend = backend.try_into_trie_backend() + let trie_backend = backend.as_trie_backend() .ok_or_else( - ||Box::new(ExecutionError::UnableToGenerateProof) as Box + ||Box::new(ExecutionError::UnableToGenerateProof) as Box )?; - prove_read_on_trie_backend(&trie_backend, key) + prove_read_on_trie_backend(trie_backend, key) } /// Generate child storage read proof. pub fn prove_child_read( - backend: B, + mut backend: B, storage_key: &[u8], key: &[u8], -) -> Result<(Option>, Vec>), Box> +) -> Result<(Option>, Vec>), Box> where B: Backend, H: Hasher, H::Out: Ord { - let trie_backend = backend.try_into_trie_backend() - .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; - prove_child_read_on_trie_backend(&trie_backend, storage_key, key) + let trie_backend = backend.as_trie_backend() + .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; + prove_child_read_on_trie_backend(trie_backend, storage_key, key) } @@ -703,14 +814,14 @@ where pub fn prove_read_on_trie_backend( trie_backend: &TrieBackend, key: &[u8] -) -> Result<(Option>, Vec>), Box> +) -> Result<(Option>, Vec>), Box> where S: trie_backend_essence::TrieBackendStorage, H: Hasher, H::Out: Ord { let proving_backend = proving_backend::ProvingBackend::<_, H>::new(trie_backend); - let result = proving_backend.storage(key).map_err(|e| Box::new(e) as Box)?; + let result = proving_backend.storage(key).map_err(|e| Box::new(e) as Box)?; Ok((result, proving_backend.extract_proof())) } @@ -719,15 +830,14 @@ pub fn prove_child_read_on_trie_backend( trie_backend: &TrieBackend, storage_key: &[u8], key: &[u8] -) -> Result<(Option>, Vec>), Box> +) -> Result<(Option>, Vec>), Box> where S: trie_backend_essence::TrieBackendStorage, H: Hasher, H::Out: Ord { let proving_backend = proving_backend::ProvingBackend::<_, H>::new(trie_backend); - let result = proving_backend.child_storage(storage_key, key) - .map_err(|e| Box::new(e) as Box)?; + let result = proving_backend.child_storage(storage_key, key).map_err(|e| Box::new(e) as Box)?; Ok((result, proving_backend.extract_proof())) } @@ -736,7 +846,7 @@ pub fn read_proof_check( root: H::Out, proof: Vec>, key: &[u8], -) -> Result>, Box> +) -> Result>, Box> where H: Hasher, H::Out: Ord @@ -751,7 +861,7 @@ pub fn read_child_proof_check( proof: Vec>, storage_key: &[u8], key: &[u8], -) -> Result>, Box> +) -> Result>, Box> where H: Hasher, H::Out: Ord @@ -765,12 +875,12 @@ where pub fn read_proof_check_on_proving_backend( proving_backend: &TrieBackend, H>, key: &[u8], -) -> Result>, Box> +) -> Result>, Box> where H: Hasher, H::Out: Ord { - proving_backend.storage(key).map_err(|e| Box::new(e) as Box) + proving_backend.storage(key).map_err(|e| Box::new(e) as Box) } /// Check child storage read proof on pre-created proving backend. @@ -778,20 +888,24 @@ pub fn read_child_proof_check_on_proving_backend( proving_backend: &TrieBackend, H>, storage_key: &[u8], key: &[u8], -) -> Result>, Box> +) -> Result>, Box> where H: Hasher, H::Out: Ord { - proving_backend.child_storage(storage_key, key).map_err(|e| Box::new(e) as Box) + proving_backend.child_storage(storage_key, key).map_err(|e| Box::new(e) as Box) } /// Sets overlayed changes' changes trie configuration. Returns error if configuration /// differs from previous OR config decode has failed. -pub(crate) fn set_changes_trie_config(overlay: &mut OverlayedChanges, config: Option>, final_check: bool) -> Result<(), Box> { +pub(crate) fn set_changes_trie_config( + overlay: &mut OverlayedChanges, + config: Option>, + final_check: bool, +) -> Result<(), Box> { let config = match config { Some(v) => Some(Decode::decode(&mut &v[..]) - .ok_or_else(|| Box::new("Failed to decode changes trie configuration".to_owned()) as Box)?), + .ok_or_else(|| Box::new("Failed to decode changes trie configuration".to_owned()) as Box)?), None => None, }; @@ -809,16 +923,16 @@ pub(crate) fn set_changes_trie_config(overlay: &mut OverlayedChanges, config: Op /// Reads storage value from overlay or from the backend. fn try_read_overlay_value(overlay: &OverlayedChanges, backend: &B, key: &[u8]) - -> Result>, Box> + -> Result>, Box> where H: Hasher, - B: Backend, { match overlay.storage(key).map(|x| x.map(|x| x.to_vec())) { Some(value) => Ok(value), - None => backend.storage(key) - .map_err(|err| Box::new(ExecutionError::Backend(format!("{}", err))) as Box), + None => backend + .storage(key) + .map_err(|err| Box::new(ExecutionError::Backend(format!("{}", err))) as Box), } } @@ -892,7 +1006,7 @@ mod tests { fn execute_works() { assert_eq!(new( &trie_backend::tests::test_trie(), - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::::new()), NeverOffchainExt::new(), &mut Default::default(), &DummyCodeExecutor { @@ -913,7 +1027,7 @@ mod tests { fn execute_works_with_native_else_wasm() { assert_eq!(new( &trie_backend::tests::test_trie(), - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::::new()), NeverOffchainExt::new(), &mut Default::default(), &DummyCodeExecutor { @@ -934,7 +1048,7 @@ mod tests { let mut consensus_failed = false; assert!(new( &trie_backend::tests::test_trie(), - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::::new()), NeverOffchainExt::new(), &mut Default::default(), &DummyCodeExecutor { @@ -989,7 +1103,8 @@ mod tests { b"abc".to_vec() => b"2".to_vec(), b"bbb".to_vec() => b"3".to_vec() ]; - let backend = InMemory::::from(initial).try_into_trie_backend().unwrap(); + let mut state = InMemory::::from(initial); + let backend = state.as_trie_backend().unwrap(); let mut overlay = OverlayedChanges { committed: map![ b"aba".to_vec() => OverlayedValue::from(Some(b"1312".to_vec())), @@ -1003,8 +1118,8 @@ mod tests { }; { - let changes_trie_storage = InMemoryChangesTrieStorage::new(); - let mut ext = Ext::new(&mut overlay, &backend, Some(&changes_trie_storage), NeverOffchainExt::new()); + let changes_trie_storage = InMemoryChangesTrieStorage::::new(); + let mut ext = Ext::new(&mut overlay, backend, Some(&changes_trie_storage), NeverOffchainExt::new()); ext.clear_prefix(b"ab"); } overlay.commit_prospective(); @@ -1025,12 +1140,13 @@ mod tests { #[test] fn set_child_storage_works() { - let backend = InMemory::::default().try_into_trie_backend().unwrap(); - let changes_trie_storage = InMemoryChangesTrieStorage::new(); + let mut state = InMemory::::default(); + let backend = state.as_trie_backend().unwrap(); + let changes_trie_storage = InMemoryChangesTrieStorage::::new(); let mut overlay = OverlayedChanges::default(); let mut ext = Ext::new( &mut overlay, - &backend, + backend, Some(&changes_trie_storage), NeverOffchainExt::new() ); @@ -1106,7 +1222,7 @@ mod tests { fn cannot_change_changes_trie_config() { assert!(new( &trie_backend::tests::test_trie(), - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::::new()), NeverOffchainExt::new(), &mut Default::default(), &DummyCodeExecutor { @@ -1126,7 +1242,7 @@ mod tests { fn cannot_change_changes_trie_config_with_native_else_wasm() { assert!(new( &trie_backend::tests::test_trie(), - Some(&InMemoryChangesTrieStorage::new()), + Some(&InMemoryChangesTrieStorage::::new()), NeverOffchainExt::new(), &mut Default::default(), &DummyCodeExecutor { diff --git a/core/state-machine/src/overlayed_changes.rs b/core/state-machine/src/overlayed_changes.rs index e595cff0e4e4abc3af11b00e4d313e5401038a86..663e4ff72e7c943b9bdf4affec780867609bb428 100644 --- a/core/state-machine/src/overlayed_changes.rs +++ b/core/state-machine/src/overlayed_changes.rs @@ -361,7 +361,7 @@ mod tests { ..Default::default() }; - let changes_trie_storage = InMemoryChangesTrieStorage::new(); + let changes_trie_storage = InMemoryChangesTrieStorage::::new(); let mut ext = Ext::new( &mut overlay, &backend, diff --git a/core/state-machine/src/proving_backend.rs b/core/state-machine/src/proving_backend.rs index fa7e94f78f297f20cf465fd60b6a8e7676fccf95..60178ff8996d33b35e5989c461d70df9d5fb2de3 100644 --- a/core/state-machine/src/proving_backend.rs +++ b/core/state-machine/src/proving_backend.rs @@ -162,10 +162,14 @@ impl<'a, S, H> Backend for ProvingBackend<'a, S, H> self.backend.pairs() } - fn keys(&self, prefix: &Vec) -> Vec> { + fn keys(&self, prefix: &[u8]) -> Vec> { self.backend.keys(prefix) } + fn child_keys(&self, child_storage_key: &[u8], prefix: &[u8]) -> Vec> { + self.backend.child_keys(child_storage_key, prefix) + } + fn storage_root(&self, delta: I) -> (H::Out, Self::Transaction) where I: IntoIterator, Option>)> { @@ -180,7 +184,7 @@ impl<'a, S, H> Backend for ProvingBackend<'a, S, H> self.backend.child_storage_root(storage_key, delta) } - fn try_into_trie_backend(self) -> Option> { + fn as_trie_backend(&mut self) -> Option<&TrieBackend> { None } } @@ -189,17 +193,17 @@ impl<'a, S, H> Backend for ProvingBackend<'a, S, H> pub fn create_proof_check_backend( root: H::Out, proof: Vec> -) -> Result, H>, Box> +) -> Result, H>, Box> where H: Hasher, { let db = create_proof_check_backend_storage(proof); - if !db.contains(&root, &[]) { - return Err(Box::new(ExecutionError::InvalidProof) as Box); + if db.contains(&root, &[]) { + Ok(TrieBackend::new(db, root)) + } else { + Err(Box::new(ExecutionError::InvalidProof)) } - - Ok(TrieBackend::new(db, root)) } /// Create in-memory storage of proof check backend. @@ -265,16 +269,16 @@ mod tests { fn proof_recorded_and_checked() { let contents = (0..64).map(|i| (None, vec![i], Some(vec![i]))).collect::>(); let in_memory = InMemory::::default(); - let in_memory = in_memory.update(contents); + let mut in_memory = in_memory.update(contents); let in_memory_root = in_memory.storage_root(::std::iter::empty()).0; (0..64).for_each(|i| assert_eq!(in_memory.storage(&[i]).unwrap().unwrap(), vec![i])); - let trie = in_memory.try_into_trie_backend().unwrap(); + let trie = in_memory.as_trie_backend().unwrap(); let trie_root = trie.storage_root(::std::iter::empty()).0; assert_eq!(in_memory_root, trie_root); (0..64).for_each(|i| assert_eq!(trie.storage(&[i]).unwrap().unwrap(), vec![i])); - let proving = ProvingBackend::new(&trie); + let proving = ProvingBackend::new(trie); assert_eq!(proving.storage(&[42]).unwrap().unwrap(), vec![42]); let proof = proving.extract_proof(); @@ -298,7 +302,7 @@ mod tests { .chain((10..15).map(|i| (Some(own2.clone()), vec![i], Some(vec![i])))) .collect::>(); let in_memory = InMemory::::default(); - let in_memory = in_memory.update(contents); + let mut in_memory = in_memory.update(contents); let in_memory_root = in_memory.full_storage_root::<_, Vec<_>, _>( ::std::iter::empty(), in_memory.child_storage_keys().map(|k|(k.to_vec(), Vec::new())) @@ -316,7 +320,7 @@ mod tests { vec![i] )); - let trie = in_memory.try_into_trie_backend().unwrap(); + let trie = in_memory.as_trie_backend().unwrap(); let trie_root = trie.storage_root(::std::iter::empty()).0; assert_eq!(in_memory_root, trie_root); (0..64).for_each(|i| assert_eq!( @@ -324,7 +328,7 @@ mod tests { vec![i] )); - let proving = ProvingBackend::new(&trie); + let proving = ProvingBackend::new(trie); assert_eq!(proving.storage(&[42]).unwrap().unwrap(), vec![42]); let proof = proving.extract_proof(); @@ -339,7 +343,7 @@ mod tests { assert_eq!(proof_check.storage(&[41]).unwrap().unwrap(), vec![41]); assert_eq!(proof_check.storage(&[64]).unwrap(), None); - let proving = ProvingBackend::new(&trie); + let proving = ProvingBackend::new(trie); assert_eq!(proving.child_storage(&own1[..], &[64]), Ok(Some(vec![64]))); let proof = proving.extract_proof(); diff --git a/core/state-machine/src/testing.rs b/core/state-machine/src/testing.rs index a4f650bcf212aa9677d90590b21eefd96fcbc6de..68b9d28752c28215131c61e1c71f99f457d3dcda 100644 --- a/core/state-machine/src/testing.rs +++ b/core/state-machine/src/testing.rs @@ -16,25 +16,31 @@ //! Test implementation for Externalities. -use std::collections::HashMap; +use std::collections::{HashMap, BTreeMap}; use std::iter::FromIterator; use hash_db::Hasher; -use trie::trie_root; -use crate::backend::InMemory; -use crate::changes_trie::{compute_changes_trie_root, InMemoryStorage as ChangesTrieInMemoryStorage, AnchorBlockId}; +use crate::backend::{InMemory, Backend}; +use primitives::storage::well_known_keys::is_child_storage_key; +use crate::changes_trie::{ + compute_changes_trie_root, InMemoryStorage as ChangesTrieInMemoryStorage, + BlockNumber as ChangesTrieBlockNumber, +}; +use primitives::offchain; use primitives::storage::well_known_keys::{CHANGES_TRIE_CONFIG, CODE, HEAP_PAGES}; use parity_codec::Encode; use super::{ChildStorageKey, Externalities, OverlayedChanges}; +const EXT_NOT_ALLOWED_TO_FAIL: &str = "Externalities not allowed to fail within runtime"; + /// Simple HashMap-based Externalities impl. -pub struct TestExternalities { - inner: HashMap, Vec>, - changes_trie_storage: ChangesTrieInMemoryStorage, - changes: OverlayedChanges, - code: Option>, +pub struct TestExternalities { + overlay: OverlayedChanges, + backend: InMemory, + changes_trie_storage: ChangesTrieInMemoryStorage, + offchain: Option>, } -impl TestExternalities { +impl TestExternalities { /// Create a new instance of `TestExternalities` pub fn new(inner: HashMap, Vec>) -> Self { Self::new_with_code(&[], inner) @@ -43,6 +49,7 @@ impl TestExternalities { /// Create a new instance of `TestExternalities` pub fn new_with_code(code: &[u8], mut inner: HashMap, Vec>) -> Self { let mut overlay = OverlayedChanges::default(); + super::set_changes_trie_config( &mut overlay, inner.get(&CHANGES_TRIE_CONFIG.to_vec()).cloned(), @@ -50,128 +57,187 @@ impl TestExternalities { ).expect("changes trie configuration is correct in test env; qed"); inner.insert(HEAP_PAGES.to_vec(), 8u64.encode()); + inner.insert(CODE.to_vec(), code.to_vec()); TestExternalities { - inner, + overlay, changes_trie_storage: ChangesTrieInMemoryStorage::new(), - changes: overlay, - code: Some(code.to_vec()), + backend: inner.into(), + offchain: None, } } - /// Insert key/value - pub fn insert(&mut self, k: Vec, v: Vec) -> Option> { - self.inner.insert(k, v) + /// Insert key/value into backend + pub fn insert(&mut self, k: Vec, v: Vec) { + self.backend = self.backend.update(vec![(None, k, Some(v))]); + } + + /// Iter to all pairs in key order + pub fn iter_pairs_in_order(&self) -> impl Iterator, Vec)> { + self.backend.pairs().iter() + .map(|&(ref k, ref v)| (k.to_vec(), Some(v.to_vec()))) + .chain(self.overlay.committed.top.clone().into_iter().map(|(k, v)| (k, v.value))) + .chain(self.overlay.prospective.top.clone().into_iter().map(|(k, v)| (k, v.value))) + .collect::>() + .into_iter() + .filter_map(|(k, maybe_val)| maybe_val.map(|val| (k, val))) + } + + /// Set offchain externaltiies. + pub fn set_offchain_externalities(&mut self, offchain: impl offchain::Externalities + 'static) { + self.offchain = Some(Box::new(offchain)); + } + + /// Get mutable reference to changes trie storage. + pub fn changes_trie_storage(&mut self) -> &mut ChangesTrieInMemoryStorage { + &mut self.changes_trie_storage } } -impl ::std::fmt::Debug for TestExternalities { +impl ::std::fmt::Debug for TestExternalities { fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - write!(f, "{:?}", self.inner) + write!(f, "overlay: {:?}\nbackend: {:?}", self.overlay, self.backend.pairs()) } } -impl PartialEq for TestExternalities { - fn eq(&self, other: &TestExternalities) -> bool { - self.inner.eq(&other.inner) +impl PartialEq for TestExternalities { + /// This doesn't test if they are in the same state, only if they contains the + /// same data at this state + fn eq(&self, other: &TestExternalities) -> bool { + self.iter_pairs_in_order().eq(other.iter_pairs_in_order()) } } -impl FromIterator<(Vec, Vec)> for TestExternalities { +impl FromIterator<(Vec, Vec)> for TestExternalities { fn from_iter, Vec)>>(iter: I) -> Self { let mut t = Self::new(Default::default()); - t.inner.extend(iter); + t.backend = t.backend.update(iter.into_iter().map(|(k, v)| (None, k, Some(v))).collect()); t } } -impl Default for TestExternalities { +impl Default for TestExternalities { fn default() -> Self { Self::new(Default::default()) } } -impl From> for HashMap, Vec> { - fn from(tex: TestExternalities) -> Self { - tex.inner.into() +impl From> for HashMap, Vec> { + fn from(tex: TestExternalities) -> Self { + tex.iter_pairs_in_order().collect() } } -impl From< HashMap, Vec> > for TestExternalities { +impl From< HashMap, Vec> > for TestExternalities { fn from(hashmap: HashMap, Vec>) -> Self { - TestExternalities { - inner: hashmap, - changes_trie_storage: ChangesTrieInMemoryStorage::new(), - changes: Default::default(), - code: None, - } + Self::from_iter(hashmap) } } -// TODO child test primitives are currently limited to `changes` (for non child the way -// things are defined seems utterly odd to (put changes in changes but never make them -// available for read through inner) -impl Externalities for TestExternalities where H::Out: Ord { +impl Externalities for TestExternalities + where + H: Hasher, + N: ChangesTrieBlockNumber, + H::Out: Ord + 'static +{ fn storage(&self, key: &[u8]) -> Option> { - match key { - CODE => self.code.clone(), - _ => self.inner.get(key).cloned(), - } + self.overlay.storage(key).map(|x| x.map(|x| x.to_vec())).unwrap_or_else(|| + self.backend.storage(key).expect(EXT_NOT_ALLOWED_TO_FAIL)) } fn original_storage(&self, key: &[u8]) -> Option> { - self.storage(key) + self.backend.storage(key).expect(EXT_NOT_ALLOWED_TO_FAIL) } fn child_storage(&self, storage_key: ChildStorageKey, key: &[u8]) -> Option> { - self.changes.child_storage(storage_key.as_ref(), key)?.map(Vec::from) + self.overlay + .child_storage(storage_key.as_ref(), key) + .map(|x| x.map(|x| x.to_vec())) + .unwrap_or_else(|| self.backend + .child_storage(storage_key.as_ref(), key) + .expect(EXT_NOT_ALLOWED_TO_FAIL) + ) } fn place_storage(&mut self, key: Vec, maybe_value: Option>) { - self.changes.set_storage(key.clone(), maybe_value.clone()); - match key.as_ref() { - CODE => self.code = maybe_value, - _ => { - match maybe_value { - Some(value) => { self.inner.insert(key, value); } - None => { self.inner.remove(&key); } - } - } + if is_child_storage_key(&key) { + panic!("Refuse to directly set child storage key"); } + + self.overlay.set_storage(key, maybe_value); } - fn place_child_storage(&mut self, storage_key: ChildStorageKey, key: Vec, value: Option>) { - self.changes.set_child_storage(storage_key.into_owned(), key, value); + fn place_child_storage( + &mut self, + storage_key: ChildStorageKey, + key: Vec, + value: Option> + ) { + self.overlay.set_child_storage(storage_key.into_owned(), key, value); } fn kill_child_storage(&mut self, storage_key: ChildStorageKey) { - self.changes.clear_child_storage(storage_key.as_ref()); + let backend = &self.backend; + let overlay = &mut self.overlay; + + overlay.clear_child_storage(storage_key.as_ref()); + backend.for_keys_in_child_storage(storage_key.as_ref(), |key| { + overlay.set_child_storage(storage_key.as_ref().to_vec(), key.to_vec(), None); + }); } fn clear_prefix(&mut self, prefix: &[u8]) { - self.changes.clear_prefix(prefix); - self.inner.retain(|key, _| !key.starts_with(prefix)); + if is_child_storage_key(prefix) { + panic!("Refuse to directly clear prefix that is part of child storage key"); + } + + self.overlay.clear_prefix(prefix); + + let backend = &self.backend; + let overlay = &mut self.overlay; + backend.for_keys_with_prefix(prefix, |key| { + overlay.set_storage(key.to_vec(), None); + }); } fn chain_id(&self) -> u64 { 42 } fn storage_root(&mut self) -> H::Out { - trie_root::(self.inner.clone()) + // compute and memoize + let delta = self.overlay.committed.top.iter().map(|(k, v)| (k.clone(), v.value.clone())) + .chain(self.overlay.prospective.top.iter().map(|(k, v)| (k.clone(), v.value.clone()))); + + self.backend.storage_root(delta).0 } - fn child_storage_root(&mut self, _storage_key: ChildStorageKey) -> Vec { - vec![] + fn child_storage_root(&mut self, storage_key: ChildStorageKey) -> Vec { + let storage_key = storage_key.as_ref(); + + let (root, _, _) = { + let delta = self.overlay.committed.children.get(storage_key) + .into_iter() + .flat_map(|map| map.1.iter().map(|(k, v)| (k.clone(), v.clone()))) + .chain(self.overlay.prospective.children.get(storage_key) + .into_iter() + .flat_map(|map| map.1.clone().into_iter())); + + self.backend.child_storage_root(storage_key, delta) + }; + self.overlay.set_storage(storage_key.into(), Some(root.clone())); + root } - fn storage_changes_root(&mut self, parent: H::Out, parent_num: u64) -> Option { - compute_changes_trie_root::<_, _, H>( - &InMemory::default(), + fn storage_changes_root(&mut self, parent: H::Out) -> Result, ()> { + Ok(compute_changes_trie_root::<_, _, H, N>( + &self.backend, Some(&self.changes_trie_storage), - &self.changes, - &AnchorBlockId { hash: parent, number: parent_num }, - ).map(|(root, _)| root.clone()) + &self.overlay, + parent, + )?.map(|(root, _)| root.clone())) } - fn submit_extrinsic(&mut self, _extrinsic: Vec) -> Result<(), ()> { - unimplemented!() + fn offchain(&mut self) -> Option<&mut dyn offchain::Externalities> { + self.offchain + .as_mut() + .map(|x| &mut **x as _) } } @@ -183,17 +249,17 @@ mod tests { #[test] fn commit_should_work() { - let mut ext = TestExternalities::::default(); + let mut ext = TestExternalities::::default(); ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec()); ext.set_storage(b"dog".to_vec(), b"puppy".to_vec()); ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec()); - const ROOT: [u8; 32] = hex!("0b33ed94e74e0f8e92a55923bece1ed02d16cf424e124613ddebc53ac3eeeabe"); + const ROOT: [u8; 32] = hex!("cc65c26c37ebd4abcdeb3f1ecd727527051620779a2f6c809bac0f8a87dbb816"); assert_eq!(ext.storage_root(), H256::from(ROOT)); } #[test] fn set_and_retrieve_code() { - let mut ext = TestExternalities::::default(); + let mut ext = TestExternalities::::default(); let code = vec![1, 2, 3]; ext.set_storage(CODE.to_vec(), code.clone()); diff --git a/core/state-machine/src/trie_backend.rs b/core/state-machine/src/trie_backend.rs index 1ce915d5f50ebf842dfa21f085721475b93cd829..0c57cf3682fba175835b875634539da969aefa06 100644 --- a/core/state-machine/src/trie_backend.rs +++ b/core/state-machine/src/trie_backend.rs @@ -105,7 +105,7 @@ impl, H: Hasher> Backend for TrieBackend where } } - fn keys(&self, prefix: &Vec) -> Vec> { + fn keys(&self, prefix: &[u8]) -> Vec> { let mut read_overlay = S::Overlay::default(); let eph = Ephemeral::new(self.essence.backend_storage(), &mut read_overlay); @@ -179,7 +179,7 @@ impl, H: Hasher> Backend for TrieBackend where (root, is_default, write_overlay) } - fn try_into_trie_backend(self) -> Option> { + fn as_trie_backend(&mut self) -> Option<&TrieBackend> { Some(self) } } diff --git a/core/state-machine/src/trie_backend_essence.rs b/core/state-machine/src/trie_backend_essence.rs index dfb6cae08cecfac408d0adc7f2a1c36b7e77fb8c..fc30f94f05ac4649b4b2c92a1c7a6564a224192d 100644 --- a/core/state-machine/src/trie_backend_essence.rs +++ b/core/state-machine/src/trie_backend_essence.rs @@ -22,7 +22,6 @@ use std::sync::Arc; use log::{debug, warn}; use hash_db::{self, Hasher}; use trie::{TrieDB, Trie, MemoryDB, PrefixedMemoryDB, DBValue, TrieError, default_child_trie_root, read_trie_value, read_child_trie_value, for_keys_in_child_trie}; -use crate::changes_trie::Storage as ChangesTrieStorage; use crate::backend::Consolidate; /// Patricia trie-based storage trait. @@ -154,8 +153,8 @@ impl<'a, > hash_db::AsPlainDB for Ephemeral<'a, S, H> { - fn as_plain_db<'b>(&'b self) -> &'b (hash_db::PlainDB + 'b) { self } - fn as_plain_db_mut<'b>(&'b mut self) -> &'b mut (hash_db::PlainDB + 'b) { self } + fn as_plain_db<'b>(&'b self) -> &'b (dyn hash_db::PlainDB + 'b) { self } + fn as_plain_db_mut<'b>(&'b mut self) -> &'b mut (dyn hash_db::PlainDB + 'b) { self } } impl<'a, @@ -164,8 +163,8 @@ impl<'a, > hash_db::AsHashDB for Ephemeral<'a, S, H> { - fn as_hash_db<'b>(&'b self) -> &'b (hash_db::HashDB + 'b) { self } - fn as_hash_db_mut<'b>(&'b mut self) -> &'b mut (hash_db::HashDB + 'b) { self } + fn as_hash_db<'b>(&'b self) -> &'b (dyn hash_db::HashDB + 'b) { self } + fn as_hash_db_mut<'b>(&'b mut self) -> &'b mut (dyn hash_db::HashDB + 'b) { self } } impl<'a, S: TrieBackendStorage, H: Hasher> Ephemeral<'a, S, H> { @@ -276,7 +275,7 @@ pub trait TrieBackendStorage: Send + Sync { } // This implementation is used by normal storage trie clients. -impl TrieBackendStorage for Arc> { +impl TrieBackendStorage for Arc> { type Overlay = PrefixedMemoryDB; fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String> { @@ -300,12 +299,3 @@ impl TrieBackendStorage for MemoryDB { Ok(hash_db::HashDB::get(self, key, prefix)) } } - -// This implementation is used by changes trie clients. -impl<'a, S, H: Hasher> TrieBackendStorage for &'a S where S: ChangesTrieStorage { - type Overlay = MemoryDB; - - fn get(&self, key: &H::Out, prefix: &[u8]) -> Result, String> { - ChangesTrieStorage::::get(*self, key, prefix) - } -} diff --git a/core/telemetry/Cargo.toml b/core/telemetry/Cargo.toml index d1fa12abe2843edd3b5feec26fc850d9db55a1ee..1b19796836abb060f2911b30e4fc9411998254fb 100644 --- a/core/telemetry/Cargo.toml +++ b/core/telemetry/Cargo.toml @@ -6,14 +6,19 @@ description = "Telemetry utils" edition = "2018" [dependencies] -parking_lot = "0.7.1" -lazy_static = "1.0" +bytes = "0.4" +parking_lot = "0.8.0" +futures = "0.1" +libp2p = { version = "0.9.1", default-features = false, features = ["libp2p-websocket"] } log = "0.4" rand = "0.6" serde = { version = "1.0.81", features = ["derive"] } -serde_json = "1.0" slog = { version = "^2", features = ["nested-values"] } slog-json = { version = "^2", features = ["nested-values"] } -slog-async = { version = "^2", features = ["nested-values"] } slog-scope = "^4" -ws = { version = "^0.7", features = ["ssl"] } +tokio-io = "0.1" +tokio-timer = "0.2" +void = "1.0" + +[dev-dependencies] +tokio = "0.1" diff --git a/core/telemetry/src/lib.rs b/core/telemetry/src/lib.rs index 16bc69ec00beb1ddf61cbfffe099af226d413cf2..3e5d8278b06111ae2949b3066afa10b66666e48d 100644 --- a/core/telemetry/src/lib.rs +++ b/core/telemetry/src/lib.rs @@ -14,38 +14,95 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! Telemetry utils. +//! Telemetry utilities. +//! +//! Calling `init_telemetry` registers a global `slog` logger using `slog_scope::set_global_logger`. +//! After that, calling `slog_scope::with_logger` will return a logger that sends information to +//! the telemetry endpoints. The `telemetry!` macro is a short-cut for calling +//! `slog_scope::with_logger` followed with `slog_log!`. +//! +//! Note that you are supposed to only ever use `telemetry!` and not `slog_scope::with_logger` at +//! the moment. Substate may eventually be reworked to get proper `slog` support, including sending +//! information to the telemetry. +//! +//! The `Telemetry` struct implements `Future` and must be polled regularly (or sent to a +//! background thread/task) in order for the telemetry to properly function. Dropping the object +//! will also deregister the global logger and replace it with a logger that discards messages. +//! +//! # Example +//! +//! ```no_run +//! let telemetry = substrate_telemetry::init_telemetry(substrate_telemetry::TelemetryConfig { +//! endpoints: substrate_telemetry::TelemetryEndpoints::new(vec![ +//! // The `0` is the maximum verbosity level of messages to send to this endpoint. +//! ("wss://example.com".into(), 0) +//! ]), +//! on_connect: Box::new(|| {}), +//! // Can be used to pass an external implementation of WebSockets. +//! wasm_external_transport: None, +//! }); +//! +//! // The `telemetry` object implements `Future` and must be processed. +//! std::thread::spawn(move || { +//! tokio::run(telemetry); +//! }); +//! +//! // Sends a message on the telemetry. +//! substrate_telemetry::telemetry!(substrate_telemetry::SUBSTRATE_INFO; "test"; +//! "foo" => "bar", +//! ) +//! ``` //! -//! `telemetry` macro may be used anywhere in the Substrate codebase -//! in order to send real-time logging information to the telemetry -//! server (if there is one). We use the async drain adapter of `slog` -//! so that the logging thread doesn't get held up at all. -use std::{io, time, thread}; -use std::sync::Arc; +use futures::{prelude::*, task::AtomicTask}; +use libp2p::{Multiaddr, wasm_ext}; +use log::{trace, warn}; use parking_lot::Mutex; -use slog::{Drain, o, OwnedKVList, Record}; -use log::trace; -use rand::{thread_rng, Rng}; +use serde::{Serialize, Deserialize}; +use std::sync::{Arc, Weak}; +use std::time::{Duration, Instant}; + pub use slog_scope::with_logger; pub use slog; -use serde::{Serialize, Deserialize}; -use core::result; + +mod worker; /// Configuration for telemetry. pub struct TelemetryConfig { /// Collection of telemetry WebSocket servers with a corresponding verbosity level. pub endpoints: TelemetryEndpoints, - /// What do do when we connect to the servers. - /// Note that this closure is executed each time we connect to a telemetry endpoint. - pub on_connect: Box, + + /// What to do when we connect to a server. + /// + /// This closure is executed each time we connect to a telemetry endpoint, either for the first + /// time or after being disconnected. + pub on_connect: Box, + + /// Optional external implementation of a libp2p transport. Used in WASM contexts where we need + /// some binding between the networking provided by the operating system or environment and + /// libp2p. + /// + /// This parameter exists whatever the target platform is, but it is expected to be set to + /// `Some` only when compiling for WASM. + /// + /// > **Important**: Each individual call to `write` corresponds to one message. There is no + /// > internal buffering going on. In the context of WebSockets, each `write` + /// > must be one individual WebSockets frame. + pub wasm_external_transport: Option, } -/// Telemetry service guard. -pub type Telemetry = slog_scope::GlobalLoggerGuard; +/// List of telemetry servers we want to talk to. Contains the URL of the server, and the +/// maximum verbosity level. +/// +/// The URL string can be either a URL or a multiaddress. +#[derive(Debug, Clone, Serialize, Deserialize)] +pub struct TelemetryEndpoints(Vec<(String, u8)>); -/// Size of the channel for passing messages to telemetry thread. -const CHANNEL_SIZE: usize = 262144; +impl TelemetryEndpoints { + pub fn new(endpoints: Vec<(String, u8)>) -> Self { + TelemetryEndpoints(endpoints) + } +} /// Log levels. pub const SUBSTRATE_DEBUG: &str = "9"; @@ -56,232 +113,145 @@ pub const CONSENSUS_DEBUG: &str = "5"; pub const CONSENSUS_WARN: &str = "4"; pub const CONSENSUS_INFO: &str = "0"; -/// Multiply logging to all drains. This is similar to `slog::Duplicate`, which is -/// limited to two drains though and doesn't support dynamic nesting at runtime. -#[derive(Debug, Clone)] -pub struct Multiply (pub Vec); - -impl Multiply { - pub fn new(v: Vec) -> Self { - Multiply(v) - } +/// Telemetry object. Implements `Future` and must be polled regularly. +/// Contains an `Arc` and can be cloned and pass around. Only one clone needs to be polled +/// regularly. +/// Dropping all the clones unregisters the telemetry. +#[derive(Clone)] +pub struct Telemetry { + inner: Arc, + /// Slog guard so that we don't get deregistered. + _guard: Arc, } -impl Drain for Multiply { - type Ok = Vec; - type Err = Vec; - - fn log(&self, record: &Record, logger_values: &OwnedKVList) -> result::Result { - let mut oks = Vec::new(); - let mut errs = Vec::new(); - - self.0.iter().for_each(|l| { - let res: Result<::Ok, ::Err> = (*l).log(record, logger_values); - match res { - Ok(o) => oks.push(o), - Err(e) => errs.push(e), - } - }); - - if !errs.is_empty() { - result::Result::Err(errs) - } else { - result::Result::Ok(oks) - } - } -} - -/// Initialize telemetry. -pub fn init_telemetry(config: TelemetryConfig) -> slog_scope::GlobalLoggerGuard { - let mut endpoint_drains: Vec>> = Vec::new(); - let mut out_syncs = Vec::new(); - - // Set up a filter/drain for each endpoint - config.endpoints.0.iter().for_each(|(url, verbosity)| { - let writer = TelemetryWriter::new(Arc::new(url.to_owned())); - let out_sync = writer.out.clone(); - out_syncs.push(out_sync); - - let until_verbosity = *verbosity; - let filter = slog::Filter( - slog_json::Json::default(writer).fuse(), - move |rec| { - let tag = rec.tag().parse::() - .expect("`telemetry!` macro requires tag."); - tag <= until_verbosity - }); - - let filter = Box::new(filter) as Box>; - endpoint_drains.push(filter); - }); - - // Set up logging to all endpoints - let drain = slog_async::Async::new(Multiply::new(endpoint_drains).fuse()); - let root = slog::Logger::root(drain.chan_size(CHANNEL_SIZE) - .overflow_strategy(slog_async::OverflowStrategy::DropAndReport) - .build().fuse(), o!() - ); - let logger_guard = slog_scope::set_global_logger(root); - - // Spawn a thread for each endpoint - let on_connect = Arc::new(config.on_connect); - config.endpoints.0.into_iter().for_each(|(url, verbosity)| { - let inner_verbosity = Arc::new(verbosity.to_owned()); - let inner_on_connect = Arc::clone(&on_connect); - - let out_sync = out_syncs.remove(0); - let out_sync = Arc::clone(&out_sync); - - thread::spawn(move || { - loop { - let on_connect = Arc::clone(&inner_on_connect); - let out_sync = Arc::clone(&out_sync); - let verbosity = Arc::clone(&inner_verbosity); - - trace!(target: "telemetry", - "Connecting to Telemetry at {} with verbosity {}", url, Arc::clone(&verbosity)); - - let _ = ws::connect(url.to_owned(), - |out| { - Connection::new(out, Arc::clone(&out_sync), Arc::clone(&on_connect), url.clone()) - }); - - // Sleep for a random time between 5-10 secs. If there are general connection - // issues not all threads should be synchronized in their re-connection time. - let random_sleep = thread_rng().gen_range(0, 5); - thread::sleep(time::Duration::from_secs(5) + time::Duration::from_secs(random_sleep)); - } - }); - }); - - return logger_guard; -} - -/// Translates to `slog_scope::info`, but contains an additional verbosity -/// parameter which the log record is tagged with. Additionally the verbosity -/// parameter is added to the record as a key-value pair. -#[macro_export] -macro_rules! telemetry { - ( $a:expr; $b:expr; $( $t:tt )* ) => { - $crate::with_logger(|l| { - $crate::slog::slog_info!(l, #$a, $b; $($t)* ) - }) - } +// Implementation notes: considering that logging can happen at any moment, we only have two +// options: locking a mutex (which we currently do), or using a channel (which we should do). +// At the moment, `slog` doesn't provide any easy way to serialize records in order to send them +// over a channel, but ideally that's what should be done. + +/// Shared between `Telemetry` and `TelemetryDrain`. +struct TelemetryInner { + /// Worker for the telemetry. + worker: Mutex, + /// Same field as in the configuration. Called when we connected to an endpoint. + on_connect: Box, + /// Task to wake up when we add a log entry to the worker. + polling_task: AtomicTask, } -struct Connection { - out: ws::Sender, - out_sync: Arc>>, - on_connect: Arc>, - url: String, +/// Implements `slog::Drain`. +struct TelemetryDrain { + inner: std::panic::AssertUnwindSafe>, } -impl Connection { - fn new( - out: ws::Sender, - out_sync: Arc>>, - on_connect: Arc>, - url: String - ) -> Self { - Connection { - out, - out_sync, - on_connect, - url, +/// Initializes the telemetry. See the crate root documentation for more information. +/// +/// Please be careful to not call this function twice in the same program. The `slog` crate +/// doesn't provide any way of knowing whether a global logger has already been registered. +pub fn init_telemetry(config: TelemetryConfig) -> Telemetry { + // Build the list of telemetry endpoints. + let mut endpoints = Vec::new(); + for &(ref url, verbosity) in &config.endpoints.0 { + match url_to_multiaddr(url) { + Ok(addr) => endpoints.push((addr, verbosity)), + Err(err) => warn!(target: "telemetry", "Invalid telemetry URL {}: {}", url, err), } } -} - -impl ws::Handler for Connection { - fn on_open(&mut self, _: ws::Handshake) -> ws::Result<()> { - trace!(target: "telemetry", "Connected to {}!", self.url); - - *self.out_sync.lock() = Some(self.out.clone()); - (self.on_connect)(); - Ok(()) - } - fn on_close(&mut self, code: ws::CloseCode, reason: &str) { - *self.out_sync.lock() = None; - - trace!(target: "telemetry", "Connection to {} closing due to ({:?}) {}", - self.url, code, reason); - } + let inner = Arc::new(TelemetryInner { + worker: Mutex::new(worker::TelemetryWorker::new(endpoints, config.wasm_external_transport)), + on_connect: config.on_connect, + polling_task: AtomicTask::new(), + }); - fn on_error(&mut self, _: ws::Error) { - *self.out_sync.lock() = None; + let guard = { + let logger = TelemetryDrain { inner: std::panic::AssertUnwindSafe(Arc::downgrade(&inner)) }; + let root = slog::Logger::root(slog::Drain::fuse(logger), slog::o!()); + slog_scope::set_global_logger(root) + }; - // Sleep to ensure that reconnecting isn't spamming logs. - // This happens in it's own thread so it won't block anything. - thread::sleep(time::Duration::from_millis(1000)); + Telemetry { + inner, + _guard: Arc::new(guard), } } -struct TelemetryWriter { - buffer: Vec, - out: Arc>>, - url: Arc, -} +impl Future for Telemetry { + type Item = (); + type Error = (); -impl TelemetryWriter { - fn new(url: Arc) -> Self { - let out = Arc::new(Mutex::new(None)); + fn poll(&mut self) -> Poll<(), ()> { + let before = Instant::now(); - TelemetryWriter { - buffer: Vec::new(), - out, - url, + let mut has_connected = false; + while let Async::Ready(event) = self.inner.worker.lock().poll() { + // Right now we only have one possible event. This line is here in order to not + // forget to handle any possible new event type. + let worker::TelemetryWorkerEvent::Connected = event; + has_connected = true; } - } -} -impl io::Write for TelemetryWriter { - fn write(&mut self, msg: &[u8]) -> io::Result { - let mut iter = msg.split(|x| *x == b'\n'); - let first = iter.next().expect("Split iterator always has at least one element; qed"); - - self.buffer.extend_from_slice(first); - - // Flush for each occurrence of new line character - for continued in iter { - let _ = self.flush(); - self.buffer.extend_from_slice(continued); + if before.elapsed() > Duration::from_millis(200) { + warn!(target: "telemetry", "Polling the telemetry took more than 200ms"); } - Ok(msg.len()) - } - - fn flush(&mut self) -> io::Result<()> { - if self.buffer.is_empty() { - return Ok(()); + // We use an intermediary variable `has_connected` so that the lock is released when we + // call `on_connect`. + if has_connected { + trace!(target: "telemetry", "Running on_connect handlers"); + (self.inner.on_connect)(); } - if let Ok(s) = ::std::str::from_utf8(&self.buffer[..]) { - let mut out = self.out.lock(); - - let error = if let Some(ref mut o) = *out { - let r = o.send(s); - trace!(target: "telemetry", "Sent to telemetry {}: {} -> {:?}", self.url, s, r); - r.is_err() - } else { - trace!(target: "telemetry", "Telemetry socket closed to {}, failed to send: {}", self.url, s); - false - }; + self.inner.polling_task.register(); + Ok(Async::NotReady) + } +} - if error { - *out = None; +impl slog::Drain for TelemetryDrain { + type Ok = (); + type Err = (); + + fn log(&self, record: &slog::Record, values: &slog::OwnedKVList) -> Result { + if let Some(inner) = self.inner.0.upgrade() { + let before = Instant::now(); + let result = inner.worker.lock().log(record, values); + inner.polling_task.notify(); + if before.elapsed() > Duration::from_millis(50) { + warn!(target: "telemetry", "Writing a telemetry log took more than 50ms"); } + result + } else { + Ok(()) } - self.buffer.clear(); - Ok(()) } } -#[derive(Debug, Clone, Serialize, Deserialize)] -pub struct TelemetryEndpoints (Vec<(String, u8)>); +/// Parses a WebSocket URL into a libp2p `Multiaddr`. +fn url_to_multiaddr(url: &str) -> Result { + // First, assume that we have a `Multiaddr`. + let parse_error = match url.parse() { + Ok(ma) => return Ok(ma), + Err(err) => err, + }; + + // If not, try the `ws://path/url` format. + if let Ok(ma) = libp2p::multiaddr::from_url(url) { + return Ok(ma) + } -impl TelemetryEndpoints { - pub fn new(endpoints: Vec<(String, u8)>) -> Self { - TelemetryEndpoints(endpoints) + // If we have no clue about the format of that string, assume that we were expecting a + // `Multiaddr`. + Err(parse_error) +} + +/// Translates to `slog_scope::info`, but contains an additional verbosity +/// parameter which the log record is tagged with. Additionally the verbosity +/// parameter is added to the record as a key-value pair. +#[macro_export] +macro_rules! telemetry { + ( $a:expr; $b:expr; $( $t:tt )* ) => { + $crate::with_logger(|l| { + $crate::slog::slog_info!(l, #$a, $b; $($t)* ) + }) } } diff --git a/core/telemetry/src/worker.rs b/core/telemetry/src/worker.rs new file mode 100644 index 0000000000000000000000000000000000000000..87a3deb6ef9605793893ede5f9f5ddea8c4e279e --- /dev/null +++ b/core/telemetry/src/worker.rs @@ -0,0 +1,203 @@ +// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Contains the object that makes the telemetry work. +//! +//! # Usage +//! +//! - Create a `TelemetryWorker` with `TelemetryWorker::new`. +//! - Send messages to the telemetry with `TelemetryWorker::send_message`. Messages will only be +//! sent to the appropriate targets. Messages may be ignored if the target happens to be +//! temporarily unreachable. +//! - You must appropriately poll the worker with `TelemetryWorker::poll`. Polling will/may produce +//! events indicating what happened since the latest polling. +//! + +use bytes::BytesMut; +use futures::prelude::*; +use libp2p::{core::transport::OptionalTransport, core::ConnectedPoint, Multiaddr, Transport, wasm_ext}; +use log::{trace, warn, error}; +use slog::Drain; +use std::{io, time}; +use tokio_io::AsyncWrite; + +mod node; + +/// Timeout after which a connection attempt is considered failed. Includes the WebSocket HTTP +/// upgrading. +const CONNECT_TIMEOUT: time::Duration = time::Duration::from_secs(20); + +/// Event generated when polling the worker. +#[derive(Debug)] +pub enum TelemetryWorkerEvent { + /// We have established a connection to one of the telemetry endpoint, either for the first + /// time or after having been disconnected earlier. + Connected, +} + +/// Telemetry processing machine. +#[derive(Debug)] +pub struct TelemetryWorker { + /// List of nodes with their maximum verbosity level. + nodes: Vec<(node::Node, u8)>, +} + +/// The pile of libp2p transports. +#[cfg(not(target_os = "unknown"))] +type WsTrans = libp2p::core::transport::timeout::TransportTimeout< + libp2p::core::transport::OrTransport< + libp2p::core::transport::map::Map< + OptionalTransport, + fn(wasm_ext::Connection, ConnectedPoint) -> StreamSink + >, + libp2p::websocket::framed::WsConfig> + > +>; +#[cfg(target_os = "unknown")] +type WsTrans = libp2p::core::transport::timeout::TransportTimeout< + libp2p::core::transport::map::Map< + OptionalTransport, + fn(wasm_ext::Connection, ConnectedPoint) -> StreamSink + > +>; + +impl TelemetryWorker { + /// Builds a new `TelemetryWorker`. + /// + /// The endpoints must be a list of targets, plus a verbosity level. When you send a message + /// to the telemetry, only the targets whose verbosity is higher than the verbosity of the + /// message will receive it. + pub fn new( + endpoints: impl IntoIterator, + wasm_external_transport: impl Into> + ) -> Self { + let transport = match wasm_external_transport.into() { + Some(t) => OptionalTransport::some(t), + None => OptionalTransport::none() + }.map((|inner, _| StreamSink(inner)) as fn(_, _) -> _); + + // The main transport is the `wasm_external_transport`, but if we're on desktop we add + // support for TCP+WebSocket+DNS as a fallback. In practice, you're not expected to pass + // an external transport on desktop and the fallback is used all the time. + #[cfg(not(target_os = "unknown"))] + let transport = transport.or_transport({ + let inner = libp2p::dns::DnsConfig::new(libp2p::tcp::TcpConfig::new()); + libp2p::websocket::framed::WsConfig::new(inner) + }); + + let transport = transport.with_timeout(CONNECT_TIMEOUT); + + TelemetryWorker { + nodes: endpoints.into_iter().map(|(addr, verbosity)| { + let node = node::Node::new(transport.clone(), addr); + (node, verbosity) + }).collect() + } + } + + /// Polls the worker for events that happened. + pub fn poll(&mut self) -> Async { + for (node, _) in &mut self.nodes { + loop { + match node.poll() { + Async::Ready(node::NodeEvent::Connected) => + return Async::Ready(TelemetryWorkerEvent::Connected), + Async::Ready(node::NodeEvent::Disconnected(_)) => continue, + Async::NotReady => break, + } + } + } + + Async::NotReady + } + + /// Equivalent to `slog::Drain::log`, but takes `self` by `&mut` instead, which is more convenient. + /// + /// Keep in mind that you should call `TelemetryWorker::poll` in order to process the messages. + /// You should call this function right after calling `slog::Drain::log`. + pub fn log(&mut self, record: &slog::Record, values: &slog::OwnedKVList) -> Result<(), ()> { + let msg_verbosity = match record.tag().parse::() { + Ok(v) => v, + Err(err) => { + warn!(target: "telemetry", "Failed to parse telemetry tag {:?}: {:?}", + record.tag(), err); + return Err(()) + } + }; + + // None of the nodes want that verbosity, so just return without doing any serialization. + if self.nodes.iter().all(|(_, node_max_verbosity)| msg_verbosity > *node_max_verbosity) { + trace!( + target: "telemetry", + "Skipping log entry because verbosity {:?} is too high for all endpoints", + msg_verbosity + ); + return Ok(()) + } + + // Turn the message into JSON. + let serialized = { + let mut out = Vec::new(); + slog_json::Json::default(&mut out).log(record, values).map_err(|_| ())?; + out + }; + + for (node, node_max_verbosity) in &mut self.nodes { + if msg_verbosity > *node_max_verbosity { + trace!(target: "telemetry", "Skipping {:?} for log entry with verbosity {:?}", + node.addr(), msg_verbosity); + continue; + } + + // `send_message` returns an error if we're not connected, which we silently ignore. + let _ = node.send_message(serialized.clone()); + } + + Ok(()) + } +} + +/// Wraps around an `AsyncWrite` and implements `Sink`. Guarantees that each item being sent maps +/// to one call of `write`. +/// +/// For some context, we put this object around the `wasm_ext::ExtTransport` in order to make sure +/// that each telemetry message maps to one single call to `write` in the WASM FFI. +struct StreamSink(T); +impl Sink for StreamSink { + type SinkItem = BytesMut; + type SinkError = io::Error; + + fn start_send(&mut self, item: Self::SinkItem) -> Result, io::Error> { + match self.0.write(&item[..]) { + Ok(n) if n == item.len() => Ok(AsyncSink::Ready), + Ok(_) => { + error!(target: "telemetry", + "Detected some internal buffering happening in the telemetry"); + Err(io::Error::new(io::ErrorKind::Other, "Internal buffering detected")) + }, + Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => Ok(AsyncSink::NotReady(item)), + Err(err) => Err(err), + } + } + + fn poll_complete(&mut self) -> Poll<(), io::Error> { + match self.0.flush() { + Ok(()) => Ok(Async::Ready(())), + Err(ref err) if err.kind() == io::ErrorKind::WouldBlock => Ok(Async::NotReady), + Err(err) => Err(err), + } + } +} diff --git a/core/telemetry/src/worker/node.rs b/core/telemetry/src/worker/node.rs new file mode 100644 index 0000000000000000000000000000000000000000..a4d8f8d84e2cb22f0db900625e4fa4bf58af1fea --- /dev/null +++ b/core/telemetry/src/worker/node.rs @@ -0,0 +1,220 @@ +// Copyright 2017-2019 Parity Technologies (UK) Ltd. +// This file is part of Substrate. + +// Substrate is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. + +// Substrate is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. + +// You should have received a copy of the GNU General Public License +// along with Substrate. If not, see . + +//! Contains the `Node` struct, which handles communications with a single telemetry endpoint. + +use bytes::BytesMut; +use futures::prelude::*; +use libp2p::Multiaddr; +use libp2p::core::transport::Transport; +use log::{trace, debug, warn, error}; +use rand::Rng as _; +use std::{collections::VecDeque, fmt, mem, time::Duration, time::Instant}; +use tokio_timer::Delay; + +/// Maximum number of pending telemetry messages. +const MAX_PENDING: usize = 10; + +/// Handler for a single telemetry node. +pub struct Node { + /// Address of the node. + addr: Multiaddr, + /// State of the connection. + socket: NodeSocket, + /// Transport used to establish new connections. + transport: TTrans, +} + +enum NodeSocket { + /// We're connected to the node. This is the normal state. + Connected(NodeSocketConnected), + /// We are currently dialing the node. + Dialing(TTrans::Dial), + /// A new connection should be started as soon as possible. + ReconnectNow, + /// Waiting before attempting to dial again. + WaitingReconnect(Delay), + /// Temporary transition state. + Poisoned, +} + +struct NodeSocketConnected { + /// Where to send data. + sink: TTrans::Output, + /// Queue of packets to send. + pending: VecDeque, + /// If true, we need to flush the sink. + need_flush: bool, +} + +/// Event that can happen with this node. +#[derive(Debug)] +pub enum NodeEvent { + /// We are now connected to this node. + Connected, + /// We are now disconnected from this node. + Disconnected(TSinkErr), +} + +impl Node { + /// Builds a new node handler. + pub fn new(transport: TTrans, addr: Multiaddr) -> Self { + Node { + addr, + socket: NodeSocket::ReconnectNow, + transport, + } + } + + /// Returns the address that was passed to `new`. + pub fn addr(&self) -> &Multiaddr { + &self.addr + } +} + +impl Node +where TTrans: Clone, TTrans::Output: Sink, + TSinkErr: fmt::Debug { + /// Sends a WebSocket frame to the node. Returns an error if we are not connected to the node. + /// + /// After calling this method, you should call `poll` in order for it to be properly processed. + pub fn send_message(&mut self, payload: Vec) -> Result<(), ()> { + if let NodeSocket::Connected(NodeSocketConnected { pending, .. }) = &mut self.socket { + if pending.len() <= MAX_PENDING { + trace!(target: "telemetry", "Adding log entry to queue for {:?}", self.addr); + pending.push_back(payload.into()); + Ok(()) + } else { + warn!(target: "telemetry", "Rejected log entry because queue is full for {:?}", + self.addr); + Err(()) + } + } else { + Err(()) + } + } + + /// Polls the node for updates. Must be performed regularly. + pub fn poll(&mut self) -> Async> { + let mut socket = mem::replace(&mut self.socket, NodeSocket::Poisoned); + self.socket = loop { + match socket { + NodeSocket::Connected(mut conn) => match conn.poll(&self.addr) { + Ok(Async::Ready(v)) => void::unreachable(v), + Ok(Async::NotReady) => break NodeSocket::Connected(conn), + Err(err) => { + debug!(target: "telemetry", "Disconnected from {}: {:?}", self.addr, err); + let timeout = gen_rand_reconnect_delay(); + self.socket = NodeSocket::WaitingReconnect(timeout); + return Async::Ready(NodeEvent::Disconnected(err)) + } + } + NodeSocket::Dialing(mut s) => match s.poll() { + Ok(Async::Ready(sink)) => { + debug!(target: "telemetry", "Connected to {}", self.addr); + let conn = NodeSocketConnected { sink, pending: VecDeque::new(), need_flush: false }; + self.socket = NodeSocket::Connected(conn); + return Async::Ready(NodeEvent::Connected) + }, + Ok(Async::NotReady) => break NodeSocket::Dialing(s), + Err(err) => { + debug!(target: "telemetry", "Error while dialing {}: {:?}", self.addr, err); + let timeout = gen_rand_reconnect_delay(); + socket = NodeSocket::WaitingReconnect(timeout); + } + } + NodeSocket::ReconnectNow => match self.transport.clone().dial(self.addr.clone()) { + Ok(d) => { + debug!(target: "telemetry", "Started dialing {}", self.addr); + socket = NodeSocket::Dialing(d); + } + Err(err) => { + debug!(target: "telemetry", "Error while dialing {}: {:?}", self.addr, err); + let timeout = gen_rand_reconnect_delay(); + socket = NodeSocket::WaitingReconnect(timeout); + } + } + NodeSocket::WaitingReconnect(mut s) => if let Ok(Async::Ready(_)) = s.poll() { + socket = NodeSocket::ReconnectNow; + } else { + break NodeSocket::WaitingReconnect(s) + } + NodeSocket::Poisoned => { + error!(target: "telemetry", "Poisoned connection with {}", self.addr); + break NodeSocket::Poisoned + } + } + }; + + Async::NotReady + } +} + +/// Generates a `Delay` object with a random timeout. +/// +/// If there are general connection issues, not all endpoints should be synchronized in their +/// re-connection time. +fn gen_rand_reconnect_delay() -> Delay { + let random_delay = rand::thread_rng().gen_range(5, 10); + Delay::new(Instant::now() + Duration::from_secs(random_delay)) +} + +impl NodeSocketConnected +where TTrans::Output: Sink { + /// Processes the queue of messages for the connected socket. + /// + /// The address is passed for logging purposes only. + fn poll(&mut self, my_addr: &Multiaddr) -> Poll { + loop { + if let Some(item) = self.pending.pop_front() { + let item_len = item.len(); + if let AsyncSink::NotReady(item) = self.sink.start_send(item)? { + self.pending.push_front(item); + break + } else { + trace!(target: "telemetry", "Successfully sent {:?} bytes message to {}", + item_len, my_addr); + self.need_flush = true; + } + + } else if self.need_flush && self.sink.poll_complete()?.is_ready() { + self.need_flush = false; + + } else { + break + } + } + + Ok(Async::NotReady) + } +} + +impl fmt::Debug for Node { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let state = match self.socket { + NodeSocket::Connected(_) => "Connected", + NodeSocket::Dialing(_) => "Dialing", + NodeSocket::ReconnectNow => "Pending reconnect", + NodeSocket::WaitingReconnect(_) => "Pending reconnect", + NodeSocket::Poisoned => "Poisoned", + }; + + f.debug_struct("Node") + .field("addr", &self.addr) + .field("state", &state) + .finish() + } +} diff --git a/core/test-client/Cargo.toml b/core/test-client/Cargo.toml index 7628125df445b67fbb9307941292b88c077bd9a5..b459e02fbc986329523aba2375197e2d4177a8af 100644 --- a/core/test-client/Cargo.toml +++ b/core/test-client/Cargo.toml @@ -7,25 +7,13 @@ edition = "2018" [dependencies] client = { package = "substrate-client", path = "../client" } client-db = { package = "substrate-client-db", path = "../client/db", features = ["test-helpers"] } -futures = { version = "0.1.17" } -parity-codec = "3.3" -executor = { package = "substrate-executor", path = "../executor" } consensus = { package = "substrate-consensus-common", path = "../consensus/common" } -keyring = { package = "substrate-keyring", path = "../../core/keyring" } +executor = { package = "substrate-executor", path = "../executor" } +futures = { version = "0.1.27" } +hash-db = "0.12" +keyring = { package = "substrate-keyring", path = "../keyring" } +parity-codec = "3.5.1" primitives = { package = "substrate-primitives", path = "../primitives" } -state_machine = { package = "substrate-state-machine", path = "../state-machine" } -runtime = { package = "substrate-test-runtime", path = "../test-runtime", default-features = false } runtime_primitives = { package = "sr-primitives", path = "../sr-primitives" } +state_machine = { package = "substrate-state-machine", path = "../state-machine" } -[features] -default = [ - "include-wasm-blob", - "std", -] -std = [ - "runtime/std", -] -# If enabled, the WASM blob is added to the `GenesisConfig`. -include-wasm-blob = [ - "runtime/include-wasm-blob", -] \ No newline at end of file diff --git a/core/test-client/src/client_ext.rs b/core/test-client/src/client_ext.rs index d285bb726b75258210ed59d043313dc88a74d3c9..7d05b1f570da9600eedb5360d21de9b1418f8d0d 100644 --- a/core/test-client/src/client_ext.rs +++ b/core/test-client/src/client_ext.rs @@ -21,52 +21,55 @@ use consensus::{ ImportBlock, BlockImport, BlockOrigin, Error as ConsensusError, ForkChoiceStrategy, }; +use hash_db::Hasher; use runtime_primitives::Justification; +use runtime_primitives::traits::{Block as BlockT}; use runtime_primitives::generic::BlockId; use primitives::Blake2Hasher; -use runtime; use parity_codec::alloc::collections::hash_map::HashMap; /// Extension trait for a test client. -pub trait TestClient: Sized { +pub trait ClientExt: Sized { /// Import block to the chain. No finality. - fn import(&self, origin: BlockOrigin, block: runtime::Block) + fn import(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError>; /// Import block with justification, finalizes block. fn import_justified( &self, origin: BlockOrigin, - block: runtime::Block, + block: Block, justification: Justification ) -> Result<(), ConsensusError>; /// Finalize a block. fn finalize_block( &self, - id: BlockId, + id: BlockId, justification: Option, ) -> client::error::Result<()>; /// Returns hash of the genesis block. - fn genesis_hash(&self) -> runtime::Hash; + fn genesis_hash(&self) -> ::Hash; } -impl TestClient for Client +impl ClientExt for Client where - B: client::backend::Backend, - E: client::CallExecutor, - Self: BlockImport, + B: client::backend::Backend, + E: client::CallExecutor, + Self: BlockImport, + Block: BlockT::Out>, { - fn import(&self, origin: BlockOrigin, block: runtime::Block) + fn import(&self, origin: BlockOrigin, block: Block) -> Result<(), ConsensusError> { + let (header, extrinsics) = block.deconstruct(); let import = ImportBlock { origin, - header: block.header, + header, justification: None, post_digests: vec![], - body: Some(block.extrinsics), + body: Some(extrinsics), finalized: false, auxiliary: Vec::new(), fork_choice: ForkChoiceStrategy::LongestChain, @@ -78,15 +81,16 @@ impl TestClient for Client fn import_justified( &self, origin: BlockOrigin, - block: runtime::Block, + block: Block, justification: Justification, ) -> Result<(), ConsensusError> { + let (header, extrinsics) = block.deconstruct(); let import = ImportBlock { origin, - header: block.header, + header, justification: Some(justification), post_digests: vec![], - body: Some(block.extrinsics), + body: Some(extrinsics), finalized: true, auxiliary: Vec::new(), fork_choice: ForkChoiceStrategy::LongestChain, @@ -97,13 +101,13 @@ impl TestClient for Client fn finalize_block( &self, - id: BlockId, + id: BlockId, justification: Option, ) -> client::error::Result<()> { self.finalize_block(id, justification, true) } - fn genesis_hash(&self) -> runtime::Hash { - self.block_hash(0).unwrap().unwrap() + fn genesis_hash(&self) -> ::Hash { + self.block_hash(0.into()).unwrap().unwrap() } } diff --git a/core/test-client/src/lib.rs b/core/test-client/src/lib.rs index dfbb1fbcec42910ee1a1c189ce5d1c5057280565..40fbd10d9e43870d50fbd463da7b9709b3a314ed 100644 --- a/core/test-client/src/lib.rs +++ b/core/test-client/src/lib.rs @@ -1,4 +1,4 @@ -// Copyright 2018-2019 Parity Technologies (UK) Ltd. +// Copyright 2019 Parity Technologies (UK) Ltd. // This file is part of Substrate. // Substrate is free software: you can redistribute it and/or modify @@ -19,60 +19,30 @@ #![warn(missing_docs)] pub mod client_ext; -#[cfg(feature = "include-wasm-blob")] -pub mod trait_tests; -mod block_builder_ext; -pub use client_ext::TestClient; -pub use block_builder_ext::BlockBuilderExt; pub use client::{ExecutionStrategies, blockchain, backend, self}; -pub use executor::{NativeExecutor, self}; -pub use runtime; +pub use client_db::{Backend, self}; +pub use client_ext::ClientExt; pub use consensus; +pub use executor::{NativeExecutor, self}; pub use keyring::{sr25519::Keyring as AuthorityKeyring, AccountKeyring}; +pub use primitives::Blake2Hasher; +pub use runtime_primitives::{StorageOverlay, ChildrenStorageOverlay}; +pub use state_machine::ExecutionStrategy; -use std::{sync::Arc, collections::HashMap}; +use std::sync::Arc; +use std::collections::HashMap; use futures::future::FutureResult; -use primitives::Blake2Hasher; -use runtime_primitives::StorageOverlay; +use hash_db::Hasher; +use primitives::storage::well_known_keys; use runtime_primitives::traits::{ - Block as BlockT, Header as HeaderT, Hash as HashT, NumberFor + Block as BlockT, NumberFor }; -use runtime::genesismap::{GenesisConfig, additional_storage_with_genesis}; -use state_machine::ExecutionStrategy; use client::LocalCallExecutor; -#[cfg(feature = "include-wasm-blob")] -mod local_executor { - #![allow(missing_docs)] - use runtime; - use executor::native_executor_instance; - // FIXME #1576 change the macro and pass in the `BlakeHasher` that dispatch needs from here instead - native_executor_instance!( - pub LocalExecutor, - runtime::api::dispatch, - runtime::native_version, - include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm") - ); -} - -/// Native executor used for tests. -#[cfg(feature = "include-wasm-blob")] -pub use local_executor::LocalExecutor; - -/// Test client database backend. -pub type Backend = client_db::Backend; - -/// Test client executor. -#[cfg(feature = "include-wasm-blob")] -pub type Executor = client::LocalCallExecutor< - Backend, - executor::NativeExecutor, ->; - /// Test client light database backend. -pub type LightBackend = client::light::backend::Backend< - client_db::light::LightStorage, +pub type LightBackend = client::light::backend::Backend< + client_db::light::LightStorage, LightFetcher, Blake2Hasher, >; @@ -80,45 +50,85 @@ pub type LightBackend = client::light::backend::Backend< /// Test client light fetcher. pub struct LightFetcher; -/// Test client light executor. -#[cfg(feature = "include-wasm-blob")] -pub type LightExecutor = client::light::call_executor::RemoteOrLocalCallExecutor< - runtime::Block, - LightBackend, - client::light::call_executor::RemoteCallExecutor< - client::light::blockchain::Blockchain< - client_db::light::LightStorage, - LightFetcher - >, - LightFetcher - >, - client::LocalCallExecutor< - client::light::backend::Backend< - client_db::light::LightStorage, - LightFetcher, - Blake2Hasher - >, - executor::NativeExecutor - > ->; +/// A genesis storage initialisation trait. +pub trait GenesisInit: Default { + /// Construct genesis storage. + fn genesis_storage(&self) -> (StorageOverlay, ChildrenStorageOverlay); +} + +impl GenesisInit for () { + fn genesis_storage(&self) -> (StorageOverlay, ChildrenStorageOverlay) { + Default::default() + } +} /// A builder for creating a test client instance. -pub struct TestClientBuilder { +pub struct TestClientBuilder { execution_strategies: ExecutionStrategies, - genesis_extension: HashMap, Vec>, - support_changes_trie: bool, + genesis_init: G, + child_storage_extension: HashMap, Vec<(Vec, Vec)>>, + backend: Arc, + _executor: std::marker::PhantomData, +} + +impl Default for TestClientBuilder< + Executor, + Backend, +> where + Block: BlockT::Out>, +{ + fn default() -> Self { + Self::with_default_backend() + } } -impl TestClientBuilder { +impl TestClientBuilder< + Executor, + Backend, + G, +> where + Block: BlockT::Out>, +{ + /// Create new `TestClientBuilder` with default backend. + pub fn with_default_backend() -> Self { + let backend = Arc::new(Backend::new_test(std::u32::MAX, std::u64::MAX)); + Self::with_backend(backend) + } +} + +impl TestClientBuilder< + Executor, + Backend, + G, +> { /// Create a new instance of the test client builder. - pub fn new() -> Self { + pub fn with_backend(backend: Arc) -> Self { TestClientBuilder { + backend, execution_strategies: ExecutionStrategies::default(), - genesis_extension: HashMap::default(), - support_changes_trie: false, + child_storage_extension: Default::default(), + genesis_init: Default::default(), + _executor: Default::default(), } } + /// Alter the genesis storage parameters. + pub fn genesis_init_mut(&mut self) -> &mut G { + &mut self.genesis_init + } + + /// Extend child storage + pub fn add_child_storage( + mut self, + key: impl AsRef<[u8]>, + child_key: impl AsRef<[u8]>, + value: impl AsRef<[u8]>, + ) -> Self { + let entry = self.child_storage_extension.entry(key.as_ref().to_vec()).or_insert_with(Vec::new); + entry.push((child_key.as_ref().to_vec(), value.as_ref().to_vec())); + self + } + /// Set the execution strategy that should be used by all contexts. pub fn set_execution_strategy( mut self, @@ -134,153 +144,79 @@ impl TestClientBuilder { self } - /// Set an extension of the genesis storage. - pub fn set_genesis_extension( - mut self, - extension: HashMap, Vec> - ) -> Self { - self.genesis_extension = extension; - self - } - - /// Enable/Disable changes trie support. - pub fn set_support_changes_trie(mut self, enable: bool) -> Self { - self.support_changes_trie = enable; - self - } - - /// Build the test client. - #[cfg(feature = "include-wasm-blob")] - pub fn build(self) -> client::Client< - Backend, Executor, runtime::Block, runtime::RuntimeApi - > { - let backend = Arc::new(Backend::new_test(std::u32::MAX, std::u64::MAX)); - self.build_with_backend(backend) - } - - /// Build the test client with the given backend. - #[cfg(feature = "include-wasm-blob")] - pub fn build_with_backend(self, backend: Arc) -> client::Client< - B, - client::LocalCallExecutor>, - runtime::Block, - runtime::RuntimeApi - > where B: backend::LocalBackend { - let executor = NativeExecutor::new(None); - let executor = LocalCallExecutor::new(backend.clone(), executor); - - client::Client::new( - backend, - executor, - genesis_storage(self.support_changes_trie, self.genesis_extension), - self.execution_strategies - ).expect("Creates new client") - } - /// Build the test client with the given native executor. - pub fn build_with_native_executor( + pub fn build_with_executor( self, - executor: executor::NativeExecutor - ) -> client::Client< - Backend, - client::LocalCallExecutor>, - runtime::Block, - runtime::RuntimeApi - > where E: executor::NativeExecutionDispatch + executor: Executor, + ) -> ( + client::Client< + Backend, + Executor, + Block, + RuntimeApi, + >, + client::LongestChain, + ) where + Executor: client::CallExecutor, + Backend: client::backend::Backend, + Block: BlockT::Out>, { - let backend = Arc::new(Backend::new_test(std::u32::MAX, std::u64::MAX)); - let executor = LocalCallExecutor::new(backend.clone(), executor); - client::Client::new( - backend, - executor, - genesis_storage(self.support_changes_trie, self.genesis_extension), - self.execution_strategies - ).expect("Creates new client") - } -} + let storage = { + let mut storage = self.genesis_init.genesis_storage(); -/// Creates new client instance used for tests. -#[cfg(feature = "include-wasm-blob")] -pub fn new() -> client::Client { - new_with_backend(Arc::new(Backend::new_test(::std::u32::MAX, ::std::u64::MAX)), false) -} + // Add some child storage keys. + for (key, value) in self.child_storage_extension { + storage.1.insert( + well_known_keys::CHILD_STORAGE_KEY_PREFIX.iter().cloned().chain(key).collect(), + value.into_iter().collect(), + ); + } -/// Creates new light client instance used for tests. -#[cfg(feature = "include-wasm-blob")] -pub fn new_light() -> client::Client { - let storage = client_db::light::LightStorage::new_test(); - let blockchain = Arc::new(client::light::blockchain::Blockchain::new(storage)); - let backend = Arc::new(LightBackend::new(blockchain.clone())); - let executor = NativeExecutor::new(None); - let fetcher = Arc::new(LightFetcher); - let remote_call_executor = client::light::call_executor::RemoteCallExecutor::new(blockchain.clone(), fetcher); - let local_call_executor = client::LocalCallExecutor::new(backend.clone(), executor); - let call_executor = LightExecutor::new(backend.clone(), remote_call_executor, local_call_executor); - client::Client::new(backend, call_executor, genesis_storage(false, Default::default()), Default::default()).unwrap() -} + storage + }; -/// Creates new client instance used for tests with the given api execution strategy. -#[cfg(feature = "include-wasm-blob")] -pub fn new_with_execution_strategy( - execution_strategy: ExecutionStrategy -) -> client::Client { - TestClientBuilder::new().set_execution_strategy(execution_strategy).build() -} + let client = client::Client::new( + self.backend.clone(), + executor, + storage, + self.execution_strategies + ).expect("Creates new client"); -/// Creates new test client instance that suports changes trie creation. -#[cfg(feature = "include-wasm-blob")] -pub fn new_with_changes_trie() - -> client::Client -{ - TestClientBuilder::new().set_support_changes_trie(true).build() -} + let longest_chain = client::LongestChain::new(self.backend); -/// Creates new client instance used for tests with an explicitly provided backend. -/// This is useful for testing backend implementations. -#[cfg(feature = "include-wasm-blob")] -pub fn new_with_backend( - backend: Arc, - support_changes_trie: bool -) -> client::Client< - B, - client::LocalCallExecutor>, - runtime::Block, - runtime::RuntimeApi -> where B: backend::LocalBackend -{ - TestClientBuilder::new() - .set_support_changes_trie(support_changes_trie) - .build_with_backend(backend) + (client, longest_chain) + } } -fn genesis_config(support_changes_trie: bool) -> GenesisConfig { - GenesisConfig::new(support_changes_trie, vec![ - AuthorityKeyring::Alice.into(), - AuthorityKeyring::Bob.into(), - AuthorityKeyring::Charlie.into(), - ], vec![ - AccountKeyring::Alice.into(), - AccountKeyring::Bob.into(), - AccountKeyring::Charlie.into(), - ], - 1000 - ) -} +impl TestClientBuilder< + client::LocalCallExecutor>, + Backend, + G, +> { + /// Build the test client with the given native executor. + pub fn build_with_native_executor( + self, + executor: I, + ) -> ( + client::Client< + Backend, + client::LocalCallExecutor>, + Block, + RuntimeApi + >, + client::LongestChain, + ) where + I: Into>>, + E: executor::NativeExecutionDispatch, + Backend: client::backend::Backend, + Block: BlockT::Out>, + { + let executor = executor.into().unwrap_or_else(|| executor::NativeExecutor::new(None)); + let executor = LocalCallExecutor::new(self.backend.clone(), executor); -fn genesis_storage( - support_changes_trie: bool, - extension: HashMap, Vec> -) -> StorageOverlay { - let mut storage = genesis_config(support_changes_trie).genesis_map(); - storage.extend(extension.into_iter()); - - let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( - storage.clone().into_iter() - ); - let block: runtime::Block = client::genesis::construct_genesis_block(state_root); - storage.extend(additional_storage_with_genesis(&block)); - storage + self.build_with_executor(executor) + } } impl client::light::fetcher::Fetcher for LightFetcher { @@ -288,6 +224,7 @@ impl client::light::fetcher::Fetcher for LightFetcher { type RemoteReadResult = FutureResult>, client::error::Error>; type RemoteCallResult = FutureResult, client::error::Error>; type RemoteChangesResult = FutureResult, u32)>, client::error::Error>; + type RemoteBodyResult = FutureResult, client::error::Error>; fn remote_header( &self, @@ -323,4 +260,11 @@ impl client::light::fetcher::Fetcher for LightFetcher { ) -> Self::RemoteChangesResult { unimplemented!("not (yet) used in tests") } + + fn remote_body( + &self, + _request: client::light::fetcher::RemoteBodyRequest, + ) -> Self::RemoteBodyResult { + unimplemented!("not (yet) used in tests") + } } diff --git a/core/test-runtime/Cargo.toml b/core/test-runtime/Cargo.toml index 4244dcc58b8c39aea5a1b5bd3fece8fa495eec47..b0815c513bd7e247c243d4547c2903f91f97c20b 100644 --- a/core/test-runtime/Cargo.toml +++ b/core/test-runtime/Cargo.toml @@ -29,7 +29,7 @@ consensus_authorities = { package = "substrate-consensus-authorities", path = ". [dev-dependencies] substrate-executor = { path = "../executor" } -substrate-test-client = { path = "../test-client" } +substrate-test-runtime-client = { path = "./client" } [features] default = [ diff --git a/core/test-runtime/client/Cargo.toml b/core/test-runtime/client/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..9ddeb7ba2508b627132bdbc2b906f525296f4192 --- /dev/null +++ b/core/test-runtime/client/Cargo.toml @@ -0,0 +1,20 @@ +[package] +name = "substrate-test-runtime-client" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +generic-test-client = { package = "substrate-test-client", path = "../../test-client" } +primitives = { package = "substrate-primitives", path = "../../primitives" } +runtime = { package = "substrate-test-runtime", path = "../../test-runtime", default-features = false } +runtime_primitives = { package = "sr-primitives", path = "../../sr-primitives" } + +[features] +default = [ + "std", + "runtime/include-wasm-blob", +] +std = [ + "runtime/std", +] diff --git a/core/test-client/src/block_builder_ext.rs b/core/test-runtime/client/src/block_builder_ext.rs similarity index 93% rename from core/test-client/src/block_builder_ext.rs rename to core/test-runtime/client/src/block_builder_ext.rs index 15861ce3d0eaa3c997d43ee10ee6c5d46c47abf2..ae95ecd7abcf78d9196d799e0b5ed850a844c405 100644 --- a/core/test-client/src/block_builder_ext.rs +++ b/core/test-runtime/client/src/block_builder_ext.rs @@ -16,10 +16,10 @@ //! Block Builder extensions for tests. -use client; use runtime; use runtime_primitives::traits::ProvideRuntimeApi; -use client::block_builder::api::BlockBuilder; +use generic_test_client::client; +use generic_test_client::client::block_builder::api::BlockBuilder; /// Extension trait for test block builder. pub trait BlockBuilderExt { diff --git a/core/test-runtime/client/src/lib.rs b/core/test-runtime/client/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..ee1ad2421472695855215810fc717692afa286f8 --- /dev/null +++ b/core/test-runtime/client/src/lib.rs @@ -0,0 +1,208 @@ +// Copyright 2018-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 . + +//! Client testing utilities. + +#![warn(missing_docs)] + +pub mod trait_tests; + +mod block_builder_ext; + +pub use block_builder_ext::BlockBuilderExt; +pub use generic_test_client::*; +pub use runtime; + +use runtime::genesismap::{GenesisConfig, additional_storage_with_genesis}; +use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Hash as HashT}; + +/// A prelude to import in tests. +pub mod prelude { + // Trait extensions + pub use super::{BlockBuilderExt, DefaultTestClientBuilderExt, TestClientBuilderExt, ClientExt}; + // Client structs + pub use super::{ + TestClient, TestClientBuilder, Backend, LightBackend, + Executor, LightExecutor, LocalExecutor, NativeExecutor, + }; + // Keyring + pub use super::{AccountKeyring, AuthorityKeyring}; +} + +mod local_executor { + #![allow(missing_docs)] + use runtime; + use crate::executor::native_executor_instance; + // FIXME #1576 change the macro and pass in the `BlakeHasher` that dispatch needs from here instead + native_executor_instance!( + pub LocalExecutor, + runtime::api::dispatch, + runtime::native_version, + include_bytes!("../../wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm") + ); +} + +/// Native executor used for tests. +pub use local_executor::LocalExecutor; + +/// Test client database backend. +pub type Backend = generic_test_client::Backend; + +/// Test client executor. +pub type Executor = client::LocalCallExecutor< + Backend, + NativeExecutor, +>; + +/// Test client light database backend. +pub type LightBackend = generic_test_client::LightBackend; + +/// Test client light executor. +pub type LightExecutor = client::light::call_executor::RemoteOrLocalCallExecutor< + runtime::Block, + LightBackend, + client::light::call_executor::RemoteCallExecutor< + client::light::blockchain::Blockchain< + client_db::light::LightStorage, + LightFetcher + >, + LightFetcher + >, + client::LocalCallExecutor< + client::light::backend::Backend< + client_db::light::LightStorage, + LightFetcher, + Blake2Hasher + >, + NativeExecutor + > +>; + +/// Parameters of test-client builder with test-runtime. +#[derive(Default)] +pub struct GenesisParameters { + support_changes_trie: bool, +} + +impl generic_test_client::GenesisInit for GenesisParameters { + fn genesis_storage(&self) -> (StorageOverlay, ChildrenStorageOverlay) { + let mut storage = genesis_config(self.support_changes_trie).genesis_map(); + + let state_root = <<::Header as HeaderT>::Hashing as HashT>::trie_root( + storage.clone().into_iter() + ); + let block: runtime::Block = client::genesis::construct_genesis_block(state_root); + storage.extend(additional_storage_with_genesis(&block)); + + (storage, Default::default()) + } +} + +/// A `TestClient` with `test-runtime` builder. +pub type TestClientBuilder = generic_test_client::TestClientBuilder; + +/// Test client type with `LocalExecutor` and generic Backend. +pub type Client = client::Client< + B, + client::LocalCallExecutor>, + runtime::Block, + runtime::RuntimeApi, +>; + +/// A test client with default backend. +pub type TestClient = Client; + +/// A `TestClientBuilder` with default backend and executor. +pub trait DefaultTestClientBuilderExt: Sized { + /// Create new `TestClientBuilder` + fn new() -> Self; +} + +impl DefaultTestClientBuilderExt for TestClientBuilder< + Executor, + Backend, +> { + fn new() -> Self { + Self::with_default_backend() + } +} + +/// A `test-runtime` extensions to `TestClientBuilder`. +pub trait TestClientBuilderExt: Sized { + /// Enable or disable support for changes trie in genesis. + fn set_support_changes_trie(self, support_changes_trie: bool) -> Self; + + /// Build the test client. + fn build(self) -> Client { + self.build_with_longest_chain().0 + } + + /// Build the test client and longest chain selector. + fn build_with_longest_chain(self) -> (Client, client::LongestChain); +} + +impl TestClientBuilderExt for TestClientBuilder< + client::LocalCallExecutor>, + B +> where + B: client::backend::Backend, +{ + fn set_support_changes_trie(mut self, support_changes_trie: bool) -> Self { + self.genesis_init_mut().support_changes_trie = support_changes_trie; + self + } + + fn build_with_longest_chain(self) -> (Client, client::LongestChain) { + self.build_with_native_executor(None) + } +} + +fn genesis_config(support_changes_trie: bool) -> GenesisConfig { + GenesisConfig::new(support_changes_trie, vec![ + AuthorityKeyring::Alice.into(), + AuthorityKeyring::Bob.into(), + AuthorityKeyring::Charlie.into(), + ], vec![ + AccountKeyring::Alice.into(), + AccountKeyring::Bob.into(), + AccountKeyring::Charlie.into(), + ], + 1000 + ) +} + +/// Creates new client instance used for tests. +pub fn new() -> Client { + TestClientBuilder::new().build() +} + +/// Creates new light client instance used for tests. +pub fn new_light() -> client::Client { + use std::sync::Arc; + + let storage = client_db::light::LightStorage::new_test(); + let blockchain = Arc::new(client::light::blockchain::Blockchain::new(storage)); + let backend = Arc::new(LightBackend::new(blockchain.clone())); + let executor = NativeExecutor::new(None); + let fetcher = Arc::new(LightFetcher); + let remote_call_executor = client::light::call_executor::RemoteCallExecutor::new(blockchain.clone(), fetcher); + let local_call_executor = client::LocalCallExecutor::new(backend.clone(), executor); + let call_executor = LightExecutor::new(backend.clone(), remote_call_executor, local_call_executor); + + TestClientBuilder::with_backend(backend) + .build_with_executor(call_executor) + .0 +} diff --git a/core/test-client/src/trait_tests.rs b/core/test-runtime/client/src/trait_tests.rs similarity index 63% rename from core/test-client/src/trait_tests.rs rename to core/test-runtime/client/src/trait_tests.rs index aa51f7d8bf9e33b24bad88060c5b8dca23a04018..3d013e3e74263f2354c1c2fd5089c16802eba539 100644 --- a/core/test-client/src/trait_tests.rs +++ b/core/test-runtime/client/src/trait_tests.rs @@ -20,15 +20,16 @@ #![allow(missing_docs)] use std::sync::Arc; -use consensus::BlockOrigin; -use primitives::Blake2Hasher; -use crate::{TestClient, AccountKeyring}; -use runtime_primitives::traits::Block as BlockT; + use crate::backend; +use crate::block_builder_ext::BlockBuilderExt; use crate::blockchain::{Backend as BlockChainBackendT, HeaderBackend}; -use crate::{BlockBuilderExt, new_with_backend}; +use crate::{AccountKeyring, ClientExt, TestClientBuilder, TestClientBuilderExt}; +use generic_test_client::consensus::BlockOrigin; +use primitives::Blake2Hasher; use runtime::{self, Transfer}; use runtime_primitives::generic::BlockId; +use runtime_primitives::traits::Block as BlockT; /// helper to test the `leaves` implementation for various backends pub fn test_leaves_for_backend(backend: Arc) where @@ -40,51 +41,54 @@ pub fn test_leaves_for_backend(backend: Arc) where // B2 -> C3 // A1 -> D2 - let client = new_with_backend(backend.clone(), false); + let client = TestClientBuilder::with_backend(backend.clone()).build(); + let blockchain = backend.blockchain(); - let genesis_hash = client.info().unwrap().chain.genesis_hash; + let genesis_hash = client.info().chain.genesis_hash; assert_eq!( - client.backend().blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![genesis_hash]); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a1.hash()]); // A1 -> A2 - let a2 = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap().bake().unwrap(); + let a2 = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); + + #[allow(deprecated)] assert_eq!( - client.backend().blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a2.hash()]); // A2 -> A3 - let a3 = client.new_block_at(&BlockId::Hash(a2.hash())).unwrap().bake().unwrap(); + let a3 = client.new_block_at(&BlockId::Hash(a2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a3.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a3.hash()]); // A3 -> A4 - let a4 = client.new_block_at(&BlockId::Hash(a3.hash())).unwrap().bake().unwrap(); + let a4 = client.new_block_at(&BlockId::Hash(a3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a4.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a4.hash()]); // A4 -> A5 - let a5 = client.new_block_at(&BlockId::Hash(a4.hash())).unwrap().bake().unwrap(); + let a5 = client.new_block_at(&BlockId::Hash(a4.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a5.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a5.hash()]); // A1 -> B2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -95,25 +99,25 @@ pub fn test_leaves_for_backend(backend: Arc) where let b2 = builder.bake().unwrap(); client.import(BlockOrigin::Own, b2.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a5.hash(), b2.hash()]); // B2 -> B3 - let b3 = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap().bake().unwrap(); + let b3 = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b3.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a5.hash(), b3.hash()]); // B3 -> B4 - let b4 = client.new_block_at(&BlockId::Hash(b3.hash())).unwrap().bake().unwrap(); + let b4 = client.new_block_at(&BlockId::Hash(b3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b4.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a5.hash(), b4.hash()]); // // B2 -> C3 - let mut builder = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -124,11 +128,11 @@ pub fn test_leaves_for_backend(backend: Arc) where let c3 = builder.bake().unwrap(); client.import(BlockOrigin::Own, c3.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a5.hash(), b4.hash(), c3.hash()]); // A1 -> D2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -139,7 +143,7 @@ pub fn test_leaves_for_backend(backend: Arc) where let d2 = builder.bake().unwrap(); client.import(BlockOrigin::Own, d2.clone()).unwrap(); assert_eq!( - backend.blockchain().leaves().unwrap(), + blockchain.leaves().unwrap(), vec![a5.hash(), b4.hash(), c3.hash(), d2.hash()]); } @@ -153,30 +157,31 @@ pub fn test_children_for_backend(backend: Arc) where // B2 -> C3 // A1 -> D2 - let client = new_with_backend(backend.clone(), false); + let client = TestClientBuilder::with_backend(backend.clone()).build(); + let blockchain = backend.blockchain(); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); // A1 -> A2 - let a2 = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap().bake().unwrap(); + let a2 = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); // A2 -> A3 - let a3 = client.new_block_at(&BlockId::Hash(a2.hash())).unwrap().bake().unwrap(); + let a3 = client.new_block_at(&BlockId::Hash(a2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a3.clone()).unwrap(); // A3 -> A4 - let a4 = client.new_block_at(&BlockId::Hash(a3.hash())).unwrap().bake().unwrap(); + let a4 = client.new_block_at(&BlockId::Hash(a3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a4.clone()).unwrap(); // A4 -> A5 - let a5 = client.new_block_at(&BlockId::Hash(a4.hash())).unwrap().bake().unwrap(); + let a5 = client.new_block_at(&BlockId::Hash(a4.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a5.clone()).unwrap(); // A1 -> B2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -188,15 +193,15 @@ pub fn test_children_for_backend(backend: Arc) where client.import(BlockOrigin::Own, b2.clone()).unwrap(); // B2 -> B3 - let b3 = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap().bake().unwrap(); + let b3 = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b3.clone()).unwrap(); // B3 -> B4 - let b4 = client.new_block_at(&BlockId::Hash(b3.hash())).unwrap().bake().unwrap(); + let b4 = client.new_block_at(&BlockId::Hash(b3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b4.clone()).unwrap(); // // B2 -> C3 - let mut builder = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -208,7 +213,7 @@ pub fn test_children_for_backend(backend: Arc) where client.import(BlockOrigin::Own, c3.clone()).unwrap(); // A1 -> D2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -219,18 +224,18 @@ pub fn test_children_for_backend(backend: Arc) where let d2 = builder.bake().unwrap(); client.import(BlockOrigin::Own, d2.clone()).unwrap(); - let genesis_hash = client.info().unwrap().chain.genesis_hash; + let genesis_hash = client.info().chain.genesis_hash; - let children1 = backend.blockchain().children(a4.hash()).unwrap(); + let children1 = blockchain.children(a4.hash()).unwrap(); assert_eq!(vec![a5.hash()], children1); - let children2 = backend.blockchain().children(a1.hash()).unwrap(); + let children2 = blockchain.children(a1.hash()).unwrap(); assert_eq!(vec![a2.hash(), b2.hash(), d2.hash()], children2); - let children3 = backend.blockchain().children(genesis_hash).unwrap(); + let children3 = blockchain.children(genesis_hash).unwrap(); assert_eq!(vec![a1.hash()], children3); - let children4 = backend.blockchain().children(b2.hash()).unwrap(); + let children4 = blockchain.children(b2.hash()).unwrap(); assert_eq!(vec![b3.hash(), c3.hash()], children4); } @@ -242,30 +247,31 @@ pub fn test_blockchain_query_by_number_gets_canonical(backend: Arc B2 -> B3 -> B4 // B2 -> C3 // A1 -> D2 - let client = new_with_backend(backend, false); + let client = TestClientBuilder::with_backend(backend.clone()).build(); + let blockchain = backend.blockchain(); // G -> A1 - let a1 = client.new_block().unwrap().bake().unwrap(); + let a1 = client.new_block(Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a1.clone()).unwrap(); // A1 -> A2 - let a2 = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap().bake().unwrap(); + let a2 = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a2.clone()).unwrap(); // A2 -> A3 - let a3 = client.new_block_at(&BlockId::Hash(a2.hash())).unwrap().bake().unwrap(); + let a3 = client.new_block_at(&BlockId::Hash(a2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a3.clone()).unwrap(); // A3 -> A4 - let a4 = client.new_block_at(&BlockId::Hash(a3.hash())).unwrap().bake().unwrap(); + let a4 = client.new_block_at(&BlockId::Hash(a3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a4.clone()).unwrap(); // A4 -> A5 - let a5 = client.new_block_at(&BlockId::Hash(a4.hash())).unwrap().bake().unwrap(); + let a5 = client.new_block_at(&BlockId::Hash(a4.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, a5.clone()).unwrap(); // A1 -> B2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise B2 has the same hash as A2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -277,15 +283,15 @@ pub fn test_blockchain_query_by_number_gets_canonical(backend: Arc B3 - let b3 = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap().bake().unwrap(); + let b3 = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b3.clone()).unwrap(); // B3 -> B4 - let b4 = client.new_block_at(&BlockId::Hash(b3.hash())).unwrap().bake().unwrap(); + let b4 = client.new_block_at(&BlockId::Hash(b3.hash()), Default::default()).unwrap().bake().unwrap(); client.import(BlockOrigin::Own, b4.clone()).unwrap(); // // B2 -> C3 - let mut builder = client.new_block_at(&BlockId::Hash(b2.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(b2.hash()), Default::default()).unwrap(); // this push is required as otherwise C3 has the same hash as B3 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -297,7 +303,7 @@ pub fn test_blockchain_query_by_number_gets_canonical(backend: Arc D2 - let mut builder = client.new_block_at(&BlockId::Hash(a1.hash())).unwrap(); + let mut builder = client.new_block_at(&BlockId::Hash(a1.hash()), Default::default()).unwrap(); // this push is required as otherwise D2 has the same hash as B2 and won't get imported builder.push_transfer(Transfer { from: AccountKeyring::Alice.into(), @@ -308,23 +314,23 @@ pub fn test_blockchain_query_by_number_gets_canonical(backend: Arc Ok(Extrinsic::IncludeData(data)), + Extrinsic::IncludeData(_) => Err(runtime_primitives::BAD_SIGNATURE), } } } impl ExtrinsicT for Extrinsic { fn is_signed(&self) -> Option { - Some(true) + if let Extrinsic::IncludeData(_) = *self { + Some(false) + } else { + Some(true) + } } } @@ -347,10 +352,6 @@ cfg_if! { fn initialize_block(header: &::Header) { system::initialize_block(header) } - - fn authorities() -> Vec { - panic!("Deprecated, please use `AuthoritiesApi`.") - } } impl client_api::Metadata for Runtime { @@ -361,6 +362,16 @@ cfg_if! { impl client_api::TaggedTransactionQueue for Runtime { fn validate_transaction(utx: ::Extrinsic) -> TransactionValidity { + if let Extrinsic::IncludeData(data) = utx { + return TransactionValidity::Valid { + priority: data.len() as u64, + requires: vec![], + provides: vec![data], + longevity: 1, + propagate: false, + }; + } + system::validate_transaction(utx) } } @@ -461,7 +472,7 @@ cfg_if! { impl offchain_primitives::OffchainWorkerApi for Runtime { fn offchain_worker(block: u64) { let ex = Extrinsic::IncludeData(block.encode()); - runtime_io::submit_extrinsic(&ex) + runtime_io::submit_transaction(&ex).unwrap(); } } @@ -485,10 +496,6 @@ cfg_if! { fn initialize_block(header: &::Header) { system::initialize_block(header) } - - fn authorities() -> Vec { - panic!("Deprecated, please use `AuthoritiesApi`.") - } } impl client_api::Metadata for Runtime { @@ -499,6 +506,16 @@ cfg_if! { impl client_api::TaggedTransactionQueue for Runtime { fn validate_transaction(utx: ::Extrinsic) -> TransactionValidity { + if let Extrinsic::IncludeData(data) = utx { + return TransactionValidity::Valid { + priority: data.len() as u64, + requires: vec![], + provides: vec![data], + longevity: 1, + propagate: false, + }; + } + system::validate_transaction(utx) } } @@ -603,7 +620,7 @@ cfg_if! { impl offchain_primitives::OffchainWorkerApi for Runtime { fn offchain_worker(block: u64) { let ex = Extrinsic::IncludeData(block.encode()); - runtime_io::submit_extrinsic(&ex) + runtime_io::submit_transaction(&ex).unwrap() } } diff --git a/core/test-runtime/src/system.rs b/core/test-runtime/src/system.rs index 5345dc0cdb01bac03d568b94b9499878ddde3120..57a5cb9ea2d852000494e4302dbfb8279238b814 100644 --- a/core/test-runtime/src/system.rs +++ b/core/test-runtime/src/system.rs @@ -21,7 +21,7 @@ use rstd::prelude::*; use runtime_io::{storage_root, enumerated_trie_root, storage_changes_root, twox_128, blake2_256}; use runtime_support::storage::{self, StorageValue, StorageMap}; use runtime_support::storage_items; -use runtime_primitives::traits::{Hash as HashT, BlakeTwo256, Digest as DigestT}; +use runtime_primitives::traits::{Hash as HashT, BlakeTwo256, Digest as DigestT, Header as _}; use runtime_primitives::generic; use runtime_primitives::{ApplyError, ApplyOutcome, ApplyResult, transaction_validity::TransactionValidity}; use parity_codec::{KeyedVec, Encode}; @@ -38,6 +38,7 @@ storage_items! { Number: b"sys:num" => BlockNumber; ParentHash: b"sys:pha" => required Hash; NewAuthorities: b"sys:new_auth" => Vec; + StorageDigest: b"sys:digest" => Digest; } pub fn balance_of_key(who: AccountId) -> Vec { @@ -67,6 +68,7 @@ pub fn initialize_block(header: &Header) { // populate environment. ::put(&header.number); ::put(&header.parent_hash); + ::put(header.digest()); storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &0u32); } @@ -99,18 +101,17 @@ pub fn polish_block(block: &mut Block) { header.state_root = storage_root().into(); // check digest - let mut digest = Digest::default(); - if let Some(storage_changes_root) = storage_changes_root(header.parent_hash.into(), header.number - 1) { + let digest = &mut header.digest; + if let Some(storage_changes_root) = storage_changes_root(header.parent_hash.into()) { digest.push(generic::DigestItem::ChangesTrieRoot(storage_changes_root.into())); } if let Some(new_authorities) = ::take() { digest.push(generic::DigestItem::AuthoritiesChange(new_authorities)); } - header.digest = digest; } -pub fn execute_block(block: Block) { - let ref header = block.header; +pub fn execute_block(mut block: Block) { + let header = &mut block.header; // check transaction trie root represents the transactions. let txs = block.extrinsics.iter().map(Encode::encode).collect::>(); @@ -132,14 +133,13 @@ pub fn execute_block(block: Block) { assert!(storage_root == header.state_root, "Storage root must match that calculated."); // check digest - let mut digest = Digest::default(); - if let Some(storage_changes_root) = storage_changes_root(header.parent_hash.into(), header.number - 1) { + let digest = &mut header.digest; + if let Some(storage_changes_root) = storage_changes_root(header.parent_hash.into()) { digest.push(generic::DigestItem::ChangesTrieRoot(storage_changes_root.into())); } if let Some(new_authorities) = ::take() { digest.push(generic::DigestItem::AuthoritiesChange(new_authorities)); } - assert!(digest == header.digest, "Header digest items must match that calculated."); } /// The block executor. @@ -190,6 +190,7 @@ pub fn validate_transaction(utx: Extrinsic) -> TransactionValidity { requires, provides, longevity: 64, + propagate: true, } } @@ -209,13 +210,16 @@ pub fn finalize_block() -> Header { let txs: Vec<_> = (0..extrinsic_index).map(ExtrinsicData::take).collect(); let txs = txs.iter().map(Vec::as_slice).collect::>(); let extrinsics_root = enumerated_trie_root::(&txs).into(); - + // let mut digest = Digest::default(); let number = ::take().expect("Number is set by `initialize_block`"); let parent_hash = ::take(); + let mut digest = ::take().expect("StorageDigest is set by `initialize_block`"); + + // This MUST come after all changes to storage are done. Otherwise we will fail the + // “Storage root does not match that calculated” assertion. let storage_root = BlakeTwo256::storage_root(); - let storage_changes_root = BlakeTwo256::storage_changes_root(parent_hash, number - 1); + let storage_changes_root = BlakeTwo256::storage_changes_root(parent_hash); - let mut digest = Digest::default(); if let Some(storage_changes_root) = storage_changes_root { digest.push(generic::DigestItem::ChangesTrieRoot(storage_changes_root)); } @@ -307,7 +311,7 @@ mod tests { use runtime_io::{with_externalities, twox_128, blake2_256, TestExternalities}; use parity_codec::{Joiner, KeyedVec}; - use substrate_test_client::{AuthorityKeyring, AccountKeyring}; + use substrate_test_runtime_client::{AuthorityKeyring, AccountKeyring}; use crate::{Header, Transfer}; use primitives::{Blake2Hasher, map}; use primitives::storage::well_known_keys; diff --git a/core/test-runtime/wasm/Cargo.lock b/core/test-runtime/wasm/Cargo.lock index 2a8f1942a347c2c30a1729dcf2c1b8337384c6e1..19c6b36ebcb745917bb8ce353cf6a9e1e0cc36d1 100644 --- a/core/test-runtime/wasm/Cargo.lock +++ b/core/test-runtime/wasm/Cargo.lock @@ -1,5 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "adler32" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "aes-ctr" version = "0.3.0" @@ -33,7 +38,7 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.6.10" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -44,12 +49,12 @@ name = "aio-limited" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -79,7 +84,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -87,27 +92,26 @@ name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.14" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -115,19 +119,22 @@ name = "backtrace-sys" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "base-x" -version = "0.2.4" +name = "base58" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "base58" -version = "0.1.0" +name = "base64" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "bigint" @@ -179,10 +186,10 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.7.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -198,7 +205,7 @@ dependencies = [ [[package]] name = "block-padding" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -209,9 +216,14 @@ name = "bs58" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "build_const" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bumpalo" -version = "2.4.1" +version = "2.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -250,12 +262,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.30" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -263,8 +275,8 @@ name = "chrono" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -273,7 +285,7 @@ name = "clear_on_drop" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -289,12 +301,28 @@ name = "constant_time_eq" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "crc" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -346,7 +374,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -360,7 +388,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -380,7 +408,7 @@ name = "crossbeam-utils" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -388,7 +416,7 @@ name = "crossbeam-utils" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -399,7 +427,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crunchy" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -440,14 +468,14 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -457,13 +485,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "derive_more" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -482,11 +510,6 @@ dependencies = [ "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "dns-parser" version = "0.8.0" @@ -502,7 +525,7 @@ version = "1.0.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -510,7 +533,7 @@ dependencies = [ [[package]] name = "either" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -529,7 +552,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -543,15 +566,7 @@ name = "erased-serde" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "error-chain" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -559,7 +574,7 @@ name = "failure" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -568,10 +583,10 @@ name = "failure_derive" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -581,33 +596,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "fixed-hash" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "fnv" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "foreign-types" -version = "0.3.2" +name = "flate2" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "foreign-types-shared" -version = "0.1.1" +name = "fnv" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -631,7 +646,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.1.25" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -639,7 +654,7 @@ name = "futures-cpupool" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -672,7 +687,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "get_if_addrs-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -682,7 +697,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -692,10 +707,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hash256-std-hasher" -version = "0.12.0" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -717,7 +732,7 @@ name = "heapsize" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -725,7 +740,7 @@ name = "heck" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -735,16 +750,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hex-literal" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "hex-literal-impl" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,6 +794,16 @@ dependencies = [ "hmac 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "http" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "httparse" version = "1.3.3" @@ -816,7 +841,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "impl-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -829,21 +862,26 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ipnet" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "itoa" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "js-sys" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -874,53 +912,51 @@ name = "lazy_static" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "lazycell" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" -version = "0.2.50" +version = "0.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libp2p" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core-derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-dns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-floodsub 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-identify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-kad 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-mdns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-mplex 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-noise 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-ping 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-plaintext 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-ratelimit 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-secio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-tcp 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-uds 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-yamux 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core-derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-deflate 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-dns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-floodsub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identify 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-kad 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-mdns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-mplex 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-noise 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-ping 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-plaintext 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-ratelimit 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-secio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-tcp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-uds 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-wasm-ext 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-websocket 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-yamux 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-core" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -929,64 +965,74 @@ dependencies = [ "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "multistream-select 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "secp256k1 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-core-derive" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libp2p-deflate" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-dns" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-floodsub" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "cuckoofilter 0.3.2 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -996,28 +1042,28 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-kad" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1026,54 +1072,55 @@ dependencies = [ "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-mdns" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-mplex" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1081,103 +1128,107 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", "snow 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "x25519-dalek 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-ping" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-plaintext" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-ratelimit" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-secio" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-futures 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-tcp" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ipnet 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1185,26 +1236,57 @@ dependencies = [ [[package]] name = "libp2p-uds" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libp2p-websocket" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "soketto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-rustls 0.10.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libp2p-yamux" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "yamux 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "yamux 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1229,12 +1311,20 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lock_api" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1269,7 +1359,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "merlin" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1278,17 +1368,44 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "miniz-sys" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide_c_api" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "mio" -version = "0.6.16" +version = "0.6.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1296,25 +1413,14 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "mio-extras" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "mio-uds" version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1334,7 +1440,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1347,9 +1453,9 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1373,23 +1479,27 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.39" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "num_cpus" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1410,31 +1520,6 @@ name = "opaque-debug" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "openssl" -version = "0.10.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "openssl-sys" -version = "0.9.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "owning_ref" version = "0.3.3" @@ -1463,7 +1548,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1471,15 +1556,15 @@ name = "parity-codec-derive" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-multiaddr" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1487,24 +1572,31 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-multihash" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parity-send-wrapper" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "parity-wasm" version = "0.31.3" @@ -1540,15 +1632,25 @@ dependencies = [ "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parking_lot_core" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1556,11 +1658,11 @@ name = "parking_lot_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1568,31 +1670,46 @@ name = "parking_lot_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot_core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "paste" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "paste-impl" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1610,28 +1727,23 @@ name = "percent-encoding" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "pkg-config" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "primitive-types" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-crate" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1644,12 +1756,12 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1659,7 +1771,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "0.4.27" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1667,7 +1779,7 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.4.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1685,7 +1797,7 @@ name = "quote" version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1693,7 +1805,7 @@ name = "rand" version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1703,10 +1815,10 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1716,9 +1828,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1726,17 +1838,17 @@ name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1744,7 +1856,7 @@ name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1779,12 +1891,12 @@ dependencies = [ [[package]] name = "rand_jitter" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1794,10 +1906,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1805,7 +1917,7 @@ name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1823,7 +1935,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1834,7 +1946,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1848,7 +1960,7 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.51" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1856,24 +1968,24 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" -version = "1.1.2" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1884,17 +1996,17 @@ name = "ring" version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-demangle" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1910,19 +2022,32 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustls" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rw-stream-sink" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ryu" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1935,51 +2060,38 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.0.0" -source = "git+https://github.com/w3f/schnorrkel#3179838da9dd4896c12bb910e7c42477a3250641" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "schnorrkel" -version = "0.1.0" +name = "scopeguard" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "scopeguard" -version = "0.3.3" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "secp256k1" -version = "0.12.0" +name = "sct" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2002,20 +2114,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2023,9 +2135,20 @@ name = "serde_json" version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sha-1" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2050,7 +2173,7 @@ name = "sha2" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2058,10 +2181,10 @@ dependencies = [ [[package]] name = "sha3" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2081,16 +2204,6 @@ dependencies = [ "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "slog-async" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "slog-json" version = "2.3.0" @@ -2098,7 +2211,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2132,7 +2245,25 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "soketto" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2150,10 +2281,10 @@ name = "sr-api-macros" version = "2.0.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2178,9 +2309,9 @@ version = "2.0.0" dependencies = [ "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-std 2.0.0", "substrate-primitives 2.0.0", @@ -2199,7 +2330,7 @@ version = "2.0.0" dependencies = [ "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", ] @@ -2209,7 +2340,7 @@ name = "srml-executive" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2222,7 +2353,7 @@ name = "srml-metadata" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-primitives 2.0.0", ] @@ -2234,8 +2365,8 @@ dependencies = [ "bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2248,31 +2379,31 @@ dependencies = [ name = "srml-support-procedural" version = "2.0.0" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "srml-support-procedural-tools 2.0.0", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "srml-support-procedural-tools" version = "2.0.0" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "srml-support-procedural-tools-derive 2.0.0", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "srml-support-procedural-tools-derive" version = "2.0.0" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2281,7 +2412,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2304,50 +2435,6 @@ name = "static_slice" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "stdweb" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-macros 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-runtime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base-x 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "stream-cipher" version = "0.3.0" @@ -2367,19 +2454,19 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-bip39" -version = "0.2.0" -source = "git+https://github.com/paritytech/substrate-bip39#a28806512c977992af8d6740d45352f5a1c832a0" +version = "0.2.1" +source = "git+https://github.com/paritytech/substrate-bip39#44307fda4ea17fe97aeb93af317fbc8f6ed34193" dependencies = [ "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)", + "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2387,15 +2474,15 @@ dependencies = [ name = "substrate-client" version = "2.0.0" dependencies = [ - "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.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.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hex-literal 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2447,33 +2534,34 @@ name = "substrate-consensus-common" version = "2.0.0" dependencies = [ "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", + "sr-std 2.0.0", "sr-version 2.0.0", "substrate-inherents 2.0.0", "substrate-primitives 2.0.0", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-consensus-slots" version = "2.0.0" dependencies = [ - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "substrate-client 2.0.0", "substrate-consensus-common 2.0.0", "substrate-inherents 2.0.0", "substrate-primitives 2.0.0", - "tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2481,12 +2569,12 @@ name = "substrate-executor" version = "2.0.0" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-version 2.0.0", "substrate-panic-handler 2.0.0", @@ -2495,7 +2583,7 @@ dependencies = [ "substrate-state-machine 2.0.0", "substrate-trie 2.0.0", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2503,7 +2591,7 @@ name = "substrate-inherents" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", ] @@ -2531,7 +2619,7 @@ dependencies = [ name = "substrate-panic-handler" version = "2.0.0" dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2544,29 +2632,30 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", - "substrate-bip39 0.2.0 (git+https://github.com/paritytech/substrate-bip39)", + "substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)", "tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "twox-hash 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "twox-hash 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-serializer" version = "2.0.0" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2576,8 +2665,9 @@ version = "2.0.0" dependencies = [ "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-panic-handler 2.0.0", "substrate-primitives 2.0.0", "substrate-trie 2.0.0", @@ -2589,28 +2679,30 @@ dependencies = [ name = "substrate-telemetry" version = "2.0.0" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-test-runtime" version = "2.0.0" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2656,35 +2748,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "subtle" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.33" +version = "0.15.34" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "synstructure" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "termcolor" version = "1.0.4" @@ -2698,9 +2785,9 @@ name = "termion" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2717,9 +2804,9 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2749,31 +2836,32 @@ name = "tk-listen" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio" -version = "0.1.16" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-current-thread 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2784,17 +2872,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-current-thread" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2802,19 +2890,19 @@ name = "tokio-dns-unofficial" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-executor" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2822,9 +2910,9 @@ name = "tokio-fs" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2833,7 +2921,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2843,25 +2931,38 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-rustls" +version = "0.10.0-alpha.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-sync" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2870,38 +2971,46 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-threadpool" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-timer" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-trace-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2910,9 +3019,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2924,11 +3033,11 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2937,10 +3046,10 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.10" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2975,7 +3084,7 @@ dependencies = [ [[package]] name = "twox-hash" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2993,11 +3102,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "uint" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3020,7 +3129,7 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3057,11 +3166,6 @@ name = "utf8-ranges" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "vcpkg" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "version_check" version = "0.1.5" @@ -3074,103 +3178,141 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen-macro 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bumpalo 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-futures" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro-support 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro-support 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen-webidl" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "weedle 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-timer" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmi" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi-validation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasmi-validation" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "web-sys" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-webidl 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-webidl 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki-roots" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "weedle" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3183,7 +3325,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3205,7 +3347,7 @@ name = "winapi-util" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3218,28 +3360,10 @@ name = "wincolor" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ws" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" @@ -3251,21 +3375,21 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "yamux" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3280,45 +3404,68 @@ name = "zeroize" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "zeroize" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "zeroize_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zeroize_derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] +"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" "checksum aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" -"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f10b352bc3fc08ae24dc5d2d3ddcac153678533986122dc283d747b12071000" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9893d63fc3b1c44231e667da6836a33f27d8b6b3bdc82f83da5dfd579d1b6528" "checksum asn1_der_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e7f92edafad155aff997fa5b727c6429b91e996b5a5d62a2b0adbae1306b5fe" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4" +"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" +"checksum backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)" = "1a13fc43f04daf08ab4f71e3d27e1fc27fc437d3e95ac0063a796d92fb40f39b" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" -"checksum base-x 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d55aa264e822dbafa12db4d54767aff17c6ba55ea2d8559b3e17392c7d000e5d" "checksum base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" +"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ebecac13b3c745150d7b6c3ea7572d372f09d627c2077e893bf26c5c7f70d282" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5da9b3d9f6f585199287a473f4f8dfab6566cf827d15c00c219f53c645687ead" "checksum blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91721a6330935673395a0607df4d49a9cb90ae12d259f1b3e0a3f6e1d486872e" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum block-buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1339a1042f5d9f295737ad4d9a6ab6bf81c84a933dba110b9200cd6d1448b814" -"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d" +"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" -"checksum block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d75255892aeb580d3c566f213a2b6fdc1c66667839f45719ee1d30ebf2aea591" +"checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" "checksum bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0de79cfb98e7aa9988188784d8664b4b5dad6eaaa0863b91d9a4ed871d4f7a42" -"checksum bumpalo 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4639720be048090544634e0402490838995ccdc9d2fe648f528f30d3c33ae71f" +"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" +"checksum bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "84dca3afd8e01b9526818b7963e5b4916063b3cdf9f10cf6b73ef0bd0ec37aa5" "checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" -"checksum cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "d01c69d08ff207f231f07196e30f84c70f1c815b04f980f8b7b01ff01f05eb92" -"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" +"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" +"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum crossbeam 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4c7ea749d9fb09e23c5cb17e3b70650860553a0e2744e38446b1803bf7db94" "checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" @@ -3330,36 +3477,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" -"checksum crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c240f247c278fa08a6d4820a6a222bfc6e0d999e51ba67be94f44c905b2161f2" +"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" "checksum crypto-mac 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "779015233ac67d65098614aec748ac1c756ab6677fa2e14cf8b37c08dfed1198" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" "checksum cuckoofilter 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" -"checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1" +"checksum curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "750226d75fc2f5a8daec6e7477624e258674023eb73d8d647f63b943ca182a4a" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" -"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615" +"checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" -"checksum discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" "checksum dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d33be9473d06f75f58220f71f7a9317aca647dc061dbd3c361b0bef505fbea" "checksum ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81956bcf7ef761fb4e1d88de3fa181358a0d26cbcb9755b587a08f9119824b86" -"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac" +"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" "checksum elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "073be79b6538296faf81c631872676600616073817dd9a440c477ad09b408983" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c7464757b80de8930c91c9afe77ddce501826bf9d134a87db2c67d9dc177e2c" "checksum erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3beee4bc16478a1b26f2e80ad819a52d24745e292f521a63c16eea5f74b7eb60" -"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" -"checksum fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a557e80084b05c32b455963ff565a9de6f2866da023d6671705c6aff6f65e01c" +"checksum fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" +"checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" -"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" +"checksum futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a2037ec1c6c1c4f79557762eab1f7eae1f64f6cb418ace90fae88f0942b60139" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" @@ -3367,60 +3511,68 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "abddb55a898d32925f3148bd281174a68eeb68bbfd9a5938a57b18f506ee4ef7" "checksum get_if_addrs-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d04f9fb746cf36b191c00f3ede8bde9c8e64f9f4b05ae2694a9ccf5e3f5ab48" "checksum hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fb417e5c470acdd61068c79767d0e65962e70836cf6c9dfd2409f06345ce0" -"checksum hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1224388a21c88a80ae7087a2a245ca6d80acc97a9186b75789fb3eeefd0609af" +"checksum hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b2027c19ec91eb304999abae7307d225cf93be42af53b0039f76e98ed5af86" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" "checksum hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8e04cb7a5051270ef3fa79f8c7604d581ecfa73d520e74f554e45541c4b5881a" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" -"checksum hex-literal 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "27455ce8b4a6666c87220e4b59c9a83995476bdadc10197905e61dbe906e36fa" -"checksum hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d340b6514f232f6db1bd16db65302a5278a04fef9ce867cb932e7e5fa21130a" +"checksum hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc2928beef125e519d69ae1baa8c37ea2e0d3848545217f6db0179c5eb1d639" +"checksum hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "520870c3213943eb8d7803e80180d12a6c7ceb4ae74602544529d1643dc4ddda" "checksum hmac 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a13f4163aa0c5ca1be584aace0e2212b2e41be5478218d4f657f5f778b2ae2a" "checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" "checksum hmac-drbg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe727d41d2eec0a6574d887914347e5ff96a3b87177817e2a9820c5c87fecc2" +"checksum http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2050d823639fbeae26b2b5ba09aca8907793117324858070ade0673c49f793b" "checksum impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5158079de9d4158e0ce1de3ae0bd7be03904efc40b3d7dd8b8c301cbf6b52b56" +"checksum impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d26be4b97d738552ea423f76c4f681012ff06c3fa36fa968656b3679f60b4a1" "checksum integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ea155abb3ba6f382a75f1418988c05fe82959ed9ce727de427f9cfd425b0c903" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3c994fd445b81741d77f6bcd227d6ed645b95b35a2ecfd2050767450ff1c0b6d" +"checksum ipnet 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e61c2da0d0f700c77d2d313dbf4f93e41d235fa12c6681fee06621036df4c2af" +"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +"checksum js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "9987e7c13a91d9cf0efe59cca48a3a7a70e2b11695d5a4640f85ae71e28f5e73" "checksum keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" -"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" -"checksum libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0231edab431064b30b7749484a39735eb36492cef4658c372c9059e58c3003aa" -"checksum libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a3bad2ed26297112847678683dd221473a0d44297250b61f004e1b35e72493" -"checksum libp2p-core-derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f765f103b680cbed910b02bfdbdcfce5b1142899c93e51acb960bf59b6f81b1" -"checksum libp2p-dns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b129d20cc8cbb6ce5da8361045649c024659173e246c5dfbf20ae06071c046a" -"checksum libp2p-floodsub 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70d68816b8435d6788399416eb2f0a6974fb1d15c4be5c30141f87c8e81746df" -"checksum libp2p-identify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "718ca645a065fd70855ca6042a7df686c24cd21add750c37a82c811fbd1e5c43" -"checksum libp2p-kad 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bbe27c623a6a720efd5d704347838972062f89149a9c3cd149748da60bdcd3e0" -"checksum libp2p-mdns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9bc1a5d85f4812cae6367b49a432763fe28997bac7c530dc55b70ec18a78aa7" -"checksum libp2p-mplex 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe5a858342a1cc89464474f7edc4bae1da649b9c823a3e04d9fb494493601746" -"checksum libp2p-noise 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc6b5185c50a52a12e7bbe2ee7799059e24de4e52ab25edbfd26c8ab8515d317" -"checksum libp2p-ping 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7905c1431ad115bee83405770629a27d6f17153ad02ec9670a7347998ef20e22" -"checksum libp2p-plaintext 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc17626763ded57da8fed73187c2d9f6ebb89d30838673c430315bf560c7e4db" -"checksum libp2p-ratelimit 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2409d08b809ab1a74269597f7da2829d117cc11b9ed3343af33fc20831619726" -"checksum libp2p-secio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258cdc6742945c8f6402997bbbf36733588e2db18e5a0014da6d46e3ccfb92cf" -"checksum libp2p-tcp 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b5691e2ba2720d42bd1e93d6b90239fa9235c1956ef6a5f1dd499a7ae2767be" -"checksum libp2p-uds 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ab0b9ca050105fd94229c48911c0c84aef4d6b86a53d1b6df81d938354e47e" -"checksum libp2p-yamux 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6ff51a5b2056bacee1c9f2ed8455cdf3c5c619261ddb4efc783119130aaf52" +"checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880" +"checksum libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6abde4e6fc777dc06ae2a15202ddedb1a38d7c71ed16bc10fa704b03f73aec37" +"checksum libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ceb4791289534d4c1ad8e4bd3c6f06d3670efa55ce71482951a287df93ddd1" +"checksum libp2p-core-derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "851a59dcaab66c96777ae0cace96de88a700243c3b8360ab51c7e093f3727066" +"checksum libp2p-deflate 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "902b44e92e1f8b7e697b3a186d15c841e0e38037f14286513207a5407650a635" +"checksum libp2p-dns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71a6630a84552b39e5f752e1f6a951d31f3211079465d2e7af73491b6f48fc3f" +"checksum libp2p-floodsub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9fced4da0c31e0dc8a759472c65fab41db40c01de2d93bc45e1431c13f0564f0" +"checksum libp2p-identify 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba5e882d72c71cdf77f45ab68dd715451d3b78a23085f8d385c7a31ec1b4272" +"checksum libp2p-kad 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d71966dbbb4cedcfcdb1d4c87d5dbb6f3f07b465d1ca74f2624256669997d1f2" +"checksum libp2p-mdns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdbdaea6f0049cc09ba5db00308f5b93105a8a33b65ba2e36bd35da707850ea2" +"checksum libp2p-mplex 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b351bfd67e97154e7b60f62402237671486c8a89f83eabdb6838f37d4d5f006" +"checksum libp2p-noise 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44324032b2f9260d2b862c741d79d250dc02298dbba56354a992528a826ee2d5" +"checksum libp2p-ping 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1ac43ffd01de4210cf1b969bbb55a008c77f9ec22b74df26a6590bb6bd4c93f" +"checksum libp2p-plaintext 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0506e10770bcbcb59f2a6154ce93c8fd5cb9730b6ceb5aa1463164af1fd0b9c6" +"checksum libp2p-ratelimit 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3886b79a35c0348497bab763517a9a2b4965173f4b4c7438d59f1e4dcf5122ff" +"checksum libp2p-secio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b811272e5cd86d39bd71fb94687025d9802b13daf0998ebe0d3f2885c636c51a" +"checksum libp2p-tcp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b2c54cb75f17557de6ce0149aa03e729455e2d240f84d854272bc4b11012a324" +"checksum libp2p-uds 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbedf4a1e72a5f67523915414e9e12d71d128731873f0f24d8b878398fb47aa4" +"checksum libp2p-wasm-ext 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c1f615b56aa2a6f4ec07bf9667be9fff8877b9c5bd5335601af47490eda341" +"checksum libp2p-websocket 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d1bfe60577558f48a9fdf9f35c0ee2dc5baa01f685ff847d3b5cf4f12ee135" +"checksum libp2p-yamux 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf4bfc7ff127cd622502dbe56f10513dd6776b970e33d8ebb6e367f0752324f6" "checksum libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "688e8d65e495567c2c35ea0001b26b9debf0b4ea11f8cccc954233b75fc3428a" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +"checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7623b01a4f1b7acb7cf8e3f678f05e15e6ae26cb0b738dfeb5cc186fd6b82ef4" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" -"checksum merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "83c2dda19c01176e8e7148f7bdb88bbdf215a8db0641f89fc40e4b81736aeda5" -"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432" -"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" +"checksum merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c39467de91b004f5b9c06fac5bbc8e7d28309a205ee66905166b70804a71fea" +"checksum miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9e3ae51cea1576ceba0dde3d484d30e6e5b86dee0b2d412fe3a16a15c98202" +"checksum miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c468f2369f07d651a5d0bb2c9079f8488a66d5466efe42d0c5c6466edcb7f71e" +"checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab" +"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum multistream-select 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f989d40aab0ed0d83c1cdb4856b5790e980b96548d1a921f280e985eb049f38d" @@ -3428,40 +3580,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d138afcce92d219ccb6eb53d9b1e8a96ac0d633cfd3c53cd9856d96d1741bb8" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" -"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" "checksum once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" -"checksum openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)" = "84321fb9004c3bce5611188a644d6171f895fa2889d155927d528782edb21c5d" -"checksum openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)" = "cb534d752bf98cf363b473950659ac2546517f9c6be9723771614ab3f03bbc9e" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb43c05fb71c03b4ea7327bf15694da1e0f23f19d5b1e95bab6c6d74097e336" "checksum parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00a486fd383382ddcb2de928364b1f82571c1e48274fc43b7667a4738ee4056c" -"checksum parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18a130a727008cfcd1068a28439fe939897ccad28664422aeca65b384d6de6d0" -"checksum parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e8eab0287ccde7821e337a124dc5a4f1d6e4c25d10cc91e3f9361615dd95076" +"checksum parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "045b3c7af871285146300da35b1932bb6e4639b66c7c98e85d06a32cbc4e8fa7" +"checksum parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05d6a68e07ab34a9e87bd8dd4936f6bb5be21e4f6dbcdbaf04d8e854eba0af01" +"checksum parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" "checksum parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)" = "511379a8194230c2395d2f5fa627a5a7e108a9f976656ce723ae68fca4097bfc" "checksum parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4d05f1349491390b1730afba60bb20d55761bef489a954546b58b4b34e1e2ac" "checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +"checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" -"checksum paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f50392d1265092fbee9273414cc40eb6d47d307bd66222c477bb8450c8504f9d" -"checksum paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3cd512fe3a55e8933b2dcad913e365639db86d512e4004c3084b86864d9467a" +"checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" +"checksum paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4a4a1c555c6505821f9d58b8779d0f630a6b7e4e1be24ba718610acf01fa79" +"checksum paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "26e796e623b8b257215f27e6c80a5478856cae305f5b59810ff9acdaa34570e6" "checksum pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" -"checksum primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edb92f1ebfc177432c03287b15d48c202e6e2c95993a7af3ba039abb43b1492e" -"checksum proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c6cf4e5b00300d151dfffae39f529dfa5188f42eeb14201229aa420d6aad10c" +"checksum primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6e8612a8dc70f26276fed6131c153ca277cf275ee0a5e2a50cd8a69c697beb8f" +"checksum proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" "checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" -"checksum proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e90aa19cd73dedc2d0e1e8407473f073d735fef0ab521438de6da8ee449ab66" +"checksum proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0c1dd4172a1e1f96f709341418f49b11ea6c2d95d53dca08c0f74cbd332d9cf3" "checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" -"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" -"checksum protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24d5d73d2b88fddb8b8141f2730d950d88772c940ac4f8f3e93230b9a99d92df" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a151c11a92df0059d6ab446fafa3b21a1210aad4bc2293e1c946e8132b10db01" "checksum quick-error 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5fb6ccf8db7bbcb9c2eae558db5ab4f3da1c2a87e4e597ed394726bc8ea6ca1d" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" @@ -3474,63 +3626,60 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -"checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" +"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" +"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f" -"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" +"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" +"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" -"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" +"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d548a40fe17c3a77d54b82457b79fcc9b8a288d509ca20fbf5aa1dac386d22d6" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" +"checksum rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" +"checksum rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9cbe61c20455d3015b2bb7be39e1872310283b8e5a52f5b242b0ac7581fe78" +"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" "checksum safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f7bf422d23a88c16d5090d455f182bc99c60af4df6a345c63428acf5129e347" -"checksum schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)" = "" -"checksum schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a700659388785588c75b197cecda0f23c7112a9281ef703e8ffc651061ce014c" +"checksum schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5eff518f9bed3d803a0d002af0ab96339b0ebbedde3bec98a684986134b7a39" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum secp256k1 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4070f3906e65249228094cf97b04a90799fba04468190bbbcfa812309cf86e32" +"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" +"checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0eddf2e8f50ced781f288c19f18621fa72a3779e3cb58dbf23b07469b0abeb4" -"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" -"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c" +"checksum serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "a72e9b96fa45ce22a4bc23da3858dfccfd60acd28a25bcd328a98fdd6bea43fd" +"checksum serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "101b495b109a3e3ca8c4cbe44cf62391527cdfb6ba15821c5ce80bcd5ea23f9f" "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" +"checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" "checksum sha2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d963c78ce367df26d7ea8b8cc655c651b42e8a1e584e869c1e17dae3ccb116a" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" -"checksum sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34a5e54083ce2b934bf059fdf38e7330a154177e029ab6c4e18638f2f624053a" +"checksum sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e1a2eec401952cd7b12a84ea120e2d57281329940c3f93c2bf04f462539508e" -"checksum slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e544d16c6b230d84c866662fe55e31aacfca6ae71e6fc49ae9a311cb379bfc2f" "checksum slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc0d2aff1f8f325ef660d9a0eb6e6dcd20b30b3f581a5897f58bf42d061c37a" "checksum slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "60c04b4726fa04595ccf2c2dad7bcd15474242c4c5e109a8a376e8a2c9b1539a" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum snow 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5a64f02fd208ef15bd2d1a65861df4707e416151e1272d02c8faafad1c138100" +"checksum soketto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8cf3ae22c0bce5437c7dce6a2b00e492c19da1feb21ad64a7b6fd7058438c3f2" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "92a7e0c5e3dfb52e8fbe0e63a1b947bbb17b4036408b151353c4491374931362" -"checksum stdweb 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a3edad410e603184d656e2abded5fd4d3d6e93d5763d21130dbaf99795db74eb" -"checksum stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e21ebd9179de08f2300a65454268a17ea3de204627458588c84319c4def3930" -"checksum stdweb-internal-macros 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1635afd059cbfac7d5b1274f0c44cec110c1e013c48e8bbc22e07e52696cf887" -"checksum stdweb-internal-runtime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a2a2f4a2eb556337b2d1a302630bbddf989ae383c70393e89b48152b9896cbda" "checksum stream-cipher 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8861bc80f649f5b4c9bd38b696ae9af74499d479dbfb327f0607de6b326a36bc" "checksum strum 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1810e25f576e7ffce1ff5243b37066da5ded0310b3274c20baaeccb1145b2806" "checksum strum_macros 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "572a2f4e53dd4c3483fd79e5cc10ddd773a3acb1169bbfe8762365e107110579" -"checksum substrate-bip39 0.2.0 (git+https://github.com/paritytech/substrate-bip39)" = "" +"checksum substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)" = "" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" -"checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" -"checksum syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)" = "ec52cd796e5f01d0067225a5392e70084acc4c0013fa71d55166d38a8b307836" -"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" -"checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" +"checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829" +"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" +"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" @@ -3538,58 +3687,64 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" "checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" "checksum tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5462b0f968c0457efe38fcd2df7e487096b992419e4f5337b06775a614bbda4b" -"checksum tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fcaabb3cec70485d0df6e9454fe514393ad1c4070dee8915f11041e95630b230" +"checksum tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "94a1f9396aec29d31bb16c24d155cfa144d1af91c40740125db3131bdaf76da8" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" -"checksum tokio-current-thread 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c756b04680eea21902a46fca4e9f410a2332c04995af590e07ff262e2193a9a3" +"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" "checksum tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "82c65483db54eb91b4ef3a9389a3364558590faf30ce473141707c0e16fda975" -"checksum tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30c6dbf2d1ad1de300b393910e8a3aa272b724a400b6531da03eed99e329fbf0" +"checksum tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "83ea44c6c0773cc034771693711c35c677b4b5a4b21b9e7071704c54de7d555e" "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce" -"checksum tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1bf2b9dac2a0509b5cfd1df5aa25eafacb616a42a491a13604d6bbeab4486363" +"checksum tokio-rustls 0.10.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)" = "316fdbc899efec48b3b492bd0f339e6d81c4ee96a409257572147ec341943452" +"checksum tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5b2f843ffdf8d6e1f90bddd48da43f99ab071660cd92b7ec560ef3cdfd7a409a" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" -"checksum tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "742e511f6ce2298aeb86fc9ea0d8df81c2388c6ebae3dc8a7316e8c9df0df801" -"checksum tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2910970404ba6fa78c5539126a9ae2045d62e3713041e447f695f41405a120c6" +"checksum tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72558af20be886ea124595ea0f806dd5703b8958e4705429dd58b3d8231f72f2" +"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" +"checksum tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "350c9edade9830dc185ae48ba45667a445ab59f6167ef6d0254ec9d2430d9dd3" "checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" -"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +"checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039" "checksum trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba73747fd3a64ab531274c04cb588dfa9d30d972d62990831e63fbce2cfec59" "checksum trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfa2e20c4f1418ac2e71ddc418e35e1b56e34022e2146209ffdbf1b2de8b1bd9" "checksum twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d261e83e727c8e2dbb75dacac67c36e35db36a958ee504f2164fc052434e1" -"checksum twox-hash 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09871da9f15424236082e0b220fd404a4eb6bebc7205c67653701229234ac64c" +"checksum twox-hash 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6c7bcecad121018bdcd6b709fa2325b004878fcb3d3067934ce90749f0faff9a" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" -"checksum uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7780bb27fd8a22295e0d9d53ae3be253f715a0dccb1808527f478f1c2603708" +"checksum uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2143cded94692b156c356508d92888acc824db5bffc0b4089732264c6fcf86d4" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" -"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" +"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2c64cdf40b4a9645534a943668681bcb219faf51874d4b65d2e0abda1b10a2ab" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "ffde3534e5fa6fd936e3260cd62cd644b8656320e369388f9303c955895e35d4" -"checksum wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "40c0543374a7ae881cdc5d32d19de28d1d1929e92263ffa7e31712cc2d53f9f1" -"checksum wasm-bindgen-futures 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "0ad171fc1f6e43f97d155d27f4ee5657bd8aa5cce7c497ef3a0a0c5b44618b2d" -"checksum wasm-bindgen-macro 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "f914c94c2c5f4c9364510ca2429e59c92157ec89429243bcc245e983db990a71" -"checksum wasm-bindgen-macro-support 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "9168c413491e4233db7b6884f09a43beb00c14d11d947ffd165242daa48a2385" -"checksum wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "326c32126e1a157b6ced7400061a84ac5b11182b2cda6edad7314eb3ae9ac9fe" -"checksum wasm-bindgen-webidl 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "613dbf4d7d3bf10aeb212b35de14a8ef07222c26526d4f931061a83fc9e2a851" -"checksum wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "21ef487a11df1ed468cf613c78798c26282da5c30e9d49f824872d4c77b47d1d" -"checksum web-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "24129e4be2281109b3e15a328d3d7f233ee232a5405f75ba1e9bb59a25ebc4d4" -"checksum weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26a4c67f132386d965390b8a734d5d10adbcd30eb5cc74bd9229af8b83f10044" +"checksum wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "b7ccc7b93cfd13e26700a9e2e41e6305f1951b87e166599069f77d10358100e6" +"checksum wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "1953f91b1608eb1522513623c7739f047bb0fed4128ce51a93f08e12cc314645" +"checksum wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fa1af11c73eca3dc8c51c76ea475a4416e912da6402064a49fc6c0214701866d" +"checksum wasm-bindgen-macro 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "0f69da5696545d7ca6607a2e4b1a0edf5a6b36b2c49dbb0f1df6ad1d92884047" +"checksum wasm-bindgen-macro-support 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d4246f3bc73223bbb846f4f2430a60725826a96c9389adf715ed1d5af46dec6" +"checksum wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "c08381e07e7a79e5e229ad7c60d15833d19033542cc5dd91d085df59d235f4a6" +"checksum wasm-bindgen-webidl 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "1f42ff7adb8102bf5ad8adbc45b1635c520c8175f9fdf6eb2c54479d485d435a" +"checksum wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad9ac33c834103916e373d648adf65f58c83fb3d8a0f3e6b9a64bca7253a4dca" +"checksum wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aebbaef470840d157a5c47c8c49f024da7b1b80e90ff729ca982b2b80447e78b" +"checksum wasmi-validation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab380192444b3e8522ae79c0a1976e42a82920916ccdfbce3def89f456ea33f3" +"checksum web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "540b8259eb242ff3a566fa0140bda03a4ece4e5c226e1284b5c95dddcd4341f6" +"checksum webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4f7e1cd7900a3a6b65a3e8780c51a3e6b59c0e2c55c6dc69578c288d69f7d082" +"checksum webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c10fa4212003ba19a564f25cd8ab572c6791f99a03cc219c13ed35ccab00de0e" +"checksum weedle 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc44aa200daee8b1f3a004beaf16554369746f1b4486f0cf93b0caf8a3c2d1e" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" -"checksum ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "329d3e6dd450a9c5c73024e1047f0be7e24121a68484eb0b5368977bee3cf8c3" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -"checksum x25519-dalek 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4aca1ba6bec2719576bd20dfe5b24d9359552e616d10bff257e50cd85f745d17" -"checksum yamux 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9073f5dbc901abb0b2ec4f866e726fed2f54953bdf81f8a5fde7762b7cc3b3" +"checksum x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" +"checksum yamux 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "01bd67889938c48f0049fc60a77341039e6c3eaf16cb7693e6ead7c0ba701295" "checksum zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ddfeb6eee2fb3b262ef6e0898a52b7563bb8e0d5955a313b3cf2f808246ea14" +"checksum zeroize 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b60a6c572b91d8ecb0a460950d84fe5b40699edd07d65f73789b31237afc8f66" +"checksum zeroize_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9dac4b660d969bff9c3fe1847a891cacaa8b21dd5f2aae6e0a3e0975aea96431" diff --git a/core/test-runtime/wasm/build.sh b/core/test-runtime/wasm/build.sh index 635532babf3e8329e31ab4dbae91047809bb29e6..059e475c71e78c7c23f2acb6ffcfa7a8e31f95b6 100755 --- a/core/test-runtime/wasm/build.sh +++ b/core/test-runtime/wasm/build.sh @@ -6,7 +6,7 @@ if cargo --version | grep -q "nightly"; then else CARGO_CMD="cargo +nightly" fi -CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release +CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release "$@" for i in substrate_test_runtime do wasm-gc "target/wasm32-unknown-unknown/release/$i.wasm" "target/wasm32-unknown-unknown/release/$i.compact.wasm" diff --git a/core/transaction-pool/Cargo.toml b/core/transaction-pool/Cargo.toml index c3f9dce5fe28bfc71886908a0f60c5d8f9e472f8..2bcad4d4d6c2e624b0b887e4c3d34ff8cd6199bf 100644 --- a/core/transaction-pool/Cargo.toml +++ b/core/transaction-pool/Cargo.toml @@ -5,11 +5,11 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -error-chain = "0.12" +derive_more = "0.14.0" futures = "0.1" log = "0.4" parity-codec = "3.3" -parking_lot = "0.7.1" +parking_lot = "0.8.0" sr-primitives = { path = "../sr-primitives" } client = { package = "substrate-client", path = "../client" } substrate-primitives = { path = "../primitives" } @@ -17,4 +17,4 @@ txpool = { package = "substrate-transaction-graph", path = "./graph" } [dev-dependencies] keyring = { package = "substrate-keyring", path = "../../core/keyring" } -test_client = { package = "substrate-test-client", path = "../../core/test-client" } +test-client = { package = "substrate-test-runtime-client", path = "../../core/test-runtime/client" } diff --git a/core/transaction-pool/graph/Cargo.toml b/core/transaction-pool/graph/Cargo.toml index 29accf0eb819d9543ca0f851e80eb046b40390e8..3f918efa4a2ea7c61b5717123f7fdd37e4a85a8e 100644 --- a/core/transaction-pool/graph/Cargo.toml +++ b/core/transaction-pool/graph/Cargo.toml @@ -5,10 +5,10 @@ authors = ["Parity Technologies "] edition = "2018" [dependencies] -error-chain = "0.12" +derive_more = "0.14.0" futures = "0.1" log = "0.4" -parking_lot = "0.7.1" +parking_lot = "0.8.0" serde = { version = "1.0", features = ["derive"] } substrate-primitives = { path = "../../primitives" } sr-primitives = { path = "../../sr-primitives" } diff --git a/core/transaction-pool/graph/src/base_pool.rs b/core/transaction-pool/graph/src/base_pool.rs index 2b4b96839d7bf49acdb7d2fbff0828f179f12888..b3a2cf0e54702475a514da18705c6b76971dd3cb 100644 --- a/core/transaction-pool/graph/src/base_pool.rs +++ b/core/transaction-pool/graph/src/base_pool.rs @@ -25,7 +25,6 @@ use std::{ sync::Arc, }; -use error_chain::bail; use log::{trace, debug, warn}; use serde::Serialize; use substrate_primitives::hexdisplay::HexDisplay; @@ -101,6 +100,15 @@ pub struct Transaction { pub requires: Vec, /// Tags that this transaction provides. pub provides: Vec, + /// Should that transaction be propagated. + pub propagate: bool, +} + +impl Transaction { + /// Returns `true` if the transaction should be propagated to other peers. + pub fn is_propagateable(&self) -> bool { + self.propagate + } } impl fmt::Debug for Transaction where @@ -124,6 +132,7 @@ impl fmt::Debug for Transaction where write!(fmt, "priority: {:?}, ", &self.priority)?; write!(fmt, "valid_till: {:?}, ", &self.valid_till)?; write!(fmt, "bytes: {:?}, ", &self.bytes)?; + write!(fmt, "propagate: {:?}, ", &self.propagate)?; write!(fmt, "requires: [")?; print_tags(fmt, &self.requires)?; write!(fmt, "], provides: [")?; @@ -184,7 +193,7 @@ impl BasePool, ) -> error::Result> { if self.future.contains(&tx.hash) || self.ready.contains(&tx.hash) { - bail!(error::ErrorKind::AlreadyImported(Box::new(tx.hash.clone()))) + return Err(error::Error::AlreadyImported(Box::new(tx.hash.clone()))) } let tx = WaitingTransaction::new( @@ -259,7 +268,7 @@ impl BasePool) { - description("Transaction is already in the pool"), - display("[{:?}] Already imported", hash), - } - /// The transaction cannot be imported cause it's a replacement and has too low priority. - TooLowPriority(old: Priority, new: Priority) { - description("The priority is too low to replace transactions already in the pool."), - display("Too low priority ({} > {})", old, new) - } - /// Deps cycle detected and we couldn't import transaction. - CycleDetected { - description("Transaction was not imported because of detected cycle."), - display("Cycle Detected"), - } - /// Transaction was dropped immediately after it got inserted. - ImmediatelyDropped { - description("Transaction couldn't enter the pool because of the limit."), - display("Immediately Dropped"), - } - } +/// Transaction pool result. +pub type Result = std::result::Result; + +/// Transaction pool error type. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Transaction is not verifiable yet, but might be in the future. + #[display(fmt="Unkown Transaction Validity. Error code: {}", _0)] + UnknownTransactionValidity(i8), + /// Transaction is invalid. + #[display(fmt="Invalid Transaction. Error Code: {}", _0)] + InvalidTransaction(i8), + /// The transaction is temporarily banned. + #[display(fmt="Temporarily Banned")] + TemporarilyBanned, + /// The transaction is already in the pool. + #[display(fmt="[{:?}] Already imported", _0)] + AlreadyImported(Box), + /// The transaction cannot be imported cause it's a replacement and has too low priority. + #[display(fmt="Too low priority ({} > {})", old, new)] + TooLowPriority { + /// Transaction already in the pool. + old: Priority, + /// Transaction entering the pool. + new: Priority + }, + /// Deps cycle etected and we couldn't import transaction. + #[display(fmt="Cycle Detected")] + CycleDetected, + /// Transaction was dropped immediately after it got inserted. + #[display(fmt="Transaction couldn't enter the pool because of the limit.")] + ImmediatelyDropped, + /// Invalid block id. + InvalidBlockId(String), } +impl std::error::Error for Error {} + /// Transaction pool error conversion. pub trait IntoPoolError: ::std::error::Error + Send + Sized { /// Try to extract original `Error` diff --git a/core/transaction-pool/graph/src/pool.rs b/core/transaction-pool/graph/src/pool.rs index 121e3ddf0049220078bf6cf37ec4f3436a6522f3..4498598aee9cab96b878e4f5984460c806c8e053 100644 --- a/core/transaction-pool/graph/src/pool.rs +++ b/core/transaction-pool/graph/src/pool.rs @@ -27,14 +27,13 @@ use crate::listener::Listener; use crate::rotator::PoolRotator; use crate::watcher::Watcher; use serde::Serialize; -use error_chain::bail; use log::debug; use futures::sync::mpsc; use parking_lot::{Mutex, RwLock}; use sr_primitives::{ generic::BlockId, - traits::{self, As}, + traits::{self, SaturatedConversion}, transaction_validity::{TransactionValidity, TransactionTag as Tag}, }; @@ -119,18 +118,18 @@ impl Pool { T: IntoIterator> { let block_number = self.api.block_id_to_number(at)? - .ok_or_else(|| error::ErrorKind::Msg(format!("Invalid block id: {:?}", at)).into())?; + .ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())?; let results = xts .into_iter() .map(|xt| -> Result<_, B::Error> { let (hash, bytes) = self.api.hash_and_length(&xt); if self.rotator.is_banned(&hash) { - bail!(error::Error::from(error::ErrorKind::TemporarilyBanned)) + return Err(error::Error::TemporarilyBanned.into()) } match self.api.validate_transaction(at, xt.clone())? { - TransactionValidity::Valid { priority, requires, provides, longevity } => { + TransactionValidity::Valid { priority, requires, provides, longevity, propagate } => { Ok(base::Transaction { data: xt, bytes, @@ -138,15 +137,18 @@ impl Pool { priority, requires, provides, - valid_till: block_number.as_().saturating_add(longevity), + propagate, + valid_till: block_number + .saturated_into::() + .saturating_add(longevity), }) }, TransactionValidity::Invalid(e) => { - bail!(error::Error::from(error::ErrorKind::InvalidTransaction(e))) + Err(error::Error::InvalidTransaction(e).into()) }, TransactionValidity::Unknown(e) => { self.listener.write().invalid(&hash); - bail!(error::Error::from(error::ErrorKind::UnknownTransactionValidity(e))) + Err(error::Error::UnknownTransactionValidity(e).into()) }, } }) @@ -166,7 +168,7 @@ impl Pool { let removed = self.enforce_limits(); Ok(results.into_iter().map(|res| match res { - Ok(ref hash) if removed.contains(hash) => Err(error::Error::from(error::ErrorKind::ImmediatelyDropped).into()), + Ok(ref hash) if removed.contains(hash) => Err(error::Error::ImmediatelyDropped.into()), other => other, }).collect()) } @@ -306,10 +308,7 @@ impl Pool { // Collect the hashes of transactions that now became invalid (meaning that they are succesfully pruned). let hashes = results.into_iter().enumerate().filter_map(|(idx, r)| match r.map_err(error::IntoPoolError::into_pool_error) { - Err(Ok(err)) => match err.kind() { - error::ErrorKind::InvalidTransaction(_) => Some(hashes[idx].clone()), - _ => None, - }, + Err(Ok(error::Error::InvalidTransaction(_))) => Some(hashes[idx].clone()), _ => None, }); // Fire `pruned` notifications for collected hashes and make sure to include @@ -317,7 +316,7 @@ impl Pool { let hashes = hashes.chain(known_imported_hashes.into_iter()); { let header_hash = self.api.block_id_to_hash(at)? - .ok_or_else(|| error::ErrorKind::Msg(format!("Invalid block id: {:?}", at)).into())?; + .ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())?; let mut listener = self.listener.write(); for h in hashes { listener.pruned(header_hash, &h); @@ -336,8 +335,8 @@ impl Pool { /// See `prune_tags` if you want this. pub fn clear_stale(&self, at: &BlockId) -> Result<(), B::Error> { let block_number = self.api.block_id_to_number(at)? - .ok_or_else(|| error::ErrorKind::Msg(format!("Invalid block id: {:?}", at)).into())? - .as_(); + .ok_or_else(|| error::Error::InvalidBlockId(format!("{:?}", at)).into())? + .saturated_into::(); let now = time::Instant::now(); let to_remove = { self.ready() @@ -418,8 +417,7 @@ impl Pool { } /// Returns transaction hash - #[cfg(test)] - fn hash_of(&self, xt: &ExtrinsicFor) -> ExHash { + pub fn hash_of(&self, xt: &ExtrinsicFor) -> ExHash { self.api.hash_and_length(xt).0 } } @@ -493,6 +491,7 @@ mod tests { requires: if nonce > block_number { vec![vec![nonce as u8 - 1]] } else { vec![] }, provides: vec![vec![nonce as u8]], longevity: 3, + propagate: true, }) } } @@ -567,7 +566,7 @@ mod tests { assert_eq!(pool.status().future, 0); // then - assert_matches!(res.unwrap_err().kind(), error::ErrorKind::TemporarilyBanned); + assert_matches!(res.unwrap_err(), error::Error::TemporarilyBanned); } #[test] diff --git a/core/transaction-pool/graph/src/ready.rs b/core/transaction-pool/graph/src/ready.rs index befb1b60ccc2deb18e18eee7a4a08b977f87045d..3497c1bc4ba72408535c33d43813fc08031c465c 100644 --- a/core/transaction-pool/graph/src/ready.rs +++ b/core/transaction-pool/graph/src/ready.rs @@ -23,7 +23,6 @@ use std::{ use serde::Serialize; use log::debug; -use error_chain::bail; use parking_lot::RwLock; use sr_primitives::traits::Member; use sr_primitives::transaction_validity::{ @@ -376,7 +375,7 @@ impl ReadyTransactions { // bail - the transaction has too low priority to replace the old ones if old_priority >= tx.priority { - bail!(error::ErrorKind::TooLowPriority(old_priority, tx.priority)) + return Err(error::Error::TooLowPriority { old: old_priority, new: tx.priority }) } replace_hashes.into_iter().cloned().collect::>() @@ -500,6 +499,7 @@ mod tests { valid_till: 2, requires: vec![vec![1], vec![2]], provides: vec![vec![3], vec![4]], + propagate: true, } } @@ -559,6 +559,7 @@ mod tests { valid_till: u64::max_value(), // use the max_value() here for testing. requires: vec![tx1.provides[0].clone()], provides: vec![], + propagate: true, }; // when diff --git a/core/transaction-pool/graph/src/rotator.rs b/core/transaction-pool/graph/src/rotator.rs index 2ca51ef74e880007285ec8b0f279019fb2b5fa3f..41c1b5842ae849a3ff41e47896f4cf41d3d80ca1 100644 --- a/core/transaction-pool/graph/src/rotator.rs +++ b/core/transaction-pool/graph/src/rotator.rs @@ -120,6 +120,7 @@ mod tests { valid_till: 1, requires: vec![], provides: vec![], + propagate: true, }; (hash, tx) @@ -185,6 +186,7 @@ mod tests { valid_till, requires: vec![], provides: vec![], + propagate: true, } } diff --git a/core/transaction-pool/src/error.rs b/core/transaction-pool/src/error.rs index d4cc0acee8d79923bbeefa8314fc36f3e7ab9e30..f3641aa8ecee3bfc31d86977686d709ce4a355e4 100644 --- a/core/transaction-pool/src/error.rs +++ b/core/transaction-pool/src/error.rs @@ -16,29 +16,34 @@ //! Transaction pool error. -// Silence: `use of deprecated item 'std::error::Error::cause': replaced by Error::source, which can support downcasting` -// https://github.com/paritytech/substrate/issues/1547 -#![allow(deprecated)] - use client; use txpool; -use error_chain::{ - error_chain, error_chain_processing, impl_error_chain_processed, impl_extract_backtrace, impl_error_chain_kind -}; -error_chain! { - foreign_links { - Client(client::error::Error) #[doc = "Client error"]; - } - links { - Pool(txpool::error::Error, txpool::error::ErrorKind) #[doc = "Pool error"]; +/// Transaction pool result. +pub type Result = std::result::Result; + +/// Transaction pool error type. +#[derive(Debug, derive_more::Display, derive_more::From)] +pub enum Error { + /// Client error. + Client(client::error::Error), + /// Pool error. + Pool(txpool::error::Error), +} + +impl std::error::Error for Error { + fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + match self { + Error::Client(ref err) => Some(err), + Error::Pool(ref err) => Some(err), + } } } impl txpool::IntoPoolError for Error { - fn into_pool_error(self) -> ::std::result::Result { + fn into_pool_error(self) -> std::result::Result { match self { - Error(ErrorKind::Pool(e), c) => Ok(txpool::error::Error(e, c)), + Error::Pool(e) => Ok(e), e => Err(e), } } diff --git a/core/transaction-pool/src/tests.rs b/core/transaction-pool/src/tests.rs index cab44f49cc79c4b812c513a2cc197b0a5e00d01d..a1ee4a50df332b9fe9d74fd0f4a1e8f3d637bebf 100644 --- a/core/transaction-pool/src/tests.rs +++ b/core/transaction-pool/src/tests.rs @@ -53,6 +53,7 @@ impl txpool::ChainApi for TestApi { requires, provides, longevity: 64, + propagate: true, }) } diff --git a/core/trie/src/lib.rs b/core/trie/src/lib.rs index 1322038d7847cbec83d36349014ba5e0717282e3..6298f10bf4b51d01b13d73a73cccf8a0c492d736 100644 --- a/core/trie/src/lib.rs +++ b/core/trie/src/lib.rs @@ -43,9 +43,9 @@ pub type TrieError = trie_db::TrieError; pub trait AsHashDB: hash_db::AsHashDB {} impl> AsHashDB for T {} /// As in `hash_db`, but less generic, trait exposed. -pub type HashDB<'a, H> = hash_db::HashDB + 'a; +pub type HashDB<'a, H> = dyn hash_db::HashDB + 'a; /// As in `hash_db`, but less generic, trait exposed. -pub type PlainDB<'a, K> = hash_db::PlainDB + 'a; +pub type PlainDB<'a, K> = dyn hash_db::PlainDB + 'a; /// As in `memory_db::MemoryDB` that uses prefixed storage key scheme. pub type PrefixedMemoryDB = memory_db::MemoryDB, trie_db::DBValue>; /// As in `memory_db::MemoryDB` that uses prefixed storage key scheme. @@ -471,7 +471,7 @@ mod tests { } fn populate_trie<'db>( - db: &'db mut HashDB, + db: &'db mut dyn HashDB, root: &'db mut ::Out, v: &[(Vec, Vec)] ) -> TrieDBMut<'db, Blake2Hasher> { diff --git a/core/trie/src/node_header.rs b/core/trie/src/node_header.rs index 4f7617c0684bb881d970c177d940559d0760d9a9..2c01189f8a155118d3c1779524df729ed5059544 100644 --- a/core/trie/src/node_header.rs +++ b/core/trie/src/node_header.rs @@ -60,12 +60,12 @@ impl Decode for NodeHeader { Some(match input.read_byte()? { EMPTY_TRIE => NodeHeader::Null, // 0 - i @ LEAF_NODE_OFFSET ... LEAF_NODE_SMALL_MAX => // 1 ... (127 - 1) + i @ LEAF_NODE_OFFSET ..= LEAF_NODE_SMALL_MAX => // 1 ... (127 - 1) NodeHeader::Leaf((i - LEAF_NODE_OFFSET) as usize), LEAF_NODE_BIG => // 127 NodeHeader::Leaf(input.read_byte()? as usize + LEAF_NODE_THRESHOLD as usize), - i @ EXTENSION_NODE_OFFSET ... EXTENSION_NODE_SMALL_MAX =>// 128 ... (253 - 1) + i @ EXTENSION_NODE_OFFSET ..= EXTENSION_NODE_SMALL_MAX =>// 128 ... (253 - 1) NodeHeader::Extension((i - EXTENSION_NODE_OFFSET) as usize), EXTENSION_NODE_BIG => // 253 NodeHeader::Extension(input.read_byte()? as usize + EXTENSION_NODE_THRESHOLD as usize), diff --git a/core/trie/src/trie_stream.rs b/core/trie/src/trie_stream.rs index 123ab1ea16de5bd242f88e3715ebe7f192070b34..913cff2c5a94e0664e3e24163e9a39f65538ff72 100644 --- a/core/trie/src/trie_stream.rs +++ b/core/trie/src/trie_stream.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . -//! `TrieStream` implementation for Substrate's trie format. +//! `TrieStream` implementation for Substrate's trie format. use rstd::iter::once; use hash_db::Hasher; @@ -83,7 +83,7 @@ impl trie_root::TrieStream for TrieStream { fn append_substream(&mut self, other: Self) { let data = other.out(); match data.len() { - 0...31 => { + 0..=31 => { data.encode_to(&mut self.buffer) }, _ => { diff --git a/core/util/fork-tree/src/lib.rs b/core/util/fork-tree/src/lib.rs index cba5a1535b6f2046c37539816c4c0571cd656f82..4b6745a354cb051ffed35d350e42659a0a7e560b 100644 --- a/core/util/fork-tree/src/lib.rs +++ b/core/util/fork-tree/src/lib.rs @@ -52,7 +52,7 @@ impl std::error::Error for Error { } } - fn cause(&self) -> Option<&std::error::Error> { + fn cause(&self) -> Option<&dyn std::error::Error> { None } } diff --git a/node-template/Cargo.toml b/node-template/Cargo.toml index d0427ec80de0140ac2d1f779d03c720696b77556..e78bb2d27e4447142823e27a7c90eda5cea80d44 100644 --- a/node-template/Cargo.toml +++ b/node-template/Cargo.toml @@ -10,13 +10,13 @@ name = "node-template" path = "src/main.rs" [dependencies] -error-chain = "0.12" +derive_more = "0.14.0" futures = "0.1" ctrlc = { version = "3.0", features = ["termination"] } log = "0.4" tokio = "0.1" exit-future = "0.1" -parking_lot = "0.7.1" +parking_lot = "0.8.0" parity-codec = "3.3" trie-root = "0.12.2" sr-io = { path = "../core/sr-io" } diff --git a/node-template/runtime/src/lib.rs b/node-template/runtime/src/lib.rs index 875b537a9fe492dbc6db628bd0d1f3126157731a..6193fd8e71810abb146c7892d356284e72184adf 100644 --- a/node-template/runtime/src/lib.rs +++ b/node-template/runtime/src/lib.rs @@ -155,7 +155,7 @@ impl indices::Trait for Runtime { type ResolveHint = indices::SimpleResolveHint; /// Determine whether an account is dead. type IsDeadAccount = Balances; - /// The uniquitous event type. + /// The ubiquitous event type. type Event = Event; } @@ -172,7 +172,7 @@ impl balances::Trait for Runtime { type OnFreeBalanceZero = (); /// What to do if a new account is created. type OnNewAccount = Indices; - /// The uniquitous event type. + /// The ubiquitous event type. type Event = Event; type TransactionPayment = (); @@ -181,7 +181,7 @@ impl balances::Trait for Runtime { } impl sudo::Trait for Runtime { - /// The uniquitous event type. + /// The ubiquitous event type. type Event = Event; type Proposal = Call; } @@ -200,7 +200,7 @@ construct_runtime!( System: system::{default, Log(ChangesTrieRoot)}, Timestamp: timestamp::{Module, Call, Storage, Config, Inherent}, Consensus: consensus::{Module, Call, Storage, Config, Log(AuthoritiesChange), Inherent}, - Aura: aura::{Module}, + Aura: aura::{Module, Log(PreRuntime)}, Indices: indices, Balances: balances, Sudo: sudo, @@ -240,10 +240,6 @@ impl_runtime_apis! { fn initialize_block(header: &::Header) { Executive::initialize_block(header) } - - fn authorities() -> Vec { - panic!("Deprecated, please use `AuthoritiesApi`.") - } } impl runtime_api::Metadata for Runtime { diff --git a/node-template/runtime/wasm/Cargo.lock b/node-template/runtime/wasm/Cargo.lock index bd69f55c6244e1feff0b2ccf0ccc1ca6ca15c152..c94150dc5b1103a9b3fba355d4b0e3e622ec6855 100644 --- a/node-template/runtime/wasm/Cargo.lock +++ b/node-template/runtime/wasm/Cargo.lock @@ -1,5 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "adler32" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "aes-ctr" version = "0.3.0" @@ -33,7 +38,7 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.6.10" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -44,12 +49,12 @@ name = "aio-limited" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -79,7 +84,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -87,27 +92,26 @@ name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.14" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -115,19 +119,22 @@ name = "backtrace-sys" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "base-x" -version = "0.2.4" +name = "base58" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "base58" -version = "0.1.0" +name = "base64" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "bigint" @@ -179,10 +186,10 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.7.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -198,7 +205,7 @@ dependencies = [ [[package]] name = "block-padding" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -209,9 +216,14 @@ name = "bs58" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "build_const" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bumpalo" -version = "2.4.1" +version = "2.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -250,12 +262,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.31" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -263,8 +275,8 @@ name = "chrono" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -273,7 +285,7 @@ name = "clear_on_drop" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -289,12 +301,28 @@ name = "constant_time_eq" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "crc" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -346,7 +374,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -360,7 +388,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -380,7 +408,7 @@ name = "crossbeam-utils" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -388,7 +416,7 @@ name = "crossbeam-utils" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -399,7 +427,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crunchy" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -440,14 +468,14 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -457,13 +485,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "derive_more" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -482,11 +510,6 @@ dependencies = [ "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "dns-parser" version = "0.8.0" @@ -502,7 +525,7 @@ version = "1.0.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -510,7 +533,7 @@ dependencies = [ [[package]] name = "either" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -529,7 +552,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -543,15 +566,7 @@ name = "erased-serde" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "error-chain" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -559,7 +574,7 @@ name = "failure" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -568,10 +583,10 @@ name = "failure_derive" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -581,33 +596,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "fixed-hash" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "fnv" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "foreign-types" -version = "0.3.2" +name = "flate2" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "foreign-types-shared" -version = "0.1.1" +name = "fnv" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -631,7 +646,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.1.25" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -639,7 +654,7 @@ name = "futures-cpupool" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -672,7 +687,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "get_if_addrs-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -682,7 +697,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -692,10 +707,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hash256-std-hasher" -version = "0.12.0" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -717,7 +732,7 @@ name = "heapsize" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -725,7 +740,7 @@ name = "heck" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -735,16 +750,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hex-literal" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "hex-literal-impl" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,6 +794,16 @@ dependencies = [ "hmac 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "http" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "httparse" version = "1.3.3" @@ -816,7 +841,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "impl-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -829,21 +862,26 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ipnet" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "itoa" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "js-sys" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -874,53 +912,51 @@ name = "lazy_static" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "lazycell" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" -version = "0.2.50" +version = "0.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libp2p" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core-derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-dns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-floodsub 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-identify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-kad 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-mdns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-mplex 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-noise 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-ping 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-plaintext 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-ratelimit 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-secio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-tcp 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-uds 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-yamux 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core-derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-deflate 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-dns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-floodsub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identify 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-kad 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-mdns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-mplex 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-noise 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-ping 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-plaintext 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-ratelimit 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-secio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-tcp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-uds 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-wasm-ext 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-websocket 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-yamux 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-core" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -929,64 +965,74 @@ dependencies = [ "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "multistream-select 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "secp256k1 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-core-derive" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libp2p-deflate" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-dns" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-floodsub" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "cuckoofilter 0.3.2 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -996,28 +1042,28 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-kad" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1026,54 +1072,55 @@ dependencies = [ "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-mdns" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-mplex" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1081,103 +1128,107 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", "snow 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "x25519-dalek 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-ping" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-plaintext" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-ratelimit" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-secio" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-futures 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-tcp" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ipnet 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1185,26 +1236,57 @@ dependencies = [ [[package]] name = "libp2p-uds" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libp2p-websocket" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "soketto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-rustls 0.10.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libp2p-yamux" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "yamux 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "yamux 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1229,12 +1311,20 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lock_api" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1269,7 +1359,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "merlin" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1278,17 +1368,44 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "miniz-sys" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide_c_api" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "mio" -version = "0.6.16" +version = "0.6.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1296,25 +1413,14 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "mio-extras" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "mio-uds" version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1334,7 +1440,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1347,9 +1453,9 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1358,7 +1464,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -1407,23 +1513,27 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.39" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "num_cpus" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1444,31 +1554,6 @@ name = "opaque-debug" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "openssl" -version = "0.10.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "openssl-sys" -version = "0.9.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "owning_ref" version = "0.3.3" @@ -1497,7 +1582,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1505,15 +1590,15 @@ name = "parity-codec-derive" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-multiaddr" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1521,24 +1606,31 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-multihash" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parity-send-wrapper" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "parity-wasm" version = "0.31.3" @@ -1574,15 +1666,25 @@ dependencies = [ "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parking_lot_core" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1590,11 +1692,11 @@ name = "parking_lot_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1602,31 +1704,46 @@ name = "parking_lot_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot_core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "paste" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "paste-impl" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1644,28 +1761,23 @@ name = "percent-encoding" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "pkg-config" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "primitive-types" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-crate" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1678,12 +1790,12 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1693,7 +1805,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "0.4.27" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1701,7 +1813,7 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.4.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1719,7 +1831,7 @@ name = "quote" version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1727,7 +1839,7 @@ name = "rand" version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1737,10 +1849,10 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1750,9 +1862,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1760,17 +1872,17 @@ name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1778,7 +1890,7 @@ name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1813,12 +1925,12 @@ dependencies = [ [[package]] name = "rand_jitter" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1828,10 +1940,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1839,7 +1951,7 @@ name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1857,7 +1969,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1868,7 +1980,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1882,7 +1994,7 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.51" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1890,24 +2002,24 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" -version = "1.1.2" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1918,17 +2030,17 @@ name = "ring" version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-demangle" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1944,19 +2056,32 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustls" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rw-stream-sink" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ryu" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1969,51 +2094,38 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.0.0" -source = "git+https://github.com/w3f/schnorrkel#0a0de4294b475ef6abdeebb50067f213ca79b3c7" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "schnorrkel" -version = "0.1.0" +name = "scopeguard" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "scopeguard" -version = "0.3.3" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "secp256k1" -version = "0.12.0" +name = "sct" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2036,20 +2148,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2057,9 +2169,20 @@ name = "serde_json" version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sha-1" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2084,7 +2207,7 @@ name = "sha2" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2092,10 +2215,10 @@ dependencies = [ [[package]] name = "sha3" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2115,16 +2238,6 @@ dependencies = [ "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "slog-async" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "slog-json" version = "2.3.0" @@ -2132,7 +2245,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2166,7 +2279,25 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "soketto" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2184,10 +2315,10 @@ name = "sr-api-macros" version = "2.0.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2212,9 +2343,9 @@ version = "2.0.0" dependencies = [ "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-std 2.0.0", "substrate-primitives 2.0.0", @@ -2233,7 +2364,7 @@ version = "2.0.0" dependencies = [ "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", ] @@ -2243,7 +2374,7 @@ name = "srml-aura" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-session 2.0.0", @@ -2260,7 +2391,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-support 2.0.0", @@ -2273,7 +2404,7 @@ name = "srml-consensus" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-support 2.0.0", @@ -2287,7 +2418,7 @@ name = "srml-executive" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2301,7 +2432,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2316,7 +2447,7 @@ name = "srml-metadata" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-primitives 2.0.0", ] @@ -2327,7 +2458,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-consensus 2.0.0", @@ -2342,7 +2473,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2358,7 +2489,8 @@ name = "srml-sudo" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", + "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-support 2.0.0", @@ -2373,8 +2505,8 @@ dependencies = [ "bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2387,31 +2519,31 @@ dependencies = [ name = "srml-support-procedural" version = "2.0.0" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "srml-support-procedural-tools 2.0.0", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "srml-support-procedural-tools" version = "2.0.0" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "srml-support-procedural-tools-derive 2.0.0", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "srml-support-procedural-tools-derive" version = "2.0.0" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2420,7 +2552,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2433,7 +2565,7 @@ name = "srml-timestamp" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-support 2.0.0", @@ -2456,50 +2588,6 @@ name = "static_slice" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "stdweb" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-macros 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-runtime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base-x 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "stream-cipher" version = "0.3.0" @@ -2519,19 +2607,19 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-bip39" -version = "0.2.0" -source = "git+https://github.com/paritytech/substrate-bip39#a28806512c977992af8d6740d45352f5a1c832a0" +version = "0.2.1" +source = "git+https://github.com/paritytech/substrate-bip39#44307fda4ea17fe97aeb93af317fbc8f6ed34193" dependencies = [ "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)", + "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2539,15 +2627,15 @@ dependencies = [ name = "substrate-client" version = "2.0.0" dependencies = [ - "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.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.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hex-literal 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2589,16 +2677,18 @@ name = "substrate-consensus-common" version = "2.0.0" dependencies = [ "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", + "sr-std 2.0.0", "sr-version 2.0.0", "substrate-inherents 2.0.0", "substrate-primitives 2.0.0", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2606,12 +2696,12 @@ name = "substrate-executor" version = "2.0.0" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-version 2.0.0", "substrate-panic-handler 2.0.0", @@ -2620,7 +2710,7 @@ dependencies = [ "substrate-state-machine 2.0.0", "substrate-trie 2.0.0", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2628,7 +2718,7 @@ name = "substrate-inherents" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", ] @@ -2656,7 +2746,7 @@ dependencies = [ name = "substrate-panic-handler" version = "2.0.0" dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2669,29 +2759,30 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", - "substrate-bip39 0.2.0 (git+https://github.com/paritytech/substrate-bip39)", - "tiny-bip39 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "twox-hash 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)", + "tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "twox-hash 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-serializer" version = "2.0.0" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2701,8 +2792,9 @@ version = "2.0.0" dependencies = [ "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-panic-handler 2.0.0", "substrate-primitives 2.0.0", "substrate-trie 2.0.0", @@ -2714,17 +2806,19 @@ dependencies = [ name = "substrate-telemetry" version = "2.0.0" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2747,35 +2841,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "subtle" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.33" +version = "0.15.34" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "synstructure" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "termcolor" version = "1.0.4" @@ -2789,9 +2878,9 @@ name = "termion" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2808,14 +2897,14 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tiny-bip39" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2840,31 +2929,32 @@ name = "tk-listen" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio" -version = "0.1.16" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-current-thread 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2875,17 +2965,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-current-thread" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2893,19 +2983,19 @@ name = "tokio-dns-unofficial" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-executor" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2913,9 +3003,9 @@ name = "tokio-fs" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2924,7 +3014,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2934,25 +3024,38 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-rustls" +version = "0.10.0-alpha.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-sync" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2961,38 +3064,46 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-threadpool" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-timer" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-trace-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3001,9 +3112,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3015,11 +3126,11 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3028,10 +3139,10 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.10" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3066,7 +3177,7 @@ dependencies = [ [[package]] name = "twox-hash" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3084,11 +3195,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "uint" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3111,7 +3222,7 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3148,11 +3259,6 @@ name = "utf8-ranges" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "vcpkg" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "version_check" version = "0.1.5" @@ -3165,103 +3271,141 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen-macro 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bumpalo 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-futures" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro-support 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro-support 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen-webidl" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "weedle 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-timer" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmi" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi-validation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasmi-validation" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "web-sys" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-webidl 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-webidl 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki-roots" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "weedle" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3274,7 +3418,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3296,7 +3440,7 @@ name = "winapi-util" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3309,28 +3453,10 @@ name = "wincolor" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ws" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" @@ -3342,21 +3468,21 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "yamux" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3371,45 +3497,68 @@ name = "zeroize" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "zeroize" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "zeroize_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zeroize_derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] +"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" "checksum aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" -"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f10b352bc3fc08ae24dc5d2d3ddcac153678533986122dc283d747b12071000" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9893d63fc3b1c44231e667da6836a33f27d8b6b3bdc82f83da5dfd579d1b6528" "checksum asn1_der_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e7f92edafad155aff997fa5b727c6429b91e996b5a5d62a2b0adbae1306b5fe" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4" +"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" +"checksum backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)" = "1a13fc43f04daf08ab4f71e3d27e1fc27fc437d3e95ac0063a796d92fb40f39b" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" -"checksum base-x 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d55aa264e822dbafa12db4d54767aff17c6ba55ea2d8559b3e17392c7d000e5d" "checksum base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" +"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ebecac13b3c745150d7b6c3ea7572d372f09d627c2077e893bf26c5c7f70d282" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5da9b3d9f6f585199287a473f4f8dfab6566cf827d15c00c219f53c645687ead" "checksum blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91721a6330935673395a0607df4d49a9cb90ae12d259f1b3e0a3f6e1d486872e" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum block-buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1339a1042f5d9f295737ad4d9a6ab6bf81c84a933dba110b9200cd6d1448b814" -"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d" +"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" -"checksum block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d75255892aeb580d3c566f213a2b6fdc1c66667839f45719ee1d30ebf2aea591" +"checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" "checksum bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0de79cfb98e7aa9988188784d8664b4b5dad6eaaa0863b91d9a4ed871d4f7a42" -"checksum bumpalo 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4639720be048090544634e0402490838995ccdc9d2fe648f528f30d3c33ae71f" +"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" +"checksum bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "84dca3afd8e01b9526818b7963e5b4916063b3cdf9f10cf6b73ef0bd0ec37aa5" "checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" -"checksum cc 1.0.31 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ce8bb087aacff865633f0bd5aeaed910fe2fe55b55f4739527f2e023a2e53d" -"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" +"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" +"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum crossbeam 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4c7ea749d9fb09e23c5cb17e3b70650860553a0e2744e38446b1803bf7db94" "checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" @@ -3421,36 +3570,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" -"checksum crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c240f247c278fa08a6d4820a6a222bfc6e0d999e51ba67be94f44c905b2161f2" +"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" "checksum crypto-mac 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "779015233ac67d65098614aec748ac1c756ab6677fa2e14cf8b37c08dfed1198" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" "checksum cuckoofilter 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" -"checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1" +"checksum curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "750226d75fc2f5a8daec6e7477624e258674023eb73d8d647f63b943ca182a4a" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" -"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615" +"checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" -"checksum discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" "checksum dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d33be9473d06f75f58220f71f7a9317aca647dc061dbd3c361b0bef505fbea" "checksum ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81956bcf7ef761fb4e1d88de3fa181358a0d26cbcb9755b587a08f9119824b86" -"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac" +"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" "checksum elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "073be79b6538296faf81c631872676600616073817dd9a440c477ad09b408983" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c7464757b80de8930c91c9afe77ddce501826bf9d134a87db2c67d9dc177e2c" "checksum erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3beee4bc16478a1b26f2e80ad819a52d24745e292f521a63c16eea5f74b7eb60" -"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" -"checksum fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a557e80084b05c32b455963ff565a9de6f2866da023d6671705c6aff6f65e01c" +"checksum fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" +"checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" -"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" +"checksum futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a2037ec1c6c1c4f79557762eab1f7eae1f64f6cb418ace90fae88f0942b60139" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" @@ -3458,60 +3604,68 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "abddb55a898d32925f3148bd281174a68eeb68bbfd9a5938a57b18f506ee4ef7" "checksum get_if_addrs-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d04f9fb746cf36b191c00f3ede8bde9c8e64f9f4b05ae2694a9ccf5e3f5ab48" "checksum hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fb417e5c470acdd61068c79767d0e65962e70836cf6c9dfd2409f06345ce0" -"checksum hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1224388a21c88a80ae7087a2a245ca6d80acc97a9186b75789fb3eeefd0609af" +"checksum hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b2027c19ec91eb304999abae7307d225cf93be42af53b0039f76e98ed5af86" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" "checksum hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8e04cb7a5051270ef3fa79f8c7604d581ecfa73d520e74f554e45541c4b5881a" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" -"checksum hex-literal 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "27455ce8b4a6666c87220e4b59c9a83995476bdadc10197905e61dbe906e36fa" -"checksum hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d340b6514f232f6db1bd16db65302a5278a04fef9ce867cb932e7e5fa21130a" +"checksum hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc2928beef125e519d69ae1baa8c37ea2e0d3848545217f6db0179c5eb1d639" +"checksum hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "520870c3213943eb8d7803e80180d12a6c7ceb4ae74602544529d1643dc4ddda" "checksum hmac 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a13f4163aa0c5ca1be584aace0e2212b2e41be5478218d4f657f5f778b2ae2a" "checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" "checksum hmac-drbg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe727d41d2eec0a6574d887914347e5ff96a3b87177817e2a9820c5c87fecc2" +"checksum http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2050d823639fbeae26b2b5ba09aca8907793117324858070ade0673c49f793b" "checksum impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5158079de9d4158e0ce1de3ae0bd7be03904efc40b3d7dd8b8c301cbf6b52b56" +"checksum impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d26be4b97d738552ea423f76c4f681012ff06c3fa36fa968656b3679f60b4a1" "checksum integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ea155abb3ba6f382a75f1418988c05fe82959ed9ce727de427f9cfd425b0c903" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3c994fd445b81741d77f6bcd227d6ed645b95b35a2ecfd2050767450ff1c0b6d" +"checksum ipnet 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e61c2da0d0f700c77d2d313dbf4f93e41d235fa12c6681fee06621036df4c2af" +"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +"checksum js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "9987e7c13a91d9cf0efe59cca48a3a7a70e2b11695d5a4640f85ae71e28f5e73" "checksum keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" -"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" -"checksum libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0231edab431064b30b7749484a39735eb36492cef4658c372c9059e58c3003aa" -"checksum libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a3bad2ed26297112847678683dd221473a0d44297250b61f004e1b35e72493" -"checksum libp2p-core-derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f765f103b680cbed910b02bfdbdcfce5b1142899c93e51acb960bf59b6f81b1" -"checksum libp2p-dns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b129d20cc8cbb6ce5da8361045649c024659173e246c5dfbf20ae06071c046a" -"checksum libp2p-floodsub 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70d68816b8435d6788399416eb2f0a6974fb1d15c4be5c30141f87c8e81746df" -"checksum libp2p-identify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "718ca645a065fd70855ca6042a7df686c24cd21add750c37a82c811fbd1e5c43" -"checksum libp2p-kad 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bbe27c623a6a720efd5d704347838972062f89149a9c3cd149748da60bdcd3e0" -"checksum libp2p-mdns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9bc1a5d85f4812cae6367b49a432763fe28997bac7c530dc55b70ec18a78aa7" -"checksum libp2p-mplex 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe5a858342a1cc89464474f7edc4bae1da649b9c823a3e04d9fb494493601746" -"checksum libp2p-noise 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc6b5185c50a52a12e7bbe2ee7799059e24de4e52ab25edbfd26c8ab8515d317" -"checksum libp2p-ping 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7905c1431ad115bee83405770629a27d6f17153ad02ec9670a7347998ef20e22" -"checksum libp2p-plaintext 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc17626763ded57da8fed73187c2d9f6ebb89d30838673c430315bf560c7e4db" -"checksum libp2p-ratelimit 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2409d08b809ab1a74269597f7da2829d117cc11b9ed3343af33fc20831619726" -"checksum libp2p-secio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258cdc6742945c8f6402997bbbf36733588e2db18e5a0014da6d46e3ccfb92cf" -"checksum libp2p-tcp 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b5691e2ba2720d42bd1e93d6b90239fa9235c1956ef6a5f1dd499a7ae2767be" -"checksum libp2p-uds 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ab0b9ca050105fd94229c48911c0c84aef4d6b86a53d1b6df81d938354e47e" -"checksum libp2p-yamux 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6ff51a5b2056bacee1c9f2ed8455cdf3c5c619261ddb4efc783119130aaf52" +"checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880" +"checksum libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6abde4e6fc777dc06ae2a15202ddedb1a38d7c71ed16bc10fa704b03f73aec37" +"checksum libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ceb4791289534d4c1ad8e4bd3c6f06d3670efa55ce71482951a287df93ddd1" +"checksum libp2p-core-derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "851a59dcaab66c96777ae0cace96de88a700243c3b8360ab51c7e093f3727066" +"checksum libp2p-deflate 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "902b44e92e1f8b7e697b3a186d15c841e0e38037f14286513207a5407650a635" +"checksum libp2p-dns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71a6630a84552b39e5f752e1f6a951d31f3211079465d2e7af73491b6f48fc3f" +"checksum libp2p-floodsub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9fced4da0c31e0dc8a759472c65fab41db40c01de2d93bc45e1431c13f0564f0" +"checksum libp2p-identify 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba5e882d72c71cdf77f45ab68dd715451d3b78a23085f8d385c7a31ec1b4272" +"checksum libp2p-kad 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d71966dbbb4cedcfcdb1d4c87d5dbb6f3f07b465d1ca74f2624256669997d1f2" +"checksum libp2p-mdns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdbdaea6f0049cc09ba5db00308f5b93105a8a33b65ba2e36bd35da707850ea2" +"checksum libp2p-mplex 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b351bfd67e97154e7b60f62402237671486c8a89f83eabdb6838f37d4d5f006" +"checksum libp2p-noise 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44324032b2f9260d2b862c741d79d250dc02298dbba56354a992528a826ee2d5" +"checksum libp2p-ping 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1ac43ffd01de4210cf1b969bbb55a008c77f9ec22b74df26a6590bb6bd4c93f" +"checksum libp2p-plaintext 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0506e10770bcbcb59f2a6154ce93c8fd5cb9730b6ceb5aa1463164af1fd0b9c6" +"checksum libp2p-ratelimit 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3886b79a35c0348497bab763517a9a2b4965173f4b4c7438d59f1e4dcf5122ff" +"checksum libp2p-secio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b811272e5cd86d39bd71fb94687025d9802b13daf0998ebe0d3f2885c636c51a" +"checksum libp2p-tcp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b2c54cb75f17557de6ce0149aa03e729455e2d240f84d854272bc4b11012a324" +"checksum libp2p-uds 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbedf4a1e72a5f67523915414e9e12d71d128731873f0f24d8b878398fb47aa4" +"checksum libp2p-wasm-ext 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c1f615b56aa2a6f4ec07bf9667be9fff8877b9c5bd5335601af47490eda341" +"checksum libp2p-websocket 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d1bfe60577558f48a9fdf9f35c0ee2dc5baa01f685ff847d3b5cf4f12ee135" +"checksum libp2p-yamux 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf4bfc7ff127cd622502dbe56f10513dd6776b970e33d8ebb6e367f0752324f6" "checksum libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "688e8d65e495567c2c35ea0001b26b9debf0b4ea11f8cccc954233b75fc3428a" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +"checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7623b01a4f1b7acb7cf8e3f678f05e15e6ae26cb0b738dfeb5cc186fd6b82ef4" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" -"checksum merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "83c2dda19c01176e8e7148f7bdb88bbdf215a8db0641f89fc40e4b81736aeda5" -"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432" -"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" +"checksum merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c39467de91b004f5b9c06fac5bbc8e7d28309a205ee66905166b70804a71fea" +"checksum miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9e3ae51cea1576ceba0dde3d484d30e6e5b86dee0b2d412fe3a16a15c98202" +"checksum miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c468f2369f07d651a5d0bb2c9079f8488a66d5466efe42d0c5c6466edcb7f71e" +"checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab" +"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum multistream-select 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f989d40aab0ed0d83c1cdb4856b5790e980b96548d1a921f280e985eb049f38d" @@ -3519,40 +3673,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d138afcce92d219ccb6eb53d9b1e8a96ac0d633cfd3c53cd9856d96d1741bb8" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" -"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" "checksum once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" -"checksum openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)" = "84321fb9004c3bce5611188a644d6171f895fa2889d155927d528782edb21c5d" -"checksum openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)" = "cb534d752bf98cf363b473950659ac2546517f9c6be9723771614ab3f03bbc9e" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb43c05fb71c03b4ea7327bf15694da1e0f23f19d5b1e95bab6c6d74097e336" "checksum parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00a486fd383382ddcb2de928364b1f82571c1e48274fc43b7667a4738ee4056c" -"checksum parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18a130a727008cfcd1068a28439fe939897ccad28664422aeca65b384d6de6d0" -"checksum parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e8eab0287ccde7821e337a124dc5a4f1d6e4c25d10cc91e3f9361615dd95076" +"checksum parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "045b3c7af871285146300da35b1932bb6e4639b66c7c98e85d06a32cbc4e8fa7" +"checksum parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05d6a68e07ab34a9e87bd8dd4936f6bb5be21e4f6dbcdbaf04d8e854eba0af01" +"checksum parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" "checksum parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)" = "511379a8194230c2395d2f5fa627a5a7e108a9f976656ce723ae68fca4097bfc" "checksum parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4d05f1349491390b1730afba60bb20d55761bef489a954546b58b4b34e1e2ac" "checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +"checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" -"checksum paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f50392d1265092fbee9273414cc40eb6d47d307bd66222c477bb8450c8504f9d" -"checksum paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3cd512fe3a55e8933b2dcad913e365639db86d512e4004c3084b86864d9467a" +"checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" +"checksum paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4a4a1c555c6505821f9d58b8779d0f630a6b7e4e1be24ba718610acf01fa79" +"checksum paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "26e796e623b8b257215f27e6c80a5478856cae305f5b59810ff9acdaa34570e6" "checksum pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" -"checksum primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edb92f1ebfc177432c03287b15d48c202e6e2c95993a7af3ba039abb43b1492e" -"checksum proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c6cf4e5b00300d151dfffae39f529dfa5188f42eeb14201229aa420d6aad10c" +"checksum primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6e8612a8dc70f26276fed6131c153ca277cf275ee0a5e2a50cd8a69c697beb8f" +"checksum proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" "checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" -"checksum proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e90aa19cd73dedc2d0e1e8407473f073d735fef0ab521438de6da8ee449ab66" +"checksum proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0c1dd4172a1e1f96f709341418f49b11ea6c2d95d53dca08c0f74cbd332d9cf3" "checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" -"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" -"checksum protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24d5d73d2b88fddb8b8141f2730d950d88772c940ac4f8f3e93230b9a99d92df" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a151c11a92df0059d6ab446fafa3b21a1210aad4bc2293e1c946e8132b10db01" "checksum quick-error 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5fb6ccf8db7bbcb9c2eae558db5ab4f3da1c2a87e4e597ed394726bc8ea6ca1d" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" "checksum quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)" = "faf4799c5d274f3868a4aae320a0a182cbd2baee377b378f080e16a23e9d80db" @@ -3565,122 +3719,125 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -"checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" +"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" +"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f" -"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" +"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" +"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" -"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" +"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d548a40fe17c3a77d54b82457b79fcc9b8a288d509ca20fbf5aa1dac386d22d6" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" +"checksum rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" +"checksum rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9cbe61c20455d3015b2bb7be39e1872310283b8e5a52f5b242b0ac7581fe78" +"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" "checksum safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f7bf422d23a88c16d5090d455f182bc99c60af4df6a345c63428acf5129e347" -"checksum schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)" = "" -"checksum schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a700659388785588c75b197cecda0f23c7112a9281ef703e8ffc651061ce014c" +"checksum schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5eff518f9bed3d803a0d002af0ab96339b0ebbedde3bec98a684986134b7a39" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum secp256k1 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4070f3906e65249228094cf97b04a90799fba04468190bbbcfa812309cf86e32" +"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" +"checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0eddf2e8f50ced781f288c19f18621fa72a3779e3cb58dbf23b07469b0abeb4" -"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" -"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c" +"checksum serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "a72e9b96fa45ce22a4bc23da3858dfccfd60acd28a25bcd328a98fdd6bea43fd" +"checksum serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "101b495b109a3e3ca8c4cbe44cf62391527cdfb6ba15821c5ce80bcd5ea23f9f" "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" +"checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" "checksum sha2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d963c78ce367df26d7ea8b8cc655c651b42e8a1e584e869c1e17dae3ccb116a" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" -"checksum sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34a5e54083ce2b934bf059fdf38e7330a154177e029ab6c4e18638f2f624053a" +"checksum sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e1a2eec401952cd7b12a84ea120e2d57281329940c3f93c2bf04f462539508e" -"checksum slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e544d16c6b230d84c866662fe55e31aacfca6ae71e6fc49ae9a311cb379bfc2f" "checksum slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc0d2aff1f8f325ef660d9a0eb6e6dcd20b30b3f581a5897f58bf42d061c37a" "checksum slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "60c04b4726fa04595ccf2c2dad7bcd15474242c4c5e109a8a376e8a2c9b1539a" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum snow 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5a64f02fd208ef15bd2d1a65861df4707e416151e1272d02c8faafad1c138100" +"checksum soketto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8cf3ae22c0bce5437c7dce6a2b00e492c19da1feb21ad64a7b6fd7058438c3f2" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "92a7e0c5e3dfb52e8fbe0e63a1b947bbb17b4036408b151353c4491374931362" -"checksum stdweb 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a3edad410e603184d656e2abded5fd4d3d6e93d5763d21130dbaf99795db74eb" -"checksum stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e21ebd9179de08f2300a65454268a17ea3de204627458588c84319c4def3930" -"checksum stdweb-internal-macros 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1635afd059cbfac7d5b1274f0c44cec110c1e013c48e8bbc22e07e52696cf887" -"checksum stdweb-internal-runtime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a2a2f4a2eb556337b2d1a302630bbddf989ae383c70393e89b48152b9896cbda" "checksum stream-cipher 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8861bc80f649f5b4c9bd38b696ae9af74499d479dbfb327f0607de6b326a36bc" "checksum strum 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1810e25f576e7ffce1ff5243b37066da5ded0310b3274c20baaeccb1145b2806" "checksum strum_macros 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "572a2f4e53dd4c3483fd79e5cc10ddd773a3acb1169bbfe8762365e107110579" -"checksum substrate-bip39 0.2.0 (git+https://github.com/paritytech/substrate-bip39)" = "" +"checksum substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)" = "" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" -"checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" -"checksum syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)" = "ec52cd796e5f01d0067225a5392e70084acc4c0013fa71d55166d38a8b307836" -"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" -"checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" +"checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829" +"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" +"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" -"checksum tiny-bip39 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5388a470627f97a01a6e13389ced797a42b1611f9de7e0f6ca705675ac55297" +"checksum tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" "checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" "checksum tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5462b0f968c0457efe38fcd2df7e487096b992419e4f5337b06775a614bbda4b" -"checksum tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fcaabb3cec70485d0df6e9454fe514393ad1c4070dee8915f11041e95630b230" +"checksum tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "94a1f9396aec29d31bb16c24d155cfa144d1af91c40740125db3131bdaf76da8" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" -"checksum tokio-current-thread 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c756b04680eea21902a46fca4e9f410a2332c04995af590e07ff262e2193a9a3" +"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" "checksum tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "82c65483db54eb91b4ef3a9389a3364558590faf30ce473141707c0e16fda975" -"checksum tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30c6dbf2d1ad1de300b393910e8a3aa272b724a400b6531da03eed99e329fbf0" +"checksum tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "83ea44c6c0773cc034771693711c35c677b4b5a4b21b9e7071704c54de7d555e" "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce" -"checksum tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1bf2b9dac2a0509b5cfd1df5aa25eafacb616a42a491a13604d6bbeab4486363" +"checksum tokio-rustls 0.10.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)" = "316fdbc899efec48b3b492bd0f339e6d81c4ee96a409257572147ec341943452" +"checksum tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5b2f843ffdf8d6e1f90bddd48da43f99ab071660cd92b7ec560ef3cdfd7a409a" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" -"checksum tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "742e511f6ce2298aeb86fc9ea0d8df81c2388c6ebae3dc8a7316e8c9df0df801" -"checksum tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2910970404ba6fa78c5539126a9ae2045d62e3713041e447f695f41405a120c6" +"checksum tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72558af20be886ea124595ea0f806dd5703b8958e4705429dd58b3d8231f72f2" +"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" +"checksum tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "350c9edade9830dc185ae48ba45667a445ab59f6167ef6d0254ec9d2430d9dd3" "checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" -"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +"checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039" "checksum trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba73747fd3a64ab531274c04cb588dfa9d30d972d62990831e63fbce2cfec59" "checksum trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfa2e20c4f1418ac2e71ddc418e35e1b56e34022e2146209ffdbf1b2de8b1bd9" "checksum twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d261e83e727c8e2dbb75dacac67c36e35db36a958ee504f2164fc052434e1" -"checksum twox-hash 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09871da9f15424236082e0b220fd404a4eb6bebc7205c67653701229234ac64c" +"checksum twox-hash 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6c7bcecad121018bdcd6b709fa2325b004878fcb3d3067934ce90749f0faff9a" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" -"checksum uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7780bb27fd8a22295e0d9d53ae3be253f715a0dccb1808527f478f1c2603708" +"checksum uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2143cded94692b156c356508d92888acc824db5bffc0b4089732264c6fcf86d4" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" -"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" +"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2c64cdf40b4a9645534a943668681bcb219faf51874d4b65d2e0abda1b10a2ab" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "ffde3534e5fa6fd936e3260cd62cd644b8656320e369388f9303c955895e35d4" -"checksum wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "40c0543374a7ae881cdc5d32d19de28d1d1929e92263ffa7e31712cc2d53f9f1" -"checksum wasm-bindgen-futures 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "0ad171fc1f6e43f97d155d27f4ee5657bd8aa5cce7c497ef3a0a0c5b44618b2d" -"checksum wasm-bindgen-macro 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "f914c94c2c5f4c9364510ca2429e59c92157ec89429243bcc245e983db990a71" -"checksum wasm-bindgen-macro-support 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "9168c413491e4233db7b6884f09a43beb00c14d11d947ffd165242daa48a2385" -"checksum wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "326c32126e1a157b6ced7400061a84ac5b11182b2cda6edad7314eb3ae9ac9fe" -"checksum wasm-bindgen-webidl 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "613dbf4d7d3bf10aeb212b35de14a8ef07222c26526d4f931061a83fc9e2a851" -"checksum wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "21ef487a11df1ed468cf613c78798c26282da5c30e9d49f824872d4c77b47d1d" -"checksum web-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "24129e4be2281109b3e15a328d3d7f233ee232a5405f75ba1e9bb59a25ebc4d4" -"checksum weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26a4c67f132386d965390b8a734d5d10adbcd30eb5cc74bd9229af8b83f10044" +"checksum wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "b7ccc7b93cfd13e26700a9e2e41e6305f1951b87e166599069f77d10358100e6" +"checksum wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "1953f91b1608eb1522513623c7739f047bb0fed4128ce51a93f08e12cc314645" +"checksum wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fa1af11c73eca3dc8c51c76ea475a4416e912da6402064a49fc6c0214701866d" +"checksum wasm-bindgen-macro 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "0f69da5696545d7ca6607a2e4b1a0edf5a6b36b2c49dbb0f1df6ad1d92884047" +"checksum wasm-bindgen-macro-support 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d4246f3bc73223bbb846f4f2430a60725826a96c9389adf715ed1d5af46dec6" +"checksum wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "c08381e07e7a79e5e229ad7c60d15833d19033542cc5dd91d085df59d235f4a6" +"checksum wasm-bindgen-webidl 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "1f42ff7adb8102bf5ad8adbc45b1635c520c8175f9fdf6eb2c54479d485d435a" +"checksum wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad9ac33c834103916e373d648adf65f58c83fb3d8a0f3e6b9a64bca7253a4dca" +"checksum wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aebbaef470840d157a5c47c8c49f024da7b1b80e90ff729ca982b2b80447e78b" +"checksum wasmi-validation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab380192444b3e8522ae79c0a1976e42a82920916ccdfbce3def89f456ea33f3" +"checksum web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "540b8259eb242ff3a566fa0140bda03a4ece4e5c226e1284b5c95dddcd4341f6" +"checksum webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4f7e1cd7900a3a6b65a3e8780c51a3e6b59c0e2c55c6dc69578c288d69f7d082" +"checksum webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c10fa4212003ba19a564f25cd8ab572c6791f99a03cc219c13ed35ccab00de0e" +"checksum weedle 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc44aa200daee8b1f3a004beaf16554369746f1b4486f0cf93b0caf8a3c2d1e" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" -"checksum ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "329d3e6dd450a9c5c73024e1047f0be7e24121a68484eb0b5368977bee3cf8c3" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -"checksum x25519-dalek 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4aca1ba6bec2719576bd20dfe5b24d9359552e616d10bff257e50cd85f745d17" -"checksum yamux 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9073f5dbc901abb0b2ec4f866e726fed2f54953bdf81f8a5fde7762b7cc3b3" +"checksum x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" +"checksum yamux 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "01bd67889938c48f0049fc60a77341039e6c3eaf16cb7693e6ead7c0ba701295" "checksum zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ddfeb6eee2fb3b262ef6e0898a52b7563bb8e0d5955a313b3cf2f808246ea14" +"checksum zeroize 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b60a6c572b91d8ecb0a460950d84fe5b40699edd07d65f73789b31237afc8f66" +"checksum zeroize_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9dac4b660d969bff9c3fe1847a891cacaa8b21dd5f2aae6e0a3e0975aea96431" diff --git a/node-template/runtime/wasm/build.sh b/node-template/runtime/wasm/build.sh index 0be6e7a11c75464ce42a8ad0ddb8a7ccd8d630fc..a549eeb50a5f14168ff41313b61c98edc381bd87 100755 --- a/node-template/runtime/wasm/build.sh +++ b/node-template/runtime/wasm/build.sh @@ -6,7 +6,7 @@ if cargo --version | grep -q "nightly"; then else CARGO_CMD="cargo +nightly" fi -$CARGO_CMD build --target=wasm32-unknown-unknown --release +CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release "$@" for i in node_template_runtime_wasm do wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm diff --git a/node-template/scripts/build.sh b/node-template/scripts/build.sh index 01d0fee3549461f5f2f36be54fc38dc5c64011f7..980a8fa802d02f9f66f58ec8aebea522d690f19a 100755 --- a/node-template/scripts/build.sh +++ b/node-template/scripts/build.sh @@ -17,7 +17,7 @@ do echo "${bold}Building webassembly binary in $SRC...${normal}" cd "$PROJECT_ROOT/$SRC" - ./build.sh + ./build.sh "$@" cd - >> /dev/null done diff --git a/node-template/src/cli.rs b/node-template/src/cli.rs index f41674631e8a43f78104dede2d4fe30e0b8d9462..cd148f3462dce8cac7ffa981d37439967954ba3c 100644 --- a/node-template/src/cli.rs +++ b/node-template/src/cli.rs @@ -61,8 +61,8 @@ fn run_until_exit( { let (exit_send, exit) = exit_future::signal(); - let executor = runtime.executor(); - informant::start(&service, exit.clone(), executor.clone()); + let informant = informant::build(&service); + runtime.executor().spawn(exit.until(informant).map(|_| ())); let _ = runtime.block_on(e.into_exit()); exit_send.fire(); diff --git a/node-template/src/error.rs b/node-template/src/error.rs deleted file mode 100644 index a8aa94bf3285f928b79468ed5317a28eeaa8b635..0000000000000000000000000000000000000000 --- a/node-template/src/error.rs +++ /dev/null @@ -1,13 +0,0 @@ -//! Initialization errors. - -use client; - -error_chain! { - foreign_links { - Io(::std::io::Error) #[doc="IO error"]; - Cli(::clap::Error) #[doc="CLI error"]; - } - links { - Client(client::error::Error, client::error::ErrorKind) #[doc="Client error"]; - } -} diff --git a/node-template/src/main.rs b/node-template/src/main.rs index 53845ddd087b84ddb8bf654caeee7f9e44e13855..5418453a022cac246e767dbda5c031b9b201836c 100644 --- a/node-template/src/main.rs +++ b/node-template/src/main.rs @@ -9,7 +9,7 @@ mod cli; pub use substrate_cli::{VersionInfo, IntoExit, error}; -fn run() -> cli::error::Result<()> { +fn main() { let version = VersionInfo { name: "Substrate Node", commit: env!("VERGEN_SHA_SHORT"), @@ -19,7 +19,9 @@ fn run() -> cli::error::Result<()> { description: "Template Node", support_url: "support.anonymous.an", }; - cli::run(::std::env::args(), cli::Exit, version) -} -error_chain::quick_main!(run); + if let Err(e) = cli::run(::std::env::args(), cli::Exit, version) { + eprintln!("Error starting the node: {}\n\n{:?}", e, e); + std::process::exit(1) + } +} diff --git a/node-template/src/service.rs b/node-template/src/service.rs index 7a6a3f0c27b222d57ae03d553583494aac7d3843..25e7db8dec34d6ca6605c0bb26bd2bdc21fabe8e 100644 --- a/node-template/src/service.rs +++ b/node-template/src/service.rs @@ -10,10 +10,11 @@ use substrate_service::{ FactoryFullConfiguration, LightComponents, FullComponents, FullBackend, FullClient, LightClient, LightBackend, FullExecutor, LightExecutor, TaskExecutor, - error::{Error as ServiceError, ErrorKind as ServiceErrorKind}, + error::{Error as ServiceError}, }; use basic_authorship::ProposerFactory; use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, NothingExtra}; +use futures::prelude::*; use substrate_client::{self as client, LongestChain}; use primitives::{ed25519::Pair, Pair as PairT}; use inherents::InherentDataProviders; @@ -46,10 +47,18 @@ construct_service_factory! { RuntimeApi = RuntimeApi, NetworkProtocol = NodeProtocol { |config| Ok(NodeProtocol::new()) }, RuntimeDispatch = Executor, - FullTransactionPoolApi = transaction_pool::ChainApi, FullExecutor, Block, RuntimeApi>, Block> - { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, - LightTransactionPoolApi = transaction_pool::ChainApi, LightExecutor, Block, RuntimeApi>, Block> - { |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) }, + FullTransactionPoolApi = transaction_pool::ChainApi< + client::Client, FullExecutor, Block, RuntimeApi>, + Block + > { + |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) + }, + LightTransactionPoolApi = transaction_pool::ChainApi< + client::Client, LightExecutor, Block, RuntimeApi>, + Block + > { + |config, client| Ok(TransactionPool::new(config, transaction_pool::ChainApi::new(client))) + }, Genesis = GenesisConfig, Configuration = NodeConfig, FullService = FullComponents @@ -63,12 +72,11 @@ construct_service_factory! { let proposer = Arc::new(ProposerFactory { client: service.client(), transaction_pool: service.transaction_pool(), - inherents_pool: service.inherents_pool(), }); let client = service.client(); let select_chain = service.select_chain() - .ok_or_else(|| ServiceError::from(ServiceErrorKind::SelectChainRequired))?; - executor.spawn(start_aura( + .ok_or_else(|| ServiceError::SelectChainRequired)?; + let aura = start_aura( SlotDuration::get_or_compute(&*client)?, key.clone(), client.clone(), @@ -76,10 +84,10 @@ construct_service_factory! { client, proposer, service.network(), - service.on_exit(), service.config.custom.inherent_data_providers.clone(), service.config.force_authoring, - )?); + )?; + executor.spawn(aura.select(service.on_exit()).then(|_| Ok(()))); } Ok(service) @@ -121,10 +129,8 @@ construct_service_factory! { }, SelectChain = LongestChain, Self::Block> { |config: &FactoryFullConfiguration, client: Arc>| { - Ok(LongestChain::new( - client.backend().clone(), - client.import_lock() - )) + #[allow(deprecated)] + Ok(LongestChain::new(client.backend().clone())) } }, FinalityProofProvider = { |_client: Arc>| { diff --git a/node/cli/Cargo.toml b/node/cli/Cargo.toml index 38cf49c35f7ba074b21c7740cd3fc6acde887d81..24234fd271e0223cac31bfef46990367b2751b66 100644 --- a/node/cli/Cargo.toml +++ b/node/cli/Cargo.toml @@ -30,8 +30,16 @@ sr-primitives = { path = "../../core/sr-primitives" } node-executor = { path = "../executor" } substrate-keystore = { path = "../../core/keystore" } substrate-telemetry = { package = "substrate-telemetry", path = "../../core/telemetry" } +structopt = "0.2" +transaction-factory = { path = "../../test-utils/transaction-factory" } +keyring = { package = "substrate-keyring", path = "../../core/keyring" } +indices = { package = "srml-indices", path = "../../srml/indices" } +timestamp = { package = "srml-timestamp", path = "../../srml/timestamp", default-features = false } +rand = "0.6" +finality_tracker = { package = "srml-finality-tracker", path = "../../srml/finality-tracker", default-features = false } [dev-dependencies] +consensus-common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } service-test = { package = "substrate-service-test", path = "../../core/service/test" } [build-dependencies] diff --git a/node/cli/src/chain_spec.rs b/node/cli/src/chain_spec.rs index 336636fef884b027398a50e46df7ba72ce62935e..242c5078f5f39390f9e357b3154f45691e9c9b52 100644 --- a/node/cli/src/chain_spec.rs +++ b/node/cli/src/chain_spec.rs @@ -18,7 +18,7 @@ use primitives::{ed25519::Public as AuthorityId, ed25519, sr25519, Pair, crypto::UncheckedInto}; use node_primitives::AccountId; -use node_runtime::{ConsensusConfig, CouncilSeatsConfig, CouncilVotingConfig, DemocracyConfig, +use node_runtime::{ConsensusConfig, CouncilSeatsConfig, DemocracyConfig, SessionConfig, StakingConfig, StakerStatus, TimestampConfig, BalancesConfig, TreasuryConfig, SudoConfig, ContractConfig, GrandpaConfig, IndicesConfig, Permill, Perbill}; pub use node_runtime::GenesisConfig; @@ -119,30 +119,21 @@ fn staging_testnet_config_genesis() -> GenesisConfig { stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(), invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(), }), - democracy: Some(DemocracyConfig { - launch_period: 10 * MINUTES, // 1 day per public referendum - voting_period: 10 * MINUTES, // 3 days to discuss & vote on an active referendum - minimum_deposit: 50 * DOLLARS, // 12000 as the minimum deposit for a referendum - public_delay: 10 * MINUTES, - max_lock_periods: 6, - }), + democracy: Some(DemocracyConfig::default()), council_seats: Some(CouncilSeatsConfig { active_council: vec![], candidacy_bond: 10 * DOLLARS, voter_bond: 1 * DOLLARS, + voting_fee: 2 * DOLLARS, present_slash_per_voter: 1 * CENTS, carry_count: 6, presentation_duration: 1 * DAYS, approval_voting_period: 2 * DAYS, term_duration: 28 * DAYS, desired_seats: 0, + decay_ratio: 0, inactive_grace_period: 1, // one additional vote should go by before an inactive voter can be reaped. }), - council_voting: Some(CouncilVotingConfig { - cooloff_period: 4 * DAYS, - voting_period: 1 * DAYS, - enact_delay_period: 0, - }), timestamp: Some(TimestampConfig { minimum_period: SECS_PER_BLOCK / 2, // due to the nature of aura the slots are 2*period }), @@ -245,6 +236,7 @@ pub fn testnet_genesis( const STASH: u128 = 1 << 20; const ENDOWMENT: u128 = 1 << 20; + let council_desired_seats = (endowed_accounts.len() / 2 - initial_authorities.len()) as u32; let mut contract_config = ContractConfig { signed_claim_handicap: 2, rent_byte_price: 4, @@ -303,32 +295,23 @@ pub fn testnet_genesis( stakers: initial_authorities.iter().map(|x| (x.0.clone(), x.1.clone(), STASH, StakerStatus::Validator)).collect(), invulnerables: initial_authorities.iter().map(|x| x.1.clone()).collect(), }), - democracy: Some(DemocracyConfig { - launch_period: 9, - voting_period: 18, - minimum_deposit: 10, - public_delay: 0, - max_lock_periods: 6, - }), + democracy: Some(DemocracyConfig::default()), council_seats: Some(CouncilSeatsConfig { active_council: endowed_accounts.iter() .filter(|&endowed| initial_authorities.iter().find(|&(_, controller, _)| controller == endowed).is_none()) .map(|a| (a.clone(), 1000000)).collect(), candidacy_bond: 10, voter_bond: 2, + voting_fee: 5, present_slash_per_voter: 1, carry_count: 4, presentation_duration: 10, approval_voting_period: 20, term_duration: 1000000, - desired_seats: (endowed_accounts.len() / 2 - initial_authorities.len()) as u32, + desired_seats: council_desired_seats, + decay_ratio: council_desired_seats / 3, inactive_grace_period: 1, }), - council_voting: Some(CouncilVotingConfig { - cooloff_period: 75, - voting_period: 20, - enact_delay_period: 0, - }), timestamp: Some(TimestampConfig { minimum_period: 2, // 2*2=4 second block time. }), @@ -382,7 +365,7 @@ pub fn local_testnet_config() -> ChainSpec { } #[cfg(test)] -mod tests { +pub(crate) mod tests { use super::*; use service_test; use crate::service::Factory; @@ -393,13 +376,41 @@ mod tests { genesis } + fn local_testnet_genesis_instant_single() -> GenesisConfig { + let mut genesis = testnet_genesis( + vec![ + get_authority_keys_from_seed("Alice"), + ], + get_account_id_from_seed("Alice"), + None, + false, + ); + genesis.timestamp = Some(TimestampConfig { minimum_period: 1 }); + genesis + } + + /// Local testnet config (single validator - Alice) + pub fn integration_test_config_with_single_authority() -> ChainSpec { + ChainSpec::from_genesis( + "Integration Test", + "test", + local_testnet_genesis_instant_single, + vec![], + None, + None, + None, + None, + ) + } + /// Local testnet config (multivalidator Alice + Bob) - pub fn integration_test_config() -> ChainSpec { + pub fn integration_test_config_with_two_authorities() -> ChainSpec { ChainSpec::from_genesis("Integration Test", "test", local_testnet_genesis_instant, vec![], None, None, None, None) } #[test] + #[ignore] fn test_connectivity() { - service_test::connectivity::(integration_test_config()); + service_test::connectivity::(integration_test_config_with_two_authorities()); } } diff --git a/node/cli/src/factory_impl.rs b/node/cli/src/factory_impl.rs new file mode 100644 index 0000000000000000000000000000000000000000..a2ac6f5b2917eb7aca502216941a3f63cab945fc --- /dev/null +++ b/node/cli/src/factory_impl.rs @@ -0,0 +1,259 @@ +// 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 . + +//! Implementation of the transaction factory trait, which enables +//! using the cli to manufacture transactions and distribute them +//! to accounts. + +use rand::{Rng, SeedableRng}; +use rand::rngs::StdRng; + +use parity_codec::Decode; +use keyring::sr25519::Keyring; +use node_primitives::Hash; +use node_runtime::{Call, CheckedExtrinsic, UncheckedExtrinsic, BalancesCall}; +use primitives::sr25519; +use primitives::crypto::Pair; +use parity_codec::Encode; +use sr_primitives::generic::Era; +use sr_primitives::traits::{Block as BlockT, Header as HeaderT}; +use substrate_service::ServiceFactory; +use transaction_factory::RuntimeAdapter; +use transaction_factory::modes::Mode; +use crate::service; +use inherents::InherentData; +use timestamp; +use finality_tracker; + +// TODO get via api: >::minimum_period(). See #2587. +const MINIMUM_PERIOD: u64 = 99; + +pub struct FactoryState { + block_no: N, + + mode: Mode, + start_number: u64, + rounds: u64, + round: u64, + block_in_round: u64, + num: u64, +} + +type Number = <::Header as HeaderT>::Number; + +impl RuntimeAdapter for FactoryState { + type AccountId = node_primitives::AccountId; + type Balance = node_primitives::Balance; + type Block = node_primitives::Block; + type Phase = sr_primitives::generic::Phase; + type Secret = sr25519::Pair; + type Index = node_primitives::Index; + + type Number = Number; + + fn new( + mode: Mode, + num: u64, + rounds: u64, + ) -> FactoryState { + FactoryState { + mode, + num: num, + round: 0, + rounds, + block_in_round: 0, + block_no: 0, + start_number: 0, + } + } + + fn block_no(&self) -> Self::Number { + self.block_no + } + + fn block_in_round(&self) -> Self::Number { + self.block_in_round + } + + fn rounds(&self) -> Self::Number { + self.rounds + } + + fn num(&self) -> Self::Number { + self.num + } + + fn round(&self) -> Self::Number { + self.round + } + + fn start_number(&self) -> Self::Number { + self.start_number + } + + fn mode(&self) -> &Mode { + &self.mode + } + + fn set_block_no(&mut self, val: Self::Number) { + self.block_no = val; + } + + fn set_block_in_round(&mut self, val: Self::Number) { + self.block_in_round = val; + } + + fn set_round(&mut self, val: Self::Number) { + self.round = val; + } + + fn transfer_extrinsic( + &self, + sender: &Self::AccountId, + key: &Self::Secret, + destination: &Self::AccountId, + amount: &Self::Number, + prior_block_hash: &::Hash, + ) -> ::Extrinsic { + let index = self.extract_index(&sender, prior_block_hash); + let phase = self.extract_phase(*prior_block_hash); + + sign::(CheckedExtrinsic { + signed: Some((sender.clone(), index)), + function: Call::Balances( + BalancesCall::transfer( + indices::address::Address::Id( + destination.clone().into() + ), + (*amount).into() + ) + ) + }, key, &prior_block_hash, phase) + } + + fn inherent_extrinsics(&self) -> InherentData { + let timestamp = self.block_no * MINIMUM_PERIOD; + + let mut inherent = InherentData::new(); + inherent.put_data(timestamp::INHERENT_IDENTIFIER, ×tamp) + .expect("Failed putting timestamp inherent"); + inherent.put_data(finality_tracker::INHERENT_IDENTIFIER, &self.block_no) + .expect("Failed putting finalized number inherent"); + inherent + } + + fn minimum_balance() -> Self::Number { + // TODO get correct amount via api. See #2587. + 1337 + } + + fn master_account_id() -> Self::AccountId { + Keyring::Alice.pair().public() + } + + fn master_account_secret() -> Self::Secret { + Keyring::Alice.pair() + } + + /// Generates a random `AccountId` from `seed`. + fn gen_random_account_id(seed: &Self::Number) -> Self::AccountId { + let pair: sr25519::Pair = sr25519::Pair::from_seed(gen_seed_bytes(*seed)); + pair.public().into() + } + + /// Generates a random `Secret` from `seed`. + fn gen_random_account_secret(seed: &Self::Number) -> Self::Secret { + let pair: sr25519::Pair = sr25519::Pair::from_seed(gen_seed_bytes(*seed)); + pair + } + + fn extract_index( + &self, + _account_id: &Self::AccountId, + _block_hash: &::Hash, + ) -> Self::Index { + // TODO get correct index for account via api. See #2587. + // This currently prevents the factory from being used + // without a preceding purge of the database. + if self.mode == Mode::MasterToN || self.mode == Mode::MasterTo1 { + self.block_no() + } else { + match self.round() { + 0 => + // if round is 0 all transactions will be done with master as a sender + self.block_no(), + _ => + // if round is e.g. 1 every sender account will be new and not yet have + // any transactions done + 0 + } + } + } + + fn extract_phase( + &self, + _block_hash: ::Hash + ) -> Self::Phase { + // TODO get correct phase via api. See #2587. + // This currently prevents the factory from being used + // without a preceding purge of the database. + self.block_no + } +} + +fn gen_seed_bytes(seed: u64) -> [u8; 32] { + let mut rng: StdRng = SeedableRng::seed_from_u64(seed); + + let mut seed_bytes = [0u8; 32]; + for i in 0..32 { + seed_bytes[i] = rng.gen::(); + } + seed_bytes +} + +/// Creates an `UncheckedExtrinsic` containing the appropriate signature for +/// a `CheckedExtrinsics`. +fn sign( + xt: CheckedExtrinsic, + key: &sr25519::Pair, + prior_block_hash: &Hash, + phase: u64, +) -> ::Extrinsic { + let s = match xt.signed { + Some((signed, index)) => { + let era = Era::mortal(256, phase); + let payload = (index.into(), xt.function, era, prior_block_hash); + let signature = payload.using_encoded(|b| { + if b.len() > 256 { + key.sign(&sr_io::blake2_256(b)) + } else { + key.sign(b) + } + }).into(); + UncheckedExtrinsic { + signature: Some((indices::address::Address::Id(signed), signature, payload.0, era)), + function: payload.1, + } + } + None => UncheckedExtrinsic { + signature: None, + function: xt.function, + }, + }; + + let e = Encode::encode(&s); + Decode::decode(&mut &e[..]).expect("Failed to decode signed unchecked extrinsic") +} diff --git a/node/cli/src/lib.rs b/node/cli/src/lib.rs index cbb0628a91258d7f773689eaca314a873fe54133..ab1fd03ae7b24eb7afc4a4ba44a710f143bc09c9 100644 --- a/node/cli/src/lib.rs +++ b/node/cli/src/lib.rs @@ -22,16 +22,21 @@ pub use cli::error; pub mod chain_spec; mod service; +mod factory_impl; use tokio::prelude::Future; use tokio::runtime::{Builder as RuntimeBuilder, Runtime}; -pub use cli::{VersionInfo, IntoExit, NoCustom}; +pub use cli::{VersionInfo, IntoExit, NoCustom, SharedParams}; use substrate_service::{ServiceFactory, Roles as ServiceRoles}; use std::ops::Deref; use log::info; +use structopt::{StructOpt, clap::App}; +use cli::{AugmentClap, GetLogFilter}; +use crate::factory_impl::FactoryState; +use transaction_factory::RuntimeAdapter; /// The chain specification option. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, PartialEq)] pub enum ChainSpec { /// Whatever the current runtime is, with just Alice as an auth. Development, @@ -43,6 +48,68 @@ pub enum ChainSpec { StagingTestnet, } +/// Custom subcommands. +#[derive(Clone, Debug, StructOpt)] +pub enum CustomSubcommands { + /// The custom factory subcommmand for manufacturing transactions. + #[structopt( + name = "factory", + about = "Manufactures num transactions from Alice to random accounts. \ + Only supported for development or local testnet." + )] + Factory(FactoryCmd), +} + +impl GetLogFilter for CustomSubcommands { + fn get_log_filter(&self) -> Option { + None + } +} + +/// The `factory` command used to generate transactions. +/// Please note: this command currently only works on an empty database! +#[derive(Debug, StructOpt, Clone)] +pub struct FactoryCmd { + /// How often to repeat. This option only has an effect in mode `MasterToNToM`. + #[structopt(long="rounds", default_value = "1")] + pub rounds: u64, + + /// MasterToN: Manufacture `num` transactions from the master account + /// to `num` randomly created accounts, one each. + /// + /// MasterTo1: Manufacture `num` transactions from the master account + /// to exactly one other randomly created account. + /// + /// MasterToNToM: Manufacture `num` transactions from the master account + /// to `num` randomly created accounts. + /// From each of these randomly created accounts manufacture + /// a transaction to another randomly created account. + /// Repeat this `rounds` times. If `rounds` = 1 the behavior + /// is the same as `MasterToN`.{n} + /// A -> B, A -> C, A -> D, ... x `num`{n} + /// B -> E, C -> F, D -> G, ...{n} + /// ... x `rounds` + /// + /// These three modes control manufacturing. + #[structopt(long="mode", default_value = "MasterToN")] + pub mode: transaction_factory::Mode, + + /// Number of transactions to generate. In mode `MasterNToNToM` this is + /// the number of transactions per round. + #[structopt(long="num", default_value = "8")] + pub num: u64, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl AugmentClap for FactoryCmd { + fn augment_clap<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> { + FactoryCmd::augment_clap(app) + } +} + /// Get a chain config from a spec setting. impl ChainSpec { pub(crate) fn load(self) -> Result { @@ -78,7 +145,7 @@ pub fn run(args: I, exit: E, version: cli::VersionInfo) -> error::Resul T: Into + Clone, E: IntoExit, { - cli::parse_and_execute::( + let ret = cli::parse_and_execute::( load_spec, &version, "substrate-node", args, exit, |exit, _cli_args, _custom_args, config| { info!("{}", version.name); @@ -103,7 +170,35 @@ pub fn run(args: I, exit: E, version: cli::VersionInfo) -> error::Resul ), }.map_err(|e| format!("{:?}", e)) } - ).map_err(Into::into).map(|_| ()) + ); + + match &ret { + Ok(Some(CustomSubcommands::Factory(cli_args))) => { + let config = cli::create_config_with_db_path::( + load_spec, + &cli_args.shared_params, + &version, + )?; + + match ChainSpec::from(config.chain_spec.id()) { + Some(ref c) if c == &ChainSpec::Development || c == &ChainSpec::LocalTestnet => {}, + _ => panic!("Factory is only supported for development and local testnet."), + } + + let factory_state = FactoryState::new( + cli_args.mode.clone(), + cli_args.num, + cli_args.rounds, + ); + transaction_factory::factory::>( + factory_state, + config, + ).map_err(|e| format!("Error in transaction factory: {}", e))?; + + Ok(()) + }, + _ => ret.map_err(Into::into).map(|_| ()) + } } fn run_until_exit( @@ -118,8 +213,8 @@ fn run_until_exit( { let (exit_send, exit) = exit_future::signal(); - let executor = runtime.executor(); - cli::informant::start(&service, exit.clone(), executor.clone()); + let informant = cli::informant::build(&service); + runtime.executor().spawn(exit.until(informant).map(|_| ())); let _ = runtime.block_on(e.into_exit()); exit_send.fire(); diff --git a/node/cli/src/service.rs b/node/cli/src/service.rs index 90041b4cbb7259e2d9cd20cd4a93edd7715fd0f3..1458392b0f5fe1af914bfcda71742fcf5ab1b225 100644 --- a/node/cli/src/service.rs +++ b/node/cli/src/service.rs @@ -26,12 +26,13 @@ use consensus::{import_queue, start_aura, AuraImportQueue, SlotDuration, Nothing use grandpa::{self, FinalityProofProvider as GrandpaFinalityProofProvider}; use node_executor; use primitives::{Pair as PairT, ed25519}; +use futures::prelude::*; use node_primitives::Block; use node_runtime::{GenesisConfig, RuntimeApi}; use substrate_service::{ FactoryFullConfiguration, LightComponents, FullComponents, FullBackend, FullClient, LightClient, LightBackend, FullExecutor, LightExecutor, TaskExecutor, - error::{Error as ServiceError, ErrorKind as ServiceErrorKind}, + error::{Error as ServiceError}, }; use transaction_pool::{self, txpool::{Pool as TransactionPool}}; use inherents::InherentDataProviders; @@ -87,13 +88,12 @@ construct_service_factory! { let proposer = Arc::new(substrate_basic_authorship::ProposerFactory { client: service.client(), transaction_pool: service.transaction_pool(), - inherents_pool: service.inherents_pool(), }); let client = service.client(); let select_chain = service.select_chain() - .ok_or_else(|| ServiceError::from(ServiceErrorKind::SelectChainRequired))?; - executor.spawn(start_aura( + .ok_or(ServiceError::SelectChainRequired)?; + let aura = start_aura( SlotDuration::get_or_compute(&*client)?, key.clone(), client, @@ -101,10 +101,10 @@ construct_service_factory! { block_import.clone(), proposer, service.network(), - service.on_exit(), service.config.custom.inherent_data_providers.clone(), service.config.force_authoring, - )?); + )?; + executor.spawn(aura.select(service.on_exit()).then(|_| Ok(()))); info!("Running Grandpa session as Authority {}", key.public()); } @@ -180,6 +180,7 @@ construct_service_factory! { }}, LightImportQueue = AuraImportQueue { |config: &FactoryFullConfiguration, client: Arc>| { + #[allow(deprecated)] let fetch_checker = client.backend().blockchain().fetcher() .upgrade() .map(|fetcher| fetcher.checker().clone()) @@ -204,10 +205,8 @@ construct_service_factory! { }}, SelectChain = LongestChain, Self::Block> { |config: &FactoryFullConfiguration, client: Arc>| { - Ok(LongestChain::new( - client.backend().clone(), - client.import_lock() - )) + #[allow(deprecated)] + Ok(LongestChain::new(client.backend().clone())) } }, FinalityProofProvider = { |client: Arc>| { @@ -219,6 +218,23 @@ construct_service_factory! { #[cfg(test)] mod tests { + use std::sync::Arc; + use consensus::CompatibleDigestItem; + use consensus_common::{Environment, Proposer, ImportBlock, BlockOrigin, ForkChoiceStrategy}; + use node_primitives::DigestItem; + use node_runtime::{Call, BalancesCall, UncheckedExtrinsic}; + use parity_codec::{Compact, Encode, Decode}; + use primitives::{ + crypto::Pair as CryptoPair, ed25519::Pair, blake2_256, + sr25519::Public as AddressPublic, + }; + use sr_primitives::{generic::{BlockId, Era, Digest}, traits::{Block, Digest as DigestT}, OpaqueExtrinsic}; + use timestamp; + use finality_tracker; + use keyring::{ed25519::Keyring as AuthorityKeyring, sr25519::Keyring as AccountKeyring}; + use substrate_service::ServiceFactory; + use crate::service::Factory; + #[cfg(feature = "rhd")] fn test_sync() { use {service_test, Factory}; @@ -230,7 +246,7 @@ mod tests { let keys: Vec<&ed25519::Pair> = vec![&*alice, &*bob]; let dummy_runtime = ::tokio::runtime::Runtime::new().unwrap(); let block_factory = |service: &::FullService| { - let block_id = BlockId::number(service.client().info().unwrap().chain.best_number); + let block_id = BlockId::number(service.client().info().chain.best_number); let parent_header = service.client().header(&block_id).unwrap().unwrap(); let consensus_net = ConsensusNetwork::new(service.network(), service.client().clone()); let proposer_factory = consensus::ProposerFactory { @@ -266,4 +282,107 @@ mod tests { service_test::sync::(chain_spec::integration_test_config(), block_factory, extrinsic_factory); } + #[test] + #[ignore] + fn test_sync() { + let chain_spec = crate::chain_spec::tests::integration_test_config_with_single_authority(); + + let alice = Arc::new(AuthorityKeyring::Alice.pair()); + let mut slot_num = 1u64; + let block_factory = |service: &::FullService| { + let mut inherent_data = service.config.custom.inherent_data_providers + .create_inherent_data().unwrap(); + inherent_data.replace_data(finality_tracker::INHERENT_IDENTIFIER, &1u64); + inherent_data.replace_data(timestamp::INHERENT_IDENTIFIER, &(slot_num * 10)); + + let parent_id = BlockId::number(service.client().info().chain.best_number); + let parent_header = service.client().header(&parent_id).unwrap().unwrap(); + let proposer_factory = Arc::new(substrate_basic_authorship::ProposerFactory { + client: service.client(), + transaction_pool: service.transaction_pool(), + }); + let mut digest = Digest::::default(); + digest.push(>::aura_pre_digest(slot_num * 10 / 2)); + let proposer = proposer_factory.init(&parent_header, &[]).unwrap(); + let new_block = proposer.propose( + inherent_data, + digest, + ::std::time::Duration::from_secs(1), + ).expect("Error making test block"); + + let (new_header, new_body) = new_block.deconstruct(); + let pre_hash = new_header.hash(); + // sign the pre-sealed hash of the block and then + // add it to a digest item. + let to_sign = pre_hash.encode(); + let signature = alice.sign(&to_sign[..]); + let item = >::aura_seal( + signature, + ); + slot_num += 1; + + ImportBlock { + origin: BlockOrigin::File, + header: new_header, + justification: None, + post_digests: vec![item], + body: Some(new_body), + finalized: true, + auxiliary: Vec::new(), + fork_choice: ForkChoiceStrategy::LongestChain, + } + }; + + let bob = Arc::new(AccountKeyring::Bob.pair()); + let charlie = Arc::new(AccountKeyring::Charlie.pair()); + + let mut index = 0; + let extrinsic_factory = |service: &::FullService| { + let amount = 1000; + let to = AddressPublic::from_raw(bob.public().0); + let from = AddressPublic::from_raw(charlie.public().0); + let genesis_hash = service.client().block_hash(0).unwrap().unwrap(); + let signer = charlie.clone(); + + let function = Call::Balances(BalancesCall::transfer(to.into(), amount)); + let era = Era::immortal(); + let raw_payload = (Compact(index), function, era, genesis_hash); + let signature = raw_payload.using_encoded(|payload| if payload.len() > 256 { + signer.sign(&blake2_256(payload)[..]) + } else { + signer.sign(payload) + }); + let xt = UncheckedExtrinsic::new_signed( + index, + raw_payload.1, + from.into(), + signature.into(), + era, + ).encode(); + let v: Vec = Decode::decode(&mut xt.as_slice()).unwrap(); + + index += 1; + OpaqueExtrinsic(v) + }; + + service_test::sync::( + chain_spec, + block_factory, + extrinsic_factory, + ); + } + + #[test] + #[ignore] + fn test_consensus() { + use super::Factory; + + service_test::consensus::( + crate::chain_spec::tests::integration_test_config_with_two_authorities(), + vec![ + "//Alice".into(), + "//Bob".into(), + ], + ) + } } diff --git a/node/executor/Cargo.toml b/node/executor/Cargo.toml index 89b448ec90141481644a2dd7faa7df59031e0567..ee126d19ea495c50ad02ec7e0e0fbeab8729b51c 100644 --- a/node/executor/Cargo.toml +++ b/node/executor/Cargo.toml @@ -17,6 +17,7 @@ node-primitives = { path = "../primitives" } node-runtime = { path = "../runtime" } [dev-dependencies] +test-client = { package = "substrate-test-client", path = "../../core/test-client" } keyring = { package = "substrate-keyring", path = "../../core/keyring" } runtime_primitives = { package = "sr-primitives", path = "../../core/sr-primitives" } runtime_support = { package = "srml-support", path = "../../srml/support" } diff --git a/node/executor/src/lib.rs b/node/executor/src/lib.rs index c6903529c4cd1a21af259e580ae6b3a26ee25af9..aabee6805e327c1af028c9ed2517a1c797ced4e5 100644 --- a/node/executor/src/lib.rs +++ b/node/executor/src/lib.rs @@ -33,7 +33,7 @@ mod tests { use parity_codec::{Encode, Decode, Joiner}; use keyring::{AuthorityKeyring, AccountKeyring}; use runtime_support::{Hashable, StorageValue, StorageMap, traits::Currency}; - use state_machine::{CodeExecutor, Externalities, TestExternalities}; + use state_machine::{CodeExecutor, Externalities, TestExternalities as CoreTestExternalities}; use primitives::{twox_128, blake2_256, Blake2Hasher, ChangesTrieConfiguration, NeverNativeValue, NativeOrEncoded}; use node_primitives::{Hash, BlockNumber, AccountId}; @@ -52,6 +52,8 @@ mod tests { const COMPACT_CODE: &[u8] = include_bytes!("../../runtime/wasm/target/wasm32-unknown-unknown/release/node_runtime.compact.wasm"); const GENESIS_HASH: [u8; 32] = [69u8; 32]; + type TestExternalities = CoreTestExternalities; + fn alice() -> AccountId { AccountKeyring::Alice.into() } @@ -258,7 +260,7 @@ mod tests { fn new_test_ext(code: &[u8], support_changes_trie: bool) -> TestExternalities { let three = AccountId::from_raw([3u8; 32]); - TestExternalities::new_with_code(code, GenesisConfig { + let mut ext = TestExternalities::new_with_code(code, GenesisConfig { consensus: Some(Default::default()), system: Some(SystemConfig { changes_trie_config: if support_changes_trie { Some(ChangesTrieConfiguration { @@ -314,7 +316,6 @@ mod tests { }), democracy: Some(Default::default()), council_seats: Some(Default::default()), - council_voting: Some(Default::default()), timestamp: Some(Default::default()), treasury: Some(Default::default()), contract: Some(Default::default()), @@ -322,7 +323,9 @@ mod tests { grandpa: Some(GrandpaConfig { authorities: vec![], }), - }.build_storage().unwrap().0) + }.build_storage().unwrap().0); + ext.changes_trie_storage().insert(0, GENESIS_HASH.into(), Default::default()); + ext } fn construct_block( @@ -879,7 +882,7 @@ mod tests { None, ).0.unwrap(); - assert!(t.storage_changes_root(Default::default(), 0).is_some()); + assert!(t.storage_changes_root(GENESIS_HASH.into()).unwrap().is_some()); } #[test] @@ -889,7 +892,22 @@ mod tests { let mut t = new_test_ext(COMPACT_CODE, true); WasmExecutor::new().call(&mut t, 8, COMPACT_CODE, "Core_execute_block", &block1.0).unwrap(); - assert!(t.storage_changes_root(Default::default(), 0).is_some()); + assert!(t.storage_changes_root(GENESIS_HASH.into()).unwrap().is_some()); + } + + #[test] + fn should_import_block_with_test_client() { + use test_client::{ClientExt, TestClientBuilder, consensus::BlockOrigin}; + + let client = TestClientBuilder::default() + .build_with_native_executor::(executor()) + .0; + + let block1 = changes_trie_block(); + let block_data = block1.0; + let block = Block::decode(&mut &block_data[..]).unwrap(); + + client.import(BlockOrigin::Own, block).unwrap(); } #[cfg(feature = "benchmarks")] diff --git a/node/primitives/src/lib.rs b/node/primitives/src/lib.rs index 4dde59296f4980c6ec4a0b3bf6734609de6405bf..2135ad672ff87725349e216fe553be1df96edd21 100644 --- a/node/primitives/src/lib.rs +++ b/node/primitives/src/lib.rs @@ -57,9 +57,10 @@ pub type Hash = primitives::H256; /// A timestamp: seconds since the unix epoch. pub type Timestamp = u64; +/// Digest item type. +pub type DigestItem = generic::DigestItem; /// Header type. -/// -pub type Header = generic::Header>; +pub type Header = generic::Header; /// Block type. pub type Block = generic::Block; /// Block ID. diff --git a/node/rpc-client/Cargo.toml b/node/rpc-client/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..ea255808e463e47d2f6c0d3bdf15044b0b827815 --- /dev/null +++ b/node/rpc-client/Cargo.toml @@ -0,0 +1,14 @@ +[package] +name = "node-rpc-client" +version = "2.0.0" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +env_logger = "0.6" +futures = "0.1.26" +hyper = "0.12" +jsonrpc-core-client = { version = "12.0.0", features = ["http", "ws"] } +log = "0.4" +node-primitives = { path = "../primitives" } +substrate-rpc = { path = "../../core/rpc", version = "2.0.0" } diff --git a/node/rpc-client/src/main.rs b/node/rpc-client/src/main.rs new file mode 100644 index 0000000000000000000000000000000000000000..fe057bcbeaf4236661d5109513138a93a7e894f7 --- /dev/null +++ b/node/rpc-client/src/main.rs @@ -0,0 +1,70 @@ +// 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 . + +#![warn(missing_docs)] + +//! Example substrate RPC client code. +//! +//! This module shows how you can write a Rust RPC client that connects to a running +//! substrate node and use staticly typed RPC wrappers. + +use futures::Future; +use hyper::rt; +use node_primitives::Hash; +use substrate_rpc::author::{ + AuthorClient, + hash::ExtrinsicOrHash, +}; +use jsonrpc_core_client::{ + transports::http, + RpcError, +}; + +fn main() { + env_logger::init(); + + rt::run(rt::lazy(|| { + let uri = "http://localhost:9933"; + + http::connect(uri) + .and_then(|client: AuthorClient| { + remove_all_extrinsics(client) + }) + .map_err(|e| { + println!("Error: {:?}", e); + }) + })) +} + +/// Remove all pending extrinsics from the node. +/// +/// The example code takes `AuthorClient` and first: +/// 1. Calls the `pending_extrinsics` method to get all extrinsics in the pool. +/// 2. Then calls `remove_extrinsic` passing the obtained raw extrinsics. +/// +/// As the resul of running the code the entire content of the transaction pool is going +/// to be removed and the extrinsics are going to be temporarily banned. +fn remove_all_extrinsics(client: AuthorClient) -> impl Future { + client.pending_extrinsics() + .and_then(move |pending| { + client.remove_extrinsic( + pending.into_iter().map(|tx| ExtrinsicOrHash::Extrinsic(tx.into())).collect() + ) + }) + .map(|removed| { + println!("Removed extrinsics: {:?}", removed); + }) +} diff --git a/node/runtime/src/lib.rs b/node/runtime/src/lib.rs index e2bd33691656503934efb5905cc8092c85f63461..1c9c0ca4fde62389c487ba0b8fdd72e76b88b92f 100644 --- a/node/runtime/src/lib.rs +++ b/node/runtime/src/lib.rs @@ -21,8 +21,8 @@ #![recursion_limit="256"] use rstd::prelude::*; -use support::construct_runtime; -use substrate_primitives::u32_trait::{_2, _4}; +use support::{construct_runtime, parameter_types}; +use substrate_primitives::u32_trait::{_1, _2, _3, _4}; use node_primitives::{ AccountId, AccountIndex, Balance, BlockNumber, Hash, Index, AuthorityId, Signature, AuthoritySignature }; @@ -37,7 +37,7 @@ use runtime_primitives::traits::{ BlakeTwo256, Block as BlockT, DigestFor, NumberFor, StaticLookup, AuthorityIdFor, Convert, }; use version::RuntimeVersion; -use council::{motions as council_motions, voting as council_voting}; +use council::{motions as council_motions}; #[cfg(feature = "std")] use council::seats as council_seats; #[cfg(any(feature = "std", test))] @@ -58,8 +58,8 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: create_runtime_str!("node"), impl_name: create_runtime_str!("substrate-node"), authoring_version: 10, - spec_version: 81, - impl_version: 82, + spec_version: 92, + impl_version: 94, apis: RUNTIME_API_VERSIONS, }; @@ -150,21 +150,43 @@ impl staking::Trait for Runtime { type Reward = (); } +const MINUTES: BlockNumber = 6; +const BUCKS: Balance = 1_000_000_000_000; + +parameter_types! { + pub const LaunchPeriod: BlockNumber = 28 * 24 * 60 * MINUTES; + pub const VotingPeriod: BlockNumber = 28 * 24 * 60 * MINUTES; + pub const EmergencyVotingPeriod: BlockNumber = 3 * 24 * 60 * MINUTES; + pub const MinimumDeposit: Balance = 100 * BUCKS; + pub const EnactmentPeriod: BlockNumber = 30 * 24 * 60 * MINUTES; + pub const CooloffPeriod: BlockNumber = 30 * 24 * 60 * MINUTES; +} impl democracy::Trait for Runtime { - type Currency = Balances; type Proposal = Call; type Event = Event; + type Currency = Balances; + type EnactmentPeriod = EnactmentPeriod; + type LaunchPeriod = LaunchPeriod; + type VotingPeriod = VotingPeriod; + type EmergencyVotingPeriod = EmergencyVotingPeriod; + type MinimumDeposit = MinimumDeposit; + type ExternalOrigin = council_motions::EnsureProportionAtLeast<_1, _2, AccountId>; + type ExternalMajorityOrigin = council_motions::EnsureProportionAtLeast<_2, _3, AccountId>; + type EmergencyOrigin = council_motions::EnsureProportionAtLeast<_1, _1, AccountId>; + type CancellationOrigin = council_motions::EnsureProportionAtLeast<_2, _3, AccountId>; + type VetoOrigin = council_motions::EnsureMember; + type CooloffPeriod = CooloffPeriod; } impl council::Trait for Runtime { type Event = Event; type BadPresentation = (); type BadReaper = (); + type BadVoterIndex = (); + type LoserCandidate = (); + type OnMembersChanged = CouncilMotions; } -impl council::voting::Trait for Runtime { - type Event = Event; -} impl council::motions::Trait for Runtime { type Origin = Origin; @@ -174,8 +196,8 @@ impl council::motions::Trait for Runtime { impl treasury::Trait for Runtime { type Currency = Balances; - type ApproveOrigin = council_motions::EnsureMembers<_4>; - type RejectOrigin = council_motions::EnsureMembers<_2>; + type ApproveOrigin = council_motions::EnsureMembers<_4, AccountId>; + type RejectOrigin = council_motions::EnsureMembers<_2, AccountId>; type Event = Event; type MintedForSpending = (); type ProposalRejection = (); @@ -214,7 +236,7 @@ construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic { System: system::{default, Log(ChangesTrieRoot)}, - Aura: aura::{Module, Inherent(Timestamp)}, + Aura: aura::{Module, Inherent(Timestamp), Log(PreRuntime)}, Timestamp: timestamp::{Module, Call, Storage, Config, Inherent}, Consensus: consensus::{Module, Call, Storage, Config, Log(AuthoritiesChange), Inherent}, Indices: indices, @@ -223,8 +245,7 @@ construct_runtime!( Staking: staking::{default, OfflineWorker}, Democracy: democracy, Council: council::{Module, Call, Storage, Event}, - CouncilVoting: council_voting, - CouncilMotions: council_motions::{Module, Call, Storage, Event, Origin}, + CouncilMotions: council_motions::{Module, Call, Storage, Event, Origin}, CouncilSeats: council_seats::{Config}, FinalityTracker: finality_tracker::{Module, Call, Inherent}, Grandpa: grandpa::{Module, Call, Storage, Config, Log(), Event}, @@ -264,10 +285,6 @@ impl_runtime_apis! { fn initialize_block(header: &::Header) { Executive::initialize_block(header) } - - fn authorities() -> Vec> { - panic!("Deprecated, please use `AuthoritiesApi`.") - } } impl client_api::Metadata for Runtime { diff --git a/node/runtime/wasm/Cargo.lock b/node/runtime/wasm/Cargo.lock index edcd20c7c0d5be1fc69afb7e18be0718d71a4c6b..add74b0db21c7a201adf32735e3be20fe5f4f7de 100644 --- a/node/runtime/wasm/Cargo.lock +++ b/node/runtime/wasm/Cargo.lock @@ -1,5 +1,10 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. +[[package]] +name = "adler32" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "aes-ctr" version = "0.3.0" @@ -33,7 +38,7 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "0.6.10" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -44,12 +49,12 @@ name = "aio-limited" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -79,7 +84,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -87,27 +92,26 @@ name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" -version = "0.1.2" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.14" +version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -115,19 +119,22 @@ name = "backtrace-sys" version = "0.1.28" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "base-x" -version = "0.2.4" +name = "base58" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "base58" -version = "0.1.0" +name = "base64" +version = "0.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "bigint" @@ -179,10 +186,10 @@ dependencies = [ [[package]] name = "block-buffer" -version = "0.7.0" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -198,7 +205,7 @@ dependencies = [ [[package]] name = "block-padding" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -209,9 +216,14 @@ name = "bs58" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "build_const" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "bumpalo" -version = "2.4.1" +version = "2.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -250,12 +262,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.30" +version = "1.0.37" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cfg-if" -version = "0.1.7" +version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -263,8 +275,8 @@ name = "chrono" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -273,7 +285,7 @@ name = "clear_on_drop" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -289,12 +301,28 @@ name = "constant_time_eq" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "crc" +version = "1.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "crc32fast" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam" version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-epoch 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -346,7 +374,7 @@ version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -360,7 +388,7 @@ version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -380,7 +408,7 @@ name = "crossbeam-utils" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -388,7 +416,7 @@ name = "crossbeam-utils" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -399,7 +427,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crunchy" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -440,14 +468,14 @@ dependencies = [ [[package]] name = "curve25519-dalek" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -457,13 +485,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "derive_more" -version = "0.14.0" +version = "0.14.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -482,11 +510,6 @@ dependencies = [ "generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "discard" -version = "1.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "dns-parser" version = "0.8.0" @@ -502,7 +525,7 @@ version = "1.0.0-pre.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -510,7 +533,7 @@ dependencies = [ [[package]] name = "either" -version = "1.5.1" +version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -529,7 +552,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -543,15 +566,7 @@ name = "erased-serde" version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "error-chain" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -559,7 +574,7 @@ name = "failure" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -568,10 +583,10 @@ name = "failure_derive" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -581,33 +596,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "fixed-hash" -version = "0.3.0" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "fnv" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - -[[package]] -name = "foreign-types" -version = "0.3.2" +name = "flate2" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "foreign-types-shared" -version = "0.1.1" +name = "fnv" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -631,7 +646,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "futures" -version = "0.1.25" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -639,7 +654,7 @@ name = "futures-cpupool" version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -672,7 +687,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "get_if_addrs-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -682,7 +697,7 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -692,10 +707,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hash256-std-hasher" -version = "0.12.0" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -717,7 +732,7 @@ name = "heapsize" version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -725,7 +740,7 @@ name = "heck" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -735,16 +750,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "hex-literal" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "hex-literal-impl" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,6 +794,16 @@ dependencies = [ "hmac 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "http" +version = "0.1.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "httparse" version = "1.3.3" @@ -816,7 +841,15 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "impl-serde" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -829,21 +862,26 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ipnet" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "itoa" -version = "0.4.3" +version = "0.4.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "js-sys" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -874,53 +912,51 @@ name = "lazy_static" version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "lazycell" -version = "1.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "libc" -version = "0.2.50" +version = "0.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libp2p" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core-derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-dns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-floodsub 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-identify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-kad 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-mdns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-mplex 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-noise 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-ping 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-plaintext 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-ratelimit 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-secio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-tcp 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-uds 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-yamux 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core-derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-deflate 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-dns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-floodsub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-identify 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-kad 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-mdns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-mplex 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-noise 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-ping 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-plaintext 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-ratelimit 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-secio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-tcp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-uds 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-wasm-ext 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-websocket 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-yamux 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-core" -version = "0.7.0" +version = "0.9.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -929,64 +965,74 @@ dependencies = [ "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "multistream-select 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "secp256k1 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-core-derive" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libp2p-deflate" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-dns" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-floodsub" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "cuckoofilter 0.3.2 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -996,28 +1042,28 @@ dependencies = [ [[package]] name = "libp2p-identify" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-kad" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1026,54 +1072,55 @@ dependencies = [ "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-mdns" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-mplex" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (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.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1081,103 +1128,107 @@ dependencies = [ [[package]] name = "libp2p-noise" -version = "0.5.0" +version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", "snow 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "x25519-dalek 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", + "zeroize 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-ping" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-plaintext" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-ratelimit" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-secio" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-futures 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "web-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "libp2p-tcp" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "ipnet 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1185,26 +1236,57 @@ dependencies = [ [[package]] name = "libp2p-uds" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "libp2p-wasm-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libp2p-websocket" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "soketto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-rustls 0.10.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "libp2p-yamux" -version = "0.7.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "yamux 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "yamux 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1229,12 +1311,20 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lock_api" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1269,7 +1359,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "merlin" -version = "1.0.3" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1278,17 +1368,44 @@ dependencies = [ "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "miniz-sys" +version = "0.1.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "miniz_oxide_c_api" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "mio" -version = "0.6.16" +version = "0.6.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "net2 0.2.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1296,25 +1413,14 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "mio-extras" -version = "2.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "mio-uds" version = "0.6.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1334,7 +1440,7 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1347,9 +1453,9 @@ name = "net2" version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1357,7 +1463,7 @@ name = "node-primitives" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "substrate-primitives 2.0.0", @@ -1372,7 +1478,7 @@ dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "sr-version 2.0.0", @@ -1429,23 +1535,27 @@ dependencies = [ [[package]] name = "num-integer" -version = "0.1.39" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "num-traits" -version = "0.2.6" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", +] [[package]] name = "num_cpus" version = "1.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1466,31 +1576,6 @@ name = "opaque-debug" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "openssl" -version = "0.10.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "openssl-sys" -version = "0.9.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "owning_ref" version = "0.3.3" @@ -1519,7 +1604,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1527,15 +1612,15 @@ name = "parity-codec-derive" version = "3.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-multiaddr" -version = "0.4.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1543,24 +1628,31 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", "data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "parity-multihash" -version = "0.1.0" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parity-send-wrapper" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "parity-wasm" version = "0.31.3" @@ -1596,15 +1688,25 @@ dependencies = [ "parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parking_lot" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parking_lot_core" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1612,11 +1714,11 @@ name = "parking_lot_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1624,31 +1726,46 @@ name = "parking_lot_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "parking_lot_core" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "paste" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", + "paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "paste-impl" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1666,28 +1783,23 @@ name = "percent-encoding" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "pkg-config" -version = "0.3.14" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "primitive-types" -version = "0.2.1" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "proc-macro-crate" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1700,12 +1812,12 @@ dependencies = [ [[package]] name = "proc-macro-hack" -version = "0.5.4" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1715,7 +1827,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "proc-macro2" -version = "0.4.27" +version = "0.4.30" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1723,7 +1835,7 @@ dependencies = [ [[package]] name = "protobuf" -version = "2.4.0" +version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1751,7 +1863,7 @@ name = "quote" version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1759,7 +1871,7 @@ name = "rand" version = "0.3.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1769,10 +1881,10 @@ version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1782,9 +1894,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1792,17 +1904,17 @@ name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1810,7 +1922,7 @@ name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1845,12 +1957,12 @@ dependencies = [ [[package]] name = "rand_jitter" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1860,10 +1972,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1871,7 +1983,7 @@ name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1889,7 +2001,7 @@ version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1900,7 +2012,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1914,7 +2026,7 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.1.51" +version = "0.1.54" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1922,24 +2034,24 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex" -version = "1.1.2" +version = "1.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", + "aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", "utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "regex-syntax" -version = "0.6.5" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1950,17 +2062,17 @@ name = "ring" version = "0.14.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "rustc-demangle" -version = "0.1.13" +version = "0.1.15" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1976,19 +2088,32 @@ dependencies = [ "semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustls" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "rw-stream-sink" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ryu" -version = "0.2.7" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2001,51 +2126,38 @@ dependencies = [ [[package]] name = "schnorrkel" -version = "0.0.0" -source = "git+https://github.com/w3f/schnorrkel#3179838da9dd4896c12bb910e7c42477a3250641" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", + "merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] -name = "schnorrkel" -version = "0.1.0" +name = "scopeguard" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", - "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", -] [[package]] name = "scopeguard" -version = "0.3.3" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] -name = "secp256k1" -version = "0.12.0" +name = "sct" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2068,20 +2180,20 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "serde_derive" -version = "1.0.89" +version = "1.0.91" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2089,9 +2201,20 @@ name = "serde_json" version = "1.0.39" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "sha-1" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", + "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2116,7 +2239,7 @@ name = "sha2" version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2124,10 +2247,10 @@ dependencies = [ [[package]] name = "sha3" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)", "byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2147,16 +2270,6 @@ dependencies = [ "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "slog-async" -version = "2.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "slog-json" version = "2.3.0" @@ -2164,7 +2277,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2198,7 +2311,25 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", "static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)", - "subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "soketto" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)", + "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", + "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2216,10 +2347,10 @@ name = "sr-api-macros" version = "2.0.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2244,9 +2375,9 @@ version = "2.0.0" dependencies = [ "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-std 2.0.0", "substrate-primitives 2.0.0", @@ -2260,7 +2391,7 @@ dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-primitives 2.0.0", - "wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2276,7 +2407,7 @@ version = "2.0.0" dependencies = [ "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", ] @@ -2286,7 +2417,7 @@ name = "srml-aura" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-session 2.0.0", @@ -2303,7 +2434,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-support 2.0.0", @@ -2316,7 +2447,7 @@ name = "srml-consensus" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-support 2.0.0", @@ -2332,7 +2463,7 @@ dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", "pwasm-utils 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-sandbox 2.0.0", @@ -2350,7 +2481,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2366,7 +2497,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2379,7 +2510,7 @@ name = "srml-executive" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2393,7 +2524,7 @@ name = "srml-finality-tracker" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-support 2.0.0", @@ -2406,7 +2537,7 @@ name = "srml-grandpa" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-consensus 2.0.0", @@ -2424,7 +2555,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2439,7 +2570,7 @@ name = "srml-metadata" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", "substrate-primitives 2.0.0", ] @@ -2450,7 +2581,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-consensus 2.0.0", @@ -2465,7 +2596,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2481,7 +2612,7 @@ name = "srml-sudo" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2497,8 +2628,8 @@ dependencies = [ "bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2511,31 +2642,31 @@ dependencies = [ name = "srml-support-procedural" version = "2.0.0" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "srml-support-procedural-tools 2.0.0", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "srml-support-procedural-tools" version = "2.0.0" dependencies = [ - "proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "srml-support-procedural-tools-derive 2.0.0", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "srml-support-procedural-tools-derive" version = "2.0.0" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2544,7 +2675,7 @@ version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2557,7 +2688,7 @@ name = "srml-timestamp" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-support 2.0.0", @@ -2570,7 +2701,7 @@ name = "srml-treasury" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", "srml-balances 2.0.0", @@ -2593,50 +2724,6 @@ name = "static_slice" version = "0.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "stdweb" -version = "0.4.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-macros 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "stdweb-internal-runtime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-derive" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-internal-macros" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base-x 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "stdweb-internal-runtime" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "stream-cipher" version = "0.3.0" @@ -2656,19 +2743,19 @@ version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-bip39" -version = "0.2.0" -source = "git+https://github.com/paritytech/substrate-bip39#a28806512c977992af8d6740d45352f5a1c832a0" +version = "0.2.1" +source = "git+https://github.com/paritytech/substrate-bip39#44307fda4ea17fe97aeb93af317fbc8f6ed34193" dependencies = [ "hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)", + "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2676,15 +2763,15 @@ dependencies = [ name = "substrate-client" version = "2.0.0" dependencies = [ - "derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.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.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hex-literal 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-api-macros 2.0.0", "sr-primitives 2.0.0", "sr-std 2.0.0", @@ -2726,16 +2813,18 @@ name = "substrate-consensus-common" version = "2.0.0" dependencies = [ "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", + "sr-std 2.0.0", "sr-version 2.0.0", "substrate-inherents 2.0.0", "substrate-primitives 2.0.0", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2743,12 +2832,12 @@ name = "substrate-executor" version = "2.0.0" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 2.0.0", "sr-version 2.0.0", "substrate-panic-handler 2.0.0", @@ -2757,7 +2846,7 @@ dependencies = [ "substrate-state-machine 2.0.0", "substrate-trie 2.0.0", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2776,7 +2865,7 @@ name = "substrate-inherents" version = "2.0.0" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-primitives 2.0.0", "sr-std 2.0.0", ] @@ -2804,7 +2893,7 @@ dependencies = [ name = "substrate-panic-handler" version = "2.0.0" dependencies = [ - "backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2817,29 +2906,30 @@ dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "sr-std 2.0.0", - "substrate-bip39 0.2.0 (git+https://github.com/paritytech/substrate-bip39)", - "tiny-bip39 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "twox-hash 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", + "substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)", + "tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "twox-hash 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "substrate-serializer" version = "2.0.0" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2849,8 +2939,9 @@ version = "2.0.0" dependencies = [ "hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-panic-handler 2.0.0", "substrate-primitives 2.0.0", "substrate-trie 2.0.0", @@ -2862,17 +2953,19 @@ dependencies = [ name = "substrate-telemetry" version = "2.0.0" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", "slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2895,35 +2988,30 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "subtle" -version = "2.0.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "syn" -version = "0.15.33" +version = "0.15.34" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "synstructure" -version = "0.10.1" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "take_mut" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "termcolor" version = "1.0.4" @@ -2937,9 +3025,9 @@ name = "termion" version = "1.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2956,14 +3044,14 @@ name = "time" version = "0.1.42" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tiny-bip39" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2988,31 +3076,32 @@ name = "tk-listen" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio" -version = "0.1.16" +version = "0.1.20" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-current-thread 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3023,17 +3112,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-current-thread" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3041,19 +3130,19 @@ name = "tokio-dns-unofficial" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-executor" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3061,9 +3150,9 @@ name = "tokio-fs" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3072,7 +3161,7 @@ version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3082,25 +3171,38 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-rustls" +version = "0.10.0-alpha.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-sync" -version = "0.1.3" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3109,38 +3211,46 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-threadpool" -version = "0.1.12" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "tokio-timer" -version = "0.2.10" +version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "tokio-trace-core" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3149,9 +3259,9 @@ version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3163,11 +3273,11 @@ version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", + "mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)", "mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3176,10 +3286,10 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.10" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3214,7 +3324,7 @@ dependencies = [ [[package]] name = "twox-hash" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3232,11 +3342,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "uint" -version = "0.6.1" +version = "0.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3259,7 +3369,7 @@ dependencies = [ [[package]] name = "unicode-segmentation" -version = "1.2.1" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -3296,11 +3406,6 @@ name = "utf8-ranges" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "vcpkg" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "version_check" version = "0.1.5" @@ -3313,85 +3418,97 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "wasm-bindgen-macro 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "bumpalo 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-futures" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-macro-support 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-macro-support 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-bindgen-webidl" -version = "0.2.42" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)", + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "weedle 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "wasm-timer" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "wasmi" -version = "0.4.3" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)", + "wasmi-validation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3405,20 +3522,38 @@ dependencies = [ [[package]] name = "web-sys" -version = "0.3.19" +version = "0.3.22" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", + "js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", - "wasm-bindgen-webidl 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "wasm-bindgen-webidl 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki" +version = "0.19.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)", + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "webpki-roots" +version = "0.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", + "webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "weedle" -version = "0.8.0" +version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3431,7 +3566,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.6" +version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3453,7 +3588,7 @@ name = "winapi-util" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3466,28 +3601,10 @@ name = "wincolor" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ws" -version = "0.7.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "ws2_32-sys" version = "0.2.1" @@ -3499,21 +3616,21 @@ dependencies = [ [[package]] name = "x25519-dalek" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "yamux" -version = "0.2.0" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", - "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", + "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3528,45 +3645,68 @@ name = "zeroize" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "zeroize" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "zeroize_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "zeroize_derive" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", + "synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [metadata] +"checksum adler32 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7e522997b529f05601e05166c07ed17789691f562762c7f3b987263d2dedee5c" "checksum aes-ctr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2e5b0458ea3beae0d1d8c0f3946564f8e10f90646cf78c06b4351052058d1ee" "checksum aes-soft 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cfd7e7ae3f9a1fb5c03b389fc6bb9a51400d0c13053f0dca698c832bfd893a0d" "checksum aesni 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f70a6b5f971e473091ab7cfb5ffac6cde81666c4556751d8d5620ead8abf100" -"checksum aho-corasick 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "81ce3d38065e618af2d7b77e10c5ad9a069859b4be3c2250f674af3840d9c8a5" +"checksum aho-corasick 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e6f484ae0c99fec2e858eb6134949117399f222608d84cadb3f58c1f97c2364c" "checksum aio-limited 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f10b352bc3fc08ae24dc5d2d3ddcac153678533986122dc283d747b12071000" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "92c7fb76bc8826a8b33b4ee5bb07a247a81e76764ab4d55e8f73e3a4d8808c71" "checksum asn1_der 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9893d63fc3b1c44231e667da6836a33f27d8b6b3bdc82f83da5dfd579d1b6528" "checksum asn1_der_derive 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9e7f92edafad155aff997fa5b727c6429b91e996b5a5d62a2b0adbae1306b5fe" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a6d640bee2da49f60a4068a7fae53acde8982514ab7bae8b8cea9e88cbcfd799" -"checksum backtrace 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "cd5a90e2b463010cd0e0ce9a11d4a9d5d58d9f41d4a6ba3dcaf9e68b466e88b4" +"checksum autocfg 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "0e49efa51329a5fd37e7c79db4621af617cd4e3e5bc224939808d076077077bf" +"checksum backtrace 0.3.26 (registry+https://github.com/rust-lang/crates.io-index)" = "1a13fc43f04daf08ab4f71e3d27e1fc27fc437d3e95ac0063a796d92fb40f39b" "checksum backtrace-sys 0.1.28 (registry+https://github.com/rust-lang/crates.io-index)" = "797c830ac25ccc92a7f8a7b9862bde440715531514594a6154e3d4a54dd769b6" -"checksum base-x 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d55aa264e822dbafa12db4d54767aff17c6ba55ea2d8559b3e17392c7d000e5d" "checksum base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" +"checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ebecac13b3c745150d7b6c3ea7572d372f09d627c2077e893bf26c5c7f70d282" "checksum bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "228047a76f468627ca71776ecdebd732a3423081fcf5125585bcd7c49886ce12" "checksum bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5da9b3d9f6f585199287a473f4f8dfab6566cf827d15c00c219f53c645687ead" "checksum blake2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "91721a6330935673395a0607df4d49a9cb90ae12d259f1b3e0a3f6e1d486872e" "checksum blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)" = "5d6d530bdd2d52966a6d03b7a964add7ae1a288d25214066fd4b600f0f796400" "checksum block-buffer 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1339a1042f5d9f295737ad4d9a6ab6bf81c84a933dba110b9200cd6d1448b814" -"checksum block-buffer 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49665c62e0e700857531fa5d3763e91b539ff1abeebd56808d378b495870d60d" +"checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-cipher-trait 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1c924d49bd09e7c06003acda26cd9742e796e34282ec6c1189404dee0c1f4774" -"checksum block-padding 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d75255892aeb580d3c566f213a2b6fdc1c66667839f45719ee1d30ebf2aea591" +"checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" "checksum bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0de79cfb98e7aa9988188784d8664b4b5dad6eaaa0863b91d9a4ed871d4f7a42" -"checksum bumpalo 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4639720be048090544634e0402490838995ccdc9d2fe648f528f30d3c33ae71f" +"checksum build_const 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "39092a32794787acd8525ee150305ff051b0aa6cc2abaf193924f5ab05425f39" +"checksum bumpalo 2.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "84dca3afd8e01b9526818b7963e5b4916063b3cdf9f10cf6b73ef0bd0ec37aa5" "checksum byte-tools 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "560c32574a12a89ecd91f5e742165893f86e3ab98d21f8ea548658eb9eef5f40" "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a019b10a2a7cdeb292db131fc8113e57ea2a908f6e7894b0c3c671893b65dbeb" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" "checksum c_linked_list 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4964518bd3b4a8190e832886cdc0da9794f12e8e6c1613a9e90ff331c4c8724b" -"checksum cc 1.0.30 (registry+https://github.com/rust-lang/crates.io-index)" = "d01c69d08ff207f231f07196e30f84c70f1c815b04f980f8b7b01ff01f05eb92" -"checksum cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "11d43355396e872eefb45ce6342e4374ed7bc2b3a502d1b28e36d6e23c05d1f4" +"checksum cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)" = "39f75544d7bbaf57560d2168f28fd649ff9c76153874db88bdbdfd839b1a7e7d" +"checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum crc 1.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d663548de7f5cca343f1e0a48d14dcfb0e9eb4e079ec58883b7251539fa10aeb" +"checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum crossbeam 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ad4c7ea749d9fb09e23c5cb17e3b70650860553a0e2744e38446b1803bf7db94" "checksum crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "0f0ed1a4de2235cabda8558ff5840bffb97fcb64c97827f354a451307df5f72b" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" @@ -3578,36 +3718,33 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f8306fcef4a7b563b76b7dd949ca48f52bc1141aa067d2ea09565f3e2652aa5c" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" -"checksum crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c240f247c278fa08a6d4820a6a222bfc6e0d999e51ba67be94f44c905b2161f2" +"checksum crunchy 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" "checksum crypto-mac 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "779015233ac67d65098614aec748ac1c756ab6677fa2e14cf8b37c08dfed1198" "checksum crypto-mac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" "checksum ctr 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "022cd691704491df67d25d006fe8eca083098253c4d43516c2206479c58c6736" "checksum cuckoofilter 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8dd43f7cfaffe0a386636a10baea2ee05cc50df3b77bea4a456c9572a939bf1f" -"checksum curve25519-dalek 1.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1f8a6fc0376eb52dc18af94915cc04dfdf8353746c0e8c550ae683a0815e5c1" +"checksum curve25519-dalek 1.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "750226d75fc2f5a8daec6e7477624e258674023eb73d8d647f63b943ca182a4a" "checksum data-encoding 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f4f47ca1860a761136924ddd2422ba77b2ea54fe8cc75b9040804a0d9d32ad97" -"checksum derive_more 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbe9f11be34f800b3ecaaed0ec9ec2e015d1d0ba0c8644c1310f73d6e8994615" +"checksum derive_more 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6d944ac6003ed268757ef1ee686753b57efc5fcf0ebe7b64c9fc81e7e32ff839" "checksum digest 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e5b29bf156f3f4b3c4f610a25ff69370616ae6e0657d416de22645483e72af0a" "checksum digest 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "05f47366984d3ad862010e22c7ce81a7dbcaebbdfb37241a620f8b6596ee135c" -"checksum discard 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "212d0f5754cb6769937f4501cc0e67f4f4483c8d2c3e1e922ee9edbe4ab4c7c0" "checksum dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d33be9473d06f75f58220f71f7a9317aca647dc061dbd3c361b0bef505fbea" "checksum ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81956bcf7ef761fb4e1d88de3fa181358a0d26cbcb9755b587a08f9119824b86" -"checksum either 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c67353c641dc847124ea1902d69bd753dee9bb3beff9aa3662ecf86c971d1fac" +"checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" "checksum elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "073be79b6538296faf81c631872676600616073817dd9a440c477ad09b408983" "checksum env_logger 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b61fa891024a945da30a9581546e8cfaf5602c7b3f4c137a2805cf388f92075a" "checksum environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c7464757b80de8930c91c9afe77ddce501826bf9d134a87db2c67d9dc177e2c" "checksum erased-serde 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3beee4bc16478a1b26f2e80ad819a52d24745e292f521a63c16eea5f74b7eb60" -"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" -"checksum fixed-hash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a557e80084b05c32b455963ff565a9de6f2866da023d6671705c6aff6f65e01c" +"checksum fixed-hash 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a683d1234507e4f3bf2736eeddf0de1dc65996dc0164d57eba0a74bcf29489" +"checksum flate2 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f87e68aa82b2de08a6e037f1385455759df6e445a8df5e005b4297191dbf18aa" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" -"checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" -"checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" "checksum fuchsia-cprng 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" "checksum fuchsia-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e9763c69ebaae630ba35f74888db465e49e259ba1bc0eda7d06f4a067615d82" "checksum fuchsia-zircon-sys 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "3dcaa9ae7725d12cdb85b3ad99a434db70b468c09ded17e012d86b5c1010f7a7" -"checksum futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)" = "49e7653e374fe0d0c12de4250f0bdb60680b8c80eed558c5c7538eec9c89e21b" +"checksum futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)" = "a2037ec1c6c1c4f79557762eab1f7eae1f64f6cb418ace90fae88f0942b60139" "checksum futures-cpupool 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ab90cde24b3319636588d0c35fe03b1333857621051837ed769faefb4c2162e4" "checksum gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)" = "8f5f3913fa0bfe7ee1fd8248b6b9f42a5af4b9d65ec2dd2c3c26132b950ecfc2" "checksum generic-array 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c0f28c2f5bfb5960175af447a2da7c18900693738343dc896ffbcabd9839592" @@ -3615,60 +3752,68 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum get_if_addrs 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "abddb55a898d32925f3148bd281174a68eeb68bbfd9a5938a57b18f506ee4ef7" "checksum get_if_addrs-sys 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d04f9fb746cf36b191c00f3ede8bde9c8e64f9f4b05ae2694a9ccf5e3f5ab48" "checksum hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fb417e5c470acdd61068c79767d0e65962e70836cf6c9dfd2409f06345ce0" -"checksum hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1224388a21c88a80ae7087a2a245ca6d80acc97a9186b75789fb3eeefd0609af" +"checksum hash256-std-hasher 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f8b2027c19ec91eb304999abae7307d225cf93be42af53b0039f76e98ed5af86" "checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da" "checksum hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8e04cb7a5051270ef3fa79f8c7604d581ecfa73d520e74f554e45541c4b5881a" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" -"checksum hex-literal 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "27455ce8b4a6666c87220e4b59c9a83995476bdadc10197905e61dbe906e36fa" -"checksum hex-literal-impl 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1d340b6514f232f6db1bd16db65302a5278a04fef9ce867cb932e7e5fa21130a" +"checksum hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc2928beef125e519d69ae1baa8c37ea2e0d3848545217f6db0179c5eb1d639" +"checksum hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "520870c3213943eb8d7803e80180d12a6c7ceb4ae74602544529d1643dc4ddda" "checksum hmac 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7a13f4163aa0c5ca1be584aace0e2212b2e41be5478218d4f657f5f778b2ae2a" "checksum hmac 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f127a908633569f208325f86f71255d3363c79721d7f9fe31cd5569908819771" "checksum hmac-drbg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe727d41d2eec0a6574d887914347e5ff96a3b87177817e2a9820c5c87fecc2" +"checksum http 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "eed324f0f0daf6ec10c474f150505af2c143f251722bf9dbd1261bd1f2ee2c1a" "checksum httparse 1.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e8734b0cfd3bc3e101ec59100e101c2eecd19282202e87808b3037b442777a83" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum impl-codec 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2050d823639fbeae26b2b5ba09aca8907793117324858070ade0673c49f793b" "checksum impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5158079de9d4158e0ce1de3ae0bd7be03904efc40b3d7dd8b8c301cbf6b52b56" +"checksum impl-serde 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d26be4b97d738552ea423f76c4f681012ff06c3fa36fa968656b3679f60b4a1" "checksum integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ea155abb3ba6f382a75f1418988c05fe82959ed9ce727de427f9cfd425b0c903" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" -"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" -"checksum js-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "3c994fd445b81741d77f6bcd227d6ed645b95b35a2ecfd2050767450ff1c0b6d" +"checksum ipnet 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e61c2da0d0f700c77d2d313dbf4f93e41d235fa12c6681fee06621036df4c2af" +"checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" +"checksum js-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "9987e7c13a91d9cf0efe59cca48a3a7a70e2b11695d5a4640f85ae71e28f5e73" "checksum keccak 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "67c21572b4949434e4fc1e1978b99c5f77064153c59d998bf13ecd96fb5ecba7" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" "checksum kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" -"checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)" = "aab692d7759f5cd8c859e169db98ae5b52c924add2af5fbbca11d12fefb567c1" -"checksum libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0231edab431064b30b7749484a39735eb36492cef4658c372c9059e58c3003aa" -"checksum libp2p-core 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d1a3bad2ed26297112847678683dd221473a0d44297250b61f004e1b35e72493" -"checksum libp2p-core-derive 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f765f103b680cbed910b02bfdbdcfce5b1142899c93e51acb960bf59b6f81b1" -"checksum libp2p-dns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b129d20cc8cbb6ce5da8361045649c024659173e246c5dfbf20ae06071c046a" -"checksum libp2p-floodsub 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "70d68816b8435d6788399416eb2f0a6974fb1d15c4be5c30141f87c8e81746df" -"checksum libp2p-identify 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "718ca645a065fd70855ca6042a7df686c24cd21add750c37a82c811fbd1e5c43" -"checksum libp2p-kad 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bbe27c623a6a720efd5d704347838972062f89149a9c3cd149748da60bdcd3e0" -"checksum libp2p-mdns 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9bc1a5d85f4812cae6367b49a432763fe28997bac7c530dc55b70ec18a78aa7" -"checksum libp2p-mplex 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fe5a858342a1cc89464474f7edc4bae1da649b9c823a3e04d9fb494493601746" -"checksum libp2p-noise 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc6b5185c50a52a12e7bbe2ee7799059e24de4e52ab25edbfd26c8ab8515d317" -"checksum libp2p-ping 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7905c1431ad115bee83405770629a27d6f17153ad02ec9670a7347998ef20e22" -"checksum libp2p-plaintext 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc17626763ded57da8fed73187c2d9f6ebb89d30838673c430315bf560c7e4db" -"checksum libp2p-ratelimit 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2409d08b809ab1a74269597f7da2829d117cc11b9ed3343af33fc20831619726" -"checksum libp2p-secio 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258cdc6742945c8f6402997bbbf36733588e2db18e5a0014da6d46e3ccfb92cf" -"checksum libp2p-tcp 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b5691e2ba2720d42bd1e93d6b90239fa9235c1956ef6a5f1dd499a7ae2767be" -"checksum libp2p-uds 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c9ab0b9ca050105fd94229c48911c0c84aef4d6b86a53d1b6df81d938354e47e" -"checksum libp2p-yamux 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5e6ff51a5b2056bacee1c9f2ed8455cdf3c5c619261ddb4efc783119130aaf52" +"checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880" +"checksum libp2p 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6abde4e6fc777dc06ae2a15202ddedb1a38d7c71ed16bc10fa704b03f73aec37" +"checksum libp2p-core 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b4ceb4791289534d4c1ad8e4bd3c6f06d3670efa55ce71482951a287df93ddd1" +"checksum libp2p-core-derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "851a59dcaab66c96777ae0cace96de88a700243c3b8360ab51c7e093f3727066" +"checksum libp2p-deflate 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "902b44e92e1f8b7e697b3a186d15c841e0e38037f14286513207a5407650a635" +"checksum libp2p-dns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71a6630a84552b39e5f752e1f6a951d31f3211079465d2e7af73491b6f48fc3f" +"checksum libp2p-floodsub 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9fced4da0c31e0dc8a759472c65fab41db40c01de2d93bc45e1431c13f0564f0" +"checksum libp2p-identify 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba5e882d72c71cdf77f45ab68dd715451d3b78a23085f8d385c7a31ec1b4272" +"checksum libp2p-kad 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d71966dbbb4cedcfcdb1d4c87d5dbb6f3f07b465d1ca74f2624256669997d1f2" +"checksum libp2p-mdns 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cdbdaea6f0049cc09ba5db00308f5b93105a8a33b65ba2e36bd35da707850ea2" +"checksum libp2p-mplex 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b351bfd67e97154e7b60f62402237671486c8a89f83eabdb6838f37d4d5f006" +"checksum libp2p-noise 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44324032b2f9260d2b862c741d79d250dc02298dbba56354a992528a826ee2d5" +"checksum libp2p-ping 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1ac43ffd01de4210cf1b969bbb55a008c77f9ec22b74df26a6590bb6bd4c93f" +"checksum libp2p-plaintext 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0506e10770bcbcb59f2a6154ce93c8fd5cb9730b6ceb5aa1463164af1fd0b9c6" +"checksum libp2p-ratelimit 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3886b79a35c0348497bab763517a9a2b4965173f4b4c7438d59f1e4dcf5122ff" +"checksum libp2p-secio 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b811272e5cd86d39bd71fb94687025d9802b13daf0998ebe0d3f2885c636c51a" +"checksum libp2p-tcp 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b2c54cb75f17557de6ce0149aa03e729455e2d240f84d854272bc4b11012a324" +"checksum libp2p-uds 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fbedf4a1e72a5f67523915414e9e12d71d128731873f0f24d8b878398fb47aa4" +"checksum libp2p-wasm-ext 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0c1f615b56aa2a6f4ec07bf9667be9fff8877b9c5bd5335601af47490eda341" +"checksum libp2p-websocket 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a0d1bfe60577558f48a9fdf9f35c0ee2dc5baa01f685ff847d3b5cf4f12ee135" +"checksum libp2p-yamux 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf4bfc7ff127cd622502dbe56f10513dd6776b970e33d8ebb6e367f0752324f6" "checksum libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "688e8d65e495567c2c35ea0001b26b9debf0b4ea11f8cccc954233b75fc3428a" "checksum lock_api 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "62ebf1391f6acad60e5c8b43706dde4582df75c06698ab44511d15016bc2442c" +"checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" "checksum log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c84ec4b527950aa83a329754b01dbe3f58361d1c5efacd1f6d68c494d08a17c6" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7623b01a4f1b7acb7cf8e3f678f05e15e6ae26cb0b738dfeb5cc186fd6b82ef4" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" -"checksum merlin 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "83c2dda19c01176e8e7148f7bdb88bbdf215a8db0641f89fc40e4b81736aeda5" -"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432" -"checksum mio-extras 2.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "46e73a04c2fa6250b8d802134d56d554a9ec2922bf977777c805ea5def61ce40" +"checksum merlin 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c39467de91b004f5b9c06fac5bbc8e7d28309a205ee66905166b70804a71fea" +"checksum miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9e3ae51cea1576ceba0dde3d484d30e6e5b86dee0b2d412fe3a16a15c98202" +"checksum miniz_oxide 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c468f2369f07d651a5d0bb2c9079f8488a66d5466efe42d0c5c6466edcb7f71e" +"checksum miniz_oxide_c_api 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b7fe927a42e3807ef71defb191dc87d4e24479b221e67015fe38ae2b7b447bab" +"checksum mio 0.6.19 (registry+https://github.com/rust-lang/crates.io-index)" = "83f51996a3ed004ef184e16818edc51fadffe8e7ca68be67f9dee67d84d0ff23" "checksum mio-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)" = "966257a94e196b11bb43aca423754d87429960a768de9414f3691d6957abf125" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" "checksum multistream-select 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f989d40aab0ed0d83c1cdb4856b5790e980b96548d1a921f280e985eb049f38d" @@ -3676,40 +3821,40 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9667ddcc6cc8a43afc9b7917599d7216aa09c463919ea32c59ed6cac8bc945" "checksum nohash-hasher 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0d138afcce92d219ccb6eb53d9b1e8a96ac0d633cfd3c53cd9856d96d1741bb8" "checksum nom 4.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2ad2a91a8e869eeb30b9cb3119ae87773a8f4ae617f41b1eb9c154b2905f7bd6" -"checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" -"checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" +"checksum num-integer 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "b85e541ef8255f6cf42bbfe4ef361305c6c135d10919ecc26126c4e5ae94bc09" +"checksum num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "6ba9a427cfca2be13aa6f6403b0b7e7368fe982bfa16fccc450ce74c46cd9b32" "checksum num_cpus 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a23f0ed30a54abaa0c7e83b1d2d87ada7c3c23078d1d87815af3e3b6385fbba" "checksum numtoa 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b8f8bdf33df195859076e54ab11ee78a1b208382d3a26ec40d142ffc1ecc49ef" "checksum once_cell 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "532c29a261168a45ce28948f9537ddd7a5dd272cc513b3017b1e82a88f962c37" "checksum opaque-debug 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "93f5bb2e8e8dec81642920ccff6b61f1eb94fa3020c5a325c9851ff604152409" -"checksum openssl 0.10.19 (registry+https://github.com/rust-lang/crates.io-index)" = "84321fb9004c3bce5611188a644d6171f895fa2889d155927d528782edb21c5d" -"checksum openssl-sys 0.9.42 (registry+https://github.com/rust-lang/crates.io-index)" = "cb534d752bf98cf363b473950659ac2546517f9c6be9723771614ab3f03bbc9e" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" "checksum parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)" = "" "checksum parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dcb43c05fb71c03b4ea7327bf15694da1e0f23f19d5b1e95bab6c6d74097e336" "checksum parity-codec-derive 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "00a486fd383382ddcb2de928364b1f82571c1e48274fc43b7667a4738ee4056c" -"checksum parity-multiaddr 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "18a130a727008cfcd1068a28439fe939897ccad28664422aeca65b384d6de6d0" -"checksum parity-multihash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e8eab0287ccde7821e337a124dc5a4f1d6e4c25d10cc91e3f9361615dd95076" +"checksum parity-multiaddr 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "045b3c7af871285146300da35b1932bb6e4639b66c7c98e85d06a32cbc4e8fa7" +"checksum parity-multihash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05d6a68e07ab34a9e87bd8dd4936f6bb5be21e4f6dbcdbaf04d8e854eba0af01" +"checksum parity-send-wrapper 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aa9777aa91b8ad9dd5aaa04a9b6bcb02c7f1deb952fca5a66034d5e63afc5c6f" "checksum parity-wasm 0.31.3 (registry+https://github.com/rust-lang/crates.io-index)" = "511379a8194230c2395d2f5fa627a5a7e108a9f976656ce723ae68fca4097bfc" "checksum parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4d05f1349491390b1730afba60bb20d55761bef489a954546b58b4b34e1e2ac" "checksum parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f0802bff09003b291ba756dc7e79313e51cc31667e94afbe847def490424cde5" "checksum parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ab41b4aed082705d1056416ae4468b6ea99d52599ecf3169b00088d43113e337" +"checksum parking_lot 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fa7767817701cce701d5585b9c4db3cdd02086398322c1d7e8bf5094a96a2ce7" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" "checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c" "checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9" -"checksum paste 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "f50392d1265092fbee9273414cc40eb6d47d307bd66222c477bb8450c8504f9d" -"checksum paste-impl 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "a3cd512fe3a55e8933b2dcad913e365639db86d512e4004c3084b86864d9467a" +"checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" +"checksum paste 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "1f4a4a1c555c6505821f9d58b8779d0f630a6b7e4e1be24ba718610acf01fa79" +"checksum paste-impl 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "26e796e623b8b257215f27e6c80a5478856cae305f5b59810ff9acdaa34570e6" "checksum pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" -"checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" -"checksum primitive-types 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "edb92f1ebfc177432c03287b15d48c202e6e2c95993a7af3ba039abb43b1492e" -"checksum proc-macro-crate 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4c6cf4e5b00300d151dfffae39f529dfa5188f42eeb14201229aa420d6aad10c" +"checksum primitive-types 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6e8612a8dc70f26276fed6131c153ca277cf275ee0a5e2a50cd8a69c697beb8f" +"checksum proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e10d4b51f154c8a7fb96fd6dad097cb74b863943ec010ac94b9fd1be8861fe1e" "checksum proc-macro-hack 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2c725b36c99df7af7bf9324e9c999b9e37d92c8f8caf106d82e1d7953218d2d8" -"checksum proc-macro-hack 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3e90aa19cd73dedc2d0e1e8407473f073d735fef0ab521438de6da8ee449ab66" +"checksum proc-macro-hack 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0c1dd4172a1e1f96f709341418f49b11ea6c2d95d53dca08c0f74cbd332d9cf3" "checksum proc-macro-hack-impl 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2b753ad9ed99dd8efeaa7d2fb8453c8f6bc3e54b97966d35f1bc77ca6865254a" -"checksum proc-macro2 0.4.27 (registry+https://github.com/rust-lang/crates.io-index)" = "4d317f9caece796be1980837fd5cb3dfec5613ebdb04ad0956deea83ce168915" -"checksum protobuf 2.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "24d5d73d2b88fddb8b8141f2730d950d88772c940ac4f8f3e93230b9a99d92df" +"checksum proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)" = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759" +"checksum protobuf 2.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a151c11a92df0059d6ab446fafa3b21a1210aad4bc2293e1c946e8132b10db01" "checksum pwasm-utils 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "efb0dcbddbb600f47a7098d33762a00552c671992171637f5bb310b37fe1f0e4" "checksum quick-error 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5fb6ccf8db7bbcb9c2eae558db5ab4f3da1c2a87e4e597ed394726bc8ea6ca1d" "checksum quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9274b940887ce9addde99c4eee6b5c44cc494b182b97e73dc8ffdcb3397fd3f0" @@ -3723,123 +3868,125 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum rand_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d0e7a549d590831370895ab7ba4ea0c1b6b011d106b5ff2da6eee112615e6dc0" "checksum rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" "checksum rand_isaac 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -"checksum rand_jitter 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b9ea758282efe12823e0d952ddb269d2e1897227e464919a554f2a03ef1b832" +"checksum rand_jitter 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" "checksum rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7b75f676a1e053fc562eafbb47838d67c84801e38fc1ba459e8f180deabd5071" "checksum rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" "checksum rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" "checksum rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "373814f27745b2686b350dd261bfd24576a6fb0e2c5919b3a2b6005f820b0473" "checksum rayon-core 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b055d1e92aba6877574d8fe604a63c8b5df60f60e5982bf7ccbb1338ea527356" "checksum rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -"checksum redox_syscall 0.1.51 (registry+https://github.com/rust-lang/crates.io-index)" = "423e376fffca3dfa06c9e9790a9ccd282fafb3cc6e6397d01dbf64f9bacc6b85" +"checksum redox_syscall 0.1.54 (registry+https://github.com/rust-lang/crates.io-index)" = "12229c14a0f65c4f1cb046a3b52047cdd9da1f4b30f8a39c5063c8bae515e252" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" -"checksum regex 1.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53ee8cfdddb2e0291adfb9f13d31d3bbe0a03c9a402c01b1e24188d86c35b24f" -"checksum regex-syntax 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "8c2f35eedad5295fdf00a63d7d4b238135723f92b434ec06774dad15c7ab0861" +"checksum regex 1.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "8f0a0bcab2fd7d1d7c54fa9eae6f43eddeb9ce2e7352f8518a814a4f65d60c58" +"checksum regex-syntax 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)" = "dcfd8681eebe297b81d98498869d4aae052137651ad7b96822f09ceb690d0a96" "checksum ring 0.14.6 (registry+https://github.com/rust-lang/crates.io-index)" = "426bc186e3e95cac1e4a4be125a4aca7e84c2d616ffc02244eef36e2a60a093c" -"checksum rustc-demangle 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "adacaae16d02b6ec37fdc7acfcddf365978de76d1983d3ee22afc260e1ca9619" +"checksum rustc-demangle 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a7f4dccf6f4891ebcc0c39f9b6eb1a83b9bf5d747cb439ec6fba4f3b977038af" "checksum rustc-hex 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "403bb3a286107a04825a5f82e1270acc1e14028d3d554d7a1e08914549575ab8" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" -"checksum rw-stream-sink 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d548a40fe17c3a77d54b82457b79fcc9b8a288d509ca20fbf5aa1dac386d22d6" -"checksum ryu 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "eb9e9b8cde282a9fe6a42dd4681319bfb63f121b8a8ee9439c6f4107e58a46f7" +"checksum rustls 0.15.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f271e3552cd835fa28c541c34a7e8fdd8cdff09d77fe4eb8f6c42e87a11b096e" +"checksum rw-stream-sink 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f9cbe61c20455d3015b2bb7be39e1872310283b8e5a52f5b242b0ac7581fe78" +"checksum ryu 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "b96a9549dc8d48f2c283938303c4b5a77aa29bfbc5b54b084fb1630408899a8f" "checksum safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f7bf422d23a88c16d5090d455f182bc99c60af4df6a345c63428acf5129e347" -"checksum schnorrkel 0.0.0 (git+https://github.com/w3f/schnorrkel)" = "" -"checksum schnorrkel 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a700659388785588c75b197cecda0f23c7112a9281ef703e8ffc651061ce014c" +"checksum schnorrkel 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b5eff518f9bed3d803a0d002af0ab96339b0ebbedde3bec98a684986134b7a39" "checksum scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "94258f53601af11e6a49f722422f6e3425c52b06245a5cf9bc09908b174f5e27" -"checksum secp256k1 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4070f3906e65249228094cf97b04a90799fba04468190bbbcfa812309cf86e32" +"checksum scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b42e15e59b18a828bbf5c58ea01debb36b9b096346de35d941dcb89009f24a0d" +"checksum sct 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2f5adf8fbd58e1b1b52699dc8bed2630faecb6d8c7bee77d009d6bbe4af569b9" "checksum semver 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum send_wrapper 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a0eddf2e8f50ced781f288c19f18621fa72a3779e3cb58dbf23b07469b0abeb4" -"checksum serde 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "92514fb95f900c9b5126e32d020f5c6d40564c27a5ea6d1d7d9f157a96623560" -"checksum serde_derive 1.0.89 (registry+https://github.com/rust-lang/crates.io-index)" = "bb6eabf4b5914e88e24eea240bb7c9f9a2cbc1bbbe8d961d381975ec3c6b806c" +"checksum serde 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "a72e9b96fa45ce22a4bc23da3858dfccfd60acd28a25bcd328a98fdd6bea43fd" +"checksum serde_derive 1.0.91 (registry+https://github.com/rust-lang/crates.io-index)" = "101b495b109a3e3ca8c4cbe44cf62391527cdfb6ba15821c5ce80bcd5ea23f9f" "checksum serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)" = "5a23aa71d4a4d43fdbfaac00eff68ba8a06a51759a89ac3304323e800c4dd40d" +"checksum sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "23962131a91661d643c98940b20fcaffe62d776a823247be80a48fcb8b6fce68" "checksum sha1 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2579985fda508104f7587689507983eadd6a6e84dd35d6d115361f530916fa0d" "checksum sha2 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d963c78ce367df26d7ea8b8cc655c651b42e8a1e584e869c1e17dae3ccb116a" "checksum sha2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7b4d8bfd0e469f417657573d8451fb33d16cfe0989359b93baf3a1ffc639543d" -"checksum sha3 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "34a5e54083ce2b934bf059fdf38e7330a154177e029ab6c4e18638f2f624053a" +"checksum sha3 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd26bc0e7a2e3a7c959bc494caf58b72ee0c71d67704e9520f736ca7e4853ecf" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum slog 2.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1e1a2eec401952cd7b12a84ea120e2d57281329940c3f93c2bf04f462539508e" -"checksum slog-async 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e544d16c6b230d84c866662fe55e31aacfca6ae71e6fc49ae9a311cb379bfc2f" "checksum slog-json 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc0d2aff1f8f325ef660d9a0eb6e6dcd20b30b3f581a5897f58bf42d061c37a" "checksum slog-scope 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "60c04b4726fa04595ccf2c2dad7bcd15474242c4c5e109a8a376e8a2c9b1539a" "checksum smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)" = "c4488ae950c49d403731982257768f48fada354a5203fe81f9bb6f43ca9002be" "checksum snow 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5a64f02fd208ef15bd2d1a65861df4707e416151e1272d02c8faafad1c138100" +"checksum soketto 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8cf3ae22c0bce5437c7dce6a2b00e492c19da1feb21ad64a7b6fd7058438c3f2" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum spin 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "44363f6f51401c34e7be73db0db371c04705d35efbe9f7d6082e03a921a32c55" "checksum stable_deref_trait 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dba1a27d3efae4351c8051072d619e3ade2820635c3958d826bfea39d59b54c8" "checksum static_assertions 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c19be23126415861cb3a23e501d34a708f7f9b2183c5252d690941c2e69199d5" "checksum static_slice 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "92a7e0c5e3dfb52e8fbe0e63a1b947bbb17b4036408b151353c4491374931362" -"checksum stdweb 0.4.15 (registry+https://github.com/rust-lang/crates.io-index)" = "a3edad410e603184d656e2abded5fd4d3d6e93d5763d21130dbaf99795db74eb" -"checksum stdweb-derive 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e21ebd9179de08f2300a65454268a17ea3de204627458588c84319c4def3930" -"checksum stdweb-internal-macros 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "1635afd059cbfac7d5b1274f0c44cec110c1e013c48e8bbc22e07e52696cf887" -"checksum stdweb-internal-runtime 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a2a2f4a2eb556337b2d1a302630bbddf989ae383c70393e89b48152b9896cbda" "checksum stream-cipher 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8861bc80f649f5b4c9bd38b696ae9af74499d479dbfb327f0607de6b326a36bc" "checksum strum 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1810e25f576e7ffce1ff5243b37066da5ded0310b3274c20baaeccb1145b2806" "checksum strum_macros 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)" = "572a2f4e53dd4c3483fd79e5cc10ddd773a3acb1169bbfe8762365e107110579" -"checksum substrate-bip39 0.2.0 (git+https://github.com/paritytech/substrate-bip39)" = "" +"checksum substrate-bip39 0.2.1 (git+https://github.com/paritytech/substrate-bip39)" = "" "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" -"checksum subtle 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "702662512f3ddeb74a64ce2fbbf3707ee1b6bb663d28bb054e0779bbc720d926" -"checksum syn 0.15.33 (registry+https://github.com/rust-lang/crates.io-index)" = "ec52cd796e5f01d0067225a5392e70084acc4c0013fa71d55166d38a8b307836" -"checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" -"checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" +"checksum subtle 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "01dca13cf6c3b179864ab3292bd794e757618d35a7766b7c46050c614ba00829" +"checksum syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)" = "a1393e4a97a19c01e900df2aec855a29f71cf02c402e2f443b8d2747c25c5dbe" +"checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum termcolor 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4096add70612622289f2fdcdbd5086dc81c1e2675e6ae58d6c4f62a16c6d7f2f" "checksum termion 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dde0593aeb8d47accea5392b39350015b5eccb12c0d98044d856983d89548dea" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" -"checksum tiny-bip39 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f5388a470627f97a01a6e13389ced797a42b1611f9de7e0f6ca705675ac55297" +"checksum tiny-bip39 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c1c5676413eaeb1ea35300a0224416f57abc3bd251657e0fafc12c47ff98c060" "checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" "checksum tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5462b0f968c0457efe38fcd2df7e487096b992419e4f5337b06775a614bbda4b" -"checksum tokio 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "fcaabb3cec70485d0df6e9454fe514393ad1c4070dee8915f11041e95630b230" +"checksum tokio 0.1.20 (registry+https://github.com/rust-lang/crates.io-index)" = "94a1f9396aec29d31bb16c24d155cfa144d1af91c40740125db3131bdaf76da8" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" -"checksum tokio-current-thread 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c756b04680eea21902a46fca4e9f410a2332c04995af590e07ff262e2193a9a3" +"checksum tokio-current-thread 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "d16217cad7f1b840c5a97dfb3c43b0c871fef423a6e8d2118c604e843662a443" "checksum tokio-dns-unofficial 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "82c65483db54eb91b4ef3a9389a3364558590faf30ce473141707c0e16fda975" -"checksum tokio-executor 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30c6dbf2d1ad1de300b393910e8a3aa272b724a400b6531da03eed99e329fbf0" +"checksum tokio-executor 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "83ea44c6c0773cc034771693711c35c677b4b5a4b21b9e7071704c54de7d555e" "checksum tokio-fs 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "3fe6dc22b08d6993916647d108a1a7d15b9cd29c4f4496c62b92c45b5041b7af" "checksum tokio-io 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "5090db468dad16e1a7a54c8c67280c5e4b544f3d3e018f0b913b400261f85926" "checksum tokio-reactor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6af16bfac7e112bea8b0442542161bfc41cbfa4466b580bdda7d18cb88b911ce" -"checksum tokio-sync 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1bf2b9dac2a0509b5cfd1df5aa25eafacb616a42a491a13604d6bbeab4486363" +"checksum tokio-rustls 0.10.0-alpha.3 (registry+https://github.com/rust-lang/crates.io-index)" = "316fdbc899efec48b3b492bd0f339e6d81c4ee96a409257572147ec341943452" +"checksum tokio-sync 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "5b2f843ffdf8d6e1f90bddd48da43f99ab071660cd92b7ec560ef3cdfd7a409a" "checksum tokio-tcp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1d14b10654be682ac43efee27401d792507e30fd8d26389e1da3b185de2e4119" -"checksum tokio-threadpool 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "742e511f6ce2298aeb86fc9ea0d8df81c2388c6ebae3dc8a7316e8c9df0df801" -"checksum tokio-timer 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "2910970404ba6fa78c5539126a9ae2045d62e3713041e447f695f41405a120c6" +"checksum tokio-threadpool 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "72558af20be886ea124595ea0f806dd5703b8958e4705429dd58b3d8231f72f2" +"checksum tokio-timer 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "f2106812d500ed25a4f38235b9cae8f78a09edf43203e16e59c3b769a342a60e" +"checksum tokio-trace-core 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "350c9edade9830dc185ae48ba45667a445ab59f6167ef6d0254ec9d2430d9dd3" "checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92" "checksum tokio-uds 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "037ffc3ba0e12a0ab4aca92e5234e0dedeb48fddf6ccd260f1f150a36a9f2445" -"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" +"checksum toml 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b8c96d7873fa7ef8bdeb3a9cda3ac48389b4154f32b9803b4bc26220b677b039" "checksum trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba73747fd3a64ab531274c04cb588dfa9d30d972d62990831e63fbce2cfec59" "checksum trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfa2e20c4f1418ac2e71ddc418e35e1b56e34022e2146209ffdbf1b2de8b1bd9" "checksum twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d261e83e727c8e2dbb75dacac67c36e35db36a958ee504f2164fc052434e1" -"checksum twox-hash 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "09871da9f15424236082e0b220fd404a4eb6bebc7205c67653701229234ac64c" +"checksum twox-hash 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "6c7bcecad121018bdcd6b709fa2325b004878fcb3d3067934ce90749f0faff9a" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" -"checksum uint 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e7780bb27fd8a22295e0d9d53ae3be253f715a0dccb1808527f478f1c2603708" +"checksum uint 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2143cded94692b156c356508d92888acc824db5bffc0b4089732264c6fcf86d4" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" -"checksum unicode-segmentation 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aa6024fc12ddfd1c6dbc14a80fa2324d4568849869b779f6bd37e5e4c03344d1" +"checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unsigned-varint 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2c64cdf40b4a9645534a943668681bcb219faf51874d4b65d2e0abda1b10a2ab" "checksum untrusted 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "55cd1f4b4e96b46aeb8d4855db4a7a9bd96eeeb5c6a1ab54593328761642ce2f" "checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" -"checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" -"checksum wasm-bindgen 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "ffde3534e5fa6fd936e3260cd62cd644b8656320e369388f9303c955895e35d4" -"checksum wasm-bindgen-backend 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "40c0543374a7ae881cdc5d32d19de28d1d1929e92263ffa7e31712cc2d53f9f1" -"checksum wasm-bindgen-futures 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "0ad171fc1f6e43f97d155d27f4ee5657bd8aa5cce7c497ef3a0a0c5b44618b2d" -"checksum wasm-bindgen-macro 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "f914c94c2c5f4c9364510ca2429e59c92157ec89429243bcc245e983db990a71" -"checksum wasm-bindgen-macro-support 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "9168c413491e4233db7b6884f09a43beb00c14d11d947ffd165242daa48a2385" -"checksum wasm-bindgen-shared 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "326c32126e1a157b6ced7400061a84ac5b11182b2cda6edad7314eb3ae9ac9fe" -"checksum wasm-bindgen-webidl 0.2.42 (registry+https://github.com/rust-lang/crates.io-index)" = "613dbf4d7d3bf10aeb212b35de14a8ef07222c26526d4f931061a83fc9e2a851" -"checksum wasmi 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "21ef487a11df1ed468cf613c78798c26282da5c30e9d49f824872d4c77b47d1d" +"checksum wasm-bindgen 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "b7ccc7b93cfd13e26700a9e2e41e6305f1951b87e166599069f77d10358100e6" +"checksum wasm-bindgen-backend 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "1953f91b1608eb1522513623c7739f047bb0fed4128ce51a93f08e12cc314645" +"checksum wasm-bindgen-futures 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "fa1af11c73eca3dc8c51c76ea475a4416e912da6402064a49fc6c0214701866d" +"checksum wasm-bindgen-macro 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "0f69da5696545d7ca6607a2e4b1a0edf5a6b36b2c49dbb0f1df6ad1d92884047" +"checksum wasm-bindgen-macro-support 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d4246f3bc73223bbb846f4f2430a60725826a96c9389adf715ed1d5af46dec6" +"checksum wasm-bindgen-shared 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "c08381e07e7a79e5e229ad7c60d15833d19033542cc5dd91d085df59d235f4a6" +"checksum wasm-bindgen-webidl 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "1f42ff7adb8102bf5ad8adbc45b1635c520c8175f9fdf6eb2c54479d485d435a" +"checksum wasm-timer 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad9ac33c834103916e373d648adf65f58c83fb3d8a0f3e6b9a64bca7253a4dca" +"checksum wasmi 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)" = "aebbaef470840d157a5c47c8c49f024da7b1b80e90ff729ca982b2b80447e78b" "checksum wasmi-validation 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab380192444b3e8522ae79c0a1976e42a82920916ccdfbce3def89f456ea33f3" -"checksum web-sys 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "24129e4be2281109b3e15a328d3d7f233ee232a5405f75ba1e9bb59a25ebc4d4" -"checksum weedle 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "26a4c67f132386d965390b8a734d5d10adbcd30eb5cc74bd9229af8b83f10044" +"checksum web-sys 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)" = "540b8259eb242ff3a566fa0140bda03a4ece4e5c226e1284b5c95dddcd4341f6" +"checksum webpki 0.19.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4f7e1cd7900a3a6b65a3e8780c51a3e6b59c0e2c55c6dc69578c288d69f7d082" +"checksum webpki-roots 0.16.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c10fa4212003ba19a564f25cd8ab572c6791f99a03cc219c13ed35ccab00de0e" +"checksum weedle 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bcc44aa200daee8b1f3a004beaf16554369746f1b4486f0cf93b0caf8a3c2d1e" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "92c1eb33641e276cfa214a0522acad57be5c56b10cb348b3c5117db75f3ac4b0" +"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-util 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7168bab6e1daee33b4557efd0e95d5ca70a03706d39fa5f3fe7a236f584b03c9" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" -"checksum ws 0.7.9 (registry+https://github.com/rust-lang/crates.io-index)" = "329d3e6dd450a9c5c73024e1047f0be7e24121a68484eb0b5368977bee3cf8c3" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" -"checksum x25519-dalek 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4aca1ba6bec2719576bd20dfe5b24d9359552e616d10bff257e50cd85f745d17" -"checksum yamux 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ae9073f5dbc901abb0b2ec4f866e726fed2f54953bdf81f8a5fde7762b7cc3b3" +"checksum x25519-dalek 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7ee1585dc1484373cbc1cee7aafda26634665cf449436fd6e24bfd1fad230538" +"checksum yamux 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "01bd67889938c48f0049fc60a77341039e6c3eaf16cb7693e6ead7c0ba701295" "checksum zeroize 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8ddfeb6eee2fb3b262ef6e0898a52b7563bb8e0d5955a313b3cf2f808246ea14" +"checksum zeroize 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b60a6c572b91d8ecb0a460950d84fe5b40699edd07d65f73789b31237afc8f66" +"checksum zeroize_derive 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9dac4b660d969bff9c3fe1847a891cacaa8b21dd5f2aae6e0a3e0975aea96431" diff --git a/node/runtime/wasm/build.sh b/node/runtime/wasm/build.sh index f0b7c961bda7b9253fb8054ba01059afa1c04e9c..4a81e47f9ee843943de032c4177c8b693f6e92d5 100755 --- a/node/runtime/wasm/build.sh +++ b/node/runtime/wasm/build.sh @@ -6,7 +6,7 @@ if cargo --version | grep -q "nightly"; then else CARGO_CMD="cargo +nightly" fi -CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release +CARGO_INCREMENTAL=0 RUSTFLAGS="-C link-arg=--export-table" $CARGO_CMD build --target=wasm32-unknown-unknown --release "$@" for i in node_runtime do wasm-gc target/wasm32-unknown-unknown/release/$i.wasm target/wasm32-unknown-unknown/release/$i.compact.wasm diff --git a/node/src/main.rs b/node/src/main.rs index 5ff0d7ff3b0e68fae90eca12154bd1409d866d80..15b603e7a2706abe220785213169ea02273520f6 100644 --- a/node/src/main.rs +++ b/node/src/main.rs @@ -43,9 +43,7 @@ impl cli::IntoExit for Exit { } } -error_chain::quick_main!(run); - -fn run() -> cli::error::Result<()> { +fn main() { let version = VersionInfo { name: "Substrate Node", commit: env!("VERGEN_SHA_SHORT"), @@ -55,5 +53,9 @@ fn run() -> cli::error::Result<()> { description: "Generic substrate node", support_url: "https://github.com/paritytech/substrate/issues/new", }; - cli::run(::std::env::args(), Exit, version) + + if let Err(e) = cli::run(::std::env::args(), Exit, version) { + eprintln!("Error starting the node: {}\n\n{:?}", e, e); + std::process::exit(1) + } } diff --git a/scripts/build.sh b/scripts/build.sh index 46bc74b7a94f6bd2159c8dee3fcd40f72e935eef..d79ebe52301e5e0d764eff3203a0feda2b09c771 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -19,7 +19,7 @@ do echo "*** Building wasm binaries in $SRC" cd "$PROJECT_ROOT/$SRC" - ./build.sh + ./build.sh "$@" cd - >> /dev/null done diff --git a/scripts/docker/Dockerfile b/scripts/docker/Dockerfile index 4afa0101fce3c88a9d5a8efd80cc408133b4bfa5..2bdf49e2fcec22240420837b001018bdb9ffe79d 100644 --- a/scripts/docker/Dockerfile +++ b/scripts/docker/Dockerfile @@ -8,7 +8,7 @@ LABEL io.parity.image.authors="devops-team@parity.io" \ io.parity.image.vendor="Parity Technologies" \ io.parity.image.title="parity/substrate" \ io.parity.image.description="Substrate: The platform for blockchain innovators." \ - io.parity.image.source="https://github.com/paritytech/substrate/blob/master/scripts/docker/Dockerfile" \ + io.parity.image.source="https://github.com/paritytech/substrate/blob/${VCS_REF}/scripts/docker/Dockerfile" \ io.parity.image.revision="${VCS_REF}" \ io.parity.image.created="${BUILD_DATE}" \ io.parity.image.documentation="https://wiki.parity.io/Parity-Substrate" diff --git a/scripts/flamingfir-deploy.sh b/scripts/flamingfir-deploy.sh new file mode 100755 index 0000000000000000000000000000000000000000..13be56dfbd2f5bb77143ee2df1a71cb55819d30b --- /dev/null +++ b/scripts/flamingfir-deploy.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +RETRY_COUNT=10 +RETRY_ATTEMPT=0 +SLEEP_TIME=15 +TARGET_HOST="$1" +COMMIT=$(cat artifacts/VERSION) +DOWNLOAD_URL="https://releases.parity.io/substrate/x86_64-debian:stretch/${COMMIT}/substrate" +POST_DATA='{"extra_vars":{"artifact_path":"'${DOWNLOAD_URL}'","target_host":"'${TARGET_HOST}'"}}' + +JOB_ID=$(wget -O - --header "Authorization: Bearer ${AWX_TOKEN}" --header "Content-type: application/json" --post-data "${POST_DATA}" https://ansible-awx.parity.io/api/v2/job_templates/32/launch/ | jq .job) + +echo "Launched job: $JOB_ID" + + +while [ ${RETRY_ATTEMPT} -le ${RETRY_COUNT} ] ; do + export RETRY_RESULT=$(wget -O - --header "Authorization: Bearer ${AWX_TOKEN}" https://ansible-awx.parity.io/api/v2/jobs/${JOB_ID}/ | jq .status) + RETRY_ATTEMPT=$(( $RETRY_ATTEMPT +1 )) + sleep $SLEEP_TIME + if [ $(echo $RETRY_RESULT | egrep -e successful -e failed) ] ; then + break + fi +done + +AWX_OUTPUT=$(wget -O - --header "Authorization: Bearer ${AWX_TOKEN}" https://ansible-awx.parity.io/api/v2/jobs/${JOB_ID}/stdout?format=txt_download) + +echo "AWX job log:" +echo "${AWX_OUTPUT}" + + +JOB_STATUS=$(wget -O - --header "Authorization: Bearer ${AWX_TOKEN}" https://ansible-awx.parity.io/api/v2/jobs/${JOB_ID}/ | jq .status ) + +echo "===================================" +echo -e "Ansible AWX Remote Job: ${JOB_ID} \x1B[31mStatus: ${JOB_STATUS}\x1B[0m" +echo "===================================" diff --git a/scripts/gitlab/check_line_width.sh b/scripts/gitlab/check_line_width.sh index ad78b24e1157fd1f031dd8b272036c504901d039..f382d630b183c6396115cc1e76e77dfab4c20047 100755 --- a/scripts/gitlab/check_line_width.sh +++ b/scripts/gitlab/check_line_width.sh @@ -11,7 +11,10 @@ GOOD_LINE_WIDTH="101" git diff --name-only ${BASE_BRANCH}...${CI_COMMIT_SHA} \*.rs | ( while read file do - if git diff ${BASE_BRANCH}...${CI_COMMIT_SHA} ${file} | grep -q "^+.\{${LINE_WIDTH}\}" + if [ ! -f ${file} ]; + then + echo "Skipping removed file." + elif git diff ${BASE_BRANCH}...${CI_COMMIT_SHA} ${file} | grep -q "^+.\{${LINE_WIDTH}\}" then if [ -z "${FAIL}" ] then diff --git a/scripts/update-deps.sh b/scripts/update-deps.sh new file mode 100755 index 0000000000000000000000000000000000000000..cd6b7c853825ed42a0b55d32018b81207a3d1642 --- /dev/null +++ b/scripts/update-deps.sh @@ -0,0 +1,9 @@ +#!/bin/sh -- +set -eu +case $0 in + (/*) dir=${0%/*}/;; + (*/*) dir=./${0%/*};; + (*) dir=.;; +esac + +find "$dir/.." -name Cargo.lock -execdir cargo update \; diff --git a/scripts/update.sh b/scripts/update.sh index cbf81b57cd5c6c255189fc7b541b43ffb3ca8316..a264fab43df306a2384aa15ae8e3a41faf7e33b0 100755 --- a/scripts/update.sh +++ b/scripts/update.sh @@ -20,7 +20,7 @@ do cd "$PROJECT_ROOT/$SRC" cargo update - ./build.sh + ./build.sh "$@" cd - >> /dev/null done diff --git a/srml/aura/Cargo.toml b/srml/aura/Cargo.toml index 6a437ce71acaedc41173fa4eafdc7ef94cea2c2f..82027871b4bb4c55a44219bfe79695d64d980a37 100644 --- a/srml/aura/Cargo.toml +++ b/srml/aura/Cargo.toml @@ -18,7 +18,7 @@ session = { package = "srml-session", path = "../session", default-features = fa [dev-dependencies] lazy_static = "1.0" -parking_lot = "0.7.1" +parking_lot = "0.8.0" substrate-primitives = { path = "../../core/primitives" } runtime_io = { package = "sr-io", path = "../../core/sr-io" } consensus = { package = "srml-consensus", path = "../consensus" } diff --git a/srml/aura/src/lib.rs b/srml/aura/src/lib.rs index e5eb3674cdf6b2e09783cbe97c3ad3c6c7551b3b..597618c1428a7b3ddb2cb8f850d1f75107b77ea0 100644 --- a/srml/aura/src/lib.rs +++ b/srml/aura/src/lib.rs @@ -51,16 +51,19 @@ pub use timestamp; use rstd::{result, prelude::*}; +use parity_codec::{Encode, Decode}; use srml_support::storage::StorageValue; use srml_support::{decl_storage, decl_module}; -use primitives::traits::{As, Zero}; +use primitives::traits::{SaturatedConversion, Saturating, Zero, One}; use timestamp::OnTimestampSet; +use rstd::marker::PhantomData; #[cfg(feature = "std")] use timestamp::TimestampInherentData; -use parity_codec::{Encode, Decode}; use inherents::{RuntimeString, InherentIdentifier, InherentData, ProvideInherent, MakeFatalError}; #[cfg(feature = "std")] use inherents::{InherentDataProviders, ProvideInherentData}; +#[cfg(feature = "std")] +use serde::Serialize; mod mock; mod tests; @@ -90,6 +93,20 @@ impl AuraInherentData for InherentData { } } +/// Logs in this module. +pub type Log = RawLog; + +/// Logs in this module. +/// +/// The type parameter distinguishes logs belonging to two different runtimes, +/// which should not be mixed. +#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[derive(Encode, Decode, PartialEq, Eq, Clone)] +pub enum RawLog { + /// AuRa inherent digests + PreRuntime([u8; 4], Vec, PhantomData), +} + /// Provides the slot duration inherent data for `Aura`. #[cfg(feature = "std")] pub struct InherentDataProvider { @@ -154,7 +171,7 @@ pub trait Trait: timestamp::Trait { decl_storage! { trait Store for Module as Aura { /// The last timestamp. - LastTimestamp get(last) build(|_| T::Moment::sa(0)): T::Moment; + LastTimestamp get(last) build(|_| 0.into()): T::Moment; } } @@ -163,7 +180,7 @@ decl_module! { } /// A report of skipped authorities in Aura. -#[derive(Clone, Encode, Decode, PartialEq, Eq)] +#[derive(Clone, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(Debug))] pub struct AuraReport { // The first skipped slot. @@ -192,43 +209,41 @@ impl AuraReport { impl Module { /// Determine the Aura slot-duration based on the Timestamp module configuration. - pub fn slot_duration() -> u64 { + pub fn slot_duration() -> T::Moment { // we double the minimum block-period so each author can always propose within // the majority of its slot. - >::minimum_period().as_().saturating_mul(2) + >::minimum_period().saturating_mul(2.into()) } fn on_timestamp_set(now: T::Moment, slot_duration: T::Moment) { let last = Self::last(); ::LastTimestamp::put(now.clone()); - if last == T::Moment::zero() { + if last.is_zero() { return; } - assert!(slot_duration > T::Moment::zero(), "Aura slot duration cannot be zero."); + assert!(!slot_duration.is_zero(), "Aura slot duration cannot be zero."); let last_slot = last / slot_duration.clone(); - let first_skipped = last_slot.clone() + T::Moment::sa(1); + let first_skipped = last_slot.clone() + One::one(); let cur_slot = now / slot_duration; assert!(last_slot < cur_slot, "Only one block may be authored per slot."); if cur_slot == first_skipped { return } - let slot_to_usize = |slot: T::Moment| { slot.as_() as usize }; - - let skipped_slots = cur_slot - last_slot - T::Moment::sa(1); + let skipped_slots = cur_slot - last_slot - One::one(); H::handle_report(AuraReport { - start_slot: slot_to_usize(first_skipped), - skipped: slot_to_usize(skipped_slots), + start_slot: first_skipped.saturated_into::(), + skipped: skipped_slots.saturated_into::(), }) } } impl OnTimestampSet for Module { fn on_timestamp_set(moment: T::Moment) { - Self::on_timestamp_set::(moment, T::Moment::sa(Self::slot_duration())) + Self::on_timestamp_set::(moment, Self::slot_duration()) } } @@ -265,9 +280,9 @@ impl ProvideInherent for Module { _ => return Ok(()), }; - let timestamp_based_slot = timestamp.as_() / Self::slot_duration(); + let timestamp_based_slot = timestamp / Self::slot_duration(); - let seal_slot = data.aura_inherent_data()?; + let seal_slot = data.aura_inherent_data()?.saturated_into(); if timestamp_based_slot == seal_slot { Ok(()) diff --git a/srml/aura/src/tests.rs b/srml/aura/src/tests.rs index e74c7dace2ff3fd6179f755e05add387f1bc7f92..3e20613c48f6119befbd3a1cede6004fedb5f5bc 100644 --- a/srml/aura/src/tests.rs +++ b/srml/aura/src/tests.rs @@ -73,7 +73,7 @@ fn aura_reports_offline() { } with_externalities(&mut new_test_ext(vec![0, 1, 2, 3]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); let slot_duration = Aura::slot_duration(); Aura::on_timestamp_set::(5 * slot_duration, slot_duration); @@ -82,7 +82,7 @@ fn aura_reports_offline() { // no slashing when last step was 0. assert_eq!(SLASH_COUNTS.lock().as_slice(), &[0, 0, 0, 0]); - System::initialize(&2, &header.hash(), &Default::default()); + System::initialize(&2, &header.hash(), &Default::default(), &Default::default()); Aura::on_timestamp_set::(8 * slot_duration, slot_duration); let _header = System::finalize(); diff --git a/srml/babe/Cargo.toml b/srml/babe/Cargo.toml index 0c25a98948baf801b2457e4e6f68f4e1dac77390..0f189dfcdadfd702010cebca8798a94b021d0c43 100644 --- a/srml/babe/Cargo.toml +++ b/srml/babe/Cargo.toml @@ -20,7 +20,7 @@ babe-primitives = { package = "substrate-consensus-babe-primitives", path = "../ [dev-dependencies] lazy_static = "1.3.0" -parking_lot = "0.7.1" +parking_lot = "0.8.0" substrate-primitives = { path = "../../core/primitives" } runtime_io = { package = "sr-io", path = "../../core/sr-io" } consensus = { package = "srml-consensus", path = "../consensus" } diff --git a/srml/babe/src/lib.rs b/srml/babe/src/lib.rs index e9b5426221c69cac904e458026888d67e98a1c50..e969dee74bfa7b40f7bab3dc2859b515340fee09 100644 --- a/srml/babe/src/lib.rs +++ b/srml/babe/src/lib.rs @@ -17,19 +17,21 @@ //! Consensus extension module for BABE consensus. #![cfg_attr(not(feature = "std"), no_std)] -#![forbid(unsafe_code, warnings)] +#![forbid(unsafe_code)] pub use timestamp; -use rstd::{result, prelude::*}; +use rstd::{result, prelude::*, marker::PhantomData}; use srml_support::{decl_storage, decl_module}; -use primitives::traits::As; use timestamp::{OnTimestampSet, Trait}; +use primitives::traits::{SaturatedConversion, Saturating}; #[cfg(feature = "std")] use timestamp::TimestampInherentData; -use parity_codec::Decode; +use parity_codec::{Encode, Decode}; use inherents::{RuntimeString, InherentIdentifier, InherentData, ProvideInherent, MakeFatalError}; #[cfg(feature = "std")] use inherents::{InherentDataProviders, ProvideInherentData}; +#[cfg(feature = "std")] +use serde::Serialize; /// The BABE inherent identifier. pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"babeslot"; @@ -56,6 +58,20 @@ impl BabeInherentData for InherentData { } } +/// Logs in this module. +pub type Log = RawLog; + +/// Logs in this module. +/// +/// The type parameter distinguishes logs belonging to two different runtimes, +/// which should not be mixed. +#[cfg_attr(feature = "std", derive(Serialize, Debug))] +#[derive(Encode, Decode, PartialEq, Eq, Clone)] +pub enum RawLog { + /// BABE inherent digests + PreRuntime([u8; 4], Vec, PhantomData), +} + /// Provides the slot duration inherent data for BABE. #[cfg(feature = "std")] pub struct InherentDataProvider { @@ -116,10 +132,10 @@ decl_module! { impl Module { /// Determine the BABE slot duration based on the Timestamp module configuration. - pub fn slot_duration() -> u64 { + pub fn slot_duration() -> T::Moment { // we double the minimum block-period so each author can always propose within // the majority of their slot. - >::minimum_period().as_().saturating_mul(2) + >::minimum_period().saturating_mul(2.into()) } } @@ -142,10 +158,8 @@ impl ProvideInherent for Module { _ => return Ok(()), }; - let timestamp_based_slot = timestamp.as_() / Self::slot_duration(); - + let timestamp_based_slot = (timestamp / Self::slot_duration()).saturated_into::(); let seal_slot = data.babe_inherent_data()?; - if timestamp_based_slot == seal_slot { Ok(()) } else { diff --git a/srml/balances/src/lib.rs b/srml/balances/src/lib.rs index 90f774dbf38f60a320feccc2b28334b56307179a..e205fa0aaa629e0cd0c7ee46b84b2a479ba92069 100644 --- a/srml/balances/src/lib.rs +++ b/srml/balances/src/lib.rs @@ -51,7 +51,8 @@ //! deleted, then the account is said to be dead. //! - **Imbalance:** A condition when some funds were credited or debited without equal and opposite accounting //! (i.e. a difference between total issuance and account balances). Functions that result in an imbalance will -//! return an object of the `Imbalance` trait that must be handled. +//! return an object of the `Imbalance` trait that can be managed within your runtime logic. (If an imbalance is +//! simply dropped, it should automatically maintain any book-keeping such as total issuance.) //! - **Lock:** A freeze on a specified amount of an account's free balance until a specified block number. Multiple //! locks always operate over the same funds, so they "overlay" rather than "stack". //! - **Vesting:** Similar to a lock, this is another, but independent, liquidity restriction that reduces linearly @@ -155,7 +156,7 @@ use srml_support::traits::{ }; use srml_support::dispatch::Result; use primitives::traits::{ - Zero, SimpleArithmetic, As, StaticLookup, Member, CheckedAdd, CheckedSub, + Zero, SimpleArithmetic, StaticLookup, Member, CheckedAdd, CheckedSub, MaybeSerializeDebug, Saturating }; use system::{IsDeadAccount, OnNewAccount, ensure_signed}; @@ -167,7 +168,8 @@ pub use self::imbalances::{PositiveImbalance, NegativeImbalance}; pub trait Subtrait: system::Trait { /// The balance of an account. - type Balance: Parameter + Member + SimpleArithmetic + Codec + Default + Copy + MaybeSerializeDebug; + type Balance: Parameter + Member + SimpleArithmetic + Codec + Default + Copy + + MaybeSerializeDebug + From; /// A function that is invoked when the free-balance has fallen below the existential deposit and /// has been reduced to zero. @@ -181,7 +183,8 @@ pub trait Subtrait: system::Trait { pub trait Trait: system::Trait { /// The balance of an account. - type Balance: Parameter + Member + SimpleArithmetic + Codec + Default + Copy + MaybeSerializeDebug; + type Balance: Parameter + Member + SimpleArithmetic + Codec + Default + Copy + + MaybeSerializeDebug + From; /// A function that is invoked when the free-balance has fallen below the existential deposit and /// has been reduced to zero. @@ -236,10 +239,12 @@ pub struct VestingSchedule { pub per_block: Balance, } -impl> VestingSchedule { +impl VestingSchedule { /// Amount locked at block `n`. - pub fn locked_at>(&self, n: BlockNumber) -> Balance { - if let Some(x) = Balance::sa(n.as_()).checked_mul(&self.per_block) { + pub fn locked_at(&self, n: BlockNumber) -> Balance + where Balance: From + { + if let Some(x) = Balance::from(n).checked_mul(&self.per_block) { self.offset.max(x) - x } else { Zero::zero() @@ -276,10 +281,8 @@ decl_storage! { /// Information regarding the vesting of a given account. pub Vesting get(vesting) build(|config: &GenesisConfig| { config.vesting.iter().filter_map(|&(ref who, begin, length)| { - let begin: u64 = begin.as_(); - let length: u64 = length.as_(); - let begin: T::Balance = As::sa(begin); - let length: T::Balance = As::sa(length); + let begin = >::from(begin); + let length = >::from(length); config.balances.iter() .find(|&&(ref w, _)| w == who) @@ -380,7 +383,8 @@ impl, I: Instance> Module { /// Get the amount that is currently being vested and cannot be transferred out of this account. pub fn vesting_balance(who: &T::AccountId) -> T::Balance { if let Some(v) = Self::vesting(who) { - Self::free_balance(who).min(v.locked_at(>::block_number())) + Self::free_balance(who) + .min(v.locked_at::(>::block_number())) } else { Zero::zero() } @@ -1013,7 +1017,7 @@ where impl, I: Instance> MakePayment for Module { fn make_payment(transactor: &T::AccountId, encoded_len: usize) -> Result { - let encoded_len = >::sa(encoded_len as u64); + let encoded_len = T::Balance::from(encoded_len as u32); let transaction_fee = Self::transaction_base_fee() + Self::transaction_byte_fee() * encoded_len; let imbalance = Self::withdraw( transactor, diff --git a/srml/consensus/src/lib.rs b/srml/consensus/src/lib.rs index 696b9d75f4d9732830ddd0154d40203ad64b1bf5..4613981ec5d9e80b52e5598491665883f86dfa5e 100644 --- a/srml/consensus/src/lib.rs +++ b/srml/consensus/src/lib.rs @@ -221,6 +221,7 @@ impl>> InherentOfflineReport for InstantFinalityRepo } } +/// Logs in this module. pub type Log = RawLog< ::SessionKey, >; diff --git a/srml/consensus/src/tests.rs b/srml/consensus/src/tests.rs index bf8b3a09f37686ba3b47979cdb45e8bd1b589486..471cdf4979097ffa71a9a578ee1f339b2d5a6e95 100644 --- a/srml/consensus/src/tests.rs +++ b/srml/consensus/src/tests.rs @@ -26,7 +26,7 @@ use inherents::{InherentData, ProvideInherent}; #[test] fn authorities_change_logged() { with_externalities(&mut new_test_ext(vec![1, 2, 3]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); Consensus::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)]); Consensus::on_finalize(1); let header = System::finalize(); @@ -47,7 +47,7 @@ fn authorities_change_logged() { #[test] fn partial_authorities_change_logged() { with_externalities(&mut new_test_ext(vec![1, 2, 3]), || { - System::initialize(&2, &Default::default(), &Default::default()); + System::initialize(&2, &Default::default(), &Default::default(), &Default::default()); Consensus::set_authorities(&[UintAuthorityId(2), UintAuthorityId(4), UintAuthorityId(5)]); Consensus::on_finalize(2); let header = System::finalize(); @@ -68,7 +68,7 @@ fn partial_authorities_change_logged() { #[test] fn authorities_change_is_not_logged_when_not_changed() { with_externalities(&mut new_test_ext(vec![1, 2, 3]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); Consensus::on_finalize(1); let header = System::finalize(); assert_eq!(header.digest, testing::Digest { @@ -80,7 +80,7 @@ fn authorities_change_is_not_logged_when_not_changed() { #[test] fn authorities_change_is_not_logged_when_changed_back_to_original() { with_externalities(&mut new_test_ext(vec![1, 2, 3]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); Consensus::set_authorities(&[UintAuthorityId(4), UintAuthorityId(5), UintAuthorityId(6)]); Consensus::set_authorities(&[UintAuthorityId(1), UintAuthorityId(2), UintAuthorityId(3)]); Consensus::on_finalize(1); @@ -94,7 +94,7 @@ fn authorities_change_is_not_logged_when_changed_back_to_original() { #[test] fn offline_report_can_be_excluded() { with_externalities(&mut new_test_ext(vec![1, 2, 3]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); assert!(Consensus::create_inherent(&InherentData::new()).is_none()); let offline_report: Vec = vec![0]; @@ -110,7 +110,7 @@ fn set_and_kill_storage_work() { use srml_support::storage; with_externalities(&mut new_test_ext(vec![1, 2, 3]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); let item = (vec![42u8], vec![42u8]); diff --git a/srml/contract/COMPLEXITY.md b/srml/contract/COMPLEXITY.md index 3cd7fee448204849edb14c7ca7e9207458990a47..d87525a982291d20c6480ed24301780255c6dc23 100644 --- a/srml/contract/COMPLEXITY.md +++ b/srml/contract/COMPLEXITY.md @@ -83,7 +83,25 @@ The size of the arguments and the return value depends on the exact function in `AccountDb` is an abstraction that supports collecting changes to accounts with the ability to efficiently reverting them. Contract execution contexts operate on the AccountDb. All changes are flushed into underlying storage only after origin transaction succeeds. -Today `AccountDb` is implemented as a cascade of overlays with the direct storage at the bottom. Each overlay is represented by a `Map`. On a commit from an overlay to an overlay, maps are merged. On commit from an overlay to the bottommost `AccountDb` all changes are flushed to the storage. On revert, the overlay is just discarded. +## Relation to the underlying storage + +At present, `AccountDb` is implemented as a cascade of overlays with the direct storage at the bottom. The direct +storage `AccountDb` leverages child tries. Each overlay is represented by a `Map`. On a commit from an overlay to an +overlay, maps are merged. On commit from an overlay to the bottommost `AccountDb` all changes are flushed to the storage +and on revert, the overlay is just discarded. + +> ℹ️ The underlying storage has a overlay layer implemented as a `Map`. If the runtime reads a storage location and the +> respective key doesn't exist in the overlay, then the underlying storage performs a DB access, but the value won't be +> placed into the overlay. The overlay is only filled with writes. +> +> This means that the overlay can be abused in the following ways: +> +> - The overlay can be inflated by issuing a lot of writes to unique locations, +> - Deliberate cache misses can be induced by reading non-modified storage locations, + +It also worth noting that the performance degrades with more state stored in the trie. Due to this +there is not negligible chance that gas schedule will be updated for all operations that involve +storage access. ## get_storage, get_code_hash, get_rent_allowance, get_balance, contract_exists @@ -158,20 +176,36 @@ Assuming marshaled size of a balance value is of the constant size we can neglec This function receives input data for the contract execution. The execution consists of the following steps: -1. Loading code from the DB. -2. `transfer`-ing funds between the caller and the destination account. -3. Executing the code of the destination account. -4. Committing overlayed changed to the underlying `AccountDb`. +1. Checking rent payment. +2. Loading code from the DB. +3. `transfer`-ing funds between the caller and the destination account. +4. Executing the code of the destination account. +5. Committing overlayed changed to the underlying `AccountDb`. **Note** that the complexity of executing the contract code should be considered separately. -Loading code most probably will trigger a DB read, since the code is immutable and therefore will not get into the cache (unless a suicide removes it). +Checking for rent involves 2 unconditional DB reads: `ContractInfoOf` and `block_number` +and on top of that at most once per block: + +- DB read to `free_balance` and +- `rent_deposit_offset` and +- `rent_byte_price` and +- `Currency::minimum_balance` and +- `tombstone_deposit`. +- Calls to `ensure_can_withdraw`, `withdraw`, `make_free_balance_be` can perform arbitrary logic and should be considered separately, +- `child_storage_root` +- `kill_child_storage` +- mutation of `ContractInfoOf` + +Loading code most likely will trigger a DB read, since the code is immutable and therefore will not get into the cache (unless a suicide removes it, or it has been created in the same call chain). Also, `transfer` can make up to 2 DB reads and up to 2 DB writes (if flushed to the storage) in the standard case. If removal of the source account takes place then it will additionally perform a DB write per one storage entry that the account has. Finally, all changes are `commit`-ted into the underlying overlay. The complexity of this depends on the number of changes performed by the code. Thus, the pricing of storage modification should account for that. -**complexity**: Up to 3 DB reads. DB read of the code is of dynamic size. There can also be up to 2 DB writes (if flushed to the storage). Additionally, if the source account removal takes place a DB write will be performed per one storage entry that the account has. +**complexity**: +- Only for the first invocation of the contract: up to 5 DB reads and one DB write as well as logic executed by `ensure_can_withdraw`, `withdraw`, `make_free_balance_be`. +- On top of that for every invocation: Up to 5 DB reads. DB read of the code is of dynamic size. There can also be up to 2 DB writes (if flushed to the storage). Additionally, if the source account removal takes place a DB write will be performed per one storage entry that the account has. ## Create @@ -185,7 +219,7 @@ This function takes the code of the constructor and input data. Creation of a co **Note** that the complexity of executing the constructor code should be considered separately. -**Note** that the complexity of `DetermineContractAddress` hook should be considered separately as well. Most probably it will use some kind of hashing over the code of the constructor and input data. The default `SimpleAddressDeterminator` does precisely that. +**Note** that the complexity of `DetermineContractAddress` hook should be considered separately as well. Most likely it will use some kind of hashing over the code of the constructor and input data. The default `SimpleAddressDeterminator` does precisely that. **Note** that the constructor returns code in the owned form and it's obtained via return facilities, which should have take fee for the return value. @@ -224,9 +258,11 @@ This function receives a `key` as an argument. It consists of the following step Key is of a constant size. Therefore, the sandbox memory load can be considered to be of constant complexity. -However, a read from the contract's storage can hit the DB, and the size of this read is dynamical. +Unless the value is cached, a DB read will be performed. The size of the value is not known until the read is +performed. Moreover, the DB read has to be synchronous and no progress can be made until the value is fetched. -**complexity**: The memory and computing complexity is proportional to the size of the fetched value. +**complexity**: The memory and computing complexity is proportional to the size of the fetched value. This function performs a +DB read. ## ext_call @@ -242,7 +278,7 @@ It consists of the following steps: 1. Loading `callee` buffer from the sandbox memory (see sandboxing memory get) and then decoding it. 2. Loading `value` buffer from the sandbox memory and then decoding it. 3. Loading `input_data` buffer from the sandbox memory. -4. Invoking `call` executive function. +4. Invoking the executive function `call`. Loading of `callee` and `value` buffers should be charged. This is because the sizes of buffers are specified by the calling code, even though marshaled representations are, essentially, of constant size. This can be fixed by assigning an upper bound for sizes of `AccountId` and `Balance`. @@ -298,11 +334,13 @@ This function serializes the address of the caller into the scratch buffer. **complexity**: Assuming that the address is of constant size, this function has constant complexity. -## ext_random_seed +## ext_random -This function serializes the current block's random seed into the scratch buffer. +This function serializes a random number generated by the given subject into the scratch buffer. +The complexity of this function highly depends on the complexity of `System::random`. `max_subject_len` +limits the size of the subject buffer. -**complexity**: Assuming that the random seed is of constant size, this function has constant complexity. +**complexity**: The complexity of this function depends on the implementation of `System::random`. ## ext_now @@ -324,6 +362,8 @@ This function copies slice of data from the input buffer to the sandbox memory. ## ext_scratch_size +This function returns the size of the scratch buffer. + **complexity**: This function is of constant complexity. ## ext_scratch_copy @@ -354,4 +394,5 @@ It consists of the following steps: 1. Invoking `get_rent_allowance` AccountDB function. 2. Serializing the rent allowance of the current contract into the scratch buffer. -**complexity**: Assuming that the rent allowance is of constant size, this function has constant complexity. +**complexity**: Assuming that the rent allowance is of constant size, this function has constant complexity. This +function performs a DB read. diff --git a/srml/contract/Cargo.toml b/srml/contract/Cargo.toml index be34da3cacbbb936351ea01b839f6c373fe081e2..7c04758171beb0eeb15916df4043127b0be0a65c 100644 --- a/srml/contract/Cargo.toml +++ b/srml/contract/Cargo.toml @@ -25,6 +25,7 @@ assert_matches = "1.1" hex-literal = "0.2.0" consensus = { package = "srml-consensus", path = "../consensus" } balances = { package = "srml-balances", path = "../balances" } +hex = "0.3" [features] default = ["std"] diff --git a/srml/contract/src/account_db.rs b/srml/contract/src/account_db.rs index df63ccc479cd5a22ff2f50754740e4d7a2f4632f..2421eab00abb187582503dda96b1866d3d91726b 100644 --- a/srml/contract/src/account_db.rs +++ b/srml/contract/src/account_db.rs @@ -124,6 +124,7 @@ impl AccountDb for DirectAccountDb { trie_id: ::TrieIdGenerator::trie_id(&address), deduct_block: >::block_number(), rent_allowance: >::max_value(), + last_write: None, } } else { // No contract exist and no code_hash provided @@ -138,12 +139,16 @@ impl AccountDb for DirectAccountDb { new_info.code_hash = code_hash; } + if !changed.storage.is_empty() { + new_info.last_write = Some(>::block_number()); + } + for (k, v) in changed.storage.into_iter() { if let Some(value) = child::get_raw(&new_info.trie_id[..], &blake2_256(&k)) { - new_info.storage_size -= value.len() as u64; + new_info.storage_size -= value.len() as u32; } if let Some(value) = v { - new_info.storage_size += value.len() as u64; + new_info.storage_size += value.len() as u32; child::put_raw(&new_info.trie_id[..], &blake2_256(&k), &value[..]); } else { child::kill(&new_info.trie_id[..], &blake2_256(&k)); @@ -172,10 +177,10 @@ impl AccountDb for DirectAccountDb { } pub struct OverlayAccountDb<'a, T: Trait + 'a> { local: RefCell>, - underlying: &'a AccountDb, + underlying: &'a dyn AccountDb, } impl<'a, T: Trait> OverlayAccountDb<'a, T> { - pub fn new(underlying: &'a AccountDb) -> OverlayAccountDb<'a, T> { + pub fn new(underlying: &'a dyn AccountDb) -> OverlayAccountDb<'a, T> { OverlayAccountDb { local: RefCell::new(ChangeSet::new()), underlying, diff --git a/srml/contract/src/exec.rs b/srml/contract/src/exec.rs index 9d63c037c06d7602edcdaa910bcf74398f40a3cb..7a16c9d60dc7c0ca0ffbf0033224eae1b4adc808 100644 --- a/srml/contract/src/exec.rs +++ b/srml/contract/src/exec.rs @@ -106,8 +106,8 @@ pub trait Ext { /// Returns a reference to the timestamp of the current block fn now(&self) -> &MomentOf; - /// Returns a reference to the random seed for the current block - fn random_seed(&self) -> &SeedOf; + /// Returns a random number for the current block with the given subject. + fn random(&self, subject: &[u8]) -> SeedOf; /// Deposit an event with the given topics. /// @@ -353,7 +353,6 @@ where caller: self.self_account.clone(), value_transferred: value, timestamp: timestamp::Module::::now(), - random_seed: system::Module::::random_seed(), }, input_data, empty_output_buf, @@ -423,7 +422,6 @@ where caller: self.self_account.clone(), value_transferred: endowment, timestamp: timestamp::Module::::now(), - random_seed: system::Module::::random_seed(), }, input_data, EmptyOutputBuf::new(), @@ -576,7 +574,6 @@ struct CallContext<'a, 'b: 'a, T: Trait + 'b, V: Vm + 'b, L: Loader> { caller: T::AccountId, value_transferred: BalanceOf, timestamp: T::Moment, - random_seed: T::Hash, } impl<'a, 'b: 'a, T, E, V, L> Ext for CallContext<'a, 'b, T, V, L> @@ -642,8 +639,8 @@ where self.value_transferred } - fn random_seed(&self) -> &T::Hash { - &self.random_seed + fn random(&self, subject: &[u8]) -> SeedOf { + system::Module::::random(subject) } fn now(&self) -> &T::Moment { @@ -706,7 +703,7 @@ mod tests { } #[derive(Clone)] - struct MockExecutable<'a>(Rc VmExecResult + 'a>); + struct MockExecutable<'a>(Rc VmExecResult + 'a>); impl<'a> MockExecutable<'a> { fn new(f: impl Fn(MockCtx) -> VmExecResult + 'a) -> Self { diff --git a/srml/contract/src/gas.rs b/srml/contract/src/gas.rs index f42b0919f3149b1854bb12c7fe1ced368a66ef74..1ea519634463c7ed232e99f1ad9c363247c0ca20 100644 --- a/srml/contract/src/gas.rs +++ b/srml/contract/src/gas.rs @@ -16,7 +16,7 @@ use crate::{GasSpent, Module, Trait, BalanceOf, NegativeImbalanceOf}; use runtime_primitives::BLOCK_FULL; -use runtime_primitives::traits::{As, CheckedMul, CheckedSub, Zero}; +use runtime_primitives::traits::{CheckedMul, CheckedSub, Zero, SaturatedConversion}; use srml_support::{StorageValue, traits::{OnUnbalanced, ExistenceRequirement, WithdrawReason, Currency, Imbalance}}; #[cfg(test)] @@ -212,7 +212,7 @@ pub fn buy_gas( // Buy the specified amount of gas. let gas_price = >::gas_price(); - let cost = >>::as_(gas_limit.clone()) + let cost = gas_limit.clone().into() .checked_mul(&gas_price) .ok_or("overflow multiplying gas limit by price")?; @@ -248,7 +248,7 @@ pub fn refund_unused_gas( >::mutate(|block_gas_spent| *block_gas_spent += gas_spent); // Refund gas left by the price it was bought at. - let refund = >>::as_(gas_left) * gas_meter.gas_price; + let refund = gas_left.into() * gas_meter.gas_price; let refund_imbalance = T::Currency::deposit_creating(transactor, refund); if let Ok(imbalance) = imbalance.offset(refund_imbalance) { T::GasPayment::on_unbalanced(imbalance); @@ -258,8 +258,7 @@ pub fn refund_unused_gas( /// A little handy utility for converting a value in balance units into approximate value in gas units /// at the given gas price. pub fn approx_gas_for_balance(gas_price: BalanceOf, balance: BalanceOf) -> T::Gas { - let amount_in_gas: BalanceOf = balance / gas_price; - >>::sa(amount_in_gas) + (balance / gas_price).saturated_into::() } /// A simple utility macro that helps to match against a diff --git a/srml/contract/src/lib.rs b/srml/contract/src/lib.rs index 0cd3b0a325b8db15659f0bac0ac1bbb19fc73492..0111ce7840204e6112045579fe32349c6770eceb 100644 --- a/srml/contract/src/lib.rs +++ b/srml/contract/src/lib.rs @@ -94,12 +94,16 @@ use crate::account_db::{AccountDb, DirectAccountDb}; #[cfg(feature = "std")] use serde::{Serialize, Deserialize}; use substrate_primitives::crypto::UncheckedFrom; -use rstd::prelude::*; -use rstd::marker::PhantomData; +use rstd::{prelude::*, marker::PhantomData, convert::TryFrom}; use parity_codec::{Codec, Encode, Decode}; -use runtime_primitives::traits::{Hash, As, SimpleArithmetic, Bounded, StaticLookup, Zero}; +use runtime_io::blake2_256; +use runtime_primitives::traits::{ + Hash, SimpleArithmetic, Bounded, StaticLookup, Zero, MaybeSerializeDebug, Member +}; use srml_support::dispatch::{Result, Dispatchable}; -use srml_support::{Parameter, StorageMap, StorageValue, decl_module, decl_event, decl_storage, storage::child}; +use srml_support::{ + Parameter, StorageMap, StorageValue, decl_module, decl_event, decl_storage, storage::child +}; use srml_support::traits::{OnFreeBalanceZero, OnUnbalanced, Currency}; use system::{ensure_signed, RawOrigin}; use substrate_primitives::storage::well_known_keys::CHILD_STORAGE_KEY_PREFIX; @@ -121,6 +125,7 @@ pub trait ComputeDispatchFee { /// Information for managing an acocunt and its sub trie abstraction. /// This is the required info to cache for an account #[derive(Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] pub enum ContractInfo { Alive(AliveContractInfo), Tombstone(TombstoneContractInfo), @@ -178,33 +183,47 @@ impl ContractInfo { } } -pub type AliveContractInfo = RawAliveContractInfo, BalanceOf, ::BlockNumber>; +pub type AliveContractInfo = + RawAliveContractInfo, BalanceOf, ::BlockNumber>; /// Information for managing an account and its sub trie abstraction. /// This is the required info to cache for an account. // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. #[derive(Encode, Decode, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] pub struct RawAliveContractInfo { /// Unique ID for the subtree encoded as a bytes vector. pub trie_id: TrieId, /// The size of stored value in octet. - pub storage_size: u64, + pub storage_size: u32, /// The code associated with a given account. pub code_hash: CodeHash, + /// Pay rent at most up to this value. pub rent_allowance: Balance, + /// Last block rent has been payed. pub deduct_block: BlockNumber, + /// Last block child storage has been written. + pub last_write: Option, } -#[derive(Encode, Decode)] -pub struct TombstoneContractInfo(T::Hash); +pub type TombstoneContractInfo = + RawTombstoneContractInfo<::Hash, ::Hashing>; + +// Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. +#[derive(Encode, Decode, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct RawTombstoneContractInfo(H, PhantomData); -impl TombstoneContractInfo { - fn new(storage_root: Vec, storage_size: u64, code_hash: CodeHash) -> Self { +impl RawTombstoneContractInfo +where + H: Member + MaybeSerializeDebug + AsRef<[u8]> + AsMut<[u8]> + Copy + Default + rstd::hash::Hash, + Hasher: Hash, +{ + fn new(storage_root: &[u8], code_hash: H) -> Self { let mut buf = Vec::new(); storage_root.using_encoded(|encoded| buf.extend_from_slice(encoded)); - storage_size.using_encoded(|encoded| buf.extend_from_slice(encoded)); buf.extend_from_slice(code_hash.as_ref()); - TombstoneContractInfo(T::Hashing::hash(&buf[..])) + RawTombstoneContractInfo(Hasher::hash(&buf[..]), PhantomData) } } @@ -236,7 +255,10 @@ where fn trie_id(account_id: &T::AccountId) -> TrieId { // Note that skipping a value due to error is not an issue here. // We only need uniqueness, not sequence. - let new_seed = >::mutate(|v| v.wrapping_add(1)); + let new_seed = >::mutate(|v| { + *v = v.wrapping_add(1); + *v + }); let mut buf = Vec::new(); buf.extend_from_slice(account_id.as_ref()); @@ -252,7 +274,8 @@ where } pub type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; -pub type NegativeImbalanceOf = <::Currency as Currency<::AccountId>>::NegativeImbalance; +pub type NegativeImbalanceOf = + <::Currency as Currency<::AccountId>>::NegativeImbalance; pub trait Trait: timestamp::Trait { type Currency: Currency; @@ -263,8 +286,8 @@ pub trait Trait: timestamp::Trait { /// The overarching event type. type Event: From> + Into<::Event>; - // `As` is needed for wasm-utils - type Gas: Parameter + Default + Codec + SimpleArithmetic + Bounded + Copy + As> + As + As; + type Gas: Parameter + Default + Codec + SimpleArithmetic + Bounded + Copy + + Into> + TryFrom>; /// A function type to get the contract address given the creator. type DetermineContractAddress: ContractAddressFor, Self::AccountId>; @@ -310,10 +333,10 @@ where pub struct DefaultDispatchFeeComputor(PhantomData); impl ComputeDispatchFee> for DefaultDispatchFeeComputor { fn compute_dispatch_fee(call: &T::Call) -> BalanceOf { - let encoded_len = call.using_encoded(|encoded| encoded.len()); + let encoded_len = call.using_encoded(|encoded| encoded.len() as u32); let base_fee = >::transaction_base_fee(); let byte_fee = >::transaction_byte_fee(); - base_fee + byte_fee * as As>::sa(encoded_len as u64) + base_fee + byte_fee * encoded_len.into() } } @@ -483,10 +506,10 @@ decl_module! { fn claim_surcharge(origin, dest: T::AccountId, aux_sender: Option) { let origin = origin.into(); let (signed, rewarded) = match origin { - Some(system::RawOrigin::Signed(ref account)) if aux_sender.is_none() => { + Ok(system::RawOrigin::Signed(ref account)) if aux_sender.is_none() => { (true, account) }, - Some(system::RawOrigin::None) if aux_sender.is_some() => { + Ok(system::RawOrigin::None) if aux_sender.is_some() => { (false, aux_sender.as_ref().expect("checked above")) }, _ => return Err("Invalid surcharge claim: origin must be signed or \ @@ -508,6 +531,84 @@ decl_module! { } } + /// Allows a contract to restore a tombstone by giving its storage. + /// + /// The contract that wants to restore (i.e. origin of the call, or `msg.sender` in Solidity terms) will compute a + /// tombstone with its storage and the given code_hash. If the computed tombstone + /// match the destination one, the destination contract is restored with the rent_allowance` specified, + /// while the origin sends all its funds to the destination and is removed. + fn restore_to( + origin, + dest: T::AccountId, + code_hash: CodeHash, + rent_allowance: BalanceOf, + delta: Vec + ) { + let origin = ensure_signed(origin)?; + + let mut origin_contract = >::get(&origin) + .and_then(|c| c.get_alive()) + .ok_or("Cannot restore from inexisting or tombstone contract")?; + + let current_block = >::block_number(); + + if origin_contract.last_write == Some(current_block) { + return Err("Origin TrieId written in the current block"); + } + + let dest_tombstone = >::get(&dest) + .and_then(|c| c.get_tombstone()) + .ok_or("Cannot restore to inexisting or alive contract")?; + + let last_write = if !delta.is_empty() { + Some(current_block) + } else { + origin_contract.last_write + }; + + let key_values_taken = delta.iter() + .filter_map(|key| { + child::get_raw(&origin_contract.trie_id, &blake2_256(key)).map(|value| { + child::kill(&origin_contract.trie_id, &blake2_256(key)); + (key, value) + }) + }) + .collect::>(); + + let tombstone = >::new( + // This operation is cheap enough because last_write (delta not included) + // is not this block as it has been checked earlier. + &runtime_io::child_storage_root(&origin_contract.trie_id)[..], + code_hash, + ); + + if tombstone != dest_tombstone { + for (key, value) in key_values_taken { + child::put_raw(&origin_contract.trie_id, &blake2_256(key), &value); + } + + return Err("Tombstones don't match"); + } + + origin_contract.storage_size -= key_values_taken.iter() + .map(|(_, value)| value.len() as u32) + .sum::(); + + >::remove(&origin); + >::insert(&dest, ContractInfo::Alive(RawAliveContractInfo { + trie_id: origin_contract.trie_id, + storage_size: origin_contract.storage_size, + code_hash, + rent_allowance, + deduct_block: current_block, + last_write, + })); + + let origin_free_balance = T::Currency::free_balance(&origin); + T::Currency::make_free_balance_be(&origin, >::zero()); + T::Currency::deposit_creating(&dest, origin_free_balance); + } + fn on_finalize() { >::kill(); } @@ -553,7 +654,7 @@ decl_storage! { TombstoneDeposit get(tombstone_deposit) config(): BalanceOf; /// Size of a contract at the time of creation. This is a simple way to ensure /// that empty contracts eventually gets deleted. - StorageSizeOffset get(storage_size_offset) config(): u64; + StorageSizeOffset get(storage_size_offset) config(): u32; /// Price of a byte of storage per one block interval. Should be greater than 0. RentByteFee get(rent_byte_price) config(): BalanceOf; /// The amount of funds a contract should deposit in order to offset @@ -576,17 +677,17 @@ decl_storage! { /// The fee to be paid for making a transaction; the per-byte portion. TransactionByteFee get(transaction_byte_fee) config(): BalanceOf; /// The fee required to create a contract instance. - ContractFee get(contract_fee) config(): BalanceOf = BalanceOf::::sa(21); + ContractFee get(contract_fee) config(): BalanceOf = 21.into(); /// The base fee charged for calling into a contract. - CallBaseFee get(call_base_fee) config(): T::Gas = T::Gas::sa(135); + CallBaseFee get(call_base_fee) config(): T::Gas = 135.into(); /// The base fee charged for creating a contract. - CreateBaseFee get(create_base_fee) config(): T::Gas = T::Gas::sa(175); + CreateBaseFee get(create_base_fee) config(): T::Gas = 175.into(); /// The price of one unit of gas. - GasPrice get(gas_price) config(): BalanceOf = BalanceOf::::sa(1); + GasPrice get(gas_price) config(): BalanceOf = 1.into(); /// The maximum nesting level of a call/create stack. MaxDepth get(max_depth) config(): u32 = 100; /// The maximum amount of gas that could be expended per block. - BlockGasLimit get(block_gas_limit) config(): T::Gas = T::Gas::sa(10_000_000); + BlockGasLimit get(block_gas_limit) config(): T::Gas = 10_000_000.into(); /// Gas spent so far in this block. GasSpent get(gas_spent): T::Gas; /// Current cost schedule for contracts. @@ -690,25 +791,29 @@ pub struct Schedule { /// Whether the `ext_println` function is allowed to be used contracts. /// MUST only be enabled for `dev` chains, NOT for production chains pub enable_println: bool, + + /// The maximum length of a subject used for PRNG generation. + pub max_subject_len: u32, } -impl> Default for Schedule { +impl> Default for Schedule { fn default() -> Schedule { Schedule { version: 0, - put_code_per_byte_cost: Gas::sa(1), - grow_mem_cost: Gas::sa(1), - regular_op_cost: Gas::sa(1), - return_data_per_byte_cost: Gas::sa(1), - event_data_per_byte_cost: Gas::sa(1), - event_per_topic_cost: Gas::sa(1), - event_base_cost: Gas::sa(1), - sandbox_data_read_cost: Gas::sa(1), - sandbox_data_write_cost: Gas::sa(1), + put_code_per_byte_cost: 1.into(), + grow_mem_cost: 1.into(), + regular_op_cost: 1.into(), + return_data_per_byte_cost: 1.into(), + event_data_per_byte_cost: 1.into(), + event_per_topic_cost: 1.into(), + event_base_cost: 1.into(), + sandbox_data_read_cost: 1.into(), + sandbox_data_write_cost: 1.into(), max_event_topics: 4, max_stack_height: 64 * 1024, max_memory_pages: 16, enable_println: false, + max_subject_len: 32, } } } diff --git a/srml/contract/src/rent.rs b/srml/contract/src/rent.rs index 5466e2553d90b2236102990374b391ebec4726f5..3baf043b90d37d16ceefd29e141f5c727a5d3eb0 100644 --- a/srml/contract/src/rent.rs +++ b/srml/contract/src/rent.rs @@ -15,7 +15,8 @@ // along with Substrate. If not, see . use crate::{BalanceOf, ContractInfo, ContractInfoOf, Module, TombstoneContractInfo, Trait}; -use runtime_primitives::traits::{As, Bounded, CheckedDiv, CheckedMul, Saturating, Zero}; +use runtime_primitives::traits::{Bounded, CheckedDiv, CheckedMul, Saturating, Zero, + SaturatedConversion}; use srml_support::traits::{Currency, ExistenceRequirement, Imbalance, WithdrawReason}; use srml_support::StorageMap; @@ -75,10 +76,10 @@ fn try_evict_or_and_pay_rent( let fee_per_block = { let free_storage = balance .checked_div(&>::rent_deposit_offset()) - .unwrap_or(>::sa(0)); + .unwrap_or_else(Zero::zero); let effective_storage_size = - >::sa(contract.storage_size).saturating_sub(free_storage); + >::from(contract.storage_size).saturating_sub(free_storage); effective_storage_size .checked_mul(&>::rent_byte_price()) @@ -95,7 +96,7 @@ fn try_evict_or_and_pay_rent( let subsistence_threshold = T::Currency::minimum_balance() + >::tombstone_deposit(); let dues = fee_per_block - .checked_mul(&>::sa(blocks_passed.as_())) + .checked_mul(&blocks_passed.saturated_into::().into()) .unwrap_or(>::max_value()); let dues_limited = dues.min(contract.rent_allowance); @@ -162,9 +163,8 @@ fn try_evict_or_and_pay_rent( // Note: this operation is heavy. let child_storage_root = runtime_io::child_storage_root(&contract.trie_id); - let tombstone = TombstoneContractInfo::new( - child_storage_root, - contract.storage_size, + let tombstone = >::new( + &child_storage_root[..], contract.code_hash, ); >::insert(account, ContractInfo::Tombstone(tombstone)); diff --git a/srml/contract/src/tests.rs b/srml/contract/src/tests.rs index 4eed6777b409e7b6bdbc0eef7621a73f9c5850a2..7a19fdb1d6563add4d481c341b349e7fefdb424a 100644 --- a/srml/contract/src/tests.rs +++ b/srml/contract/src/tests.rs @@ -21,8 +21,8 @@ use crate::account_db::{AccountDb, DirectAccountDb, OverlayAccountDb}; use crate::{ - BalanceOf, ComputeDispatchFee, ContractAddressFor, ContractInfo, ContractInfoOf, GenesisConfig, Module, - RawAliveContractInfo, RawEvent, Trait, TrieId, TrieIdFromParentCounter, TrieIdGenerator, + BalanceOf, ComputeDispatchFee, ContractAddressFor, ContractInfo, ContractInfoOf, GenesisConfig, + Module, RawAliveContractInfo, RawEvent, Trait, TrieId, TrieIdFromParentCounter, TrieIdGenerator, }; use assert_matches::assert_matches; use hex_literal::*; @@ -30,11 +30,11 @@ use parity_codec::{Decode, Encode, KeyedVec}; use runtime_io; use runtime_io::with_externalities; use runtime_primitives::testing::{Digest, DigestItem, Header, UintAuthorityId, H256}; -use runtime_primitives::traits::{As, BlakeTwo256, IdentityLookup}; +use runtime_primitives::traits::{BlakeTwo256, IdentityLookup}; use runtime_primitives::BuildStorage; use srml_support::{ assert_ok, impl_outer_dispatch, impl_outer_event, impl_outer_origin, storage::child, - traits::Currency, StorageMap, + traits::Currency, StorageMap, StorageValue }; use std::sync::atomic::{AtomicUsize, Ordering}; use substrate_primitives::storage::well_known_keys; @@ -119,18 +119,21 @@ impl ContractAddressFor for DummyContractAddressFor { } } -static KEY_COUNTER: AtomicUsize = AtomicUsize::new(0); - pub struct DummyTrieIdGenerator; impl TrieIdGenerator for DummyTrieIdGenerator { fn trie_id(account_id: &u64) -> TrieId { use substrate_primitives::storage::well_known_keys; + let new_seed = >::mutate(|v| { + *v = v.wrapping_add(1); + *v + }); + // TODO: see https://github.com/paritytech/substrate/issues/2325 let mut res = vec![]; res.extend_from_slice(well_known_keys::CHILD_STORAGE_KEY_PREFIX); res.extend_from_slice(b"default:"); - res.extend_from_slice(&KEY_COUNTER.fetch_add(1, Ordering::Relaxed).to_le_bytes()); + res.extend_from_slice(&new_seed.to_le_bytes()); res.extend_from_slice(&account_id.to_le_bytes()); res } @@ -146,6 +149,7 @@ impl ComputeDispatchFee for DummyComputeDispatchFee { const ALICE: u64 = 1; const BOB: u64 = 2; const CHARLIE: u64 = 3; +const DJANGO: u64 = 4; pub struct ExtBuilder { existential_deposit: u64, @@ -263,6 +267,7 @@ fn account_removal_removes_storage() { deduct_block: System::block_number(), code_hash: H256::repeat_byte(1), rent_allowance: 40, + last_write: None, })); let mut overlay = OverlayAccountDb::::new(&DirectAccountDb); @@ -277,6 +282,7 @@ fn account_removal_removes_storage() { deduct_block: System::block_number(), code_hash: H256::repeat_byte(2), rent_allowance: 40, + last_write: None, })); let mut overlay = OverlayAccountDb::::new(&DirectAccountDb); @@ -294,15 +300,15 @@ fn account_removal_removes_storage() { // Verify that all entries from account 1 is removed, while // entries from account 2 is in place. { - assert!(>::get_storage(&DirectAccountDb, &1, Some(&trie_id1), key1).is_none()); - assert!(>::get_storage(&DirectAccountDb, &1, Some(&trie_id1), key2).is_none()); + assert!(>::get_storage(&DirectAccountDb, &1, Some(&trie_id1), key1).is_none()); + assert!(>::get_storage(&DirectAccountDb, &1, Some(&trie_id1), key2).is_none()); assert_eq!( - >::get_storage(&DirectAccountDb, &2, Some(&trie_id2), key1), + >::get_storage(&DirectAccountDb, &2, Some(&trie_id2), key1), Some(b"3".to_vec()) ); assert_eq!( - >::get_storage(&DirectAccountDb, &2, Some(&trie_id2), key2), + >::get_storage(&DirectAccountDb, &2, Some(&trie_id2), key2), Some(b"4".to_vec()) ); } @@ -424,7 +430,7 @@ const HASH_DISPATCH_CALL: [u8; 32] = hex!("49dfdcaf9c1553be10634467e95b8e71a3bc1 fn dispatch_call() { // This test can fail due to the encoding changes. In case it becomes too annoying // let's rewrite so as we use this module controlled call or we serialize it in runtime. - let encoded = parity_codec::Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50))); + let encoded = Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50))); assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]); let wasm = wabt::wat2wasm(CODE_DISPATCH_CALL).unwrap(); @@ -555,7 +561,7 @@ const CODE_SET_RENT: &str = r#" ;; transfer 50 to ALICE (func $call_2 (call $ext_dispatch_call - (i32.const 8) + (i32.const 68) (i32.const 11) ) ) @@ -627,10 +633,12 @@ const CODE_SET_RENT: &str = r#" (data (i32.const 0) "\28") ;; Encoding of call transfer 50 to CHARLIE - (data (i32.const 8) "\00\00\03\00\00\00\00\00\00\00\C8") + (data (i32.const 68) "\00\00\03\00\00\00\00\00\00\00\C8") ) "#; -const HASH_SET_RENT: [u8; 32] = hex!("a51c2a6f3f68936d4ae9abdb93b28eedcbd0f6f39770e168f9025f0c1e7094ef"); + +// Use test_hash_and_code test to get the actual hash if the code changed. +const HASH_SET_RENT: [u8; 32] = hex!("21d6b1d59aa6038fcad632488e9026893a1bbb48581774c771b8f24320697f05"); /// Input data for each call in set_rent code mod call { @@ -643,10 +651,10 @@ mod call { /// Test correspondance of set_rent code and its hash. /// Also test that encoded extrinsic in code correspond to the correct transfer #[test] -fn set_rent_hash_and_code() { +fn test_set_rent_code_and_hash() { // This test can fail due to the encoding changes. In case it becomes too annoying // let's rewrite so as we use this module controlled call or we serialize it in runtime. - let encoded = parity_codec::Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50))); + let encoded = Encode::encode(&Call::Balances(balances::Call::transfer(CHARLIE, 50))); assert_eq!(&encoded[..], &hex!("00000300000000000000C8")[..]); let wasm = wabt::wat2wasm(CODE_SET_RENT).unwrap(); @@ -657,7 +665,8 @@ fn set_rent_hash_and_code() { Balances::deposit_creating(&ALICE, 1_000_000); assert_ok!(Contract::put_code(Origin::signed(ALICE), 100_000, wasm)); - // If you ever need to update the wasm source this test will fail and will show you the actual hash. + // If you ever need to update the wasm source this test will fail + // and will show you the actual hash. assert_eq!(System::events(), vec![ EventRecord { phase: Phase::ApplyExtrinsic(0), @@ -689,17 +698,17 @@ fn storage_size() { Origin::signed(ALICE), 30_000, 100_000, HASH_SET_RENT.into(), - ::Balance::sa(1_000u64).encode() // rent allowance + ::Balance::from(1_000u32).encode() // rent allowance )); - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); assert_eq!(bob_contract.storage_size, Contract::storage_size_offset() + 4); assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::set_storage_4_byte())); - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); assert_eq!(bob_contract.storage_size, Contract::storage_size_offset() + 4 + 4); assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::remove_storage_4_byte())); - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); assert_eq!(bob_contract.storage_size, Contract::storage_size_offset() + 4); } ); @@ -719,15 +728,15 @@ fn deduct_blocks() { Origin::signed(ALICE), 30_000, 100_000, HASH_SET_RENT.into(), - ::Balance::sa(1_000u64).encode() // rent allowance + ::Balance::from(1_000u32).encode() // rent allowance )); // Check creation - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); assert_eq!(bob_contract.rent_allowance, 1_000); // Advance 4 blocks - System::initialize(&5, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&5, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent through call assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null())); @@ -736,13 +745,13 @@ fn deduct_blocks() { let rent = (8 + 4 - 3) // storage size = size_offset + deploy_set_storage - deposit_offset * 4 // rent byte price * 4; // blocks to rent - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); assert_eq!(bob_contract.rent_allowance, 1_000 - rent); assert_eq!(bob_contract.deduct_block, 5); assert_eq!(Balances::free_balance(BOB), 30_000 - rent); // Advance 7 blocks more - System::initialize(&12, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&12, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent through call assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null())); @@ -751,7 +760,7 @@ fn deduct_blocks() { let rent_2 = (8 + 4 - 2) // storage size = size_offset + deploy_set_storage - deposit_offset * 4 // rent byte price * 7; // blocks to rent - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); assert_eq!(bob_contract.rent_allowance, 1_000 - rent - rent_2); assert_eq!(bob_contract.deduct_block, 12); assert_eq!(Balances::free_balance(BOB), 30_000 - rent - rent_2); @@ -759,7 +768,7 @@ fn deduct_blocks() { // Second call on same block should have no effect on rent assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null())); - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); assert_eq!(bob_contract.rent_allowance, 1_000 - rent - rent_2); assert_eq!(bob_contract.deduct_block, 12); assert_eq!(Balances::free_balance(BOB), 30_000 - rent - rent_2); @@ -812,19 +821,19 @@ fn claim_surcharge(blocks: u64, trigger_call: impl Fn() -> bool, removes: bool) Origin::signed(ALICE), 100, 100_000, HASH_SET_RENT.into(), - ::Balance::sa(1_000u64).encode() // rent allowance + ::Balance::from(1_000u32).encode() // rent allowance )); // Advance blocks - System::initialize(&blocks, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&blocks, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent through call assert!(trigger_call()); if removes { - assert!(super::ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); + assert!(ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); } else { - assert!(super::ContractInfoOf::::get(BOB).unwrap().get_alive().is_some()); + assert!(ContractInfoOf::::get(BOB).unwrap().get_alive().is_some()); } } ); @@ -848,26 +857,26 @@ fn removals(trigger_call: impl Fn() -> bool) { Origin::signed(ALICE), 100, 100_000, HASH_SET_RENT.into(), - ::Balance::sa(1_000u64).encode() // rent allowance + ::Balance::from(1_000u32).encode() // rent allowance )); // Trigger rent must have no effect assert!(trigger_call()); - assert_eq!(super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000); + assert_eq!(ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000); // Advance blocks - System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent through call assert!(trigger_call()); - assert!(super::ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); + assert!(ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); // Advance blocks - System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent must have no effect assert!(trigger_call()); - assert!(super::ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); + assert!(ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); } ); @@ -882,26 +891,26 @@ fn removals(trigger_call: impl Fn() -> bool) { Origin::signed(ALICE), 1_000, 100_000, HASH_SET_RENT.into(), - ::Balance::sa(100u64).encode() // rent allowance + ::Balance::from(100u32).encode() // rent allowance )); // Trigger rent must have no effect assert!(trigger_call()); - assert_eq!(super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 100); + assert_eq!(ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 100); // Advance blocks - System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent through call assert!(trigger_call()); - assert!(super::ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); + assert!(ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); // Advance blocks - System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent must have no effect assert!(trigger_call()); - assert!(super::ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); + assert!(ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); } ); @@ -916,30 +925,30 @@ fn removals(trigger_call: impl Fn() -> bool) { Origin::signed(ALICE), 50+Balances::minimum_balance(), 100_000, HASH_SET_RENT.into(), - ::Balance::sa(1_000u64).encode() // rent allowance + ::Balance::from(1_000u32).encode() // rent allowance )); // Trigger rent must have no effect assert!(trigger_call()); - assert_eq!(super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000); + assert_eq!(ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000); // Transfer funds assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::transfer())); - assert_eq!(super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000); + assert_eq!(ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap().rent_allowance, 1_000); // Advance blocks - System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&10, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent through call assert!(trigger_call()); - assert!(super::ContractInfoOf::::get(BOB).is_none()); + assert!(ContractInfoOf::::get(BOB).is_none()); // Advance blocks - System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&20, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent must have no effect assert!(trigger_call()); - assert!(super::ContractInfoOf::::get(BOB).is_none()); + assert!(ContractInfoOf::::get(BOB).is_none()); } ); } @@ -1014,18 +1023,206 @@ fn default_rent_allowance_on_create() { )); // Check creation - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); assert_eq!(bob_contract.rent_allowance, >::max_value()); // Advance blocks - System::initialize(&5, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&5, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); // Trigger rent through call assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null())); // Check contract is still alive - let bob_contract = super::ContractInfoOf::::get(BOB).unwrap().get_alive(); + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive(); assert!(bob_contract.is_some()) } ); } + +const CODE_RESTORATION: &str = r#" +(module + (import "env" "ext_set_storage" (func $ext_set_storage (param i32 i32 i32 i32))) + (import "env" "ext_dispatch_call" (func $ext_dispatch_call (param i32 i32))) + (import "env" "memory" (memory 1 1)) + + (func (export "call") + (call $ext_dispatch_call + (i32.const 200) ;; Pointer to the start of encoded call buffer + (i32.const 115) ;; Length of the buffer + ) + ) + (func (export "deploy") + ;; Data to restore + (call $ext_set_storage + (i32.const 0) + (i32.const 1) + (i32.const 0) + (i32.const 4) + ) + + ;; ACL + (call $ext_set_storage + (i32.const 100) + (i32.const 1) + (i32.const 0) + (i32.const 4) + ) + ) + + ;; Data to restore + (data (i32.const 0) "\28") + + ;; ACL + (data (i32.const 100) "\01") + + ;; Call + (data (i32.const 200) "\01\05\02\00\00\00\00\00\00\00\21\d6\b1\d5\9a\a6\03\8f\ca\d6\32\48\8e\90" + "\26\89\3a\1b\bb\48\58\17\74\c7\71\b8\f2\43\20\69\7f\05\32\00\00\00\00\00\00\00\08\01\00\00" + "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\01" + "\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00\00" + "\00" + ) +) +"#; +const HASH_RESTORATION: [u8; 32] = hex!("b393bfa8de97b02f08ba1580b46100a80c9489a97c8d870691c9ff7236b29bc7"); + +#[test] +fn restorations_dirty_storage_and_different_storage() { + restoration(true, true); +} + +#[test] +fn restorations_dirty_storage() { + restoration(false, true); +} + +#[test] +fn restoration_different_storage() { + restoration(true, false); +} + +#[test] +fn restoration_success() { + restoration(false, false); +} + +fn restoration(test_different_storage: bool, test_restore_to_with_dirty_storage: bool) { + let acl_key = { + let mut s = [0u8; 32]; + s[0] = 1; + s + }; + + // This test can fail due to the encoding changes. In case it becomes too annoying + // let's rewrite so as we use this module controlled call or we serialize it in runtime. + let encoded = hex::encode(Encode::encode(&Call::Contract(super::Call::restore_to( + BOB, + HASH_SET_RENT.into(), + ::Balance::from(50u32), + vec![acl_key, acl_key], + )))); + + let literal = "0105020000000000000021d6b1d59aa6038fcad632488e9026893a1bbb48581774c771b8f243206\ + 97f053200000000000000080100000000000000000000000000000000000000000000000000000000000000010\ + 0000000000000000000000000000000000000000000000000000000000000"; + + assert_eq!(encoded, literal); + assert_eq!(115, hex::decode(literal).unwrap().len()); + + let restoration_wasm = wabt::wat2wasm(CODE_RESTORATION).unwrap(); + let set_rent_wasm = wabt::wat2wasm(CODE_SET_RENT).unwrap(); + + with_externalities( + &mut ExtBuilder::default().existential_deposit(50).build(), + || { + Balances::deposit_creating(&ALICE, 1_000_000); + assert_ok!(Contract::put_code(Origin::signed(ALICE), 100_000, restoration_wasm)); + assert_ok!(Contract::put_code(Origin::signed(ALICE), 100_000, set_rent_wasm)); + + // If you ever need to update the wasm source this test will fail + // and will show you the actual hash. + assert_eq!(System::events(), vec![ + EventRecord { + phase: Phase::ApplyExtrinsic(0), + event: MetaEvent::balances(balances::RawEvent::NewAccount(1, 1_000_000)), + topics: vec![], + }, + EventRecord { + phase: Phase::ApplyExtrinsic(0), + event: MetaEvent::contract(RawEvent::CodeStored(HASH_RESTORATION.into())), + topics: vec![], + }, + EventRecord { + phase: Phase::ApplyExtrinsic(0), + event: MetaEvent::contract(RawEvent::CodeStored(HASH_SET_RENT.into())), + topics: vec![], + }, + ]); + + assert_ok!(Contract::create( + Origin::signed(ALICE), + 30_000, + 100_000, HASH_SET_RENT.into(), + ::Balance::from(0u32).encode() + )); + + // Check creation + let bob_contract = ContractInfoOf::::get(BOB).unwrap().get_alive().unwrap(); + assert_eq!(bob_contract.rent_allowance, 0); + + if test_different_storage { + assert_ok!(Contract::call( + Origin::signed(ALICE), + BOB, 0, 100_000, + call::set_storage_4_byte()) + ); + } + + // Advance 4 blocks + System::initialize(&5, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); + + // Trigger rent through call + assert_ok!(Contract::call(Origin::signed(ALICE), BOB, 0, 100_000, call::null())); + assert!(ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); + + Balances::deposit_creating(&CHARLIE, 1_000_000); + assert_ok!(Contract::create( + Origin::signed(CHARLIE), + 30_000, + 100_000, HASH_RESTORATION.into(), + ::Balance::from(0u32).encode() + )); + + let django_trie_id = ContractInfoOf::::get(DJANGO).unwrap() + .get_alive().unwrap().trie_id; + + if !test_restore_to_with_dirty_storage { + // Advance 1 blocks + System::initialize(&6, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); + } + + assert_ok!(Contract::call( + Origin::signed(ALICE), + DJANGO, 0, 100_000, + vec![], + )); + + if test_different_storage || test_restore_to_with_dirty_storage { + assert!(ContractInfoOf::::get(BOB).unwrap().get_tombstone().is_some()); + let django_contract = ContractInfoOf::::get(DJANGO).unwrap() + .get_alive().unwrap(); + assert_eq!(django_contract.storage_size, 16); + assert_eq!(django_contract.trie_id, django_trie_id); + assert_eq!(django_contract.deduct_block, System::block_number()); + } else { + let bob_contract = ContractInfoOf::::get(BOB).unwrap() + .get_alive().unwrap(); + assert_eq!(bob_contract.rent_allowance, 50); + assert_eq!(bob_contract.storage_size, 12); + assert_eq!(bob_contract.trie_id, django_trie_id); + assert_eq!(bob_contract.deduct_block, System::block_number()); + assert!(ContractInfoOf::::get(DJANGO).is_none()); + } + } + ); +} diff --git a/srml/contract/src/wasm/code_cache.rs b/srml/contract/src/wasm/code_cache.rs index 0c71fe8cb5b8f9584a86467a01589cca345ea929..da92272c3803a7b9cae15fd26e5fb17861b7cbae 100644 --- a/srml/contract/src/wasm/code_cache.rs +++ b/srml/contract/src/wasm/code_cache.rs @@ -29,7 +29,7 @@ use crate::gas::{GasMeter, Token}; use crate::wasm::{prepare, runtime::Env, PrefabWasmModule}; use crate::{CodeHash, CodeStorage, PristineCode, Schedule, Trait}; use rstd::prelude::*; -use runtime_primitives::traits::{As, CheckedMul, Hash, Bounded}; +use runtime_primitives::traits::{CheckedMul, Hash, Bounded}; use srml_support::StorageMap; /// Gas metering token that used for charging storing code into the code storage. @@ -37,16 +37,15 @@ use srml_support::StorageMap; /// Specifies the code length in bytes. #[cfg_attr(test, derive(Debug, PartialEq, Eq))] #[derive(Copy, Clone)] -pub struct PutCodeToken(u64); +pub struct PutCodeToken(u32); impl Token for PutCodeToken { type Metadata = Schedule; fn calculate_amount(&self, metadata: &Schedule) -> T::Gas { - let code_len_in_gas = >::sa(self.0); metadata .put_code_per_byte_cost - .checked_mul(&code_len_in_gas) + .checked_mul(&self.0.into()) .unwrap_or_else(|| Bounded::max_value()) } } @@ -63,7 +62,7 @@ pub fn save( // The first time instrumentation is on the user. However, consequent reinstrumentation // due to the schedule changes is on governance system. if gas_meter - .charge(schedule, PutCodeToken(original_code.len() as u64)) + .charge(schedule, PutCodeToken(original_code.len() as u32)) .is_out_of_gas() { return Err("there is not enough gas for storing the code"); diff --git a/srml/contract/src/wasm/env_def/macros.rs b/srml/contract/src/wasm/env_def/macros.rs index bfb42d19d01aeb35ba5fb09275db48b7038c5d09..32d02f5abea76f9bd536377878efb257a26216dc 100644 --- a/srml/contract/src/wasm/env_def/macros.rs +++ b/srml/contract/src/wasm/env_def/macros.rs @@ -195,7 +195,7 @@ macro_rules! define_env { mod tests { use parity_wasm::elements::FunctionType; use parity_wasm::elements::ValueType; - use runtime_primitives::traits::{As, Zero}; + use runtime_primitives::traits::Zero; use sandbox::{self, ReturnValue, TypedValue}; use crate::wasm::tests::MockExt; use crate::wasm::Runtime; @@ -256,7 +256,7 @@ mod tests { #[test] fn macro_define_func() { define_func!( ext_gas (_ctx, amount: u32) => { - let amount = <::Gas as As>::sa(amount); + let amount = ::Gas::from(amount); if !amount.is_zero() { Ok(()) } else { @@ -308,7 +308,7 @@ mod tests { define_env!(Env, , ext_gas( _ctx, amount: u32 ) => { - let amount = <::Gas as As>::sa(amount); + let amount = ::Gas::from(amount); if !amount.is_zero() { Ok(()) } else { diff --git a/srml/contract/src/wasm/mod.rs b/srml/contract/src/wasm/mod.rs index 2776f4041b572cd7cd207ae3022387154a25dbc2..d86678d383e0955fa0b2364f6d8f876c85ff721b 100644 --- a/srml/contract/src/wasm/mod.rs +++ b/srml/contract/src/wasm/mod.rs @@ -177,9 +177,10 @@ mod tests { use crate::exec::{CallReceipt, Ext, InstantiateReceipt, EmptyOutputBuf, StorageKey}; use crate::gas::GasMeter; use crate::tests::{Test, Call}; - use wabt; use crate::wasm::prepare::prepare_contract; use crate::CodeHash; + use wabt; + use hex_literal::hex; #[derive(Debug, PartialEq, Eq)] struct DispatchEntry(Call); @@ -207,7 +208,6 @@ mod tests { // (topics, data) events: Vec<(Vec, Vec)>, next_account_id: u64, - random_seed: H256, } impl Ext for MockExt { type T = Test; @@ -276,8 +276,8 @@ mod tests { &1111 } - fn random_seed(&self) -> &H256{ - &self.random_seed + fn random(&self, subject: &[u8]) -> H256 { + H256::from_slice(subject) } fn deposit_event(&mut self, topics: Vec, data: Vec) { @@ -1115,11 +1115,12 @@ mod tests { .unwrap(); } - const CODE_RANDOM_SEED: &str = r#" + const CODE_RANDOM: &str = r#" (module - (import "env" "ext_random_seed" (func $ext_random_seed)) + (import "env" "ext_random" (func $ext_random (param i32 i32))) (import "env" "ext_scratch_size" (func $ext_scratch_size (result i32))) (import "env" "ext_scratch_copy" (func $ext_scratch_copy (param i32 i32 i32))) + (import "env" "ext_return" (func $ext_return (param i32 i32))) (import "env" "memory" (memory 1 1)) (func $assert (param i32) @@ -1133,7 +1134,10 @@ mod tests { (func (export "call") ;; This stores the block random seed in the scratch buffer - (call $ext_random_seed) + (call $ext_random + (i32.const 40) ;; Pointer in memory to the start of the subject buffer + (i32.const 32) ;; The subject buffer's length + ) ;; assert $ext_scratch_size == 32 (call $assert @@ -1150,35 +1154,44 @@ mod tests { (i32.const 32) ;; Count of bytes to copy. ) - ;; assert the contents of the buffer in 4 x i64 parts matches 1,2,3,4. - (call $assert (i64.eq (i64.load (i32.const 8)) (i64.const 1))) - (call $assert (i64.eq (i64.load (i32.const 16)) (i64.const 2))) - (call $assert (i64.eq (i64.load (i32.const 24)) (i64.const 3))) - (call $assert (i64.eq (i64.load (i32.const 32)) (i64.const 4))) + ;; return the data from the contract + (call $ext_return + (i32.const 8) + (i32.const 32) + ) ) (func (export "deploy")) + + ;; [8,40) is reserved for the result of PRNG. + + ;; the subject used for the PRNG. [40,72) + (data (i32.const 40) + "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F" + "\00\01\02\03\04\05\06\07\08\09\0A\0B\0C\0D\0E\0F" + ) ) "#; #[test] - fn random_seed() { + fn random() { let mut mock_ext = MockExt::default(); - let seed: [u8; 32] = [ - 1,0,0,0,0,0,0,0, - 2,0,0,0,0,0,0,0, - 3,0,0,0,0,0,0,0, - 4,0,0,0,0,0,0,0, - ]; - mock_ext.random_seed = H256::from_slice(&seed); let mut gas_meter = GasMeter::with_limit(50_000, 1); + + let mut return_buf = Vec::new(); execute( - CODE_RANDOM_SEED, + CODE_RANDOM, &[], - &mut Vec::new(), + &mut return_buf, &mut mock_ext, &mut gas_meter, ) .unwrap(); + + // The mock ext just returns the same data that was passed as the subject. + assert_eq!( + &return_buf, + &hex!("000102030405060708090A0B0C0D0E0F000102030405060708090A0B0C0D0E0F") + ); } const CODE_DEPOSIT_EVENT: &str = r#" diff --git a/srml/contract/src/wasm/prepare.rs b/srml/contract/src/wasm/prepare.rs index 94a38ef5883f84ef4a1d8dccc37080ecdba7223f..d780cc1a28328ac6c467fefb7f2094d8988080c0 100644 --- a/srml/contract/src/wasm/prepare.rs +++ b/srml/contract/src/wasm/prepare.rs @@ -26,7 +26,7 @@ use parity_wasm::elements::{self, Internal, External, MemoryType, Type}; use pwasm_utils; use pwasm_utils::rules; use rstd::prelude::*; -use runtime_primitives::traits::As; +use runtime_primitives::traits::{UniqueSaturatedInto, SaturatedConversion}; struct ContractModule<'a, Gas: 'a> { /// A deserialized module. The module is valid (this is Guaranteed by `new` method). @@ -38,7 +38,7 @@ struct ContractModule<'a, Gas: 'a> { schedule: &'a Schedule, } -impl<'a, Gas: 'a + As + Clone> ContractModule<'a, Gas> { +impl<'a, Gas: 'a + From + UniqueSaturatedInto + Clone> ContractModule<'a, Gas> { /// Creates a new instance of `ContractModule`. /// /// Returns `Err` if the `original_code` couldn't be decoded or @@ -85,10 +85,10 @@ impl<'a, Gas: 'a + As + Clone> ContractModule<'a, Gas> { fn inject_gas_metering(&mut self) -> Result<(), &'static str> { let gas_rules = rules::Set::new( - self.schedule.regular_op_cost.clone().as_(), + self.schedule.regular_op_cost.clone().saturated_into(), Default::default(), ) - .with_grow_cost(self.schedule.grow_mem_cost.clone().as_()) + .with_grow_cost(self.schedule.grow_mem_cost.clone().saturated_into()) .with_forbidden_floats(); let module = self diff --git a/srml/contract/src/wasm/runtime.rs b/srml/contract/src/wasm/runtime.rs index 6327d8f2cecbe8d60c2f6bf5e868ed3a299ca73c..873464c5bea0a743577611e23113c93db6978828 100644 --- a/srml/contract/src/wasm/runtime.rs +++ b/srml/contract/src/wasm/runtime.rs @@ -27,7 +27,7 @@ use system; use rstd::prelude::*; use rstd::mem; use parity_codec::{Decode, Encode}; -use runtime_primitives::traits::{As, CheckedMul, CheckedAdd, Bounded}; +use runtime_primitives::traits::{CheckedMul, CheckedAdd, Bounded, SaturatedConversion}; /// Enumerates all possible *special* trap conditions. /// @@ -122,24 +122,24 @@ impl Token for RuntimeToken { fn calculate_amount(&self, metadata: &Schedule) -> T::Gas { use self::RuntimeToken::*; let value = match *self { - Explicit(amount) => Some(>::sa(amount)), + Explicit(amount) => Some(amount.into()), ReadMemory(byte_count) => metadata .sandbox_data_read_cost - .checked_mul(&>::sa(byte_count)), + .checked_mul(&byte_count.into()), WriteMemory(byte_count) => metadata .sandbox_data_write_cost - .checked_mul(&>::sa(byte_count)), + .checked_mul(&byte_count.into()), ReturnData(byte_count) => metadata .return_data_per_byte_cost - .checked_mul(&>::sa(byte_count)), + .checked_mul(&byte_count.into()), DepositEvent(topic_count, data_byte_count) => { let data_cost = metadata .event_data_per_byte_cost - .checked_mul(&>::sa(data_byte_count)); + .checked_mul(&data_byte_count.into()); let topics_cost = metadata .event_per_topic_cost - .checked_mul(&>::sa(topic_count)); + .checked_mul(&topic_count.into()); data_cost .and_then(|data_cost| { @@ -340,7 +340,7 @@ define_env!(Env, , let nested_gas_limit = if gas == 0 { ctx.gas_meter.gas_left() } else { - <::Gas as As>::sa(gas) + gas.saturated_into() }; let ext = &mut ctx.ext; let call_outcome = ctx.gas_meter.with_nested(nested_gas_limit, |nested_meter| { @@ -413,7 +413,7 @@ define_env!(Env, , let nested_gas_limit = if gas == 0 { ctx.gas_meter.gas_left() } else { - <::Gas as As>::sa(gas) + gas.saturated_into() }; let ext = &mut ctx.ext; let instantiate_outcome = ctx.gas_meter.with_nested(nested_gas_limit, |nested_meter| { @@ -527,16 +527,25 @@ define_env!(Env, , Ok(()) }, - // Load the latest block RNG seed into the scratch buffer - ext_random_seed(ctx) => { - ctx.scratch_buf = ctx.ext.random_seed().encode(); + // Stores the random number for the current block for the given subject into the scratch + // buffer. + // + // The data is encoded as T::Hash. The current contents of the scratch buffer are + // overwritten. + ext_random(ctx, subject_ptr: u32, subject_len: u32) => { + // The length of a subject can't exceed `max_subject_len`. + if subject_len > ctx.schedule.max_subject_len { + return Err(sandbox::HostError); + } + + let subject_buf = read_sandbox_memory(ctx, subject_ptr, subject_len)?; + ctx.scratch_buf = ctx.ext.random(&subject_buf).encode(); Ok(()) }, // Load the latest block timestamp into the scratch buffer ext_now(ctx) => { - let now: u64 = As::as_(ctx.ext.now().clone()); - ctx.scratch_buf = now.encode(); + ctx.scratch_buf = ctx.ext.now().encode(); Ok(()) }, diff --git a/srml/council/src/lib.rs b/srml/council/src/lib.rs index a13eb7e28067ac66a8ac95ee5c8d2a63f5d85ff1..fd6980573294a9a0372a22f57187ad1c355353b3 100644 --- a/srml/council/src/lib.rs +++ b/srml/council/src/lib.rs @@ -18,34 +18,42 @@ #![cfg_attr(not(feature = "std"), no_std)] -pub mod voting; pub mod motions; pub mod seats; pub use crate::seats::{Trait, Module, RawEvent, Event, VoteIndex}; +/// Trait for type that can handle incremental changes to a set of account IDs. +pub trait OnMembersChanged { + /// A number of members `new` just joined the set and replaced some `old` ones. + fn on_members_changed(new: &[AccountId], old: &[AccountId]); +} + +impl OnMembersChanged for () { + fn on_members_changed(_new: &[T], _old: &[T]) {} +} + #[cfg(test)] mod tests { // These re-exports are here for a reason, edit with care pub use super::*; pub use runtime_io::with_externalities; - use srml_support::{impl_outer_origin, impl_outer_event, impl_outer_dispatch}; - pub use substrate_primitives::H256; - pub use primitives::BuildStorage; - pub use primitives::traits::{BlakeTwo256, IdentityLookup}; - pub use primitives::testing::{Digest, DigestItem, Header}; - pub use substrate_primitives::{Blake2Hasher}; - pub use {seats, motions, voting}; + use srml_support::{impl_outer_origin, impl_outer_event, impl_outer_dispatch, parameter_types}; + pub use substrate_primitives::{H256, Blake2Hasher, u32_trait::{_1, _2, _3, _4}}; + pub use primitives::{ + BuildStorage, traits::{BlakeTwo256, IdentityLookup}, testing::{Digest, DigestItem, Header} + }; + pub use {seats, motions}; impl_outer_origin! { pub enum Origin for Test { - motions + motions } } impl_outer_event! { pub enum Event for Test { - balances, democracy, seats, voting, motions, + balances, democracy, seats, motions, } } @@ -81,71 +89,133 @@ mod tests { type TransferPayment = (); type DustRemoval = (); } + parameter_types! { + pub const LaunchPeriod: u64 = 1; + pub const VotingPeriod: u64 = 3; + pub const MinimumDeposit: u64 = 1; + pub const EnactmentPeriod: u64 = 0; + pub const CooloffPeriod: u64 = 2; + } impl democracy::Trait for Test { - type Currency = balances::Module; type Proposal = Call; type Event = Event; + type Currency = balances::Module; + type EnactmentPeriod = EnactmentPeriod; + type LaunchPeriod = LaunchPeriod; + type EmergencyVotingPeriod = VotingPeriod; + type VotingPeriod = VotingPeriod; + type MinimumDeposit = MinimumDeposit; + type ExternalOrigin = motions::EnsureProportionAtLeast<_1, _2, u64>; + type ExternalMajorityOrigin = motions::EnsureProportionAtLeast<_2, _3, u64>; + type EmergencyOrigin = motions::EnsureProportionAtLeast<_1, _1, u64>; + type CancellationOrigin = motions::EnsureProportionAtLeast<_2, _3, u64>; + type VetoOrigin = motions::EnsureMember; + type CooloffPeriod = CooloffPeriod; } impl seats::Trait for Test { type Event = Event; type BadPresentation = (); type BadReaper = (); + type BadVoterIndex = (); + type LoserCandidate = (); + type OnMembersChanged = CouncilMotions; } impl motions::Trait for Test { type Origin = Origin; type Proposal = Call; type Event = Event; } - impl voting::Trait for Test { - type Event = Event; + + pub struct ExtBuilder { + balance_factor: u64, + decay_ratio: u32, + voting_fee: u64, + voter_bond: u64, + bad_presentation_punishment: u64, + with_council: bool, } - pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities { - let mut t = system::GenesisConfig::::default().build_storage().unwrap().0; - t.extend(balances::GenesisConfig::{ - transaction_base_fee: 0, - transaction_byte_fee: 0, - balances: vec![(1, 10), (2, 20), (3, 30), (4, 40), (5, 50), (6, 60)], - existential_deposit: 0, - transfer_fee: 0, - creation_fee: 0, - vesting: vec![], - }.build_storage().unwrap().0); - t.extend(democracy::GenesisConfig::{ - launch_period: 1, - voting_period: 3, - minimum_deposit: 1, - public_delay: 0, - max_lock_periods: 6, - }.build_storage().unwrap().0); - t.extend(seats::GenesisConfig:: { - candidacy_bond: 9, - voter_bond: 3, - present_slash_per_voter: 1, - carry_count: 2, - inactive_grace_period: 1, - active_council: if with_council { vec![ - (1, 10), - (2, 10), - (3, 10) - ] } else { vec![] }, - approval_voting_period: 4, - presentation_duration: 2, - desired_seats: 2, - term_duration: 5, - }.build_storage().unwrap().0); - t.extend(voting::GenesisConfig:: { - cooloff_period: 2, - voting_period: 1, - enact_delay_period: 0, - }.build_storage().unwrap().0); - runtime_io::TestExternalities::new(t) + impl Default for ExtBuilder { + fn default() -> Self { + Self { + balance_factor: 1, + decay_ratio: 24, + voting_fee: 0, + voter_bond: 0, + bad_presentation_punishment: 1, + with_council: false, + } + } + } + + impl ExtBuilder { + pub fn with_council(mut self, council: bool) -> Self { + self.with_council = council; + self + } + pub fn balance_factor(mut self, factor: u64) -> Self { + self.balance_factor = factor; + self + } + pub fn decay_ratio(mut self, ratio: u32) -> Self { + self.decay_ratio = ratio; + self + } + pub fn voting_fee(mut self, fee: u64) -> Self { + self.voting_fee = fee; + self + } + pub fn bad_presentation_punishment(mut self, fee: u64) -> Self { + self.bad_presentation_punishment = fee; + self + } + pub fn voter_bond(mut self, fee: u64) -> Self { + self.voter_bond = fee; + self + } + pub fn build(self) -> runtime_io::TestExternalities { + let mut t = system::GenesisConfig::::default().build_storage().unwrap().0; + t.extend(balances::GenesisConfig::{ + transaction_base_fee: 0, + transaction_byte_fee: 0, + balances: vec![ + (1, 10 * self.balance_factor), + (2, 20 * self.balance_factor), + (3, 30 * self.balance_factor), + (4, 40 * self.balance_factor), + (5, 50 * self.balance_factor), + (6, 60 * self.balance_factor) + ], + existential_deposit: 0, + transfer_fee: 0, + creation_fee: 0, + vesting: vec![], + }.build_storage().unwrap().0); + t.extend(seats::GenesisConfig:: { + candidacy_bond: 3, + voter_bond: self.voter_bond, + present_slash_per_voter: self.bad_presentation_punishment, + carry_count: 2, + inactive_grace_period: 1, + active_council: if self.with_council { vec![ + (1, 10), + (2, 10), + (3, 10) + ] } else { vec![] }, + approval_voting_period: 4, + presentation_duration: 2, + desired_seats: 2, + decay_ratio: self.decay_ratio, + voting_fee: self.voting_fee, + term_duration: 5, + }.build_storage().unwrap().0); + runtime_io::TestExternalities::new(t) + } } pub type System = system::Module; pub type Balances = balances::Module; pub type Democracy = democracy::Module; pub type Council = seats::Module; - pub type CouncilVoting = voting::Module; pub type CouncilMotions = motions::Module; } diff --git a/srml/council/src/motions.rs b/srml/council/src/motions.rs index e560fadb9c5a49a5a34e7b5b9d45932a480d868c..df357ac8c8769b3900347ffe6af83854fb2de9c3 100644 --- a/srml/council/src/motions.rs +++ b/srml/council/src/motions.rs @@ -16,21 +16,27 @@ //! Council voting system. -use rstd::prelude::*; -use rstd::result; +use rstd::{prelude::*, result}; use substrate_primitives::u32_trait::Value as U32; use primitives::traits::{Hash, EnsureOrigin}; -use srml_support::dispatch::{Dispatchable, Parameter}; -use srml_support::{StorageValue, StorageMap, decl_module, decl_event, decl_storage, ensure}; -use super::{Trait as CouncilTrait, Module as Council}; +use srml_support::{ + dispatch::{Dispatchable, Parameter}, codec::{Encode, Decode}, + StorageValue, StorageMap, decl_module, decl_event, decl_storage, ensure +}; +use super::{Trait as CouncilTrait, Module as Council, OnMembersChanged}; use system::{self, ensure_signed}; /// Simple index type for proposal counting. pub type ProposalIndex = u32; +/// A number of council members. +/// +/// This also serves as a number of voting members, and since for motions, each council member may +/// vote exactly once, therefore also the number of votes for any given motion. +pub type MemberCount = u32; pub trait Trait: CouncilTrait { /// The outer origin type. - type Origin: From; + type Origin: From>; /// The outer call dispatch type. type Proposal: Parameter + Dispatchable::Origin>; @@ -42,31 +48,79 @@ pub trait Trait: CouncilTrait { /// Origin for the council module. #[derive(PartialEq, Eq, Clone)] #[cfg_attr(feature = "std", derive(Debug))] -pub enum Origin { - /// It has been condoned by a given number of council members. - Members(u32), +pub enum RawOrigin { + /// It has been condoned by a given number of council members from a given total. + Members(MemberCount, MemberCount), + /// It has been condoned by a single council member. + Member(AccountId), +} + +/// Origin for the council module. +pub type Origin = RawOrigin<::AccountId>; + +#[derive(PartialEq, Eq, Clone, Encode, Decode)] +#[cfg_attr(feature = "std", derive(Debug))] +/// Info for keeping track of a motion being voted on. +pub struct Votes { + /// The proposal's unique index. + index: ProposalIndex, + /// The number of approval votes that are needed to pass the motion. + threshold: MemberCount, + /// The current set of voters that approved it. + ayes: Vec, + /// The current set of voters that rejected it. + nays: Vec, +} + +decl_storage! { + trait Store for Module as CouncilMotions { + /// The hashes of the active proposals. + pub Proposals get(proposals): Vec; + /// Actual proposal for a given hash, if it's current. + pub ProposalOf get(proposal_of): map T::Hash => Option<::Proposal>; + /// Votes on a given proposal, if it is ongoing. + pub Voting get(voting): map T::Hash => Option>; + /// Proposals so far. + pub ProposalCount get(proposal_count): u32; + } } decl_event!( pub enum Event where ::Hash, ::AccountId { - /// A motion (given hash) has been proposed (by given account) with a threshold (given u32). - Proposed(AccountId, ProposalIndex, Hash, u32), + /// A motion (given hash) has been proposed (by given account) with a threshold (given + /// `MemberCount`). + Proposed(AccountId, ProposalIndex, Hash, MemberCount), /// A motion (given hash) has been voted on by given account, leaving - /// a tally (yes votes and no votes given as u32s respectively). - Voted(AccountId, Hash, bool, u32, u32), + /// a tally (yes votes and no votes given respectively as `MemberCount`). + Voted(AccountId, Hash, bool, MemberCount, MemberCount), /// A motion was approved by the required threshold. Approved(Hash), /// A motion was not approved by the required threshold. Disapproved(Hash), /// A motion was executed; `bool` is true if returned without error. Executed(Hash, bool), + /// A single councillor did some action; `bool` is true if returned without error. + MemberExecuted(Hash, bool), } ); decl_module! { pub struct Module for enum Call where origin: ::Origin { fn deposit_event() = default; - fn propose(origin, #[compact] threshold: u32, proposal: Box<::Proposal>) { + + /// Dispatch a proposal from a councilor using the `Member` origin. + /// + /// Origin must be a council member. + fn execute(origin, proposal: Box<::Proposal>) { + let who = ensure_signed(origin)?; + ensure!(Self::is_councillor(&who), "proposer not on council"); + + let proposal_hash = T::Hashing::hash_of(&proposal); + let ok = proposal.dispatch(RawOrigin::Member(who).into()).is_ok(); + Self::deposit_event(RawEvent::MemberExecuted(proposal_hash, ok)); + } + + fn propose(origin, #[compact] threshold: MemberCount, proposal: Box<::Proposal>) { let who = ensure_signed(origin)?; ensure!(Self::is_councillor(&who), "proposer not on council"); @@ -76,14 +130,16 @@ decl_module! { ensure!(!>::exists(proposal_hash), "duplicate proposals not allowed"); if threshold < 2 { - let ok = proposal.dispatch(Origin::Members(1).into()).is_ok(); + let seats = >::active_council().len() as MemberCount; + let ok = proposal.dispatch(RawOrigin::Members(1, seats).into()).is_ok(); Self::deposit_event(RawEvent::Executed(proposal_hash, ok)); } else { let index = Self::proposal_count(); >::mutate(|i| *i += 1); >::mutate(|proposals| proposals.push(proposal_hash)); >::insert(proposal_hash, *proposal); - >::insert(proposal_hash, (index, threshold, vec![who.clone()], vec![])); + let votes = Votes { index, threshold, ayes: vec![who.clone()], nays: vec![] }; + >::insert(proposal_hash, votes); Self::deposit_event(RawEvent::Proposed(who, index, proposal_hash, threshold)); } @@ -95,46 +151,46 @@ decl_module! { ensure!(Self::is_councillor(&who), "voter not on council"); let mut voting = Self::voting(&proposal).ok_or("proposal must exist")?; - ensure!(voting.0 == index, "mismatched index"); + ensure!(voting.index == index, "mismatched index"); - let position_yes = voting.2.iter().position(|a| a == &who); - let position_no = voting.3.iter().position(|a| a == &who); + let position_yes = voting.ayes.iter().position(|a| a == &who); + let position_no = voting.nays.iter().position(|a| a == &who); if approve { if position_yes.is_none() { - voting.2.push(who.clone()); + voting.ayes.push(who.clone()); } else { return Err("duplicate vote ignored") } if let Some(pos) = position_no { - voting.3.swap_remove(pos); + voting.nays.swap_remove(pos); } } else { if position_no.is_none() { - voting.3.push(who.clone()); + voting.nays.push(who.clone()); } else { return Err("duplicate vote ignored") } if let Some(pos) = position_yes { - voting.2.swap_remove(pos); + voting.ayes.swap_remove(pos); } } - let yes_votes = voting.2.len() as u32; - let no_votes = voting.3.len() as u32; + let yes_votes = voting.ayes.len() as MemberCount; + let no_votes = voting.nays.len() as MemberCount; Self::deposit_event(RawEvent::Voted(who, proposal, approve, yes_votes, no_votes)); - let threshold = voting.1; - let potential_votes = >::active_council().len() as u32; - let approved = yes_votes >= threshold; - let disapproved = potential_votes.saturating_sub(no_votes) < threshold; + let seats = >::active_council().len() as MemberCount; + let approved = yes_votes >= voting.threshold; + let disapproved = seats.saturating_sub(no_votes) < voting.threshold; if approved || disapproved { if approved { Self::deposit_event(RawEvent::Approved(proposal)); // execute motion, assuming it exists. if let Some(p) = >::take(&proposal) { - let ok = p.dispatch(Origin::Members(threshold).into()).is_ok(); + let origin = RawOrigin::Members(voting.threshold, seats).into(); + let ok = p.dispatch(origin).is_ok(); Self::deposit_event(RawEvent::Executed(proposal, ok)); } } else { @@ -153,22 +209,6 @@ decl_module! { } } -decl_storage! { - trait Store for Module as CouncilMotions { - /// The (hashes of) the active proposals. - pub Proposals get(proposals): Vec; - /// Actual proposal for a given hash, if it's current. - pub ProposalOf get(proposal_of): map T::Hash => Option< ::Proposal >; - /// Votes for a given proposal: (required_yes_votes, yes_voters, no_voters). - pub Voting get(voting): map T::Hash => Option<(ProposalIndex, u32, Vec, Vec)>; - /// Proposals so far. - pub ProposalCount get(proposal_count): u32; - } - add_extra_genesis { - build(|_, _, _| {}); - } -} - impl Module { pub fn is_councillor(who: &T::AccountId) -> bool { >::active_council().iter() @@ -176,24 +216,101 @@ impl Module { } } -/// Ensure that the origin `o` represents at least `n` council members. Returns -/// `Ok` or an `Err` otherwise. -pub fn ensure_council_members(o: OuterOrigin, n: u32) -> result::Result - where OuterOrigin: Into> +impl OnMembersChanged for Module { + fn on_members_changed(_new: &[T::AccountId], old: &[T::AccountId]) { + // remove accounts from all current voting in motions. + let mut old = old.to_vec(); + old.sort_unstable(); + for h in Self::proposals().into_iter() { + >::mutate(h, |v| + if let Some(mut votes) = v.take() { + votes.ayes = votes.ayes.into_iter() + .filter(|i| old.binary_search(i).is_err()) + .collect(); + votes.nays = votes.nays.into_iter() + .filter(|i| old.binary_search(i).is_err()) + .collect(); + *v = Some(votes); + } + ); + } + } +} + +/// Ensure that the origin `o` represents at least `n` council members. Returns `Ok` or an `Err` +/// otherwise. +pub fn ensure_council_members(o: OuterOrigin, n: MemberCount) + -> result::Result + where OuterOrigin: Into, OuterOrigin>> { match o.into() { - Some(Origin::Members(x)) if x >= n => Ok(n), + Ok(RawOrigin::Members(x, _)) if x >= n => Ok(n), _ => Err("bad origin: expected to be a threshold number of council members"), } } -pub struct EnsureMembers(::rstd::marker::PhantomData); -impl EnsureOrigin for EnsureMembers - where O: Into> -{ - type Success = u32; - fn ensure_origin(o: O) -> result::Result { - ensure_council_members(o, N::VALUE) +pub struct EnsureMember(::rstd::marker::PhantomData); +impl< + O: Into, O>> + From>, + AccountId +> EnsureOrigin for EnsureMember { + type Success = AccountId; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + RawOrigin::Member(id) => Ok(id), + r => Err(O::from(r)), + }) + } +} + +pub struct EnsureMembers(::rstd::marker::PhantomData<(N, AccountId)>); +impl< + O: Into, O>> + From>, + N: U32, + AccountId, +> EnsureOrigin for EnsureMembers { + type Success = (MemberCount, MemberCount); + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + RawOrigin::Members(n, m) if n >= N::VALUE => Ok((n, m)), + r => Err(O::from(r)), + }) + } +} + +pub struct EnsureProportionMoreThan( + ::rstd::marker::PhantomData<(N, D, AccountId)> +); +impl< + O: Into, O>> + From>, + N: U32, + D: U32, + AccountId, +> EnsureOrigin for EnsureProportionMoreThan { + type Success = (); + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + RawOrigin::Members(n, m) if n * D::VALUE > N::VALUE * m => Ok(()), + r => Err(O::from(r)), + }) + } +} + +pub struct EnsureProportionAtLeast( + ::rstd::marker::PhantomData<(N, D, AccountId)> +); +impl< + O: Into, O>> + From>, + N: U32, + D: U32, + AccountId, +> EnsureOrigin for EnsureProportionAtLeast { + type Success = (); + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + RawOrigin::Members(n, m) if n * D::VALUE >= N::VALUE * m => Ok(()), + r => Err(O::from(r)), + }) } } @@ -203,13 +320,14 @@ mod tests { use super::RawEvent; use crate::tests::*; use crate::tests::{Call, Origin, Event as OuterEvent}; + use primitives::traits::BlakeTwo256; use srml_support::{Hashable, assert_ok, assert_noop}; use system::{EventRecord, Phase}; use hex_literal::hex; #[test] fn motions_basic_environment_works() { - with_externalities(&mut new_test_ext(true), || { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { System::set_block_number(1); assert_eq!(Balances::free_balance(&42), 0); assert_eq!(CouncilMotions::proposals(), Vec::::new()); @@ -221,15 +339,52 @@ mod tests { } #[test] - fn motions_propose_works() { - with_externalities(&mut new_test_ext(true), || { + fn removal_of_old_voters_votes_works() { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { + System::set_block_number(1); + let proposal = set_balance_proposal(42); + let hash = BlakeTwo256::hash_of(&proposal); + assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone()))); + assert_ok!(CouncilMotions::vote(Origin::signed(2), hash.clone(), 0, true)); + assert_eq!( + CouncilMotions::voting(&hash), + Some(Votes { index: 0, threshold: 3, ayes: vec![1, 2], nays: vec![] }) + ); + CouncilMotions::on_members_changed(&[], &[1]); + assert_eq!( + CouncilMotions::voting(&hash), + Some(Votes { index: 0, threshold: 3, ayes: vec![2], nays: vec![] }) + ); + + let proposal = set_balance_proposal(69); + let hash = BlakeTwo256::hash_of(&proposal); + assert_ok!(CouncilMotions::propose(Origin::signed(2), 2, Box::new(proposal.clone()))); + assert_ok!(CouncilMotions::vote(Origin::signed(3), hash.clone(), 1, false)); + assert_eq!( + CouncilMotions::voting(&hash), + Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![3] }) + ); + CouncilMotions::on_members_changed(&[], &[3]); + assert_eq!( + CouncilMotions::voting(&hash), + Some(Votes { index: 1, threshold: 2, ayes: vec![2], nays: vec![] }) + ); + }); + } + + #[test] + fn propose_works() { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash = proposal.blake2_256().into(); assert_ok!(CouncilMotions::propose(Origin::signed(1), 3, Box::new(proposal.clone()))); assert_eq!(CouncilMotions::proposals(), vec![hash]); assert_eq!(CouncilMotions::proposal_of(&hash), Some(proposal)); - assert_eq!(CouncilMotions::voting(&hash), Some((0, 3, vec![1], Vec::::new()))); + assert_eq!( + CouncilMotions::voting(&hash), + Some(Votes { index: 0, threshold: 3, ayes: vec![1], nays: vec![] }) + ); assert_eq!(System::events(), vec![ EventRecord { @@ -243,7 +398,7 @@ mod tests { #[test] fn motions_ignoring_non_council_proposals_works() { - with_externalities(&mut new_test_ext(true), || { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { System::set_block_number(1); let proposal = set_balance_proposal(42); assert_noop!(CouncilMotions::propose(Origin::signed(42), 3, Box::new(proposal.clone())), "proposer not on council"); @@ -252,7 +407,7 @@ mod tests { #[test] fn motions_ignoring_non_council_votes_works() { - with_externalities(&mut new_test_ext(true), || { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); @@ -263,7 +418,7 @@ mod tests { #[test] fn motions_ignoring_bad_index_council_vote_works() { - with_externalities(&mut new_test_ext(true), || { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { System::set_block_number(3); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); @@ -274,15 +429,21 @@ mod tests { #[test] fn motions_revoting_works() { - with_externalities(&mut new_test_ext(true), || { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); assert_ok!(CouncilMotions::propose(Origin::signed(1), 2, Box::new(proposal.clone()))); - assert_eq!(CouncilMotions::voting(&hash), Some((0, 2, vec![1], Vec::::new()))); + assert_eq!( + CouncilMotions::voting(&hash), + Some(Votes { index: 0, threshold: 2, ayes: vec![1], nays: vec![] }) + ); assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, true), "duplicate vote ignored"); assert_ok!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, false)); - assert_eq!(CouncilMotions::voting(&hash), Some((0, 2, Vec::::new(), vec![1]))); + assert_eq!( + CouncilMotions::voting(&hash), + Some(Votes { index: 0, threshold: 2, ayes: vec![], nays: vec![1] }) + ); assert_noop!(CouncilMotions::vote(Origin::signed(1), hash.clone(), 0, false), "duplicate vote ignored"); assert_eq!(System::events(), vec![ @@ -302,7 +463,7 @@ mod tests { #[test] fn motions_disapproval_works() { - with_externalities(&mut new_test_ext(true), || { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); @@ -331,7 +492,7 @@ mod tests { #[test] fn motions_approval_works() { - with_externalities(&mut new_test_ext(true), || { + with_externalities(&mut ExtBuilder::default().with_council(true).build(), || { System::set_block_number(1); let proposal = set_balance_proposal(42); let hash: H256 = proposal.blake2_256().into(); diff --git a/srml/council/src/seats.rs b/srml/council/src/seats.rs index 9ace6227da636a3aecdb0b1fb5031e120edb6dd0..3e80584900aca5475cc37ef79f9763e17d701c23 100644 --- a/srml/council/src/seats.rs +++ b/srml/council/src/seats.rs @@ -17,14 +17,20 @@ //! Council system: Handles the voting in and maintenance of council members. use rstd::prelude::*; -use primitives::traits::{Zero, One, As, StaticLookup}; +use primitives::traits::{Zero, One, StaticLookup, Bounded, Saturating}; use runtime_io::print; use srml_support::{ - StorageValue, StorageMap, dispatch::Result, decl_storage, decl_event, ensure, - traits::{Currency, ReservableCurrency, OnUnbalanced} + StorageValue, StorageMap, + dispatch::Result, decl_storage, decl_event, ensure, decl_module, + traits::{ + Currency, ReservableCurrency, OnUnbalanced, LockIdentifier, + LockableCurrency, WithdrawReasons, WithdrawReason, ExistenceRequirement + } }; use democracy; +use parity_codec::{Encode, Decode}; use system::{self, ensure_signed}; +use super::OnMembersChanged; // no polynomial attacks: // @@ -80,13 +86,51 @@ use system::{self, ensure_signed}; // after each vote as all but K entries are cleared. newly registering candidates must use cleared // entries before they increase the capacity. -use srml_support::decl_module; -pub type VoteIndex = u32; +/// The activity status of a voter. +#[derive(PartialEq, Eq, Copy, Clone, Encode, Decode, Default)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct VoterInfo { + /// Last VoteIndex in which this voter assigned (or initialized) approvals. + last_active: VoteIndex, + /// Last VoteIndex in which one of this voter's approvals won. + /// Note that `last_win = N` indicates a last win at index `N-1`, hence `last_win = 0` means no win ever. + last_win: VoteIndex, + /// The amount of stored weight as a result of not winning but changing approvals. + pot: Balance, + /// Current staked amount. A lock equal to this value always exists. + stake: Balance, +} + +/// Used to demonstrate the status of a particular index in the global voter list. +#[derive(PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub enum CellStatus { + /// Any out of bound index. Means a push a must happen to the chunk pointed by `NextVoterSet`. + /// Voting fee is applied in case a new chunk is created. + Head, + /// Already occupied by another voter. Voting fee is applied. + Occupied, + /// Empty hole which should be filled. No fee will be applied. + Hole, +} + +const COUNCIL_SEATS_ID: LockIdentifier = *b"councils"; + +pub const VOTER_SET_SIZE: usize = 64; +pub const APPROVAL_SET_SIZE: usize = 8; type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; type NegativeImbalanceOf = <::Currency as Currency<::AccountId>>::NegativeImbalance; +type SetIndex = u32; +pub type VoteIndex = u32; + +// all three must be in sync. +type ApprovalFlag = u32; +pub const APPROVAL_FLAG_MASK: ApprovalFlag = 0x8000_0000; +pub const APPROVAL_FLAG_LEN: usize = 32; + pub trait Trait: democracy::Trait { type Event: From> + Into<::Event>; @@ -95,6 +139,14 @@ pub trait Trait: democracy::Trait { /// Handler for the unbalanced reduction when slashing an invalid reaping attempt. type BadReaper: OnUnbalanced>; + + /// Handler for the unbalanced reduction when submitting a bad `voter_index`. + type BadVoterIndex: OnUnbalanced>; + + /// Handler for the unbalanced reduction when a candidate has lost (and is not a runner up) + type LoserCandidate: OnUnbalanced>; + /// What to do when the members change. + type OnMembersChanged: OnMembersChanged; } decl_module! { @@ -103,22 +155,40 @@ decl_module! { /// Set candidate approvals. Approval slots stay valid as long as candidates in those slots /// are registered. - fn set_approvals(origin, votes: Vec, #[compact] index: VoteIndex) -> Result { + /// + /// Locks the total balance of caller indefinitely. + /// Only [`retract_voter`] or [`reap_inactive_voter`] can unlock the balance. + /// + /// `hint` argument is interpreted differently based on: + /// - if `origin` is setting approvals for the first time: The index will be checked + /// for being a valid _hole_ in the voter list. + /// - if the hint is correctly pointing to a hole, no fee is deducted from `origin`. + /// - Otherwise, the call will succeed but the index is ignored and simply a push to the last chunk + /// with free space happens. If the new push causes a new chunk to be created, a fee indicated by + /// [`VotingFee`] is deducted. + /// - if `origin` is already a voter: the index __must__ be valid and point to the correct + /// position of the `origin` in the current voters list. + /// + /// Note that any trailing `false` votes in `votes` is ignored; In approval voting, not voting for a candidate + /// and voting false, are equal. + fn set_approvals(origin, votes: Vec, #[compact] index: VoteIndex, hint: SetIndex) -> Result { let who = ensure_signed(origin)?; - Self::do_set_approvals(who, votes, index) + Self::do_set_approvals(who, votes, index, hint) } /// Set candidate approvals from a proxy. Approval slots stay valid as long as candidates in those slots /// are registered. - fn proxy_set_approvals(origin, votes: Vec, #[compact] index: VoteIndex) -> Result { + fn proxy_set_approvals(origin, votes: Vec, #[compact] index: VoteIndex, hint: SetIndex) -> Result { let who = >::proxy(ensure_signed(origin)?).ok_or("not a proxy")?; - Self::do_set_approvals(who, votes, index) + Self::do_set_approvals(who, votes, index, hint) } /// Remove a voter. For it not to be a bond-consuming no-op, all approved candidate indices /// must now be either unregistered or registered to a candidate that registered the slot after /// the voter gave their last approval set. /// + /// Both indices must be provided as explained in [`voter_at`] function. + /// /// May be called by anyone. Returns the voter deposit to `signed`. fn reap_inactive_voter( origin, @@ -128,34 +198,49 @@ decl_module! { #[compact] assumed_vote_index: VoteIndex ) { let reporter = ensure_signed(origin)?; - let who = T::Lookup::lookup(who)?; + ensure!(!Self::presentation_active(), "cannot reap during presentation period"); - ensure!(Self::voter_last_active(&reporter).is_some(), "reporter must be a voter"); - let last_active = Self::voter_last_active(&who).ok_or("target for inactivity cleanup must be active")?; + ensure!(Self::voter_info(&reporter).is_some(), "reporter must be a voter"); + + let info = Self::voter_info(&who).ok_or("target for inactivity cleanup must be active")?; + let last_active = info.last_active; + ensure!(assumed_vote_index == Self::vote_index(), "vote index not current"); - ensure!(assumed_vote_index > last_active + Self::inactivity_grace_period(), "cannot reap during grace period"); - let voters = Self::voters(); + ensure!( + assumed_vote_index > last_active+ Self::inactivity_grace_period(), + "cannot reap during grace period" + ); + let reporter_index = reporter_index as usize; let who_index = who_index as usize; - ensure!(reporter_index < voters.len() && voters[reporter_index] == reporter, "bad reporter index"); - ensure!(who_index < voters.len() && voters[who_index] == who, "bad target index"); + let assumed_reporter = Self::voter_at(reporter_index).ok_or("invalid reporter index")?; + let assumed_who = Self::voter_at(who_index).ok_or("invalid target index")?; - // will definitely kill one of signed or who now. + ensure!(assumed_reporter == reporter, "bad reporter index"); + ensure!(assumed_who == who, "bad target index"); - let valid = !Self::approvals_of(&who).iter() + // will definitely kill one of reporter or who now. + + let valid = !Self::all_approvals_of(&who).iter() .zip(Self::candidates().iter()) .any(|(&appr, addr)| appr && *addr != T::AccountId::default() && - Self::candidate_reg_info(addr).map_or(false, |x| x.0 <= last_active)/*defensive only: all items in candidates list are registered*/ + // defensive only: all items in candidates list are registered + Self::candidate_reg_info(addr).map_or(false, |x| x.0 <= last_active) ); Self::remove_voter( if valid { &who } else { &reporter }, - if valid { who_index } else { reporter_index }, - voters + if valid { who_index } else { reporter_index } + ); + + T::Currency::remove_lock( + COUNCIL_SEATS_ID, + if valid { &who } else { &reporter } ); + if valid { // This only fails if `reporter` doesn't exist, which it clearly must do since its the origin. // Still, it's no more harmful to propagate any error at this point. @@ -169,23 +254,32 @@ decl_module! { } /// Remove a voter. All votes are cancelled and the voter deposit is returned. + /// + /// The index must be provided as explained in [`voter_at`] function. + /// + /// Also removes the lock on the balance of the voter. See [`do_set_approvals()`]. fn retract_voter(origin, #[compact] index: u32) { let who = ensure_signed(origin)?; ensure!(!Self::presentation_active(), "cannot retract when presenting"); - ensure!(>::exists(&who), "cannot retract non-voter"); - let voters = Self::voters(); + ensure!(>::exists(&who), "cannot retract non-voter"); let index = index as usize; - ensure!(index < voters.len(), "retraction index invalid"); - ensure!(voters[index] == who, "retraction index mismatch"); + let voter = Self::voter_at(index).ok_or("retraction index invalid")?; + ensure!(voter == who, "retraction index mismatch"); - Self::remove_voter(&who, index, voters); + Self::remove_voter(&who, index); T::Currency::unreserve(&who, Self::voting_bond()); + T::Currency::remove_lock(COUNCIL_SEATS_ID, &who); } /// Submit oneself for candidacy. /// /// Account must have enough transferrable funds in it to pay the bond. + /// + /// NOTE: if `origin` has already assigned approvals via [`set_approvals`], + /// it will NOT have any usable funds to pass candidacy bond and must first retract. + /// Note that setting approvals will lock the entire balance of the voter until + /// retraction or being reported. fn submit_candidacy(origin, #[compact] slot: u32) { let who = ensure_signed(origin)?; @@ -214,7 +308,7 @@ decl_module! { } /// Claim that `signed` is one of the top Self::carry_count() + current_vote().1 candidates. - /// Only works if the `block_number >= current_vote().0` and `< current_vote().0 + presentation_duration()`` + /// Only works if the `block_number >= current_vote().0` and `< current_vote().0 + presentation_duration()` /// `signed` should have at least fn present_winner( origin, @@ -223,15 +317,21 @@ decl_module! { #[compact] index: VoteIndex ) -> Result { let who = ensure_signed(origin)?; - ensure!(!total.is_zero(), "stake deposited to present winner and be added to leaderboard should be non-zero"); + ensure!( + !total.is_zero(), + "stake deposited to present winner and be added to leaderboard should be non-zero" + ); let candidate = T::Lookup::lookup(candidate)?; ensure!(index == Self::vote_index(), "index not current"); let (_, _, expiring) = Self::next_finalize().ok_or("cannot present outside of presentation period")?; - let stakes = Self::snapshoted_stakes(); - let voters = Self::voters(); - let bad_presentation_punishment = Self::present_slash_per_voter() * BalanceOf::::sa(voters.len() as u64); - ensure!(T::Currency::can_slash(&who, bad_presentation_punishment), "presenter must have sufficient slashable funds"); + let bad_presentation_punishment = + Self::present_slash_per_voter() + * BalanceOf::::from(Self::voter_count() as u32); + ensure!( + T::Currency::can_slash(&who, bad_presentation_punishment), + "presenter must have sufficient slashable funds" + ); let mut leaderboard = Self::leaderboard().ok_or("leaderboard must exist while present phase active")?; ensure!(total > leaderboard[0].0, "candidate not worthy of leaderboard"); @@ -240,17 +340,24 @@ decl_module! { ensure!(p < expiring.len(), "candidate must not form a duplicated member if elected"); } + let voters = Self::all_voters(); let (registered_since, candidate_index): (VoteIndex, u32) = Self::candidate_reg_info(&candidate).ok_or("presented candidate must be current")?; let actual_total = voters.iter() - .zip(stakes.iter()) - .filter_map(|(voter, stake)| - match Self::voter_last_active(voter) { - Some(b) if b >= registered_since => - Self::approvals_of(voter).get(candidate_index as usize) - .and_then(|approved| if *approved { Some(*stake) } else { None }), - _ => None, - }) + .filter_map(|maybe_voter| maybe_voter.as_ref()) + .filter_map(|voter| match Self::voter_info(voter) { + Some(b) if b.last_active >= registered_since => { + let last_win = b.last_win; + let now = Self::vote_index(); + let stake = b.stake; + let offset = Self::get_offset(stake, now - last_win); + let weight = stake + offset + b.pot; + if Self::approvals_of_at(voter, candidate_index as usize) { + Some(weight) + } else { None } + }, + _ => None, + }) .fold(Zero::zero(), |acc, n| acc + n); let dupe = leaderboard.iter().find(|&&(_, ref c)| c == &candidate).is_some(); if total == actual_total && !dupe { @@ -269,15 +376,16 @@ decl_module! { } /// Set the desired member count; if lower than the current count, then seats will not be up - /// election when they expire. If more, then a new vote will be started if one is not already - /// in progress. + /// election when they expire. If more, then a new vote will be started if one is not + /// already in progress. fn set_desired_seats(#[compact] count: u32) { >::put(count); } - /// Remove a particular member. A tally will happen instantly (if not already in a presentation + /// Remove a particular member from the council. This is effective immediately. + /// + /// Note: A tally should happen instantly (if not already in a presentation /// period) to fill the seat if removal means that the desired members are not met. - /// This is effective immediately. fn remove_member(who: ::Source) { let who = T::Lookup::lookup(who)?; let new_council: Vec<(T::AccountId, T::BlockNumber)> = Self::active_council() @@ -285,6 +393,7 @@ decl_module! { .filter(|i| i.0 != who) .collect(); >::put(new_council); + T::OnMembersChanged::on_members_changed(&[], &[who]); } /// Set the presentation duration. If there is currently a vote being presented for, will @@ -299,7 +408,7 @@ decl_module! { >::put(count); } - fn on_finalize(n: T::BlockNumber) { + fn on_initialize(n: T::BlockNumber) { if let Err(e) = Self::end_block(n) { print("Guru meditation"); print(e); @@ -311,57 +420,71 @@ decl_module! { decl_storage! { trait Store for Module as Council { - // parameters + // ---- parameters /// How much should be locked up in order to submit one's candidacy. - pub CandidacyBond get(candidacy_bond) config(): BalanceOf = BalanceOf::::sa(9); + pub CandidacyBond get(candidacy_bond) config(): BalanceOf = 9.into(); /// How much should be locked up in order to be able to submit votes. pub VotingBond get(voting_bond) config(voter_bond): BalanceOf; + /// The amount of fee paid upon each vote submission, unless if they submit a _hole_ index and replace it. + pub VotingFee get(voting_fee) config(voting_fee): BalanceOf; /// The punishment, per voter, if you provide an invalid presentation. - pub PresentSlashPerVoter get(present_slash_per_voter) config(): BalanceOf = BalanceOf::::sa(1); + pub PresentSlashPerVoter get(present_slash_per_voter) config(): BalanceOf = 1.into(); /// How many runners-up should have their approvals persist until the next vote. pub CarryCount get(carry_count) config(): u32 = 2; /// How long to give each top candidate to present themselves after the vote ends. - pub PresentationDuration get(presentation_duration) config(): T::BlockNumber = T::BlockNumber::sa(1000); - /// How many vote indexes need to go by after a target voter's last vote before they can be reaped if their + pub PresentationDuration get(presentation_duration) config(): T::BlockNumber = 1000.into(); + /// How many vote indices need to go by after a target voter's last vote before they can be reaped if their /// approvals are moot. pub InactiveGracePeriod get(inactivity_grace_period) config(inactive_grace_period): VoteIndex = 1; /// How often (in blocks) to check for new votes. - pub VotingPeriod get(voting_period) config(approval_voting_period): T::BlockNumber = T::BlockNumber::sa(1000); + pub VotingPeriod get(voting_period) config(approval_voting_period): T::BlockNumber = 1000.into(); /// How long each position is active for. - pub TermDuration get(term_duration) config(): T::BlockNumber = T::BlockNumber::sa(5); + pub TermDuration get(term_duration) config(): T::BlockNumber = 5.into(); /// Number of accounts that should be sitting on the council. pub DesiredSeats get(desired_seats) config(): u32; + /// Decay factor of weight when being accumulated. It should typically be set to + /// __at least__ `council_size -1` to keep the council secure. + /// When set to `N`, it indicates `(1/N)^t` of staked is decayed at weight increment step `t`. + /// 0 will result in no weight being added at all (normal approval voting). + pub DecayRatio get(decay_ratio) config(decay_ratio): u32 = 24; - // permanent state (always relevant, changes only at the finalization of voting) + // ---- permanent state (always relevant, changes only at the finalization of voting) /// The current council. When there's a vote going on, this should still be used for executive /// matters. The block number (second element in the tuple) is the block that their position is /// active until (calculated by the sum of the block number when the council member was elected /// and their term duration). pub ActiveCouncil get(active_council) config(): Vec<(T::AccountId, T::BlockNumber)>; - /// The total number of votes that have happened or are in progress. + /// The total number of vote rounds that have happened or are in progress. pub VoteCount get(vote_index): VoteIndex; - // persistent state (always relevant, changes constantly) - /// A list of votes for each voter, respecting the last cleared vote index that this voter was - /// last active at. - pub ApprovalsOf get(approvals_of): map T::AccountId => Vec; + // ---- persistent state (always relevant, changes constantly) + /// A list of votes for each voter. The votes are stored as numeric values and parsed in a bit-wise manner. + /// + /// In order to get a human-readable representation (`Vec`), use [`all_approvals_of`]. + /// + /// Furthermore, each vector of scalars is chunked with the cap of `APPROVAL_SET_SIZE`. + pub ApprovalsOf get(approvals_of): map (T::AccountId, SetIndex) => Vec; /// The vote index and list slot that the candidate `who` was registered or `None` if they are not /// currently registered. pub RegisterInfoOf get(candidate_reg_info): map T::AccountId => Option<(VoteIndex, u32)>; - /// The last cleared vote index that this voter was last active at. - pub LastActiveOf get(voter_last_active): map T::AccountId => Option; - /// The present voter list. - pub Voters get(voters): Vec; + /// Basic information about a voter. + pub VoterInfoOf get(voter_info): map T::AccountId => Option>>; + /// The present voter list (chunked and capped at [`VOTER_SET_SIZE`]). + pub Voters get(voters): map SetIndex => Vec>; + /// the next free set to store a voter in. This will keep growing. + pub NextVoterSet get(next_nonfull_voter_set): SetIndex = 0; + /// Current number of Voters. + pub VoterCount get(voter_count): SetIndex = 0; /// The present candidate list. pub Candidates get(candidates): Vec; // has holes + /// Current number of active candidates pub CandidateCount get(candidate_count): u32; - // temporary state (only relevant during finalization/presentation) + // ---- temporary state (only relevant during finalization/presentation) /// The accounts holding the seats that will become free on the next tally. pub NextFinalize get(next_finalize): Option<(T::BlockNumber, u32, Vec)>; - /// The stakes as they were at the point that the vote ended. - pub SnapshotedStakes get(snapshoted_stakes): Vec>; - /// Get the leaderboard if we;re in the presentation phase. + /// Get the leaderboard if we're in the presentation phase. The first element is the weight of each entry; + /// It may be the direct summed approval stakes, or a weighted version of it. pub Leaderboard get(leaderboard): Option, T::AccountId)> >; // ORDERED low -> high } } @@ -392,6 +515,14 @@ impl Module { >::exists(who) } + /// Iff the councillor `who` still has a seat at blocknumber `n` returns `true`. + pub fn will_still_be_councillor_at(who: &T::AccountId, n: T::BlockNumber) -> bool { + Self::active_council().iter() + .find(|&&(ref a, _)| a == who) + .map(|&(_, expires)| expires > n) + .unwrap_or(false) + } + /// Determine the block that a vote can happen on which is no less than `n`. pub fn next_vote_from(n: T::BlockNumber) -> T::BlockNumber { let voting_period = Self::voting_period(); @@ -446,15 +577,21 @@ impl Module { Ok(()) } - /// Remove a voter from the system. Trusts that Self::voters()[index] != voter. - fn remove_voter(voter: &T::AccountId, index: usize, mut voters: Vec) { - >::put({ voters.swap_remove(index); voters }); - >::remove(voter); - >::remove(voter); + /// Remove a voter at a specified index from the system. + fn remove_voter(voter: &T::AccountId, index: usize) { + let (set_index, vec_index) = Self::split_index(index, VOTER_SET_SIZE); + let mut set = Self::voters(set_index); + set[vec_index] = None; + >::insert(set_index, set); + >::mutate(|c| *c = *c - 1); + Self::remove_all_approvals_of(voter); + >::remove(voter); } - // Actually do the voting. - fn do_set_approvals(who: T::AccountId, votes: Vec, index: VoteIndex) -> Result { + /// Actually do the voting. + /// + /// The voter index must be provided as explained in [`voter_at`] function. + fn do_set_approvals(who: T::AccountId, votes: Vec, index: VoteIndex, hint: SetIndex) -> Result { let candidates = Self::candidates(); ensure!(!Self::presentation_active(), "no approval changes during presentation period"); @@ -463,39 +600,98 @@ impl Module { // Prevent a vote from voters that provide a list of votes that exceeds the candidates length // since otherwise an attacker may be able to submit a very long list of `votes` that far exceeds // the amount of candidates and waste more computation than a reasonable voting bond would cover. - ensure!(candidates.len() >= votes.len(), "amount of candidate approval votes cannot exceed amount of candidates"); + ensure!(candidates.len() >= votes.len(), "amount of candidate votes cannot exceed amount of candidates"); + + // Amount to be locked up. + let mut locked_balance = T::Currency::total_balance(&who); + let mut pot_to_set = Zero::zero(); + let hint = hint as usize; + + if let Some(info) = Self::voter_info(&who) { + // already a voter. Index must be valid. No fee. update pot. O(1) + let voter = Self::voter_at(hint).ok_or("invalid voter index")?; + ensure!(voter == who, "wrong voter index"); + + // write new accumulated offset. + let last_win = info.last_win; + let now = index; + let offset = Self::get_offset(info.stake, now - last_win); + pot_to_set = info.pot + offset; + } else { + // not yet a voter. Index _could be valid_. Fee might apply. Bond will be reserved O(1). + ensure!( + T::Currency::free_balance(&who) > Self::voting_bond(), + "new voter must have sufficient funds to pay the bond" + ); - if !>::exists(&who) { - // not yet a voter - deduct bond. - // NOTE: this must be the last potential bailer, since it changes state. - T::Currency::reserve(&who, Self::voting_bond())?; + let (set_index, vec_index) = Self::split_index(hint, VOTER_SET_SIZE); + match Self::cell_status(set_index, vec_index) { + CellStatus::Hole => { + // requested cell was a valid hole. + >::mutate(set_index, |set| set[vec_index] = Some(who.clone())); + }, + CellStatus::Head | CellStatus::Occupied => { + // Either occupied or out-of-range. + let next = Self::next_nonfull_voter_set(); + let mut set = Self::voters(next); + // Caused a new set to be created. Pay for it. + // This is the last potential error. Writes will begin afterwards. + if set.is_empty() { + let imbalance = T::Currency::withdraw( + &who, + Self::voting_fee(), + WithdrawReason::Fee, + ExistenceRequirement::KeepAlive, + )?; + T::BadVoterIndex::on_unbalanced(imbalance); + // NOTE: this is safe since the `withdraw()` will check this. + locked_balance -= Self::voting_fee(); + } + Self::checked_push_voter(&mut set, who.clone(), next); + >::insert(next, set); + } + } - >::mutate(|v| v.push(who.clone())); + T::Currency::reserve(&who, Self::voting_bond())?; + >::mutate(|c| *c = *c + 1); } - >::insert(&who, index); - >::insert(&who, votes); + + T::Currency::set_lock( + COUNCIL_SEATS_ID, + &who, + locked_balance, + T::BlockNumber::max_value(), + WithdrawReasons::all() + ); + + >::insert( + &who, + VoterInfo::> { + last_active: index, + last_win: index, + stake: locked_balance, + pot: pot_to_set, + } + ); + Self::set_approvals_chunked(&who, votes); Ok(()) } - /// Close the voting, snapshot the staking and the number of seats that are actually up for grabs. + /// Close the voting, record the number of seats that are actually up for grabs. fn start_tally() { let active_council = Self::active_council(); let desired_seats = Self::desired_seats() as usize; let number = >::block_number(); - let expiring = active_council.iter().take_while(|i| i.1 == number).map(|i| i.0.clone()).collect::>(); + let expiring = active_council.iter().take_while(|i| i.1 <= number).map(|i| i.0.clone()).collect::>(); let retaining_seats = active_council.len() - expiring.len(); if retaining_seats < desired_seats { let empty_seats = desired_seats - retaining_seats; >::put((number + Self::presentation_duration(), empty_seats as u32, expiring)); - let voters = Self::voters(); - let votes = voters.iter().map(T::Currency::total_balance).collect::>(); - >::put(votes); - // initialize leaderboard. let leaderboard_size = empty_seats + Self::carry_count() as usize; - >::put(vec![(BalanceOf::::zero(), T::AccountId::default()); leaderboard_size]); + >::put(vec![(Zero::zero(), T::AccountId::default()); leaderboard_size]); Self::deposit_event(RawEvent::TallyStarted(empty_seats as u32)); } @@ -506,7 +702,6 @@ impl Module { /// a new vote is started. /// Clears all presented candidates, returning the bond of the elected ones. fn finalize_tally() -> Result { - >::kill(); let (_, coming, expiring): (T::BlockNumber, u32, Vec) = >::take().ok_or("finalize can only be called after a tally is started.")?; let leaderboard: Vec<(BalanceOf, T::AccountId)> = >::take().unwrap_or_default(); @@ -514,16 +709,30 @@ impl Module { // return bond to winners. let candidacy_bond = Self::candidacy_bond(); - let incoming: Vec = leaderboard.iter() + let incoming: Vec<_> = leaderboard.iter() .rev() .take_while(|&&(b, _)| !b.is_zero()) .take(coming as usize) .map(|(_, a)| a) .cloned() - .inspect(|a| {T::Currency::unreserve(a, candidacy_bond);}) + .inspect(|a| { T::Currency::unreserve(a, candidacy_bond); }) .collect(); + + // Update last win index for anyone voted for any of the incomings. + incoming.iter().filter_map(|i| Self::candidate_reg_info(i)).for_each(|r| { + let index = r.1 as usize; + Self::all_voters() + .iter() + .filter_map(|mv| mv.as_ref()) + .filter(|v| Self::approvals_of_at(*v, index)) + .for_each(|v| >::mutate(v, |a| { + if let Some(activity) = a { activity.last_win = Self::vote_index() + 1; } + })); + }); let active_council = Self::active_council(); - let outgoing = active_council.iter().take(expiring.len()).map(|a| a.0.clone()).collect(); + let outgoing: Vec<_> = active_council.iter() + .take(expiring.len()) + .map(|a| a.0.clone()).collect(); // set the new council. let mut new_council: Vec<_> = active_council @@ -534,6 +743,8 @@ impl Module { new_council.sort_by_key(|&(_, expiry)| expiry); >::put(new_council); + T::OnMembersChanged::on_members_changed(&incoming, &outgoing); + // clear all except runners-up from candidate list. let candidates = Self::candidates(); let mut new_candidates = vec![T::AccountId::default(); candidates.len()]; // shrink later. @@ -565,6 +776,205 @@ impl Module { >::put(Self::vote_index() + 1); Ok(()) } + + fn checked_push_voter(set: &mut Vec>, who: T::AccountId, index: u32) { + let len = set.len(); + + // Defensive only: this should never happen. Don't push since it will break more things. + if len == VOTER_SET_SIZE { return; } + + set.push(Some(who)); + if len + 1 == VOTER_SET_SIZE { + >::put(index + 1); + } + } + + /// Get the set and vector index of a global voter index. + /// + /// Note that this function does not take holes into account. + /// See [`voter_at`]. + fn split_index(index: usize, scale: usize) -> (SetIndex, usize) { + let set_index = (index / scale) as u32; + let vec_index = index % scale; + (set_index, vec_index) + } + + /// Return a concatenated vector over all voter sets. + fn all_voters() -> Vec> { + let mut all = >::get(0); + let mut index = 1; + // NOTE: we could also use `Self::next_nonfull_voter_set()` here but that might change based + // on how we do chunking. This is more generic. + loop { + let next_set = >::get(index); + if next_set.is_empty() { + break; + } else { + index += 1; + all.extend(next_set); + } + } + all + } + + /// Shorthand for fetching a voter at a specific (global) index. + /// + /// NOTE: this function is used for checking indices. Yet, it does not take holes into account. + /// This means that any account submitting an index at any point in time should submit: + /// `VOTER_SET_SIZE * set_index + local_index`, meaning that you are ignoring all holes in the + /// first `set_index` sets. + fn voter_at(index: usize) -> Option { + let (set_index, vec_index) = Self::split_index(index, VOTER_SET_SIZE); + let set = Self::voters(set_index); + if vec_index < set.len() { + set[vec_index].clone() + } else { + None + } + } + + /// A more sophisticated version of `voter_at`. Will be kept separate as most often it is an overdue + /// compared to `voter_at`. Only used when setting approvals. + fn cell_status(set_index: SetIndex, vec_index: usize) -> CellStatus { + let set = Self::voters(set_index); + if vec_index < set.len() { + if let Some(_) = set[vec_index] { + CellStatus::Occupied + } else { + CellStatus::Hole + } + } else { + CellStatus::Head + } + } + + /// Sets the approval of a voter in a chunked manner. + fn set_approvals_chunked(who: &T::AccountId, approvals: Vec) { + let approvals_flag_vec = Self::bool_to_flag(approvals); + approvals_flag_vec + .chunks(APPROVAL_SET_SIZE) + .enumerate() + .for_each(|(index, slice)| >::insert((who.clone(), index as SetIndex), slice.to_vec())); + } + + /// shorthand for fetching a specific approval of a voter at a specific (global) index. + /// + /// Using this function to read a vote is preferred as it reads `APPROVAL_SET_SIZE` items of type + /// `ApprovalFlag` from storage at most; not all of them. + /// + /// Note that false is returned in case of no-vote or an explicit `false`. + fn approvals_of_at(who: &T::AccountId, index: usize) -> bool { + let (flag_index, bit) = Self::split_index(index, APPROVAL_FLAG_LEN); + let (set_index, vec_index) = Self::split_index(flag_index as usize, APPROVAL_SET_SIZE); + let set = Self::approvals_of((who.clone(), set_index)); + if vec_index < set.len() { + // This is because bit_at treats numbers in lsb -> msb order. + let reversed_index = set.len() - 1 - vec_index; + Self::bit_at(set[reversed_index], bit) + } else { + false + } + } + + /// Return true of the bit `n` of scalar `x` is set to `1` and false otherwise. + fn bit_at(x: ApprovalFlag, n: usize) -> bool { + if n < APPROVAL_FLAG_LEN { + // x & ( APPROVAL_FLAG_MASK >> n ) != 0 + x & ( 1 << n ) != 0 + } else { + false + } + } + + /// Convert a vec of boolean approval flags to a vec of integers, as denoted by + /// the type `ApprovalFlag`. see `bool_to_flag_should_work` test for examples. + pub fn bool_to_flag(x: Vec) -> Vec { + let mut result: Vec = Vec::with_capacity(x.len() / APPROVAL_FLAG_LEN); + if x.is_empty() { + return result; + } + result.push(0); + let mut index = 0; + let mut counter = 0; + loop { + let shl_index = counter % APPROVAL_FLAG_LEN; + result[index] += (if x[counter] { 1 } else { 0 }) << shl_index; + counter += 1; + if counter > x.len() - 1 { break; } + if counter % APPROVAL_FLAG_LEN == 0 { + result.push(0); + index += 1; + } + } + result + } + + /// Convert a vec of flags (u32) to boolean. + pub fn flag_to_bool(chunk: Vec) -> Vec { + let mut result = Vec::with_capacity(chunk.len()); + if chunk.is_empty() { return vec![] } + chunk.into_iter() + .map(|num| (0..APPROVAL_FLAG_LEN).map(|bit| Self::bit_at(num, bit)).collect::>()) + .for_each(|c| { + let last_approve = match c.iter().rposition(|n| *n) { + Some(index) => index + 1, + None => 0 + }; + result.extend(c.into_iter().take(last_approve)); + }); + result + } + + /// Return a concatenated vector over all approvals of a voter as boolean. + /// The trailing zeros are removed. + fn all_approvals_of(who: &T::AccountId) -> Vec { + let mut all: Vec = vec![]; + let mut index = 0_u32; + loop { + let chunk = Self::approvals_of((who.clone(), index)); + if chunk.is_empty() { break; } + all.extend(Self::flag_to_bool(chunk)); + index += 1; + } + all + } + + /// Remove all approvals associated with one account. + fn remove_all_approvals_of(who: &T::AccountId) { + let mut index = 0; + loop { + let set = Self::approvals_of((who.clone(), index)); + if set.len() > 0 { + >::remove((who.clone(), index)); + index += 1; + } else { + break + } + } + } + + /// Calculates the offset value (stored pot) of a stake, based on the distance + /// to the last win_index, `t`. Regardless of the internal implementation, + /// it should always be used with the following structure: + /// + /// Given Stake of voter `V` being `x` and distance to last_win index `t`, the new weight + /// of `V` is `x + get_offset(x, t)`. + /// + /// In other words, this function returns everything extra that should be added + /// to a voter's stake value to get the correct weight. Indeed, zero is + /// returned if `t` is zero. + fn get_offset(stake: BalanceOf, t: VoteIndex) -> BalanceOf { + let decay_ratio: BalanceOf = Self::decay_ratio().into(); + if t > 150 { return stake * decay_ratio } + let mut offset = stake; + let mut r = Zero::zero(); + let decay = decay_ratio + One::one(); + for _ in 0..t { + offset = offset.saturating_sub(offset / decay); + r += offset + } + r + } } #[cfg(test)] @@ -573,16 +983,86 @@ mod tests { use crate::tests::*; use srml_support::{assert_ok, assert_noop, assert_err}; + fn voter_ids() -> Vec { + Council::all_voters().iter().map(|v| v.unwrap_or(0) ).collect::>() + } + + fn vote(i: u64, l: usize) { + let _ = Balances::make_free_balance_be(&i, 20); + assert_ok!(Council::set_approvals(Origin::signed(i), (0..l).map(|_| true).collect::>(), 0, 0)); + } + + fn vote_at(i: u64, l: usize, index: VoteIndex) { + let _ = Balances::make_free_balance_be(&i, 20); + assert_ok!(Council::set_approvals(Origin::signed(i), (0..l).map(|_| true).collect::>(), 0, index)); + } + + fn create_candidate(i: u64, index: u32) { + let _ = Balances::make_free_balance_be(&i, 20); + assert_ok!(Council::submit_candidacy(Origin::signed(i), index)); + } + + fn bond() -> u64 { + Council::voting_bond() + } + + + #[test] + fn bool_to_flag_should_work() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_eq!(Council::bool_to_flag(vec![]), vec![]); + assert_eq!(Council::bool_to_flag(vec![false]), vec![0]); + assert_eq!(Council::bool_to_flag(vec![true]), vec![1]); + assert_eq!(Council::bool_to_flag(vec![true, true, true, true]), vec![15]); + assert_eq!(Council::bool_to_flag(vec![true, true, true, true, true]), vec![15 + 16]); + + let set_1 = vec![ + true, false, false, false, // 0x1 + false, true, true, true, // 0xE + ]; + assert_eq!( + Council::bool_to_flag(set_1.clone()), + vec![0x00_00_00_E1_u32] + ); + assert_eq!( + Council::flag_to_bool(vec![0x00_00_00_E1_u32]), + set_1 + ); + + let set_2 = vec![ + false, false, false, true, // 0x8 + false, true, false, true, // 0xA + ]; + assert_eq!( + Council::bool_to_flag(set_2.clone()), + vec![0x00_00_00_A8_u32] + ); + assert_eq!( + Council::flag_to_bool(vec![0x00_00_00_A8_u32]), + set_2 + ); + + let mut rhs = (0..100/APPROVAL_FLAG_LEN).map(|_| 0xFFFFFFFF_u32).collect::>(); + // NOTE: this might be need change based on `APPROVAL_FLAG_LEN`. + rhs.extend(vec![0x00_00_00_0F]); + assert_eq!( + Council::bool_to_flag((0..100).map(|_| true).collect()), + rhs + ) + }) + } + #[test] fn params_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_eq!(Council::next_vote_from(1), 4); assert_eq!(Council::next_vote_from(4), 4); assert_eq!(Council::next_vote_from(5), 8); assert_eq!(Council::vote_index(), 0); - assert_eq!(Council::candidacy_bond(), 9); - assert_eq!(Council::voting_bond(), 3); + assert_eq!(Council::candidacy_bond(), 3); + assert_eq!(Council::voting_bond(), 0); + assert_eq!(Council::voting_fee(), 0); assert_eq!(Council::present_slash_per_voter(), 1); assert_eq!(Council::presentation_duration(), 2); assert_eq!(Council::inactivity_grace_period(), 1); @@ -600,15 +1080,225 @@ mod tests { assert_eq!(Council::is_a_candidate(&1), false); assert_eq!(Council::candidate_reg_info(1), None); - assert_eq!(Council::voters(), Vec::::new()); - assert_eq!(Council::voter_last_active(1), None); - assert_eq!(Council::approvals_of(1), vec![]); + assert_eq!(Council::voters(0), Vec::>::new()); + assert_eq!(Council::voter_info(1), None); + assert_eq!(Council::all_approvals_of(&1), vec![]); + }); + } + + #[test] + fn voter_set_growth_should_work() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); + + // create 65. 64 (set0) + 1 (set1) + (1..=63).for_each(|i| vote(i, 2)); + assert_eq!(Council::next_nonfull_voter_set(), 0); + vote(64, 2); + assert_eq!(Council::next_nonfull_voter_set(), 1); + vote(65, 2); + + let set1 = Council::voters(0); + let set2 = Council::voters(1); + + assert_eq!(set1.len(), 64); + assert_eq!(set2.len(), 1); + + assert_eq!(set1[0], Some(1)); + assert_eq!(set1[10], Some(11)); + assert_eq!(set2[0], Some(65)); + }) + } + + #[test] + fn voter_set_reclaim_should_work() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); + + (1..=129).for_each(|i| vote(i, 2)); + assert_eq!(Council::next_nonfull_voter_set(), 2); + + assert_ok!(Council::retract_voter(Origin::signed(11), 10)); + + assert_ok!(Council::retract_voter(Origin::signed(66), 65)); + assert_ok!(Council::retract_voter(Origin::signed(67), 66)); + + // length does not show it but holes do exist. + assert_eq!(Council::voters(0).len(), 64); + assert_eq!(Council::voters(1).len(), 64); + assert_eq!(Council::voters(2).len(), 1); + + assert_eq!(Council::voters(0)[10], None); + assert_eq!(Council::voters(1)[1], None); + assert_eq!(Council::voters(1)[2], None); + // Next set with capacity is 2. + assert_eq!(Council::next_nonfull_voter_set(), 2); + + // But we can fill a hole. + vote_at(130, 2, 10); + + // Nothing added to set 2. A hole was filled. + assert_eq!(Council::voters(0).len(), 64); + assert_eq!(Council::voters(1).len(), 64); + assert_eq!(Council::voters(2).len(), 1); + + // and the next two (scheduled) to the second set. + assert_eq!(Council::next_nonfull_voter_set(), 2); + }) + } + + #[test] + fn approvals_set_growth_should_work() { + with_externalities(&mut ExtBuilder::default().build(), || { + // create candidates and voters. + (1..=250).for_each(|i| create_candidate(i, (i-1) as u32)); + (1..=250).for_each(|i| vote(i, i as usize)); + + // all approvals of should return the exact expected vector. + assert_eq!(Council::all_approvals_of(&180), (0..180).map(|_| true).collect::>()); + + assert_eq!(Council::all_approvals_of(&32), (0..32).map(|_| true).collect::>()); + assert_eq!(Council::all_approvals_of(&8), (0..8).map(|_| true).collect::>()); + assert_eq!(Council::all_approvals_of(&64), (0..64).map(|_| true).collect::>()); + assert_eq!(Council::all_approvals_of(&65), (0..65).map(|_| true).collect::>()); + assert_eq!(Council::all_approvals_of(&63), (0..63).map(|_| true).collect::>()); + + // NOTE: assuming that APPROVAL_SET_SIZE is more or less small-ish. Might fail otherwise. + let full_sets = (180 / APPROVAL_FLAG_LEN) / APPROVAL_SET_SIZE; + let left_over = (180 / APPROVAL_FLAG_LEN) / APPROVAL_SET_SIZE; + let rem = 180 % APPROVAL_FLAG_LEN; + + // grab and check the last full set, if it exists. + if full_sets > 0 { + assert_eq!( + Council::approvals_of((180, (full_sets-1) as SetIndex )), + Council::bool_to_flag((0..APPROVAL_SET_SIZE * APPROVAL_FLAG_LEN).map(|_| true).collect::>()) + ); + } + + // grab and check the last, half-empty, set. + if left_over > 0 { + assert_eq!( + Council::approvals_of((180, full_sets as SetIndex)), + Council::bool_to_flag((0..left_over * APPROVAL_FLAG_LEN + rem).map(|_| true).collect::>()) + ); + } + }) + } + + + #[test] + fn cell_status_works() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); + + (1..=63).for_each(|i| vote(i, 2)); + + assert_ok!(Council::retract_voter(Origin::signed(11), 10)); + assert_ok!(Council::retract_voter(Origin::signed(21), 20)); + + assert_eq!(Council::cell_status(0, 10), CellStatus::Hole); + assert_eq!(Council::cell_status(0, 0), CellStatus::Occupied); + assert_eq!(Council::cell_status(0, 20), CellStatus::Hole); + assert_eq!(Council::cell_status(0, 63), CellStatus::Head); + assert_eq!(Council::cell_status(1, 0), CellStatus::Head); + assert_eq!(Council::cell_status(1, 10), CellStatus::Head); + }) + } + + #[test] + fn initial_set_approvals_ignores_voter_index() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + + // Last argument is essentially irrelevant. You might get or miss a tip. + assert_ok!(Council::set_approvals(Origin::signed(3), vec![true], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0, 5)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 0, 100)); + + // indices are more or less ignored. all is pushed. + assert_eq!(voter_ids(), vec![3, 4, 5]); + }) + } + + #[test] + fn bad_approval_index_slashes_voters_and_bond_reduces_stake() { + with_externalities(&mut ExtBuilder::default().voting_fee(5).voter_bond(2).build(), || { + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); + + (1..=63).for_each(|i| vote(i, 2)); + assert_eq!(Balances::free_balance(&1), 20 - 5 - 2); // -5 fee -2 bond + assert_eq!(Balances::free_balance(&10), 20 - 2); + assert_eq!(Balances::free_balance(&60), 20 - 2); + + // still no fee + vote(64, 2); + assert_eq!(Balances::free_balance(&64), 20 - 2); // -2 bond + assert_eq!( + Council::voter_info(&64).unwrap(), + VoterInfo { last_win: 0, last_active: 0, stake: 20, pot:0 } + ); + + assert_eq!(Council::next_nonfull_voter_set(), 1); + + // now we charge the next voter. + vote(65, 2); + assert_eq!(Balances::free_balance(&65), 20 - 5 - 2); + assert_eq!( + Council::voter_info(&65).unwrap(), + VoterInfo { last_win: 0, last_active: 0, stake: 15, pot:0 } + ); }); } + #[test] + fn subsequent_set_approvals_checks_voter_index() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + + assert_ok!(Council::set_approvals(Origin::signed(3), vec![true], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0, 5)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 0, 100)); + + // invalid index + assert_noop!(Council::set_approvals(Origin::signed(4), vec![true], 0, 5), "invalid voter index"); + // wrong index + assert_noop!(Council::set_approvals(Origin::signed(4), vec![true], 0, 0), "wrong voter index"); + // correct + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0, 1)); + }) + } + + #[test] + fn voter_index_does_not_take_holes_into_account() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); + + // create 65. 64 (set0) + 1 (set1) + (1..=65).for_each(|i| vote(i, 2)); + + // account 65 has global index 65. + assert_eq!(Council::voter_at(64).unwrap(), 65); + + assert_ok!(Council::retract_voter(Origin::signed(1), 0)); + assert_ok!(Council::retract_voter(Origin::signed(2), 1)); + + // still the same. These holes are in some other set. + assert_eq!(Council::voter_at(64).unwrap(), 65); + // proof: can submit a new approval with the old index. + assert_noop!(Council::set_approvals(Origin::signed(65), vec![false, true], 0, 64 - 2), "wrong voter index"); + assert_ok!(Council::set_approvals(Origin::signed(65), vec![false, true], 0, 64)); + }) + } + #[test] fn simple_candidate_submission_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); assert_eq!(Council::candidate_reg_info(1), None); @@ -633,7 +1323,7 @@ mod tests { } fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities { - let mut t = new_test_ext(false); + let mut t = ExtBuilder::default().build(); with_externalities(&mut t, || { >::put(vec![0, 0, 1]); >::put(1); @@ -676,7 +1366,9 @@ mod tests { #[test] fn candidate_submission_not_using_free_slot_should_not_work() { - with_externalities(&mut new_test_ext_with_candidate_holes(), || { + let mut t = new_test_ext_with_candidate_holes(); + + with_externalities(&mut t, || { System::set_block_number(1); assert_noop!(Council::submit_candidacy(Origin::signed(4), 3), "invalid candidate slot"); }); @@ -684,7 +1376,7 @@ mod tests { #[test] fn bad_candidate_slot_submission_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); assert_noop!(Council::submit_candidacy(Origin::signed(1), 1), "invalid candidate slot"); @@ -693,7 +1385,7 @@ mod tests { #[test] fn non_free_candidate_slot_submission_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); @@ -704,7 +1396,7 @@ mod tests { #[test] fn dupe_candidate_submission_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); @@ -715,45 +1407,367 @@ mod tests { #[test] fn poor_candidate_submission_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_eq!(Council::candidates(), Vec::::new()); assert_noop!(Council::submit_candidacy(Origin::signed(7), 0), "candidate has not enough funds"); }); } + #[test] + fn balance_should_lock_to_the_maximum() { + with_externalities(&mut ExtBuilder::default().build(), || { + System::set_block_number(1); + assert_eq!(Council::candidates(), Vec::::new()); + assert_eq!(Balances::free_balance(&2), 20); + + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); + + assert_eq!(Balances::free_balance(&2), 20 - bond() ); + assert_noop!(Balances::reserve(&2, 1), "account liquidity restrictions prevent withdrawal"); // locked. + + // deposit a bit more. + let _ = Balances::deposit_creating(&2, 100); + assert_ok!(Balances::reserve(&2, 1)); // locked but now has enough. + + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); + assert_noop!(Balances::reserve(&2, 1), "account liquidity restrictions prevent withdrawal"); // locked. + assert_eq!(Balances::locks(&2).len(), 1); + assert_eq!(Balances::locks(&2)[0].amount, 100 + 20); + + assert_ok!(Council::retract_voter(Origin::signed(2), 0)); + + assert_eq!(Balances::locks(&2).len(), 0); + assert_eq!(Balances::free_balance(&2), 120 - 1); // 1 ok call to .reserve() happened. + assert_ok!(Balances::reserve(&2, 1)); // unlocked. + }); + } + + #[test] + fn balance_should_lock_on_submit_approvals_unlock_on_retract() { + with_externalities(&mut ExtBuilder::default().voter_bond(8).voting_fee(0).build(), || { + System::set_block_number(1); + assert_eq!(Council::candidates(), Vec::::new()); + assert_eq!(Balances::free_balance(&2), 20); + + assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); + + assert_eq!(Balances::free_balance(&2), 12); // 20 - 8 (bond) + assert_noop!(Balances::reserve(&2, 10), "account liquidity restrictions prevent withdrawal"); // locked. + + assert_ok!(Council::retract_voter(Origin::signed(2), 0)); + + assert_eq!(Balances::free_balance(&2), 20); + assert_ok!(Balances::reserve(&2, 10)); // unlocked. + }); + } + + #[test] + fn accumulating_weight_and_decaying_should_work() { + with_externalities(&mut ExtBuilder::default().balance_factor(10).build(), || { + System::set_block_number(4); + assert!(!Council::presentation_active()); + + assert_ok!(Council::submit_candidacy(Origin::signed(6), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 2)); + + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true, false, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![false, false, true], 0, 0)); + + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(6); + assert!(Council::presentation_active()); + + assert_eq!(Council::present_winner(Origin::signed(6), 6, 600, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(5), 5, 500, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(1), 1, 100, 0), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (100, 1), (500, 5), (600, 6)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(6, 11), (5, 11)]); + assert_eq!(Council::voter_info(6).unwrap(), VoterInfo { last_win: 1, last_active: 0, stake: 600, pot: 0}); + assert_eq!(Council::voter_info(5).unwrap(), VoterInfo { last_win: 1, last_active: 0, stake: 500, pot: 0}); + assert_eq!(Council::voter_info(1).unwrap(), VoterInfo { last_win: 0, last_active: 0, stake: 100, pot: 0}); + + System::set_block_number(12); + // retract needed to unlock approval funds => submit candidacy again. + assert_ok!(Council::retract_voter(Origin::signed(6), 0)); + assert_ok!(Council::retract_voter(Origin::signed(5), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(6), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true, false, false], 1, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true, false], 1, 1)); + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(14); + assert!(Council::presentation_active()); + assert_eq!(Council::present_winner(Origin::signed(6), 6, 600, 1), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(5), 5, 500, 1), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(1), 1, 100 + Council::get_offset(100, 1), 1), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (100 + 96, 1), (500, 5), (600, 6)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(6, 19), (5, 19)]); + assert_eq!( + Council::voter_info(6).unwrap(), + VoterInfo { last_win: 2, last_active: 1, stake: 600, pot:0 } + ); + assert_eq!(Council::voter_info(5).unwrap(), VoterInfo { last_win: 2, last_active: 1, stake: 500, pot:0 }); + assert_eq!(Council::voter_info(1).unwrap(), VoterInfo { last_win: 0, last_active: 0, stake: 100, pot:0 }); + + System::set_block_number(20); + assert_ok!(Council::retract_voter(Origin::signed(6), 0)); + assert_ok!(Council::retract_voter(Origin::signed(5), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(6), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true, false, false], 2, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true, false], 2, 1)); + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(22); + assert!(Council::presentation_active()); + assert_eq!(Council::present_winner(Origin::signed(6), 6, 600, 2), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(5), 5, 500, 2), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(1), 1, 100 + Council::get_offset(100, 2), 2), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (100 + 96 + 93, 1), (500, 5), (600, 6)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(6, 27), (5, 27)]); + assert_eq!( + Council::voter_info(6).unwrap(), + VoterInfo { last_win: 3, last_active: 2, stake: 600, pot: 0} + ); + assert_eq!(Council::voter_info(5).unwrap(), VoterInfo { last_win: 3, last_active: 2, stake: 500, pot: 0}); + assert_eq!(Council::voter_info(1).unwrap(), VoterInfo { last_win: 0, last_active: 0, stake: 100, pot: 0}); + + + System::set_block_number(28); + assert_ok!(Council::retract_voter(Origin::signed(6), 0)); + assert_ok!(Council::retract_voter(Origin::signed(5), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(6), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true, false, false], 3, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true, false], 3, 1)); + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(30); + assert!(Council::presentation_active()); + assert_eq!(Council::present_winner(Origin::signed(6), 6, 600, 3), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(5), 5, 500, 3), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(1), 1, 100 + Council::get_offset(100, 3), 3), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (100 + 96 + 93 + 90, 1), (500, 5), (600, 6)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(6, 35), (5, 35)]); + assert_eq!( + Council::voter_info(6).unwrap(), + VoterInfo { last_win: 4, last_active: 3, stake: 600, pot: 0} + ); + assert_eq!(Council::voter_info(5).unwrap(), VoterInfo { last_win: 4, last_active: 3, stake: 500, pot: 0}); + assert_eq!(Council::voter_info(1).unwrap(), VoterInfo { last_win: 0, last_active: 0, stake: 100, pot: 0}); + }) + } + + #[test] + fn winning_resets_accumulated_pot() { + with_externalities(&mut ExtBuilder::default().balance_factor(10).build(), || { + System::set_block_number(4); + assert!(!Council::presentation_active()); + + assert_ok!(Council::submit_candidacy(Origin::signed(6), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(4), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 3)); + + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true, false, false, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, true, false, false], 0, 1)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true, true], 0, 2)); + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(6); + assert!(Council::presentation_active()); + assert_eq!(Council::present_winner(Origin::signed(6), 6, 600, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(4), 4, 400, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(3), 3, 300, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(2), 2, 300, 0), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(300, 2), (300, 3), (400, 4), (600, 6)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(6, 11), (4, 11)]); + + System::set_block_number(12); + assert_ok!(Council::retract_voter(Origin::signed(6), 0)); + assert_ok!(Council::retract_voter(Origin::signed(4), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(6), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(4), 1)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true, false, false, false], 1, 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, true, false, false], 1, 1)); + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(14); + assert!(Council::presentation_active()); + assert_eq!(Council::present_winner(Origin::signed(6), 6, 600, 1), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(4), 4, 400, 1), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(3), 3, 300 + Council::get_offset(300, 1), 1), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(2), 2, 300 + Council::get_offset(300, 1), 1), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(400, 4), (588, 2), (588, 3), (600, 6)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(6, 19), (3, 19)]); + + System::set_block_number(20); + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(22); + // 2 will not get re-elected with 300 + 288, instead just 300. + // because one of 3's candidates (3) won in previous round + // 4 on the other hand will get extra weight since it was unlucky. + assert_eq!(Council::present_winner(Origin::signed(3), 2, 300, 2), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(4), 4, 400 + Council::get_offset(400, 1), 2), Ok(())); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(4, 27), (2, 27)]); + }) + } + + #[test] + fn resubmitting_approvals_stores_pot() { + with_externalities(&mut ExtBuilder::default() + .voter_bond(0) + .voting_fee(0) + .balance_factor(10) + .build(), + || { System::set_block_number(4); + assert!(!Council::presentation_active()); + + assert_ok!(Council::submit_candidacy(Origin::signed(6), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(1), 2)); + + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true, false, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true, false], 0, 1)); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![false, false, true], 0, 2)); + + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(6); + assert!(Council::presentation_active()); + + assert_eq!(Council::present_winner(Origin::signed(6), 6, 600, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(5), 5, 500, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(1), 1, 100, 0), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (100, 1), (500, 5), (600, 6)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(6, 11), (5, 11)]); + + System::set_block_number(12); + assert_ok!(Council::retract_voter(Origin::signed(6), 0)); + assert_ok!(Council::retract_voter(Origin::signed(5), 1)); + assert_ok!(Council::submit_candidacy(Origin::signed(6), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true, false, false], 1, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true, false], 1, 1)); + // give 1 some new high balance + let _ = Balances::make_free_balance_be(&1, 997); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![false, false, true], 1, 2)); + assert_eq!(Council::voter_info(1).unwrap(), + VoterInfo { + stake: 1000, // 997 + 3 which is candidacy bond. + pot: Council::get_offset(100, 1), + last_active: 1, + last_win: 1, + } + ); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(6, 11), (5, 11)]); + + System::set_block_number(14); + assert!(Council::presentation_active()); + assert_eq!(Council::present_winner(Origin::signed(6), 6, 600, 1), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(5), 5, 500, 1), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(1), 1, 1000 + 96 /* pot */, 1), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (500, 5), (600, 6), (1096, 1)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(1, 19), (6, 19)]); + }) + } + + #[test] + fn get_offset_should_work() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_eq!(Council::get_offset(100, 0), 0); + assert_eq!(Council::get_offset(100, 1), 96); + assert_eq!(Council::get_offset(100, 2), 96 + 93); + assert_eq!(Council::get_offset(100, 3), 96 + 93 + 90); + assert_eq!(Council::get_offset(100, 4), 96 + 93 + 90 + 87); + // limit + assert_eq!(Council::get_offset(100, 1000), 100 * 24); + + assert_eq!(Council::get_offset(50_000_000_000, 0), 0); + assert_eq!(Council::get_offset(50_000_000_000, 1), 48_000_000_000); + assert_eq!(Council::get_offset(50_000_000_000, 2), 48_000_000_000 + 46_080_000_000); + assert_eq!(Council::get_offset(50_000_000_000, 3), 48_000_000_000 + 46_080_000_000 + 44_236_800_000); + assert_eq!( + Council::get_offset(50_000_000_000, 4), + 48_000_000_000 + 46_080_000_000 + 44_236_800_000 + 42_467_328_000 + ); + // limit + assert_eq!(Council::get_offset(50_000_000_000, 1000), 50_000_000_000 * 24); + }) + } + + #[test] + fn get_offset_with_zero_decay() { + with_externalities(&mut ExtBuilder::default().decay_ratio(0).build(), || { + assert_eq!(Council::get_offset(100, 0), 0); + assert_eq!(Council::get_offset(100, 1), 0); + assert_eq!(Council::get_offset(100, 2), 0); + assert_eq!(Council::get_offset(100, 3), 0); + // limit + assert_eq!(Council::get_offset(100, 1000), 0); + }) + } + #[test] fn voting_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0, 1)); - assert_eq!(Council::approvals_of(1), vec![true]); - assert_eq!(Council::approvals_of(4), vec![true]); - assert_eq!(Council::voters(), vec![1, 4]); + assert_eq!(Council::all_approvals_of(&1), vec![true]); + assert_eq!(Council::all_approvals_of(&4), vec![true]); + assert_eq!(voter_ids(), vec![1, 4]); assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0, 2)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0, 3)); - assert_eq!(Council::approvals_of(1), vec![true]); - assert_eq!(Council::approvals_of(4), vec![true]); - assert_eq!(Council::approvals_of(2), vec![false, true, true]); - assert_eq!(Council::approvals_of(3), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&1), vec![true]); + assert_eq!(Council::all_approvals_of(&4), vec![true]); + assert_eq!(Council::all_approvals_of(&2), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&3), vec![false, true, true]); - assert_eq!(Council::voters(), vec![1, 4, 2, 3]); + assert_eq!(voter_ids(), vec![1, 4, 2, 3]); }); } #[test] fn proxy_voting_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); @@ -762,74 +1776,79 @@ mod tests { Democracy::force_proxy(2, 12); Democracy::force_proxy(3, 13); Democracy::force_proxy(4, 14); + assert_ok!(Council::proxy_set_approvals(Origin::signed(11), vec![true], 0, 0)); + assert_ok!(Council::proxy_set_approvals(Origin::signed(14), vec![true], 0, 1)); - assert_ok!(Council::proxy_set_approvals(Origin::signed(11), vec![true], 0)); - assert_ok!(Council::proxy_set_approvals(Origin::signed(14), vec![true], 0)); - - assert_eq!(Council::approvals_of(1), vec![true]); - assert_eq!(Council::approvals_of(4), vec![true]); - assert_eq!(Council::voters(), vec![1, 4]); + assert_eq!(Council::all_approvals_of(&1), vec![true]); + assert_eq!(Council::all_approvals_of(&4), vec![true]); + assert_eq!(voter_ids(), vec![1, 4]); assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::proxy_set_approvals(Origin::signed(12), vec![false, true, true], 0)); - assert_ok!(Council::proxy_set_approvals(Origin::signed(13), vec![false, true, true], 0)); + assert_ok!(Council::proxy_set_approvals(Origin::signed(12), vec![false, true, true], 0, 2)); + assert_ok!(Council::proxy_set_approvals(Origin::signed(13), vec![false, true, true], 0, 3)); - assert_eq!(Council::approvals_of(1), vec![true]); - assert_eq!(Council::approvals_of(4), vec![true]); - assert_eq!(Council::approvals_of(2), vec![false, true, true]); - assert_eq!(Council::approvals_of(3), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&1), vec![true]); + assert_eq!(Council::all_approvals_of(&4), vec![true]); + assert_eq!(Council::all_approvals_of(&2), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&3), vec![false, true, true]); - assert_eq!(Council::voters(), vec![1, 4, 2, 3]); + assert_eq!(voter_ids(), vec![1, 4, 2, 3]); }); } #[test] fn setting_any_approval_vote_count_without_any_candidate_count_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_eq!(Council::candidates().len(), 0); - assert_noop!(Council::set_approvals(Origin::signed(4), vec![], 0), "amount of candidates to receive approval votes should be non-zero"); + assert_noop!( + Council::set_approvals(Origin::signed(4), vec![], 0, 0), + "amount of candidates to receive approval votes should be non-zero" + ); }); } #[test] fn setting_an_approval_vote_count_more_than_candidate_count_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); assert_eq!(Council::candidates().len(), 1); - assert_noop!(Council::set_approvals(Origin::signed(4), vec![true, true], 0), "amount of candidate approval votes cannot exceed amount of candidates"); + assert_noop!( + Council::set_approvals(Origin::signed(4),vec![true, true], 0, 0), + "amount of candidate votes cannot exceed amount of candidates" + ); }); } #[test] fn resubmitting_voting_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true], 0, 0)); - assert_eq!(Council::approvals_of(4), vec![true]); + assert_eq!(Council::all_approvals_of(&4), vec![true]); assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); assert_eq!(Council::candidates().len(), 3); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0, 0)); - assert_eq!(Council::approvals_of(4), vec![true, false, true]); + assert_eq!(Council::all_approvals_of(&4), vec![true, false, true]); }); } #[test] fn retracting_voter_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); @@ -837,88 +1856,108 @@ mod tests { assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); assert_eq!(Council::candidates().len(), 3); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true, true], 0, 1)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, true], 0, 2)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![true, false, true], 0, 3)); - assert_eq!(Council::voters(), vec![1, 2, 3, 4]); - assert_eq!(Council::approvals_of(1), vec![true]); - assert_eq!(Council::approvals_of(2), vec![false, true, true]); - assert_eq!(Council::approvals_of(3), vec![false, true, true]); - assert_eq!(Council::approvals_of(4), vec![true, false, true]); + assert_eq!(voter_ids(), vec![1, 2, 3, 4]); + assert_eq!(Council::all_approvals_of(&1), vec![true]); + assert_eq!(Council::all_approvals_of(&2), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&3), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&4), vec![true, false, true]); assert_ok!(Council::retract_voter(Origin::signed(1), 0)); - assert_eq!(Council::voters(), vec![4, 2, 3]); - assert_eq!(Council::approvals_of(1), Vec::::new()); - assert_eq!(Council::approvals_of(2), vec![false, true, true]); - assert_eq!(Council::approvals_of(3), vec![false, true, true]); - assert_eq!(Council::approvals_of(4), vec![true, false, true]); + assert_eq!(voter_ids(), vec![0, 2, 3, 4]); + assert_eq!(Council::all_approvals_of(&1), Vec::::new()); + assert_eq!(Council::all_approvals_of(&2), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&3), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&4), vec![true, false, true]); assert_ok!(Council::retract_voter(Origin::signed(2), 1)); - assert_eq!(Council::voters(), vec![4, 3]); - assert_eq!(Council::approvals_of(1), Vec::::new()); - assert_eq!(Council::approvals_of(2), Vec::::new()); - assert_eq!(Council::approvals_of(3), vec![false, true, true]); - assert_eq!(Council::approvals_of(4), vec![true, false, true]); + assert_eq!(voter_ids(), vec![0, 0, 3, 4]); + assert_eq!(Council::all_approvals_of(&1), Vec::::new()); + assert_eq!(Council::all_approvals_of(&2), Vec::::new()); + assert_eq!(Council::all_approvals_of(&3), vec![false, true, true]); + assert_eq!(Council::all_approvals_of(&4), vec![true, false, true]); - assert_ok!(Council::retract_voter(Origin::signed(3), 1)); + assert_ok!(Council::retract_voter(Origin::signed(3), 2)); - assert_eq!(Council::voters(), vec![4]); - assert_eq!(Council::approvals_of(1), Vec::::new()); - assert_eq!(Council::approvals_of(2), Vec::::new()); - assert_eq!(Council::approvals_of(3), Vec::::new()); - assert_eq!(Council::approvals_of(4), vec![true, false, true]); + assert_eq!(voter_ids(), vec![0, 0, 0, 4]); + assert_eq!(Council::all_approvals_of(&1), Vec::::new()); + assert_eq!(Council::all_approvals_of(&2), Vec::::new()); + assert_eq!(Council::all_approvals_of(&3), Vec::::new()); + assert_eq!(Council::all_approvals_of(&4), vec![true, false, true]); }); } #[test] fn invalid_retraction_index_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_ok!(Council::submit_candidacy(Origin::signed(3), 0)); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); - assert_eq!(Council::voters(), vec![1, 2]); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); + assert_eq!(voter_ids(), vec![1, 2]); assert_noop!(Council::retract_voter(Origin::signed(1), 1), "retraction index mismatch"); }); } #[test] fn overflow_retraction_index_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_ok!(Council::submit_candidacy(Origin::signed(3), 0)); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0, 0)); assert_noop!(Council::retract_voter(Origin::signed(1), 1), "retraction index invalid"); }); } #[test] fn non_voter_retraction_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(1); assert_ok!(Council::submit_candidacy(Origin::signed(3), 0)); - assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0, 0)); assert_noop!(Council::retract_voter(Origin::signed(2), 0), "cannot retract non-voter"); }); } + #[test] + fn approval_storage_should_work() { + with_externalities(&mut ExtBuilder::default().build(), || { + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); + + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![], 0, 0)); + + assert_eq!(Council::all_approvals_of(&2), vec![true]); + // NOTE: these two are stored in mem differently though. + assert_eq!(Council::all_approvals_of(&3), vec![]); + assert_eq!(Council::all_approvals_of(&4), vec![]); + + assert_eq!(Council::approvals_of((3, 0)), vec![0]); + assert_eq!(Council::approvals_of((4, 0)), vec![]); + }); + } + #[test] fn simple_tally_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert!(!Council::presentation_active()); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); - assert_eq!(Council::voters(), vec![2, 5]); - assert_eq!(Council::approvals_of(2), vec![true, false]); - assert_eq!(Council::approvals_of(5), vec![false, true]); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0, 0)); + assert_eq!(voter_ids(), vec![2, 5]); + assert_eq!(Council::all_approvals_of(&2), vec![true]); + assert_eq!(Council::all_approvals_of(&5), vec![false, true]); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -935,34 +1974,71 @@ mod tests { assert!(!Council::is_a_candidate(&2)); assert!(!Council::is_a_candidate(&5)); assert_eq!(Council::vote_index(), 1); - assert_eq!(Council::voter_last_active(2), Some(0)); - assert_eq!(Council::voter_last_active(5), Some(0)); + assert_eq!(Council::voter_info(2), Some(VoterInfo { last_win: 1, last_active: 0, stake: 20, pot: 0 })); + assert_eq!(Council::voter_info(5), Some(VoterInfo { last_win: 1, last_active: 0, stake: 50, pot: 0 })); + }); + } + + #[test] + fn seats_should_be_released() { + with_externalities(&mut ExtBuilder::default().build(), || { + System::set_block_number(4); + assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); + assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0, 0)); + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(6); + assert!(Council::presentation_active()); + assert_eq!(Council::present_winner(Origin::signed(4), 2, 20, 0), Ok(())); + assert_eq!(Council::present_winner(Origin::signed(4), 5, 50, 0), Ok(())); + assert_eq!(Council::leaderboard(), Some(vec![(0, 0), (0, 0), (20, 2), (50, 5)])); + assert_ok!(Council::end_block(System::block_number())); + + assert_eq!(Council::active_council(), vec![(5, 11), (2, 11)]); + let mut current = System::block_number(); + let free_block; + loop { + current += 1; + System::set_block_number(current); + assert_ok!(Council::end_block(System::block_number())); + if Council::active_council().len() == 0 { + free_block = current; + break; + } + } + // 11 + 2 which is the next voting period. + assert_eq!(free_block, 14); }); } #[test] fn presentations_with_zero_staked_deposit_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); - assert_noop!(Council::present_winner(Origin::signed(4), 2, 0, 0), "stake deposited to present winner and be added to leaderboard should be non-zero"); + assert_noop!( + Council::present_winner(Origin::signed(4), 2, 0, 0), + "stake deposited to present winner and be added to leaderboard should be non-zero" + ); }); } #[test] fn double_presentations_should_be_punished() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { assert!(Balances::can_slash(&4, 10)); System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -978,10 +2054,10 @@ mod tests { #[test] fn retracting_inactive_voter_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -990,7 +2066,7 @@ mod tests { System::set_block_number(8); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); @@ -998,24 +2074,24 @@ mod tests { assert_ok!(Council::end_block(System::block_number())); assert_ok!(Council::reap_inactive_voter(Origin::signed(5), - (Council::voters().iter().position(|&i| i == 5).unwrap() as u32).into(), - 2, (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + (voter_ids().iter().position(|&i| i == 5).unwrap() as u32).into(), + 2, (voter_ids().iter().position(|&i| i == 2).unwrap() as u32).into(), 2 )); - assert_eq!(Council::voters(), vec![5]); - assert_eq!(Council::approvals_of(2).len(), 0); - assert_eq!(Balances::total_balance(&2), 17); - assert_eq!(Balances::total_balance(&5), 53); + assert_eq!(voter_ids(), vec![0, 5]); + assert_eq!(Council::all_approvals_of(&2).len(), 0); + assert_eq!(Balances::total_balance(&2), 20); + assert_eq!(Balances::total_balance(&5), 50); }); } #[test] fn presenting_for_double_election_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_eq!(Council::submit_candidacy(Origin::signed(2), 0), Ok(())); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1023,21 +2099,26 @@ mod tests { assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); + // NOTE: This is now mandatory to disable the lock + assert_ok!(Council::retract_voter(Origin::signed(2), 0)); assert_eq!(Council::submit_candidacy(Origin::signed(2), 0), Ok(())); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 1)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 1, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_noop!(Council::present_winner(Origin::signed(4), 2, 20, 1), "candidate must not form a duplicated member if elected"); + assert_noop!( + Council::present_winner(Origin::signed(4), 2, 20, 1), + "candidate must not form a duplicated member if elected" + ); }); } #[test] fn retracting_inactive_voter_with_other_candidates_in_slots_should_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().voter_bond(2).build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1046,7 +2127,7 @@ mod tests { System::set_block_number(8); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); @@ -1057,24 +2138,24 @@ mod tests { assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); assert_ok!(Council::reap_inactive_voter(Origin::signed(5), - (Council::voters().iter().position(|&i| i == 5).unwrap() as u32).into(), - 2, (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + (voter_ids().iter().position(|&i| i == 5).unwrap() as u32).into(), + 2, (voter_ids().iter().position(|&i| i == 2).unwrap() as u32).into(), 2 )); - assert_eq!(Council::voters(), vec![5]); - assert_eq!(Council::approvals_of(2).len(), 0); - assert_eq!(Balances::total_balance(&2), 17); - assert_eq!(Balances::total_balance(&5), 53); + assert_eq!(voter_ids(), vec![0, 5]); + assert_eq!(Council::all_approvals_of(&2).len(), 0); + assert_eq!(Balances::total_balance(&2), 18); + assert_eq!(Balances::total_balance(&5), 52); }); } #[test] fn retracting_inactive_voter_with_bad_reporter_index_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1083,7 +2164,7 @@ mod tests { System::set_block_number(8); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); @@ -1092,18 +2173,18 @@ mod tests { assert_noop!(Council::reap_inactive_voter(Origin::signed(2), 42, - 2, (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + 2, (voter_ids().iter().position(|&i| i == 2).unwrap() as u32).into(), 2 - ), "bad reporter index"); + ), "invalid reporter index"); }); } #[test] fn retracting_inactive_voter_with_bad_target_index_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1112,7 +2193,7 @@ mod tests { System::set_block_number(8); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); @@ -1120,25 +2201,25 @@ mod tests { assert_ok!(Council::end_block(System::block_number())); assert_noop!(Council::reap_inactive_voter(Origin::signed(2), - (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + (voter_ids().iter().position(|&i| i == 2).unwrap() as u32).into(), 2, 42, 2 - ), "bad target index"); + ), "invalid target index"); }); } #[test] fn attempting_to_retract_active_voter_should_slash_reporter() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); assert_ok!(Council::submit_candidacy(Origin::signed(3), 1)); assert_ok!(Council::submit_candidacy(Origin::signed(4), 2)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 3)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false, false, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, false, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false, false, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, true, false, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, true, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1153,34 +2234,34 @@ mod tests { assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 2, 20, 1)); - assert_ok!(Council::present_winner(Origin::signed(4), 3, 30, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 2, 20 + Council::get_offset(20, 1), 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 3, 30 + Council::get_offset(30, 1), 1)); assert_ok!(Council::end_block(System::block_number())); assert_eq!(Council::vote_index(), 2); assert_eq!(Council::inactivity_grace_period(), 1); assert_eq!(Council::voting_period(), 4); - assert_eq!(Council::voter_last_active(4), Some(0)); + assert_eq!(Council::voter_info(4), Some(VoterInfo { last_win: 1, last_active: 0, stake: 40, pot: 0 })); assert_ok!(Council::reap_inactive_voter(Origin::signed(4), - (Council::voters().iter().position(|&i| i == 4).unwrap() as u32).into(), + (voter_ids().iter().position(|&i| i == 4).unwrap() as u32).into(), 2, - (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + (voter_ids().iter().position(|&i| i == 2).unwrap() as u32).into(), 2 )); - assert_eq!(Council::voters(), vec![2, 3, 5]); - assert_eq!(Council::approvals_of(4).len(), 0); - assert_eq!(Balances::total_balance(&4), 37); + assert_eq!(voter_ids(), vec![2, 3, 0, 5]); + assert_eq!(Council::all_approvals_of(&4).len(), 0); + assert_eq!(Balances::total_balance(&4), 40); }); } #[test] fn attempting_to_retract_inactive_voter_by_nonvoter_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1189,7 +2270,7 @@ mod tests { System::set_block_number(8); assert_ok!(Council::submit_candidacy(Origin::signed(5), 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![true], 1, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); @@ -1198,7 +2279,7 @@ mod tests { assert_noop!(Council::reap_inactive_voter(Origin::signed(4), 0, - 2, (Council::voters().iter().position(|&i| i == 2).unwrap() as u32).into(), + 2, (voter_ids().iter().position(|&i| i == 2).unwrap() as u32).into(), 2 ), "reporter must be a voter"); }); @@ -1206,18 +2287,18 @@ mod tests { #[test] fn presenting_loser_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(4), 3)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 4)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1239,18 +2320,18 @@ mod tests { #[test] fn presenting_loser_first_should_not_matter() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(4), 3)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 4)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1271,21 +2352,24 @@ mod tests { #[test] fn present_outside_of_presentation_period_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert!(!Council::presentation_active()); - assert_noop!(Council::present_winner(Origin::signed(5), 5, 1, 0), "cannot present outside of presentation period"); + assert_noop!( + Council::present_winner(Origin::signed(5), 5, 1, 0), + "cannot present outside of presentation period" + ); }); } #[test] fn present_with_invalid_vote_index_should_not_work() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1295,34 +2379,50 @@ mod tests { #[test] fn present_when_presenter_is_poor_should_not_work() { - with_externalities(&mut new_test_ext(false), || { - System::set_block_number(4); - assert!(!Council::presentation_active()); - - assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); - assert_ok!(Council::end_block(System::block_number())); - - System::set_block_number(6); - assert_eq!(Balances::free_balance(&1), 1); - assert_eq!(Balances::reserved_balance(&1), 9); - assert_noop!(Council::present_winner(Origin::signed(1), 1, 20, 0), "presenter must have sufficient slashable funds"); - }); + let test_present = |p| { + with_externalities(&mut ExtBuilder::default() + .voting_fee(5) + .voter_bond(2) + .bad_presentation_punishment(p) + .build(), + || { + System::set_block_number(4); + let _ = Balances::make_free_balance_be(&1, 15); + assert!(!Council::presentation_active()); + + assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); // -3 + assert_eq!(Balances::free_balance(&1), 12); + assert_ok!(Council::set_approvals(Origin::signed(1), vec![true], 0, 0)); // -2 -5 + assert_ok!(Council::end_block(System::block_number())); + + System::set_block_number(6); + assert_eq!(Balances::free_balance(&1), 5); + assert_eq!(Balances::reserved_balance(&1), 5); + if p > 5 { + assert_noop!(Council::present_winner( + Origin::signed(1), 1, 10, 0), + "presenter must have sufficient slashable funds" + ); + } else { + assert_ok!(Council::present_winner(Origin::signed(1), 1, 10, 0)); + } + }); + }; + test_present(4); + test_present(6); } #[test] fn invalid_present_tally_should_slash() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert!(!Council::presentation_active()); assert_eq!(Balances::total_balance(&4), 40); assert_ok!(Council::submit_candidacy(Origin::signed(2), 0)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![true, false], 0, 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1334,20 +2434,20 @@ mod tests { #[test] fn runners_up_should_be_kept() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert!(!Council::presentation_active()); assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(4), 3)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 4)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); @@ -1355,7 +2455,7 @@ mod tests { assert!(Council::presentation_active()); assert_ok!(Council::present_winner(Origin::signed(4), 1, 60, 0)); // leaderboard length is the empty seats plus the carry count (i.e. 5 + 2), where those - // to be carried are the lowest and stored in lowest indexes + // to be carried are the lowest and stored in lowest indices assert_eq!(Council::leaderboard(), Some(vec![ (0, 0), (0, 0), @@ -1383,11 +2483,11 @@ mod tests { assert!(Council::is_a_candidate(&3)); assert!(Council::is_a_candidate(&4)); assert_eq!(Council::vote_index(), 1); - assert_eq!(Council::voter_last_active(2), Some(0)); - assert_eq!(Council::voter_last_active(3), Some(0)); - assert_eq!(Council::voter_last_active(4), Some(0)); - assert_eq!(Council::voter_last_active(5), Some(0)); - assert_eq!(Council::voter_last_active(6), Some(0)); + assert_eq!(Council::voter_info(2), Some(VoterInfo { last_win: 0, last_active: 0, stake: 20, pot: 0 })); + assert_eq!(Council::voter_info(3), Some(VoterInfo { last_win: 0, last_active: 0, stake: 30, pot: 0 })); + assert_eq!(Council::voter_info(4), Some(VoterInfo { last_win: 0, last_active: 0, stake: 40, pot: 0 })); + assert_eq!(Council::voter_info(5), Some(VoterInfo { last_win: 1, last_active: 0, stake: 50, pot: 0 })); + assert_eq!(Council::voter_info(6), Some(VoterInfo { last_win: 1, last_active: 0, stake: 60, pot: 0 })); assert_eq!(Council::candidate_reg_info(3), Some((0, 2))); assert_eq!(Council::candidate_reg_info(4), Some((0, 3))); }); @@ -1395,18 +2495,18 @@ mod tests { #[test] fn second_tally_should_use_runners_up() { - with_externalities(&mut new_test_ext(false), || { + with_externalities(&mut ExtBuilder::default().build(), || { System::set_block_number(4); assert_ok!(Council::submit_candidacy(Origin::signed(1), 0)); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(2), 1)); - assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(2), vec![false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(3), 2)); - assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(3), vec![false, false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(4), 3)); - assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(4), vec![false, false, false, true], 0, 0)); assert_ok!(Council::submit_candidacy(Origin::signed(5), 4)); - assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0)); + assert_ok!(Council::set_approvals(Origin::signed(5), vec![false, false, false, false, true], 0, 0)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(6); @@ -1417,13 +2517,13 @@ mod tests { assert_ok!(Council::end_block(System::block_number())); System::set_block_number(8); - assert_ok!(Council::set_approvals(Origin::signed(6), vec![false, false, true, false], 1)); + assert_ok!(Council::set_approvals(Origin::signed(6), vec![false, false, true, false], 1, 0)); assert_ok!(Council::set_desired_seats(3)); assert_ok!(Council::end_block(System::block_number())); System::set_block_number(10); - assert_ok!(Council::present_winner(Origin::signed(4), 3, 90, 1)); - assert_ok!(Council::present_winner(Origin::signed(4), 4, 40, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 3, 30 + Council::get_offset(30, 1) + 60, 1)); + assert_ok!(Council::present_winner(Origin::signed(4), 4, 40 + Council::get_offset(40, 1), 1)); assert_ok!(Council::end_block(System::block_number())); assert!(!Council::presentation_active()); @@ -1435,11 +2535,14 @@ mod tests { assert!(!Council::is_a_candidate(&5)); assert!(Council::is_a_candidate(&4)); assert_eq!(Council::vote_index(), 2); - assert_eq!(Council::voter_last_active(2), Some(0)); - assert_eq!(Council::voter_last_active(3), Some(0)); - assert_eq!(Council::voter_last_active(4), Some(0)); - assert_eq!(Council::voter_last_active(5), Some(0)); - assert_eq!(Council::voter_last_active(6), Some(1)); + assert_eq!(Council::voter_info(2), Some( VoterInfo { last_win: 0, last_active: 0, stake: 20, pot: 0})); + assert_eq!(Council::voter_info(3), Some( VoterInfo { last_win: 2, last_active: 0, stake: 30, pot: 0})); + assert_eq!(Council::voter_info(4), Some( VoterInfo { last_win: 0, last_active: 0, stake: 40, pot: 0})); + assert_eq!(Council::voter_info(5), Some( VoterInfo { last_win: 1, last_active: 0, stake: 50, pot: 0})); + assert_eq!( + Council::voter_info(6), + Some(VoterInfo { last_win: 2, last_active: 1, stake: 60, pot: 0}) + ); assert_eq!(Council::candidate_reg_info(4), Some((0, 3))); }); diff --git a/srml/council/src/voting.rs b/srml/council/src/voting.rs deleted file mode 100644 index 22b4b9639cd3fee7acefe67e44ed1e7d9ba6e154..0000000000000000000000000000000000000000 --- a/srml/council/src/voting.rs +++ /dev/null @@ -1,494 +0,0 @@ -// Copyright 2017-2019 Parity Technologies (UK) Ltd. -// This file is part of Substrate. - -// Substrate is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. - -// Substrate is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. - -// You should have received a copy of the GNU General Public License -// along with Substrate. If not, see . - -//! Council voting system. - -use rstd::prelude::*; -use rstd::borrow::Borrow; -use primitives::traits::{Hash, As, Zero}; -use runtime_io::print; -use srml_support::dispatch::Result; -use srml_support::{StorageValue, StorageMap, IsSubType, decl_module, decl_storage, decl_event, ensure}; -use {system, democracy}; -use super::{Trait as CouncilTrait, Module as Council}; -use system::ensure_signed; - -pub trait Trait: CouncilTrait { - type Event: From> + Into<::Event>; -} - -decl_module! { - pub struct Module for enum Call where origin: T::Origin { - fn deposit_event() = default; - - fn propose(origin, proposal: Box) { - let who = ensure_signed(origin)?; - - let expiry = >::block_number() + Self::voting_period(); - ensure!(Self::will_still_be_councillor_at(&who, expiry), "proposer would not be on council"); - - let proposal_hash = T::Hashing::hash_of(&proposal); - - ensure!(!>::exists(proposal_hash), "duplicate proposals not allowed"); - ensure!(!Self::is_vetoed(&proposal_hash), "proposal is vetoed"); - - let mut proposals = Self::proposals(); - proposals.push((expiry, proposal_hash)); - proposals.sort_by_key(|&(expiry, _)| expiry); - Self::set_proposals(&proposals); - - >::insert(proposal_hash, *proposal); - >::insert(proposal_hash, vec![who.clone()]); - >::insert((proposal_hash, who.clone()), true); - } - - fn vote(origin, proposal: T::Hash, approve: bool) { - let who = ensure_signed(origin)?; - - ensure!(Self::is_councillor(&who), "only councillors may vote on council proposals"); - - if Self::vote_of((proposal, who.clone())).is_none() { - >::mutate(proposal, |voters| voters.push(who.clone())); - } - >::insert((proposal, who), approve); - } - - fn veto(origin, proposal_hash: T::Hash) { - let who = ensure_signed(origin)?; - - ensure!(Self::is_councillor(&who), "only councillors may veto council proposals"); - ensure!(>::exists(&proposal_hash), "proposal must exist to be vetoed"); - - let mut existing_vetoers = Self::veto_of(&proposal_hash) - .map(|pair| pair.1) - .unwrap_or_else(Vec::new); - let insert_position = existing_vetoers.binary_search(&who) - .err().ok_or("a councillor may not veto a proposal twice")?; - existing_vetoers.insert(insert_position, who); - Self::set_veto_of( - &proposal_hash, - >::block_number() + Self::cooloff_period(), - existing_vetoers - ); - - Self::set_proposals( - &Self::proposals().into_iter().filter(|&(_, h)| h != proposal_hash - ).collect::>()); - >::remove(proposal_hash); - >::remove(proposal_hash); - for (c, _) in >::active_council() { - >::remove((proposal_hash, c)); - } - } - - fn set_cooloff_period(#[compact] blocks: T::BlockNumber) { - >::put(blocks); - } - - fn set_voting_period(#[compact] blocks: T::BlockNumber) { - >::put(blocks); - } - - fn on_finalize(n: T::BlockNumber) { - if let Err(e) = Self::end_block(n) { - print("Guru meditation"); - print(e); - } - } - } -} - -decl_storage! { - trait Store for Module as CouncilVoting { - pub CooloffPeriod get(cooloff_period) config(): T::BlockNumber = T::BlockNumber::sa(1000); - pub VotingPeriod get(voting_period) config(): T::BlockNumber = T::BlockNumber::sa(3); - /// Number of blocks by which to delay enactment of successful, non-unanimous-council-instigated referendum proposals. - pub EnactDelayPeriod get(enact_delay_period) config(): T::BlockNumber = T::BlockNumber::sa(0); - pub Proposals get(proposals) build(|_| vec![]): Vec<(T::BlockNumber, T::Hash)>; // ordered by expiry. - pub ProposalOf get(proposal_of): map T::Hash => Option; - pub ProposalVoters get(proposal_voters): map T::Hash => Vec; - pub CouncilVoteOf get(vote_of): map (T::Hash, T::AccountId) => Option; - pub VetoedProposal get(veto_of): map T::Hash => Option<(T::BlockNumber, Vec)>; - } -} - -decl_event!( - pub enum Event where ::Hash { - /// A voting tally has happened for a referendum cancellation vote. - /// Last three are yes, no, abstain counts. - TallyCancelation(Hash, u32, u32, u32), - /// A voting tally has happened for a referendum vote. - /// Last three are yes, no, abstain counts. - TallyReferendum(Hash, u32, u32, u32), - } -); - -impl Module { - pub fn is_vetoed>(proposal: B) -> bool { - Self::veto_of(proposal.borrow()) - .map(|(expiry, _): (T::BlockNumber, Vec)| >::block_number() < expiry) - .unwrap_or(false) - } - - pub fn will_still_be_councillor_at(who: &T::AccountId, n: T::BlockNumber) -> bool { - >::active_council().iter() - .find(|&&(ref a, _)| a == who) - .map(|&(_, expires)| expires > n) - .unwrap_or(false) - } - - pub fn is_councillor(who: &T::AccountId) -> bool { - >::active_council().iter() - .any(|&(ref a, _)| a == who) - } - - pub fn tally(proposal_hash: &T::Hash) -> (u32, u32, u32) { - Self::generic_tally(proposal_hash, |w: &T::AccountId, p: &T::Hash| Self::vote_of((*p, w.clone()))) - } - - // Private - fn set_veto_of(proposal: &T::Hash, expiry: T::BlockNumber, vetoers: Vec) { - >::insert(proposal, (expiry, vetoers)); - } - - fn kill_veto_of(proposal: &T::Hash) { - >::remove(proposal); - } - - fn take_tally(proposal_hash: &T::Hash) -> (u32, u32, u32) { - Self::generic_tally(proposal_hash, |w: &T::AccountId, p: &T::Hash| >::take((*p, w.clone()))) - } - - fn generic_tally Option>(proposal_hash: &T::Hash, vote_of: F) -> (u32, u32, u32) { - let c = >::active_council(); - let (approve, reject) = c.iter() - .filter_map(|&(ref a, _)| vote_of(a, proposal_hash)) - .map(|approve| if approve { (1, 0) } else { (0, 1) }) - .fold((0, 0), |(a, b), (c, d)| (a + c, b + d)); - (approve, reject, c.len() as u32 - approve - reject) - } - - fn set_proposals(p: &Vec<(T::BlockNumber, T::Hash)>) { - >::put(p); - } - - fn take_proposal_if_expiring_at(n: T::BlockNumber) -> Option<(T::Proposal, T::Hash)> { - let proposals = Self::proposals(); - match proposals.first() { - Some(&(expiry, hash)) if expiry == n => { - // yes this is horrible, but fixing it will need substantial work in storage. - Self::set_proposals(&proposals[1..].to_vec()); - >::take(hash).map(|p| (p, hash)) /* defensive only: all queued proposal hashes must have associated proposals*/ - } - _ => None, - } - } - - fn end_block(now: T::BlockNumber) -> Result { - while let Some((proposal, proposal_hash)) = Self::take_proposal_if_expiring_at(now) { - let tally = Self::take_tally(&proposal_hash); - if let Some(&democracy::Call::cancel_referendum(ref_index)) = IsSubType::>::is_aux_sub_type(&proposal) { - Self::deposit_event(RawEvent::TallyCancelation(proposal_hash, tally.0, tally.1, tally.2)); - if let (_, 0, 0) = tally { - >::internal_cancel_referendum(ref_index.into()); - } - } else { - Self::deposit_event(RawEvent::TallyReferendum(proposal_hash.clone(), tally.0, tally.1, tally.2)); - if tally.0 > tally.1 + tally.2 { - Self::kill_veto_of(&proposal_hash); - // If there were no nay-votes from the council, then it's weakly uncontroversial; we enact immediately. - let period = match tally.1 { - 0 => Zero::zero(), - _ => Self::enact_delay_period(), - }; - // If all council members voted yes, then it's strongly uncontroversial; we require a negative - // super-majority at referendum in order to defeat it. - let threshold = match tally { - (_, 0, 0) => democracy::VoteThreshold::SuperMajorityAgainst, - _ => democracy::VoteThreshold::SimpleMajority, - }; - >::internal_start_referendum(proposal, threshold, period).map(|_| ())?; - } - } - } - Ok(()) - } -} - -#[cfg(test)] -mod tests { - use super::*; - use crate::tests::*; - use crate::tests::{Call, Origin}; - use srml_support::{Hashable, assert_ok, assert_noop}; - use democracy::{ReferendumInfo, VoteThreshold}; - - #[test] - fn basic_environment_works() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - assert_eq!(Balances::free_balance(&42), 0); - assert_eq!(CouncilVoting::cooloff_period(), 2); - assert_eq!(CouncilVoting::voting_period(), 1); - assert_eq!(CouncilVoting::will_still_be_councillor_at(&1, 1), true); - assert_eq!(CouncilVoting::will_still_be_councillor_at(&1, 10), false); - assert_eq!(CouncilVoting::will_still_be_councillor_at(&4, 10), false); - assert_eq!(CouncilVoting::is_councillor(&1), true); - assert_eq!(CouncilVoting::is_councillor(&4), false); - assert_eq!(CouncilVoting::proposals(), Vec::<(u64, H256)>::new()); - assert_eq!(CouncilVoting::proposal_voters(H256::default()), Vec::::new()); - assert_eq!(CouncilVoting::is_vetoed(&H256::default()), false); - assert_eq!(CouncilVoting::vote_of((H256::default(), 1)), None); - assert_eq!(CouncilVoting::tally(&H256::default()), (0, 0, 3)); - }); - } - - fn set_balance_proposal(value: u64) -> Call { - Call::Balances(balances::Call::set_balance(42, value.into(), 0)) - } - - fn cancel_referendum_proposal(id: u32) -> Call { - Call::Democracy(democracy::Call::cancel_referendum(id.into())) - } - - #[test] - fn referendum_cancellation_should_work_when_unanimous() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0); - assert_eq!(Democracy::active_referenda(), vec![(0, ReferendumInfo::new(4, proposal, VoteThreshold::SuperMajorityApprove, 0))]); - - let cancellation = cancel_referendum_proposal(0); - let hash = cancellation.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(cancellation))); - assert_ok!(CouncilVoting::vote(Origin::signed(2), hash, true)); - assert_ok!(CouncilVoting::vote(Origin::signed(3), hash, true)); - assert_eq!(CouncilVoting::proposals(), vec![(2, hash)]); - assert_ok!(CouncilVoting::end_block(System::block_number())); - - System::set_block_number(2); - assert_ok!(CouncilVoting::end_block(System::block_number())); - assert_eq!(Democracy::active_referenda(), vec![]); - assert_eq!(Balances::free_balance(&42), 0); - }); - } - - #[test] - fn referendum_cancellation_should_fail_when_not_unanimous() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0); - - let cancellation = cancel_referendum_proposal(0); - let hash = cancellation.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(cancellation))); - assert_ok!(CouncilVoting::vote(Origin::signed(2), hash, true)); - assert_ok!(CouncilVoting::vote(Origin::signed(3), hash, false)); - assert_ok!(CouncilVoting::end_block(System::block_number())); - - System::set_block_number(2); - assert_ok!(CouncilVoting::end_block(System::block_number())); - assert_eq!(Democracy::active_referenda(), vec![(0, ReferendumInfo::new(4, proposal, VoteThreshold::SuperMajorityApprove, 0))]); - }); - } - - #[test] - fn referendum_cancellation_should_fail_when_abstentions() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - assert_ok!(Democracy::internal_start_referendum(proposal.clone(), VoteThreshold::SuperMajorityApprove, 0), 0); - - let cancellation = cancel_referendum_proposal(0); - let hash = cancellation.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(cancellation))); - assert_ok!(CouncilVoting::vote(Origin::signed(2), hash, true)); - assert_ok!(CouncilVoting::end_block(System::block_number())); - - System::set_block_number(2); - assert_ok!(CouncilVoting::end_block(System::block_number())); - assert_eq!(Democracy::active_referenda(), vec![(0, ReferendumInfo::new(4, proposal, VoteThreshold::SuperMajorityApprove, 0))]); - }); - } - - #[test] - fn veto_should_work() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - let hash = proposal.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::veto(Origin::signed(2), hash)); - assert_eq!(CouncilVoting::proposals().len(), 0); - assert_eq!(Democracy::active_referenda().len(), 0); - }); - } - - #[test] - fn double_veto_should_not_work() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - let hash = proposal.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::veto(Origin::signed(2), hash)); - - System::set_block_number(3); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_noop!(CouncilVoting::veto(Origin::signed(2), hash), "a councillor may not veto a proposal twice"); - }); - } - - #[test] - fn retry_in_cooloff_should_not_work() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - let hash = proposal.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::veto(Origin::signed(2), hash)); - - System::set_block_number(2); - assert_noop!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone())), "proposal is vetoed"); - }); - } - - #[test] - fn retry_after_cooloff_should_work() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - let hash = proposal.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::veto(Origin::signed(2), hash)); - - System::set_block_number(3); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::vote(Origin::signed(2), hash, false)); - assert_ok!(CouncilVoting::vote(Origin::signed(3), hash, true)); - assert_ok!(CouncilVoting::end_block(System::block_number())); - - System::set_block_number(4); - assert_ok!(CouncilVoting::end_block(System::block_number())); - assert_eq!(CouncilVoting::proposals().len(), 0); - assert_eq!(Democracy::active_referenda(), vec![(0, ReferendumInfo::new(7, set_balance_proposal(42), VoteThreshold::SimpleMajority, 0))]); - }); - } - - #[test] - fn alternative_double_veto_should_work() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - let hash = proposal.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::veto(Origin::signed(2), hash)); - - System::set_block_number(3); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::veto(Origin::signed(3), hash)); - assert_eq!(CouncilVoting::proposals().len(), 0); - assert_eq!(Democracy::active_referenda().len(), 0); - }); - } - - #[test] - fn simple_propose_should_work() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - let hash = proposal.blake2_256().into(); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_eq!(CouncilVoting::proposals().len(), 1); - assert_eq!(CouncilVoting::proposal_voters(&hash), vec![1]); - assert_eq!(CouncilVoting::vote_of((hash, 1)), Some(true)); - assert_eq!(CouncilVoting::tally(&hash), (1, 0, 2)); - }); - } - - #[test] - fn unvoted_proposal_should_expire_without_action() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_eq!(CouncilVoting::tally(&proposal.blake2_256().into()), (1, 0, 2)); - assert_ok!(CouncilVoting::end_block(System::block_number())); - - System::set_block_number(2); - assert_ok!(CouncilVoting::end_block(System::block_number())); - assert_eq!(CouncilVoting::proposals().len(), 0); - assert_eq!(Democracy::active_referenda().len(), 0); - }); - } - - #[test] - fn unanimous_proposal_should_expire_with_biased_referendum() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::vote(Origin::signed(2), proposal.blake2_256().into(), true)); - assert_ok!(CouncilVoting::vote(Origin::signed(3), proposal.blake2_256().into(), true)); - assert_eq!(CouncilVoting::tally(&proposal.blake2_256().into()), (3, 0, 0)); - assert_ok!(CouncilVoting::end_block(System::block_number())); - - System::set_block_number(2); - assert_ok!(CouncilVoting::end_block(System::block_number())); - assert_eq!(CouncilVoting::proposals().len(), 0); - assert_eq!(Democracy::active_referenda(), vec![(0, ReferendumInfo::new(5, proposal, VoteThreshold::SuperMajorityAgainst, 0))]); - }); - } - - #[test] - fn majority_proposal_should_expire_with_unbiased_referendum() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_ok!(CouncilVoting::vote(Origin::signed(2), proposal.blake2_256().into(), true)); - assert_ok!(CouncilVoting::vote(Origin::signed(3), proposal.blake2_256().into(), false)); - assert_eq!(CouncilVoting::tally(&proposal.blake2_256().into()), (2, 1, 0)); - assert_ok!(CouncilVoting::end_block(System::block_number())); - - System::set_block_number(2); - assert_ok!(CouncilVoting::end_block(System::block_number())); - assert_eq!(CouncilVoting::proposals().len(), 0); - assert_eq!(Democracy::active_referenda(), vec![(0, ReferendumInfo::new(5, proposal, VoteThreshold::SimpleMajority, 0))]); - }); - } - - #[test] - fn propose_by_public_should_not_work() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - assert_noop!(CouncilVoting::propose(Origin::signed(4), Box::new(proposal)), "proposer would not be on council"); - }); - } - - #[test] - fn vote_by_public_should_not_work() { - with_externalities(&mut new_test_ext(true), || { - System::set_block_number(1); - let proposal = set_balance_proposal(42); - assert_ok!(CouncilVoting::propose(Origin::signed(1), Box::new(proposal.clone()))); - assert_noop!(CouncilVoting::vote(Origin::signed(4), proposal.blake2_256().into(), true), "only councillors may vote on council proposals"); - }); - } -} diff --git a/srml/democracy/src/lib.rs b/srml/democracy/src/lib.rs index b72a3add2e78dcf37ccb0ca9c86fbf1607be1867..2ccff71869de63dc29c24efc793ff59d90adf415 100644 --- a/srml/democracy/src/lib.rs +++ b/srml/democracy/src/lib.rs @@ -19,15 +19,19 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::prelude::*; -use rstd::result; -use primitives::traits::{Zero, As, Bounded}; -use parity_codec::{Encode, Decode}; -use srml_support::{StorageValue, StorageMap, Parameter, Dispatchable, IsSubType, EnumerableStorageMap}; -use srml_support::{decl_module, decl_storage, decl_event, ensure}; -use srml_support::traits::{Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, - OnFreeBalanceZero}; +use rstd::{result, convert::TryFrom}; +use primitives::traits::{Zero, Bounded, CheckedMul, CheckedDiv, EnsureOrigin, Hash}; +use parity_codec::{Encode, Decode, Input, Output}; +use srml_support::{ + decl_module, decl_storage, decl_event, ensure, + StorageValue, StorageMap, Parameter, Dispatchable, IsSubType, EnumerableStorageMap, + traits::{ + Currency, ReservableCurrency, LockableCurrency, WithdrawReason, LockIdentifier, + OnFreeBalanceZero, Get + } +}; use srml_support::dispatch::Result; -use system::ensure_signed; +use system::{ensure_signed, ensure_root}; mod vote_threshold; pub use vote_threshold::{Approved, VoteThreshold}; @@ -36,63 +40,294 @@ const DEMOCRACY_ID: LockIdentifier = *b"democrac"; /// A proposal index. pub type PropIndex = u32; + /// A referendum index. pub type ReferendumIndex = u32; -/// A number of lock periods. -pub type LockPeriods = i8; - -const MAX_RECURSION_LIMIT: u32 = 16; -/// A number of lock periods, plus a vote, one way or the other. -#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Default)] +/// A value denoting the strength of conviction of a vote. +#[derive(Encode, Decode, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)] #[cfg_attr(feature = "std", derive(Debug))] -pub struct Vote(i8); +pub enum Conviction { + /// 0.1x votes, unlocked. + None, + /// 1x votes, locked for an enactment period following a successful vote. + Locked1x, + /// 2x votes, locked for 2x enactment periods following a successful vote. + Locked2x, + /// 3x votes, locked for 4x... + Locked3x, + /// 4x votes, locked for 8x... + Locked4x, + /// 5x votes, locked for 16x... + Locked5x, +} -impl Vote { - /// Create a new instance. - pub fn new(aye: bool, multiplier: LockPeriods) -> Self { - let m = multiplier.max(1) - 1; - Vote(if aye { - -1 - m - } else { - m +impl Default for Conviction { + fn default() -> Self { + Conviction::None + } +} + +impl From for u8 { + fn from(c: Conviction) -> u8 { + match c { + Conviction::None => 0, + Conviction::Locked1x => 1, + Conviction::Locked2x => 2, + Conviction::Locked3x => 3, + Conviction::Locked4x => 4, + Conviction::Locked5x => 5, + } + } +} + +impl TryFrom for Conviction { + type Error = (); + fn try_from(i: u8) -> result::Result { + Ok(match i { + 0 => Conviction::None, + 1 => Conviction::Locked1x, + 2 => Conviction::Locked2x, + 3 => Conviction::Locked3x, + 4 => Conviction::Locked4x, + 5 => Conviction::Locked5x, + _ => return Err(()), }) } +} + +impl Conviction { + /// The amount of time (in number of periods) that our conviction implies a successful voter's + /// balance should be locked for. + fn lock_periods(self) -> u32 { + match self { + Conviction::None => 0, + Conviction::Locked1x => 1, + Conviction::Locked2x => 2, + Conviction::Locked3x => 4, + Conviction::Locked4x => 8, + Conviction::Locked5x => 16, + } + } + + /// The votes of a voter of the given `balance` with our conviction. + fn votes< + B: From + Zero + Copy + CheckedMul + CheckedDiv + Bounded + >(self, balance: B) -> (B, B) { + match self { + Conviction::None => { + let r = balance.checked_div(&10u8.into()).unwrap_or_else(Zero::zero); + (r, r) + } + x => ( + balance.checked_mul(&u8::from(x).into()).unwrap_or_else(B::max_value), + balance, + ) + } + } +} - /// Is this an aye vote? - pub fn is_aye(self) -> bool { - self.0 < 0 +impl Bounded for Conviction { + fn min_value() -> Self { + Conviction::None } - /// The strength (measured in lock periods). - pub fn multiplier(self) -> LockPeriods { - 1 + if self.0 < 0 { -(self.0 + 1) } else { self.0 } + fn max_value() -> Self { + Conviction::Locked5x + } +} + +const MAX_RECURSION_LIMIT: u32 = 16; + +/// A number of lock periods, plus a vote, one way or the other. +#[derive(Copy, Clone, Eq, PartialEq, Default)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct Vote { + pub aye: bool, + pub conviction: Conviction, +} + +impl Encode for Vote { + fn encode_to(&self, output: &mut T) { + output.push_byte(u8::from(self.conviction) | if self.aye { 0b1000_0000 } else { 0 }); + } +} + +impl Decode for Vote { + fn decode(input: &mut I) -> Option { + let b = input.read_byte()?; + Some(Vote { + aye: (b & 0b1000_0000) == 0b1000_0000, + conviction: Conviction::try_from(b & 0b0111_1111).ok()?, + }) } } type BalanceOf = <::Currency as Currency<::AccountId>>::Balance; pub trait Trait: system::Trait + Sized { - type Currency: ReservableCurrency + LockableCurrency; - type Proposal: Parameter + Dispatchable + IsSubType>; - type Event: From> + Into<::Event>; + + /// Currency type for this module. + type Currency: ReservableCurrency + + LockableCurrency; + + /// The minimum period of locking and the period between a proposal being approved and enacted. + /// + /// It should generally be a little more than the unstake period to ensure that + /// voting stakers have an opportunity to remove themselves from the system in the case where + /// they are on the losing side of a vote. + type EnactmentPeriod: Get; + + /// How often (in blocks) new public referenda are launched. + type LaunchPeriod: Get; + + /// How often (in blocks) to check for new votes. + type VotingPeriod: Get; + + /// The minimum amount to be used as a deposit for a public referendum proposal. + type MinimumDeposit: Get>; + + /// Origin from which the next tabled referendum may be forced. This is a normal + /// "super-majority-required" referendum. + type ExternalOrigin: EnsureOrigin; + + /// Origin from which the next tabled referendum may be forced; this allows for the tabling of + /// a majority-carries referendum. + type ExternalMajorityOrigin: EnsureOrigin; + + /// Origin from which emergency referenda may be scheduled. + type EmergencyOrigin: EnsureOrigin; + + /// Minimum voting period allowed for an emergency referendum. + type EmergencyVotingPeriod: Get; + + /// Origin from which any referenda may be cancelled in an emergency. + type CancellationOrigin: EnsureOrigin; + + /// Origin for anyone able to veto proposals. + type VetoOrigin: EnsureOrigin; + + /// Period in blocks where an external proposal may not be re-submitted after being vetoed. + type CooloffPeriod: Get; +} + +/// Info regarding an ongoing referendum. +#[derive(Encode, Decode, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "std", derive(Debug))] +pub struct ReferendumInfo { + /// When voting on this referendum will end. + end: BlockNumber, + /// The proposal being voted on. + proposal: Proposal, + /// The thresholding mechanism to determine whether it passed. + threshold: VoteThreshold, + /// The delay (in blocks) to wait after a successful referendum before deploying. + delay: BlockNumber, } +impl ReferendumInfo { + /// Create a new instance. + pub fn new( + end: BlockNumber, + proposal: Proposal, + threshold: VoteThreshold, + delay: BlockNumber + ) -> Self { + ReferendumInfo { end, proposal, threshold, delay } + } +} + +decl_storage! { + trait Store for Module as Democracy { + + /// The number of (public) proposals that have been made so far. + pub PublicPropCount get(public_prop_count) build(|_| 0 as PropIndex) : PropIndex; + /// The public proposals. Unsorted. + pub PublicProps get(public_props): Vec<(PropIndex, T::Proposal, T::AccountId)>; + /// Those who have locked a deposit. + pub DepositOf get(deposit_of): map PropIndex => Option<(BalanceOf, Vec)>; + + /// The next free referendum index, aka the number of referenda started so far. + pub ReferendumCount get(referendum_count) build(|_| 0 as ReferendumIndex): ReferendumIndex; + /// The next referendum index that should be tallied. + pub NextTally get(next_tally) build(|_| 0 as ReferendumIndex): ReferendumIndex; + /// Information concerning any given referendum. + pub ReferendumInfoOf get(referendum_info): + map ReferendumIndex => Option<(ReferendumInfo)>; + /// Queue of successful referenda to be dispatched. + pub DispatchQueue get(dispatch_queue): + map T::BlockNumber => Vec>; + + /// Get the voters for the current proposal. + pub VotersFor get(voters_for): map ReferendumIndex => Vec; + + /// Get the vote in a given referendum of a particular voter. The result is meaningful only + /// if `voters_for` includes the voter when called with the referendum (you'll get the + /// default `Vote` value otherwise). If you don't want to check `voters_for`, then you can + /// also check for simple existence with `VoteOf::exists` first. + pub VoteOf get(vote_of): map (ReferendumIndex, T::AccountId) => Vote; + + /// Who is able to vote for whom. Value is the fund-holding account, key is the + /// vote-transaction-sending account. + pub Proxy get(proxy): map T::AccountId => Option; + + /// Get the account (and lock periods) to which another account is delegating vote. + pub Delegations get(delegations): linked_map T::AccountId => (T::AccountId, Conviction); + + /// True if the last referendum tabled was submitted externally. False if it was a public + /// proposal. + pub LastTabledWasExternal: bool; + + /// The referendum to be tabled whenever it would be valid to table an external proposal. + /// This happens when a referendum needs to be tabled and one of two conditions are met: + /// - `LastTabledWasExternal` is `false`; or + /// - `PublicProps` is empty. + pub NextExternal: Option<(T::Proposal, VoteThreshold)>; + + /// A record of who vetoed what. Maps proposal hash to a possible existent block number + /// (until when it may not be resubmitted) and who vetoed it. + pub Blacklist get(blacklist): map T::Hash => Option<(T::BlockNumber, Vec)>; + + /// Record of all proposals that have been subject to emergency cancellation. + pub Cancellations: map T::Hash => bool; + } +} + +decl_event!( + pub enum Event where + Balance = BalanceOf, + ::AccountId, + ::Hash, + ::BlockNumber, + { + Proposed(PropIndex, Balance), + Tabled(PropIndex, Balance, Vec), + ExternalTabled, + Started(ReferendumIndex, VoteThreshold), + Passed(ReferendumIndex), + NotPassed(ReferendumIndex), + Cancelled(ReferendumIndex), + Executed(ReferendumIndex, bool), + Delegated(AccountId, AccountId), + Undelegated(AccountId), + Vetoed(AccountId, Hash, BlockNumber), + } +); + decl_module! { pub struct Module for enum Call where origin: T::Origin { fn deposit_event() = default; /// Propose a sensitive action to be taken. - fn propose( - origin, + fn propose(origin, proposal: Box, #[compact] value: BalanceOf ) { let who = ensure_signed(origin)?; - ensure!(value >= Self::minimum_deposit(), "value too low"); + ensure!(value >= T::MinimumDeposit::get(), "value too low"); T::Currency::reserve(&who, value) .map_err(|_| "proposer's balance too low")?; @@ -120,26 +355,113 @@ decl_module! { /// Vote in a referendum. If `vote.is_aye()`, the vote is to enact the proposal; /// otherwise it is a vote to keep the status quo. - fn vote(origin, #[compact] ref_index: ReferendumIndex, vote: Vote) -> Result { + fn vote(origin, + #[compact] ref_index: ReferendumIndex, + vote: Vote + ) -> Result { let who = ensure_signed(origin)?; Self::do_vote(who, ref_index, vote) } - /// Vote in a referendum on behalf of a stash. If `vote.is_aye()`, the vote is to enact the proposal; - /// otherwise it is a vote to keep the status quo. - fn proxy_vote(origin, #[compact] ref_index: ReferendumIndex, vote: Vote) -> Result { + /// Vote in a referendum on behalf of a stash. If `vote.is_aye()`, the vote is to enact + /// the proposal; otherwise it is a vote to keep the status quo. + fn proxy_vote(origin, + #[compact] ref_index: ReferendumIndex, + vote: Vote + ) -> Result { let who = Self::proxy(ensure_signed(origin)?).ok_or("not a proxy")?; Self::do_vote(who, ref_index, vote) } - /// Start a referendum. - fn start_referendum(proposal: Box, threshold: VoteThreshold, delay: T::BlockNumber) -> Result { + /// Schedule an emergency referendum. + /// + /// This will create a new referendum for the `proposal`, approved as long as counted votes + /// exceed `threshold` and, if approved, enacted after the given `delay`. + /// + /// It may be called from either the Root or the Emergency origin. + fn emergency_propose(origin, + proposal: Box, + threshold: VoteThreshold, + voting_period: T::BlockNumber, + delay: T::BlockNumber + ) { + T::EmergencyOrigin::try_origin(origin) + .map(|_| ()) + .or_else(|origin| ensure_root(origin))?; + let now = >::block_number(); + // We don't consider it an error if `vote_period` is too low, but we do enforce the + // minimum. This is primarily due to practicality. If it's an emergency, we don't want + // to introduce more delays than is strictly needed by requiring a potentially costly + // resubmission in the case of a mistakenly low `vote_period`; better to just let the + // referendum take place with the lowest valid value. + let period = voting_period.max(T::EmergencyVotingPeriod::get()); Self::inject_referendum( - >::block_number() + Self::voting_period(), + now + period, *proposal, threshold, delay, - ).map(|_| ()) + ).map(|_| ())?; + } + + /// Schedule an emergency cancellation of a referendum. Cannot happen twice to the same + /// referendum. + fn emergency_cancel(origin, ref_index: ReferendumIndex) { + T::CancellationOrigin::ensure_origin(origin)?; + + let info = Self::referendum_info(ref_index).ok_or("unknown index")?; + let h = T::Hashing::hash_of(&info.proposal); + ensure!(!>::exists(h), "cannot cancel the same proposal twice"); + + >::insert(h, true); + Self::clear_referendum(ref_index); + } + + /// Schedule a referendum to be tabled once it is legal to schedule an external + /// referendum. + fn external_propose(origin, proposal: Box) { + T::ExternalOrigin::ensure_origin(origin)?; + ensure!(!>::exists(), "proposal already made"); + let proposal_hash = T::Hashing::hash_of(&proposal); + if let Some((until, _)) = >::get(proposal_hash) { + ensure!(>::block_number() >= until, "proposal still blacklisted"); + } + >::put((*proposal, VoteThreshold::SuperMajorityApprove)); + } + + /// Schedule a majority-carries referendum to be tabled next once it is legal to schedule + /// an external referendum. + fn external_propose_majority(origin, proposal: Box) { + T::ExternalMajorityOrigin::ensure_origin(origin)?; + ensure!(!>::exists(), "proposal already made"); + let proposal_hash = T::Hashing::hash_of(&proposal); + if let Some((until, _)) = >::get(proposal_hash) { + ensure!(>::block_number() >= until, "proposal still blacklisted"); + } + >::put((*proposal, VoteThreshold::SimpleMajority)); + } + + /// Veto and blacklist the external proposal hash. + fn veto_external(origin, proposal_hash: T::Hash) { + let who = T::VetoOrigin::ensure_origin(origin)?; + + if let Some((proposal, _)) = >::get() { + ensure!(proposal_hash == T::Hashing::hash_of(&proposal), "unknown proposal"); + } else { + Err("no external proposal")?; + } + + let mut existing_vetoers = >::get(&proposal_hash) + .map(|pair| pair.1) + .unwrap_or_else(Vec::new); + let insert_position = existing_vetoers.binary_search(&who) + .err().ok_or("identity may not veto a proposal twice")?; + + existing_vetoers.insert(insert_position, who.clone()); + let until = >::block_number() + T::CooloffPeriod::get(); + >::insert(&proposal_hash, (until, existing_vetoers)); + + Self::deposit_event(RawEvent::Vetoed(who, proposal_hash, until)); + >::kill(); } /// Remove a referendum. @@ -148,12 +470,22 @@ decl_module! { } /// Cancel a proposal queued for enactment. - pub fn cancel_queued(#[compact] when: T::BlockNumber, #[compact] which: u32) { + fn cancel_queued( + #[compact] when: T::BlockNumber, + #[compact] which: u32, + #[compact] what: ReferendumIndex + ) { let which = which as usize; - >::mutate(when, |items| if items.len() > which { items[which] = None }); + let mut items = >::get(when); + if items.get(which).and_then(Option::as_ref).map_or(false, |x| x.1 == what) { + items[which] = None; + >::insert(when, items); + } else { + Err("proposal not found")? + } } - fn on_finalize(n: T::BlockNumber) { + fn on_initialize(n: T::BlockNumber) { if let Err(e) = Self::end_block(n) { runtime_io::print(e); } @@ -180,11 +512,17 @@ decl_module! { } /// Delegate vote. - pub fn delegate(origin, to: T::AccountId, lock_periods: LockPeriods) { + pub fn delegate(origin, to: T::AccountId, conviction: Conviction) { let who = ensure_signed(origin)?; - >::insert(who.clone(), (to.clone(), lock_periods.clone())); + >::insert(who.clone(), (to.clone(), conviction)); // Currency is locked indefinitely as long as it's delegated. - T::Currency::extend_lock(DEMOCRACY_ID, &who, Bounded::max_value(), T::BlockNumber::max_value(), WithdrawReason::Transfer.into()); + T::Currency::extend_lock( + DEMOCRACY_ID, + &who, + Bounded::max_value(), + T::BlockNumber::max_value(), + WithdrawReason::Transfer.into() + ); Self::deposit_event(RawEvent::Delegated(who, to)); } @@ -192,105 +530,29 @@ decl_module! { fn undelegate(origin) { let who = ensure_signed(origin)?; ensure!(>::exists(&who), "not delegated"); - let d = >::take(&who); + let (_, conviction) = >::take(&who); // Indefinite lock is reduced to the maximum voting lock that could be possible. - let lock_period = Self::public_delay(); let now = >::block_number(); - let locked_until = now + lock_period * T::BlockNumber::sa(d.1 as u64); - T::Currency::set_lock(DEMOCRACY_ID, &who, Bounded::max_value(), locked_until, WithdrawReason::Transfer.into()); + let locked_until = now + T::EnactmentPeriod::get() * conviction.lock_periods().into(); + T::Currency::set_lock( + DEMOCRACY_ID, + &who, + Bounded::max_value(), + locked_until, + WithdrawReason::Transfer.into() + ); Self::deposit_event(RawEvent::Undelegated(who)); } } } -/// Info regarding an ongoing referendum. -#[derive(Encode, Decode, Clone, PartialEq, Eq)] -#[cfg_attr(feature = "std", derive(Debug))] -pub struct ReferendumInfo { - /// When voting on this referendum will end. - end: BlockNumber, - /// The proposal being voted on. - proposal: Proposal, - /// The thresholding mechanism to determine whether it passed. - threshold: VoteThreshold, - /// The delay (in blocks) to wait after a successful referendum before deploying. - delay: BlockNumber, -} - -impl ReferendumInfo { - /// Create a new instance. - pub fn new(end: BlockNumber, proposal: Proposal, threshold: VoteThreshold, delay: BlockNumber) -> Self { - ReferendumInfo { end, proposal, threshold, delay } - } -} - -decl_storage! { - trait Store for Module as Democracy { - - /// The number of (public) proposals that have been made so far. - pub PublicPropCount get(public_prop_count) build(|_| 0 as PropIndex) : PropIndex; - /// The public proposals. Unsorted. - pub PublicProps get(public_props): Vec<(PropIndex, T::Proposal, T::AccountId)>; - /// Those who have locked a deposit. - pub DepositOf get(deposit_of): map PropIndex => Option<(BalanceOf, Vec)>; - /// How often (in blocks) new public referenda are launched. - pub LaunchPeriod get(launch_period) config(): T::BlockNumber = T::BlockNumber::sa(1000); - /// The minimum amount to be used as a deposit for a public referendum proposal. - pub MinimumDeposit get(minimum_deposit) config(): BalanceOf; - /// The delay before enactment for all public referenda. - pub PublicDelay get(public_delay) config(): T::BlockNumber; - /// The maximum number of additional lock periods a voter may offer to strengthen their vote. Multiples of `PublicDelay`. - pub MaxLockPeriods get(max_lock_periods) config(): LockPeriods; - - /// How often (in blocks) to check for new votes. - pub VotingPeriod get(voting_period) config(): T::BlockNumber = T::BlockNumber::sa(1000); - - /// The next free referendum index, aka the number of referenda started so far. - pub ReferendumCount get(referendum_count) build(|_| 0 as ReferendumIndex): ReferendumIndex; - /// The next referendum index that should be tallied. - pub NextTally get(next_tally) build(|_| 0 as ReferendumIndex): ReferendumIndex; - /// Information concerning any given referendum. - pub ReferendumInfoOf get(referendum_info): map ReferendumIndex => Option<(ReferendumInfo)>; - /// Queue of successful referenda to be dispatched. - pub DispatchQueue get(dispatch_queue): map T::BlockNumber => Vec>; - - /// Get the voters for the current proposal. - pub VotersFor get(voters_for): map ReferendumIndex => Vec; - - /// Get the vote in a given referendum of a particular voter. The result is meaningful only if `voters_for` includes the - /// voter when called with the referendum (you'll get the default `Vote` value otherwise). If you don't want to check - /// `voters_for`, then you can also check for simple existence with `VoteOf::exists` first. - pub VoteOf get(vote_of): map (ReferendumIndex, T::AccountId) => Vote; - - /// Who is able to vote for whom. Value is the fund-holding account, key is the vote-transaction-sending account. - pub Proxy get(proxy): map T::AccountId => Option; - - /// Get the account (and lock periods) to which another account is delegating vote. - pub Delegations get(delegations): linked_map T::AccountId => (T::AccountId, LockPeriods); - } -} - -decl_event!( - pub enum Event where Balance = BalanceOf, ::AccountId { - Proposed(PropIndex, Balance), - Tabled(PropIndex, Balance, Vec), - Started(ReferendumIndex, VoteThreshold), - Passed(ReferendumIndex), - NotPassed(ReferendumIndex), - Cancelled(ReferendumIndex), - Executed(ReferendumIndex, bool), - Delegated(AccountId, AccountId), - Undelegated(AccountId), - } -); - impl Module { // exposed immutables. /// Get the amount locked in support of `proposal`; `None` if proposal isn't a valid proposal /// index. pub fn locked_for(proposal: PropIndex) -> Option> { - Self::deposit_of(proposal).map(|(d, l)| d * BalanceOf::::sa(l.len() as u64)) + Self::deposit_of(proposal).map(|(d, l)| d * (l.len() as u32).into()) } /// Return true if `ref_index` is an on-going referendum. @@ -299,7 +561,9 @@ impl Module { } /// Get all referenda currently active. - pub fn active_referenda() -> Vec<(ReferendumIndex, ReferendumInfo)> { + pub fn active_referenda() + -> Vec<(ReferendumIndex, ReferendumInfo)> + { let next = Self::next_tally(); let last = Self::referendum_count(); (next..last).into_iter() @@ -308,7 +572,9 @@ impl Module { } /// Get all referenda ready for tally at block `n`. - pub fn maturing_referenda_at(n: T::BlockNumber) -> Vec<(ReferendumIndex, ReferendumInfo)> { + pub fn maturing_referenda_at( + n: T::BlockNumber + ) -> Vec<(ReferendumIndex, ReferendumInfo)> { let next = Self::next_tally(); let last = Self::referendum_count(); (next..last).into_iter() @@ -319,52 +585,75 @@ impl Module { /// Get the voters for the current proposal. pub fn tally(ref_index: ReferendumIndex) -> (BalanceOf, BalanceOf, BalanceOf) { - let (approve, against, capital): (BalanceOf, BalanceOf, BalanceOf) = Self::voters_for(ref_index).iter() - .map(|voter| ( - T::Currency::total_balance(voter), Self::vote_of((ref_index, voter.clone())) - )) - .map(|(bal, vote)| - if vote.is_aye() { - (bal * BalanceOf::::sa(vote.multiplier() as u64), Zero::zero(), bal) - } else { - (Zero::zero(), bal * BalanceOf::::sa(vote.multiplier() as u64), bal) - } - ).fold((Zero::zero(), Zero::zero(), Zero::zero()), |(a, b, c), (d, e, f)| (a + d, b + e, c + f)); + let (approve, against, capital): + (BalanceOf, BalanceOf, BalanceOf) = Self::voters_for(ref_index) + .iter() + .map(|voter| ( + T::Currency::total_balance(voter), Self::vote_of((ref_index, voter.clone())) + )) + .map(|(balance, Vote { aye, conviction })| { + let (votes, turnout) = conviction.votes(balance); + if aye { + (votes, Zero::zero(), turnout) + } else { + (Zero::zero(), votes, turnout) + } + }).fold( + (Zero::zero(), Zero::zero(), Zero::zero()), + |(a, b, c), (d, e, f)| (a + d, b + e, c + f) + ); let (del_approve, del_against, del_capital) = Self::tally_delegation(ref_index); (approve + del_approve, against + del_against, capital + del_capital) } /// Get the delegated voters for the current proposal. - /// I think this goes into a worker once https://github.com/paritytech/substrate/issues/1458 is done. + /// I think this goes into a worker once https://github.com/paritytech/substrate/issues/1458 is + /// done. fn tally_delegation(ref_index: ReferendumIndex) -> (BalanceOf, BalanceOf, BalanceOf) { - Self::voters_for(ref_index).iter() - .fold((Zero::zero(), Zero::zero(), Zero::zero()), |(approve_acc, against_acc, capital_acc), voter| { - let vote = Self::vote_of((ref_index, voter.clone())); - let (votes, balance) = Self::delegated_votes(ref_index, voter.clone(), vote.multiplier(), MAX_RECURSION_LIMIT); - if vote.is_aye() { - (approve_acc + votes, against_acc, capital_acc + balance) + Self::voters_for(ref_index).iter().fold( + (Zero::zero(), Zero::zero(), Zero::zero()), + |(approve_acc, against_acc, turnout_acc), voter| { + let Vote { aye, conviction } = Self::vote_of((ref_index, voter.clone())); + let (votes, turnout) = Self::delegated_votes( + ref_index, + voter.clone(), + conviction, + MAX_RECURSION_LIMIT + ); + if aye { + (approve_acc + votes, against_acc, turnout_acc + turnout) } else { - (approve_acc, against_acc + votes, capital_acc + balance) + (approve_acc, against_acc + votes, turnout_acc + turnout) } - }) + } + ) } fn delegated_votes( ref_index: ReferendumIndex, to: T::AccountId, - min_lock_periods: LockPeriods, + parent_conviction: Conviction, recursion_limit: u32, ) -> (BalanceOf, BalanceOf) { if recursion_limit == 0 { return (Zero::zero(), Zero::zero()); } >::enumerate() - .filter(|(delegator, (delegate, _))| *delegate == to && !>::exists(&(ref_index, delegator.clone()))) - .fold((Zero::zero(), Zero::zero()), |(votes_acc, balance_acc), (delegator, (_delegate, periods))| { - let lock_periods = if min_lock_periods <= periods { min_lock_periods } else { periods }; - let balance = T::Currency::total_balance(&delegator); - let votes = T::Currency::total_balance(&delegator) * BalanceOf::::sa(lock_periods as u64); - let (del_votes, del_balance) = Self::delegated_votes(ref_index, delegator, lock_periods, recursion_limit - 1); - (votes_acc + votes + del_votes, balance_acc + balance + del_balance) - }) + .filter(|(delegator, (delegate, _))| + *delegate == to && !>::exists(&(ref_index, delegator.clone())) + ).fold( + (Zero::zero(), Zero::zero()), + |(votes_acc, turnout_acc), (delegator, (_delegate, max_conviction))| { + let conviction = Conviction::min(parent_conviction, max_conviction); + let balance = T::Currency::total_balance(&delegator); + let (votes, turnout) = conviction.votes(balance); + let (del_votes, del_turnout) = Self::delegated_votes( + ref_index, + delegator, + conviction, + recursion_limit - 1 + ); + (votes_acc + votes + del_votes, turnout_acc + turnout + del_turnout) + } + ) } // Exposed mutables. @@ -375,8 +664,17 @@ impl Module { } /// Start a referendum. Can be called directly by the council. - pub fn internal_start_referendum(proposal: T::Proposal, threshold: VoteThreshold, delay: T::BlockNumber) -> result::Result { - >::inject_referendum(>::block_number() + >::voting_period(), proposal, threshold, delay) + pub fn internal_start_referendum( + proposal: T::Proposal, + threshold: VoteThreshold, + delay: T::BlockNumber + ) -> result::Result { + >::inject_referendum( + >::block_number() + T::VotingPeriod::get(), + proposal, + threshold, + delay + ) } /// Remove a referendum. Can be called directly by the council. @@ -389,7 +687,6 @@ impl Module { /// Actually enact a vote, if legit. fn do_vote(who: T::AccountId, ref_index: ReferendumIndex, vote: Vote) -> Result { - ensure!(vote.multiplier() <= Self::max_lock_periods(), "vote has too great a strength"); ensure!(Self::is_active_referendum(ref_index), "vote given for invalid referendum."); if !>::exists(&(ref_index, who.clone())) { >::mutate(ref_index, |voters| voters.push(who.clone())); @@ -406,12 +703,17 @@ impl Module { delay: T::BlockNumber, ) -> result::Result { let ref_index = Self::referendum_count(); - if ref_index > 0 && Self::referendum_info(ref_index - 1).map(|i| i.end > end).unwrap_or(false) { + if ref_index.checked_sub(1) + .and_then(Self::referendum_info) + .map(|i| i.end > end) + .unwrap_or(false) + { Err("Cannot inject a referendum that ends earlier than preceeding referendum")? } >::put(ref_index + 1); - >::insert(ref_index, ReferendumInfo { end, proposal, threshold, delay }); + let item = ReferendumInfo { end, proposal, threshold, delay }; + >::insert(ref_index, item); Self::deposit_event(RawEvent::Started(ref_index, threshold)); Ok(ref_index) } @@ -431,47 +733,92 @@ impl Module { Self::deposit_event(RawEvent::Executed(index, ok)); } + /// Table the next waiting proposal for a vote. fn launch_next(now: T::BlockNumber) -> Result { + if >::take() { + Self::launch_public(now).or_else(|_| Self::launch_external(now)) + } else { + Self::launch_external(now).or_else(|_| Self::launch_public(now)) + }.map_err(|_| "No proposals waiting") + } + + /// Table the waiting external proposal for a vote, if there is one. + fn launch_external(now: T::BlockNumber) -> Result { + if let Some((proposal, threshold)) = >::take() { + >::put(true); + Self::deposit_event(RawEvent::ExternalTabled); + Self::inject_referendum( + now + T::VotingPeriod::get(), + proposal, + threshold, + T::EnactmentPeriod::get(), + )?; + Ok(()) + } else { + Err("No external proposal waiting") + } + } + + /// Table the waiting public proposal with the highest backing for a vote. + fn launch_public(now: T::BlockNumber) -> Result { let mut public_props = Self::public_props(); if let Some((winner_index, _)) = public_props.iter() .enumerate() - .max_by_key(|x| Self::locked_for((x.1).0).unwrap_or_else(Zero::zero)/*defensive only: All current public proposals have an amount locked*/) + .max_by_key(|x| Self::locked_for((x.1).0).unwrap_or_else(Zero::zero) + /* ^^ defensive only: All current public proposals have an amount locked*/) { let (prop_index, proposal, _) = public_props.swap_remove(winner_index); >::put(public_props); - if let Some((deposit, depositors)) = >::take(prop_index) {//: (BalanceOf, Vec) = + if let Some((deposit, depositors)) = >::take(prop_index) { // refund depositors for d in &depositors { T::Currency::unreserve(d, deposit); } Self::deposit_event(RawEvent::Tabled(prop_index, deposit, depositors)); - Self::inject_referendum(now + Self::voting_period(), proposal, VoteThreshold::SuperMajorityApprove, Self::public_delay())?; + Self::inject_referendum( + now + T::VotingPeriod::get(), + proposal, + VoteThreshold::SuperMajorityApprove, + T::EnactmentPeriod::get(), + )?; } + Ok(()) + } else { + Err("No public proposals waiting") } - Ok(()) } - fn bake_referendum(now: T::BlockNumber, index: ReferendumIndex, info: ReferendumInfo) -> Result { + fn bake_referendum( + now: T::BlockNumber, + index: ReferendumIndex, + info: ReferendumInfo + ) -> Result { let (approve, against, capital) = Self::tally(index); let total_issuance = T::Currency::total_issuance(); let approved = info.threshold.approved(approve, against, capital, total_issuance); - let lock_period = Self::public_delay(); // Logic defined in https://www.slideshare.net/gavofyork/governance-in-polkadot-poc3 // Essentially, we extend the lock-period of the coins behind the winning votes to be the // vote strength times the public delay period from now. - for (a, vote) in Self::voters_for(index).into_iter() + for (a, Vote { conviction, .. }) in Self::voters_for(index).into_iter() .map(|a| (a.clone(), Self::vote_of((index, a)))) - // ^^^ defensive only: all items come from `voters`; for an item to be in `voters` there must be a vote registered; qed - .filter(|&(_, vote)| vote.is_aye() == approved) // Just the winning coins + // ^^^ defensive only: all items come from `voters`; for an item to be in `voters` + // there must be a vote registered; qed + .filter(|&(_, vote)| vote.aye == approved) // Just the winning coins { - // now plus: the base lock period multiplied by the number of periods this voter offered to - // lock should they win... - let locked_until = now + lock_period * T::BlockNumber::sa((vote.multiplier()) as u64); + // now plus: the base lock period multiplied by the number of periods this voter + // offered to lock should they win... + let locked_until = now + T::EnactmentPeriod::get() * conviction.lock_periods().into(); // ...extend their bondage until at least then. - T::Currency::extend_lock(DEMOCRACY_ID, &a, Bounded::max_value(), locked_until, WithdrawReason::Transfer.into()); + T::Currency::extend_lock( + DEMOCRACY_ID, + &a, + Bounded::max_value(), + locked_until, + WithdrawReason::Transfer.into() + ); } Self::clear_referendum(index); @@ -480,7 +827,10 @@ impl Module { if info.delay.is_zero() { Self::enact_proposal(info.proposal, index); } else { - >::mutate(now + info.delay, |q| q.push(Some((info.proposal, index)))); + >::mutate( + now + info.delay, + |q| q.push(Some((info.proposal, index))) + ); } } else { Self::deposit_event(RawEvent::NotPassed(index)); @@ -491,10 +841,13 @@ impl Module { } /// Current era is ending; we should finish up any proposals. + // TODO: move to initialize_block #2779 fn end_block(now: T::BlockNumber) -> Result { // pick out another public referendum if it's time. - if (now % Self::launch_period()).is_zero() { - Self::launch_next(now.clone())?; + if (now % T::LaunchPeriod::get()).is_zero() { + // Errors come from the queue being empty. we don't really care about that, and even if + // we did, there is nothing we can do here. + let _ = Self::launch_next(now.clone()); } // tally up votes for any expiring referenda. @@ -519,15 +872,21 @@ impl OnFreeBalanceZero for Module { mod tests { use super::*; use runtime_io::with_externalities; - use srml_support::{impl_outer_origin, impl_outer_dispatch, assert_noop, assert_ok}; + use srml_support::{ + impl_outer_origin, impl_outer_dispatch, assert_noop, assert_ok, parameter_types, + traits::Contains + }; use substrate_primitives::{H256, Blake2Hasher}; use primitives::BuildStorage; - use primitives::traits::{BlakeTwo256, IdentityLookup}; + use primitives::traits::{BlakeTwo256, IdentityLookup, Bounded}; use primitives::testing::{Digest, DigestItem, Header}; use balances::BalanceLock; + use system::EnsureSignedBy; - const AYE: Vote = Vote(-1); - const NAY: Vote = Vote(0); + const AYE: Vote = Vote{ aye: true, conviction: Conviction::None }; + const NAY: Vote = Vote{ aye: false, conviction: Conviction::None }; + const BIG_AYE: Vote = Vote{ aye: true, conviction: Conviction::Locked1x }; + const BIG_NAY: Vote = Vote{ aye: false, conviction: Conviction::Locked1x }; impl_outer_origin! { pub enum Origin for Test {} @@ -565,17 +924,43 @@ mod tests { type TransferPayment = (); type DustRemoval = (); } - impl Trait for Test { - type Currency = balances::Module; + parameter_types! { + pub const LaunchPeriod: u64 = 2; + pub const VotingPeriod: u64 = 2; + pub const EmergencyVotingPeriod: u64 = 1; + pub const MinimumDeposit: u64 = 1; + pub const EnactmentPeriod: u64 = 2; + pub const CooloffPeriod: u64 = 2; + pub const One: u64 = 1; + pub const Two: u64 = 2; + pub const Three: u64 = 3; + pub const Four: u64 = 4; + pub const Five: u64 = 5; + } + pub struct OneToFive; + impl Contains for OneToFive { + fn contains(n: &u64) -> bool { + *n >= 1 && *n <= 5 + } + } + impl super::Trait for Test { type Proposal = Call; type Event = (); + type Currency = balances::Module; + type EnactmentPeriod = EnactmentPeriod; + type LaunchPeriod = LaunchPeriod; + type VotingPeriod = VotingPeriod; + type EmergencyVotingPeriod = EmergencyVotingPeriod; + type MinimumDeposit = MinimumDeposit; + type EmergencyOrigin = EnsureSignedBy; + type ExternalOrigin = EnsureSignedBy; + type ExternalMajorityOrigin = EnsureSignedBy; + type CancellationOrigin = EnsureSignedBy; + type VetoOrigin = EnsureSignedBy; + type CooloffPeriod = CooloffPeriod; } fn new_test_ext() -> runtime_io::TestExternalities { - new_test_ext_with_public_delay(0) - } - - fn new_test_ext_with_public_delay(public_delay: u64) -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap().0; t.extend(balances::GenesisConfig::{ transaction_base_fee: 0, @@ -586,13 +971,7 @@ mod tests { creation_fee: 0, vesting: vec![], }.build_storage().unwrap().0); - t.extend(GenesisConfig::{ - launch_period: 1, - voting_period: 1, - minimum_deposit: 1, - public_delay, - max_lock_periods: 6, - }.build_storage().unwrap().0); + t.extend(GenesisConfig::::default().build_storage().unwrap().0); runtime_io::TestExternalities::new(t) } @@ -603,49 +982,347 @@ mod tests { #[test] fn params_should_work() { with_externalities(&mut new_test_ext(), || { - assert_eq!(Democracy::launch_period(), 1); - assert_eq!(Democracy::voting_period(), 1); - assert_eq!(Democracy::minimum_deposit(), 1); assert_eq!(Democracy::referendum_count(), 0); assert_eq!(Balances::free_balance(&42), 0); assert_eq!(Balances::total_issuance(), 210); - assert_eq!(Democracy::public_delay(), 0); - assert_eq!(Democracy::max_lock_periods(), 6); }); } + fn set_balance_proposal(value: u64) -> Call { + Call::Balances(balances::Call::set_balance(42, value, 0)) + } + + fn propose_set_balance(who: u64, value: u64, delay: u64) -> super::Result { + Democracy::propose( + Origin::signed(who), + Box::new(set_balance_proposal(value)), + delay + ) + } + + fn next_block() { + assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + System::set_block_number(System::block_number() + 1); + } + + fn fast_forward_to(n: u64) { + while System::block_number() < n { + next_block(); + } + } + #[test] - fn vote_should_work() { - assert_eq!(Vote::new(true, 0).multiplier(), 1); - assert_eq!(Vote::new(true, 1).multiplier(), 1); - assert_eq!(Vote::new(true, 2).multiplier(), 2); - assert_eq!(Vote::new(true, 0).is_aye(), true); - assert_eq!(Vote::new(true, 1).is_aye(), true); - assert_eq!(Vote::new(true, 2).is_aye(), true); - assert_eq!(Vote::new(false, 0).multiplier(), 1); - assert_eq!(Vote::new(false, 1).multiplier(), 1); - assert_eq!(Vote::new(false, 2).multiplier(), 2); - assert_eq!(Vote::new(false, 0).is_aye(), false); - assert_eq!(Vote::new(false, 1).is_aye(), false); - assert_eq!(Vote::new(false, 2).is_aye(), false); + fn external_and_public_interleaving_works() { + with_externalities(&mut new_test_ext(), || { + System::set_block_number(0); + assert_ok!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(1)), + )); + assert_ok!(propose_set_balance(6, 2, 2)); + + fast_forward_to(1); + + // both waiting: external goes first. + assert_eq!( + Democracy::referendum_info(0), + Some(ReferendumInfo { + end: 2, + proposal: set_balance_proposal(1), + threshold: VoteThreshold::SuperMajorityApprove, + delay: 2 + }) + ); + // replenish external + assert_ok!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(3)), + )); + + fast_forward_to(3); + + // both waiting: public goes next. + assert_eq!( + Democracy::referendum_info(1), + Some(ReferendumInfo { + end: 4, + proposal: set_balance_proposal(2), + threshold: VoteThreshold::SuperMajorityApprove, + delay: 2 + }) + ); + // don't replenish public + + fast_forward_to(5); + + // it's external "turn" again, though since public is empty that doesn't really matter + assert_eq!( + Democracy::referendum_info(2), + Some(ReferendumInfo { + end: 6, + proposal: set_balance_proposal(3), + threshold: VoteThreshold::SuperMajorityApprove, + delay: 2 + }) + ); + // replenish external + assert_ok!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(5)), + )); + + fast_forward_to(7); + + // external goes again because there's no public waiting. + assert_eq!( + Democracy::referendum_info(3), + Some(ReferendumInfo { + end: 8, + proposal: set_balance_proposal(5), + threshold: VoteThreshold::SuperMajorityApprove, + delay: 2 + }) + ); + // replenish both + assert_ok!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(7)), + )); + assert_ok!(propose_set_balance(6, 4, 2)); + + fast_forward_to(9); + + // public goes now since external went last time. + assert_eq!( + Democracy::referendum_info(4), + Some(ReferendumInfo { + end: 10, + proposal: set_balance_proposal(4), + threshold: VoteThreshold::SuperMajorityApprove, + delay: 2 + }) + ); + // replenish public again + assert_ok!(propose_set_balance(6, 6, 2)); + // cancel external + let h = BlakeTwo256::hash_of(&set_balance_proposal(7)); + assert_ok!(Democracy::veto_external(Origin::signed(3), h)); + + fast_forward_to(11); + + // public goes again now since there's no external waiting. + assert_eq!( + Democracy::referendum_info(5), + Some(ReferendumInfo { + end: 12, + proposal: set_balance_proposal(6), + threshold: VoteThreshold::SuperMajorityApprove, + delay: 2 + }) + ); + }); } + #[test] - fn invalid_vote_strength_should_not_work() { + fn emergency_cancel_should_work() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); - assert_noop!(Democracy::vote(Origin::signed(1), r, Vote::new(true, 7)), "vote has too great a strength"); - assert_noop!(Democracy::vote(Origin::signed(1), r, Vote::new(false, 7)), "vote has too great a strength"); + System::set_block_number(0); + let r = Democracy::inject_referendum( + 2, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 2 + ).unwrap(); + assert!(Democracy::referendum_info(r).is_some()); + + assert_noop!(Democracy::emergency_cancel(Origin::signed(3), r), "Invalid origin"); + assert_ok!(Democracy::emergency_cancel(Origin::signed(4), r)); + assert!(Democracy::referendum_info(r).is_none()); + + // some time later... + + let r = Democracy::inject_referendum( + 2, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 2 + ).unwrap(); + assert!(Democracy::referendum_info(r).is_some()); + assert_noop!(Democracy::emergency_cancel(Origin::signed(4), r), "cannot cancel the same proposal twice"); }); } - fn set_balance_proposal(value: u64) -> Call { - Call::Balances(balances::Call::set_balance(42, value.into(), 0)) + #[test] + fn veto_external_works() { + with_externalities(&mut new_test_ext(), || { + System::set_block_number(0); + assert_ok!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(2)), + )); + assert!(>::exists()); + + let h = BlakeTwo256::hash_of(&set_balance_proposal(2)); + assert_ok!(Democracy::veto_external(Origin::signed(3), h.clone())); + // cancelled. + assert!(!>::exists()); + // fails - same proposal can't be resubmitted. + assert_noop!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(2)), + ), "proposal still blacklisted"); + + fast_forward_to(1); + // fails as we're still in cooloff period. + assert_noop!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(2)), + ), "proposal still blacklisted"); + + fast_forward_to(2); + // works; as we're out of the cooloff period. + assert_ok!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(2)), + )); + assert!(>::exists()); + + // 3 can't veto the same thing twice. + assert_noop!( + Democracy::veto_external(Origin::signed(3), h.clone()), + "identity may not veto a proposal twice" + ); + + // 4 vetoes. + assert_ok!(Democracy::veto_external(Origin::signed(4), h.clone())); + // cancelled again. + assert!(!>::exists()); + + fast_forward_to(3); + // same proposal fails as we're still in cooloff + assert_noop!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(2)), + ), "proposal still blacklisted"); + // different proposal works fine. + assert_ok!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(3)), + )); + }); + } + + #[test] + fn emergency_referendum_works() { + with_externalities(&mut new_test_ext(), || { + System::set_block_number(0); + assert_noop!(Democracy::emergency_propose( + Origin::signed(6), // invalid + Box::new(set_balance_proposal(2)), + VoteThreshold::SuperMajorityAgainst, + 0, + 0, + ), "bad origin: expected to be a root origin"); + assert_ok!(Democracy::emergency_propose( + Origin::signed(1), + Box::new(set_balance_proposal(2)), + VoteThreshold::SuperMajorityAgainst, + 0, + 0, + )); + assert_eq!( + Democracy::referendum_info(0), + Some(ReferendumInfo { + end: 1, + proposal: set_balance_proposal(2), + threshold: VoteThreshold::SuperMajorityAgainst, + delay: 0 + }) + ); + + assert_ok!(Democracy::vote(Origin::signed(1), 0, AYE)); + fast_forward_to(1); + assert_eq!(Balances::free_balance(&42), 0); + fast_forward_to(2); + assert_eq!(Balances::free_balance(&42), 2); + + assert_ok!(Democracy::emergency_propose( + Origin::signed(1), + Box::new(set_balance_proposal(4)), + VoteThreshold::SuperMajorityAgainst, + 3, + 3 + )); + assert_eq!( + Democracy::referendum_info(1), + Some(ReferendumInfo { + end: 5, + proposal: set_balance_proposal(4), + threshold: VoteThreshold::SuperMajorityAgainst, + delay: 3 + }) + ); + assert_ok!(Democracy::vote(Origin::signed(1), 1, AYE)); + fast_forward_to(8); + assert_eq!(Balances::free_balance(&42), 2); + fast_forward_to(9); + assert_eq!(Balances::free_balance(&42), 4); + }); } - fn propose_set_balance(who: u64, value: u64, locked: u64) -> super::Result { - Democracy::propose(Origin::signed(who), Box::new(set_balance_proposal(value)), locked.into()) + #[test] + fn external_referendum_works() { + with_externalities(&mut new_test_ext(), || { + System::set_block_number(0); + assert_noop!(Democracy::external_propose( + Origin::signed(1), + Box::new(set_balance_proposal(2)), + ), "Invalid origin"); + assert_ok!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(2)), + )); + assert_noop!(Democracy::external_propose( + Origin::signed(2), + Box::new(set_balance_proposal(1)), + ), "proposal already made"); + fast_forward_to(1); + assert_eq!( + Democracy::referendum_info(0), + Some(ReferendumInfo { + end: 2, + proposal: set_balance_proposal(2), + threshold: VoteThreshold::SuperMajorityApprove, + delay: 2 + }) + ); + }); + } + + #[test] + fn external_majority_referendum_works() { + with_externalities(&mut new_test_ext(), || { + System::set_block_number(0); + assert_noop!(Democracy::external_propose_majority( + Origin::signed(1), + Box::new(set_balance_proposal(2)) + ), "Invalid origin"); + assert_ok!(Democracy::external_propose_majority( + Origin::signed(3), + Box::new(set_balance_proposal(2)) + )); + fast_forward_to(1); + assert_eq!( + Democracy::referendum_info(0), + Some(ReferendumInfo { + end: 2, + proposal: set_balance_proposal(2), + threshold: VoteThreshold::SimpleMajority, + delay: 2, + }) + ); + }); } #[test] @@ -664,24 +1341,74 @@ mod tests { #[test] fn single_proposal_should_work() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); + System::set_block_number(0); assert_ok!(propose_set_balance(1, 2, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + assert!(Democracy::referendum_info(0).is_none()); + + // end of 0 => next referendum scheduled. + fast_forward_to(1); - System::set_block_number(2); let r = 0; assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); assert_eq!(Democracy::referendum_count(), 1); + assert_eq!( + Democracy::referendum_info(0), + Some(ReferendumInfo { + end: 2, + proposal: set_balance_proposal(2), + threshold: VoteThreshold::SuperMajorityApprove, + delay: 2 + }) + ); assert_eq!(Democracy::voters_for(r), vec![1]); assert_eq!(Democracy::vote_of((r, 1)), AYE); - assert_eq!(Democracy::tally(r), (10, 0, 10)); + assert_eq!(Democracy::tally(r), (1, 0, 1)); + + fast_forward_to(2); + + // referendum still running + assert!(Democracy::referendum_info(0).is_some()); + + // referendum runs during 1 and 2, ends @ end of 2. + fast_forward_to(3); + + assert!(Democracy::referendum_info(0).is_none()); + assert_eq!(Democracy::dispatch_queue(4), vec![ + Some((set_balance_proposal(2), 0)) + ]); + + // referendum passes and wait another two blocks for enactment. + fast_forward_to(5); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); assert_eq!(Balances::free_balance(&42), 2); }); } + #[test] + fn cancel_queued_should_work() { + with_externalities(&mut new_test_ext(), || { + System::set_block_number(0); + assert_ok!(propose_set_balance(1, 2, 1)); + + // end of 0 => next referendum scheduled. + fast_forward_to(1); + + assert_ok!(Democracy::vote(Origin::signed(1), 0, AYE)); + + fast_forward_to(3); + + assert_eq!(Democracy::dispatch_queue(4), vec![ + Some((set_balance_proposal(2), 0)) + ]); + + assert_noop!(Democracy::cancel_queued(3, 0, 0), "proposal not found"); + assert_noop!(Democracy::cancel_queued(4, 1, 0), "proposal not found"); + assert_ok!(Democracy::cancel_queued(4, 0, 0)); + assert_eq!(Democracy::dispatch_queue(4), vec![None]); + }); + } + #[test] fn proxy_should_work() { with_externalities(&mut new_test_ext(), || { @@ -715,21 +1442,19 @@ mod tests { #[test] fn single_proposal_should_work_with_proxy() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); + System::set_block_number(0); assert_ok!(propose_set_balance(1, 2, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - System::set_block_number(2); + fast_forward_to(1); let r = 0; assert_ok!(Democracy::set_proxy(Origin::signed(1), 10)); assert_ok!(Democracy::proxy_vote(Origin::signed(10), r, AYE)); - assert_eq!(Democracy::referendum_count(), 1); assert_eq!(Democracy::voters_for(r), vec![1]); assert_eq!(Democracy::vote_of((r, 1)), AYE); - assert_eq!(Democracy::tally(r), (10, 0, 10)); + assert_eq!(Democracy::tally(r), (1, 0, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + fast_forward_to(5); assert_eq!(Balances::free_balance(&42), 2); }); } @@ -737,27 +1462,23 @@ mod tests { #[test] fn single_proposal_should_work_with_delegation() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); + System::set_block_number(0); assert_ok!(propose_set_balance(1, 2, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - System::set_block_number(2); - let r = 0; + fast_forward_to(1); // Delegate vote. - assert_ok!(Democracy::delegate(Origin::signed(2), 1, 100)); + assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::max_value())); + let r = 0; assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); - - assert_eq!(Democracy::referendum_count(), 1); assert_eq!(Democracy::voters_for(r), vec![1]); assert_eq!(Democracy::vote_of((r, 1)), AYE); - // Delegated vote is counted. - assert_eq!(Democracy::tally(r), (30, 0, 30)); + assert_eq!(Democracy::tally(r), (3, 0, 3)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + fast_forward_to(5); assert_eq!(Balances::free_balance(&42), 2); }); @@ -766,27 +1487,24 @@ mod tests { #[test] fn single_proposal_should_work_with_cyclic_delegation() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); + System::set_block_number(0); assert_ok!(propose_set_balance(1, 2, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - System::set_block_number(2); - let r = 0; + fast_forward_to(1); // Check behavior with cycle. - assert_ok!(Democracy::delegate(Origin::signed(2), 1, 100)); - assert_ok!(Democracy::delegate(Origin::signed(3), 2, 100)); - assert_ok!(Democracy::delegate(Origin::signed(1), 3, 100)); - + assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::max_value())); + assert_ok!(Democracy::delegate(Origin::signed(3), 2, Conviction::max_value())); + assert_ok!(Democracy::delegate(Origin::signed(1), 3, Conviction::max_value())); + let r = 0; assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); - - assert_eq!(Democracy::referendum_count(), 1); assert_eq!(Democracy::voters_for(r), vec![1]); // Delegated vote is counted. - assert_eq!(Democracy::tally(r), (60, 0, 60)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + assert_eq!(Democracy::tally(r), (6, 0, 6)); + + fast_forward_to(5); assert_eq!(Balances::free_balance(&42), 2); }); @@ -796,30 +1514,24 @@ mod tests { /// If transactor already voted, delegated vote is overwriten. fn single_proposal_should_work_with_vote_and_delegation() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); + System::set_block_number(0); assert_ok!(propose_set_balance(1, 2, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - System::set_block_number(2); - let r = 0; + fast_forward_to(1); + let r = 0; assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); - // Vote. assert_ok!(Democracy::vote(Origin::signed(2), r, AYE)); - // Delegate vote. - assert_ok!(Democracy::delegate(Origin::signed(2), 1, 100)); - - assert_eq!(Democracy::referendum_count(), 1); + assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::max_value())); assert_eq!(Democracy::voters_for(r), vec![1, 2]); assert_eq!(Democracy::vote_of((r, 1)), AYE); - // Delegated vote is not counted. - assert_eq!(Democracy::tally(r), (30, 0, 30)); + assert_eq!(Democracy::tally(r), (3, 0, 3)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + fast_forward_to(5); assert_eq!(Balances::free_balance(&42), 2); }); @@ -828,16 +1540,15 @@ mod tests { #[test] fn single_proposal_should_work_with_undelegation() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); + System::set_block_number(0); assert_ok!(propose_set_balance(1, 2, 1)); // Delegate and undelegate vote. - assert_ok!(Democracy::delegate(Origin::signed(2), 1, 100)); + assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::max_value())); assert_ok!(Democracy::undelegate(Origin::signed(2))); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - System::set_block_number(2); + fast_forward_to(1); let r = 0; assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); @@ -846,9 +1557,9 @@ mod tests { assert_eq!(Democracy::vote_of((r, 1)), AYE); // Delegated vote is not counted. - assert_eq!(Democracy::tally(r), (10, 0, 10)); + assert_eq!(Democracy::tally(r), (1, 0, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + fast_forward_to(5); assert_eq!(Balances::free_balance(&42), 2); }); @@ -858,18 +1569,17 @@ mod tests { /// If transactor voted, delegated vote is overwriten. fn single_proposal_should_work_with_delegation_and_vote() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); + System::set_block_number(0); assert_ok!(propose_set_balance(1, 2, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - System::set_block_number(2); + fast_forward_to(1); let r = 0; assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); // Delegate vote. - assert_ok!(Democracy::delegate(Origin::signed(2), 1, 100)); + assert_ok!(Democracy::delegate(Origin::signed(2), 1, Conviction::max_value())); // Vote. assert_ok!(Democracy::vote(Origin::signed(2), r, AYE)); @@ -879,9 +1589,9 @@ mod tests { assert_eq!(Democracy::vote_of((r, 1)), AYE); // Delegated vote is not counted. - assert_eq!(Democracy::tally(r), (30, 0, 30)); + assert_eq!(Democracy::tally(r), (3, 0, 3)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + fast_forward_to(5); assert_eq!(Balances::free_balance(&42), 2); }); @@ -911,7 +1621,7 @@ mod tests { assert_ok!(Democracy::second(Origin::signed(5), 0)); assert_ok!(Democracy::second(Origin::signed(5), 0)); assert_ok!(Democracy::second(Origin::signed(5), 0)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + fast_forward_to(3); assert_eq!(Balances::free_balance(&1), 10); assert_eq!(Balances::free_balance(&2), 20); assert_eq!(Balances::free_balance(&5), 50); @@ -950,21 +1660,12 @@ mod tests { assert_ok!(propose_set_balance(1, 2, 2)); assert_ok!(propose_set_balance(1, 4, 4)); assert_ok!(propose_set_balance(1, 3, 3)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - - System::set_block_number(1); + fast_forward_to(1); assert_ok!(Democracy::vote(Origin::signed(1), 0, AYE)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - assert_eq!(Balances::free_balance(&42), 4); - - System::set_block_number(2); + fast_forward_to(3); assert_ok!(Democracy::vote(Origin::signed(1), 1, AYE)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - assert_eq!(Balances::free_balance(&42), 3); - - System::set_block_number(3); + fast_forward_to(5); assert_ok!(Democracy::vote(Origin::signed(1), 2, AYE)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); }); } @@ -972,14 +1673,20 @@ mod tests { fn simple_passing_should_work() { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 0 + ).unwrap(); assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); assert_eq!(Democracy::voters_for(r), vec![1]); assert_eq!(Democracy::vote_of((r, 1)), AYE); - assert_eq!(Democracy::tally(r), (10, 0, 10)); + assert_eq!(Democracy::tally(r), (1, 0, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + next_block(); + next_block(); assert_eq!(Balances::free_balance(&42), 2); }); @@ -989,11 +1696,17 @@ mod tests { fn cancel_referendum_should_work() { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 0 + ).unwrap(); assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); assert_ok!(Democracy::cancel_referendum(r.into())); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + next_block(); + next_block(); assert_eq!(Balances::free_balance(&42), 0); }); @@ -1003,14 +1716,20 @@ mod tests { fn simple_failing_should_work() { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 0 + ).unwrap(); assert_ok!(Democracy::vote(Origin::signed(1), r, NAY)); assert_eq!(Democracy::voters_for(r), vec![1]); assert_eq!(Democracy::vote_of((r, 1)), NAY); - assert_eq!(Democracy::tally(r), (0, 10, 10)); + assert_eq!(Democracy::tally(r), (0, 1, 1)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + next_block(); + next_block(); assert_eq!(Balances::free_balance(&42), 0); }); @@ -1020,17 +1739,23 @@ mod tests { fn controversial_voting_should_work() { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); - assert_ok!(Democracy::vote(Origin::signed(2), r, NAY)); - assert_ok!(Democracy::vote(Origin::signed(3), r, NAY)); - assert_ok!(Democracy::vote(Origin::signed(4), r, AYE)); - assert_ok!(Democracy::vote(Origin::signed(5), r, NAY)); - assert_ok!(Democracy::vote(Origin::signed(6), r, AYE)); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 0 + ).unwrap(); + assert_ok!(Democracy::vote(Origin::signed(1), r, BIG_AYE)); + assert_ok!(Democracy::vote(Origin::signed(2), r, BIG_NAY)); + assert_ok!(Democracy::vote(Origin::signed(3), r, BIG_NAY)); + assert_ok!(Democracy::vote(Origin::signed(4), r, BIG_AYE)); + assert_ok!(Democracy::vote(Origin::signed(5), r, BIG_NAY)); + assert_ok!(Democracy::vote(Origin::signed(6), r, BIG_AYE)); assert_eq!(Democracy::tally(r), (110, 100, 210)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + next_block(); + next_block(); assert_eq!(Balances::free_balance(&42), 2); }); @@ -1040,7 +1765,12 @@ mod tests { fn delayed_enactment_should_work() { with_externalities(&mut new_test_ext(), || { System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 1).unwrap(); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 1 + ).unwrap(); assert_ok!(Democracy::vote(Origin::signed(1), r, AYE)); assert_ok!(Democracy::vote(Origin::signed(2), r, AYE)); assert_ok!(Democracy::vote(Origin::signed(3), r, AYE)); @@ -1048,102 +1778,157 @@ mod tests { assert_ok!(Democracy::vote(Origin::signed(5), r, AYE)); assert_ok!(Democracy::vote(Origin::signed(6), r, AYE)); - assert_eq!(Democracy::tally(r), (210, 0, 210)); + assert_eq!(Democracy::tally(r), (21, 0, 21)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + next_block(); assert_eq!(Balances::free_balance(&42), 0); - System::set_block_number(2); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + next_block(); assert_eq!(Balances::free_balance(&42), 2); }); } #[test] - fn lock_voting_should_work() { - with_externalities(&mut new_test_ext_with_public_delay(1), || { + fn controversial_low_turnout_voting_should_work() { + with_externalities(&mut new_test_ext(), || { System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(1), r, Vote::new(false, 6))); - assert_ok!(Democracy::vote(Origin::signed(2), r, Vote::new(true, 5))); - assert_ok!(Democracy::vote(Origin::signed(3), r, Vote::new(true, 4))); - assert_ok!(Democracy::vote(Origin::signed(4), r, Vote::new(true, 3))); - assert_ok!(Democracy::vote(Origin::signed(5), r, Vote::new(true, 2))); - assert_ok!(Democracy::vote(Origin::signed(6), r, Vote::new(false, 1))); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 0 + ).unwrap(); + assert_ok!(Democracy::vote(Origin::signed(5), r, BIG_NAY)); + assert_ok!(Democracy::vote(Origin::signed(6), r, BIG_AYE)); - assert_eq!(Democracy::tally(r), (440, 120, 210)); - - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); - - assert_eq!(Balances::locks(1), vec![]); - assert_eq!(Balances::locks(2), vec![BalanceLock { id: DEMOCRACY_ID, amount: u64::max_value(), until: 6, reasons: WithdrawReason::Transfer.into() }]); - assert_eq!(Balances::locks(3), vec![BalanceLock { id: DEMOCRACY_ID, amount: u64::max_value(), until: 5, reasons: WithdrawReason::Transfer.into() }]); - assert_eq!(Balances::locks(4), vec![BalanceLock { id: DEMOCRACY_ID, amount: u64::max_value(), until: 4, reasons: WithdrawReason::Transfer.into() }]); - assert_eq!(Balances::locks(5), vec![BalanceLock { id: DEMOCRACY_ID, amount: u64::max_value(), until: 3, reasons: WithdrawReason::Transfer.into() }]); - assert_eq!(Balances::locks(6), vec![]); + assert_eq!(Democracy::tally(r), (60, 50, 110)); - System::set_block_number(2); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + next_block(); + next_block(); - assert_eq!(Balances::free_balance(&42), 2); + assert_eq!(Balances::free_balance(&42), 0); }); } #[test] - fn lock_voting_should_work_with_delegation() { - with_externalities(&mut new_test_ext_with_public_delay(1), || { - System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(1), r, Vote::new(false, 6))); - assert_ok!(Democracy::vote(Origin::signed(2), r, Vote::new(true, 5))); - assert_ok!(Democracy::vote(Origin::signed(3), r, Vote::new(true, 4))); - assert_ok!(Democracy::vote(Origin::signed(4), r, Vote::new(true, 3))); - assert_ok!(Democracy::delegate(Origin::signed(5), 2, 2)); - assert_ok!(Democracy::vote(Origin::signed(6), r, Vote::new(false, 1))); + fn passing_low_turnout_voting_should_work() { + with_externalities(&mut new_test_ext(), || { + assert_eq!(Balances::free_balance(&42), 0); + assert_eq!(Balances::total_issuance(), 210); - assert_eq!(Democracy::tally(r), (440, 120, 210)); + System::set_block_number(1); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 0 + ).unwrap(); + assert_ok!(Democracy::vote(Origin::signed(4), r, BIG_AYE)); + assert_ok!(Democracy::vote(Origin::signed(5), r, BIG_NAY)); + assert_ok!(Democracy::vote(Origin::signed(6), r, BIG_AYE)); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + assert_eq!(Democracy::tally(r), (100, 50, 150)); - System::set_block_number(2); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + next_block(); + next_block(); assert_eq!(Balances::free_balance(&42), 2); }); } #[test] - fn controversial_low_turnout_voting_should_work() { + fn lock_voting_should_work() { with_externalities(&mut new_test_ext(), || { - System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(5), r, NAY)); - assert_ok!(Democracy::vote(Origin::signed(6), r, AYE)); - - assert_eq!(Democracy::tally(r), (60, 50, 110)); + System::set_block_number(0); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 0 + ).unwrap(); + assert_ok!(Democracy::vote(Origin::signed(1), r, Vote { + aye: false, + conviction: Conviction::Locked5x + })); + assert_ok!(Democracy::vote(Origin::signed(2), r, Vote { + aye: true, + conviction: Conviction::Locked4x + })); + assert_ok!(Democracy::vote(Origin::signed(3), r, Vote { + aye: true, + conviction: Conviction::Locked3x + })); + assert_ok!(Democracy::vote(Origin::signed(4), r, Vote { + aye: true, + conviction: Conviction::Locked2x + })); + assert_ok!(Democracy::vote(Origin::signed(5), r, Vote { + aye: false, + conviction: Conviction::Locked1x + })); + + assert_eq!(Democracy::tally(r), (250, 100, 150)); + + fast_forward_to(2); - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + assert_eq!(Balances::locks(1), vec![]); + assert_eq!(Balances::locks(2), vec![BalanceLock { + id: DEMOCRACY_ID, + amount: u64::max_value(), + until: 17, + reasons: WithdrawReason::Transfer.into() + }]); + assert_eq!(Balances::locks(3), vec![BalanceLock { + id: DEMOCRACY_ID, + amount: u64::max_value(), + until: 9, + reasons: WithdrawReason::Transfer.into() + }]); + assert_eq!(Balances::locks(4), vec![BalanceLock { + id: DEMOCRACY_ID, + amount: u64::max_value(), + until: 5, + reasons: WithdrawReason::Transfer.into() + }]); + assert_eq!(Balances::locks(5), vec![]); - assert_eq!(Balances::free_balance(&42), 0); + assert_eq!(Balances::free_balance(&42), 2); }); } #[test] - fn passing_low_turnout_voting_should_work() { + fn lock_voting_should_work_with_delegation() { with_externalities(&mut new_test_ext(), || { - assert_eq!(Balances::free_balance(&42), 0); - assert_eq!(Balances::total_issuance(), 210); - System::set_block_number(1); - let r = Democracy::inject_referendum(1, set_balance_proposal(2), VoteThreshold::SuperMajorityApprove, 0).unwrap(); - assert_ok!(Democracy::vote(Origin::signed(4), r, AYE)); - assert_ok!(Democracy::vote(Origin::signed(5), r, NAY)); - assert_ok!(Democracy::vote(Origin::signed(6), r, AYE)); - - assert_eq!(Democracy::tally(r), (100, 50, 150)); - - assert_eq!(Democracy::end_block(System::block_number()), Ok(())); + let r = Democracy::inject_referendum( + 1, + set_balance_proposal(2), + VoteThreshold::SuperMajorityApprove, + 0 + ).unwrap(); + assert_ok!(Democracy::vote(Origin::signed(1), r, Vote { + aye: false, + conviction: Conviction::Locked5x + })); + assert_ok!(Democracy::vote(Origin::signed(2), r, Vote { + aye: true, + conviction: Conviction::Locked4x + })); + assert_ok!(Democracy::vote(Origin::signed(3), r, Vote { + aye: true, + conviction: Conviction::Locked3x + })); + assert_ok!(Democracy::delegate(Origin::signed(4), 2, Conviction::Locked2x)); + assert_ok!(Democracy::vote(Origin::signed(5), r, Vote { + aye: false, + conviction: Conviction::Locked1x + })); + + assert_eq!(Democracy::tally(r), (250, 100, 150)); + + next_block(); + next_block(); assert_eq!(Balances::free_balance(&42), 2); }); diff --git a/srml/executive/src/lib.rs b/srml/executive/src/lib.rs index bc15acfffbcaa67ae279e131598d4fc9ecedbad5..8bb96eb81475511915896ccdb6511f659c865aee 100644 --- a/srml/executive/src/lib.rs +++ b/srml/executive/src/lib.rs @@ -80,7 +80,7 @@ use rstd::result; use primitives::traits::{ self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize, OnInitialize, Digest, NumberFor, Block as BlockT, OffchainWorker, - ValidateUnsigned, + ValidateUnsigned, DigestItem, }; use srml_support::{Dispatchable, traits::MakePayment}; use parity_codec::{Codec, Encode}; @@ -153,11 +153,13 @@ where { /// Start the execution of a particular block. pub fn initialize_block(header: &System::Header) { - Self::initialize_block_impl(header.number(), header.parent_hash(), header.extrinsics_root()); + let mut digests = System::Digest::default(); + header.digest().logs().iter().for_each(|d| if d.as_pre_runtime().is_some() { digests.push(d.clone()) }); + Self::initialize_block_impl(header.number(), header.parent_hash(), header.extrinsics_root(), &digests); } - fn initialize_block_impl(block_number: &System::BlockNumber, parent_hash: &System::Hash, extrinsics_root: &System::Hash) { - >::initialize(block_number, parent_hash, extrinsics_root); + fn initialize_block_impl(block_number: &System::BlockNumber, parent_hash: &System::Hash, extrinsics_root: &System::Hash, digest: &System::Digest) { + >::initialize(block_number, parent_hash, extrinsics_root, digest); >::on_initialize(*block_number); } @@ -268,7 +270,8 @@ where Payment::make_payment(sender, encoded_len).map_err(|_| internal::ApplyError::CantPay)?; // AUDIT: Under no circumstances may this function panic from here onwards. - + // FIXME: ensure this at compile-time (such as by not defining a panic function, forcing + // a linker error unless the compiler can prove it cannot be called). // increment nonce in storage >::inc_account_nonce(sender); } @@ -361,6 +364,7 @@ where requires, provides, longevity: TransactionLongevity::max_value(), + propagate: true, } }, (None, None) => UnsignedValidator::validate_unsigned(&xt.deconstruct().0), @@ -435,6 +439,7 @@ mod tests { requires: vec![], provides: vec![], longevity: std::u64::MAX, + propagate: false, }, _ => TransactionValidity::Invalid(0), } @@ -480,7 +485,7 @@ mod tests { header: Header { parent_hash: [69u8; 32].into(), number: 1, - state_root: hex!("ac2840371d51ff2e036c8fc05af7313b7a030f735c38b2f03b94cbe87bfbb7c9").into(), + state_root: hex!("5ba497e45e379d80a4524f9509d224e9c175d0fa30f3491481e7e44a6a758adf").into(), extrinsics_root: hex!("03170a2e7597b7b7e3d84c05391d139a62b157e78786d8c082f29dcf4c111314").into(), digest: Digest { logs: vec![], }, }, @@ -572,7 +577,8 @@ mod tests { priority: 0, requires: vec![], provides: vec![], - longevity: 18446744073709551615 + longevity: 18446744073709551615, + propagate: false, }; let mut t = new_test_ext(); diff --git a/srml/finality-tracker/Cargo.toml b/srml/finality-tracker/Cargo.toml index c7006a3c3e632b98eca02b44c191f03b947a3897..e6cf47ab25a26db462e35d96a8a3e344e9446cd8 100644 --- a/srml/finality-tracker/Cargo.toml +++ b/srml/finality-tracker/Cargo.toml @@ -17,7 +17,7 @@ srml-system = { path = "../system", default-features = false } substrate-primitives = { path = "../../core/primitives", default-features = false } sr-io = { path = "../../core/sr-io", default-features = false } lazy_static = "1.0" -parking_lot = "0.7" +parking_lot = "0.8.0" [features] default = ["std"] diff --git a/srml/finality-tracker/src/lib.rs b/srml/finality-tracker/src/lib.rs index 91beefa66b290881ab41d76021bbaedef7a15071..9e8319850212cabf0d225f195d537033fd6f4ef6 100644 --- a/srml/finality-tracker/src/lib.rs +++ b/srml/finality-tracker/src/lib.rs @@ -26,7 +26,7 @@ use inherents::{ InherentData, MakeFatalError, }; use srml_support::StorageValue; -use primitives::traits::{As, One, Zero}; +use primitives::traits::{One, Zero, SaturatedConversion}; use rstd::{prelude::*, result, cmp, vec}; use parity_codec::Decode; use srml_system::{ensure_none, Trait as SystemTrait}; @@ -34,8 +34,8 @@ use srml_system::{ensure_none, Trait as SystemTrait}; #[cfg(feature = "std")] use parity_codec::Encode; -const DEFAULT_WINDOW_SIZE: u64 = 101; -const DEFAULT_DELAY: u64 = 1000; +const DEFAULT_WINDOW_SIZE: u32 = 101; +const DEFAULT_DELAY: u32 = 1000; /// The identifier for the `finalnum` inherent. pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"finalnum"; @@ -100,9 +100,9 @@ decl_storage! { /// The median. Median get(median) build(|_| T::BlockNumber::zero()): T::BlockNumber; /// The number of recent samples to keep from this chain. Default is n-100 - pub WindowSize get(window_size) config(window_size): T::BlockNumber = T::BlockNumber::sa(DEFAULT_WINDOW_SIZE); + pub WindowSize get(window_size) config(window_size): T::BlockNumber = DEFAULT_WINDOW_SIZE.into(); /// The delay after which point things become suspicious. - pub ReportLatency get(report_latency) config(report_latency): T::BlockNumber = T::BlockNumber::sa(DEFAULT_DELAY); + pub ReportLatency get(report_latency) config(report_latency): T::BlockNumber = DEFAULT_DELAY.into(); /// Final hint to apply in the block. `None` means "same as parent". Update: Option; @@ -154,7 +154,7 @@ impl Module { // the sample size has just been shrunk. { // take into account the item we haven't pushed yet. - let to_prune = (recent.len() + 1).saturating_sub(window_size.as_() as usize); + let to_prune = (recent.len() + 1).saturating_sub(window_size.saturated_into::()); for drained in recent.drain(..to_prune) { let idx = ordered.binary_search(&drained) @@ -188,13 +188,13 @@ impl Module { } }; - let our_window_size = recent.len(); + let our_window_size = recent.len() as u32; ::RecentHints::put(recent); ::OrderedHints::put(ordered); ::Median::put(median); - if T::BlockNumber::sa(our_window_size as u64) == window_size { + if T::BlockNumber::from(our_window_size) == window_size { let now = srml_system::Module::::block_number(); let latency = Self::report_latency(); @@ -344,7 +344,7 @@ mod tests { with_externalities(&mut TestExternalities::new(t), || { let mut parent_hash = System::parent_hash(); for i in 2..106 { - System::initialize(&i, &parent_hash, &Default::default()); + System::initialize(&i, &parent_hash, &Default::default(), &Default::default()); FinalityTracker::on_finalize(i); let hdr = System::finalize(); parent_hash = hdr.hash(); @@ -369,7 +369,7 @@ mod tests { with_externalities(&mut TestExternalities::new(t), || { let mut parent_hash = System::parent_hash(); for i in 2..106 { - System::initialize(&i, &parent_hash, &Default::default()); + System::initialize(&i, &parent_hash, &Default::default(), &Default::default()); assert_ok!(FinalityTracker::dispatch( Call::final_hint(i-1), Origin::NONE, diff --git a/srml/grandpa/src/lib.rs b/srml/grandpa/src/lib.rs index e9886eddb13c75e31744c32b991a63d3272a036f..5425ace8bb89e18b5cd398c374d9f61f3ab54f00 100644 --- a/srml/grandpa/src/lib.rs +++ b/srml/grandpa/src/lib.rs @@ -275,8 +275,6 @@ impl Module { in_blocks: T::BlockNumber, forced: Option, ) -> Result { - use primitives::traits::As; - if Self::pending_change().is_none() { let scheduled_at = system::ChainContext::::default().current_height(); @@ -287,7 +285,7 @@ impl Module { // only allow the next forced change when twice the window has passed since // this one. - >::put(scheduled_at + in_blocks * T::BlockNumber::sa(2)); + >::put(scheduled_at + in_blocks * 2.into()); } >::put(StoredPendingChange { diff --git a/srml/grandpa/src/tests.rs b/srml/grandpa/src/tests.rs index 560766f8c62ade033eb8229db0ebc12348ae71ec..d19c5c25b639ef553ea112ceaad429783c321c3e 100644 --- a/srml/grandpa/src/tests.rs +++ b/srml/grandpa/src/tests.rs @@ -30,7 +30,7 @@ use super::*; #[test] fn authorities_change_logged() { with_externalities(&mut new_test_ext(vec![(1, 1), (2, 1), (3, 1)]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); Grandpa::schedule_change(vec![(4, 1), (5, 1), (6, 1)], 0, None).unwrap(); System::note_finished_extrinsics(); @@ -56,7 +56,7 @@ fn authorities_change_logged() { #[test] fn authorities_change_logged_after_delay() { with_externalities(&mut new_test_ext(vec![(1, 1), (2, 1), (3, 1)]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); Grandpa::schedule_change(vec![(4, 1), (5, 1), (6, 1)], 1, None).unwrap(); Grandpa::on_finalize(1); let header = System::finalize(); @@ -69,7 +69,7 @@ fn authorities_change_logged_after_delay() { // no change at this height. assert_eq!(System::events(), vec![]); - System::initialize(&2, &header.hash(), &Default::default()); + System::initialize(&2, &header.hash(), &Default::default(), &Default::default()); System::note_finished_extrinsics(); Grandpa::on_finalize(2); @@ -87,7 +87,7 @@ fn authorities_change_logged_after_delay() { #[test] fn cannot_schedule_change_when_one_pending() { with_externalities(&mut new_test_ext(vec![(1, 1), (2, 1), (3, 1)]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); Grandpa::schedule_change(vec![(4, 1), (5, 1), (6, 1)], 1, None).unwrap(); assert!(Grandpa::pending_change().is_some()); assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_err()); @@ -95,14 +95,14 @@ fn cannot_schedule_change_when_one_pending() { Grandpa::on_finalize(1); let header = System::finalize(); - System::initialize(&2, &header.hash(), &Default::default()); + System::initialize(&2, &header.hash(), &Default::default(), &Default::default()); assert!(Grandpa::pending_change().is_some()); assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_err()); Grandpa::on_finalize(2); let header = System::finalize(); - System::initialize(&3, &header.hash(), &Default::default()); + System::initialize(&3, &header.hash(), &Default::default(), &Default::default()); assert!(Grandpa::pending_change().is_none()); assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_ok()); @@ -130,7 +130,7 @@ fn new_decodes_from_old() { #[test] fn dispatch_forced_change() { with_externalities(&mut new_test_ext(vec![(1, 1), (2, 1), (3, 1)]), || { - System::initialize(&1, &Default::default(), &Default::default()); + System::initialize(&1, &Default::default(), &Default::default(), &Default::default()); Grandpa::schedule_change( vec![(4, 1), (5, 1), (6, 1)], 5, @@ -144,7 +144,7 @@ fn dispatch_forced_change() { let mut header = System::finalize(); for i in 2..7 { - System::initialize(&i, &header.hash(), &Default::default()); + System::initialize(&i, &header.hash(), &Default::default(), &Default::default()); assert!(Grandpa::pending_change().unwrap().forced.is_some()); assert_eq!(Grandpa::next_forced(), Some(11)); assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_err()); @@ -157,7 +157,7 @@ fn dispatch_forced_change() { // change has been applied at the end of block 6. // add a normal change. { - System::initialize(&7, &header.hash(), &Default::default()); + System::initialize(&7, &header.hash(), &Default::default(), &Default::default()); assert!(Grandpa::pending_change().is_none()); assert_eq!(Grandpa::grandpa_authorities(), vec![(4, 1), (5, 1), (6, 1)]); assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_ok()); @@ -167,7 +167,7 @@ fn dispatch_forced_change() { // run the normal change. { - System::initialize(&8, &header.hash(), &Default::default()); + System::initialize(&8, &header.hash(), &Default::default(), &Default::default()); assert!(Grandpa::pending_change().is_some()); assert_eq!(Grandpa::grandpa_authorities(), vec![(4, 1), (5, 1), (6, 1)]); assert!(Grandpa::schedule_change(vec![(5, 1)], 1, None).is_err()); @@ -178,7 +178,7 @@ fn dispatch_forced_change() { // normal change applied. but we can't apply a new forced change for some // time. for i in 9..11 { - System::initialize(&i, &header.hash(), &Default::default()); + System::initialize(&i, &header.hash(), &Default::default(), &Default::default()); assert!(Grandpa::pending_change().is_none()); assert_eq!(Grandpa::grandpa_authorities(), vec![(5, 1)]); assert_eq!(Grandpa::next_forced(), Some(11)); @@ -188,7 +188,7 @@ fn dispatch_forced_change() { } { - System::initialize(&11, &header.hash(), &Default::default()); + System::initialize(&11, &header.hash(), &Default::default(), &Default::default()); assert!(Grandpa::pending_change().is_none()); assert!(Grandpa::schedule_change(vec![(5, 1), (6, 1), (7, 1)], 5, Some(0)).is_ok()); assert_eq!(Grandpa::next_forced(), Some(21)); diff --git a/srml/indices/src/address.rs b/srml/indices/src/address.rs index c7709e3bec3a5722b0662d141a65c9b494474d6c..c76585d2169670f3e1e253f5f29d736458f4e0ea 100644 --- a/srml/indices/src/address.rs +++ b/srml/indices/src/address.rs @@ -18,7 +18,8 @@ #[cfg(feature = "std")] use std::fmt; -use crate::{Member, Decode, Encode, As, Input, Output}; +use rstd::convert::TryInto; +use crate::{Member, Decode, Encode, Input, Output}; /// An indices-aware address, which can be either a direct `AccountId` or /// an index. @@ -59,14 +60,20 @@ fn need_more_than(a: T, b: T) -> Option { impl Decode for Address where AccountId: Member + Decode, - AccountIndex: Member + Decode + PartialOrd + Ord + As + As + As + Copy, + AccountIndex: Member + Decode + PartialOrd + Ord + From + Copy, { fn decode(input: &mut I) -> Option { Some(match input.read_byte()? { - x @ 0x00...0xef => Address::Index(As::sa(x)), - 0xfc => Address::Index(As::sa(need_more_than(0xef, u16::decode(input)?)?)), - 0xfd => Address::Index(As::sa(need_more_than(0xffff, u32::decode(input)?)?)), - 0xfe => Address::Index(need_more_than(As::sa(0xffffffffu32), Decode::decode(input)?)?), + x @ 0x00..=0xef => Address::Index(AccountIndex::from(x as u32)), + 0xfc => Address::Index(AccountIndex::from( + need_more_than(0xef, u16::decode(input)?)? as u32 + )), + 0xfd => Address::Index(AccountIndex::from( + need_more_than(0xffff, u32::decode(input)?)? + )), + 0xfe => Address::Index( + need_more_than(0xffffffffu32.into(), Decode::decode(input)?)? + ), 0xff => Address::Id(Decode::decode(input)?), _ => return None, }) @@ -75,7 +82,7 @@ impl Decode for Address where impl Encode for Address where AccountId: Member + Encode, - AccountIndex: Member + Encode + PartialOrd + Ord + As + As + As + Copy, + AccountIndex: Member + Encode + PartialOrd + Ord + Copy + From + TryInto, { fn encode_to(&self, dest: &mut T) { match *self { @@ -83,19 +90,26 @@ impl Encode for Address where dest.push_byte(255); dest.push(i); } - Address::Index(i) if i > As::sa(0xffffffffu32) => { - dest.push_byte(254); - dest.push(&i); - } - Address::Index(i) if i > As::sa(0xffffu32) => { - dest.push_byte(253); - dest.push(&As::::as_(i)); - } - Address::Index(i) if i >= As::sa(0xf0u32) => { - dest.push_byte(252); - dest.push(&As::::as_(i)); - } - Address::Index(i) => dest.push_byte(As::::as_(i)), + Address::Index(i) => { + let maybe_u32: Result = i.try_into(); + if let Ok(x) = maybe_u32 { + if x > 0xffff { + dest.push_byte(253); + dest.push(&x); + } + else if x >= 0xf0 { + dest.push_byte(252); + dest.push(&(x as u16)); + } + else { + dest.push_byte(x as u8); + } + + } else { + dest.push_byte(254); + dest.push(&i); + } + }, } } } diff --git a/srml/indices/src/lib.rs b/srml/indices/src/lib.rs index 4a6010f800dec7b60a465b5816e2221a8a4eee0f..38f7ee668dd84d169daacb92496b5eba64ca6468 100644 --- a/srml/indices/src/lib.rs +++ b/srml/indices/src/lib.rs @@ -19,10 +19,10 @@ #![cfg_attr(not(feature = "std"), no_std)] -use rstd::{prelude::*, result, marker::PhantomData}; +use rstd::{prelude::*, result, marker::PhantomData, convert::TryInto}; use parity_codec::{Encode, Decode, Codec, Input, Output}; use srml_support::{StorageValue, StorageMap, Parameter, decl_module, decl_event, decl_storage}; -use primitives::traits::{One, SimpleArithmetic, As, StaticLookup, Member}; +use primitives::traits::{One, SimpleArithmetic, StaticLookup, Member}; use system::{IsDeadAccount, OnNewAccount}; use self::address::Address as RawAddress; @@ -33,23 +33,25 @@ pub mod address; mod tests; /// Number of account IDs stored per enum set. -const ENUM_SET_SIZE: usize = 64; +const ENUM_SET_SIZE: u32 = 64; pub type Address = RawAddress<::AccountId, ::AccountIndex>; /// Turn an Id into an Index, or None for the purpose of getting /// a hint at a possibly desired index. -pub trait ResolveHint> { +pub trait ResolveHint { /// Turn an Id into an Index, or None for the purpose of getting /// a hint at a possibly desired index. fn resolve_hint(who: &AccountId) -> Option; } -/// Simple encode-based resolve hint implemenntation. +/// Simple encode-based resolve hint implementation. pub struct SimpleResolveHint(PhantomData<(AccountId, AccountIndex)>); -impl> ResolveHint for SimpleResolveHint { +impl> + ResolveHint for SimpleResolveHint +{ fn resolve_hint(who: &AccountId) -> Option { - Some(AccountIndex::sa(who.using_encoded(|e| e[0] as usize + e[1] as usize * 256))) + Some(AccountIndex::from(who.using_encoded(|e| e[0] as u32 + e[1] as u32 * 256))) } } @@ -57,7 +59,7 @@ impl> ResolveHint + As + As + As + As + Copy; + type AccountIndex: Parameter + Member + Codec + Default + SimpleArithmetic + Copy; /// Whether an account is dead or not. type IsDeadAccount: IsDeadAccount; @@ -92,15 +94,18 @@ decl_storage! { trait Store for Module as Indices { /// The next free enumeration set. pub NextEnumSet get(next_enum_set) build(|config: &GenesisConfig| { - T::AccountIndex::sa(config.ids.len() / ENUM_SET_SIZE) + (config.ids.len() as u32 / ENUM_SET_SIZE).into() }): T::AccountIndex; /// The enumeration sets. pub EnumSet get(enum_set) build(|config: &GenesisConfig| { - (0..(config.ids.len() + ENUM_SET_SIZE - 1) / ENUM_SET_SIZE) + (0..((config.ids.len() as u32) + ENUM_SET_SIZE - 1) / ENUM_SET_SIZE) .map(|i| ( - T::AccountIndex::sa(i), - config.ids[i * ENUM_SET_SIZE..config.ids.len().min((i + 1) * ENUM_SET_SIZE)].to_owned(), + i.into(), + config.ids[ + (i * ENUM_SET_SIZE) as usize.. + config.ids.len().min(((i + 1) * ENUM_SET_SIZE) as usize) + ].to_owned(), )) .collect::>() }): map T::AccountIndex => Vec; @@ -117,7 +122,7 @@ impl Module { pub fn lookup_index(index: T::AccountIndex) -> Option { let enum_set_size = Self::enum_set_size(); let set = Self::enum_set(index / enum_set_size); - let i: usize = (index % enum_set_size).as_(); + let i: usize = (index % enum_set_size).try_into().ok()?; set.get(i).cloned() } @@ -125,12 +130,18 @@ impl Module { pub fn can_reclaim(try_index: T::AccountIndex) -> bool { let enum_set_size = Self::enum_set_size(); let try_set = Self::enum_set(try_index / enum_set_size); - let i = (try_index % enum_set_size).as_(); - i < try_set.len() && T::IsDeadAccount::is_dead_account(&try_set[i]) + let maybe_usize: Result = (try_index % enum_set_size).try_into(); + if let Ok(i) = maybe_usize { + i < try_set.len() && T::IsDeadAccount::is_dead_account(&try_set[i]) + } else { + false + } } /// Lookup an address to get an Id, if there's one there. - pub fn lookup_address(a: address::Address) -> Option { + pub fn lookup_address( + a: address::Address + ) -> Option { match a { address::Address::Id(i) => Some(i), address::Address::Index(i) => Self::lookup_index(i), @@ -140,7 +151,7 @@ impl Module { // PUBLIC MUTABLES (DANGEROUS) fn enum_set_size() -> T::AccountIndex { - T::AccountIndex::sa(ENUM_SET_SIZE) + ENUM_SET_SIZE.into() } } @@ -153,36 +164,38 @@ impl OnNewAccount for Module { // then check to see if this account id identifies a dead account index. let set_index = try_index / enum_set_size; let mut try_set = Self::enum_set(set_index); - let item_index = (try_index % enum_set_size).as_(); - if item_index < try_set.len() { - if T::IsDeadAccount::is_dead_account(&try_set[item_index]) { - // yup - this index refers to a dead account. can be reused. - try_set[item_index] = who.clone(); - >::insert(set_index, try_set); - - return + if let Ok(item_index) = (try_index % enum_set_size).try_into() { + if item_index < try_set.len() { + if T::IsDeadAccount::is_dead_account(&try_set[item_index]) { + // yup - this index refers to a dead account. can be reused. + try_set[item_index] = who.clone(); + >::insert(set_index, try_set); + + return + } } } } // insert normally as a back up let mut set_index = next_set_index; - // defensive only: this loop should never iterate since we keep NextEnumSet up to date later. + // defensive only: this loop should never iterate since we keep NextEnumSet up to date + // later. let mut set = loop { let set = Self::enum_set(set_index); - if set.len() < ENUM_SET_SIZE { + if set.len() < ENUM_SET_SIZE as usize { break set; } set_index += One::one(); }; - let index = T::AccountIndex::sa(set_index.as_() * ENUM_SET_SIZE + set.len()); + let index = set_index * enum_set_size + T::AccountIndex::from(set.len() as u32); // update set. set.push(who.clone()); // keep NextEnumSet up to date - if set.len() == ENUM_SET_SIZE { + if set.len() == ENUM_SET_SIZE as usize { >::put(set_index + One::one()); } diff --git a/srml/metadata/src/lib.rs b/srml/metadata/src/lib.rs index 28a513cc07b54d5e32d1b6981096e1bb1a21bec2..b1ab57b506878559b3a8dd07e2d37a1e00c2629b 100644 --- a/srml/metadata/src/lib.rs +++ b/srml/metadata/src/lib.rs @@ -280,7 +280,7 @@ pub enum StorageFunctionType { key1: DecodeDifferentStr, key2: DecodeDifferentStr, value: DecodeDifferentStr, - key2_hasher: DecodeDifferentStr, + key2_hasher: StorageHasher, }, } @@ -311,8 +311,10 @@ pub enum RuntimeMetadata { V2(RuntimeMetadataDeprecated), /// Version 3 for runtime metadata. No longer used. V3(RuntimeMetadataDeprecated), - /// Version 4 for runtime metadata. - V4(RuntimeMetadataV4), + /// Version 4 for runtime metadata. No longer used. + V4(RuntimeMetadataDeprecated), + /// Version 5 for runtime metadata. + V5(RuntimeMetadataV5), } /// Enum that should fail. @@ -335,7 +337,7 @@ impl Decode for RuntimeMetadataDeprecated { /// The metadata of a runtime. #[derive(Eq, Encode, PartialEq)] #[cfg_attr(feature = "std", derive(Decode, Debug, Serialize))] -pub struct RuntimeMetadataV4 { +pub struct RuntimeMetadataV5 { pub modules: DecodeDifferentArray, } diff --git a/srml/session/src/lib.rs b/srml/session/src/lib.rs index 255bb4f64741616885bc71b53091ddb7a0d5d4cf..d13795e4bb09cc4b7bbdf76fe1dc2df9300e65a0 100644 --- a/srml/session/src/lib.rs +++ b/srml/session/src/lib.rs @@ -116,7 +116,7 @@ #![cfg_attr(not(feature = "std"), no_std)] use rstd::prelude::*; -use primitives::traits::{As, Zero, One, Convert}; +use primitives::traits::{Zero, One, Convert}; use srml_support::{StorageValue, StorageMap, for_each_tuple, decl_module, decl_event, decl_storage}; use srml_support::{dispatch::Result, traits::OnFreeBalanceZero}; use system::ensure_signed; @@ -200,9 +200,9 @@ decl_storage! { /// The current set of validators. pub Validators get(validators) config(): Vec; /// Current length of the session. - pub SessionLength get(length) config(session_length): T::BlockNumber = T::BlockNumber::sa(1000); + pub SessionLength get(length) config(session_length): T::BlockNumber = 1000.into(); /// Current index of the session. - pub CurrentIndex get(current_index) build(|_| T::BlockNumber::sa(0)): T::BlockNumber; + pub CurrentIndex get(current_index) build(|_| 0.into()): T::BlockNumber; /// Timestamp when current session started. pub CurrentStart get(current_start) build(|_| T::Moment::zero()): T::Moment; diff --git a/srml/staking/Cargo.toml b/srml/staking/Cargo.toml index 857ea73ee44421cf6ce636e558d858ff969e492c..62fc187176ed4a4e1e77b22a3b1bfb27df6d3fd4 100644 --- a/srml/staking/Cargo.toml +++ b/srml/staking/Cargo.toml @@ -21,8 +21,10 @@ session = { package = "srml-session", path = "../session", default-features = fa substrate-primitives = { path = "../../core/primitives" } timestamp = { package = "srml-timestamp", path = "../timestamp" } balances = { package = "srml-balances", path = "../balances" } +rand = "0.6.5" [features] +bench = [] default = ["std"] std = [ "serde", diff --git a/srml/staking/src/benches.rs b/srml/staking/src/benches.rs new file mode 100644 index 0000000000000000000000000000000000000000..e3ee00b9e94802658a05364b1b0b34a1ceee79ff --- /dev/null +++ b/srml/staking/src/benches.rs @@ -0,0 +1,114 @@ +// Copyright 2019 Parity Technologies +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//! Benchmarks of the phragmen election algorithm. +//! Note that execution times will not be accurate in an absolute scale, since +//! - Everything is executed in the context of `TestExternalities` +//! - Everything is executed in native environment. +//! +//! Run using: +//! +//! ```zsh +//! cargo bench --features bench --color always +//! ``` + +use test::Bencher; +use runtime_io::with_externalities; +use mock::*; +use super::*; +use rand::{self, Rng}; + +const VALIDATORS: u64 = 1000; +const NOMINATORS: u64 = 10_000; +const EDGES: u64 = 2; +const TO_ELECT: usize = 100; +const STAKE: u64 = 1000; + +fn do_phragmen(b: &mut Bencher, num_vals: u64, num_noms: u64, count: usize, votes_per: u64) { + with_externalities(&mut ExtBuilder::default().nominate(false).build(), || { + assert!(num_vals > votes_per); + let rr = |a, b| rand::thread_rng().gen_range(a as usize, b as usize) as u64; + + // prefix to distinguish the validator and nominator account ranges. + let np = 10_000; + + (1 ..= 2*num_vals) + .step_by(2) + .for_each(|acc| bond_validator(acc, STAKE + rr(10, 50))); + + (np ..= (np + 2*num_noms)) + .step_by(2) + .for_each(|acc| { + let mut stashes_to_vote = (1 ..= 2*num_vals) + .step_by(2) + .map(|ctrl| ctrl + 1) + .collect::>(); + let votes = (0 .. votes_per) + .map(|_| { + stashes_to_vote.remove(rr(0, stashes_to_vote.len()) as usize) + }) + .collect::>(); + bond_nominator(acc, STAKE + rr(10, 50), votes); + }); + + b.iter(|| { + let _ = phragmen::elect::( + count, + 1_usize, + >::enumerate(), + >::enumerate(), + Staking::slashable_balance_of + ); + }) + }) +} + +macro_rules! phragmen_benches { + ($($name:ident: $tup:expr,)*) => { + $( + #[bench] + fn $name(b: &mut Bencher) { + let (v, n, t, e) = $tup; + println!(""); + println!( + "++ Benchmark: {} Validators // {} Nominators // {} Edges-per-nominator // {} total edges // electing {}", + v, n, e, e * n, t + ); + do_phragmen(b, v, n, t, e); + } + )* + } +} + +phragmen_benches! { + bench_1_1: (VALIDATORS, NOMINATORS, TO_ELECT, EDGES), + bench_1_2: (VALIDATORS*2, NOMINATORS, TO_ELECT, EDGES), + bench_1_3: (VALIDATORS*4, NOMINATORS, TO_ELECT, EDGES), + bench_1_4: (VALIDATORS*8, NOMINATORS, TO_ELECT, EDGES), + + bench_0_1: (VALIDATORS, NOMINATORS, TO_ELECT, EDGES), + bench_0_2: (VALIDATORS, NOMINATORS, TO_ELECT * 4, EDGES), + bench_0_3: (VALIDATORS, NOMINATORS, TO_ELECT * 8, EDGES), + bench_0_4: (VALIDATORS, NOMINATORS, TO_ELECT * 16, EDGES), + + bench_2_1: (VALIDATORS, NOMINATORS, TO_ELECT, EDGES), + bench_2_2: (VALIDATORS, NOMINATORS*2, TO_ELECT, EDGES), + bench_2_3: (VALIDATORS, NOMINATORS*4, TO_ELECT, EDGES), + bench_2_4: (VALIDATORS, NOMINATORS*8, TO_ELECT, EDGES), + + bench_3_1: (VALIDATORS, NOMINATORS, TO_ELECT, EDGES), + bench_3_2: (VALIDATORS, NOMINATORS, TO_ELECT, EDGES*2), + bench_3_3: (VALIDATORS, NOMINATORS, TO_ELECT, EDGES*4), + bench_3_4: (VALIDATORS, NOMINATORS, TO_ELECT, EDGES*8), +} diff --git a/srml/staking/src/lib.rs b/srml/staking/src/lib.rs index 93bd941092515a7e7883a2cf9caa27efdd99cbd0..3f6905f6540425179af4887c58c937a874bd9806 100644 --- a/srml/staking/src/lib.rs +++ b/srml/staking/src/lib.rs @@ -187,15 +187,16 @@ //! A validator can be _reported_ to be offline at any point via the public function //! [`on_offline_validator`](enum.Call.html#variant.on_offline_validator). Each validator declares how many times it //! can be _reported_ before it actually gets slashed via its -//! [`unstake_threshold`](./struct.ValidatorPrefs.html#structfield.unstake_threshold). +//! [`ValidatorPrefs::unstake_threshold`](./struct.ValidatorPrefs.html#structfield.unstake_threshold). //! //! On top of this, the Staking module also introduces an //! [`OfflineSlashGrace`](./struct.Module.html#method.offline_slash_grace), which applies //! to all validators and prevents them from getting immediately slashed. //! //! Essentially, a validator gets slashed once they have been reported more than -//! [`OfflineSlashGrace`] + [`unstake_threshold`] times. Getting slashed due to offline report always leads -//! to being _unstaked_ (_i.e._ removed as a validator candidate) as the consequence. +//! [`OfflineSlashGrace`] + [`ValidatorPrefs::unstake_threshold`] times. Getting slashed due to +//! offline report always leads to being _unstaked_ (_i.e._ removed as a validator candidate) as +//! the consequence. //! //! The base slash value is computed _per slash-event_ by multiplying //! [`OfflineSlash`](./struct.Module.html#method.offline_slash) and the `total` `Exposure`. This value is then @@ -213,6 +214,11 @@ //! removed. Once the `BondingDuration` is over, the [`withdraw_unbonded`](./enum.Call.html#variant.withdraw_unbonded) call can be used //! to actually withdraw the funds. //! +//! Note that there is a limitation to the number of fund-chunks that can be scheduled to be unlocked in the future +//! via [`unbond`](enum.Call.html#variant.unbond). +//! In case this maximum (`MAX_UNLOCKING_CHUNKS`) is reached, the bonded account _must_ first wait until a successful +//! call to `withdraw_unbonded` to remove some of the chunks. +//! //! ### Election Algorithm //! //! The current election algorithm is implemented based on Phragmén. @@ -234,34 +240,50 @@ //! stored in the Session module's `Validators` at the end of each era. #![cfg_attr(not(feature = "std"), no_std)] +#![cfg_attr(all(feature = "bench", test), feature(test))] + +#[cfg(all(feature = "bench", test))] +extern crate test; + +#[cfg(any(feature = "bench", test))] +mod mock; + +#[cfg(test)] +mod tests; + +mod phragmen; + +#[cfg(all(feature = "bench", test))] +mod benches; #[cfg(feature = "std")] use runtime_io::with_storage; use rstd::{prelude::*, result, collections::btree_map::BTreeMap}; use parity_codec::{HasCompact, Encode, Decode}; -use srml_support::{StorageValue, StorageMap, EnumerableStorageMap, dispatch::Result}; -use srml_support::{decl_module, decl_event, decl_storage, ensure}; -use srml_support::traits::{ - Currency, OnFreeBalanceZero, OnDilution, LockIdentifier, LockableCurrency, WithdrawReasons, - OnUnbalanced, Imbalance, +use srml_support::{ StorageValue, StorageMap, EnumerableStorageMap, dispatch::Result, + decl_module, decl_event, decl_storage, ensure, + traits::{Currency, OnFreeBalanceZero, OnDilution, LockIdentifier, LockableCurrency, + WithdrawReasons, OnUnbalanced, Imbalance + } }; use session::OnSessionChange; use primitives::Perbill; -use primitives::traits::{Convert, Zero, One, As, StaticLookup, CheckedSub, CheckedShl, Saturating, Bounded}; +use primitives::traits::{ + Convert, Zero, One, StaticLookup, CheckedSub, CheckedShl, Saturating, + Bounded, SaturatedConversion +}; #[cfg(feature = "std")] use primitives::{Serialize, Deserialize}; use system::ensure_signed; -mod mock; -mod tests; -mod phragmen; - use phragmen::{elect, ACCURACY, ExtendedBalance}; const RECENT_OFFLINE_COUNT: usize = 32; const DEFAULT_MINIMUM_VALIDATOR_COUNT: u32 = 4; const MAX_NOMINATIONS: usize = 16; const MAX_UNSTAKE_THRESHOLD: u32 = 10; +const MAX_UNLOCKING_CHUNKS: usize = 32; +const STAKING_ID: LockIdentifier = *b"staking "; /// Indicates the initial status of the staker. #[cfg_attr(feature = "std", derive(Debug, Serialize, Deserialize))] @@ -396,7 +418,7 @@ type NegativeImbalanceOf = <::Currency as Currency< = (::AccountId, ExtendedBalance); type Assignment = (::AccountId, ExtendedBalance, BalanceOf); -type ExpoMap = BTreeMap::<::AccountId, Exposure<::AccountId, BalanceOf>>; +type ExpoMap = BTreeMap<::AccountId, Exposure<::AccountId, BalanceOf>>; pub trait Trait: system::Trait + session::Trait { /// The staking balance. @@ -422,8 +444,6 @@ pub trait Trait: system::Trait + session::Trait { type Reward: OnUnbalanced>; } -const STAKING_ID: LockIdentifier = *b"staking "; - decl_storage! { trait Store for Module as Staking { @@ -432,7 +452,7 @@ decl_storage! { /// Minimum number of staking participants before emergency conditions are imposed. pub MinimumValidatorCount get(minimum_validator_count) config(): u32 = DEFAULT_MINIMUM_VALIDATOR_COUNT; /// The length of a staking era in sessions. - pub SessionsPerEra get(sessions_per_era) config(): T::BlockNumber = T::BlockNumber::sa(1000); + pub SessionsPerEra get(sessions_per_era) config(): T::BlockNumber = 1000.into(); /// Maximum reward, per validator, that is provided per acceptable session. pub SessionReward get(session_reward) config(): Perbill = Perbill::from_parts(60); /// Slash, per validator that is taken for the first time they are found to be offline. @@ -440,7 +460,7 @@ decl_storage! { /// Number of instances of offline reports before slashing begins for validators. pub OfflineSlashGrace get(offline_slash_grace) config(): u32; /// The length of the bonding duration in eras. - pub BondingDuration get(bonding_duration) config(): T::BlockNumber = T::BlockNumber::sa(12); + pub BondingDuration get(bonding_duration) config(): T::BlockNumber = 12.into(); /// Any validators that may never be slashed or forcibly kicked. It's a Vec since they're easy to initialize /// and the performance hit is minimal (we expect no more than four invulnerables) and restricted to testnets. @@ -601,12 +621,20 @@ decl_module! { /// Once the unlock period is done, you can call `withdraw_unbonded` to actually move /// the funds out of management ready for transfer. /// + /// No more than a limited number of unlocking chunks (see `MAX_UNLOCKING_CHUNKS`) + /// can co-exists at the same time. In that case, [`Call::withdraw_unbonded`] need + /// to be called first to remove some of the chunks (if possible). + /// /// The dispatch origin for this call must be _Signed_ by the controller, not the stash. /// /// See also [`Call::withdraw_unbonded`]. fn unbond(origin, #[compact] value: BalanceOf) { let controller = ensure_signed(origin)?; let mut ledger = Self::ledger(&controller).ok_or("not a controller")?; + ensure!( + ledger.unlocking.len() < MAX_UNLOCKING_CHUNKS, + "can not schedule more unlock chunks" + ); let mut value = value.min(ledger.active); @@ -867,8 +895,12 @@ impl Module { if ideal_elapsed.is_zero() { return Self::current_session_reward(); } - let per65536: u64 = (T::Moment::sa(65536u64) * ideal_elapsed.clone() / actual_elapsed.max(ideal_elapsed)).as_(); - Self::current_session_reward() * >::sa(per65536) / >::sa(65536u64) + // Assumes we have 16-bits free at the top of T::Moment. Holds true for moment as seconds + // in a u64 for the forseeable future, but more correct would be to handle overflows + // explicitly. + let per65536 = T::Moment::from(65536) * ideal_elapsed.clone() / actual_elapsed.max(ideal_elapsed); + let per65536: BalanceOf = per65536.saturated_into::().into(); + Self::current_session_reward() * per65536 / 65536.into() } /// Session has just changed. We need to determine whether we pay a reward, slash and/or @@ -901,8 +933,8 @@ impl Module { Self::reward_validator(v, reward); } Self::deposit_event(RawEvent::Reward(reward)); - let len = validators.len() as u64; // validators length can never overflow u64 - let len = BalanceOf::::sa(len); + let len = validators.len() as u32; // validators length can never overflow u64 + let len: BalanceOf = len.into(); let total_minted = reward * len; let total_rewarded_stake = Self::slot_stake() * len; T::OnRewardMinted::on_dilution(total_minted, total_rewarded_stake); diff --git a/srml/staking/src/mock.rs b/srml/staking/src/mock.rs index 88b401b19eb51a81b38dc3a1818e3efbc0c16ac5..5b3b22dda5f9a8c70a3ba7ea413e36ce3bd422d8 100644 --- a/srml/staking/src/mock.rs +++ b/srml/staking/src/mock.rs @@ -16,14 +16,12 @@ //! Test utilities -#![cfg(test)] - use primitives::{traits::{IdentityLookup, Convert}, BuildStorage, Perbill}; use primitives::testing::{Digest, DigestItem, Header, UintAuthorityId, ConvertUintAuthorityId}; use substrate_primitives::{H256, Blake2Hasher}; use runtime_io; -use srml_support::impl_outer_origin; -use crate::{GenesisConfig, Module, Trait, StakerStatus}; +use srml_support::{impl_outer_origin, assert_ok, traits::Currency}; +use crate::{GenesisConfig, Module, Trait, StakerStatus, ValidatorPrefs, RewardDestination}; /// The AccountId alias in this test module. pub type AccountIdType = u64; @@ -241,3 +239,33 @@ pub type Balances = balances::Module; pub type Session = session::Module; pub type Timestamp = timestamp::Module; pub type Staking = Module; + +pub fn check_exposure(acc: u64) { + let expo = Staking::stakers(&acc); + assert_eq!(expo.total as u128, expo.own as u128 + expo.others.iter().map(|e| e.value as u128).sum::()); +} + +pub fn check_exposure_all() { + Staking::current_elected().into_iter().for_each(|acc| check_exposure(acc)); +} + +pub fn assert_total_expo(acc: u64, val: u64) { + let expo = Staking::stakers(&acc); + assert_eq!(expo.total, val); +} + +pub fn bond_validator(acc: u64, val: u64) { + // a = controller + // a + 1 = stash + let _ = Balances::make_free_balance_be(&(acc+1), val); + assert_ok!(Staking::bond(Origin::signed(acc+1), acc, val, RewardDestination::Controller)); + assert_ok!(Staking::validate(Origin::signed(acc), ValidatorPrefs::default())); +} + +pub fn bond_nominator(acc: u64, val: u64, target: Vec) { + // a = controller + // a + 1 = stash + let _ = Balances::make_free_balance_be(&(acc+1), val); + assert_ok!(Staking::bond(Origin::signed(acc+1), acc, val, RewardDestination::Controller)); + assert_ok!(Staking::nominate(Origin::signed(acc), target)); +} \ No newline at end of file diff --git a/srml/staking/src/phragmen.rs b/srml/staking/src/phragmen.rs index 56f6419c06ec1704fb80115a5cf1acee46e55de5..ba79de48698838f289f0d4cdeaf2a1ee34ebb7ec 100644 --- a/srml/staking/src/phragmen.rs +++ b/srml/staking/src/phragmen.rs @@ -19,7 +19,6 @@ use rstd::{prelude::*, collections::btree_map::BTreeMap}; use primitives::{PerU128}; use primitives::traits::{Zero, Convert, Saturating}; -use parity_codec::{Encode, Decode}; use crate::{BalanceOf, Assignment, RawAssignment, ExpoMap, Trait, ValidatorPrefs}; type Fraction = PerU128; @@ -35,7 +34,7 @@ const SCALE_FACTOR: ExtendedBalance = u32::max_value() as ExtendedBalance + 1; pub const ACCURACY: ExtendedBalance = u32::max_value() as ExtendedBalance + 1; /// Wrapper around validation candidates some metadata. -#[derive(Clone, Encode, Decode, Default)] +#[derive(Clone, Default)] #[cfg_attr(feature = "std", derive(Debug))] pub struct Candidate { /// The validator's account @@ -49,7 +48,7 @@ pub struct Candidate { } /// Wrapper around the nomination info of a single nominator for a group of validators. -#[derive(Clone, Encode, Decode, Default)] +#[derive(Clone, Default)] #[cfg_attr(feature = "std", derive(Debug))] pub struct Nominator { /// The nominator's account. @@ -63,7 +62,7 @@ pub struct Nominator { } /// Wrapper around a nominator vote and the load of that vote. -#[derive(Clone, Encode, Decode, Default)] +#[derive(Clone, Default)] #[cfg_attr(feature = "std", derive(Debug))] pub struct Edge { /// Account being voted for @@ -108,29 +107,29 @@ pub fn elect( // Candidates who have 0 stake => have no votes or all null-votes. Kick them out not. let mut nominators: Vec> = Vec::with_capacity(validator_iter.size_hint().0 + nominator_iter.size_hint().0); let mut candidates = validator_iter.map(|(who, _)| { - let stash_balance = stash_of(&who); - (Candidate { who, ..Default::default() }, stash_balance) - }) - .filter_map(|(mut c, s)| { - c.approval_stake += to_votes(s); - if c.approval_stake.is_zero() { - None - } else { - Some((c, s)) - } - }) - .enumerate() - .map(|(idx, (c, s))| { - nominators.push(Nominator { - who: c.who.clone(), - edges: vec![ Edge { who: c.who.clone(), candidate_index: idx, ..Default::default() }], - budget: to_votes(s), - load: Fraction::zero(), - }); - c_idx_cache.insert(c.who.clone(), idx); - c - }) - .collect::>>(); + let stash_balance = stash_of(&who); + (Candidate { who, ..Default::default() }, stash_balance) + }) + .filter_map(|(mut c, s)| { + c.approval_stake += to_votes(s); + if c.approval_stake.is_zero() { + None + } else { + Some((c, s)) + } + }) + .enumerate() + .map(|(idx, (c, s))| { + nominators.push(Nominator { + who: c.who.clone(), + edges: vec![ Edge { who: c.who.clone(), candidate_index: idx, ..Default::default() }], + budget: to_votes(s), + load: Fraction::zero(), + }); + c_idx_cache.insert(c.who.clone(), idx); + c + }) + .collect::>>(); // 2- Collect the nominators with the associated votes. // Also collect approval stake along the way. diff --git a/srml/staking/src/tests.rs b/srml/staking/src/tests.rs index 17885dc2510220718ad1f510a5372d403cfab56e..eba6ce77a560cef415e456ecc8f90a18e5ee841e 100644 --- a/srml/staking/src/tests.rs +++ b/srml/staking/src/tests.rs @@ -16,50 +16,13 @@ //! Tests for the module. -#![cfg(test)] - use super::*; use runtime_io::with_externalities; use phragmen; use srml_support::{assert_ok, assert_noop, assert_eq_uvec, EnumerableStorageMap}; -use mock::{Balances, Session, Staking, System, Timestamp, Test, ExtBuilder, Origin}; +use mock::*; use srml_support::traits::{Currency, ReservableCurrency}; -#[inline] -fn check_exposure(acc: u64) { - let expo = Staking::stakers(&acc); - assert_eq!(expo.total as u128, expo.own as u128 + expo.others.iter().map(|e| e.value as u128).sum::()); -} - -#[inline] -fn check_exposure_all() { - Staking::current_elected().into_iter().for_each(|acc| check_exposure(acc)); -} - -#[inline] -fn assert_total_expo(acc: u64, val: u64) { - let expo = Staking::stakers(&acc); - assert_eq!(expo.total, val); -} - -#[inline] -fn bond_validator(acc: u64, val: u64) { - // a = controller - // a + 1 = stash - let _ = Balances::make_free_balance_be(&(acc+1), val); - assert_ok!(Staking::bond(Origin::signed(acc+1), acc, val, RewardDestination::Controller)); - assert_ok!(Staking::validate(Origin::signed(acc), ValidatorPrefs::default())); -} - -#[inline] -fn bond_nominator(acc: u64, val: u64, target: Vec) { - // a = controller - // a + 1 = stash - let _ = Balances::make_free_balance_be(&(acc+1), val); - assert_ok!(Staking::bond(Origin::signed(acc+1), acc, val, RewardDestination::Controller)); - assert_ok!(Staking::nominate(Origin::signed(acc), target)); -} - #[test] fn basic_setup_works() { // Verifies initial conditions of mock @@ -1237,6 +1200,38 @@ fn bond_extra_and_withdraw_unbonded_works() { }) } +#[test] +fn too_many_unbond_calls_should_not_work() { + with_externalities(&mut ExtBuilder::default().build(), || { + // locked at era 0 until 3 + for _ in 0..MAX_UNLOCKING_CHUNKS-1 { + assert_ok!(Staking::unbond(Origin::signed(10), 1)); + } + + System::set_block_number(1); + Session::check_rotate_session(System::block_number()); + + // locked ar era 1 until 4 + assert_ok!(Staking::unbond(Origin::signed(10), 1)); + // can't do more. + assert_noop!(Staking::unbond(Origin::signed(10), 1), "can not schedule more unlock chunks"); + + System::set_block_number(2); + Session::check_rotate_session(System::block_number()); + + System::set_block_number(3); + Session::check_rotate_session(System::block_number()); + + assert_noop!(Staking::unbond(Origin::signed(10), 1), "can not schedule more unlock chunks"); + // free up. + assert_ok!(Staking::withdraw_unbonded(Origin::signed(10))); + + // Can add again. + assert_ok!(Staking::unbond(Origin::signed(10), 1)); + assert_eq!(Staking::ledger(&10).unwrap().unlocking.len(), 2); + }) +} + #[test] fn slot_stake_is_least_staked_validator_and_exposure_defines_maximum_punishment() { // Test that slot_stake is determined by the least staked validator diff --git a/srml/support/procedural/src/lib.rs b/srml/support/procedural/src/lib.rs index f98baa7ed56cde792762299c157e0f24662b72ed..abd7e90951b58d23588c312add27f56d1f428a21 100644 --- a/srml/support/procedural/src/lib.rs +++ b/srml/support/procedural/src/lib.rs @@ -47,10 +47,11 @@ use proc_macro::TokenStream; /// /// Basic storage consists of a name and a type; supported types are: /// -/// * Value: `Foo: type`: Implements [StorageValue](../srml_support/storage/trait.StorageValue.html). -/// * Map: `Foo: map hasher($hash) type => type`: Implements [StorageMap](../srml_support/storage/trait.StorageMap.html) +/// * Value: `Foo: type`: Implements the [`StorageValue`](../srml_support/storage/trait.StorageValue.html) trait. +/// * Map: `Foo: map hasher($hash) type => type`: Implements the +/// [`StorageMap`](../srml_support/storage/trait.StorageMap.html) trait /// with `$hash` representing a choice of hashing algorithms available in the -/// [`Hashable` trait](../srml_support/trait.Hashable.html). +/// [`Hashable`](../srml_support/trait.Hashable.html) trait. /// /// `hasher($hash)` is optional and its default is `blake2_256`. /// @@ -59,11 +60,12 @@ use proc_macro::TokenStream; /// `blake2_256` must be used. Otherwise, other values in storage can be compromised. /// /// * Linked map: `Foo: linked_map hasher($hash) type => type`: Same as `Map` but also implements -/// [EnumarableStorageMap](../srml_support/storage/trait.EnumerableStorageMap.html). +/// the [`EnumerableStorageMap`](../srml_support/storage/trait.EnumerableStorageMap.html) trait. /// -/// * Double map: `Foo: double_map hasher($hash) u32, $hash2(u32) => u32`: Implements `StorageDoubleMap` with +/// * Double map: `Foo: double_map hasher($hash) u32, $hash2(u32) => u32`: Implements the +/// [`StorageDoubleMap`](../srml_support/storage/trait.StorageDoubleMap.html) trait with /// `$hash` and `$hash2` representing choices of hashing algorithms available in the -/// [`Hashable` trait](../srml_support/trait.Hashable.html). +/// [`Hashable`](../srml_support/trait.Hashable.html) trait. /// /// `hasher($hash)` is optional and its default is `blake2_256`. /// diff --git a/srml/support/procedural/src/storage/impls.rs b/srml/support/procedural/src/storage/impls.rs index 39d16edd91008aaa23b0955c413acf85698aa3e3..ee2275de7c56378b122ce0d0f743e6443f968600 100644 --- a/srml/support/procedural/src/storage/impls.rs +++ b/srml/support/procedural/src/storage/impls.rs @@ -116,13 +116,13 @@ impl<'a, I: Iterator> Impls<'a, I> { } /// Take a value from storage, removing it afterwards. - fn take>(storage: &S) -> Self::Query { + fn take>(storage: &mut S) -> Self::Query { storage.take(>::key()) .#option_simple_1(|| #fielddefault) } /// Mutate the value under a key. - fn mutate R, S: #scrate::HashedStorage<#scrate::Twox128>>(f: F, storage: &S) -> R { + fn mutate R, S: #scrate::HashedStorage<#scrate::Twox128>>(f: F, storage: &mut S) -> R { let mut val = >::get(storage); let ret = f(&mut val); @@ -212,21 +212,24 @@ impl<'a, I: Iterator> Impls<'a, I> { } /// Take the value, reading and removing it. - fn take>(key: &#kty, storage: &S) -> Self::Query { + fn take>(key: &#kty, storage: &mut S) -> Self::Query { let key = #as_map::key_for(key); storage.take(&key[..]).#option_simple_1(|| #fielddefault) } /// Mutate the value under a key - fn mutate R, S: #scrate::HashedStorage<#scrate::#hasher>>(key: &#kty, f: F, storage: &S) -> R { + fn mutate R, S: #scrate::HashedStorage<#scrate::#hasher>>(key: &#kty, f: F, storage: &mut S) -> R { let mut val = #as_map::get(key, storage); let ret = f(&mut val); #mutate_impl ; ret } - } + + impl<#traitinstance: 'static + #traittype, #instance #bound_instantiable> + #scrate::storage::hashed::generator::AppendableStorageMap<#kty, #typ> for #name<#traitinstance, #instance> + {} } } @@ -349,7 +352,7 @@ impl<'a, I: Iterator> Impls<'a, I> { /// /// Takes care of updating previous and next elements points /// as well as updates head if the element is first or last. - fn remove_linkage>(linkage: Linkage<#kty>, storage: &S); + fn remove_linkage>(linkage: Linkage<#kty>, storage: &mut S); /// Read the contained data and it's linkage. fn read_with_linkage>(storage: &S, key: &[u8]) -> Option<(#value_type, Linkage<#kty>)>; @@ -358,7 +361,7 @@ impl<'a, I: Iterator> Impls<'a, I> { /// /// Takes care of updating head and previous head's pointer. fn new_head_linkage>( - storage: &S, + storage: &mut S, key: &#kty, ) -> Linkage<#kty>; @@ -368,7 +371,7 @@ impl<'a, I: Iterator> Impls<'a, I> { /// Overwrite current head pointer. /// /// If `None` is given head is removed from storage. - fn write_head>(storage: &S, head: Option<&#kty>); + fn write_head>(storage: &mut S, head: Option<&#kty>); } } }; @@ -380,7 +383,7 @@ impl<'a, I: Iterator> Impls<'a, I> { impl<#traitinstance: #traittype, #instance #bound_instantiable> self::#inner_module::Utils<#traitinstance, #instance> for #name<#traitinstance, #instance> { fn remove_linkage>( linkage: self::#inner_module::Linkage<#kty>, - storage: &S, + storage: &mut S, ) { use self::#inner_module::Utils; @@ -415,7 +418,7 @@ impl<'a, I: Iterator> Impls<'a, I> { } fn new_head_linkage>( - storage: &S, + storage: &mut S, key: &#kty, ) -> self::#inner_module::Linkage<#kty> { use self::#inner_module::Utils; @@ -450,7 +453,7 @@ impl<'a, I: Iterator> Impls<'a, I> { storage.get(#final_head_key) } - fn write_head>(storage: &S, head: Option<&#kty>) { + fn write_head>(storage: &mut S, head: Option<&#kty>) { match head { Some(head) => storage.put(#final_head_key, head), None => storage.kill(#final_head_key), @@ -489,7 +492,7 @@ impl<'a, I: Iterator> Impls<'a, I> { } /// Take the value, reading and removing it. - fn take>(key: &#kty, storage: &S) -> Self::Query { + fn take>(key: &#kty, storage: &mut S) -> Self::Query { use self::#inner_module::Utils; let res: Option<(#value_type, self::#inner_module::Linkage<#kty>)> = storage.take(&*#as_map::key_for(key)); @@ -503,12 +506,12 @@ impl<'a, I: Iterator> Impls<'a, I> { } /// Remove the value under a key. - fn remove>(key: &#kty, storage: &S) { + fn remove>(key: &#kty, storage: &mut S) { #as_map::take(key, storage); } /// Store a value to be associated with the given key from the map. - fn insert>(key: &#kty, val: &#typ, storage: &S) { + fn insert>(key: &#kty, val: &#typ, storage: &mut S) { use self::#inner_module::Utils; let key_for = &*#as_map::key_for(key); @@ -522,7 +525,7 @@ impl<'a, I: Iterator> Impls<'a, I> { } /// Mutate the value under a key - fn mutate R, S: #scrate::HashedStorage<#scrate::#hasher>>(key: &#kty, f: F, storage: &S) -> R { + fn mutate R, S: #scrate::HashedStorage<#scrate::#hasher>>(key: &#kty, f: F, storage: &mut S) -> R { use self::#inner_module::Utils; let key_for = &*#as_map::key_for(key); @@ -633,8 +636,10 @@ impl<'a, I: Iterator> Impls<'a, I> { } fn key_for(k1: &#k1ty, k2: &#k2ty) -> Vec { + use #scrate::storage::hashed::generator::StorageHasher; + let mut key = #as_double_map::prefix_for(k1); - key.extend(&#scrate::Hashable::#k2_hasher(k2)); + #scrate::codec::Encode::using_encoded(k2, |e| key.extend(&#scrate::#k2_hasher::hash(e))); key } @@ -643,12 +648,12 @@ impl<'a, I: Iterator> Impls<'a, I> { storage.get(&key).#option_simple_1(|| #fielddefault) } - fn take(key1: &#k1ty, key2: &#k2ty, storage: &S) -> Self::Query { + fn take(key1: &#k1ty, key2: &#k2ty, storage: &mut S) -> Self::Query { let key = #as_double_map::key_for(key1, key2); storage.take(&key).#option_simple_1(|| #fielddefault) } - fn mutate R, S: #scrate::UnhashedStorage>(key1: &#k1ty, key2: &#k2ty, f: F, storage: &S) -> R { + fn mutate R, S: #scrate::UnhashedStorage>(key1: &#k1ty, key2: &#k2ty, f: F, storage: &mut S) -> R { let mut val = #as_double_map::get(key1, key2, storage); let ret = f(&mut val); diff --git a/srml/support/procedural/src/storage/mod.rs b/srml/support/procedural/src/storage/mod.rs index ce81dd95c5a2e0f5200f6454e14a9741b1b9a509..742c47d259350649319910376ea61fd5bc6ce937 100644 --- a/srml/support/procedural/src/storage/mod.rs +++ b/srml/support/procedural/src/storage/mod.rs @@ -214,7 +214,13 @@ enum HasherKind { impl From<&SetHasher> for HasherKind { fn from(set_hasher: &SetHasher) -> Self { - match set_hasher.inner.content { + (&set_hasher.inner.content).into() + } +} + +impl From<&Hasher> for HasherKind { + fn from(hasher: &Hasher) -> Self { + match hasher { Hasher::Blake2_256(_) => HasherKind::Blake2_256, Hasher::Blake2_128(_) => HasherKind::Blake2_128, Hasher::Twox256(_) => HasherKind::Twox256, @@ -223,6 +229,7 @@ impl From<&SetHasher> for HasherKind { } } } + impl HasherKind { fn into_storage_hasher_struct(&self) -> TokenStream2 { match self { diff --git a/srml/support/procedural/src/storage/transformation.rs b/srml/support/procedural/src/storage/transformation.rs index 146210eb0c2ddae9f5e5198a5b6ea9c67732bd50..2827259420991ddd454b1d1c715599b3d854c33a 100644 --- a/srml/support/procedural/src/storage/transformation.rs +++ b/srml/support/procedural/src/storage/transformation.rs @@ -217,7 +217,7 @@ fn decl_store_extra_genesis( let type_infos = get_type_infos(storage_type); - let mut opt_build; + let opt_build; // need build line if let Some(ref config) = config.inner { let ident = if let Some(ident) = config.expr.content.as_ref() { @@ -295,7 +295,7 @@ fn decl_store_extra_genesis( use #scrate::codec::{Encode, Decode}; let v = (#builder)(&self); - <#name<#traitinstance, #instance> as #scrate::storage::hashed::generator::StorageValue<#typ>>::put(&v, &storage); + <#name<#traitinstance, #instance> as #scrate::storage::hashed::generator::StorageValue<#typ>>::put(&v, storage); }} }, DeclStorageTypeInfosKind::Map { key_type, .. } => { @@ -305,7 +305,7 @@ fn decl_store_extra_genesis( let data = (#builder)(&self); for (k, v) in data.into_iter() { - <#name<#traitinstance, #instance> as #scrate::storage::hashed::generator::StorageMap<#key_type, #typ>>::insert(&k, &v, &storage); + <#name<#traitinstance, #instance> as #scrate::storage::hashed::generator::StorageMap<#key_type, #typ>>::insert(&k, &v, storage); } }} }, @@ -316,7 +316,7 @@ fn decl_store_extra_genesis( let data = (#builder)(&self); for (k1, k2, v) in data.into_iter() { - <#name<#traitinstance, #instance> as #scrate::storage::unhashed::generator::StorageDoubleMap<#key1_type, #key2_type, #typ>>::insert(&k1, &k2, &v, &storage); + <#name<#traitinstance, #instance> as #scrate::storage::unhashed::generator::StorageDoubleMap<#key1_type, #key2_type, #typ>>::insert(&k1, &k2, &v, storage); } }} }, @@ -451,12 +451,11 @@ fn decl_store_extra_genesis( #[cfg(feature = "std")] impl#fparam_impl #scrate::runtime_primitives::BuildStorage for GenesisConfig#sparam { fn assimilate_storage(self, r: &mut #scrate::runtime_primitives::StorageOverlay, c: &mut #scrate::runtime_primitives::ChildrenStorageOverlay) -> ::std::result::Result<(), String> { - use #scrate::rstd::cell::RefCell; - let storage = RefCell::new(r); + let storage = r; #builders - let r = storage.into_inner(); + let r = storage; #scall(r, c, &self); @@ -607,7 +606,7 @@ fn decl_storage_items( i.linked_map(hasher.into_storage_hasher_struct(), key_type) }, DeclStorageTypeInfosKind::DoubleMap { key1_type, key2_type, key2_hasher, hasher } => { - i.double_map(hasher.into_storage_hasher_struct(), key1_type, key2_type, key2_hasher) + i.double_map(hasher.into_storage_hasher_struct(), key1_type, key2_type, key2_hasher.into_storage_hasher_struct()) }, }; impls.extend(implementation) @@ -759,14 +758,14 @@ fn store_functions_to_metadata ( let hasher = hasher.into_metadata(); let k1ty = clean_type_string("e!(#key1_type).to_string()); let k2ty = clean_type_string("e!(#key2_type).to_string()); - let k2_hasher = clean_type_string(&key2_hasher.to_string()); + let k2_hasher = key2_hasher.into_metadata(); quote!{ #scrate::metadata::StorageFunctionType::DoubleMap { hasher: #scrate::metadata::#hasher, key1: #scrate::metadata::DecodeDifferent::Encode(#k1ty), key2: #scrate::metadata::DecodeDifferent::Encode(#k2ty), value: #scrate::metadata::DecodeDifferent::Encode(#styp), - key2_hasher: #scrate::metadata::DecodeDifferent::Encode(#k2_hasher), + key2_hasher: #scrate::metadata::#k2_hasher, } } }, @@ -871,7 +870,7 @@ enum DeclStorageTypeInfosKind<'a> { hasher: HasherKind, key1_type: &'a syn::Type, key2_type: &'a syn::Type, - key2_hasher: TokenStream2, + key2_hasher: HasherKind, } } @@ -901,7 +900,7 @@ fn get_type_infos(storage_type: &DeclStorageType) -> DeclStorageTypeInfos { hasher: map.hasher.inner.as_ref().map(|h| h.into()).unwrap_or(HasherKind::Blake2_256), key1_type: &map.key1, key2_type: &map.key2.content, - key2_hasher: { let h = &map.key2_hasher; quote! { #h } }, + key2_hasher: (&map.key2_hasher).into(), }), }; diff --git a/srml/support/src/dispatch.rs b/srml/support/src/dispatch.rs index d5fabd341c9ee9d4e6a2aa371622de19e98ec17a..f2db609dc38b68df74e303fd1b7c6b1adb05fc5a 100644 --- a/srml/support/src/dispatch.rs +++ b/srml/support/src/dispatch.rs @@ -773,6 +773,7 @@ macro_rules! decl_module { $type, } variant $fn_name; + $( #[doc = $doc_attr] )* $( $rest )* } }; @@ -800,6 +801,7 @@ macro_rules! decl_module { $type, } variant $fn_name; + $( #[doc = $doc_attr] )* $( $rest )* } }; @@ -859,7 +861,10 @@ macro_rules! decl_module { (@imp $(#[$attr:meta])* - pub struct $mod_type:ident<$trait_instance:ident: $trait_name:ident$(, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)?> + pub struct $mod_type:ident< + $trait_instance:ident: $trait_name:ident + $(, $instance:ident: $instantiable:path $(= $module_default_instance:path)?)? + > for enum $call_type:ident where origin: $origin_type:ty, system = $system:ident { $( $(#[doc = $doc_attr:tt])* @@ -874,10 +879,17 @@ macro_rules! decl_module { { $( $on_finalize:tt )* } { $( $offchain:tt )* } ) => { + $crate::__check_reserved_fn_name! { + $($fn_name)* + } + // Workaround for https://github.com/rust-lang/rust/issues/26925 . Remove when sorted. #[derive(Clone, Copy, PartialEq, Eq)] #[cfg_attr(feature = "std", derive(Debug))] - pub struct $mod_type<$trait_instance: $trait_name $(, $instance: $instantiable $( = $module_default_instance)?)?>($crate::rstd::marker::PhantomData<($trait_instance $(, $instance)?)>); + pub struct $mod_type< + $trait_instance: $trait_name + $(, $instance: $instantiable $( = $module_default_instance)?)? + >($crate::rstd::marker::PhantomData<($trait_instance $(, $instance)?)>); $crate::decl_module! { @impl_on_initialize @@ -1201,6 +1213,38 @@ macro_rules! __function_to_metadata { } } +#[macro_export] +#[doc(hidden)] +macro_rules! __check_reserved_fn_name { + (deposit_event $( $rest:ident )*) => { + $crate::__check_reserved_fn_name!(@compile_error deposit_event); + }; + (on_initialize $( $rest:ident )*) => { + $crate::__check_reserved_fn_name!(@compile_error on_initialize); + }; + (on_initialise $( $rest:ident )*) => { + $crate::__check_reserved_fn_name!(@compile_error on_initialise); + }; + (on_finalize $( $rest:ident )*) => { + $crate::__check_reserved_fn_name!(@compile_error on_finalize); + }; + (on_finalise $( $rest:ident )*) => { + $crate::__check_reserved_fn_name!(@compile_error on_finalise); + }; + (offchain_worker $( $rest:ident )*) => { + $crate::__check_reserved_fn_name!(@compile_error offchain_worker); + }; + ($t:ident $( $rest:ident )*) => { + $crate::__check_reserved_fn_name!($( $rest )*); + }; + () => {}; + (@compile_error $ident:ident) => { + compile_error!(concat!("Invalid call fn name: `", stringify!($ident), + "`, name is reserved and doesn't match expected signature, please refer to `decl_module!`", + " documentation to see the appropriate usage, or rename it to an unreserved keyword.")); + }; +} + #[cfg(test)] // Do not complain about unused `dispatch` and `dispatch_aux`. #[allow(dead_code)] diff --git a/srml/support/src/double_map.rs b/srml/support/src/double_map.rs index 80d974064dedd41bbebd506e890e58575fd6f32c..d35570ae4f7b6d34bc681ec96ba50e5384f61f19 100644 --- a/srml/support/src/double_map.rs +++ b/srml/support/src/double_map.rs @@ -64,7 +64,7 @@ pub trait StorageDoubleMapWithHasher { /// Get an entry from this map. /// - /// If there is entry stored under the given keys, returns `None`. + /// If there is no entry stored under the given keys, returns `None`. fn get(k1: &Q, k2: &R) -> Option where Self::Key1: Borrow, diff --git a/srml/support/src/lib.rs b/srml/support/src/lib.rs index cdaec09632d48384e39fdf1f73eb41e98b7e6fab..fec7249c230b9f3d58dda95dbd9b9bbff9316bb2 100644 --- a/srml/support/src/lib.rs +++ b/srml/support/src/lib.rs @@ -57,12 +57,47 @@ pub mod unsigned; mod double_map; pub mod traits; -pub use self::storage::{StorageList, StorageValue, StorageMap, EnumerableStorageMap, StorageDoubleMap}; +pub use self::storage::{ + StorageValue, StorageMap, EnumerableStorageMap, StorageDoubleMap, AppendableStorageMap +}; pub use self::hashable::Hashable; pub use self::dispatch::{Parameter, Dispatchable, Callable, IsSubType}; pub use self::double_map::StorageDoubleMapWithHasher; pub use runtime_io::{print, storage_root}; +/// Macro for easily creating a new implementation of the `Get` trait. Use similarly to +/// how you would declare a `const`: +/// +/// ```no_compile +/// parameter_types! { +/// pub const Argument: u64 = 42; +/// } +/// trait Config { +/// type Parameter: Get; +/// } +/// struct Runtime; +/// impl Config for Runtime { +/// type Parameter = Argument; +/// } +/// ``` +#[macro_export] +macro_rules! parameter_types { + (pub const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => ( + pub struct $name; + $crate::parameter_types!{IMPL $name , $type , $value} + $crate::parameter_types!{ $( $rest )* } + ); + (const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => ( + struct $name; + $crate::parameter_types!{IMPL $name , $type , $value} + $crate::parameter_types!{ $( $rest )* } + ); + () => (); + (IMPL $name:ident , $type:ty , $value:expr) => { + impl $crate::traits::Get<$type> for $name { fn get() -> $type { $value } } + } +} + #[doc(inline)] pub use srml_support_procedural::decl_storage; @@ -381,7 +416,7 @@ mod tests { let key2 = 18u32; DoubleMap::insert(key1, key2, vec![1]); - DoubleMap::append(key1, key2, &[2, 3]); + DoubleMap::append(key1, key2, &[2, 3]).unwrap(); assert_eq!(DoubleMap::get(key1, key2), vec![1, 2, 3]); }); } @@ -432,7 +467,7 @@ mod tests { key1: DecodeDifferent::Encode("u32"), key2: DecodeDifferent::Encode("u32"), value: DecodeDifferent::Encode("u64"), - key2_hasher: DecodeDifferent::Encode("blake2_256"), + key2_hasher: StorageHasher::Blake2_256, }, default: DecodeDifferent::Encode( DefaultByteGetter(&__GetByteStructDataDM(PhantomData::)) @@ -447,7 +482,7 @@ mod tests { key1: DecodeDifferent::Encode("T::BlockNumber"), key2: DecodeDifferent::Encode("T::BlockNumber"), value: DecodeDifferent::Encode("T::BlockNumber"), - key2_hasher: DecodeDifferent::Encode("twox_128"), + key2_hasher: StorageHasher::Twox128, }, default: DecodeDifferent::Encode( DefaultByteGetter(&__GetByteStructGenericDataDM(PhantomData::)) @@ -462,7 +497,7 @@ mod tests { key1: DecodeDifferent::Encode("T::BlockNumber"), key2: DecodeDifferent::Encode("T::BlockNumber"), value: DecodeDifferent::Encode("T::BlockNumber"), - key2_hasher: DecodeDifferent::Encode("twox_256"), + key2_hasher: StorageHasher::Twox256, }, default: DecodeDifferent::Encode( DefaultByteGetter(&__GetByteStructGenericData2DM(PhantomData::)) @@ -477,7 +512,7 @@ mod tests { key1: DecodeDifferent::Encode("u32"), key2: DecodeDifferent::Encode("T::BlockNumber"), value: DecodeDifferent::Encode("Vec"), - key2_hasher: DecodeDifferent::Encode("blake2_256"), + key2_hasher: StorageHasher::Blake2_256, }, default: DecodeDifferent::Encode( DefaultByteGetter(&__GetByteStructGenericData2DM(PhantomData::)) diff --git a/srml/support/src/metadata.rs b/srml/support/src/metadata.rs index b1da7587be390d18789d0eb1a853a450d5e20790..0e33d7727281ea4d36b8fd243dc51704194716cf 100644 --- a/srml/support/src/metadata.rs +++ b/srml/support/src/metadata.rs @@ -16,7 +16,7 @@ pub use srml_metadata::{ DecodeDifferent, FnEncode, RuntimeMetadata, - ModuleMetadata, RuntimeMetadataV4, + ModuleMetadata, RuntimeMetadataV5, DefaultByteGetter, RuntimeMetadataPrefixed, StorageMetadata, StorageFunctionMetadata, StorageFunctionType, StorageFunctionModifier, @@ -40,8 +40,8 @@ macro_rules! impl_runtime_metadata { ) => { impl $runtime { pub fn metadata() -> $crate::metadata::RuntimeMetadataPrefixed { - $crate::metadata::RuntimeMetadata::V4 ( - $crate::metadata::RuntimeMetadataV4 { + $crate::metadata::RuntimeMetadata::V5 ( + $crate::metadata::RuntimeMetadataV5 { modules: $crate::__runtime_modules_to_metadata!($runtime;; $( $rest )*), } ).into() @@ -246,7 +246,8 @@ mod tests { mod system { pub trait Trait { - type Origin: Into>> + From>; + type Origin: Into, Self::Origin>> + + From>; type AccountId; type BlockNumber; } @@ -381,8 +382,8 @@ mod tests { event_module2::Module with Event Storage Call, ); - const EXPECTED_METADATA: RuntimeMetadata = RuntimeMetadata::V4( - RuntimeMetadataV4 { + const EXPECTED_METADATA: RuntimeMetadata = RuntimeMetadata::V5( + RuntimeMetadataV5 { modules: DecodeDifferent::Encode(&[ ModuleMetadata { name: DecodeDifferent::Encode("system"), diff --git a/srml/support/src/origin.rs b/srml/support/src/origin.rs index 48d4be80c6f984b068c0e882bb6ace3b1be27397..9bc2cab8b9d178630144cfee9d44c3485fef0f1e 100644 --- a/srml/support/src/origin.rs +++ b/srml/support/src/origin.rs @@ -112,12 +112,12 @@ macro_rules! impl_outer_origin { $name::system(x) } } - impl Into>> for $name { - fn into(self) -> Option<$system::Origin<$runtime>> { + impl Into<$crate::rstd::result::Result<$system::Origin<$runtime>, $name>> for $name { + fn into(self) -> $crate::rstd::result::Result<$system::Origin<$runtime>, Self> { if let $name::system(l) = self { - Some(l) + Ok(l) } else { - None + Err(self) } } } @@ -132,12 +132,18 @@ macro_rules! impl_outer_origin { $name::$module(x) } } - impl Into )*>> for $name { - fn into(self) -> Option<$module::Origin $( <$generic_param $(, $generic_instance )? > )*> { + impl Into<$crate::rstd::result::Result< + $module::Origin $( <$generic_param $(, $generic_instance )? > )*, + $name + >> for $name { + fn into(self) -> $crate::rstd::result::Result< + $module::Origin $( <$generic_param $(, $generic_instance )? > )*, + Self + > { if let $name::$module(l) = self { - Some(l) + Ok(l) } else { - None + Err(self) } } } diff --git a/srml/support/src/runtime.rs b/srml/support/src/runtime.rs index 4bf574bae58d1803f8cd9f4f4d56f7b10e919f95..1ce95a3f3ce562262da750da97f790156f6ff797 100644 --- a/srml/support/src/runtime.rs +++ b/srml/support/src/runtime.rs @@ -287,7 +287,7 @@ macro_rules! construct_runtime { $uncheckedextrinsic; ; $( - $name: $module::{ $( $modules $( ( $( $modules_args ),* ) )* ),* } + $name: $module::{ $( $modules $( ( $( $modules_args )* ) )* ),* } ),*; ); $crate::__impl_outer_validate_unsigned!( diff --git a/srml/support/src/storage/child.rs b/srml/support/src/storage/child.rs deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/srml/support/src/storage/hashed/generator.rs b/srml/support/src/storage/hashed/generator.rs index 12600a9eafa6a9239f9aeb8d2d508c1dbadc7998..5a8b2f9d8f54b0fe4f51edb715aafa8614bf589a 100644 --- a/srml/support/src/storage/hashed/generator.rs +++ b/srml/support/src/storage/hashed/generator.rs @@ -103,25 +103,25 @@ pub trait HashedStorage { } /// Put a value in under a key. - fn put(&self, key: &[u8], val: &T); + fn put(&mut self, key: &[u8], val: &T); /// Remove the bytes of a key from storage. - fn kill(&self, key: &[u8]); + fn kill(&mut self, key: &[u8]); /// Take a value from storage, deleting it after reading. - fn take(&self, key: &[u8]) -> Option { + fn take(&mut self, key: &[u8]) -> Option { let value = self.get(key); self.kill(key); value } /// Take a value from storage, deleting it after reading. - fn take_or_panic(&self, key: &[u8]) -> T { + fn take_or_panic(&mut self, key: &[u8]) -> T { self.take(key).expect("Required values must be in storage") } /// Take a value from storage, deleting it after reading. - fn take_or_default(&self, key: &[u8]) -> T { + fn take_or_default(&mut self, key: &[u8]) -> T { self.take(key).unwrap_or_default() } @@ -129,12 +129,12 @@ pub trait HashedStorage { fn get_raw(&self, key: &[u8]) -> Option>; /// Put a raw byte slice into storage. - fn put_raw(&self, key: &[u8], value: &[u8]); + fn put_raw(&mut self, key: &[u8], value: &[u8]); } // We use a construct like this during when genesis storage is being built. #[cfg(feature = "std")] -impl HashedStorage for std::cell::RefCell<&mut sr_primitives::StorageOverlay> { +impl HashedStorage for sr_primitives::StorageOverlay { fn exists(&self, key: &[u8]) -> bool { UnhashedStorage::exists(self, &H::hash(key).as_ref()) } @@ -143,11 +143,11 @@ impl HashedStorage for std::cell::RefCell<&mut sr_primitive UnhashedStorage::get(self, &H::hash(key).as_ref()) } - fn put(&self, key: &[u8], val: &T) { + fn put(&mut self, key: &[u8], val: &T) { UnhashedStorage::put(self, &H::hash(key).as_ref(), val) } - fn kill(&self, key: &[u8]) { + fn kill(&mut self, key: &[u8]) { UnhashedStorage::kill(self, &H::hash(key).as_ref()) } @@ -155,7 +155,7 @@ impl HashedStorage for std::cell::RefCell<&mut sr_primitive UnhashedStorage::get_raw(self, &H::hash(key).as_ref()) } - fn put_raw(&self, key: &[u8], value: &[u8]) { + fn put_raw(&mut self, key: &[u8], value: &[u8]) { UnhashedStorage::put_raw(self, &H::hash(key).as_ref(), value) } } @@ -177,18 +177,18 @@ pub trait StorageValue { fn get>(storage: &S) -> Self::Query; /// Take a value from storage, removing it afterwards. - fn take>(storage: &S) -> Self::Query; + fn take>(storage: &mut S) -> Self::Query; /// Store a value under this key into the provided storage instance. - fn put>(val: &T, storage: &S) { + fn put>(val: &T, storage: &mut S) { storage.put(Self::key(), val) } /// Mutate this value - fn mutate R, S: HashedStorage>(f: F, storage: &S) -> R; + fn mutate R, S: HashedStorage>(f: F, storage: &mut S) -> R; /// Clear the storage value. - fn kill>(storage: &S) { + fn kill>(storage: &mut S) { storage.kill(Self::key()) } @@ -196,7 +196,7 @@ pub trait StorageValue { /// /// `T` is required to implement `codec::EncodeAppend`. fn append, I: codec::Encode>( - items: &[I], storage: &S + items: &[I], storage: &mut S ) -> Result<(), &'static str> where T: codec::EncodeAppend { let new_val = ::append( storage.get_raw(Self::key()).unwrap_or_default(), @@ -207,36 +207,6 @@ pub trait StorageValue { } } -/// A strongly-typed list in storage. -pub trait StorageList { - /// Get the prefix key in storage. - fn prefix() -> &'static [u8]; - - /// Get the key used to put the length field. - fn len_key() -> Vec; - - /// Get the storage key used to fetch a value at a given index. - fn key_for(index: u32) -> Vec; - - /// Read out all the items. - fn items>(storage: &S) -> Vec; - - /// Set the current set of items. - fn set_items>(items: &[T], storage: &S); - - /// Set the item at the given index. - fn set_item>(index: u32, item: &T, storage: &S); - - /// Load the value at given index. Returns `None` if the index is out-of-bounds. - fn get>(index: u32, storage: &S) -> Option; - - /// Load the length of the list - fn len>(storage: &S) -> u32; - - /// Clear the list. - fn clear>(storage: &S); -} - /// A strongly-typed map in storage. pub trait StorageMap { /// The type that get/take returns. @@ -259,20 +229,20 @@ pub trait StorageMap { fn get>(key: &K, storage: &S) -> Self::Query; /// Take the value under a key. - fn take>(key: &K, storage: &S) -> Self::Query; + fn take>(key: &K, storage: &mut S) -> Self::Query; /// Store a value to be associated with the given key from the map. - fn insert>(key: &K, val: &V, storage: &S) { + fn insert>(key: &K, val: &V, storage: &mut S) { storage.put(&Self::key_for(key)[..], val); } /// Remove the value under a key. - fn remove>(key: &K, storage: &S) { + fn remove>(key: &K, storage: &mut S) { storage.kill(&Self::key_for(key)[..]); } /// Mutate the value under a key. - fn mutate R, S: HashedStorage>(key: &K, f: F, storage: &S) -> R; + fn mutate R, S: HashedStorage>(key: &K, f: F, storage: &mut S) -> R; } /// A `StorageMap` with enumerable entries. @@ -281,5 +251,25 @@ pub trait EnumerableStorageMap: StorageMap>(storage: &S) -> Option; /// Enumerate all elements in the map. - fn enumerate<'a, S: HashedStorage>(storage: &'a S) -> Box + 'a> where K: 'a, V: 'a; + fn enumerate<'a, S: HashedStorage>( + storage: &'a S + ) -> Box + 'a> where K: 'a, V: 'a; +} + +/// A `StorageMap` with appendable entries. +pub trait AppendableStorageMap: StorageMap { + /// Append the given items to the value in the storage. + /// + /// `T` is required to implement `codec::EncodeAppend`. + fn append, I: codec::Encode>( + key : &K, items: &[I], storage: &mut S + ) -> Result<(), &'static str> where V: codec::EncodeAppend { + let k = Self::key_for(key); + let new_val = ::append( + storage.get_raw(&k[..]).unwrap_or_default(), + items, + ).ok_or_else(|| "Could not append given item")?; + storage.put_raw(&k[..], &new_val); + Ok(()) + } } diff --git a/srml/support/src/storage/mod.rs b/srml/support/src/storage/mod.rs index 426e480f0c262717c6d055dc02a711a4664ca809..a1891dade3b0c5b4010824c0bff8e641e18f9194 100644 --- a/srml/support/src/storage/mod.rs +++ b/srml/support/src/storage/mod.rs @@ -70,17 +70,17 @@ impl HashedStorage for RuntimeStorage { } /// Put a value in under a key. - fn put(&self, key: &[u8], val: &T) { + fn put(&mut self, key: &[u8], val: &T) { hashed::put(&H::hash, key, val) } /// Remove the bytes of a key from storage. - fn kill(&self, key: &[u8]) { + fn kill(&mut self, key: &[u8]) { hashed::kill(&H::hash, key) } /// Take a value from storage, deleting it after reading. - fn take(&self, key: &[u8]) -> Option { + fn take(&mut self, key: &[u8]) -> Option { hashed::take(&H::hash, key) } @@ -88,7 +88,7 @@ impl HashedStorage for RuntimeStorage { hashed::get_raw(&H::hash, key) } - fn put_raw(&self, key: &[u8], value: &[u8]) { + fn put_raw(&mut self, key: &[u8], value: &[u8]) { hashed::put_raw(&H::hash, key, value) } } @@ -104,22 +104,22 @@ impl UnhashedStorage for RuntimeStorage { } /// Put a value in under a key. - fn put(&self, key: &[u8], val: &T) { + fn put(&mut self, key: &[u8], val: &T) { unhashed::put(key, val) } /// Remove the bytes of a key from storage. - fn kill(&self, key: &[u8]) { + fn kill(&mut self, key: &[u8]) { unhashed::kill(key) } /// Remove the bytes of a key from storage. - fn kill_prefix(&self, prefix: &[u8]) { + fn kill_prefix(&mut self, prefix: &[u8]) { unhashed::kill_prefix(prefix) } /// Take a value from storage, deleting it after reading. - fn take(&self, key: &[u8]) -> Option { + fn take(&mut self, key: &[u8]) -> Option { unhashed::take(key) } @@ -127,7 +127,7 @@ impl UnhashedStorage for RuntimeStorage { unhashed::get_raw(key) } - fn put_raw(&self, key: &[u8], value: &[u8]) { + fn put_raw(&mut self, key: &[u8], value: &[u8]) { unhashed::put_raw(key, value) } } @@ -178,89 +178,21 @@ impl StorageValue for U where U: hashed::generator::StorageValue U::get(&RuntimeStorage) } fn put>(val: Arg) { - U::put(val.borrow(), &RuntimeStorage) + U::put(val.borrow(), &mut RuntimeStorage) } fn mutate R>(f: F) -> R { - U::mutate(f, &RuntimeStorage) + U::mutate(f, &mut RuntimeStorage) } fn kill() { - U::kill(&RuntimeStorage) + U::kill(&mut RuntimeStorage) } fn take() -> Self::Query { - U::take(&RuntimeStorage) + U::take(&mut RuntimeStorage) } fn append(items: &[I]) -> Result<(), &'static str> where T: EncodeAppend { - U::append(items, &RuntimeStorage) - } -} - -/// A strongly-typed list in storage. -pub trait StorageList { - /// Get the prefix key in storage. - fn prefix() -> &'static [u8]; - - /// Get the key used to store the length field. - fn len_key() -> Vec; - - /// Get the storage key used to fetch a value at a given index. - fn key_for(index: u32) -> Vec; - - /// Read out all the items. - fn items() -> Vec; - - /// Set the current set of items. - fn set_items(items: &[T]); - - /// Set the item at the given index. - fn set_item>(index: u32, val: Arg); - - /// Load the value at given index. Returns `None` if the index is out-of-bounds. - fn get(index: u32) -> Option; - - /// Load the length of the list - fn len() -> u32; - - /// Clear the list. - fn clear(); -} - -impl StorageList for U where U: hashed::generator::StorageList { - fn prefix() -> &'static [u8] { - >::prefix() - } - - fn len_key() -> Vec { - >::len_key() - } - - fn key_for(index: u32) -> Vec { - >::key_for(index) - } - - fn items() -> Vec { - U::items(&RuntimeStorage) - } - - fn set_items(items: &[T]) { - U::set_items(items, &RuntimeStorage) - } - - fn set_item>(index: u32, val: Arg) { - U::set_item(index, val.borrow(), &RuntimeStorage) - } - - fn get(index: u32) -> Option { - U::get(index, &RuntimeStorage) - } - - fn len() -> u32 { - U::len(&RuntimeStorage) - } - - fn clear() { - U::clear(&RuntimeStorage) + U::append(items, &mut RuntimeStorage) } } @@ -314,26 +246,45 @@ impl StorageMap for U where U: hashed::generator::S } fn insert, ValArg: Borrow>(key: KeyArg, val: ValArg) { - U::insert(key.borrow(), val.borrow(), &RuntimeStorage) + U::insert(key.borrow(), val.borrow(), &mut RuntimeStorage) } fn remove>(key: KeyArg) { - U::remove(key.borrow(), &RuntimeStorage) + U::remove(key.borrow(), &mut RuntimeStorage) } fn mutate, R, F: FnOnce(&mut Self::Query) -> R>(key: KeyArg, f: F) -> R { - U::mutate(key.borrow(), f, &RuntimeStorage) + U::mutate(key.borrow(), f, &mut RuntimeStorage) } fn take>(key: KeyArg) -> Self::Query { - U::take(key.borrow(), &RuntimeStorage) + U::take(key.borrow(), &mut RuntimeStorage) + } +} + +/// A storage map with values that can be appended to. +pub trait AppendableStorageMap: StorageMap { + /// Append the given item to the value in the storage. + /// + /// `T` is required to implement `codec::EncodeAppend`. + fn append, I: Encode>(key: KeyArg, items: &[I]) -> Result<(), &'static str> + where V: EncodeAppend; +} + +impl AppendableStorageMap for U + where U: hashed::generator::AppendableStorageMap +{ + fn append, I: Encode>(key: KeyArg, items: &[I]) -> Result<(), &'static str> + where V: EncodeAppend + { + U::append(key.borrow(), items, &mut RuntimeStorage) } } /// A storage map that can be enumerated. /// -/// Note that type is primarily useful for off-chain computations. -/// Runtime implementors should avoid enumerating storage entries. +/// Primarily useful for off-chain computations. +/// Runtime implementors should avoid enumerating storage entries on-chain. pub trait EnumerableStorageMap: StorageMap { /// Return current head element. fn head() -> Option; @@ -342,7 +293,9 @@ pub trait EnumerableStorageMap: StorageMap { fn enumerate() -> Box> where K: 'static, V: 'static; } -impl EnumerableStorageMap for U where U: hashed::generator::EnumerableStorageMap { +impl EnumerableStorageMap for U + where U: hashed::generator::EnumerableStorageMap +{ fn head() -> Option { >::head(&RuntimeStorage) } @@ -444,19 +397,19 @@ where } fn take, KArg2: Borrow>(k1: KArg1, k2: KArg2) -> Self::Query { - U::take(k1.borrow(), k2.borrow(), &RuntimeStorage) + U::take(k1.borrow(), k2.borrow(), &mut RuntimeStorage) } fn insert, KArg2: Borrow, VArg: Borrow>(k1: KArg1, k2: KArg2, val: VArg) { - U::insert(k1.borrow(), k2.borrow(), val.borrow(), &RuntimeStorage) + U::insert(k1.borrow(), k2.borrow(), val.borrow(), &mut RuntimeStorage) } fn remove, KArg2: Borrow>(k1: KArg1, k2: KArg2) { - U::remove(k1.borrow(), k2.borrow(), &RuntimeStorage) + U::remove(k1.borrow(), k2.borrow(), &mut RuntimeStorage) } fn remove_prefix>(k1: KArg1) { - U::remove_prefix(k1.borrow(), &RuntimeStorage) + U::remove_prefix(k1.borrow(), &mut RuntimeStorage) } fn mutate(k1: KArg1, k2: KArg2, f: F) -> R @@ -465,7 +418,7 @@ where KArg2: Borrow, F: FnOnce(&mut Self::Query) -> R { - U::mutate(k1.borrow(), k2.borrow(), f, &RuntimeStorage) + U::mutate(k1.borrow(), k2.borrow(), f, &mut RuntimeStorage) } fn append( @@ -479,7 +432,7 @@ where I: codec::Encode, V: EncodeAppend, { - U::append(k1.borrow(), k2.borrow(), items, &RuntimeStorage) + U::append(k1.borrow(), k2.borrow(), items, &mut RuntimeStorage) } } diff --git a/srml/support/src/storage/storage_items.rs b/srml/support/src/storage/storage_items.rs index 720cac64c5361291ab3eee18fc462198c443dd10..9d89b81e0d950b224f45e31e90aa460a35948230 100644 --- a/srml/support/src/storage/storage_items.rs +++ b/srml/support/src/storage/storage_items.rs @@ -22,7 +22,6 @@ //! Three kinds of data types are currently supported: //! - values //! - maps -//! - lists //! //! # Examples: //! @@ -39,8 +38,6 @@ //! pub Value: b"putd_key" => SessionKey; //! // private map. //! Balances: b"private_map:" => map [AuthorityId => Balance]; -//! // private list. -//! Authorities: b"auth:" => list [AuthorityId]; //! } //! //!# fn main() { } @@ -159,16 +156,6 @@ macro_rules! storage_items { storage_items!($($t)*); }; - - // lists - ($name:ident : $prefix:expr => list [$ty:ty]; $($t:tt)*) => { - $crate::__storage_items_internal!(() $name: $prefix => list [$ty]); - storage_items!($($t)*); - }; - (pub $name:ident : $prefix:expr => list [$ty:ty]; $($t:tt)*) => { - $crate::__storage_items_internal!((pub) $name: $prefix => list [$ty]); - storage_items!($($t)*); - }; () => () } @@ -197,12 +184,12 @@ macro_rules! __storage_items_internal { } /// Take a value from storage, removing it afterwards. - fn take>(storage: &S) -> Self::Query { + fn take>(storage: &mut S) -> Self::Query { storage.$taker($key) } /// Mutate this value. - fn mutate R, S: $crate::HashedStorage<$crate::Twox128>>(f: F, storage: &S) -> R { + fn mutate R, S: $crate::HashedStorage<$crate::Twox128>>(f: F, storage: &mut S) -> R { let mut val = >::get(storage); let ret = f(&mut val); @@ -256,13 +243,13 @@ macro_rules! __storage_items_internal { } /// Take the value, reading and removing it. - fn take>(key: &$kty, storage: &S) -> Self::Query { + fn take>(key: &$kty, storage: &mut S) -> Self::Query { let key = <$name as $crate::storage::hashed::generator::StorageMap<$kty, $ty>>::key_for(key); storage.$taker(&key[..]) } /// Mutate the value under a key. - fn mutate R, S: $crate::HashedStorage>(key: &$kty, f: F, storage: &S) -> R { + fn mutate R, S: $crate::HashedStorage>(key: &$kty, f: F, storage: &mut S) -> R { let mut val = >::take(key, storage); let ret = f(&mut val); @@ -282,84 +269,6 @@ macro_rules! __storage_items_internal { } } }; - // generator for lists. - (($($vis:tt)*) $name:ident : $prefix:expr => list [$ty:ty]) => { - $($vis)* struct $name; - - impl $name { - fn clear_item>(index: u32, storage: &S) { - if index < <$name as $crate::storage::hashed::generator::StorageList<$ty>>::len(storage) { - storage.kill(&<$name as $crate::storage::hashed::generator::StorageList<$ty>>::key_for(index)); - } - } - - fn set_len>(count: u32, storage: &S) { - (count..<$name as $crate::storage::hashed::generator::StorageList<$ty>>::len(storage)).for_each(|i| $name::clear_item(i, storage)); - storage.put(&<$name as $crate::storage::hashed::generator::StorageList<$ty>>::len_key(), &count); - } - } - - impl $crate::storage::hashed::generator::StorageList<$ty> for $name { - /// Get the prefix key in storage. - fn prefix() -> &'static [u8] { - $prefix - } - - /// Get the key used to put the length field. - fn len_key() -> $crate::rstd::vec::Vec { - let mut key = $prefix.to_vec(); - key.extend(b"len"); - key - } - - /// Get the storage key used to fetch a value at a given index. - fn key_for(index: u32) -> $crate::rstd::vec::Vec { - let mut key = $prefix.to_vec(); - $crate::codec::Encode::encode_to(&index, &mut key); - key - } - - /// Read out all the items. - fn items>(storage: &S) -> $crate::rstd::vec::Vec<$ty> { - (0..<$name as $crate::storage::hashed::generator::StorageList<$ty>>::len(storage)) - .map(|i| <$name as $crate::storage::hashed::generator::StorageList<$ty>>::get(i, storage).expect("all items within length are set; qed")) - .collect() - } - - /// Set the current set of items. - fn set_items>(items: &[$ty], storage: &S) { - $name::set_len(items.len() as u32, storage); - items.iter() - .enumerate() - .for_each(|(i, item)| <$name as $crate::storage::hashed::generator::StorageList<$ty>>::set_item(i as u32, item, storage)); - } - - fn set_item>(index: u32, item: &$ty, storage: &S) { - if index < <$name as $crate::storage::hashed::generator::StorageList<$ty>>::len(storage) { - storage.put(&<$name as $crate::storage::hashed::generator::StorageList<$ty>>::key_for(index)[..], item); - } - } - - /// Load the value at given index. Returns `None` if the index is out-of-bounds. - fn get>(index: u32, storage: &S) -> Option<$ty> { - storage.get(&<$name as $crate::storage::hashed::generator::StorageList<$ty>>::key_for(index)[..]) - } - - /// Load the length of the list. - fn len>(storage: &S) -> u32 { - storage.get(&<$name as $crate::storage::hashed::generator::StorageList<$ty>>::len_key()).unwrap_or_default() - } - - /// Clear the list. - fn clear>(storage: &S) { - for i in 0..<$name as $crate::storage::hashed::generator::StorageList<$ty>>::len(storage) { - $name::clear_item(i, storage); - } - - storage.kill(&<$name as $crate::storage::hashed::generator::StorageList<$ty>>::len_key()[..]) - } - } - }; } #[macro_export] @@ -383,7 +292,6 @@ macro_rules! __handle_wrap_internal { #[allow(dead_code)] mod tests { use std::collections::HashMap; - use std::cell::RefCell; use super::*; use crate::metadata::*; use crate::metadata::StorageHasher; @@ -392,49 +300,26 @@ mod tests { storage_items! { Value: b"a" => u32; - List: b"b:" => list [u64]; Map: b"c:" => map [u32 => [u8; 32]]; } #[test] fn value() { - let mut overlay = HashMap::new(); - let storage = RefCell::new(&mut overlay); + let mut storage = HashMap::new(); assert!(Value::get(&storage).is_none()); - Value::put(&100_000, &storage); + Value::put(&100_000, &mut storage); assert_eq!(Value::get(&storage), Some(100_000)); - Value::kill(&storage); + Value::kill(&mut storage); assert!(Value::get(&storage).is_none()); } - #[test] - fn list() { - let mut overlay = HashMap::new(); - let storage = RefCell::new(&mut overlay); - assert_eq!(List::len(&storage), 0); - assert!(List::items(&storage).is_empty()); - - List::set_items(&[0, 2, 4, 6, 8], &storage); - assert_eq!(List::items(&storage), &[0, 2, 4, 6, 8]); - assert_eq!(List::len(&storage), 5); - - List::set_item(2, &10, &storage); - assert_eq!(List::items(&storage), &[0, 2, 10, 6, 8]); - assert_eq!(List::len(&storage), 5); - - List::clear(&storage); - assert_eq!(List::len(&storage), 0); - assert!(List::items(&storage).is_empty()); - } - #[test] fn map() { - let mut overlay = HashMap::new(); - let storage = RefCell::new(&mut overlay); + let mut storage = HashMap::new(); assert!(Map::get(&5, &storage).is_none()); - Map::insert(&5, &[1; 32], &storage); + Map::insert(&5, &[1; 32], &mut storage); assert_eq!(Map::get(&5, &storage), Some([1; 32])); - assert_eq!(Map::take(&5, &storage), Some([1; 32])); + assert_eq!(Map::take(&5, &mut storage), Some([1; 32])); assert!(Map::get(&5, &storage).is_none()); assert!(Map::get(&999, &storage).is_none()); } @@ -904,3 +789,46 @@ mod test3 { type BlockNumber = u32; } } + +#[cfg(test)] +#[allow(dead_code)] +mod test_map_vec_append { + pub trait Trait { + type Origin; + type BlockNumber; + } + decl_module! { + pub struct Module for enum Call where origin: T::Origin {} + } + crate::decl_storage! { + trait Store for Module as Test { + JustVec: Vec; + MapVec: map u32 => Vec; + } + } + + struct Test {} + + impl Trait for Test { + type Origin = u32; + type BlockNumber = u32; + } + + #[test] + fn append_works() { + use crate::storage::{AppendableStorageMap, StorageMap, StorageValue}; + use runtime_io::{with_externalities, TestExternalities}; + + with_externalities(&mut TestExternalities::default(), || { + let _ = >::append(1, &[1, 2, 3]); + let _ = >::append(1, &[4, 5]); + assert_eq!(>::get(1), vec![1, 2, 3, 4, 5]); + + let _ = >::append(&[1, 2, 3]); + let _ = >::append(&[4, 5]); + assert_eq!(>::get(), vec![1, 2, 3, 4, 5]); + }); + } +} + + diff --git a/srml/support/src/storage/unhashed/generator.rs b/srml/support/src/storage/unhashed/generator.rs index 7e9e5a21993f4e8b8056c5fba0e18f774dda0750..e6bbb5905f13120097434b19f90394179a8f051e 100644 --- a/srml/support/src/storage/unhashed/generator.rs +++ b/srml/support/src/storage/unhashed/generator.rs @@ -34,66 +34,66 @@ pub trait UnhashedStorage { fn get_or_default(&self, key: &[u8]) -> T { self.get(key).unwrap_or_default() } /// Put a value in under a key. - fn put(&self, key: &[u8], val: &T); + fn put(&mut self, key: &[u8], val: &T); /// Remove the bytes of a key from storage. - fn kill(&self, key: &[u8]); + fn kill(&mut self, key: &[u8]); /// Remove the bytes of a key from storage. - fn kill_prefix(&self, prefix: &[u8]); + fn kill_prefix(&mut self, prefix: &[u8]); /// Take a value from storage, deleting it after reading. - fn take(&self, key: &[u8]) -> Option { + fn take(&mut self, key: &[u8]) -> Option { let value = self.get(key); self.kill(key); value } /// Take a value from storage, deleting it after reading. - fn take_or_panic(&self, key: &[u8]) -> T { self.take(key).expect("Required values must be in storage") } + fn take_or_panic(&mut self, key: &[u8]) -> T { self.take(key).expect("Required values must be in storage") } /// Take a value from storage, deleting it after reading. - fn take_or_default(&self, key: &[u8]) -> T { self.take(key).unwrap_or_default() } + fn take_or_default(&mut self, key: &[u8]) -> T { self.take(key).unwrap_or_default() } /// Get a Vec of bytes from storage. fn get_raw(&self, key: &[u8]) -> Option>; /// Put a raw byte slice into storage. - fn put_raw(&self, key: &[u8], value: &[u8]); + fn put_raw(&mut self, key: &[u8], value: &[u8]); } // We use a construct like this during when genesis storage is being built. #[cfg(feature = "std")] -impl UnhashedStorage for std::cell::RefCell<&mut sr_primitives::StorageOverlay> { +impl UnhashedStorage for sr_primitives::StorageOverlay { fn exists(&self, key: &[u8]) -> bool { - self.borrow().contains_key(key) + self.contains_key(key) } fn get(&self, key: &[u8]) -> Option { - self.borrow().get(key) + self.get(key) .map(|x| codec::Decode::decode(&mut x.as_slice()).expect("Unable to decode expected type.")) } - fn put(&self, key: &[u8], val: &T) { - self.borrow_mut().insert(key.to_vec(), codec::Encode::encode(val)); + fn put(&mut self, key: &[u8], val: &T) { + self.insert(key.to_vec(), codec::Encode::encode(val)); } - fn kill(&self, key: &[u8]) { - self.borrow_mut().remove(key); + fn kill(&mut self, key: &[u8]) { + self.remove(key); } - fn kill_prefix(&self, prefix: &[u8]) { - self.borrow_mut().retain(|key, _| { + fn kill_prefix(&mut self, prefix: &[u8]) { + self.retain(|key, _| { !key.starts_with(prefix) }) } fn get_raw(&self, key: &[u8]) -> Option> { - self.borrow().get(key).cloned() + self.get(key).cloned() } - fn put_raw(&self, key: &[u8], value: &[u8]) { - self.borrow_mut().insert(key.to_vec(), value.to_vec()); + fn put_raw(&mut self, key: &[u8], value: &[u8]) { + self.insert(key.to_vec(), value.to_vec()); } } @@ -131,32 +131,32 @@ pub trait StorageDoubleMap fn get(k1: &K1, k2: &K2, storage: &S) -> Self::Query; /// Take the value under a key. - fn take(k1: &K1, k2: &K2, storage: &S) -> Self::Query; + fn take(k1: &K1, k2: &K2, storage: &mut S) -> Self::Query; /// Store a value to be associated with the given key from the map. - fn insert(k1: &K1, k2: &K2, val: &V, storage: &S) { + fn insert(k1: &K1, k2: &K2, val: &V, storage: &mut S) { storage.put(&Self::key_for(k1, k2), val); } /// Remove the value under a key. - fn remove(k1: &K1, k2: &K2, storage: &S) { + fn remove(k1: &K1, k2: &K2, storage: &mut S) { storage.kill(&Self::key_for(k1, k2)); } /// Removes all entries that shares the `k1` as the first key. - fn remove_prefix(k1: &K1, storage: &S) { + fn remove_prefix(k1: &K1, storage: &mut S) { storage.kill_prefix(&Self::prefix_for(k1)); } /// Mutate the value under a key. - fn mutate R, S: UnhashedStorage>(k1: &K1, k2: &K2, f: F, storage: &S) -> R; + fn mutate R, S: UnhashedStorage>(k1: &K1, k2: &K2, f: F, storage: &mut S) -> R; /// Append the given items to the value under the key specified. fn append( k1: &K1, k2: &K2, items: &[I], - storage: &S, + storage: &mut S, ) -> Result<(), &'static str> where I: codec::Encode, diff --git a/srml/support/src/traits.rs b/srml/support/src/traits.rs index a8db5a946e7b23a83d048b86ec6e930704edb0f0..3b3c63e223ce14831368094bf3b882a929c89f74 100644 --- a/srml/support/src/traits.rs +++ b/srml/support/src/traits.rs @@ -14,7 +14,9 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! Traits for SRML +//! Traits for SRML. +//! +//! NOTE: If you're looking for `parameter_types`, it has moved in to the top-level module. use crate::rstd::result; use crate::codec::{Codec, Encode, Decode}; @@ -22,42 +24,25 @@ use crate::runtime_primitives::traits::{ MaybeSerializeDebug, SimpleArithmetic }; -/// New trait for querying a single fixed value from a type. +use super::for_each_tuple; + +/// A trait for querying a single fixed value from a type. pub trait Get { /// Return a constant value. fn get() -> T; } -/// Macro for easily creating a new implementation of the `Get` trait. Use similarly to -/// how you would declare a `const`: -/// -/// ```no_compile -/// parameter_types! { -/// pub const Argument: u64 = 42; -/// } -/// trait Config { -/// type Parameter: Get; -/// } -/// struct Runtime; -/// impl Config for Runtime { -/// type Parameter = Argument; -/// } -/// ``` -#[macro_export] -macro_rules! parameter_types { - (pub const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => ( - pub struct $name; - parameter_types!{IMPL $name , $type , $value} - parameter_types!{ $( $rest )* } - ); - (const $name:ident: $type:ty = $value:expr; $( $rest:tt )*) => ( - struct $name; - parameter_types!{IMPL $name , $type , $value} - parameter_types!{ $( $rest )* } - ); - () => (); - (IMPL $name:ident , $type:ty , $value:expr) => { - impl $crate::traits::Get<$type> for $name { fn get() -> $type { $value } } +/// A trait for querying whether a type can be said to statically "contain" a value. Similar +/// in nature to `Get`, except it is designed to be lazy rather than active (you can't ask it to +/// enumerate all values that it contains) and work for multiple values rather than just one. +pub trait Contains { + /// Return `true` if this "contains" the given value `t`. + fn contains(t: &T) -> bool; +} + +impl> Contains for T { + fn contains(t: &V) -> bool { + &Self::get() == t } } @@ -67,20 +52,24 @@ pub trait OnFreeBalanceZero { fn on_free_balance_zero(who: &AccountId); } -impl OnFreeBalanceZero for () { - fn on_free_balance_zero(_who: &AccountId) {} -} -impl< - AccountId, - X: OnFreeBalanceZero, - Y: OnFreeBalanceZero, -> OnFreeBalanceZero for (X, Y) { - fn on_free_balance_zero(who: &AccountId) { - X::on_free_balance_zero(who); - Y::on_free_balance_zero(who); +macro_rules! impl_on_free_balance_zero { + () => ( + impl OnFreeBalanceZero for () { + fn on_free_balance_zero(_: &AccountId) {} + } + ); + + ( $($t:ident)* ) => { + impl),*> OnFreeBalanceZero for ($($t,)*) { + fn on_free_balance_zero(who: &AccountId) { + $($t::on_free_balance_zero(who);)* + } + } } } +for_each_tuple!(impl_on_free_balance_zero); + /// Trait for a hook to get called when some balance has been minted, causing dilution. pub trait OnDilution { /// Some `portion` of the total balance just "grew" by `minted`. `portion` is the pre-growth diff --git a/srml/support/src/unsigned.rs b/srml/support/src/unsigned.rs index dcdf4b2683787f84f9b5c094415bef9c90f80e43..8ea613461a1a83ddd25c421f03c276b7fe52da51 100644 --- a/srml/support/src/unsigned.rs +++ b/srml/support/src/unsigned.rs @@ -84,6 +84,7 @@ mod test_empty_call { pub enum Call { } + #[allow(unused)] pub struct Runtime; impl_outer_validate_unsigned! { diff --git a/srml/support/test/Cargo.toml b/srml/support/test/Cargo.toml index 29cc927ff7617569609a4fa1df4ea536fdd868b6..44a3b8d8841a20cdffbf6e7f62eef052574f2a47 100644 --- a/srml/support/test/Cargo.toml +++ b/srml/support/test/Cargo.toml @@ -4,13 +4,14 @@ version = "2.0.0" authors = ["Parity Technologies "] edition = "2018" -[dev-dependencies] +[dependencies] serde = { version = "1.0", default-features = false, features = ["derive"] } parity-codec = { version = "3.3", default-features = false, features = ["derive"] } runtime_io = { package = "sr-io", path = "../../../core/sr-io", default-features = false } -srml-support = { path = "../", default-features = false } +srml-support = { version = "2", path = "../", default-features = false } inherents = { package = "substrate-inherents", path = "../../../core/inherents", default-features = false } primitives = { package = "substrate-primitives", path = "../../../core/primitives", default-features = false } +trybuild = "1" [features] default = ["std"] diff --git a/srml/support/test/src/lib.rs b/srml/support/test/src/lib.rs index 7b23662e68db4dcb94b6c8e52c19710ad4a236f6..a7a869cf8794d7855697b6c7d3066c21b32533bb 100644 --- a/srml/support/test/src/lib.rs +++ b/srml/support/test/src/lib.rs @@ -16,3 +16,9 @@ //! Test crate for srml_support. Allow to make use of `srml_support::decl_storage`. //! See tests directory. + +#[test] +fn reserved_keyword() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/reserved_keyword/*.rs"); +} diff --git a/srml/support/test/tests/instance.rs b/srml/support/test/tests/instance.rs index 641ad9f4b56f475b922f13706c28f1910887dcb4..df9f648c18b14316e6202ec8d5835d25ddaea2fd 100644 --- a/srml/support/test/tests/instance.rs +++ b/srml/support/test/tests/instance.rs @@ -39,7 +39,8 @@ mod system { use super::*; pub trait Trait: 'static + Eq + Clone { - type Origin: Into>> + From>; + type Origin: Into, Self::Origin>> + + From>; type BlockNumber; type Digest: Digest; type Hash; @@ -100,12 +101,9 @@ mod system { } pub fn ensure_root(o: OuterOrigin) -> Result<(), &'static str> - where OuterOrigin: Into>> + where OuterOrigin: Into, OuterOrigin>> { - match o.into() { - Some(RawOrigin::Root) => Ok(()), - _ => Err("bad origin: expected to be a root origin"), - } + o.into().map(|_| ()).map_err(|_| "bad origin: expected to be a root origin") } } @@ -165,14 +163,17 @@ mod module1 { pub type Log = RawLog< T, I, + ::Hash, >; /// A logs in this module. #[cfg_attr(feature = "std", derive(serde::Serialize, Debug))] #[derive(parity_codec::Encode, parity_codec::Decode, PartialEq, Eq, Clone)] - pub enum RawLog { + pub enum RawLog { _Phantom(rstd::marker::PhantomData<(T, I)>), AmountChange(u32), + ChangesTrieRoot(Hash), + AuthoritiesChange(Vec<()>), } pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"12345678"; @@ -343,8 +344,8 @@ srml_support::construct_runtime!( UncheckedExtrinsic = UncheckedExtrinsic { System: system::{Module, Call, Event, Log(ChangesTrieRoot)}, - Module1_1: module1::::{Module, Call, Storage, Event, Config, Origin, Log(), Inherent}, - Module1_2: module1::::{Module, Call, Storage, Event, Config, Origin, Log(), Inherent}, + Module1_1: module1::::{Module, Call, Storage, Event, Config, Origin, Log(ChangesTrieRoot, AuthoritiesChange), Inherent}, + Module1_2: module1::::{Module, Call, Storage, Event, Config, Origin, Log(ChangesTrieRoot, AuthoritiesChange), Inherent}, Module2: module2::{Module, Call, Storage, Event, Config, Origin, Log(), Inherent}, Module2_1: module2::::{Module, Call, Storage, Event, Config, Origin, Log(), Inherent}, Module2_2: module2::::{Module, Call, Storage, Event, Config, Origin, Log(), Inherent}, diff --git a/srml/support/test/tests/reserved_keyword/on_initialize.rs b/srml/support/test/tests/reserved_keyword/on_initialize.rs new file mode 100644 index 0000000000000000000000000000000000000000..c63153241ce8f3ce052d9e355e36aa3d5f860818 --- /dev/null +++ b/srml/support/test/tests/reserved_keyword/on_initialize.rs @@ -0,0 +1,33 @@ +macro_rules! reserved { + ($($reserved:ident)*) => { + $( + mod $reserved { + pub use srml_support::dispatch::Result; + + pub trait Trait { + type Origin; + type BlockNumber: Into; + } + + pub mod system { + use srml_support::dispatch::Result; + + pub fn ensure_root(_: R) -> Result { + Ok(()) + } + } + + srml_support::decl_module! { + pub struct Module for enum Call where origin: T::Origin { + fn $reserved() -> Result { unreachable!() } + } + } + } + )* + } +} + +reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); + +fn main() { +} diff --git a/srml/support/test/tests/reserved_keyword/on_initialize.stderr b/srml/support/test/tests/reserved_keyword/on_initialize.stderr new file mode 100644 index 0000000000000000000000000000000000000000..7a37eb66c32acd89f96ef45fa3a88dd9724030c1 --- /dev/null +++ b/srml/support/test/tests/reserved_keyword/on_initialize.stderr @@ -0,0 +1,47 @@ +error: Invalid call fn name: `on_finalize`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. + --> $DIR/on_initialize.rs:30:1 + | +30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: Invalid call fn name: `on_initialize`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. + --> $DIR/on_initialize.rs:30:1 + | +30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: Invalid call fn name: `on_finalise`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. + --> $DIR/on_initialize.rs:30:1 + | +30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: Invalid call fn name: `on_initialise`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. + --> $DIR/on_initialize.rs:30:1 + | +30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: Invalid call fn name: `offchain_worker`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. + --> $DIR/on_initialize.rs:30:1 + | +30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) + +error: Invalid call fn name: `deposit_event`, name is reserved and doesn't match expected signature, please refer to `decl_module!` documentation to see the appropriate usage, or rename it to an unreserved keyword. + --> $DIR/on_initialize.rs:30:1 + | +30 | reserved!(on_finalize on_initialize on_finalise on_initialise offchain_worker deposit_event); + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ in this macro invocation + | + = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info) diff --git a/srml/system/src/lib.rs b/srml/system/src/lib.rs index b009785011fb6eb6cd7cf1a653842d0f1e2edfa4..b08321f86055f4206d90e3432ee45d135831edaa 100644 --- a/srml/system/src/lib.rs +++ b/srml/system/src/lib.rs @@ -77,7 +77,7 @@ use rstd::prelude::*; #[cfg(any(feature = "std", test))] use rstd::map; use primitives::traits::{self, CheckEqual, SimpleArithmetic, SimpleBitOps, One, Bounded, Lookup, - Hash, Member, MaybeDisplay, EnsureOrigin, Digest as DigestT, As, CurrentHeight, BlockNumberToHash, + Hash, Member, MaybeDisplay, EnsureOrigin, Digest as DigestT, CurrentHeight, BlockNumberToHash, MaybeSerializeDebugButNotDeserialize, MaybeSerializeDebug, StaticLookup }; #[cfg(any(feature = "std", test))] @@ -85,7 +85,7 @@ use primitives::traits::Zero; use substrate_primitives::storage::well_known_keys; use srml_support::{ storage, decl_module, decl_event, decl_storage, StorageDoubleMap, StorageValue, - StorageMap, Parameter, + StorageMap, Parameter, for_each_tuple, traits::Contains }; use safe_mix::TripletMix; use parity_codec::{Encode, Decode}; @@ -102,10 +102,24 @@ pub trait OnNewAccount { fn on_new_account(who: &AccountId); } -impl OnNewAccount for () { - fn on_new_account(_who: &AccountId) {} +macro_rules! impl_on_new_account { + () => ( + impl OnNewAccount for () { + fn on_new_account(_: &AccountId) {} + } + ); + + ( $($t:ident)* ) => { + impl),*> OnNewAccount for ($($t,)*) { + fn on_new_account(who: &AccountId) { + $($t::on_new_account(who);)* + } + } + } } +for_each_tuple!(impl_on_new_account); + /// Determiner to say whether a given account is unused. pub trait IsDeadAccount { /// Is the given account dead? @@ -131,7 +145,7 @@ pub fn extrinsics_data_root(xts: Vec>) -> H::Output { pub trait Trait: 'static + Eq + Clone { /// The aggregated `Origin` type used by dispatchable calls. - type Origin: Into>> + From>; + type Origin: Into, Self::Origin>> + From>; /// Account index (aka nonce) type. This stores the number of previous transactions associated with a sender /// account. @@ -311,7 +325,7 @@ decl_storage! { /// ring buffer with the `i8` prefix being the index into the `Vec` of the oldest hash. RandomMaterial get(random_material): (i8, Vec); /// The current block number being processed. Set by `execute_block`. - Number get(block_number) build(|_| T::BlockNumber::sa(1u64)): T::BlockNumber; + Number get(block_number) build(|_| 1.into()): T::BlockNumber; /// Hash of the previous block. ParentHash get(parent_hash) build(|_| hash69()): T::Hash; /// Extrinsics root of the current block, also part of the block header. @@ -362,40 +376,97 @@ decl_storage! { } pub struct EnsureRoot(::rstd::marker::PhantomData); -impl>>, AccountId> EnsureOrigin for EnsureRoot { +impl< + O: Into, O>> + From>, + AccountId, +> EnsureOrigin for EnsureRoot { + type Success = (); + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + RawOrigin::Root => Ok(()), + r => Err(O::from(r)), + }) + } +} + +pub struct EnsureSigned(::rstd::marker::PhantomData); +impl< + O: Into, O>> + From>, + AccountId, +> EnsureOrigin for EnsureSigned { + type Success = AccountId; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + RawOrigin::Signed(who) => Ok(who), + r => Err(O::from(r)), + }) + } +} + +pub struct EnsureSignedBy(::rstd::marker::PhantomData<(Who, AccountId)>); +impl< + O: Into, O>> + From>, + Who: Contains, + AccountId: PartialEq + Clone, +> EnsureOrigin for EnsureSignedBy { + type Success = AccountId; + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + RawOrigin::Signed(ref who) if Who::contains(who) => Ok(who.clone()), + r => Err(O::from(r)), + }) + } +} + +pub struct EnsureNone(::rstd::marker::PhantomData); +impl< + O: Into, O>> + From>, + AccountId, +> EnsureOrigin for EnsureNone { type Success = (); - fn ensure_origin(o: O) -> Result { - ensure_root(o) + fn try_origin(o: O) -> Result { + o.into().and_then(|o| match o { + RawOrigin::None => Ok(()), + r => Err(O::from(r)), + }) + } +} + +pub struct EnsureNever(::rstd::marker::PhantomData); +impl EnsureOrigin for EnsureNever { + type Success = T; + fn try_origin(o: O) -> Result { + Err(o) } } /// Ensure that the origin `o` represents a signed extrinsic (i.e. transaction). /// Returns `Ok` with the account that signed the extrinsic or an `Err` otherwise. pub fn ensure_signed(o: OuterOrigin) -> Result - where OuterOrigin: Into>> + where OuterOrigin: Into, OuterOrigin>> { match o.into() { - Some(RawOrigin::Signed(t)) => Ok(t), + Ok(RawOrigin::Signed(t)) => Ok(t), _ => Err("bad origin: expected to be a signed origin"), } } /// Ensure that the origin `o` represents the root. Returns `Ok` or an `Err` otherwise. pub fn ensure_root(o: OuterOrigin) -> Result<(), &'static str> - where OuterOrigin: Into>> + where OuterOrigin: Into, OuterOrigin>> { match o.into() { - Some(RawOrigin::Root) => Ok(()), + Ok(RawOrigin::Root) => Ok(()), _ => Err("bad origin: expected to be a root origin"), } } /// Ensure that the origin `o` represents an unsigned extrinsic. Returns `Ok` or an `Err` otherwise. pub fn ensure_none(o: OuterOrigin) -> Result<(), &'static str> - where OuterOrigin: Into>> + where OuterOrigin: Into, OuterOrigin>> { match o.into() { - Some(RawOrigin::None) => Ok(()), + Ok(RawOrigin::None) => Ok(()), _ => Err("bad origin: expected to be no origin"), } } @@ -465,10 +536,16 @@ impl Module { } /// Start the execution of a particular block. - pub fn initialize(number: &T::BlockNumber, parent_hash: &T::Hash, txs_root: &T::Hash) { + pub fn initialize( + number: &T::BlockNumber, + parent_hash: &T::Hash, + txs_root: &T::Hash, + digest: &T::Digest, + ) { // populate environment storage::unhashed::put(well_known_keys::EXTRINSIC_INDEX, &0u32); >::put(number); + >::put(digest); >::put(parent_hash); >::insert(*number - One::one(), parent_hash); >::put(txs_root); @@ -493,7 +570,7 @@ impl Module { let mut digest = >::take(); let extrinsics_root = >::take(); let storage_root = T::Hashing::storage_root(); - let storage_changes_root = T::Hashing::storage_changes_root(parent_hash, number.as_() - 1); + let storage_changes_root = T::Hashing::storage_changes_root(parent_hash); // we can't compute changes trie root earlier && put it to the Digest // because it will include all currently existing temporaries. @@ -553,38 +630,51 @@ impl Module { /// Get the basic random seed. /// - /// In general you won't want to use this, but rather `Self::random` which allows you to give a subject for the - /// random result and whose value will be independently low-influence random from any other such seeds. + /// In general you won't want to use this, but rather `Self::random` which + /// allows you to give a subject for the random result and whose value will + /// be independently low-influence random from any other such seeds. pub fn random_seed() -> T::Hash { Self::random(&[][..]) } /// Get a low-influence "random" value. /// - /// Being a deterministic block chain, real randomness is difficult to come by. This gives you something that - /// approximates it. `subject` is a context identifier and allows you to get a different result to other callers - /// of this function; use it like `random(&b"my context"[..])`. + /// Being a deterministic block chain, real randomness is difficult to come + /// by. This gives you something that approximates it. `subject` is a + /// context identifier and allows you to get a different result to other + /// callers of this function; use it like `random(&b"my context"[..])`. /// - /// This is initially implemented through a low-influence "triplet mix" convolution of previous block hash values. - /// In the future it will be generated from a secure "VRF". + /// This is initially implemented through a low-influence "triplet mix" + /// convolution of previous block hash values. In the future it will be + /// generated from a secure verifiable random function (VRF). /// /// ### Security Notes - /// This randomness uses a low-influence function, drawing upon the block hashes from the previous 81 blocks. Its - /// result for any given subject will be known in advance by the block producer of this block (and, indeed, anyone - /// who knows the block's `parent_hash`). However, it is mostly impossible for the producer of this block *alone* - /// to influence the value of this hash. A sizable minority of dishonest and coordinating block producers would be - /// required in order to affect this value. If that is an insufficient security guarantee then two things can be - /// used to improve this randomness: - /// - Name, in advance, the block number whose random value will be used; ensure your module retains a buffer of - /// previous random values for its subject and then index into these in order to obviate the ability of your user - /// to look up the parent hash and choose when to transact based upon it. - /// - Require your user to first commit to an additional value by first posting its hash. Require them to reveal - /// the value to determine the final result, hashing it with the output of this random function. This reduces the - /// ability of a cabal of block producers from conspiring against individuals. /// - /// WARNING: Hashing the result of this function will remove any low-infleunce properties it has and mean that - /// all bits of the resulting value are entirely manipulatable by the author of the parent block, who can determine - /// the value of `parent_hash`. + /// This randomness uses a low-influence function, drawing upon the block + /// hashes from the previous 81 blocks. Its result for any given subject + /// will be known in advance by the block producer of this block (and, + /// indeed, anyone who knows the block's `parent_hash`). However, it is + /// mostly impossible for the producer of this block *alone* to influence + /// the value of this hash. A sizable minority of dishonest and coordinating + /// block producers would be required in order to affect this value. If that + /// is an insufficient security guarantee then two things can be used to + /// improve this randomness: + /// + /// - Name, in advance, the block number whose random value will be used; + /// ensure your module retains a buffer of previous random values for its + /// subject and then index into these in order to obviate the ability of + /// your user to look up the parent hash and choose when to transact based + /// upon it. + /// - Require your user to first commit to an additional value by first + /// posting its hash. Require them to reveal the value to determine the + /// final result, hashing it with the output of this random function. This + /// reduces the ability of a cabal of block producers from conspiring + /// against individuals. + /// + /// WARNING: Hashing the result of this function will remove any + /// low-influnce properties it has and mean that all bits of the resulting + /// value are entirely manipulatable by the author of the parent block, who + /// can determine the value of `parent_hash`. pub fn random(subject: &[u8]) -> T::Hash { let (index, hash_series) = >::get(); if hash_series.len() > 0 { @@ -606,8 +696,9 @@ impl Module { >::insert(who, Self::account_nonce(who) + T::Index::one()); } - /// Note what the extrinsic data of the current extrinsic index is. If this is called, then - /// ensure `derive_extrinsics` is also called before block-building is completed. + /// Note what the extrinsic data of the current extrinsic index is. If this + /// is called, then ensure `derive_extrinsics` is also called before + /// block-building is completed. /// /// NOTE: This function is called only when the block is being constructed locally. /// `execute_block` doesn't note any extrinsics. @@ -719,10 +810,17 @@ mod tests { GenesisConfig::::default().build_storage().unwrap().0.into() } + #[test] + fn origin_works() { + let o = Origin::from(RawOrigin::::Signed(1u64)); + let x: Result, Origin> = o.into(); + assert_eq!(x, Ok(RawOrigin::::Signed(1u64))); + } + #[test] fn deposit_event_should_work() { with_externalities(&mut new_test_ext(), || { - System::initialize(&1, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&1, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); System::note_finished_extrinsics(); System::deposit_event(1u16); System::finalize(); @@ -737,7 +835,7 @@ mod tests { ] ); - System::initialize(&2, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&2, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); System::deposit_event(42u16); System::note_applied_extrinsic(&Ok(()), 0); System::note_applied_extrinsic(&Err(""), 0); @@ -758,7 +856,7 @@ mod tests { with_externalities(&mut new_test_ext(), || { const BLOCK_NUMBER: u64 = 1; - System::initialize(&BLOCK_NUMBER, &[0u8; 32].into(), &[0u8; 32].into()); + System::initialize(&BLOCK_NUMBER, &[0u8; 32].into(), &[0u8; 32].into(), &Default::default()); System::note_finished_extrinsics(); let topics = vec![ diff --git a/srml/timestamp/src/lib.rs b/srml/timestamp/src/lib.rs index bc998a8539653c1db224b5c20d656b46267b269d..24750215d1c04ebbb858ddd926bf38247ab81857 100644 --- a/srml/timestamp/src/lib.rs +++ b/srml/timestamp/src/lib.rs @@ -87,6 +87,7 @@ #![cfg_attr(not(feature = "std"), no_std)] +use rstd::{result, ops::{Mul, Div}, cmp}; use parity_codec::Encode; #[cfg(feature = "std")] use parity_codec::Decode; @@ -94,9 +95,8 @@ use parity_codec::Decode; use inherents::ProvideInherentData; use srml_support::{StorageValue, Parameter, decl_storage, decl_module}; use srml_support::for_each_tuple; -use runtime_primitives::traits::{As, SimpleArithmetic, Zero}; +use runtime_primitives::traits::{SimpleArithmetic, Zero, SaturatedConversion}; use system::ensure_none; -use rstd::{result, ops::{Mul, Div}, cmp}; use inherents::{RuntimeString, InherentIdentifier, ProvideInherent, IsFatalError, InherentData}; /// The identifier for the `timestamp` inherent. @@ -252,7 +252,7 @@ decl_module! { decl_storage! { trait Store for Module as Timestamp { /// Current time for the current block. - pub Now get(now) build(|_| T::Moment::sa(0)): T::Moment; + pub Now get(now) build(|_| 0.into()): T::Moment; /// Old storage item provided for compatibility. Remove after all networks upgraded. // TODO: #2133 @@ -262,7 +262,7 @@ decl_storage! { /// that the block production apparatus provides. Your chosen consensus system will generally /// work with this to determine a sensible block time. e.g. For Aura, it will be double this /// period on default settings. - pub MinimumPeriod get(minimum_period) config(): T::Moment = T::Moment::sa(3); + pub MinimumPeriod get(minimum_period) config(): T::Moment = 3.into(); /// Did the timestamp get updated in this block? DidUpdate: bool; @@ -297,23 +297,25 @@ impl ProvideInherent for Module { const INHERENT_IDENTIFIER: InherentIdentifier = INHERENT_IDENTIFIER; fn create_inherent(data: &InherentData) -> Option { - let data = extract_inherent_data(data).expect("Gets and decodes timestamp inherent data"); + let data: T::Moment = extract_inherent_data(data) + .expect("Gets and decodes timestamp inherent data") + .saturated_into(); - let next_time = cmp::max(As::sa(data), Self::now() + >::get()); + let next_time = cmp::max(data, Self::now() + >::get()); Some(Call::set(next_time.into())) } fn check_inherent(call: &Self::Call, data: &InherentData) -> result::Result<(), Self::Error> { const MAX_TIMESTAMP_DRIFT: u64 = 60; - let t = match call { - Call::set(ref t) => t.clone(), + let t: u64 = match call { + Call::set(ref t) => t.clone().saturated_into::(), _ => return Ok(()), - }.as_(); + }; let data = extract_inherent_data(data).map_err(|e| InherentError::Other(e))?; - let minimum = (Self::now() + >::get()).as_(); + let minimum = (Self::now() + >::get()).saturated_into::(); if t > data + MAX_TIMESTAMP_DRIFT { Err(InherentError::Other("Timestamp too far in future to accept".into())) } else if t < minimum { diff --git a/srml/treasury/src/lib.rs b/srml/treasury/src/lib.rs index 39253ac4d9b6e4dca30e1edc0ef52901f5d4f73b..cd9e781f666f8b4b211af0ee7da3d6ccab7e7894 100644 --- a/srml/treasury/src/lib.rs +++ b/srml/treasury/src/lib.rs @@ -15,47 +15,55 @@ // along with Substrate. If not, see . //! # Treasury Module -//! -//! The `treasury` module keeps account of currency in a `pot` and manages the subsequent -//! deployment of these funds. -//! +//! +//! The Treasury module provides a "pot" of funds that can be managed by stakeholders in the +//! system and a structure for making spending proposals from this pot. +//! +//! - [`treasury::Trait`](./trait.Trait.html) +//! - [`Call`](./enum.Call.html) +//! //! ## Overview -//! -//! Funds for treasury are raised in two ways: -//! 1. By minting new tokens, leading to inflation, and -//! 2. By channeling tokens from transaction fees and slashing. -//! -//! Treasury funds can be used to pay for developers who provide software updates, -//! any changes decided by referenda, and to generally keep the system running smoothly. -//! -//! Treasury can be used with other modules, such as to tax validator rewards in the `staking` module. -//! -//! ### Implementations -//! +//! +//! The Treasury Module itself provides the pot to store funds, and a means for stakeholders to +//! propose, approve, and deny expendatures. The chain will need to provide a method (e.g. +//! inflation, fees) for collecting funds. +//! +//! By way of example, the Council could vote to fund the Treasury with a portion of the block +//! reward and use the funds to pay developers. +//! +//! ### Terminology +//! +//! - **Proposal:** A suggestion to allocate funds from the pot to a beneficiary. +//! - **Beneficiary:** An account who will receive the funds from a proposal iff +//! the proposal is approved. +//! - **Deposit:** Funds that a proposer must lock when making a proposal. The +//! deposit will be returned or slashed if the proposal is approved or rejected +//! respectively. +//! - **Pot:** Unspent funds accumulated by the treasury module. +//! +//! ### Implementations +//! //! The treasury module provides an implementation for the following trait: -//! - `OnDilution` - Mint extra funds upon dilution; maintain the ratio of `portion` diluted to `total_issuance`. -//! +//! +//! - `OnDilution` - When new funds are minted to reward the deployment of other existing funds, +//! a corresponding amount of tokens are minted into the treasury so that the tokens being rewarded +//! do not represent a higher portion of total supply. For example, in the default substrate node, +//! when validators are rewarded new tokens for staking, they do not hold a higher portion of total +//! tokens. Rather, tokens are added to the treasury to keep the portion of tokens staked constant. +//! //! ## Interface -//! +//! //! ### Dispatchable Functions -//! -//! - `propose_spend` - Propose a spending proposal and stake a proposal deposit. +//! +//! - `propose_spend` - Make a spending proposal and stake the required deposit. //! - `set_pot` - Set the spendable balance of funds. //! - `configure` - Configure the module's proposal requirements. -//! - `reject_proposal` - Reject a proposal and slash the deposit. -//! - `approve_proposal` - Accept the proposal and return the deposit. -//! -//! Please refer to the [`Call`](./enum.Call.html) enum and its associated variants for documentation on each function. -//! -//! ### Public Functions -//! -//! See the [module](./struct.Module.html) for details on publicly available functions. -//! -//! ## Related Modules -//! -//! The treasury module depends on the `system` and `srml_support` modules as well as -//! Substrate Core libraries and the Rust standard library. -//! +//! - `reject_proposal` - Reject a proposal, slashing the deposit. +//! - `approve_proposal` - Accept the proposal, returning the deposit. +//! +//! ## GenesisConfig +//! +//! The Treasury module depends on the [`GenesisConfig`](./struct.GenesisConfig.html). #![cfg_attr(not(feature = "std"), no_std)] @@ -183,8 +191,8 @@ decl_storage! { trait Store for Module as Treasury { // Config... - /// Proportion of funds that should be bonded in order to place a proposal. An accepted - /// proposal gets these back. A rejected proposal doesn't. + /// Fraction of a proposal's value that should be bonded in order to place the proposal. + /// An accepted proposal gets these back. A rejected proposal does not. ProposalBond get(proposal_bond) config(): Permill; /// Minimum amount of funds that should be placed in a deposit for making a proposal. diff --git a/subkey/src/vanity.rs b/subkey/src/vanity.rs index 400b3bae82a385d25400eb5f98e5b2c5e138c2b3..2399197e99576a09ea385673ef9353eeac232637 100644 --- a/subkey/src/vanity.rs +++ b/subkey/src/vanity.rs @@ -19,9 +19,9 @@ use super::Crypto; fn good_waypoint(done: u64) -> u64 { match done { - 0 ... 1_000_000 => 100_000, - 0 ... 10_000_000 => 1_000_000, - 0 ... 100_000_000 => 10_000_000, + 0 ..= 1_000_000 => 100_000, + 0 ..= 10_000_000 => 1_000_000, + 0 ..= 100_000_000 => 10_000_000, _ => 100_000_000, } } diff --git a/test-utils/transaction-factory/Cargo.toml b/test-utils/transaction-factory/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..66faaf6b345820bff589b319255de8a177e89813 --- /dev/null +++ b/test-utils/transaction-factory/Cargo.toml @@ -0,0 +1,22 @@ +[package] +name = "transaction-factory" +version = "0.0.1" +authors = ["Parity Technologies "] +edition = "2018" + +[dependencies] +cli = { package = "substrate-cli", path = "../../core/cli" } +client = { package = "substrate-client", path = "../../core/client" } +consensus_common = { package = "substrate-consensus-common", path = "../../core/consensus/common" } +log = "0.4" +parity-codec = { version = "3.3", default-features = false, features = ["derive"] } +primitives = { package = "substrate-primitives", path = "../../core/primitives", default-features = false } +sr_primitives = { package = "sr-primitives", path = "../../core/sr-primitives", default-features = false } +substrate-service = { path = "../../core/service" } + +[features] +default = ["std"] +std = [ + "parity-codec/std", + "primitives/std", +] diff --git a/test-utils/transaction-factory/src/complex_mode.rs b/test-utils/transaction-factory/src/complex_mode.rs new file mode 100644 index 0000000000000000000000000000000000000000..6200affaeadb704571a7f71b340accd12999112b --- /dev/null +++ b/test-utils/transaction-factory/src/complex_mode.rs @@ -0,0 +1,156 @@ +// 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 . + +/// This module implements the `MasterToNToM` mode: +/// +/// Manufacture `num` transactions from the master account to `num` +/// randomly created accounts. From each of these randomly created +/// accounts manufacture a transaction to another randomly created +/// account. +/// Repeat this round `rounds` times. If `rounds` = 1 the behavior +/// is the same as `MasterToN`. +/// +/// A -> B +/// A -> C +/// A -> D +/// ... x `num` +/// +/// B -> E +/// C -> F +/// D -> G +/// ... +/// E -> H +/// F -> I +/// G -> J +/// ... +/// ... x `rounds` + +use std::sync::Arc; + +use log::info; +use client::block_builder::api::BlockBuilder; +use client::runtime_api::ConstructRuntimeApi; +use sr_primitives::generic::BlockId; +use sr_primitives::traits::{Block as BlockT, ProvideRuntimeApi, One, Zero}; +use substrate_service::{ + FactoryBlock, FullClient, ServiceFactory, ComponentClient, FullComponents +}; + +use crate::{RuntimeAdapter, create_block}; + +pub fn next( + factory_state: &mut RA, + client: &Arc>>, + prior_block_hash: ::Hash, + prior_block_id: BlockId, +) -> Option<::Block> +where + F: ServiceFactory, + F::RuntimeApi: ConstructRuntimeApi, FullClient>, + FullClient: ProvideRuntimeApi, + as ProvideRuntimeApi>::Api: BlockBuilder>, + RA: RuntimeAdapter, +{ + let total = factory_state.start_number() + factory_state.num() * factory_state.rounds(); + + if factory_state.block_no() >= total || factory_state.round() >= factory_state.rounds() { + return None; + } + + info!( + "Round {}: Creating {} transactions in total, {} per round. {} rounds in total.", + factory_state.round() + RA::Number::one(), + factory_state.num() * factory_state.rounds(), + factory_state.num(), + factory_state.rounds(), + ); + + let from = from::(factory_state); + + let seed = factory_state.start_number() + factory_state.block_no(); + let to = RA::gen_random_account_id(&seed); + + let mut amount; + if factory_state.round() == RA::Number::zero() { + amount = RA::minimum_balance() * factory_state.rounds(); + } else { + let rounds_left = factory_state.rounds() - factory_state.round(); + amount = RA::minimum_balance() * rounds_left; + }; + + let transfer = factory_state.transfer_extrinsic( + &from.0, + &from.1, + &to, + &amount, + &prior_block_hash, + ); + + let inherents = factory_state.inherent_extrinsics(); + let inherents = client.runtime_api().inherent_extrinsics(&prior_block_id, inherents) + .expect("Failed to create inherent extrinsics"); + + let block = create_block::(&client, transfer, inherents); + info!( + "Created block {} with hash {}. Transferring {} from {} to {}.", + factory_state.block_no() + RA::Number::one(), + prior_block_hash, + amount, + from.0, + to + ); + + factory_state.set_block_no(factory_state.block_no() + RA::Number::one()); + + let new_round = factory_state.block_no() > RA::Number::zero() + && factory_state.block_no() % factory_state.num() == RA::Number::zero(); + if new_round { + factory_state.set_round(factory_state.round() + RA::Number::one()); + factory_state.set_block_in_round(RA::Number::zero()); + } else { + factory_state.set_block_in_round(factory_state.block_in_round() + RA::Number::one()); + } + + Some(block) +} + +/// Return the account which received tokens at this point in the previous round. +fn from( + factory_state: &mut RA +) -> (::AccountId, ::Secret) +where RA: RuntimeAdapter +{ + let is_first_round = factory_state.round() == RA::Number::zero(); + match is_first_round { + true => { + // first round always uses master account + (RA::master_account_id(), RA::master_account_secret()) + }, + _ => { + // the account to which was sent in the last round + let is_round_one = factory_state.round() == RA::Number::one(); + let seed = match is_round_one { + true => factory_state.start_number() + factory_state.block_in_round(), + _ => { + let block_no_in_prior_round = + factory_state.num() * (factory_state.round() - RA::Number::one()) + factory_state.block_in_round(); + factory_state.start_number() + block_no_in_prior_round + } + }; + (RA::gen_random_account_id(&seed), RA::gen_random_account_secret(&seed)) + }, + } +} diff --git a/test-utils/transaction-factory/src/lib.rs b/test-utils/transaction-factory/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..8f292f3a02a2e48b6106e2ae8da8ea55d12ec68d --- /dev/null +++ b/test-utils/transaction-factory/src/lib.rs @@ -0,0 +1,180 @@ +// 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 . + +//! Simple transaction factory which distributes tokens from a master +//! account to a specified number of newly created accounts. +//! +//! The factory currently only works on an empty database! + +use std::collections::HashMap; +use std::sync::Arc; +use std::ops::Mul; +use std::cmp::PartialOrd; +use std::fmt::Display; + +use log::info; + +use client::block_builder::api::BlockBuilder; +use client::runtime_api::ConstructRuntimeApi; +use consensus_common::{ + BlockOrigin, ImportBlock, InherentData, ForkChoiceStrategy, + SelectChain +}; +use consensus_common::block_import::BlockImport; +use parity_codec::{Decode, Encode}; +use sr_primitives::generic::BlockId; +use sr_primitives::traits::{ + Block as BlockT, Header as HeaderT, ProvideRuntimeApi, SimpleArithmetic, + One, Zero, +}; +use substrate_service::{ + FactoryBlock, FactoryFullConfiguration, FullClient, new_client, + ServiceFactory, ComponentClient, FullComponents}; +pub use crate::modes::Mode; + +pub mod modes; +mod complex_mode; +mod simple_modes; + +pub trait RuntimeAdapter { + type AccountId: Display; + type Balance: Display + Mul; + type Block: BlockT; + type Index: Copy; + type Number: Display + PartialOrd + SimpleArithmetic + Zero + One; + type Phase: Copy; + type Secret; + + fn new(mode: Mode, rounds: u64, start_number: u64) -> Self; + + fn block_no(&self) -> Self::Number; + fn block_in_round(&self) -> Self::Number; + fn mode(&self) -> &Mode; + fn num(&self) -> Self::Number; + fn rounds(&self) -> Self::Number; + fn round(&self) -> Self::Number; + fn start_number(&self) -> Self::Number; + + fn set_block_in_round(&mut self, val: Self::Number); + fn set_block_no(&mut self, val: Self::Number); + fn set_round(&mut self, val: Self::Number); + + fn transfer_extrinsic( + &self, + sender: &Self::AccountId, + key: &Self::Secret, + destination: &Self::AccountId, + amount: &Self::Number, + prior_block_hash: &::Hash, + ) -> ::Extrinsic; + + fn inherent_extrinsics(&self) -> InherentData; + + fn minimum_balance() -> Self::Number; + fn master_account_id() -> Self::AccountId; + fn master_account_secret() -> Self::Secret; + fn extract_index(&self, account_id: &Self::AccountId, block_hash: &::Hash) -> Self::Index; + fn extract_phase(&self, block_hash: ::Hash) -> Self::Phase; + fn gen_random_account_id(seed: &Self::Number) -> Self::AccountId; + fn gen_random_account_secret(seed: &Self::Number) -> Self::Secret; +} + +/// Manufactures transactions. The exact amount depends on +/// `mode`, `num` and `rounds`. +pub fn factory( + mut factory_state: RA, + mut config: FactoryFullConfiguration, +) -> cli::error::Result<()> +where + F: ServiceFactory, + F::RuntimeApi: ConstructRuntimeApi, FullClient>, + FullClient: ProvideRuntimeApi, + as ProvideRuntimeApi>::Api: BlockBuilder>, + RA: RuntimeAdapter, + <::Block as BlockT>::Hash: From, +{ + if *factory_state.mode() != Mode::MasterToNToM && factory_state.rounds() > RA::Number::one() { + let msg = "The factory can only be used with rounds set to 1 in this mode.".into(); + return Err(cli::error::Error::Input(msg)); + } + + let client = new_client::(&config)?; + + let select_chain = F::build_select_chain(&mut config, client.clone())?; + + let best_header: Result<::Header, cli::error::Error> = + select_chain.best_chain().map_err(|e| format!("{:?}", e).into()); + let mut best_hash = best_header?.hash(); + let best_block_id = BlockId::::hash(best_hash); + + while let Some(block) = match factory_state.mode() { + Mode::MasterToNToM => + complex_mode::next::(&mut factory_state, &client, best_hash.into(), best_block_id), + _ => + simple_modes::next::(&mut factory_state, &client, best_hash.into(), best_block_id) + } { + best_hash = block.header().hash(); + import_block::(&client, block); + + info!("Imported block at {}", factory_state.block_no()); + } + + Ok(()) +} + +/// Create a baked block from a transfer extrinsic and timestamp inherent. +pub fn create_block( + client: &Arc>>, + transfer: ::Extrinsic, + inherent_extrinsics: Vec<::Extrinsic>, +) -> ::Block +where + F: ServiceFactory, + FullClient: ProvideRuntimeApi, + F::RuntimeApi: ConstructRuntimeApi, FullClient>, + as ProvideRuntimeApi>::Api: BlockBuilder>, + RA: RuntimeAdapter, +{ + let mut block = client.new_block(Default::default()).expect("Failed to create new block"); + block.push( + Decode::decode(&mut &transfer.encode()[..]) + .expect("Failed to decode transfer extrinsic") + ).expect("Failed to push transfer extrinsic into block"); + + for inherent in inherent_extrinsics { + block.push(inherent).expect("Failed ..."); + } + + block.bake().expect("Failed to bake block") +} + +fn import_block( + client: &Arc>>, + block: ::Block +) -> () where F: ServiceFactory +{ + let import = ImportBlock { + origin: BlockOrigin::File, + header: block.header().clone(), + post_digests: Vec::new(), + body: Some(block.extrinsics().to_vec()), + finalized: false, + justification: None, + auxiliary: Vec::new(), + fork_choice: ForkChoiceStrategy::LongestChain, + }; + client.import_block(import, HashMap::new()).expect("Failed to import block"); +} diff --git a/test-utils/transaction-factory/src/modes.rs b/test-utils/transaction-factory/src/modes.rs new file mode 100644 index 0000000000000000000000000000000000000000..a212d6aed8c3193d526b6a741536104540f1ea18 --- /dev/null +++ b/test-utils/transaction-factory/src/modes.rs @@ -0,0 +1,40 @@ +// 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 . + +//! The transaction factory can operate in different modes. See +//! the `simple_mode` and `complex_mode` modules for details. + +use std::str::FromStr; + +/// Token distribution modes. +#[derive(Debug, Clone, PartialEq)] +pub enum Mode { + MasterToN, + MasterTo1, + MasterToNToM +} + +impl FromStr for Mode { + type Err = String; + fn from_str(mode: &str) -> Result { + match mode { + "MasterToN" => Ok(Mode::MasterToN), + "MasterTo1" => Ok(Mode::MasterTo1), + "MasterToNToM" => Ok(Mode::MasterToNToM), + _ => Err(format!("Invalid mode: {}", mode)), + } + } +} diff --git a/test-utils/transaction-factory/src/simple_modes.rs b/test-utils/transaction-factory/src/simple_modes.rs new file mode 100644 index 0000000000000000000000000000000000000000..4ce7b47e6fc52d2c887964d35150c09dd0fe267b --- /dev/null +++ b/test-utils/transaction-factory/src/simple_modes.rs @@ -0,0 +1,106 @@ +// 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 . + +/// This module implements two manufacturing modes: +/// +/// # MasterToN +/// Manufacture `num` transactions from the master account +/// to `num` randomly created accounts, one each. +/// +/// A -> B +/// A -> C +/// ... x `num` +/// +/// +/// # MasterTo1 +/// Manufacture `num` transactions from the master account +/// to exactly one other randomly created account. +/// +/// A -> B +/// A -> B +/// ... x `num` + +use std::sync::Arc; + +use log::info; +use client::block_builder::api::BlockBuilder; +use client::runtime_api::ConstructRuntimeApi; +use sr_primitives::traits::{Block as BlockT, ProvideRuntimeApi, One}; +use sr_primitives::generic::BlockId; +use substrate_service::{ + FactoryBlock, FullClient, ServiceFactory, ComponentClient, FullComponents +}; + +use crate::{Mode, RuntimeAdapter, create_block}; + +pub fn next( + factory_state: &mut RA, + client: &Arc>>, + prior_block_hash: ::Hash, + prior_block_id: BlockId, +) -> Option<::Block> +where + F: ServiceFactory, + F::RuntimeApi: ConstructRuntimeApi, FullClient>, + FullClient: ProvideRuntimeApi, + as ProvideRuntimeApi>::Api: BlockBuilder>, + RA: RuntimeAdapter, +{ + if factory_state.block_no() >= factory_state.num() { + return None; + } + + let from = (RA::master_account_id(), RA::master_account_secret()); + + let seed = match factory_state.mode() { + // choose the same receiver for all transactions + Mode::MasterTo1 => factory_state.start_number(), + + // different receiver for each transaction + Mode::MasterToN => factory_state.start_number() + factory_state.block_no(), + _ => unreachable!("Mode not covered!"), + }; + let to = RA::gen_random_account_id(&seed); + + let amount = RA::minimum_balance(); + + let transfer = factory_state.transfer_extrinsic( + &from.0, + &from.1, + &to, + &amount, + &prior_block_hash, + ); + + let inherents = RA::inherent_extrinsics(&factory_state); + let inherents = client.runtime_api().inherent_extrinsics(&prior_block_id, inherents) + .expect("Failed to create inherent extrinsics"); + + let block = create_block::(&client, transfer, inherents); + + factory_state.set_block_no(factory_state.block_no() + RA::Number::one()); + + info!( + "Created block {} with hash {}. Transferring {} from {} to {}.", + factory_state.block_no(), + prior_block_hash, + amount, + from.0, + to + ); + + Some(block) +}