From e41ca0fdec9885476b0bd909ddf831566f0743e2 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 12 Dec 2018 15:20:11 +0800 Subject: [PATCH 01/45] doc: add link to CHANGELOG in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index f89912de10..d355be000d 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ Nervos CKB is released under the terms of the MIT license. See [COPYING](COPYING This project is still in development, and it's NOT in production-ready status. The wiki also lists some [known issues](https://github.com/nervosnetwork/ckb/wiki/Known-Issues) that we are currently working on. -The `master` branch is regularly built and tested, however, it is not guaranteed to be completely stable; The `develop` branch is the work branch to merge new features, and it's not stable. +The `master` branch is regularly built and tested, however, it is not guaranteed to be completely stable; The `develop` branch is the work branch to merge new features, and it's not stable. The CHANGELOG is available in [Releases](https://github.com/nervosnetwork/ckb/releases) and [CHANGELOG.md](https://github.com/nervosnetwork/ckb/blob/master/CHANGELOG.md) in the `master` branch. The contribution workflow is described in [CONTRIBUTING.md](CONTRIBUTING.md), and security policy is described in [SECURITY.md](SECURITY.md). To propose new protocol or standard for Nervos, see [Nervos RFC](https://github.com/nervosnetwork/rfcs). From d5f8a177aa90cd0d8bae18c8c1100bbe2736bf96 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 12 Dec 2018 15:35:07 +0800 Subject: [PATCH 02/45] chore: Bump to v0.3.0-pre --- Cargo.toml | 2 +- benches/Cargo.toml | 2 +- chain/Cargo.toml | 2 +- core/Cargo.toml | 2 +- db/Cargo.toml | 2 +- miner/Cargo.toml | 2 +- network/Cargo.toml | 2 +- notify/Cargo.toml | 2 +- pool/Cargo.toml | 2 +- pow/Cargo.toml | 2 +- protocol/Cargo.toml | 2 +- rpc/Cargo.toml | 2 +- script/Cargo.toml | 2 +- shared/Cargo.toml | 2 +- spec/Cargo.toml | 2 +- sync/Cargo.toml | 2 +- util/Cargo.toml | 2 +- util/avl/Cargo.toml | 2 +- util/build-info/Cargo.toml | 2 +- util/crypto/Cargo.toml | 2 +- util/dir/Cargo.toml | 2 +- util/hash/Cargo.toml | 2 +- util/instrument/Cargo.toml | 2 +- util/logger/Cargo.toml | 2 +- util/merkle-root/Cargo.toml | 2 +- util/time/Cargo.toml | 2 +- verification/Cargo.toml | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index e55f9ba794..ede19cf1cb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/benches/Cargo.toml b/benches/Cargo.toml index 03c7ab8e31..c86ce0bfd8 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-benches" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/chain/Cargo.toml b/chain/Cargo.toml index 3c6b90deac..77328fdeee 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-chain" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/core/Cargo.toml b/core/Cargo.toml index f5ebdc194c..40008755e3 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-core" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/db/Cargo.toml b/db/Cargo.toml index c19988b658..6e4e6101ae 100644 --- a/db/Cargo.toml +++ b/db/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-db" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/miner/Cargo.toml b/miner/Cargo.toml index f7e51dd5f4..98e1945909 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-miner" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/network/Cargo.toml b/network/Cargo.toml index 6bef3d445e..0b541cb359 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-network" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/notify/Cargo.toml b/notify/Cargo.toml index 5fce9f17c6..027ad5c459 100644 --- a/notify/Cargo.toml +++ b/notify/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-notify" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/pool/Cargo.toml b/pool/Cargo.toml index 96e6f49cd9..921a59167f 100644 --- a/pool/Cargo.toml +++ b/pool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-pool" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/pow/Cargo.toml b/pow/Cargo.toml index 9085aa2176..72c21da3c3 100644 --- a/pow/Cargo.toml +++ b/pow/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-pow" -version = "0.1.0" +version = "0.3.0-pre" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/protocol/Cargo.toml b/protocol/Cargo.toml index fbb2911a31..f0a283c988 100644 --- a/protocol/Cargo.toml +++ b/protocol/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-protocol" -version = "0.1.0" +version = "0.3.0-pre" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index f031f0933d..e961a12b85 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-rpc" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] diff --git a/script/Cargo.toml b/script/Cargo.toml index ae31635bef..4439aae9f7 100644 --- a/script/Cargo.toml +++ b/script/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-script" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 1e3967369f..243ef4d79a 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-shared" -version = "0.1.0" +version = "0.3.0-pre" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/spec/Cargo.toml b/spec/Cargo.toml index 2d3a9818ab..084dae296c 100644 --- a/spec/Cargo.toml +++ b/spec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-chain-spec" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/sync/Cargo.toml b/sync/Cargo.toml index c6e82fc462..4eee2d8432 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-sync" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/Cargo.toml b/util/Cargo.toml index eed340edaa..88e58f376f 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-util" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/avl/Cargo.toml b/util/avl/Cargo.toml index cad3a6aa64..87dc568e5b 100644 --- a/util/avl/Cargo.toml +++ b/util/avl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "avl-merkle" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/build-info/Cargo.toml b/util/build-info/Cargo.toml index b86b6c0469..b129bfb4a4 100644 --- a/util/build-info/Cargo.toml +++ b/util/build-info/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "build-info" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/crypto/Cargo.toml b/util/crypto/Cargo.toml index e3bec9ea07..2972211201 100644 --- a/util/crypto/Cargo.toml +++ b/util/crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "crypto" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/dir/Cargo.toml b/util/dir/Cargo.toml index 942d0c91dd..86f204ddd4 100644 --- a/util/dir/Cargo.toml +++ b/util/dir/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dir" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/hash/Cargo.toml b/util/hash/Cargo.toml index cac6faeddf..1181a06f3f 100644 --- a/util/hash/Cargo.toml +++ b/util/hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hash" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/instrument/Cargo.toml b/util/instrument/Cargo.toml index 1b1ce58428..6c4671b7c5 100644 --- a/util/instrument/Cargo.toml +++ b/util/instrument/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-instrument" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/logger/Cargo.toml b/util/logger/Cargo.toml index 95066eb719..38112e4a46 100644 --- a/util/logger/Cargo.toml +++ b/util/logger/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "logger" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos "] edition = "2018" diff --git a/util/merkle-root/Cargo.toml b/util/merkle-root/Cargo.toml index 4249e9b1be..40bde4a60b 100644 --- a/util/merkle-root/Cargo.toml +++ b/util/merkle-root/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "merkle-root" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/time/Cargo.toml b/util/time/Cargo.toml index 68d7eda76a..6f7ef8e995 100644 --- a/util/time/Cargo.toml +++ b/util/time/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-time" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/verification/Cargo.toml b/verification/Cargo.toml index 146976f587..100f3193a0 100644 --- a/verification/Cargo.toml +++ b/verification/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-verification" -version = "0.1.0" +version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" From cd88db617f7972a7b688db1523badb9f174cf01f Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 12 Dec 2018 15:49:00 +0800 Subject: [PATCH 03/45] chore: run cargo check after bumping version --- devtools/release/bump.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/devtools/release/bump.sh b/devtools/release/bump.sh index d0dce9903b..e6a222a985 100755 --- a/devtools/release/bump.sh +++ b/devtools/release/bump.sh @@ -12,6 +12,7 @@ main() { local v="$1" find . -name 'Cargo.toml' -print0 | xargs -0 sed -i .bak 's/^version = .*/version = "'"$v"'"/' find . -name 'Cargo.toml.bak' -exec rm -f {} \; + cargo check } main "$@" From ed3489035407d931e31354bdee9e294dd20e7744 Mon Sep 17 00:00:00 2001 From: ian Date: Wed, 12 Dec 2018 15:50:25 +0800 Subject: [PATCH 04/45] chore: update Cargo.lock --- Cargo.lock | 296 ++++++++++++++++++++++++++--------------------------- 1 file changed, 148 insertions(+), 148 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 928a402006..5a08df70da 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -69,12 +69,12 @@ dependencies = [ [[package]] name = "avl-merkle" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.1.0", - "ckb-db 0.1.0", - "hash 0.1.0", + "ckb-core 0.3.0-pre", + "ckb-db 0.3.0-pre", + "hash 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", @@ -224,7 +224,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "build-info" -version = "0.1.0" +version = "0.3.0-pre" [[package]] name = "byte-tools" @@ -307,37 +307,37 @@ dependencies = [ [[package]] name = "ckb" -version = "0.1.0" -dependencies = [ - "build-info 0.1.0", - "ckb-chain 0.1.0", - "ckb-chain-spec 0.1.0", - "ckb-core 0.1.0", - "ckb-db 0.1.0", - "ckb-instrument 0.1.0", - "ckb-miner 0.1.0", - "ckb-network 0.1.0", - "ckb-notify 0.1.0", - "ckb-pool 0.1.0", - "ckb-pow 0.1.0", - "ckb-rpc 0.1.0", - "ckb-script 0.1.0", - "ckb-shared 0.1.0", - "ckb-sync 0.1.0", - "ckb-time 0.1.0", - "ckb-util 0.1.0", - "ckb-verification 0.1.0", +version = "0.3.0-pre" +dependencies = [ + "build-info 0.3.0-pre", + "ckb-chain 0.3.0-pre", + "ckb-chain-spec 0.3.0-pre", + "ckb-core 0.3.0-pre", + "ckb-db 0.3.0-pre", + "ckb-instrument 0.3.0-pre", + "ckb-miner 0.3.0-pre", + "ckb-network 0.3.0-pre", + "ckb-notify 0.3.0-pre", + "ckb-pool 0.3.0-pre", + "ckb-pow 0.3.0-pre", + "ckb-rpc 0.3.0-pre", + "ckb-script 0.3.0-pre", + "ckb-shared 0.3.0-pre", + "ckb-sync 0.3.0-pre", + "ckb-time 0.3.0-pre", + "ckb-util 0.3.0-pre", + "ckb-verification 0.3.0-pre", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "config 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "crypto 0.1.0", + "crypto 0.3.0-pre", "ctrlc 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dir 0.1.0", + "dir 0.3.0-pre", "faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.1.0", + "hash 0.3.0-pre", "lazy_static 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)", - "logger 0.1.0", + "logger 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", @@ -348,25 +348,25 @@ dependencies = [ [[package]] name = "ckb-benches" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ - "ckb-pow 0.1.0", + "ckb-pow 0.3.0-pre", "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ckb-chain" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ - "avl-merkle 0.1.0", + "avl-merkle 0.3.0-pre", "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-chain-spec 0.1.0", - "ckb-core 0.1.0", - "ckb-db 0.1.0", - "ckb-notify 0.1.0", - "ckb-shared 0.1.0", - "ckb-time 0.1.0", - "ckb-verification 0.1.0", + "ckb-chain-spec 0.3.0-pre", + "ckb-core 0.3.0-pre", + "ckb-db 0.3.0-pre", + "ckb-notify 0.3.0-pre", + "ckb-shared 0.3.0-pre", + "ckb-time 0.3.0-pre", + "ckb-verification 0.3.0-pre", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -382,10 +382,10 @@ dependencies = [ [[package]] name = "ckb-chain-spec" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ - "ckb-core 0.1.0", - "ckb-pow 0.1.0", + "ckb-core 0.3.0-pre", + "ckb-pow 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", @@ -395,17 +395,17 @@ dependencies = [ [[package]] name = "ckb-core" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-time 0.1.0", - "ckb-util 0.1.0", + "ckb-time 0.3.0-pre", + "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "crypto 0.1.0", + "crypto 0.3.0-pre", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.1.0", - "merkle-root 0.1.0", + "hash 0.3.0-pre", + "merkle-root 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 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)", @@ -415,11 +415,11 @@ dependencies = [ [[package]] name = "ckb-db" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.1.0", - "ckb-util 0.1.0", + "ckb-core 0.3.0-pre", + "ckb-util 0.3.0-pre", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.10.0 (git+https://github.com/nervosnetwork/rust-rocksdb)", @@ -428,26 +428,26 @@ dependencies = [ [[package]] name = "ckb-instrument" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ - "ckb-chain 0.1.0", - "ckb-core 0.1.0", - "ckb-shared 0.1.0", + "ckb-chain 0.3.0-pre", + "ckb-core 0.3.0-pre", + "ckb-shared 0.3.0-pre", "indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ckb-miner" -version = "0.1.0" -dependencies = [ - "ckb-core 0.1.0", - "ckb-notify 0.1.0", - "ckb-pool 0.1.0", - "ckb-pow 0.1.0", - "ckb-shared 0.1.0", - "ckb-time 0.1.0", - "ckb-util 0.1.0", +version = "0.3.0-pre" +dependencies = [ + "ckb-core 0.3.0-pre", + "ckb-notify 0.3.0-pre", + "ckb-pool 0.3.0-pre", + "ckb-pow 0.3.0-pre", + "ckb-shared 0.3.0-pre", + "ckb-time 0.3.0-pre", + "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -462,10 +462,10 @@ dependencies = [ [[package]] name = "ckb-network" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-util 0.1.0", + "ckb-util 0.3.0-pre", "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 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", @@ -480,10 +480,10 @@ dependencies = [ [[package]] name = "ckb-notify" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ - "ckb-core 0.1.0", - "ckb-util 0.1.0", + "ckb-core 0.3.0-pre", + "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.3 (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)", @@ -491,22 +491,22 @@ dependencies = [ [[package]] name = "ckb-pool" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-chain 0.1.0", - "ckb-chain-spec 0.1.0", - "ckb-core 0.1.0", - "ckb-db 0.1.0", - "ckb-notify 0.1.0", - "ckb-shared 0.1.0", - "ckb-time 0.1.0", - "ckb-util 0.1.0", - "ckb-verification 0.1.0", + "ckb-chain 0.3.0-pre", + "ckb-chain-spec 0.3.0-pre", + "ckb-core 0.3.0-pre", + "ckb-db 0.3.0-pre", + "ckb-notify 0.3.0-pre", + "ckb-shared 0.3.0-pre", + "ckb-time 0.3.0-pre", + "ckb-util 0.3.0-pre", + "ckb-verification 0.3.0-pre", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.1.0", + "hash 0.3.0-pre", "linked-hash-map 0.5.1 (git+https://github.com/nervosnetwork/linked-hash-map?rev=df27f21)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", @@ -518,12 +518,12 @@ dependencies = [ [[package]] name = "ckb-pow" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.1.0", + "ckb-core 0.3.0-pre", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.1.0", + "hash 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -533,13 +533,13 @@ dependencies = [ [[package]] name = "ckb-protocol" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.1.0", - "ckb-util 0.1.0", + "ckb-core 0.3.0-pre", + "ckb-util 0.3.0-pre", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.1.0", + "hash 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -548,19 +548,19 @@ dependencies = [ [[package]] name = "ckb-rpc" -version = "0.1.0" -dependencies = [ - "ckb-chain 0.1.0", - "ckb-core 0.1.0", - "ckb-db 0.1.0", - "ckb-miner 0.1.0", - "ckb-network 0.1.0", - "ckb-pool 0.1.0", - "ckb-pow 0.1.0", - "ckb-protocol 0.1.0", - "ckb-shared 0.1.0", - "ckb-sync 0.1.0", - "ckb-verification 0.1.0", +version = "0.3.0-pre" +dependencies = [ + "ckb-chain 0.3.0-pre", + "ckb-core 0.3.0-pre", + "ckb-db 0.3.0-pre", + "ckb-miner 0.3.0-pre", + "ckb-network 0.3.0-pre", + "ckb-pool 0.3.0-pre", + "ckb-pow 0.3.0-pre", + "ckb-protocol 0.3.0-pre", + "ckb-shared 0.3.0-pre", + "ckb-sync 0.3.0-pre", + "ckb-verification 0.3.0-pre", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -575,17 +575,17 @@ dependencies = [ [[package]] name = "ckb-script" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.1.0", - "ckb-protocol 0.1.0", + "ckb-core 0.3.0-pre", + "ckb-protocol 0.3.0-pre", "ckb-vm 0.1.0 (git+https://github.com/nervosnetwork/ckb-vm?rev=1622ba0)", - "crypto 0.1.0", + "crypto 0.3.0-pre", "faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.1.0", + "hash 0.3.0-pre", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -595,15 +595,15 @@ dependencies = [ [[package]] name = "ckb-shared" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ - "avl-merkle 0.1.0", + "avl-merkle 0.3.0-pre", "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-chain-spec 0.1.0", - "ckb-core 0.1.0", - "ckb-db 0.1.0", - "ckb-time 0.1.0", - "ckb-util 0.1.0", + "ckb-chain-spec 0.3.0-pre", + "ckb-core 0.3.0-pre", + "ckb-db 0.3.0-pre", + "ckb-time 0.3.0-pre", + "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -619,21 +619,21 @@ dependencies = [ [[package]] name = "ckb-sync" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-chain 0.1.0", - "ckb-chain-spec 0.1.0", - "ckb-core 0.1.0", - "ckb-db 0.1.0", - "ckb-network 0.1.0", - "ckb-notify 0.1.0", - "ckb-pool 0.1.0", - "ckb-protocol 0.1.0", - "ckb-shared 0.1.0", - "ckb-time 0.1.0", - "ckb-util 0.1.0", - "ckb-verification 0.1.0", + "ckb-chain 0.3.0-pre", + "ckb-chain-spec 0.3.0-pre", + "ckb-core 0.3.0-pre", + "ckb-db 0.3.0-pre", + "ckb-network 0.3.0-pre", + "ckb-notify 0.3.0-pre", + "ckb-pool 0.3.0-pre", + "ckb-protocol 0.3.0-pre", + "ckb-shared 0.3.0-pre", + "ckb-time 0.3.0-pre", + "ckb-util 0.3.0-pre", + "ckb-verification 0.3.0-pre", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -649,34 +649,34 @@ dependencies = [ [[package]] name = "ckb-time" -version = "0.1.0" +version = "0.3.0-pre" [[package]] name = "ckb-util" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ckb-verification" -version = "0.1.0" -dependencies = [ - "ckb-chain 0.1.0", - "ckb-chain-spec 0.1.0", - "ckb-core 0.1.0", - "ckb-db 0.1.0", - "ckb-notify 0.1.0", - "ckb-pow 0.1.0", - "ckb-script 0.1.0", - "ckb-shared 0.1.0", - "ckb-time 0.1.0", - "ckb-util 0.1.0", +version = "0.3.0-pre" +dependencies = [ + "ckb-chain 0.3.0-pre", + "ckb-chain-spec 0.3.0-pre", + "ckb-core 0.3.0-pre", + "ckb-db 0.3.0-pre", + "ckb-notify 0.3.0-pre", + "ckb-pow 0.3.0-pre", + "ckb-script 0.3.0-pre", + "ckb-shared 0.3.0-pre", + "ckb-time 0.3.0-pre", + "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.1.0", + "hash 0.3.0-pre", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "merkle-root 0.1.0", + "merkle-root 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 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)", @@ -918,7 +918,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crypto" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -979,7 +979,7 @@ dependencies = [ [[package]] name = "dir" -version = "0.1.0" +version = "0.3.0-pre" [[package]] name = "either" @@ -1181,7 +1181,7 @@ dependencies = [ [[package]] name = "hash" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1793,7 +1793,7 @@ dependencies = [ [[package]] name = "logger" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1851,9 +1851,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "merkle-root" -version = "0.1.0" +version = "0.3.0-pre" dependencies = [ - "hash 0.1.0", + "hash 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] From deeda80e9cb3fb3e4ec4b406af09cc23d37a11d9 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Wed, 12 Dec 2018 17:19:10 +0800 Subject: [PATCH 05/45] fix: remove unsound test --- util/build-info/src/lib.rs | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/util/build-info/src/lib.rs b/util/build-info/src/lib.rs index 3e0b671e10..d184826ae3 100644 --- a/util/build-info/src/lib.rs +++ b/util/build-info/src/lib.rs @@ -85,24 +85,3 @@ pub fn get_commit_date() -> Option { .ok() .and_then(|r| String::from_utf8(r.stdout).ok()) } - -#[cfg(test)] -mod test { - use super::*; - - #[test] - fn test_struct_local() { - // hard to make positive tests for `commit_describe` and `commit_date` since they will always change - let vi = get_version!(); - assert_eq!(vi.major, 0); - assert_eq!(vi.minor, 1); - assert_eq!(vi.patch, 0); - } - - #[test] - fn test_display_local() { - let vi = get_version!(); - assert_eq!(vi.short(), "0.1.0".to_string()); - assert!(vi.long().starts_with("0.1.0")); - } -} From e5da1ae8a29f6448b826306eaa0d10a1b7bbb2f8 Mon Sep 17 00:00:00 2001 From: quake wang Date: Wed, 12 Dec 2018 20:06:56 +0900 Subject: [PATCH 06/45] fix: resolve mining old block issue (#87) --- miner/src/client.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/miner/src/client.rs b/miner/src/client.rs index 184a92c1bc..4232c64912 100644 --- a/miner/src/client.rs +++ b/miner/src/client.rs @@ -75,5 +75,9 @@ impl Client { error!(target: "miner", "rpc call submit_block error: {:?}", e); } } + + info!(target: "miner", "clear shared data and waiting for the next poll"); + let mut inner = self.shared.inner.write(); + *inner = None; } } From 36b541f4ca93c91f34ca836cf20c0b8486049a28 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Thu, 13 Dec 2018 10:53:06 +0800 Subject: [PATCH 07/45] fix: uncheck subtract overflow (#88) * fix: uncheck subtract overflow * turn off `kad` temporarily * fix debug log format --- chain/src/chain.rs | 21 ++++++++++++++------ network/src/network.rs | 14 ++++++------- sync/src/relayer/mod.rs | 9 ++++++--- sync/src/synchronizer/block_fetcher.rs | 2 +- sync/src/synchronizer/get_headers_process.rs | 2 +- sync/src/synchronizer/headers_process.rs | 4 ++-- sync/src/synchronizer/mod.rs | 8 ++++---- 7 files changed, 36 insertions(+), 24 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index f654b1109b..b2c79efb17 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -155,13 +155,17 @@ impl ChainService { }; self.shared.store().insert_block(batch, block); - self.shared.store().insert_output_root(batch, &block.header().hash(), &root); - self.shared.store().insert_block_ext(batch, &block.header().hash(), &ext); + self.shared + .store() + .insert_output_root(batch, &block.header().hash(), &root); + self.shared + .store() + .insert_block_ext(batch, &block.header().hash(), &ext); let current_total_difficulty = tip_header.total_difficulty(); debug!( - "difficulty diff = {}; current = {}, cannon = {}", - &cannon_total_difficulty - current_total_difficulty, + target: "chain", + "difficulty current = {}, cannon = {}", current_total_difficulty, cannon_total_difficulty, ); @@ -170,7 +174,12 @@ impl ChainService { || (current_total_difficulty == &cannon_total_difficulty && block.header().hash() < tip_header.hash()) { - debug!(target: "chain", "new best block found: {} => {}", block.header().number(), block.header().hash()); + debug!( + target: "chain", + "new best block found: {} => {}, difficulty diff = {}", + block.header().number(), block.header().hash(), + &cannon_total_difficulty - current_total_difficulty + ); new_best_block = true; output_root = root; total_difficulty = cannon_total_difficulty; @@ -343,7 +352,7 @@ impl ChainService { .iter() .enumerate() { - debug!(target: "chain", " {} => {:#?}", index, uncle); + debug!(target: "chain", " {} => {:?}", index, uncle); } debug!(target: "chain", "}}"); } diff --git a/network/src/network.rs b/network/src/network.rs index becd06437e..13f454da8b 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -685,7 +685,7 @@ impl Network { } } - let discovery_query_service = DiscoveryQueryService::new( + let _discovery_query_service = DiscoveryQueryService::new( Arc::clone(&network), swarm_controller.clone(), basic_transport.clone(), @@ -697,12 +697,12 @@ impl Network { // prepare services futures let futures: Vec + Send>> = vec![ Box::new(swarm_events.for_each(|_| Ok(()))), - Box::new( - discovery_query_service - .into_future() - .map(|_| ()) - .map_err(|(err, _)| err), - ) as Box + Send>, + // Box::new( + // discovery_query_service + // .into_future() + // .map(|_| ()) + // .map_err(|(err, _)| err), + // ) as Box + Send>, ping_service.start_protocol( Arc::clone(&network), swarm_controller.clone(), diff --git a/sync/src/relayer/mod.rs b/sync/src/relayer/mod.rs index c45f8932fb..2ff67720b1 100644 --- a/sync/src/relayer/mod.rs +++ b/sync/src/relayer/mod.rs @@ -140,7 +140,8 @@ where } pub fn accept_block(&self, nc: &CKBProtocolContext, peer: PeerIndex, block: &Arc) { - if self.chain.process_block(Arc::clone(&block)).is_ok() { + let ret = self.chain.process_block(Arc::clone(&block)); + if ret.is_ok() { let fbb = &mut FlatBufferBuilder::new(); let message = RelayMessage::build_compact_block(fbb, block, &HashSet::new()); fbb.finish(message, None); @@ -150,6 +151,8 @@ where let _ = nc.send(peer_id, fbb.finished_data().to_vec()); } } + } else { + debug!(target: "relay", "accept_block verify error {:?}", ret); } } @@ -262,12 +265,12 @@ where } fn connected(&self, _nc: Box, peer: PeerIndex) { - info!(target: "sync", "peer={} RelayProtocol.connected", peer); + info!(target: "relay", "peer={} RelayProtocol.connected", peer); // do nothing } fn disconnected(&self, _nc: Box, peer: PeerIndex) { - info!(target: "sync", "peer={} RelayProtocol.disconnected", peer); + info!(target: "relay", "peer={} RelayProtocol.disconnected", peer); // TODO } diff --git a/sync/src/synchronizer/block_fetcher.rs b/sync/src/synchronizer/block_fetcher.rs index 7895b5badc..463917642a 100644 --- a/sync/src/synchronizer/block_fetcher.rs +++ b/sync/src/synchronizer/block_fetcher.rs @@ -189,7 +189,7 @@ where && inflight.insert(to_fetch_hash.clone().clone()) { debug!( - target: "sync", "[Synchronizer] inflight insert {:#?}------------{:?}", + target: "sync", "[Synchronizer] inflight insert {:?}------------{:?}", to_fetch.number(), to_fetch_hash ); diff --git a/sync/src/synchronizer/get_headers_process.rs b/sync/src/synchronizer/get_headers_process.rs index ad02769a3a..5e7de4e967 100644 --- a/sync/src/synchronizer/get_headers_process.rs +++ b/sync/src/synchronizer/get_headers_process.rs @@ -71,7 +71,7 @@ where fbb.finish(message, None); let _ = self.nc.send(self.peer, fbb.finished_data().to_vec()); } else { - warn!(target: "sync", "\n\nunknown block headers from peer {} {:#?}\n\n", self.peer, block_locator_hashes); + warn!(target: "sync", "\n\nunknown block headers from peer {} {:?}\n\n", self.peer, block_locator_hashes); // Got 'headers' message without known blocks // ban or close peers self.nc diff --git a/sync/src/synchronizer/headers_process.rs b/sync/src/synchronizer/headers_process.rs index 0ef4557bc0..622bca9b93 100644 --- a/sync/src/synchronizer/headers_process.rs +++ b/sync/src/synchronizer/headers_process.rs @@ -128,7 +128,7 @@ where fn is_continuous(&self, headers: &[Header]) -> bool { debug!( target: "sync", - "headers\n {:#?}", + "headers\n {:?}", headers .iter() .map(|h| format!( @@ -201,7 +201,7 @@ where .peers .misbehavior(self.peer, result.misbehavior); } - debug!(target: "sync", "\n\nHeadersProcess accept_first is_valid {:?} headers = {:#?}\n\n", result, headers[0]); + debug!(target: "sync", "\n\nHeadersProcess accept_first is_valid {:?} headers = {:?}\n\n", result, headers[0]); return; } diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index a1d79c2cda..65d215aff7 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -441,14 +441,14 @@ impl Synchronizer { let ret = self.accept_block(peer, &block); if ret.is_err() { debug!( - target: "sync", "[Synchronizer] accept_block {:#?} error {:?}", + target: "sync", "[Synchronizer] accept_block {:?} error {:?}", block, ret.unwrap_err() ); } } else { debug!( - target: "sync", "[Synchronizer] insert_orphan_block {:#?}------------{:?}", + target: "sync", "[Synchronizer] insert_orphan_block {:?}------------{:?}", block.header().number(), block.header().hash() ); @@ -457,14 +457,14 @@ impl Synchronizer { } } else { debug!( - target: "sync", "[Synchronizer] accept_block {:#?} error {:?}", + target: "sync", "[Synchronizer] accept_block {:?} error {:?}", block, accept_ret.unwrap_err() ) } } else { debug!( - target: "sync", "[Synchronizer] insert_orphan_block {:#?}------------{:?}", + target: "sync", "[Synchronizer] insert_orphan_block {:?}------------{:?}", block.header().number(), block.header().hash() ); From 7ad3c94b23c8db3c885ef48cd83041d7ae819167 Mon Sep 17 00:00:00 2001 From: ian Date: Fri, 14 Dec 2018 12:23:39 +0800 Subject: [PATCH 08/45] chore: setup travis condition (#90) --- .travis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.travis.yml b/.travis.yml index 58d9181758..01fd06f227 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,8 @@ cache: directories: - $HOME/.cargo +if: 'branch IN (master, develop) OR type != push OR fork = true OR tag =~ ^v' + env: global: - RUST_BACKTRACE=full From f4682b633b0f532405914587c6c74aa2d983984d Mon Sep 17 00:00:00 2001 From: James Chen Date: Fri, 14 Dec 2018 16:42:08 +0900 Subject: [PATCH 09/45] refactor: replace from/to u64 type in favor of BlockNumber --- rpc/src/server.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/rpc/src/server.rs b/rpc/src/server.rs index 3f051a4b57..ee327a6d60 100644 --- a/rpc/src/server.rs +++ b/rpc/src/server.rs @@ -40,7 +40,7 @@ build_rpc_trait! { // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_cells_by_type_hash","params": ["0x1b1c832d02fdb4339f9868c8a8636c3d9dd10bd53ac7ce99595825bd6beeffb3", 1, 10]}' -H 'content-type:application/json' 'http://localhost:8114' #[rpc(name = "get_cells_by_type_hash")] - fn get_cells_by_type_hash(&self, H256, u64, u64) -> Result>; + fn get_cells_by_type_hash(&self, H256, BlockNumber, BlockNumber) -> Result>; // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_current_cell","params": [{"hash": "0x1b1c832d02fdb4339f9868c8a8636c3d9dd10bd53ac7ce99595825bd6beeffb3", "index": 1}]}' -H 'content-type:application/json' 'http://localhost:3030' #[rpc(name = "get_current_cell")] @@ -73,8 +73,8 @@ impl ChainRpc for ChainRpcImpl { fn get_cells_by_type_hash( &self, type_hash: H256, - from: u64, - to: u64, + from: BlockNumber, + to: BlockNumber, ) -> Result> { let mut result = Vec::new(); for block_number in from..=to { From 3abf2b1f43dd27e986c8b2ee311d91e896051d3a Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 17 Dec 2018 11:12:20 +0900 Subject: [PATCH 10/45] refactor: rename outpoint to out_point as its type is OutPoint (#93) Refs https://github.com/nervosnetwork/ckb-demo-ruby-sdk/pull/12 --- chain/src/chain.rs | 4 ++-- rpc/src/server.rs | 2 +- rpc/src/types.rs | 2 +- script/src/syscalls/mod.rs | 29 +++++++++++++++-------------- script/src/verify.rs | 10 +++++----- src/cli/run_impl.rs | 4 ++-- 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/chain/src/chain.rs b/chain/src/chain.rs index b2c79efb17..93214f9b2f 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -533,8 +533,8 @@ pub mod test { .set_verification(false); let (_chain_controller, shared) = start_chain(Some(consensus)); - let outpoint = OutPoint::new(root_hash, 0); - let state = shared.cell(&outpoint); + let out_point = OutPoint::new(root_hash, 0); + let state = shared.cell(&out_point); assert!(state.is_current()); } diff --git a/rpc/src/server.rs b/rpc/src/server.rs index ee327a6d60..11cc12268d 100644 --- a/rpc/src/server.rs +++ b/rpc/src/server.rs @@ -92,7 +92,7 @@ impl ChainRpc for ChainRpcImpl { for (i, output) in transaction.outputs().iter().enumerate() { if output.lock == type_hash && (!transaction_meta.is_spent(i)) { result.push(CellOutputWithOutPoint { - outpoint: OutPoint::new(transaction.hash().clone(), i as u32), + out_point: OutPoint::new(transaction.hash().clone(), i as u32), capacity: output.capacity, lock: output.lock.clone(), }); diff --git a/rpc/src/types.rs b/rpc/src/types.rs index 9c9bc81d96..ea9e762bfc 100644 --- a/rpc/src/types.rs +++ b/rpc/src/types.rs @@ -45,7 +45,7 @@ impl From for BlockWithHash { // cell's own data such as lock and capacity #[derive(Serialize)] pub struct CellOutputWithOutPoint { - pub outpoint: OutPoint, + pub out_point: OutPoint, pub capacity: Capacity, pub lock: H256, } diff --git a/script/src/syscalls/mod.rs b/script/src/syscalls/mod.rs index 8130963ba6..b20c60c011 100644 --- a/script/src/syscalls/mod.rs +++ b/script/src/syscalls/mod.rs @@ -702,7 +702,7 @@ mod tests { } } - fn _test_load_self_input_outpoint(data: Vec) { + fn _test_load_self_input_out_point(data: Vec) { let mut machine = DefaultCoreMachine::::default(); let size_addr = 0; let addr = 100; @@ -712,24 +712,24 @@ mod tests { machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index machine.registers_mut()[A4] = 2; //source: 2 self - machine.registers_mut()[A5] = 1; //field: 1 outpoint + machine.registers_mut()[A5] = 1; //field: 1 out_point machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number let unlock = Script::new(0, vec![], None, Some(vec![]), vec![]); let sha3_data = sha3_256(data); - let outpoint = OutPoint::new(H256::from_slice(&sha3_data).unwrap(), 3); + let out_point = OutPoint::new(H256::from_slice(&sha3_data).unwrap(), 3); let mut builder = FlatBufferBuilder::new(); - let fbs_offset = FbsOutPoint::build(&mut builder, &outpoint); + let fbs_offset = FbsOutPoint::build(&mut builder, &out_point); builder.finish(fbs_offset, None); - let outpoint_data = builder.finished_data(); + let out_point_data = builder.finished_data(); - let input = CellInput::new(outpoint, unlock); + let input = CellInput::new(out_point, unlock); let inputs = vec![]; let mut load_input = LoadInputByField::new(&inputs, Some(&input)); assert!(machine .memory_mut() - .store64(size_addr as usize, outpoint_data.len() as u64 + 5) + .store64(size_addr as usize, out_point_data.len() as u64 + 5) .is_ok()); assert!(load_input.ecall(&mut machine).is_ok()); @@ -737,23 +737,24 @@ mod tests { assert_eq!( machine.memory_mut().load64(size_addr as usize), - Ok(outpoint_data.len() as u64) + Ok(out_point_data.len() as u64) ); - for (i, addr) in (addr as usize..addr as usize + outpoint_data.len() as usize).enumerate() { - assert_eq!(machine.memory_mut().load8(addr), Ok(outpoint_data[i])); + for (i, addr) in (addr as usize..addr as usize + out_point_data.len() as usize).enumerate() + { + assert_eq!(machine.memory_mut().load8(addr), Ok(out_point_data[i])); } } proptest! { #[test] - fn test_load_self_input_outpoint(data in any_with::>(size_range(1000).lift())) { - _test_load_self_input_outpoint(data); + fn test_load_self_input_out_point(data in any_with::>(size_range(1000).lift())) { + _test_load_self_input_out_point(data); } } #[test] - fn test_load_missing_self_output_outpoint() { + fn test_load_missing_self_output_out_point() { let mut machine = DefaultCoreMachine::::default(); let size_addr = 0; let addr = 100; @@ -763,7 +764,7 @@ mod tests { machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index machine.registers_mut()[A4] = 2; //source: 2 self - machine.registers_mut()[A5] = 1; //field: 1 outpoint + machine.registers_mut()[A5] = 1; //field: 1 out_point machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number let inputs = vec![]; diff --git a/script/src/verify.rs b/script/src/verify.rs index 696a47210b..135e9e8ed2 100644 --- a/script/src/verify.rs +++ b/script/src/verify.rs @@ -288,10 +288,10 @@ mod tests { hex_to(&signature_der, &mut hex_signature).expect("hex privkey"); args.insert(0, hex_signature); - let dep_outpoint = OutPoint::new(H256::from_trimmed_hex_str("123").unwrap(), 8); + let dep_out_point = OutPoint::new(H256::from_trimmed_hex_str("123").unwrap(), 8); let dep_cell = CellOutput::new(buffer.len() as Capacity, buffer, H256::zero(), None); let mut dep_cells = FnvHashMap::default(); - dep_cells.insert(&dep_outpoint, &dep_cell); + dep_cells.insert(&dep_out_point, &dep_cell); let privkey = privkey.pubkey().unwrap().serialize(); let mut hex_privkey = vec![0; privkey.len() * 2]; @@ -302,7 +302,7 @@ mod tests { let transaction = TransactionBuilder::default() .input(input.clone()) - .dep(dep_outpoint.clone()) + .dep(dep_out_point.clone()) .build(); let dummy_cell = CellOutput::new(100, vec![], H256::default(), None); @@ -340,7 +340,7 @@ mod tests { hex_to(&signature_der, &mut hex_signature).expect("hex privkey"); args.insert(0, hex_signature); - let dep_outpoint = OutPoint::new(H256::from_trimmed_hex_str("123").unwrap(), 8); + let dep_out_point = OutPoint::new(H256::from_trimmed_hex_str("123").unwrap(), 8); let privkey = privkey.pubkey().unwrap().serialize(); let mut hex_privkey = vec![0; privkey.len() * 2]; @@ -357,7 +357,7 @@ mod tests { let transaction = TransactionBuilder::default() .input(input.clone()) - .dep(dep_outpoint) + .dep(dep_out_point) .build(); let dummy_cell = CellOutput::new(100, vec![], H256::default(), None); diff --git a/src/cli/run_impl.rs b/src/cli/run_impl.rs index a19ad29c98..93c3e50a0b 100644 --- a/src/cli/run_impl.rs +++ b/src/cli/run_impl.rs @@ -157,7 +157,7 @@ pub fn sign(setup: &Setup, matches: &ArgMatches) { let system_cell_tx = &consensus.genesis_block().commit_transactions()[0]; let system_cell_data_hash = system_cell_tx.outputs()[0].data_hash(); let system_cell_tx_hash = system_cell_tx.hash(); - let system_cell_outpoint = OutPoint::new(system_cell_tx_hash.clone(), 0); + let system_cell_out_point = OutPoint::new(system_cell_tx_hash.clone(), 0); let privkey: Privkey = value_t!(matches.value_of("private-key"), H256) .unwrap_or_else(|e| e.exit()) @@ -199,7 +199,7 @@ pub fn sign(setup: &Setup, matches: &ArgMatches) { // Then, sign each input let result = TransactionBuilder::default() .transaction(transaction) - .dep(system_cell_outpoint) + .dep(system_cell_out_point) .inputs_clear() .inputs(inputs) .build(); From c03f1339d834847d9e4f1db94fdfc6bad3b3fe81 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 17 Dec 2018 05:42:34 +0000 Subject: [PATCH 11/45] chore(deps): bump crossbeam-channel from 0.3.3 to 0.3.4 Bumps [crossbeam-channel](https://github.com/crossbeam-rs/crossbeam) from 0.3.3 to 0.3.4. - [Release notes](https://github.com/crossbeam-rs/crossbeam/releases) - [Changelog](https://github.com/crossbeam-rs/crossbeam/blob/master/CHANGELOG.md) - [Commits](https://github.com/crossbeam-rs/crossbeam/compare/crossbeam-channel-0.3.3...crossbeam-channel-0.3.4) Signed-off-by: dependabot[bot] --- Cargo.lock | 52 +++++++++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a08df70da..52dccc3700 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -329,7 +329,7 @@ dependencies = [ "ckb-verification 0.3.0-pre", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "config 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "crypto 0.3.0-pre", "ctrlc 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "dir 0.3.0-pre", @@ -367,7 +367,7 @@ dependencies = [ "ckb-shared 0.3.0-pre", "ckb-time 0.3.0-pre", "ckb-verification 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (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)", @@ -401,7 +401,7 @@ dependencies = [ "bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "crypto 0.3.0-pre", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", @@ -448,7 +448,7 @@ dependencies = [ "ckb-shared 0.3.0-pre", "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc 0.10.2 (git+https://github.com/quake/rust-jsonrpc)", @@ -484,7 +484,7 @@ version = "0.3.0-pre" dependencies = [ "ckb-core 0.3.0-pre", "ckb-util 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.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)", ] @@ -503,7 +503,7 @@ dependencies = [ "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", "ckb-verification 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", @@ -522,7 +522,7 @@ version = "0.3.0-pre" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "ckb-core 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -604,7 +604,7 @@ dependencies = [ "ckb-db 0.3.0-pre", "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (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)", @@ -634,7 +634,7 @@ dependencies = [ "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", "ckb-verification 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -672,7 +672,7 @@ dependencies = [ "ckb-shared 0.3.0-pre", "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -759,7 +759,7 @@ dependencies = [ "clicolors-control 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -835,10 +835,10 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.3.3" +version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-epoch 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -890,6 +890,19 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "crossbeam-epoch" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", + "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "crossbeam-utils" version = "0.2.2" @@ -1285,7 +1298,7 @@ dependencies = [ "console 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1797,7 +1810,7 @@ version = "0.3.0-pre" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 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)", @@ -2374,7 +2387,7 @@ name = "rand_chacha" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2396,7 +2409,7 @@ name = "rand_hc" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2421,7 +2434,7 @@ name = "rand_xorshift" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3540,11 +3553,12 @@ dependencies = [ "checksum criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "c47d2b548c5647e1a436dc0cb78d4ebf51b6bf7ab101ed76662828bdd4d3a24a" "checksum criterion-plot 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6e649d6aacdbbdb94ec659561a309a71336fc5655ed408f3afd28df2fc0c4f4f" "checksum criterion-stats 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ff43cac80562f91ead0b617c1be74edf350adfaa195809d355de98dfc8f9237d" -"checksum crossbeam-channel 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8b7d034925ce9668a9a19539a82a2ae75660fa65c1a3a5ddbfce333aafcceb55" +"checksum crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5b2a9ea8f77c7f9efd317a8a5645f515d903a2d86ee14d2337a5facd1bd52c12" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" "checksum crossbeam-deque 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe1b6f945f824c7a25afe44f62e25d714c0cc523f8e99d8db5cd1026e1269d3" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" "checksum crossbeam-epoch 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2449aaa4ec7ef96e5fb24db16024b935df718e9ae1cec0a1e68feeca2efca7b8" +"checksum crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f10a4f8f409aaac4b16a5474fb233624238fcdeefb9ba50d5ea059aab63ba31c" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" "checksum crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c55913cc2799171a550e307918c0a360e8c16004820291bf3b638969b4a01816" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" From 5cb0d5669508c4d7d18aa580f0b1a8c85cdcee33 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 17 Dec 2018 05:42:50 +0000 Subject: [PATCH 12/45] chore(deps): bump serde_derive from 1.0.81 to 1.0.82 Bumps [serde_derive](https://github.com/serde-rs/serde) from 1.0.81 to 1.0.82. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.81...v1.0.82) Signed-off-by: dependabot[bot] --- Cargo.lock | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5a08df70da..dd2e8099d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -77,7 +77,7 @@ dependencies = [ "hash 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -341,7 +341,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -376,7 +376,7 @@ dependencies = [ "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -389,7 +389,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -410,7 +410,7 @@ dependencies = [ "numext-fixed-uint 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)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -456,7 +456,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -472,7 +472,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "snap 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "unsigned-varint 0.2.1 (git+https://github.com/paritytech/unsigned-varint)", @@ -513,7 +513,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -528,7 +528,7 @@ dependencies = [ "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -569,7 +569,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -590,7 +590,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -613,7 +613,7 @@ dependencies = [ "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -644,7 +644,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -805,7 +805,7 @@ dependencies = [ "itertools-num 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)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "walkdir 2.2.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1331,7 +1331,7 @@ source = "git+https://github.com/quake/rust-jsonrpc#2ada29a270a2242df01c1bece375 dependencies = [ "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1343,7 +1343,7 @@ dependencies = [ "futures 0.1.25 (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.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1599,7 +1599,7 @@ dependencies = [ "multiaddr 0.3.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1804,7 +1804,7 @@ dependencies = [ "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2719,7 +2719,7 @@ dependencies = [ [[package]] name = "serde_derive" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3733,7 +3733,7 @@ dependencies = [ "checksum serde 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" "checksum serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)" = "c91eb5b0190ae87b4e2e39cbba6e3bed3ac6186935fe265f0426156c4c49961b" "checksum serde-hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0b833c5ad67d52ced5f5938b2980f32a9c1c5ef047f0b4fb3127e7a423c76153" -"checksum serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)" = "477b13b646f5b5b56fc95bedfc3b550d12141ce84f466f6c44b9a17589923885" +"checksum serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)" = "96a7f9496ac65a2db5929afa087b54f8fc5008dcfbe48a8874ed20049b0d6154" "checksum serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811" "checksum serde_test 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "110b3dbdf8607ec493c22d5d947753282f3bae73c0f56d322af1e8c78e4c23d5" "checksum sha1 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cc30b1e1e8c40c121ca33b86c23308a090d19974ef001b4bf6e61fd1a0fb095c" From c61c2208165d84e5c1c5609fa50111ce840a5d51 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" Date: Mon, 17 Dec 2018 13:03:26 +0000 Subject: [PATCH 13/45] chore(deps): bump serde from 1.0.81 to 1.0.82 Bumps [serde](https://github.com/serde-rs/serde) from 1.0.81 to 1.0.82. - [Release notes](https://github.com/serde-rs/serde/releases) - [Commits](https://github.com/serde-rs/serde/compare/v1.0.81...v1.0.82) Signed-off-by: dependabot[bot] --- Cargo.lock | 72 +++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6effdca755..9c8b5b190b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -76,7 +76,7 @@ dependencies = [ "ckb-db 0.3.0-pre", "hash 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -148,7 +148,7 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -340,7 +340,7 @@ dependencies = [ "logger 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -375,7 +375,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -388,7 +388,7 @@ dependencies = [ "ckb-pow 0.3.0-pre", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -409,7 +409,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 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)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -455,7 +455,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -471,7 +471,7 @@ dependencies = [ "libp2p 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "snap 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -512,7 +512,7 @@ dependencies = [ "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -527,7 +527,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -568,7 +568,7 @@ dependencies = [ "jsonrpc-server-utils 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -589,7 +589,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -612,7 +612,7 @@ dependencies = [ "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -643,7 +643,7 @@ dependencies = [ "multiaddr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -743,7 +743,7 @@ dependencies = [ "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "nom 4.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rust-ini 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde-hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "toml 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -759,7 +759,7 @@ dependencies = [ "clicolors-control 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -804,7 +804,7 @@ dependencies = [ "itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", "itertools-num 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)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -949,7 +949,7 @@ version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "csv-core 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -977,7 +977,7 @@ dependencies = [ "base64 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "chashmap 2.2.1 (git+https://github.com/redox-os/tfs)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1188,7 +1188,7 @@ dependencies = [ "pest_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1298,7 +1298,7 @@ dependencies = [ "console 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1343,7 +1343,7 @@ version = "0.10.2" source = "git+https://github.com/quake/rust-jsonrpc#2ada29a270a2242df01c1bece375989311e33fe0" dependencies = [ "hyper 0.10.15 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1355,7 +1355,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "futures 0.1.25 (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.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1380,7 +1380,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "jsonrpc-core 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-pubsub 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1611,7 +1611,7 @@ dependencies = [ "libp2p-core 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", "multiaddr 0.3.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1816,7 +1816,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1926,7 +1926,7 @@ dependencies = [ "byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "integer-encoding 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "multihash 0.8.1-pre (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2099,7 +2099,7 @@ dependencies = [ "numext-constructor 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2111,7 +2111,7 @@ dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-constructor 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2387,7 +2387,7 @@ name = "rand_chacha" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2409,7 +2409,7 @@ name = "rand_hc" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2434,7 +2434,7 @@ name = "rand_xorshift" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2715,7 +2715,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "serde" -version = "1.0.81" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2747,7 +2747,7 @@ 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.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3238,7 +3238,7 @@ name = "toml" version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3745,7 +3745,7 @@ dependencies = [ "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 0.8.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9dad3f759919b92c3068c696c15c3d17238234498bbdcc80f2c469606f948ac8" -"checksum serde 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)" = "c91eb5b0190ae87b4e2e39cbba6e3bed3ac6186935fe265f0426156c4c49961b" +"checksum serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)" = "6fa52f19aee12441d5ad11c9a00459122bd8f98707cadf9778c540674f1935b6" "checksum serde-hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0b833c5ad67d52ced5f5938b2980f32a9c1c5ef047f0b4fb3127e7a423c76153" "checksum serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)" = "96a7f9496ac65a2db5929afa087b54f8fc5008dcfbe48a8874ed20049b0d6154" "checksum serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)" = "c37ccd6be3ed1fdf419ee848f7c758eb31b054d7cd3ae3600e3bae0adf569811" From 190bd67ca4f64ca4a0fa167f45dfcd6f3b1eb267 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Mon, 17 Dec 2018 20:11:00 +0800 Subject: [PATCH 14/45] docs: temporary rpc api document --- rpc/doc.md | 361 ++++++++++++++++++++++++++++++++++++ rpc/src/integration_test.rs | 7 - rpc/src/server.rs | 38 +++- spec/src/lib.rs | 3 +- src/cli/run_impl.rs | 2 +- 5 files changed, 393 insertions(+), 18 deletions(-) create mode 100644 rpc/doc.md diff --git a/rpc/doc.md b/rpc/doc.md new file mode 100644 index 0000000000..07c8c58fe1 --- /dev/null +++ b/rpc/doc.md @@ -0,0 +1,361 @@ +# get_block + +Returns information about a block by hash. + +## Parameters + + Hash - Hash of a block. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_block","params": ["0x7643567cc0b8637505cce071ae764bc17a1d4e37579769c9a863d25841e48a07"]}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": { + "hash": "0x7643567cc0b8637505cce071ae764bc17a1d4e37579769c9a863d25841e48a07", + "header": { + "raw": { + "cellbase_id": "0xbddb7c2559c2c3cdfc8f3cae2697ca75489521c352265cc9e60b4b2416ad5929", + "difficulty": "0x100", + "number": 1, + "parent_hash": "0x9b0bd5be9498a0b873d08e242fff306eec04fac7c59ce479b49ca92a8f649982", + "timestamp": 1544599720510, + "txs_commit": "0xbddb7c2559c2c3cdfc8f3cae2697ca75489521c352265cc9e60b4b2416ad5929", + "txs_proposal": "0x0000000000000000000000000000000000000000000000000000000000000000", + "uncles_count": 0, + "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "version": 0 + }, + "seal": { + "nonce": 10545468520399447721, + "proof": [163, 13, 0, 0, 12, 17, 0, 0, 98, 28, 0, 0, 240, 60, 0, 0, 200, 62, 0, 0, 12, 76, 0, 0, 6, 93, 0, 0, 247, 93, 0, 0, 107, 97, 0, 0, 230, 100, 0, 0, 16, 103, 0, 0, 244, 107, 0, 0], + } + }, + "transactions": [ + { + "hash": "0xbddb7c2559c2c3cdfc8f3cae2697ca75489521c352265cc9e60b4b2416ad5929", + "transaction": { + "deps": [], + "inputs": [ + { + "previous_output": { + "hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "index": 4294967295 + }, + "unlock": { + "args": [], + "binary": [1, 0, 0, 0, 0, 0, 0, 0], + "reference": null, + "signed_args": [], + "version": 0 + } + } + ], + "outputs": [ + { + "capacity": 50000, + "contract": null, + "data": [], + "lock": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff" + } + ], + "version": 0 + } + } + ] + }, + "id": 2 +} +``` + +# get_transaction + +Returns the information about a transaction requested by transaction hash. + +## Parameters + + Hash - Hash of a transaction. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_transaction","params": ["0xbddb7c2559c2c3cdfc8f3cae2697ca75489521c352265cc9e60b4b2416ad5929"]}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": { + "hash": "0xbddb7c2559c2c3cdfc8f3cae2697ca75489521c352265cc9e60b4b2416ad5929", + "transaction": { + "deps": [], + "inputs": [ + { + "previous_output": { + "hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "index": 4294967295 + }, + "unlock": { + "args": [], + "binary": [1, 0, 0, 0, 0, 0, 0, 0], + "reference": null, + "signed_args": [], + "version": 0 + } + } + ], + "outputs": [ + { + "capacity": 50000, + "contract": null, + "data": [], + "lock": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff" + } + ], + "version": 0 + } + }, + "id": 2 +} +``` + + +# get_block_hash + +Returns hash of block in best-block-chain at ; index 0 is the genesis block. + +## Parameters + + BlockNumber - number of a block. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_block_hash","params": [1]}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": "0x7643567cc0b8637505cce071ae764bc17a1d4e37579769c9a863d25841e48a07", + "id": 2 +} +``` + +# get_tip_header + +Returns the information about the longest block chain tip header. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_tip_header","params": []}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": { + "raw": { + "cellbase_id": "0xfa531584947a905ca77ce4333bf49c9f20c97b4f464d2545584df946b3803a8b", + "difficulty": "0x100", + "number": 1246, + "parent_hash": "0xcacfcad12f3314138e929ac9833cb956fb42e4531ea5458c6a3c25fefeade315", + "timestamp": 1544600340130, + "txs_commit": "0xfa531584947a905ca77ce4333bf49c9f20c97b4f464d2545584df946b3803a8b", + "txs_proposal": "0x0000000000000000000000000000000000000000000000000000000000000000", + "uncles_count": 0, + "uncles_hash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "version": 0 + }, + "seal": { + "nonce": 15789531258138942821, + "proof": [130, 6, 0, 0, 187, 6, 0, 0, 14, 8, 0, 0, 219, 18, 0, 0, 94, 39, 0, 0, 108, 70, 0, 0, 234, 71, 0, 0, 9, 75, 0, 0, 19, 91, 0, 0, 122, 96, 0, 0, 253, 98, 0, 0, 249, 121, 0, 0] + } + }, + "id": 2 +} +``` + + + +# get_cells_by_type_hash + +Returns the information about cells collection by type_hash. + +## Parameters + + type_hash - cell type_hash. + from - start BlockNumber. + to - end BlockNumber. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_cells_by_type_hash","params": ["0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff", 1, 5]}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": [ + { + "capacity": 50000, + "lock": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff", + "out_point": { + "hash": "0xbddb7c2559c2c3cdfc8f3cae2697ca75489521c352265cc9e60b4b2416ad5929", + "index": 0 + } + }, + { + "capacity": 50000, + "lock": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff", + "out_point": { + "hash": "0x2c40a96684a99f720b6ab0eeb39564285742c5a2bed12347cd13e6ae50782111", + "index": 0 + } + }, + { + "capacity": 50000, + "lock": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff", + "out_point": { + "hash": "0x1954a9cbb21bebd859260bf851be9f1706b6e25ca511800ea05059f26973ea78", + "index": 0 + } + }, + { + "capacity": 50000, + "lock": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff", + "out_point": { + "hash": "0xc0dc6c4556ee84a176aa6f65493c31ea35d4ee190fe2f2b62b744f347b816d9b", + "index": 0 + } + }, + { + "capacity": 50000, + "lock": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff", + "out_point": { + "hash": "0xa185f069dbebf159bd0dbd495ae0822a9b71d20e59f790b0c814697609257f34", + "index": 0 + } + } + ], + "id": 2 +} +``` + + +# get_current_cell + +Returns the information about cell by out_point. + +## Parameters + + OutPoint - OutPoint Object {"hash": , "index": }. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_current_cell","params": [{"hash": "0xbddb7c2559c2c3cdfc8f3cae2697ca75489521c352265cc9e60b4b2416ad5929", "index": 0}]}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": { + "cell": { + "capacity": 50000, + "contract": null, + "data": [], + "lock": "0x321c1ca2887fb8eddaaa7e917399f71e63e03a1c83ff75ed12099a01115ea2ff" + }, + "status": "current" + }, + "id": 2 +} +``` + +# get_tip_block_number + +Returns the number of blocks in the longest block chain. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_tip_block_number","params": []}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": 1240, + "id": 2 +} +``` + +# local_node_id + +Returns local node id. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"local_node_id","params": []}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": "/ip4/0.0.0.0/tcp/8115/p2p/QmdSxB6iTcbhj6gbZNthvJrwRkJrwnsohNpVixY4FtcZwv", + "id": 2 +} +``` + + +# local_node_id + +Returns local node id. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"local_node_id","params": []}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": "/ip4/0.0.0.0/tcp/8115/p2p/QmdSxB6iTcbhj6gbZNthvJrwRkJrwnsohNpVixY4FtcZwv", + "id": 2 +} +``` + +# send_transaction + +Creates new transaction. + +## Parameters + +Transaction - The transaction object. + version - transaction version. + deps - dependent cell + inputs - transaction inputs. + outputs - transaction outputs. + +## Examples + +```shell +curl -d '{"id": 2, "jsonrpc": "2.0", "method":"send_transaction","params": [{"version":2, "deps":[], "inputs":[], "outputs":[]}]}' -H 'content-type:application/json' 'http://localhost:8114' +``` + +```json +{ + "jsonrpc": "2.0", + "result": "0xd91110fe20b7137c884d5c515f591ceda89a177bf06c1a3eb99c8a970dda2cf5", + "id": 2 +} +``` diff --git a/rpc/src/integration_test.rs b/rpc/src/integration_test.rs index d077ee24f8..746be47ea3 100644 --- a/rpc/src/integration_test.rs +++ b/rpc/src/integration_test.rs @@ -19,9 +19,6 @@ build_rpc_trait! { #[rpc(name = "submit_pow_solution")] fn submit_pow_solution(&self, u64) -> Result<()>; - #[rpc(name = "local_node_id")] - fn local_node_id(&self) -> Result>; - #[rpc(name = "add_node")] fn add_node(&self, String) -> Result<()>; } @@ -38,10 +35,6 @@ impl IntegrationTestRpc for IntegrationTestRpcImpl { Ok(()) } - fn local_node_id(&self) -> Result> { - Ok(self.network.external_url()) - } - fn add_node(&self, _node_id: String) -> Result<()> { unimplemented!() } diff --git a/rpc/src/server.rs b/rpc/src/server.rs index 11cc12268d..8c21121f4a 100644 --- a/rpc/src/server.rs +++ b/rpc/src/server.rs @@ -22,29 +22,26 @@ use types::{BlockWithHash, CellOutputWithOutPoint, CellWithStatus, Config, Trans build_rpc_trait! { pub trait ChainRpc { - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_block","params": ["0x0f9da6db98d0acd1ae0cf7ae3ee0b2b5ad2855d93c18d27c0961f985a62a93c3"]}' -H 'content-type:application/json' 'http://localhost:8114' #[rpc(name = "get_block")] fn get_block(&self, H256) -> Result>; - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_transaction","params": ["0x0f9da6db98d0acd1ae0cf7ae3ee0b2b5ad2855d93c18d27c0961f985a62a93c3"]}' -H 'content-type:application/json' 'http://localhost:8114' #[rpc(name = "get_transaction")] fn get_transaction(&self, H256) -> Result>; - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_block_hash","params": [1]}' -H 'content-type:application/json' 'http://localhost:8114' #[rpc(name = "get_block_hash")] fn get_block_hash(&self, u64) -> Result>; - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_tip_header","params": []}' -H 'content-type:application/json' 'http://localhost:8114' #[rpc(name = "get_tip_header")] fn get_tip_header(&self) -> Result
; - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_cells_by_type_hash","params": ["0x1b1c832d02fdb4339f9868c8a8636c3d9dd10bd53ac7ce99595825bd6beeffb3", 1, 10]}' -H 'content-type:application/json' 'http://localhost:8114' #[rpc(name = "get_cells_by_type_hash")] fn get_cells_by_type_hash(&self, H256, BlockNumber, BlockNumber) -> Result>; - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_current_cell","params": [{"hash": "0x1b1c832d02fdb4339f9868c8a8636c3d9dd10bd53ac7ce99595825bd6beeffb3", "index": 1}]}' -H 'content-type:application/json' 'http://localhost:3030' #[rpc(name = "get_current_cell")] fn get_current_cell(&self, OutPoint) -> Result; + + #[rpc(name = "get_tip_block_number")] + fn get_tip_block_number(&self) -> Result; } } @@ -107,6 +104,10 @@ impl ChainRpc for ChainRpcImpl { fn get_current_cell(&self, out_point: OutPoint) -> Result { Ok(self.shared.cell(&out_point).into()) } + + fn get_tip_block_number(&self) -> Result { + Ok(self.shared.tip_header().read().number()) + } } build_rpc_trait! { @@ -175,7 +176,8 @@ impl MinerRpc for MinerRpcImpl { fn submit_block(&self, block: Block) -> Result { let block = Arc::new(block); - if self.chain.process_block(Arc::clone(&block)).is_ok() { + let ret = self.chain.process_block(Arc::clone(&block)); + if ret.is_ok() { // announce new block self.network.with_protocol_context(RELAY_PROTOCOL_ID, |nc| { let fbb = &mut FlatBufferBuilder::new(); @@ -187,11 +189,30 @@ impl MinerRpc for MinerRpcImpl { }); Ok(block.header().hash().clone()) } else { + debug!(target: "rpc", "submit_block process_block {:?}", ret); Err(Error::internal_error()) } } } +build_rpc_trait! { + pub trait NetworkRpc { + // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"send_transaction","params": [{"version":2, "deps":[], "inputs":[], "outputs":[]}]}' -H 'content-type:application/json' 'http://localhost:8114' + #[rpc(name = "local_node_id")] + fn local_node_id(&self) -> Result>; + } +} + +struct NetworkRpcImpl { + pub network: Arc, +} + +impl NetworkRpc for NetworkRpcImpl { + fn local_node_id(&self) -> Result> { + Ok(self.network.external_url()) + } +} + pub struct RpcServer { pub config: Config, } @@ -223,13 +244,14 @@ impl RpcServer { ); io.extend_with( MinerRpcImpl { - network, shared, agent, chain, + network: Arc::clone(&network), } .to_delegate(), ); + io.extend_with(NetworkRpcImpl { network }.to_delegate()); let server = ServerBuilder::new(io) .cors(DomainsValidation::AllowOnly(vec![ diff --git a/spec/src/lib.rs b/spec/src/lib.rs index b532f39e10..4d0bc7a504 100644 --- a/spec/src/lib.rs +++ b/spec/src/lib.rs @@ -2,9 +2,8 @@ //! //! By default, when simply running CKB, CKB will connect to the official public Nervos network. //! -//! In order to run a chain different to the official public one, CKB provide the --chain option or +//! In order to run a chain different to the official public one, //! with a config file specifying chain = "path" under [ckb]. -//! There are a few named presets that can be selected from or a custom yaml spec file can be supplied. use crate::consensus::Consensus; use ckb_core::block::BlockBuilder; diff --git a/src/cli/run_impl.rs b/src/cli/run_impl.rs index 93c3e50a0b..6ab1316cc1 100644 --- a/src/cli/run_impl.rs +++ b/src/cli/run_impl.rs @@ -47,7 +47,7 @@ pub fn run(setup: Setup) { .build(); let _handle = chain_service.start(Some("ChainService"), chain_receivers); - info!(target: "main", "chain genesis hash: {:?}", shared.genesis_hash()); + info!(target: "main", "chain genesis hash: {:#x}", shared.genesis_hash()); let tx_pool_service = TransactionPoolService::new(setup.configs.pool, shared.clone(), notify.clone()); From cae937fa2b806fa81054604d47b6ba2182f94fb9 Mon Sep 17 00:00:00 2001 From: Xuejie Xiao Date: Tue, 18 Dec 2018 09:47:55 +0800 Subject: [PATCH 15/45] feat: add dep cell loading support in syscalls --- script/src/syscalls/load_cell.rs | 4 ++ script/src/syscalls/load_cell_by_field.rs | 4 ++ script/src/syscalls/load_input_by_field.rs | 1 + script/src/syscalls/mod.rs | 65 +++++++++++++++++++--- script/src/verify.rs | 42 +++++++++----- 5 files changed, 93 insertions(+), 23 deletions(-) diff --git a/script/src/syscalls/load_cell.rs b/script/src/syscalls/load_cell.rs index 1f79530da5..5f5bd7fdc8 100644 --- a/script/src/syscalls/load_cell.rs +++ b/script/src/syscalls/load_cell.rs @@ -10,6 +10,7 @@ pub struct LoadCell<'a> { outputs: &'a [&'a CellOutput], input_cells: &'a [&'a CellOutput], current: &'a CellOutput, + dep_cells: &'a [&'a CellOutput], } impl<'a> LoadCell<'a> { @@ -17,11 +18,13 @@ impl<'a> LoadCell<'a> { outputs: &'a [&'a CellOutput], input_cells: &'a [&'a CellOutput], current: &'a CellOutput, + dep_cells: &'a [&'a CellOutput], ) -> LoadCell<'a> { LoadCell { outputs, input_cells, current, + dep_cells, } } @@ -30,6 +33,7 @@ impl<'a> LoadCell<'a> { Source::Input => self.input_cells.get(index).cloned(), Source::Output => self.outputs.get(index).cloned(), Source::Current => Some(self.current), + Source::Dep => self.dep_cells.get(index).cloned(), } } } diff --git a/script/src/syscalls/load_cell_by_field.rs b/script/src/syscalls/load_cell_by_field.rs index d671373725..dbf7dac688 100644 --- a/script/src/syscalls/load_cell_by_field.rs +++ b/script/src/syscalls/load_cell_by_field.rs @@ -12,6 +12,7 @@ pub struct LoadCellByField<'a> { outputs: &'a [&'a CellOutput], input_cells: &'a [&'a CellOutput], current: &'a CellOutput, + dep_cells: &'a [&'a CellOutput], } impl<'a> LoadCellByField<'a> { @@ -19,11 +20,13 @@ impl<'a> LoadCellByField<'a> { outputs: &'a [&'a CellOutput], input_cells: &'a [&'a CellOutput], current: &'a CellOutput, + dep_cells: &'a [&'a CellOutput], ) -> LoadCellByField<'a> { LoadCellByField { outputs, input_cells, current, + dep_cells, } } @@ -32,6 +35,7 @@ impl<'a> LoadCellByField<'a> { Source::Input => self.input_cells.get(index).cloned(), Source::Output => self.outputs.get(index).cloned(), Source::Current => Some(self.current), + Source::Dep => self.dep_cells.get(index).cloned(), } } } diff --git a/script/src/syscalls/load_input_by_field.rs b/script/src/syscalls/load_input_by_field.rs index 19a8e1cd1b..061a4f991e 100644 --- a/script/src/syscalls/load_input_by_field.rs +++ b/script/src/syscalls/load_input_by_field.rs @@ -26,6 +26,7 @@ impl<'a> LoadInputByField<'a> { Source::Input => self.inputs.get(index).cloned(), Source::Output => None, Source::Current => self.current, + Source::Dep => None, } } } diff --git a/script/src/syscalls/mod.rs b/script/src/syscalls/mod.rs index b20c60c011..1004ebb591 100644 --- a/script/src/syscalls/mod.rs +++ b/script/src/syscalls/mod.rs @@ -67,6 +67,7 @@ enum Source { Input, Output, Current, + Dep, } impl Source { @@ -75,6 +76,7 @@ impl Source { 0 => Ok(Source::Input), 1 => Ok(Source::Output), 2 => Ok(Source::Current), + 3 => Ok(Source::Dep), _ => Err(Error::ParseError), } } @@ -231,7 +233,8 @@ mod tests { ); let outputs = vec![&output]; let input_cells = vec![&input_cell]; - let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell); + let dep_cells = vec![]; + let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell, &dep_cells); assert!(load_cell.ecall(&mut machine).is_ok()); assert_eq!(machine.registers()[A0], ITEM_MISSING as u64); @@ -265,7 +268,8 @@ mod tests { ); let outputs = vec![&output]; let input_cells = vec![&input_cell]; - let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell); + let dep_cells = vec![]; + let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell, &dep_cells); let mut builder = FlatBufferBuilder::new(); let fbs_offset = FbsCellOutput::build(&mut builder, &input_cell); @@ -348,7 +352,8 @@ mod tests { ); let outputs = vec![&output]; let input_cells = vec![&input_cell]; - let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell); + let dep_cells = vec![]; + let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell, &dep_cells); let mut builder = FlatBufferBuilder::new(); let fbs_offset = FbsCellOutput::build(&mut builder, &input_cell); @@ -395,7 +400,8 @@ mod tests { ); let outputs = vec![&output]; let input_cells = vec![&input_cell]; - let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell); + let dep_cells = vec![]; + let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell, &dep_cells); let mut builder = FlatBufferBuilder::new(); let fbs_offset = FbsCellOutput::build(&mut builder, &input_cell); @@ -447,7 +453,8 @@ mod tests { ); let outputs = vec![]; let input_cells = vec![]; - let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell); + let dep_cells = vec![]; + let mut load_cell = LoadCell::new(&outputs, &input_cells, &input_cell, &dep_cells); let mut builder = FlatBufferBuilder::new(); let fbs_offset = FbsCellOutput::build(&mut builder, &input_cell); @@ -496,7 +503,8 @@ mod tests { let input_cell = CellOutput::new(capacity, vec![], H256::zero(), None); let outputs = vec![]; let input_cells = vec![&input_cell]; - let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &input_cell); + let dep_cells = vec![]; + let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &input_cell, &dep_cells); assert!(machine.memory_mut().store64(size_addr as usize, 16).is_ok()); @@ -537,7 +545,8 @@ mod tests { let input_cell = CellOutput::new(100, vec![], H256::from_slice(&sha3_data).unwrap(), None); let outputs = vec![]; let input_cells = vec![]; - let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &input_cell); + let dep_cells = vec![]; + let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &input_cell, &dep_cells); assert!(machine.memory_mut().store64(size_addr as usize, 64).is_ok()); @@ -589,7 +598,8 @@ mod tests { let output_cell = CellOutput::new(100, vec![], H256::default(), None); let outputs = vec![&output_cell]; let input_cells = vec![]; - let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &output_cell); + let dep_cells = vec![]; + let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &output_cell, &dep_cells); assert!(machine .memory_mut() @@ -781,4 +791,43 @@ mod tests { assert_eq!(machine.memory_mut().load8(addr), Ok(0)); } } + + fn _test_load_dep_cell_data(data: Vec) { + let mut machine = DefaultCoreMachine::::default(); + let size_addr = 0; + let addr = 100; + + machine.registers_mut()[A0] = addr; // addr + machine.registers_mut()[A1] = size_addr; // size_addr + machine.registers_mut()[A2] = 0; // offset + machine.registers_mut()[A3] = 0; //index + machine.registers_mut()[A4] = 3; //source: 3 dep + machine.registers_mut()[A5] = 1; //field: 1 data + machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number + + let input_cell = CellOutput::new(1000, vec![], H256::zero(), None); + let dep_cell = CellOutput::new(1000, data.clone(), H256::zero(), None); + let outputs = vec![]; + let input_cells = vec![&input_cell]; + let dep_cells = vec![&dep_cell]; + let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &input_cell, &dep_cells); + + assert!(machine.memory_mut().store64(size_addr as usize, data.len() as u64 + 20).is_ok()); + + assert!(load_cell.ecall(&mut machine).is_ok()); + assert_eq!(machine.registers()[A0], SUCCESS as u64); + + assert_eq!(machine.memory_mut().load64(size_addr as usize), Ok(data.len() as u64)); + + for (i, addr) in (addr as usize..addr as usize + data.len() as usize).enumerate() { + assert_eq!(machine.memory_mut().load8(addr), Ok(data[i])); + } + } + + proptest! { + #[test] + fn test_load_dep_cell_data(data in any_with::>(size_range(1000).lift())) { + _test_load_dep_cell_data(data); + } + } } diff --git a/script/src/verify.rs b/script/src/verify.rs index 135e9e8ed2..391aa234d7 100644 --- a/script/src/verify.rs +++ b/script/src/verify.rs @@ -13,25 +13,30 @@ use numext_fixed_hash::H256; // FlatBufferBuilder owned Vec that grows as needed, in the // future, we might refactor this to share buffer to achive zero-copy pub struct TransactionScriptsVerifier<'a> { - dep_cells: FnvHashMap, + dep_cell_index: FnvHashMap, inputs: Vec<&'a CellInput>, outputs: Vec<&'a CellOutput>, tx_builder: FlatBufferBuilder<'a>, input_cells: Vec<&'a CellOutput>, + dep_cells: Vec<&'a CellOutput>, hash: H256, } impl<'a> TransactionScriptsVerifier<'a> { pub fn new(rtx: &'a ResolvedTransaction) -> TransactionScriptsVerifier<'a> { - let dep_cells: FnvHashMap = rtx + let dep_cells: Vec<&'a CellOutput> = rtx .dep_cells .iter() .map(|cell| { - let output = cell - .get_current() - .expect("already verifies that all dep cells are valid"); - let hash = output.data_hash(); - (hash, output) + cell.get_current() + .expect("already verifies that all dep cells are valid") + }) + .collect(); + let dep_cell_index: FnvHashMap = dep_cells + .iter() + .map(|cell| { + let hash = cell.data_hash(); + (hash, *cell) }) .collect(); @@ -52,11 +57,12 @@ impl<'a> TransactionScriptsVerifier<'a> { tx_builder.finish(tx_offset, None); TransactionScriptsVerifier { - dep_cells, + dep_cell_index, inputs, tx_builder, outputs, input_cells, + dep_cells, hash: rtx.transaction.hash().clone(), } } @@ -66,11 +72,21 @@ impl<'a> TransactionScriptsVerifier<'a> { } fn build_load_cell(&self, current_cell: &'a CellOutput) -> LoadCell { - LoadCell::new(&self.outputs, &self.input_cells, current_cell) + LoadCell::new( + &self.outputs, + &self.input_cells, + current_cell, + &self.dep_cells, + ) } fn build_load_cell_by_field(&self, current_cell: &'a CellOutput) -> LoadCellByField { - LoadCellByField::new(&self.outputs, &self.input_cells, current_cell) + LoadCellByField::new( + &self.outputs, + &self.input_cells, + current_cell, + &self.dep_cells, + ) } fn build_load_input_by_field(&self, current_input: Option<&'a CellInput>) -> LoadInputByField { @@ -84,7 +100,7 @@ impl<'a> TransactionScriptsVerifier<'a> { return Ok(data); } if let Some(ref hash) = script.reference { - return match self.dep_cells.get(hash) { + return match self.dep_cell_index.get(hash) { Some(ref cell_output) => Ok(&cell_output.data), None => Err(ScriptError::InvalidReferenceIndex), }; @@ -153,7 +169,6 @@ mod tests { use ckb_core::Capacity; use crypto::secp::Generator; use faster_hex::hex_to; - use fnv::FnvHashMap; use hash::sha3_256; use numext_fixed_hash::H256; use std::fs::File; @@ -290,9 +305,6 @@ mod tests { let dep_out_point = OutPoint::new(H256::from_trimmed_hex_str("123").unwrap(), 8); let dep_cell = CellOutput::new(buffer.len() as Capacity, buffer, H256::zero(), None); - let mut dep_cells = FnvHashMap::default(); - dep_cells.insert(&dep_out_point, &dep_cell); - let privkey = privkey.pubkey().unwrap().serialize(); let mut hex_privkey = vec![0; privkey.len() * 2]; hex_to(&privkey, &mut hex_privkey).expect("hex privkey"); From 2d0a3785c884051d6080f7e426f410cd56b77590 Mon Sep 17 00:00:00 2001 From: Xuejie Xiao Date: Tue, 18 Dec 2018 09:54:05 +0800 Subject: [PATCH 16/45] feat: add DATA_HASH field type in Load Cell By Field --- script/src/syscalls/load_cell_by_field.rs | 4 ++ script/src/syscalls/mod.rs | 59 ++++++++++++++++++++++- 2 files changed, 61 insertions(+), 2 deletions(-) diff --git a/script/src/syscalls/load_cell_by_field.rs b/script/src/syscalls/load_cell_by_field.rs index dbf7dac688..0aa6f823cb 100644 --- a/script/src/syscalls/load_cell_by_field.rs +++ b/script/src/syscalls/load_cell_by_field.rs @@ -72,6 +72,10 @@ impl<'a, R: Register, M: Memory> Syscalls for LoadCellByField<'a> { store_data(machine, &cell.data)?; SUCCESS } + CellField::DataHash => { + store_data(machine, &cell.data_hash().as_bytes())?; + SUCCESS + } CellField::LockHash => { store_data(machine, &cell.lock.as_bytes())?; SUCCESS diff --git a/script/src/syscalls/mod.rs b/script/src/syscalls/mod.rs index 1004ebb591..02b4413099 100644 --- a/script/src/syscalls/mod.rs +++ b/script/src/syscalls/mod.rs @@ -28,6 +28,7 @@ pub const DEBUG_PRINT_SYSCALL_NUMBER: u64 = 2177; enum CellField { Capacity, Data, + DataHash, LockHash, Contract, ContractHash, @@ -41,6 +42,7 @@ impl CellField { 2 => Ok(CellField::LockHash), 3 => Ok(CellField::Contract), 4 => Ok(CellField::ContractHash), + 5 => Ok(CellField::DataHash), _ => Err(Error::ParseError), } } @@ -812,12 +814,18 @@ mod tests { let dep_cells = vec![&dep_cell]; let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &input_cell, &dep_cells); - assert!(machine.memory_mut().store64(size_addr as usize, data.len() as u64 + 20).is_ok()); + assert!(machine + .memory_mut() + .store64(size_addr as usize, data.len() as u64 + 20) + .is_ok()); assert!(load_cell.ecall(&mut machine).is_ok()); assert_eq!(machine.registers()[A0], SUCCESS as u64); - assert_eq!(machine.memory_mut().load64(size_addr as usize), Ok(data.len() as u64)); + assert_eq!( + machine.memory_mut().load64(size_addr as usize), + Ok(data.len() as u64) + ); for (i, addr) in (addr as usize..addr as usize + data.len() as usize).enumerate() { assert_eq!(machine.memory_mut().load8(addr), Ok(data[i])); @@ -830,4 +838,51 @@ mod tests { _test_load_dep_cell_data(data); } } + + fn _test_load_dep_cell_data_hash(data: Vec) { + let mut machine = DefaultCoreMachine::::default(); + let size_addr = 0; + let addr = 100; + + machine.registers_mut()[A0] = addr; // addr + machine.registers_mut()[A1] = size_addr; // size_addr + machine.registers_mut()[A2] = 0; // offset + machine.registers_mut()[A3] = 0; //index + machine.registers_mut()[A4] = 3; //source: 3 dep + machine.registers_mut()[A5] = 5; //field: 5 data hash + machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number + + let input_cell = CellOutput::new(1000, vec![], H256::zero(), None); + let dep_cell = CellOutput::new(1000, data.clone(), H256::zero(), None); + let outputs = vec![]; + let input_cells = vec![&input_cell]; + let dep_cells = vec![&dep_cell]; + let mut load_cell = LoadCellByField::new(&outputs, &input_cells, &input_cell, &dep_cells); + + let data_hash = sha3_256(&data); + + assert!(machine + .memory_mut() + .store64(size_addr as usize, data_hash.len() as u64 + 20) + .is_ok()); + + assert!(load_cell.ecall(&mut machine).is_ok()); + assert_eq!(machine.registers()[A0], SUCCESS as u64); + + assert_eq!( + machine.memory_mut().load64(size_addr as usize), + Ok(data_hash.len() as u64) + ); + + for (i, addr) in (addr as usize..addr as usize + data_hash.len() as usize).enumerate() { + assert_eq!(machine.memory_mut().load8(addr), Ok(data_hash[i])); + } + } + + proptest! { + #[test] + fn test_load_dep_cell_data_hash(data in any_with::>(size_range(1000).lift())) { + _test_load_dep_cell_data_hash(data); + } + } } From c55e07697a02392e09d181228c69fd72f78c62ce Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Tue, 18 Dec 2018 10:26:09 +0800 Subject: [PATCH 17/45] fix: cli panic --- src/cli/args.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/args.rs b/src/cli/args.rs index 7974ad6f42..de8abbf94c 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -10,7 +10,7 @@ pub fn get_matches() -> ArgMatches<'static> { .about("Nervos CKB - The Common Knowledge Base") .version(version.short().as_str()) .long_version(version.long().as_str()) - .setting(AppSettings::ArgRequiredElseHelp) + .setting(AppSettings::SubcommandRequiredElseHelp) .arg( Arg::with_name("config") .short("c") From 49fc5131b156aa2a70353eee6b5649bd428cce4d Mon Sep 17 00:00:00 2001 From: Xuejie Xiao Date: Tue, 18 Dec 2018 12:40:45 +0800 Subject: [PATCH 18/45] refactor: use serialized flatbuffer format in referenced cell This enables embedding signed args in common cells --- Cargo.lock | 2 + script/src/lib.rs | 1 + script/src/verify.rs | 89 +++++++++++++++++++++++++++++--------------- spec/Cargo.toml | 2 + spec/src/lib.rs | 16 +++++++- 5 files changed, 79 insertions(+), 31 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c8b5b190b..fcc6d2668f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -386,6 +386,8 @@ version = "0.3.0-pre" dependencies = [ "ckb-core 0.3.0-pre", "ckb-pow 0.3.0-pre", + "ckb-protocol 0.3.0-pre", + "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/script/src/lib.rs b/script/src/lib.rs index f10ede1845..18f13b4837 100644 --- a/script/src/lib.rs +++ b/script/src/lib.rs @@ -9,6 +9,7 @@ pub use crate::verify::TransactionScriptsVerifier; pub enum ScriptError { NoScript, InvalidReferenceIndex, + ArgumentError, ValidationFailure(u8), VMError(VMInternalError), } diff --git a/script/src/verify.rs b/script/src/verify.rs index 391aa234d7..873bf5c367 100644 --- a/script/src/verify.rs +++ b/script/src/verify.rs @@ -3,8 +3,9 @@ use crate::ScriptError; use ckb_core::cell::ResolvedTransaction; use ckb_core::script::Script; use ckb_core::transaction::{CellInput, CellOutput}; +use ckb_protocol::{FlatbuffersVectorIterator, Script as FbsScript}; use ckb_vm::{DefaultMachine, SparseMemory}; -use flatbuffers::FlatBufferBuilder; +use flatbuffers::{get_root, FlatBufferBuilder}; use fnv::FnvHashMap; use log::info; use numext_fixed_hash::H256; @@ -94,14 +95,40 @@ impl<'a> TransactionScriptsVerifier<'a> { } // Script struct might contain references to external cells, this - // method exacts the real script from Stript struct. - fn extract_script(&self, script: &'a Script) -> Result<&'a [u8], ScriptError> { + // method exacts the referenced script if any. It also fills signed args + // so we don't need to do a second time of memory copy + fn extract_script( + &self, + script: &'a Script, + signed_args: &mut Vec>, + ) -> Result<&'a [u8], ScriptError> { if let Some(ref data) = script.binary { + signed_args.extend_from_slice(&script.signed_args); return Ok(data); } if let Some(ref hash) = script.reference { return match self.dep_cell_index.get(hash) { - Some(ref cell_output) => Ok(&cell_output.data), + Some(ref cell_output) => { + let fbs_script = get_root::(&cell_output.data); + // This way we can avoid copying the actual script binary one more + // time, which could be a lot of data. + let binary = fbs_script + .binary() + .and_then(|s| s.seq()) + .ok_or(ScriptError::NoScript)?; + // When the reference script has signed arguments, we will concat + // signed arguments from the reference script with the signed + // arguments from the main script together. + if let Some(args) = fbs_script.signed_args() { + let args: Option>> = FlatbuffersVectorIterator::new(args) + .map(|arg| arg.seq().map(|s| s.to_vec())) + .collect(); + let args = args.ok_or(ScriptError::ArgumentError)?; + signed_args.extend_from_slice(&args); + signed_args.extend_from_slice(&script.signed_args); + } + Ok(binary) + } None => Err(ScriptError::InvalidReferenceIndex), }; } @@ -115,28 +142,28 @@ impl<'a> TransactionScriptsVerifier<'a> { current_cell: &'a CellOutput, current_input: Option<&'a CellInput>, ) -> Result<(), ScriptError> { - self.extract_script(script).and_then(|script_binary| { - let mut args = vec![b"verify".to_vec()]; - args.extend_from_slice(&script.signed_args.as_slice()); - args.extend_from_slice(&script.args.as_slice()); - - let mut machine = DefaultMachine::::default(); - machine.add_syscall_module(Box::new(self.build_load_tx())); - machine.add_syscall_module(Box::new(self.build_load_cell(current_cell))); - machine.add_syscall_module(Box::new(self.build_load_cell_by_field(current_cell))); - machine.add_syscall_module(Box::new(self.build_load_input_by_field(current_input))); - machine.add_syscall_module(Box::new(Debugger::new(prefix))); - machine - .run(script_binary, &args) - .map_err(ScriptError::VMError) - .and_then(|code| { - if code == 0 { - Ok(()) - } else { - Err(ScriptError::ValidationFailure(code)) - } - }) - }) + let mut args = vec![b"verify".to_vec()]; + self.extract_script(script, &mut args) + .and_then(|script_binary| { + args.extend_from_slice(&script.args.as_slice()); + + let mut machine = DefaultMachine::::default(); + machine.add_syscall_module(Box::new(self.build_load_tx())); + machine.add_syscall_module(Box::new(self.build_load_cell(current_cell))); + machine.add_syscall_module(Box::new(self.build_load_cell_by_field(current_cell))); + machine.add_syscall_module(Box::new(self.build_load_input_by_field(current_input))); + machine.add_syscall_module(Box::new(Debugger::new(prefix))); + machine + .run(script_binary, &args) + .map_err(ScriptError::VMError) + .and_then(|code| { + if code == 0 { + Ok(()) + } else { + Err(ScriptError::ValidationFailure(code)) + } + }) + }) } pub fn verify(&self) -> Result<(), ScriptError> { @@ -287,6 +314,12 @@ mod tests { let mut buffer = Vec::new(); file.read_to_end(&mut buffer).unwrap(); + let script = Script::new(0, vec![], None, Some(buffer), vec![]); + let mut builder = FlatBufferBuilder::new(); + let offset = FbsScript::build(&mut builder, &script); + builder.finish(offset, None); + let buffer = builder.finished_data().to_vec(); + let gen = Generator::new(); let privkey = gen.random_privkey(); let mut args = vec![b"foo".to_vec(), b"bar".to_vec()]; @@ -332,10 +365,6 @@ mod tests { #[test] fn check_invalid_dep_reference() { - let mut file = open_cell_verify(); - let mut buffer = Vec::new(); - file.read_to_end(&mut buffer).unwrap(); - let gen = Generator::new(); let privkey = gen.random_privkey(); let mut args = vec![b"foo".to_vec(), b"bar".to_vec()]; diff --git a/spec/Cargo.toml b/spec/Cargo.toml index 084dae296c..b35a8ca91a 100644 --- a/spec/Cargo.toml +++ b/spec/Cargo.toml @@ -13,3 +13,5 @@ ckb-core = { path = "../core" } serde_derive = "1.0" serde = "1.0" ckb-pow = { path = "../pow" } +ckb-protocol = { path = "../protocol" } +flatbuffers = "0.5.0" diff --git a/spec/src/lib.rs b/spec/src/lib.rs index b532f39e10..12b894d369 100644 --- a/spec/src/lib.rs +++ b/spec/src/lib.rs @@ -9,9 +9,12 @@ use crate::consensus::Consensus; use ckb_core::block::BlockBuilder; use ckb_core::header::HeaderBuilder; +use ckb_core::script::Script; use ckb_core::transaction::{CellOutput, Transaction, TransactionBuilder}; use ckb_core::Capacity; use ckb_pow::{Pow, PowEngine}; +use ckb_protocol::Script as FbsScript; +use flatbuffers::FlatBufferBuilder; use numext_fixed_hash::H256; use numext_fixed_uint::U256; use serde_derive::Deserialize; @@ -68,9 +71,20 @@ fn build_system_cell_transaction(cells: &[SystemCell]) -> Result Date: Mon, 10 Dec 2018 17:49:26 +0800 Subject: [PATCH 19/45] refactor: change remote_addresses to connected_addr in PeerConnection --- network/src/ckb_service.rs | 7 +++-- network/src/identify_service.rs | 2 +- network/src/network.rs | 46 ++++++++++++++++++--------------- network/src/peers_registry.rs | 35 +++++++------------------ network/src/protocol.rs | 2 +- 5 files changed, 40 insertions(+), 52 deletions(-) diff --git a/network/src/ckb_service.rs b/network/src/ckb_service.rs index 875bc38d8f..04e26cf47b 100644 --- a/network/src/ckb_service.rs +++ b/network/src/ckb_service.rs @@ -29,16 +29,15 @@ impl CKBService { peer_id: PeerId, protocol_output: CKBProtocolOutput>, kad_system: Arc, - addr: Option, + addr: Multiaddr, ) -> Box + Send> { let protocol_id = protocol_output.protocol_id; let protocol_handler = protocol_output.protocol_handler; let protocol_version = protocol_output.protocol_version; let endpoint = protocol_output.endpoint; - let addresses = addr.map(|addr| vec![addr]); // get peer protocol_connection let protocol_connec = - match network.ckb_protocol_connec(&peer_id, protocol_id, endpoint, addresses.clone()) { + match network.ckb_protocol_connec(&peer_id, protocol_id, endpoint, addr) { Ok(protocol_connec) => protocol_connec, Err(err) => { return Box::new(future::err(IoError::new( @@ -157,7 +156,7 @@ impl ProtocolService for CKBService { addr: &Multiaddr, output: Self::Output, ) -> Protocol { - Protocol::CKBProtocol(output, PeerId::clone(&peer_id), Some(addr.to_owned())) + Protocol::CKBProtocol(output, PeerId::clone(&peer_id), addr.to_owned()) } fn handle( &self, diff --git a/network/src/identify_service.rs b/network/src/identify_service.rs index 50f78d9e28..d1a58e5ee9 100644 --- a/network/src/identify_service.rs +++ b/network/src/identify_service.rs @@ -204,7 +204,7 @@ where } } // TODO should we try all addresses? - if let Some(addr) = network.get_peer_remote_addresses(&peer_id).get(0) { + if let Some(addr) = network.get_peer_addresses(&peer_id).get(0) { trace!( target: "network", "request identify to peer {:?} {:?}", diff --git a/network/src/network.rs b/network/src/network.rs index 13f454da8b..1aaf36f2cd 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -39,6 +39,7 @@ use tokio::io::{AsyncRead, AsyncWrite}; // const WAIT_LOCK_TIMEOUT: u64 = 3; const KBUCKETS_TIMEOUT: u64 = 600; const DIAL_BOOTNODE_TIMEOUT: u64 = 20; +const PEER_ADDRS_COUNT: usize = 5; #[derive(Debug, Clone)] pub struct SessionInfo { @@ -51,7 +52,7 @@ pub struct PeerInfo { pub peer_id: PeerId, pub endpoint_role: Endpoint, pub last_ping_time: Option, - pub remote_addresses: Vec, + pub connected_addr: Multiaddr, pub identify_info: Option, } @@ -139,13 +140,14 @@ impl Network { .map(|peer| peer.pinger_loader.clone()) } - pub(crate) fn get_peer_remote_addresses(&self, peer_id: &PeerId) -> Vec { - let peers_registry = self.peers_registry.read(); - if let Some(peer) = peers_registry.get(peer_id) { - peer.remote_addresses.clone() - } else { - Vec::new() - } + pub(crate) fn get_peer_addresses(&self, peer_id: &PeerId) -> Vec { + let peer_store = self.peer_store.read(); + let addrs = peer_store.peer_addrs(&peer_id).map(|i| { + i.take(PEER_ADDRS_COUNT) + .map(|addr| addr.to_owned()) + .collect::>() + }); + addrs.unwrap_or(Vec::new()) } pub(crate) fn peers(&self) -> impl Iterator { @@ -231,16 +233,17 @@ impl Network { peer_id: &PeerId, protocol_id: ProtocolId, endpoint: Endpoint, - addresses: Option>, + connected_addr: Multiaddr, ) -> Result, u8)>, Error> { let mut peers_registry = self.peers_registry.write(); // get peer protocol_connection - match peers_registry.new_peer(peer_id.clone(), endpoint) { + match peers_registry.new_peer(peer_id.clone(), connected_addr.clone(), endpoint) { Ok(_) => { - let peer = peers_registry.get_mut(&peer_id).unwrap(); - if let Some(addresses) = addresses { - peer.append_addresses(addresses.clone()); - } + let _ = self + .peer_store() + .write() + .add_discovered_addresses(peer_id, vec![connected_addr]); + let mut peer = peers_registry.get_mut(&peer_id).unwrap(); if let Some(protocol_connec) = peer .ckb_protocols .iter() @@ -285,7 +288,7 @@ impl Network { peer_id: peer_id.to_owned(), endpoint_role: peer.endpoint_role, last_ping_time: peer.last_ping_time, - remote_addresses: peer.remote_addresses.clone(), + connected_addr: peer.connected_addr.clone(), identify_info: peer.identify_info.clone(), }, protocol_version, @@ -372,29 +375,30 @@ impl Network { ); let protocol_id = protocol.id(); - let transport = transport - .clone() - .and_then(move |out, endpoint, client_addr| { + let transport = transport.clone().and_then({ + let addr = addr.clone(); + move |out, endpoint, client_addr| { let peer_id = out.peer_id; upgrade::apply(out.socket, protocol, endpoint, client_addr).map( move |(output, client_addr)| { ( ( peer_id.clone(), - Protocol::CKBProtocol(output, peer_id, None), + Protocol::CKBProtocol(output, peer_id, addr), ), client_addr, ) }, ) - }); + } + }); let transport = TransportTimeout::new(transport, timeout); let unique_connec = match self.ckb_protocol_connec( expected_peer_id, protocol_id, Endpoint::Dialer, - Some(vec![addr.to_owned()]), + addr.to_owned(), ) { Ok(unique_connec) => unique_connec, Err(_) => return, diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index e046ece8c8..2aebca5b48 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -88,7 +88,7 @@ type ProtocolConnec = (ProtocolId, UniqueConnec<(UnboundedSender, u8)>); pub struct PeerConnection { pub(crate) peer_index: Option, - pub remote_addresses: Vec, + pub connected_addr: Multiaddr, // Dialer or Listener pub endpoint_role: Endpoint, // Used for send ping to peer @@ -99,11 +99,10 @@ pub struct PeerConnection { } impl PeerConnection { - pub fn new(endpoint_role: Endpoint) -> Self { + pub fn new(connected_addr: Multiaddr, endpoint_role: Endpoint) -> Self { PeerConnection { endpoint_role, - // at least should have 1 remote address - remote_addresses: Vec::with_capacity(1), + connected_addr: connected_addr, pinger_loader: UniqueConnec::empty(), identify_info: None, ckb_protocols: Vec::with_capacity(1), @@ -112,14 +111,6 @@ impl PeerConnection { } } - pub fn append_addresses(&mut self, addresses: Vec) { - for addr in addresses { - if !self.remote_addresses.contains(&addr) { - self.remote_addresses.push(addr); - } - } - } - #[inline] pub fn is_outgoing(&self) -> bool { self.endpoint_role == Endpoint::Dialer @@ -130,17 +121,6 @@ impl PeerConnection { pub fn is_incoming(&self) -> bool { !self.is_outgoing() } - - #[allow(dead_code)] - pub fn add_remote_address(&mut self, remote_address: Multiaddr) { - if self - .remote_addresses - .iter() - .all(|addr| addr != &remote_address) - { - self.remote_addresses.push(remote_address); - } - } } pub struct ConnectionStatus { @@ -190,7 +170,12 @@ impl PeersRegistry { // registry a new peer #[allow(clippy::needless_pass_by_value)] - pub fn new_peer(&mut self, peer_id: PeerId, endpoint: Endpoint) -> Result<(), Error> { + pub fn new_peer( + &mut self, + peer_id: PeerId, + connected_addr: Multiaddr, + endpoint: Endpoint, + ) -> Result<(), Error> { if self.peer_connections.get(&peer_id).is_some() { return Ok(()); } @@ -231,7 +216,7 @@ impl PeersRegistry { _ => (), } } - let peer = PeerConnection::new(endpoint); + let peer = PeerConnection::new(connected_addr, endpoint); let peer_index = self.add_peer(peer_id.clone(), peer); debug!(target: "network", "allocate peer_index {} to peer {:?}", peer_index, peer_id); Ok(()) diff --git a/network/src/protocol.rs b/network/src/protocol.rs index d0248e1c8a..d715f52cc1 100644 --- a/network/src/protocol.rs +++ b/network/src/protocol.rs @@ -25,6 +25,6 @@ pub enum Protocol { CKBProtocol( CKBProtocolOutput>, PeerId, - Option, + Multiaddr, ), } From e1e5750835a965c7d061da53ab0f2cebd13b04c9 Mon Sep 17 00:00:00 2001 From: jjy Date: Mon, 10 Dec 2018 17:56:15 +0800 Subject: [PATCH 20/45] feat: impl NetworkGroup for peer and multiaddr --- network/src/lib.rs | 5 +++- network/src/network.rs | 2 +- network/src/network_group.rs | 49 +++++++++++++++++++++++++++++++++++ network/src/peers_registry.rs | 9 ++++++- network/src/ping_service.rs | 2 +- sync/src/synchronizer/mod.rs | 4 +-- 6 files changed, 65 insertions(+), 6 deletions(-) create mode 100644 network/src/network_group.rs diff --git a/network/src/lib.rs b/network/src/lib.rs index b84ce1e9a0..c2b9fb539b 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -9,6 +9,7 @@ mod identify_service; mod memory_peer_store; mod network; mod network_config; +mod network_group; mod network_service; mod outgoing_service; mod peer_store; @@ -25,7 +26,9 @@ pub use crate::errors::{Error, ErrorKind}; pub use crate::network::{Network, PeerInfo, SessionInfo}; pub use crate::network_config::NetworkConfig; pub use crate::network_service::NetworkService; -pub use libp2p::{core::Endpoint, multiaddr::AddrComponent, Multiaddr, PeerId}; +pub use libp2p::{ + core::Endpoint, multiaddr::AddrComponent, multiaddr::ToMultiaddr, Multiaddr, PeerId, +}; pub type TimerToken = usize; pub type ProtocolId = [u8; 3]; diff --git a/network/src/network.rs b/network/src/network.rs index 1aaf36f2cd..92ab7a821e 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -147,7 +147,7 @@ impl Network { .map(|addr| addr.to_owned()) .collect::>() }); - addrs.unwrap_or(Vec::new()) + addrs.unwrap_or_default() } pub(crate) fn peers(&self) -> impl Iterator { diff --git a/network/src/network_group.rs b/network/src/network_group.rs new file mode 100644 index 0000000000..8405f11171 --- /dev/null +++ b/network/src/network_group.rs @@ -0,0 +1,49 @@ +use libp2p::core::{AddrComponent, Multiaddr}; +use std::net::IpAddr; + +pub type Group = Vec; + +pub trait NetworkGroup { + fn network_group(&self) -> Group; +} + +fn extract_ip_addr(addr: &Multiaddr) -> Option { + for addr_component in addr { + match addr_component { + AddrComponent::IP4(ipv4) => return Some(IpAddr::V4(ipv4)), + AddrComponent::IP6(ipv6) => return Some(IpAddr::V6(ipv6)), + _ => (), + } + } + None +} + +impl NetworkGroup for Multiaddr { + fn network_group(&self) -> Group { + if let Some(ip_addr) = extract_ip_addr(self) { + if ip_addr.is_loopback() { + // Local NetworkGroup + return vec![1]; + } + // TODO uncomment after ip feature stable + // if !ip_addr.is_global() { + // // Global NetworkGroup + // return vec![2] + // } + + // IPv4 NetworkGroup + if let IpAddr::V4(ipv4) = ip_addr { + return ipv4.octets()[0..2].to_vec(); + } + // IPv6 NetworkGroup + if let IpAddr::V6(ipv6) = ip_addr { + if let Some(ipv4) = ipv6.to_ipv4() { + return ipv4.octets()[0..2].to_vec(); + } + return ipv6.octets()[0..4].to_vec(); + } + } + // Can't group addr + vec![0] + } +} diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index 2aebca5b48..0208c4c450 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -1,3 +1,4 @@ +use crate::network_group::{Group, NetworkGroup}; use crate::peer_store::PeerStore; use crate::{Error, ErrorKind, PeerId, PeerIndex, ProtocolId}; use bytes::Bytes; @@ -102,7 +103,7 @@ impl PeerConnection { pub fn new(connected_addr: Multiaddr, endpoint_role: Endpoint) -> Self { PeerConnection { endpoint_role, - connected_addr: connected_addr, + connected_addr, pinger_loader: UniqueConnec::empty(), identify_info: None, ckb_protocols: Vec::with_capacity(1), @@ -121,6 +122,12 @@ impl PeerConnection { pub fn is_incoming(&self) -> bool { !self.is_outgoing() } + + #[allow(dead_code)] + #[inline] + fn network_group(&self) -> Group { + self.connected_addr.network_group() + } } pub struct ConnectionStatus { diff --git a/network/src/ping_service.rs b/network/src/ping_service.rs index cc612398e8..0d08827f37 100644 --- a/network/src/ping_service.rs +++ b/network/src/ping_service.rs @@ -125,7 +125,7 @@ impl ProtocolService for PingService { for peer_id in network.peers() { let peer_id = peer_id.clone(); // only ping first address? - if let Some(addr) = network.get_peer_remote_addresses(&peer_id).get(0) { + if let Some(addr) = network.get_peer_addresses(&peer_id).get(0) { if let Some(pinger_loader) = network.get_peer_pinger(&peer_id) { let ping_future = pinger_loader .dial(&swarm_controller, &addr, transport.clone()) diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 65d215aff7..8ae472be18 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -716,7 +716,7 @@ mod tests { use ckb_db::memorydb::MemoryKeyValueDB; use ckb_network::{ random_peer_id, CKBProtocolContext, Endpoint, Error as NetworkError, PeerIndex, PeerInfo, - ProtocolId, SessionInfo, Severity, TimerToken, + ProtocolId, SessionInfo, Severity, TimerToken, ToMultiaddr, }; use ckb_notify::{NotifyController, NotifyService}; use ckb_protocol::{Block as FbsBlock, Headers as FbsHeaders}; @@ -1034,7 +1034,7 @@ mod tests { peer_id: random_peer_id().unwrap(), endpoint_role: Endpoint::Dialer, last_ping_time: None, - remote_addresses: vec![], + connected_addr: "/ip4/127.0.0.1".to_multiaddr().unwrap(), identify_info: None, }, protocol_version: None, From d0db77e194b3bd419e6b70c3aad12d736bc0697b Mon Sep 17 00:00:00 2001 From: jjy Date: Tue, 11 Dec 2018 17:42:10 +0800 Subject: [PATCH 21/45] feat: try evict inbound peers when inbound slots is full --- Cargo.lock | 2 +- network/Cargo.toml | 2 +- network/src/ckb_service.rs | 29 +++-- network/src/memory_peer_store.rs | 42 ++----- network/src/network.rs | 157 +++++++++++++++------------ network/src/network_service.rs | 5 - network/src/peer_store.rs | 16 +-- network/src/peers_registry.rs | 181 ++++++++++++++++++++++--------- 8 files changed, 254 insertions(+), 180 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c8b5b190b..196a47525a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -470,7 +470,7 @@ dependencies = [ "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "snap 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/network/Cargo.toml b/network/Cargo.toml index 0b541cb359..8c7da3cca1 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -6,7 +6,7 @@ authors = ["Nervos Core Dev "] edition = "2018" [dependencies] -rand = "0.5" +rand = "0.6" fnv = "1.0" serde = "1.0" serde_derive = "1.0" diff --git a/network/src/ckb_service.rs b/network/src/ckb_service.rs index 04e26cf47b..eac2502b03 100644 --- a/network/src/ckb_service.rs +++ b/network/src/ckb_service.rs @@ -10,7 +10,7 @@ use crate::Network; use crate::PeerId; use futures::future::{self, Future}; use futures::Stream; -use libp2p::core::{Multiaddr, UniqueConnecState}; +use libp2p::core::{Endpoint, Multiaddr, UniqueConnecState}; use libp2p::kad; use log::{error, info}; use std::boxed::Box; @@ -36,16 +36,23 @@ impl CKBService { let protocol_version = protocol_output.protocol_version; let endpoint = protocol_output.endpoint; // get peer protocol_connection - let protocol_connec = - match network.ckb_protocol_connec(&peer_id, protocol_id, endpoint, addr) { - Ok(protocol_connec) => protocol_connec, - Err(err) => { - return Box::new(future::err(IoError::new( - IoErrorKind::Other, - format!("handle ckb_protocol connection error: {}", err), - ))) as Box + Send> + let protocol_connec = { + let result = match endpoint { + Endpoint::Dialer => { + network.try_outbound_ckb_protocol_connec(&peer_id, protocol_id, addr) + } + Endpoint::Listener => { + network.try_inbound_ckb_protocol_connec(&peer_id, protocol_id, addr) } }; + if let Err(err) = result { + return Box::new(future::err(IoError::new( + IoErrorKind::Other, + format!("handle ckb_protocol connection error: {}", err), + ))) as Box + Send>; + } + result.unwrap() + }; if protocol_connec.state() == UniqueConnecState::Full { error!( target: "network", @@ -107,7 +114,7 @@ impl CKBService { { let mut peer_store = network.peer_store().write(); peer_store.report(&peer_id, Behaviour::UnexpectedDisconnect); - peer_store.report_status(&peer_id, Status::Disconnected); + peer_store.update_status(&peer_id, Status::Disconnected); } protocol_handler.disconnected( Box::new(DefaultCKBProtocolContext::new( @@ -130,7 +137,7 @@ impl CKBService { { let mut peer_store = network.peer_store().write(); peer_store.report(&peer_id, Behaviour::Connect); - peer_store.report_status(&peer_id, Status::Connected); + peer_store.update_status(&peer_id, Status::Connected); } { let handle_connected = future::lazy(move || { diff --git a/network/src/memory_peer_store.rs b/network/src/memory_peer_store.rs index bbde3b8fc4..47519b7cc9 100644 --- a/network/src/memory_peer_store.rs +++ b/network/src/memory_peer_store.rs @@ -1,4 +1,4 @@ -use crate::peer_store::{Behaviour, PeerStore, Status}; +use crate::peer_store::{Behaviour, PeerStore, Score, Status}; use crate::PeerId; use fnv::FnvHashMap; use libp2p::core::Multiaddr; @@ -23,7 +23,6 @@ struct PeerInfo { pub struct MemoryPeerStore { bootnodes: Vec<(PeerId, Multiaddr)>, peers: FnvHashMap, - reserved_nodes: FnvHashMap>, } impl MemoryPeerStore { @@ -31,7 +30,6 @@ impl MemoryPeerStore { let mut peer_store = MemoryPeerStore { bootnodes: bootnodes.clone(), peers: Default::default(), - reserved_nodes: Default::default(), }; for (peer_id, addr) in bootnodes { peer_store.add_peer(peer_id, vec![addr]); @@ -56,6 +54,11 @@ impl MemoryPeerStore { } impl PeerStore for MemoryPeerStore { + fn add_discovered_address(&mut self, peer_id: &PeerId, address: Multiaddr) -> Result<(), ()> { + self.add_discovered_addresses(peer_id, vec![address]) + .map(|_| ()) + } + fn add_discovered_addresses( &mut self, peer_id: &PeerId, @@ -78,10 +81,7 @@ impl PeerStore for MemoryPeerStore { } // TODO fn report(&mut self, _peer_id: &PeerId, _behaviour: Behaviour) {} - // TODO - fn report_address(&mut self, _address: &Multiaddr, _behaviour: Behaviour) {} - // TODO - fn report_status(&mut self, peer_id: &PeerId, status: Status) { + fn update_status(&mut self, peer_id: &PeerId, status: Status) { if let Some(peer) = self.peers.get_mut(&peer_id) { let now = Instant::now(); peer.last_updated_at = now; @@ -95,6 +95,10 @@ impl PeerStore for MemoryPeerStore { None => Status::Unknown, } } + //TODO + fn peer_score(&self, _peer_id: &PeerId) -> Score { + 0 + } fn bootnodes<'a>(&'a self) -> Box + 'a> { let mut bootnodes = self @@ -130,28 +134,4 @@ impl PeerStore for MemoryPeerStore { }); Box::new(peers) as Box<_> } - - fn reserved_nodes<'a>(&'a self) -> Box + 'a> { - let iter = - self.reserved_nodes - .iter() - .filter_map(move |(peer_id, addresses)| match addresses.get(0) { - Some(address) => Some((peer_id, address)), - None => None, - }); - Box::new(iter) as Box<_> - } - fn is_reserved(&self, peer_id: &PeerId) -> bool { - self.reserved_nodes.contains_key(peer_id) - } - fn add_reserved_node( - &mut self, - peer_id: PeerId, - addresses: Vec, - ) -> Option> { - self.reserved_nodes.insert(peer_id, addresses) - } - fn remove_reserved_node(&mut self, peer_id: &PeerId) -> Option> { - self.reserved_nodes.remove(peer_id) - } } diff --git a/network/src/network.rs b/network/src/network.rs index 92ab7a821e..1eb40017da 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -87,11 +87,6 @@ impl Network { &self.local_peer_id } - pub(crate) fn add_peer(&self, peer_id: PeerId, peer: PeerConnection) { - let mut peers_registry = self.peers_registry.write(); - peers_registry.add_peer(peer_id, peer); - } - pub(crate) fn get_peer_index(&self, peer_id: &PeerId) -> Option { let peers_registry = self.peers_registry.read(); peers_registry @@ -228,35 +223,60 @@ impl Network { Err(ErrorKind::PeerNotFound.into()) } } - pub(crate) fn ckb_protocol_connec( + + fn ckb_protocol_connec( + &self, + peer: &mut PeerConnection, + protocol_id: ProtocolId, + ) -> UniqueConnec<(UnboundedSender, u8)> { + peer.ckb_protocols + .iter() + .find(|&(id, _)| id == &protocol_id) + .map(|(_, ref protocol_connec)| protocol_connec.clone()) + .unwrap_or_else(|| { + let protocol_connec = UniqueConnec::empty(); + peer.ckb_protocols + .push((protocol_id, protocol_connec.clone())); + protocol_connec + }) + } + pub(crate) fn try_outbound_ckb_protocol_connec( &self, peer_id: &PeerId, protocol_id: ProtocolId, - endpoint: Endpoint, connected_addr: Multiaddr, ) -> Result, u8)>, Error> { let mut peers_registry = self.peers_registry.write(); // get peer protocol_connection - match peers_registry.new_peer(peer_id.clone(), connected_addr.clone(), endpoint) { + match peers_registry.try_outbound_peer(peer_id.clone(), connected_addr.clone()) { Ok(_) => { let _ = self .peer_store() .write() - .add_discovered_addresses(peer_id, vec![connected_addr]); + .add_discovered_address(peer_id, connected_addr); let mut peer = peers_registry.get_mut(&peer_id).unwrap(); - if let Some(protocol_connec) = peer - .ckb_protocols - .iter() - .find(|&(id, _)| id == &protocol_id) - .map(|(_, ref protocol_connec)| protocol_connec.clone()) - { - Ok(protocol_connec) - } else { - let protocol_connec = UniqueConnec::empty(); - peer.ckb_protocols - .push((protocol_id, protocol_connec.clone())); - Ok(protocol_connec) - } + Ok(self.ckb_protocol_connec(peer, protocol_id)) + } + Err(err) => Err(err), + } + } + + pub(crate) fn try_inbound_ckb_protocol_connec( + &self, + peer_id: &PeerId, + protocol_id: ProtocolId, + connected_addr: Multiaddr, + ) -> Result, u8)>, Error> { + let mut peers_registry = self.peers_registry.write(); + // get peer protocol_connection + match peers_registry.accept_inbound_peer(peer_id.clone(), connected_addr.clone()) { + Ok(_) => { + let _ = self + .peer_store() + .write() + .add_discovered_address(peer_id, connected_addr); + let mut peer = peers_registry.get_mut(&peer_id).unwrap(); + Ok(self.ckb_protocol_connec(peer, protocol_id)) } Err(err) => Err(err), } @@ -368,10 +388,10 @@ impl Network { C: Send + 'static, { trace!( - target: "network", - "prepare open protocol {:?} to {:?}", - protocol.base_name(), - addr + target: "network", + "prepare open protocol {:?} to {:?}", + protocol.base_name(), + addr ); let protocol_id = protocol.id(); @@ -394,10 +414,9 @@ impl Network { }); let transport = TransportTimeout::new(transport, timeout); - let unique_connec = match self.ckb_protocol_connec( + let unique_connec = match self.try_outbound_ckb_protocol_connec( expected_peer_id, protocol_id, - Endpoint::Dialer, addr.to_owned(), ) { Ok(unique_connec) => unique_connec, @@ -405,30 +424,30 @@ impl Network { }; let transport = transport.and_then({ - let expected_peer_id = expected_peer_id.clone(); - move |(peer_id, protocol), _, client_addr| { - if peer_id == expected_peer_id { - debug!(target: "network", "success connect to {:?}", peer_id); - future::ok((protocol, client_addr)) - } else { - debug!(target: "network", "connected peer id mismatch {:?}, disconnect!", peer_id); - //Because multiaddrs is responsed by a third-part node, the mismatched - //peer itself should not seems as a misbehaviour peer. - //So we do not report this behaviour - future::err(IoError::new( - IoErrorKind::ConnectionRefused, - "Peer id mismatch", - )) + let expected_peer_id = expected_peer_id.clone(); + move |(peer_id, protocol), _, client_addr| { + if peer_id == expected_peer_id { + debug!(target: "network", "success connect to {:?}", peer_id); + future::ok((protocol, client_addr)) + } else { + debug!(target: "network", "connected peer id mismatch {:?}, disconnect!", peer_id); + //Because multiaddrs is responsed by a third-part node, the mismatched + //peer itself should not seems as a misbehaviour peer. + //So we do not report this behaviour + future::err(IoError::new( + IoErrorKind::ConnectionRefused, + "Peer id mismatch", + )) + } } - } - }); + }); trace!( - target: "network", - "Opening connection to {:?} addr {} with protocol {:?}", - expected_peer_id, - addr, - protocol_id + target: "network", + "Opening connection to {:?} addr {} with protocol {:?}", + expected_peer_id, + addr, + protocol_id ); let _ = unique_connec.dial(swarm_controller, addr, transport); } @@ -445,19 +464,17 @@ impl Network { let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( MemoryPeerStore::new(config.bootnodes()?), ) as Box<_>)); - let reserved_peers = config.reserved_peers()?; - { - let mut peer_store = peer_store.write(); - // put reserved_peers into peer_store - for (peer_id, addr) in reserved_peers.clone() { - peer_store.add_reserved_node(peer_id, vec![addr]); - } - } + let reserved_peers = config + .reserved_peers()? + .iter() + .map(|(peer_id, _)| peer_id.to_owned()) + .collect::>(); let peers_registry = PeersRegistry::new( Arc::clone(&peer_store), config.max_incoming_peers, config.max_outgoing_peers, config.reserved_only, + reserved_peers, ); let network: Arc = Arc::new(Network { peers_registry: RwLock::new(peers_registry), @@ -485,10 +502,7 @@ impl Network { let basic_transport = { let basic_transport = new_transport(local_private_key, basic_transport_timeout) .map_err_dial({ - let network = Arc::clone(&network); move |err, addr| { - let mut peer_store = network.peer_store().write(); - peer_store.report_address(&addr, Behaviour::FailedToConnect); trace!(target: "network", "Failed to connect to peer {}, error: {:?}", addr, err); err } @@ -640,9 +654,9 @@ impl Network { match swarm_controller.listen_on(addr.clone()) { Ok(listen_address) => { info!( - target: "network", - "Listen on address: {}", - network.to_external_url(&listen_address) + target: "network", + "Listen on address: {}", + network.to_external_url(&listen_address) ); network .original_listened_addresses @@ -651,10 +665,10 @@ impl Network { } Err(err) => { warn!( - target: "network", - "listen on address {} failed, due to error: {}", - addr.clone(), - err + target: "network", + "listen on address {} failed, due to error: {}", + addr.clone(), + err ); return Err(ErrorKind::Other(format!("listen address error: {:?}", err)).into()); } @@ -665,17 +679,18 @@ impl Network { { let network = Arc::clone(&network); let dial_timeout = Duration::from_secs(DIAL_BOOTNODE_TIMEOUT); - let peer_store = network.peer_store().read(); // dial reserved_nodes - for (peer_id, addr) in peer_store.reserved_nodes() { + for (peer_id, addr) in config.reserved_peers()? { network.dial_to_peer( basic_transport.clone(), - addr, - peer_id, + &addr, + &peer_id, &swarm_controller, dial_timeout, ); } + + let peer_store = network.peer_store().read(); // dial bootnodes for (peer_id, addr) in peer_store.bootnodes().take(max_outgoing) { debug!(target: "network", "dial bootnode {:?} {:?}", peer_id, addr); diff --git a/network/src/network_service.rs b/network/src/network_service.rs index c12d98bd4b..68e3f1fd6e 100644 --- a/network/src/network_service.rs +++ b/network/src/network_service.rs @@ -41,11 +41,6 @@ impl NetworkService { &self.network.peer_store() } - #[inline] - pub fn add_peer(&self, peer_id: PeerId, peer: PeerConnection) { - self.network.add_peer(peer_id, peer); - } - pub fn with_protocol_context(&self, protocol_id: ProtocolId, f: F) -> Option where F: FnOnce(&CKBProtocolContext) -> T, diff --git a/network/src/peer_store.rs b/network/src/peer_store.rs index 39a31707ac..e3f104682f 100644 --- a/network/src/peer_store.rs +++ b/network/src/peer_store.rs @@ -8,6 +8,7 @@ use libp2p::core::Multiaddr; // 5. limit peers from same ip group // 6. maintain reserved_node behaviours? +#[allow(dead_code)] #[derive(Copy, Clone, Eq, PartialEq)] pub enum Behaviour { FailedToConnect, @@ -23,28 +24,23 @@ pub enum Status { Unknown, } +pub type Score = i32; + pub trait PeerStore: Send + Sync { // update peer addresses, return numbers of new inserted line // return Err if peer not exists + fn add_discovered_address(&mut self, peer_id: &PeerId, address: Multiaddr) -> Result<(), ()>; fn add_discovered_addresses( &mut self, peer_id: &PeerId, addresses: Vec, ) -> Result; fn report(&mut self, peer_id: &PeerId, behaviour: Behaviour); - fn report_address(&mut self, address: &Multiaddr, behaviour: Behaviour); - fn report_status(&mut self, peer_id: &PeerId, status: Status); + fn update_status(&mut self, peer_id: &PeerId, status: Status); fn peer_status(&self, peer_id: &PeerId) -> Status; + fn peer_score(&self, peer_id: &PeerId) -> Score; // should return high scored nodes if possible, otherwise, return boostrap nodes fn bootnodes<'a>(&'a self) -> Box + 'a>; - fn reserved_nodes<'a>(&'a self) -> Box + 'a>; - fn is_reserved(&self, peer_id: &PeerId) -> bool; - fn add_reserved_node( - &mut self, - peer_id: PeerId, - addresses: Vec, - ) -> Option>; - fn remove_reserved_node(&mut self, peer_id: &PeerId) -> Option>; fn peer_addrs<'a>( &'a self, peer_id: &'a PeerId, diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index 0208c4c450..417c0bf94c 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -3,11 +3,13 @@ use crate::peer_store::PeerStore; use crate::{Error, ErrorKind, PeerId, PeerIndex, ProtocolId}; use bytes::Bytes; use ckb_util::{Mutex, RwLock}; -use fnv::FnvHashMap; +use fnv::{FnvHashMap, FnvHashSet}; use futures::sync::mpsc::UnboundedSender; use libp2p::core::{Endpoint, Multiaddr, UniqueConnec}; use libp2p::ping; use log::debug; +use rand::seq::SliceRandom; +use rand::thread_rng; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; use std::time::Duration; @@ -141,27 +143,54 @@ pub struct ConnectionStatus { pub(crate) struct PeersRegistry { // store all known peers peer_store: Arc>>, - peer_connections: PeerConnections, + peers: PeerConnections, // max incoming limitation max_incoming: u32, // max outgoing limitation max_outgoing: u32, // Only reserved peers or allow all peers. reserved_only: bool, + reserved_peers: FnvHashSet, deny_list: PeersDenyList, } +fn find_most_peers_in_same_network_group<'a>( + peers: impl Iterator, +) -> Vec<(&'a PeerId, &'a PeerConnection)> { + let mut groups: FnvHashMap> = + FnvHashMap::with_capacity_and_hasher(16, Default::default()); + let largest_group_len = 0; + let mut largest_group: Group = Default::default(); + + for (peer_id, peer) in peers { + let group_name = peer.network_group(); + let mut group = groups.entry(group_name.clone()).or_insert_with(Vec::new); + group.push((peer_id, peer)); + if group.len() > largest_group_len { + largest_group = group_name; + } + } + groups[&largest_group].clone() +} + impl PeersRegistry { pub fn new( peer_store: Arc>>, max_incoming: u32, max_outgoing: u32, reserved_only: bool, + reserved_peers: Vec, ) -> Self { + let mut reserved_peers_set = + FnvHashSet::with_capacity_and_hasher(reserved_peers.len(), Default::default()); + for reserved_peer in reserved_peers { + reserved_peers_set.insert(reserved_peer); + } let deny_list = PeersDenyList::new(); PeersRegistry { peer_store, - peer_connections: Default::default(), + peers: Default::default(), + reserved_peers: reserved_peers_set, max_incoming, max_outgoing, reserved_only, @@ -172,22 +201,14 @@ impl PeersRegistry { #[allow(clippy::needless_lifetimes)] #[inline] pub fn get_peer_id<'a>(&'a self, peer_index: PeerIndex) -> Option<&'a PeerId> { - self.peer_connections.get_peer_id(peer_index) + self.peers.get_peer_id(peer_index) } - // registry a new peer - #[allow(clippy::needless_pass_by_value)] - pub fn new_peer( - &mut self, - peer_id: PeerId, - connected_addr: Multiaddr, - endpoint: Endpoint, - ) -> Result<(), Error> { - if self.peer_connections.get(&peer_id).is_some() { + pub fn accept_inbound_peer(&mut self, peer_id: PeerId, addr: Multiaddr) -> Result<(), Error> { + if self.peers.get(&peer_id).is_some() { return Ok(()); } - let is_reserved = self.peer_store.read().is_reserved(&peer_id); - + let is_reserved = self.reserved_peers.contains(&peer_id); if !is_reserved { if self.reserved_only { return Err(ErrorKind::InvalidNewPeer(format!( @@ -203,59 +224,124 @@ impl PeersRegistry { } let connection_status = self.connection_status(); // check peers connection limitation - match endpoint { - Endpoint::Listener - if connection_status.unreserved_incoming >= self.max_incoming => - { - return Err(ErrorKind::InvalidNewPeer(format!( - "reach max incoming peers limitation, reject peer {:?}", - peer_id - )) - .into()) + if connection_status.unreserved_incoming >= self.max_incoming + && !self.try_evict_inbound_peer() + { + return Err(ErrorKind::InvalidNewPeer(format!( + "reach max inbound peers limitation, reject peer {:?}", + peer_id + )) + .into()); + } + } + self.new_peer(peer_id, addr, Endpoint::Listener); + Ok(()) + } + + fn try_evict_inbound_peer(&mut self) -> bool { + let peer_id: PeerId = { + let inbound_peers = self.peers.iter().filter(|(_, peer)| peer.is_incoming()); + let candidate_peers = find_most_peers_in_same_network_group(inbound_peers); + let peer_store = self.peer_store.read(); + + let mut lowest_score = std::i32::MAX; + let mut low_score_peers = Vec::new(); + for (peer_id, _peer) in candidate_peers { + let peer_score = peer_store.peer_score(peer_id); + if peer_score > lowest_score { + continue; } - Endpoint::Dialer if connection_status.unreserved_outgoing >= self.max_outgoing => { - return Err(ErrorKind::InvalidNewPeer(format!( - "reach max outgoing peers limitation, reject peer {:?}", - peer_id - )) - .into()) + if peer_score < lowest_score { + lowest_score = peer_score; + low_score_peers.clear(); } - _ => (), + + low_score_peers.push(peer_id); } + // failed to evict + if low_score_peers.is_empty() { + return false; + } + let mut rng = thread_rng(); + low_score_peers[..] + .choose(&mut rng) + .unwrap() + .to_owned() + .to_owned() + }; + debug!("evict inbound peer {:?}", peer_id); + self.drop_peer(&peer_id); + true + } + + pub fn try_outbound_peer(&mut self, peer_id: PeerId, addr: Multiaddr) -> Result<(), Error> { + if self.peers.get(&peer_id).is_some() { + return Ok(()); } - let peer = PeerConnection::new(connected_addr, endpoint); - let peer_index = self.add_peer(peer_id.clone(), peer); - debug!(target: "network", "allocate peer_index {} to peer {:?}", peer_index, peer_id); + let is_reserved = self.reserved_peers.contains(&peer_id); + if !is_reserved { + if self.reserved_only { + return Err(ErrorKind::InvalidNewPeer(format!( + "We are in reserved_only mode, rejected non-reserved peer {:?}", + peer_id + )) + .into()); + } + if self.deny_list.is_denied(&peer_id) { + return Err( + ErrorKind::InvalidNewPeer(format!("peer {:?} is denied", peer_id)).into(), + ); + } + let connection_status = self.connection_status(); + // check peers connection limitation + // TODO: implement extra outbound peer logic + if connection_status.unreserved_outgoing >= self.max_outgoing { + return Err(ErrorKind::InvalidNewPeer(format!( + "reach max outbound peers limitation, reject peer {:?}", + peer_id + )) + .into()); + } + } + self.new_peer(peer_id, addr, Endpoint::Dialer); Ok(()) } - // add peer without validation - #[inline] - pub fn add_peer(&mut self, peer_id: PeerId, peer_connection: PeerConnection) -> PeerIndex { - self.peer_connections.or_insert(peer_id, peer_connection) + // registry a new peer + #[allow(clippy::needless_pass_by_value)] + fn new_peer( + &mut self, + peer_id: PeerId, + connected_addr: Multiaddr, + endpoint: Endpoint, + ) -> PeerIndex { + let peer = PeerConnection::new(connected_addr, endpoint); + let peer_index = self.peers.or_insert(peer_id.clone(), peer); + debug!(target: "network", "allocate peer_index {} to peer {:?}", peer_index, peer_id); + peer_index } #[allow(clippy::needless_lifetimes)] #[inline] pub fn peers_iter<'a>(&'a self) -> impl Iterator { - self.peer_connections.iter() + self.peers.iter() } #[inline] pub fn get<'a>(&'a self, peer_id: &PeerId) -> Option<&'a PeerConnection> { - self.peer_connections.get(peer_id) + self.peers.get(peer_id) } #[inline] pub fn get_mut<'a>(&'a mut self, peer_id: &PeerId) -> Option<&'a mut PeerConnection> { - self.peer_connections.get_mut(peer_id) + self.peers.get_mut(peer_id) } pub fn connection_status(&self) -> ConnectionStatus { let mut total: u32 = 0; let mut unreserved_incoming: u32 = 0; let mut unreserved_outgoing: u32 = 0; - for (_, peer_connection) in self.peer_connections.iter() { + for (_, peer_connection) in self.peers.iter() { total += 1; if peer_connection.is_outgoing() { unreserved_outgoing += 1; @@ -274,23 +360,18 @@ impl PeersRegistry { #[inline] pub fn connected_peers_indexes<'a>(&'a self) -> impl Iterator + 'a { - Box::new( - self.peer_connections - .peer_id_by_index - .iter() - .map(|(k, _v)| *k), - ) + Box::new(self.peers.peer_id_by_index.iter().map(|(k, _v)| *k)) } #[inline] pub fn drop_peer(&mut self, peer_id: &PeerId) { - self.peer_connections.remove(peer_id); + self.peers.remove(peer_id); } #[inline] pub fn drop_all(&mut self) { debug!(target: "network", "drop_all"); - self.peer_connections = Default::default(); + self.peers = Default::default(); } pub(crate) fn ban_peer(&mut self, peer_id: PeerId, timeout: Duration) { From d160d1e1a0fbf80ef914a65d7e6b81e2c4a951b9 Mon Sep 17 00:00:00 2001 From: jjy Date: Wed, 12 Dec 2018 20:55:44 +0800 Subject: [PATCH 22/45] refactor: PeerStore implement scoring interface --- network/src/memory_peer_store.rs | 89 +++++++++++++++++++++++--------- network/src/network.rs | 14 +++-- network/src/peer_store.rs | 81 +++++++++++++++++++++++++---- network/src/peers_registry.rs | 72 +++++--------------------- 4 files changed, 159 insertions(+), 97 deletions(-) diff --git a/network/src/memory_peer_store.rs b/network/src/memory_peer_store.rs index 47519b7cc9..f372dca467 100644 --- a/network/src/memory_peer_store.rs +++ b/network/src/memory_peer_store.rs @@ -3,19 +3,14 @@ use crate::PeerId; use fnv::FnvHashMap; use libp2p::core::Multiaddr; use log::trace; -use std::time::Instant; - -// peer_id -> addresses, -// sort by score -// addr -> peer_id -// last report or updated_time -const INITIALIZED_SCORE: u32 = 0; +use peer_store::{Behaviour, PeerStore, ReportResult, Score, ScoringSchema, Status}; +use std::time::{Duration, Instant}; #[derive(Debug)] struct PeerInfo { addresses: Vec, last_updated_at: Instant, - score: u32, + score: Score, status: Status, } @@ -23,18 +18,18 @@ struct PeerInfo { pub struct MemoryPeerStore { bootnodes: Vec<(PeerId, Multiaddr)>, peers: FnvHashMap, + ban_list: FnvHashMap, + schema: ScoringSchema, } impl MemoryPeerStore { - pub fn new(bootnodes: Vec<(PeerId, Multiaddr)>) -> Self { - let mut peer_store = MemoryPeerStore { - bootnodes: bootnodes.clone(), + pub fn new(scoring_schema: ScoringSchema) -> Self { + MemoryPeerStore { + bootnodes: Default::default(), peers: Default::default(), - }; - for (peer_id, addr) in bootnodes { - peer_store.add_peer(peer_id, vec![addr]); + ban_list: Default::default(), + schema: scoring_schema, } - peer_store } fn add_peer(&mut self, peer_id: PeerId, addresses: Vec) -> bool { @@ -45,7 +40,7 @@ impl MemoryPeerStore { let peer = PeerInfo { addresses, last_updated_at: now, - score: INITIALIZED_SCORE, + score: self.schema.peer_init_score(), status: Status::Unknown, }; self.peers.insert(peer_id, peer); @@ -79,8 +74,34 @@ impl PeerStore for MemoryPeerStore { self.add_peer(peer_id.to_owned(), addresses); Ok(len) } - // TODO - fn report(&mut self, _peer_id: &PeerId, _behaviour: Behaviour) {} + + fn report(&mut self, peer_id: &PeerId, behaviour: Behaviour) -> ReportResult { + if self.is_banned(peer_id) { + return ReportResult::Banned; + } + let behaviour_score = self.schema.get_score(behaviour); + if behaviour_score.is_none() { + debug!(target: "network", "behaviour {:?} is undefined", behaviour); + return ReportResult::Normal; + } + let behaviour_score = behaviour_score.unwrap(); + // apply reported score + let score = match self.peers.get_mut(peer_id) { + Some(peer) => { + peer.score = peer.score.saturating_add(behaviour_score); + peer.score + } + None => return ReportResult::Normal, + }; + // ban peer is score is lower than ban_score + if score < self.schema.ban_score() { + let default_ban_timeout = self.schema.default_ban_timeout(); + self.ban_peer(peer_id.to_owned(), default_ban_timeout); + return ReportResult::Banned; + } + ReportResult::Normal + } + fn update_status(&mut self, peer_id: &PeerId, status: Status) { if let Some(peer) = self.peers.get_mut(&peer_id) { let now = Instant::now(); @@ -95,9 +116,14 @@ impl PeerStore for MemoryPeerStore { None => Status::Unknown, } } - //TODO - fn peer_score(&self, _peer_id: &PeerId) -> Score { - 0 + + fn peer_score(&self, peer_id: &PeerId) -> Option { + self.peers.get(peer_id).map(|peer| peer.score) + } + + fn add_bootnode(&mut self, peer_id: PeerId, addr: Multiaddr) { + self.bootnodes.push((peer_id.clone(), addr.clone())); + self.add_peer(peer_id, vec![addr]); } fn bootnodes<'a>(&'a self) -> Box + 'a> { @@ -109,6 +135,7 @@ impl PeerStore for MemoryPeerStore { let iter = bootnodes.into_iter(); Box::new(iter) as Box<_> } + fn peer_addrs<'a>( &'a self, peer_id: &'a PeerId, @@ -119,11 +146,12 @@ impl PeerStore for MemoryPeerStore { }; Some(Box::new(iter) as Box<_>) } + fn peers_to_attempt<'a>(&'a self) -> Box + 'a> { trace!( - target: "network", - "try fetch attempt peers from {:?}", - self.peers.iter().collect::>() + target: "network", + "try fetch attempt peers from {:?}", + self.peers.iter().collect::>() ); let peers = self.peers.iter().filter_map(move |(peer_id, peer_info)| { if peer_info.status == Status::Connected || peer_info.addresses.is_empty() { @@ -134,4 +162,17 @@ impl PeerStore for MemoryPeerStore { }); Box::new(peers) as Box<_> } + + fn ban_peer(&mut self, peer_id: PeerId, timeout: Duration) { + let now = Instant::now(); + let timeout_at = now + timeout; + self.ban_list.insert(peer_id, timeout_at); + } + + fn is_banned(&self, peer_id: &PeerId) -> bool { + if let Some(timeout_at) = self.ban_list.get(peer_id) { + return timeout_at > &Instant::now(); + } + false + } } diff --git a/network/src/network.rs b/network/src/network.rs index 1eb40017da..08b1e03ca6 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -163,7 +163,8 @@ impl Network { #[inline] pub(crate) fn ban_peer(&self, peer_id: PeerId, timeout: Duration) { let mut peers_registry = self.peers_registry.write(); - peers_registry.ban_peer(peer_id, timeout); + peers_registry.drop_peer(&peer_id); + self.peer_store.write().ban_peer(peer_id, timeout); } #[inline] @@ -461,9 +462,14 @@ impl Network { None => return Err(ErrorKind::Other("secret_key not set".to_owned()).into()), }; let listened_addresses = config.public_addresses.clone(); - let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( - MemoryPeerStore::new(config.bootnodes()?), - ) as Box<_>)); + let peer_store: Arc>> = { + let mut peer_store = MemoryPeerStore::new(Default::default()); + let bootnodes = config.bootnodes()?; + for (peer_id, addr) in bootnodes { + peer_store.add_bootnode(peer_id, addr); + } + Arc::new(RwLock::new(Box::new(peer_store))) + }; let reserved_peers = config .reserved_peers()? .iter() diff --git a/network/src/peer_store.rs b/network/src/peer_store.rs index e3f104682f..f9400ff977 100644 --- a/network/src/peer_store.rs +++ b/network/src/peer_store.rs @@ -1,15 +1,10 @@ use crate::PeerId; +use fnv::FnvHashMap; use libp2p::core::Multiaddr; -// TODO -// 1. maintain peer and addresses -// 2. provide interface to score peer by difference behaviours -// 3. cleanup expired peers? -// 4. limit stored peers by ip -// 5. limit peers from same ip group -// 6. maintain reserved_node behaviours? +use std::time::Duration; #[allow(dead_code)] -#[derive(Copy, Clone, Eq, PartialEq)] +#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)] pub enum Behaviour { FailedToConnect, FailedToPing, @@ -24,8 +19,71 @@ pub enum Status { Unknown, } +#[derive(Debug, Copy, Clone, Eq, PartialEq)] +pub enum ReportResult { + Normal, + Banned, +} + +impl ReportResult { + #[allow(dead_code)] + pub fn is_banned(&self) -> bool { + self == &ReportResult::Banned + } +} + pub type Score = i32; +pub struct ScoringSchema { + schema: FnvHashMap, + peer_init_score: Score, + ban_score: Score, + default_ban_timeout: Duration, +} + +impl ScoringSchema { + pub fn new_default() -> Self { + let schema = [ + (Behaviour::FailedToConnect, -20), + (Behaviour::FailedToPing, -10), + (Behaviour::Ping, 5), + (Behaviour::Connect, 10), + (Behaviour::UnexpectedDisconnect, -20), + ] + .iter() + .cloned() + .collect(); + ScoringSchema { + schema, + peer_init_score: 100, + ban_score: 40, + default_ban_timeout: Duration::from_secs(24 * 3600), + } + } + + pub fn peer_init_score(&self) -> Score { + self.peer_init_score + } + + pub fn ban_score(&self) -> Score { + self.ban_score + } + + pub fn get_score(&self, behaviour: Behaviour) -> Option { + self.schema.get(&behaviour).map(|s| *s) + } + + pub fn default_ban_timeout(&self) -> Duration { + self.default_ban_timeout + } +} + +impl Default for ScoringSchema { + fn default() -> Self { + ScoringSchema::new_default() + } +} + pub trait PeerStore: Send + Sync { // update peer addresses, return numbers of new inserted line // return Err if peer not exists @@ -35,10 +93,11 @@ pub trait PeerStore: Send + Sync { peer_id: &PeerId, addresses: Vec, ) -> Result; - fn report(&mut self, peer_id: &PeerId, behaviour: Behaviour); + fn report(&mut self, peer_id: &PeerId, behaviour: Behaviour) -> ReportResult; fn update_status(&mut self, peer_id: &PeerId, status: Status); fn peer_status(&self, peer_id: &PeerId) -> Status; - fn peer_score(&self, peer_id: &PeerId) -> Score; + fn peer_score(&self, peer_id: &PeerId) -> Option; + fn add_bootnode(&mut self, peer_id: PeerId, addr: Multiaddr); // should return high scored nodes if possible, otherwise, return boostrap nodes fn bootnodes<'a>(&'a self) -> Box + 'a>; fn peer_addrs<'a>( @@ -46,4 +105,6 @@ pub trait PeerStore: Send + Sync { peer_id: &'a PeerId, ) -> Option + 'a>>; fn peers_to_attempt<'a>(&'a self) -> Box + 'a>; + fn ban_peer(&mut self, peer_id: PeerId, timeout: Duration); + fn is_banned(&self, peer_id: &PeerId) -> bool; } diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index 417c0bf94c..af26ff8305 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -2,7 +2,7 @@ use crate::network_group::{Group, NetworkGroup}; use crate::peer_store::PeerStore; use crate::{Error, ErrorKind, PeerId, PeerIndex, ProtocolId}; use bytes::Bytes; -use ckb_util::{Mutex, RwLock}; +use ckb_util::RwLock; use fnv::{FnvHashMap, FnvHashSet}; use futures::sync::mpsc::UnboundedSender; use libp2p::core::{Endpoint, Multiaddr, UniqueConnec}; @@ -12,7 +12,6 @@ use rand::seq::SliceRandom; use rand::thread_rng; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; -use std::time::Duration; use std::time::Instant; struct PeerConnections { @@ -151,7 +150,6 @@ pub(crate) struct PeersRegistry { // Only reserved peers or allow all peers. reserved_only: bool, reserved_peers: FnvHashSet, - deny_list: PeersDenyList, } fn find_most_peers_in_same_network_group<'a>( @@ -186,7 +184,6 @@ impl PeersRegistry { for reserved_peer in reserved_peers { reserved_peers_set.insert(reserved_peer); } - let deny_list = PeersDenyList::new(); PeersRegistry { peer_store, peers: Default::default(), @@ -194,7 +191,6 @@ impl PeersRegistry { max_incoming, max_outgoing, reserved_only, - deny_list, } } @@ -217,7 +213,7 @@ impl PeersRegistry { )) .into()); } - if self.deny_list.is_denied(&peer_id) { + if self.peer_store.read().is_banned(&peer_id) { return Err( ErrorKind::InvalidNewPeer(format!("peer {:?} is denied", peer_id)).into(), ); @@ -247,16 +243,17 @@ impl PeersRegistry { let mut lowest_score = std::i32::MAX; let mut low_score_peers = Vec::new(); for (peer_id, _peer) in candidate_peers { - let peer_score = peer_store.peer_score(peer_id); - if peer_score > lowest_score { - continue; + if let Some(score) = peer_store.peer_score(peer_id) { + if score > lowest_score { + continue; + } + if score < lowest_score { + lowest_score = score; + low_score_peers.clear(); + } + + low_score_peers.push(peer_id); } - if peer_score < lowest_score { - lowest_score = peer_score; - low_score_peers.clear(); - } - - low_score_peers.push(peer_id); } // failed to evict if low_score_peers.is_empty() { @@ -287,7 +284,7 @@ impl PeersRegistry { )) .into()); } - if self.deny_list.is_denied(&peer_id) { + if self.peer_store.read().is_banned(&peer_id) { return Err( ErrorKind::InvalidNewPeer(format!("peer {:?} is denied", peer_id)).into(), ); @@ -373,47 +370,4 @@ impl PeersRegistry { debug!(target: "network", "drop_all"); self.peers = Default::default(); } - - pub(crate) fn ban_peer(&mut self, peer_id: PeerId, timeout: Duration) { - debug!(target: "network", "ban_peer: {:?}", peer_id); - self.drop_peer(&peer_id); - self.deny_list.ban_peer(peer_id, timeout); - } -} - -struct PeersDenyList { - deny_list: Mutex>, - size: usize, -} - -impl PeersDenyList { - pub fn new() -> Self { - PeersDenyList { - deny_list: Mutex::new(Default::default()), - size: 4096, - } - } - - pub fn ban_peer(&self, peer_id: PeerId, timeout: Duration) { - let now = Instant::now(); - let timeout_stamp = now + timeout; - let mut deny_list = self.deny_list.lock(); - deny_list.insert(peer_id, timeout_stamp); - // release memories - if deny_list.len() > self.size { - deny_list.retain(move |_peer_id, &mut timeout| timeout < now); - } - } - - pub fn is_denied(&self, peer_id: &PeerId) -> bool { - let mut deny_list = self.deny_list.lock(); - if let Some(timeout) = deny_list.get(peer_id).cloned() { - if timeout > Instant::now() { - return true; - } else { - deny_list.remove(peer_id); - } - } - false - } } From 6790087e991bcfbd2ca6dc653fad6a2220dced57 Mon Sep 17 00:00:00 2001 From: jjy Date: Fri, 14 Dec 2018 12:24:00 +0800 Subject: [PATCH 23/45] refactor: rename outgoing/incoming -> outbound/inbound --- network/src/lib.rs | 16 +++--- network/src/memory_peer_store.rs | 2 +- network/src/network.rs | 22 ++++---- network/src/network_config.rs | 16 +++--- ...ng_service.rs => outbound_peer_service.rs} | 24 ++++----- network/src/peer_store.rs | 6 +-- network/src/peers_registry.rs | 54 +++++++++---------- sync/src/synchronizer/mod.rs | 2 +- 8 files changed, 71 insertions(+), 71 deletions(-) rename network/src/{outgoing_service.rs => outbound_peer_service.rs} (84%) diff --git a/network/src/lib.rs b/network/src/lib.rs index c2b9fb539b..2835af2412 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -11,7 +11,7 @@ mod network; mod network_config; mod network_group; mod network_service; -mod outgoing_service; +mod outbound_peer_service; mod peer_store; mod peers_registry; mod ping_service; @@ -58,27 +58,27 @@ pub struct Config { pub non_reserved_mode: Option, /// Minimum number of connected peers to maintain pub max_peers: u32, - pub outgoing_peers_ratio: Option, + pub outbound_peers_ratio: Option, pub config_dir_path: Option, } impl Config { - fn max_outgoing_peers(&self) -> u32 { + fn max_outbound_peers(&self) -> u32 { self.max_peers / self - .outgoing_peers_ratio + .outbound_peers_ratio .unwrap_or_else(|| DEFAULT_OUTGOING_PEERS_RATIO) } - fn max_incoming_peers(&self) -> u32 { - self.max_peers - self.max_outgoing_peers() + fn max_inbound_peers(&self) -> u32 { + self.max_peers - self.max_outbound_peers() } } impl From for NetworkConfig { fn from(config: Config) -> Self { let mut cfg = NetworkConfig::default(); - cfg.max_outgoing_peers = config.max_outgoing_peers(); - cfg.max_incoming_peers = config.max_incoming_peers(); + cfg.max_outbound_peers = config.max_outbound_peers(); + cfg.max_inbound_peers = config.max_inbound_peers(); cfg.listen_addresses = config.listen_addresses; cfg.bootnodes = config.boot_nodes; cfg.reserved_peers = config.reserved_nodes; diff --git a/network/src/memory_peer_store.rs b/network/src/memory_peer_store.rs index f372dca467..1331486d25 100644 --- a/network/src/memory_peer_store.rs +++ b/network/src/memory_peer_store.rs @@ -171,7 +171,7 @@ impl PeerStore for MemoryPeerStore { fn is_banned(&self, peer_id: &PeerId) -> bool { if let Some(timeout_at) = self.ban_list.get(peer_id) { - return timeout_at > &Instant::now(); + return *timeout_at > Instant::now(); } false } diff --git a/network/src/network.rs b/network/src/network.rs index 08b1e03ca6..4a3f43da17 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -7,7 +7,7 @@ use crate::ckb_service::CKBService; use crate::discovery_service::{DiscoveryQueryService, DiscoveryService, KadManage}; use crate::identify_service::IdentifyService; use crate::memory_peer_store::MemoryPeerStore; -use crate::outgoing_service::OutgoingService; +use crate::outbound_peer_service::OutboundPeerService; use crate::peer_store::{Behaviour, PeerStore}; use crate::peers_registry::{ConnectionStatus, PeerConnection, PeerIdentifyInfo, PeersRegistry}; use crate::ping_service::PingService; @@ -58,13 +58,13 @@ pub struct PeerInfo { impl PeerInfo { #[inline] - pub fn is_outgoing(&self) -> bool { + pub fn is_outbound(&self) -> bool { self.endpoint_role == Endpoint::Dialer } #[inline] pub fn is_incoming(&self) -> bool { - !self.is_outgoing() + !self.is_outbound() } } @@ -477,8 +477,8 @@ impl Network { .collect::>(); let peers_registry = PeersRegistry::new( Arc::clone(&peer_store), - config.max_incoming_peers, - config.max_outgoing_peers, + config.max_inbound_peers, + config.max_outbound_peers, config.reserved_only, reserved_peers, ); @@ -504,7 +504,7 @@ impl Network { let basic_transport_timeout = config.transport_timeout; let client_version = config.client_version.clone(); let protocol_version = config.protocol_version.clone(); - let max_outgoing = config.max_outgoing_peers as usize; + let max_outbound = config.max_outbound_peers as usize; let basic_transport = { let basic_transport = new_transport(local_private_key, basic_transport_timeout) .map_err_dial({ @@ -589,9 +589,9 @@ impl Network { let timer_service = Arc::new(TimerService { timer_registry: Arc::clone(&timer_registry), }); - let outgoing_service = Arc::new(OutgoingService { - outgoing_interval: config.outgoing_interval, - timeout: config.outgoing_timeout, + let outbound_peer_service = Arc::new(OutboundPeerService { + try_connect_interval: config.try_outbound_connect_interval, + timeout: config.try_outbound_connect_timeout, }); // Transport used to handling received connections let handling_transport = { @@ -698,7 +698,7 @@ impl Network { let peer_store = network.peer_store().read(); // dial bootnodes - for (peer_id, addr) in peer_store.bootnodes().take(max_outgoing) { + for (peer_id, addr) in peer_store.bootnodes().take(max_outbound) { debug!(target: "network", "dial bootnode {:?} {:?}", peer_id, addr); network.dial_to_peer( basic_transport.clone(), @@ -743,7 +743,7 @@ impl Network { swarm_controller.clone(), basic_transport.clone(), ), - outgoing_service.start_protocol( + outbound_peer_service.start_protocol( Arc::clone(&network), swarm_controller.clone(), basic_transport.clone(), diff --git a/network/src/network_config.rs b/network/src/network_config.rs index eed0ff49b1..283d379b53 100644 --- a/network/src/network_config.rs +++ b/network/src/network_config.rs @@ -23,8 +23,8 @@ pub struct NetworkConfig { pub protocol_version: String, pub transport_timeout: Duration, pub reserved_only: bool, - pub max_incoming_peers: u32, - pub max_outgoing_peers: u32, + pub max_inbound_peers: u32, + pub max_outbound_peers: u32, pub reserved_peers: Vec, pub secret_key: Option, pub secret_key_path: Option, @@ -38,8 +38,8 @@ pub struct NetworkConfig { pub discovery_interval: Duration, pub identify_timeout: Duration, pub identify_interval: Duration, - pub outgoing_timeout: Duration, - pub outgoing_interval: Duration, + pub try_outbound_connect_timeout: Duration, + pub try_outbound_connect_interval: Duration, } impl NetworkConfig { @@ -151,8 +151,8 @@ impl Default for NetworkConfig { protocol_version: "ckb".to_owned(), transport_timeout: Duration::from_secs(20), reserved_only: false, - max_outgoing_peers: 15, - max_incoming_peers: 10, + max_outbound_peers: 15, + max_inbound_peers: 10, reserved_peers: vec![], secret_key: None, secret_key_path: None, @@ -166,8 +166,8 @@ impl Default for NetworkConfig { discovery_interval: Duration::from_secs(15), identify_timeout: Duration::from_secs(30), identify_interval: Duration::from_secs(15), - outgoing_timeout: Duration::from_secs(30), - outgoing_interval: Duration::from_secs(15), + try_outbound_connect_timeout: Duration::from_secs(30), + try_outbound_connect_interval: Duration::from_secs(15), } } } diff --git a/network/src/outgoing_service.rs b/network/src/outbound_peer_service.rs similarity index 84% rename from network/src/outgoing_service.rs rename to network/src/outbound_peer_service.rs index 26ef422268..2b6f9b34b6 100644 --- a/network/src/outgoing_service.rs +++ b/network/src/outbound_peer_service.rs @@ -18,12 +18,12 @@ use std::usize; use tokio::io::{AsyncRead, AsyncWrite}; use tokio::timer::Interval; -pub struct OutgoingService { - pub outgoing_interval: Duration, +pub struct OutboundPeerService { + pub try_connect_interval: Duration, pub timeout: Duration, } -impl ProtocolService for OutgoingService { +impl ProtocolService for OutboundPeerService { type Output = (); fn convert_to_protocol( _peer_id: Arc, @@ -68,14 +68,14 @@ impl ProtocolService for OutgoingService { Tran::IncomingUpgrade: Send, TranOut: AsyncRead + AsyncWrite + Send + 'static, { - let outgoing_future = Interval::new( + let outbound_future = Interval::new( Instant::now() + Duration::from_secs(5), - self.outgoing_interval, + self.try_connect_interval, ) .map_err(|err| { IoError::new( IoErrorKind::Other, - format!("outgoing service error {:?}", err), + format!("outbound peer service error {:?}", err), ) }) .for_each({ @@ -84,14 +84,14 @@ impl ProtocolService for OutgoingService { let network = Arc::clone(&network); move |_| { let connection_status = network.connection_status(); - let new_outgoing = (connection_status.max_outgoing - - connection_status.unreserved_outgoing) + let new_outbound = (connection_status.max_outbound + - connection_status.unreserved_outbound) as usize; - if new_outgoing > 0 { + if new_outbound > 0 { let peer_store = network.peer_store().read(); for (peer_id, addr) in peer_store .peers_to_attempt() - .take(new_outgoing) + .take(new_outbound) .filter_map(|(peer_id, addr)| { if network.local_peer_id() != peer_id { Some((peer_id.clone(), addr.clone())) @@ -114,9 +114,9 @@ impl ProtocolService for OutgoingService { } }) .then(|err| { - warn!(target: "network", "Outgoing service stopped, reason: {:?}", err); + warn!(target: "network", "Outbound peer service stopped, reason: {:?}", err); err }); - Box::new(outgoing_future) as Box + Send> + Box::new(outbound_future) as Box + Send> } } diff --git a/network/src/peer_store.rs b/network/src/peer_store.rs index f9400ff977..4eabc3e1e6 100644 --- a/network/src/peer_store.rs +++ b/network/src/peer_store.rs @@ -27,8 +27,8 @@ pub enum ReportResult { impl ReportResult { #[allow(dead_code)] - pub fn is_banned(&self) -> bool { - self == &ReportResult::Banned + pub fn is_banned(self) -> bool { + self == ReportResult::Banned } } @@ -70,7 +70,7 @@ impl ScoringSchema { } pub fn get_score(&self, behaviour: Behaviour) -> Option { - self.schema.get(&behaviour).map(|s| *s) + self.schema.get(&behaviour).cloned() } pub fn default_ban_timeout(&self) -> Duration { diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index af26ff8305..c5010a9572 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -114,14 +114,14 @@ impl PeerConnection { } #[inline] - pub fn is_outgoing(&self) -> bool { + pub fn is_outbound(&self) -> bool { self.endpoint_role == Endpoint::Dialer } #[allow(dead_code)] #[inline] - pub fn is_incoming(&self) -> bool { - !self.is_outgoing() + pub fn is_inbound(&self) -> bool { + !self.is_outbound() } #[allow(dead_code)] @@ -133,20 +133,20 @@ impl PeerConnection { pub struct ConnectionStatus { pub total: u32, - pub unreserved_incoming: u32, - pub unreserved_outgoing: u32, - pub max_incoming: u32, - pub max_outgoing: u32, + pub unreserved_inbound: u32, + pub unreserved_outbound: u32, + pub max_inbound: u32, + pub max_outbound: u32, } pub(crate) struct PeersRegistry { // store all known peers peer_store: Arc>>, peers: PeerConnections, - // max incoming limitation - max_incoming: u32, - // max outgoing limitation - max_outgoing: u32, + // max inbound limitation + max_inbound: u32, + // max outbound limitation + max_outbound: u32, // Only reserved peers or allow all peers. reserved_only: bool, reserved_peers: FnvHashSet, @@ -174,8 +174,8 @@ fn find_most_peers_in_same_network_group<'a>( impl PeersRegistry { pub fn new( peer_store: Arc>>, - max_incoming: u32, - max_outgoing: u32, + max_inbound: u32, + max_outbound: u32, reserved_only: bool, reserved_peers: Vec, ) -> Self { @@ -188,8 +188,8 @@ impl PeersRegistry { peer_store, peers: Default::default(), reserved_peers: reserved_peers_set, - max_incoming, - max_outgoing, + max_inbound, + max_outbound, reserved_only, } } @@ -220,7 +220,7 @@ impl PeersRegistry { } let connection_status = self.connection_status(); // check peers connection limitation - if connection_status.unreserved_incoming >= self.max_incoming + if connection_status.unreserved_inbound >= self.max_inbound && !self.try_evict_inbound_peer() { return Err(ErrorKind::InvalidNewPeer(format!( @@ -236,7 +236,7 @@ impl PeersRegistry { fn try_evict_inbound_peer(&mut self) -> bool { let peer_id: PeerId = { - let inbound_peers = self.peers.iter().filter(|(_, peer)| peer.is_incoming()); + let inbound_peers = self.peers.iter().filter(|(_, peer)| peer.is_inbound()); let candidate_peers = find_most_peers_in_same_network_group(inbound_peers); let peer_store = self.peer_store.read(); @@ -292,7 +292,7 @@ impl PeersRegistry { let connection_status = self.connection_status(); // check peers connection limitation // TODO: implement extra outbound peer logic - if connection_status.unreserved_outgoing >= self.max_outgoing { + if connection_status.unreserved_outbound >= self.max_outbound { return Err(ErrorKind::InvalidNewPeer(format!( "reach max outbound peers limitation, reject peer {:?}", peer_id @@ -336,22 +336,22 @@ impl PeersRegistry { pub fn connection_status(&self) -> ConnectionStatus { let mut total: u32 = 0; - let mut unreserved_incoming: u32 = 0; - let mut unreserved_outgoing: u32 = 0; + let mut unreserved_inbound: u32 = 0; + let mut unreserved_outbound: u32 = 0; for (_, peer_connection) in self.peers.iter() { total += 1; - if peer_connection.is_outgoing() { - unreserved_outgoing += 1; + if peer_connection.is_outbound() { + unreserved_outbound += 1; } else { - unreserved_incoming += 1; + unreserved_inbound += 1; } } ConnectionStatus { total, - unreserved_incoming, - unreserved_outgoing, - max_incoming: self.max_incoming, - max_outgoing: self.max_outgoing, + unreserved_inbound, + unreserved_outbound, + max_inbound: self.max_inbound, + max_outbound: self.max_outbound, } } diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 8ae472be18..1ee14daeba 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -102,7 +102,7 @@ impl ::std::clone::Clone for Synchronizer { fn is_outbound(nc: &CKBProtocolContext, peer: PeerIndex) -> Option { nc.session_info(peer) - .map(|session_info| session_info.peer.is_outgoing()) + .map(|session_info| session_info.peer.is_outbound()) } impl Synchronizer { From 9616a1874e94a06edd2443ee675331e81834b8a1 Mon Sep 17 00:00:00 2001 From: jjy Date: Sun, 16 Dec 2018 18:22:11 +0800 Subject: [PATCH 24/45] fix: add tests/peers_registry --- network/src/lib.rs | 2 + network/src/memory_peer_store.rs | 13 ++- network/src/network.rs | 6 +- network/src/network_service.rs | 2 - network/src/peer_store.rs | 12 ++- network/src/peers_registry.rs | 82 ++++++++++------ network/src/tests/mod.rs | 2 + network/src/tests/peers_registry.rs | 145 ++++++++++++++++++++++++++++ 8 files changed, 223 insertions(+), 41 deletions(-) create mode 100644 network/src/tests/mod.rs create mode 100644 network/src/tests/peers_registry.rs diff --git a/network/src/lib.rs b/network/src/lib.rs index 2835af2412..85d8808e26 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -17,6 +17,8 @@ mod peers_registry; mod ping_service; mod protocol; mod protocol_service; +#[cfg(test)] +mod tests; mod timer_service; mod transport; diff --git a/network/src/memory_peer_store.rs b/network/src/memory_peer_store.rs index 1331486d25..384794174d 100644 --- a/network/src/memory_peer_store.rs +++ b/network/src/memory_peer_store.rs @@ -1,9 +1,8 @@ -use crate::peer_store::{Behaviour, PeerStore, Score, Status}; +use crate::peer_store::{Behaviour, PeerStore, ReportResult, Score, ScoringSchema, Status}; use crate::PeerId; use fnv::FnvHashMap; use libp2p::core::Multiaddr; -use log::trace; -use peer_store::{Behaviour, PeerStore, ReportResult, Score, ScoringSchema, Status}; +use log::{debug, trace}; use std::time::{Duration, Instant}; #[derive(Debug)] @@ -49,6 +48,14 @@ impl MemoryPeerStore { } impl PeerStore for MemoryPeerStore { + fn new_connected_peer(&mut self, peer_id: &PeerId, address: Multiaddr) { + self.add_discovered_address(peer_id, address).unwrap(); + } + + fn scoring_schema(&self) -> &ScoringSchema { + &self.schema + } + fn add_discovered_address(&mut self, peer_id: &PeerId, address: Multiaddr) -> Result<(), ()> { self.add_discovered_addresses(peer_id, vec![address]) .map(|_| ()) diff --git a/network/src/network.rs b/network/src/network.rs index 4a3f43da17..35d4cb0cbd 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -8,7 +8,7 @@ use crate::discovery_service::{DiscoveryQueryService, DiscoveryService, KadManag use crate::identify_service::IdentifyService; use crate::memory_peer_store::MemoryPeerStore; use crate::outbound_peer_service::OutboundPeerService; -use crate::peer_store::{Behaviour, PeerStore}; +use crate::peer_store::PeerStore; use crate::peers_registry::{ConnectionStatus, PeerConnection, PeerIdentifyInfo, PeersRegistry}; use crate::ping_service::PingService; use crate::protocol::Protocol; @@ -255,7 +255,7 @@ impl Network { .peer_store() .write() .add_discovered_address(peer_id, connected_addr); - let mut peer = peers_registry.get_mut(&peer_id).unwrap(); + let peer = peers_registry.get_mut(&peer_id).unwrap(); Ok(self.ckb_protocol_connec(peer, protocol_id)) } Err(err) => Err(err), @@ -276,7 +276,7 @@ impl Network { .peer_store() .write() .add_discovered_address(peer_id, connected_addr); - let mut peer = peers_registry.get_mut(&peer_id).unwrap(); + let peer = peers_registry.get_mut(&peer_id).unwrap(); Ok(self.ckb_protocol_connec(peer, protocol_id)) } Err(err) => Err(err), diff --git a/network/src/network_service.rs b/network/src/network_service.rs index 68e3f1fd6e..7a688187a3 100644 --- a/network/src/network_service.rs +++ b/network/src/network_service.rs @@ -3,13 +3,11 @@ use crate::ckb_protocol_handler::CKBProtocolHandler; use crate::ckb_protocol_handler::{CKBProtocolContext, DefaultCKBProtocolContext}; use crate::network::Network; use crate::peer_store::PeerStore; -use crate::peers_registry::PeerConnection; use crate::NetworkConfig; use crate::{Error, ErrorKind, ProtocolId}; use ckb_util::RwLock; use futures::future::Future; use futures::sync::oneshot; -use libp2p::core::PeerId; use log::{debug, info}; use std::boxed::Box; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; diff --git a/network/src/peer_store.rs b/network/src/peer_store.rs index 4eabc3e1e6..5a14441c0a 100644 --- a/network/src/peer_store.rs +++ b/network/src/peer_store.rs @@ -85,13 +85,14 @@ impl Default for ScoringSchema { } pub trait PeerStore: Send + Sync { - // update peer addresses, return numbers of new inserted line - // return Err if peer not exists + // initial or update peer_info in peer_store + fn new_connected_peer(&mut self, peer_id: &PeerId, address: Multiaddr); + // add peer discovered addresses, return numbers of new inserted line, return Err if peer not exists fn add_discovered_address(&mut self, peer_id: &PeerId, address: Multiaddr) -> Result<(), ()>; fn add_discovered_addresses( &mut self, peer_id: &PeerId, - addresses: Vec, + address: Vec, ) -> Result; fn report(&mut self, peer_id: &PeerId, behaviour: Behaviour) -> ReportResult; fn update_status(&mut self, peer_id: &PeerId, status: Status); @@ -107,4 +108,9 @@ pub trait PeerStore: Send + Sync { fn peers_to_attempt<'a>(&'a self) -> Box + 'a>; fn ban_peer(&mut self, peer_id: PeerId, timeout: Duration); fn is_banned(&self, peer_id: &PeerId) -> bool; + fn scoring_schema(&self) -> &ScoringSchema; + fn peer_score_or_default(&self, peer_id: &PeerId) -> Score { + self.peer_score(peer_id) + .unwrap_or_else(|| self.scoring_schema().peer_init_score()) + } } diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index c5010a9572..e17f3245d1 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -1,5 +1,5 @@ use crate::network_group::{Group, NetworkGroup}; -use crate::peer_store::PeerStore; +use crate::peer_store::{PeerStore, Score}; use crate::{Error, ErrorKind, PeerId, PeerIndex, ProtocolId}; use bytes::Bytes; use ckb_util::RwLock; @@ -154,17 +154,18 @@ pub(crate) struct PeersRegistry { fn find_most_peers_in_same_network_group<'a>( peers: impl Iterator, -) -> Vec<(&'a PeerId, &'a PeerConnection)> { - let mut groups: FnvHashMap> = +) -> Vec<&'a PeerId> { + let mut groups: FnvHashMap> = FnvHashMap::with_capacity_and_hasher(16, Default::default()); - let largest_group_len = 0; + let mut largest_group_len = 0; let mut largest_group: Group = Default::default(); for (peer_id, peer) in peers { let group_name = peer.network_group(); - let mut group = groups.entry(group_name.clone()).or_insert_with(Vec::new); - group.push((peer_id, peer)); + let group = groups.entry(group_name.clone()).or_insert_with(Vec::new); + group.push(peer_id); if group.len() > largest_group_len { + largest_group_len = group.len(); largest_group = group_name; } } @@ -200,12 +201,15 @@ impl PeersRegistry { self.peers.get_peer_id(peer_index) } + pub fn is_reserved(&self, peer_id: &PeerId) -> bool { + self.reserved_peers.contains(&peer_id) + } + pub fn accept_inbound_peer(&mut self, peer_id: PeerId, addr: Multiaddr) -> Result<(), Error> { if self.peers.get(&peer_id).is_some() { return Ok(()); } - let is_reserved = self.reserved_peers.contains(&peer_id); - if !is_reserved { + if !self.is_reserved(&peer_id) { if self.reserved_only { return Err(ErrorKind::InvalidNewPeer(format!( "We are in reserved_only mode, rejected non-reserved peer {:?}", @@ -213,15 +217,19 @@ impl PeersRegistry { )) .into()); } - if self.peer_store.read().is_banned(&peer_id) { - return Err( - ErrorKind::InvalidNewPeer(format!("peer {:?} is denied", peer_id)).into(), - ); - } + let candidate_score = { + let peer_store = self.peer_store.read(); + if peer_store.is_banned(&peer_id) { + return Err( + ErrorKind::InvalidNewPeer(format!("peer {:?} is denied", peer_id)).into(), + ); + } + peer_store.peer_score_or_default(&peer_id) + }; let connection_status = self.connection_status(); // check peers connection limitation if connection_status.unreserved_inbound >= self.max_inbound - && !self.try_evict_inbound_peer() + && !self.try_evict_inbound_peer(candidate_score) { return Err(ErrorKind::InvalidNewPeer(format!( "reach max inbound peers limitation, reject peer {:?}", @@ -234,15 +242,18 @@ impl PeersRegistry { Ok(()) } - fn try_evict_inbound_peer(&mut self) -> bool { - let peer_id: PeerId = { - let inbound_peers = self.peers.iter().filter(|(_, peer)| peer.is_inbound()); + fn try_evict_inbound_peer(&mut self, candidate_score: Score) -> bool { + let (peer_id, score) = { + let inbound_peers = self + .peers + .iter() + .filter(|(peer_id, peer)| peer.is_inbound() && !self.is_reserved(peer_id)); let candidate_peers = find_most_peers_in_same_network_group(inbound_peers); let peer_store = self.peer_store.read(); let mut lowest_score = std::i32::MAX; let mut low_score_peers = Vec::new(); - for (peer_id, _peer) in candidate_peers { + for peer_id in candidate_peers { if let Some(score) = peer_store.peer_score(peer_id) { if score > lowest_score { continue; @@ -251,7 +262,6 @@ impl PeersRegistry { lowest_score = score; low_score_peers.clear(); } - low_score_peers.push(peer_id); } } @@ -260,23 +270,29 @@ impl PeersRegistry { return false; } let mut rng = thread_rng(); - low_score_peers[..] - .choose(&mut rng) - .unwrap() - .to_owned() - .to_owned() + ( + low_score_peers[..] + .choose(&mut rng) + .unwrap() + .to_owned() + .to_owned(), + lowest_score, + ) }; - debug!("evict inbound peer {:?}", peer_id); - self.drop_peer(&peer_id); - true + if score < candidate_score { + debug!("evict inbound peer {:?}", peer_id); + self.drop_peer(&peer_id); + true + } else { + false + } } pub fn try_outbound_peer(&mut self, peer_id: PeerId, addr: Multiaddr) -> Result<(), Error> { if self.peers.get(&peer_id).is_some() { return Ok(()); } - let is_reserved = self.reserved_peers.contains(&peer_id); - if !is_reserved { + if !self.is_reserved(&peer_id) { if self.reserved_only { return Err(ErrorKind::InvalidNewPeer(format!( "We are in reserved_only mode, rejected non-reserved peer {:?}", @@ -312,6 +328,9 @@ impl PeersRegistry { connected_addr: Multiaddr, endpoint: Endpoint, ) -> PeerIndex { + self.peer_store + .write() + .new_connected_peer(&peer_id, connected_addr.clone()); let peer = PeerConnection::new(connected_addr, endpoint); let peer_index = self.peers.or_insert(peer_id.clone(), peer); debug!(target: "network", "allocate peer_index {} to peer {:?}", peer_index, peer_id); @@ -338,8 +357,11 @@ impl PeersRegistry { let mut total: u32 = 0; let mut unreserved_inbound: u32 = 0; let mut unreserved_outbound: u32 = 0; - for (_, peer_connection) in self.peers.iter() { + for (peer_id, peer_connection) in self.peers.iter() { total += 1; + if self.is_reserved(peer_id) { + continue; + } if peer_connection.is_outbound() { unreserved_outbound += 1; } else { diff --git a/network/src/tests/mod.rs b/network/src/tests/mod.rs new file mode 100644 index 0000000000..eee2314adb --- /dev/null +++ b/network/src/tests/mod.rs @@ -0,0 +1,2 @@ +#[cfg(test)] +mod peers_registry; diff --git a/network/src/tests/peers_registry.rs b/network/src/tests/peers_registry.rs new file mode 100644 index 0000000000..ebfd552286 --- /dev/null +++ b/network/src/tests/peers_registry.rs @@ -0,0 +1,145 @@ +use crate::{ + memory_peer_store::MemoryPeerStore, + peer_store::{Behaviour, PeerStore}, + peers_registry::PeersRegistry, + random_peer_id, PeerId, ToMultiaddr, +}; +use ckb_util::RwLock; +use std::default::Default; +use std::sync::Arc; + +fn new_peers_registry( + peer_store: Arc>>, + max_inbound: u32, + max_outbound: u32, + reserved_only: bool, + reserved_peers: Vec, +) -> PeersRegistry { + PeersRegistry::new( + peer_store, + max_inbound, + max_outbound, + reserved_only, + reserved_peers, + ) +} + +#[test] +fn test_accept_inbound_peer_in_reserve_only_mode() { + let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( + MemoryPeerStore::new(Default::default()), + ))); + let reserved_peer = random_peer_id().unwrap(); + let addr = "/ip4/127.0.0.1".to_multiaddr().unwrap(); + + // reserved_only mode: only accept reserved_peer + let mut peers_registry = new_peers_registry( + Arc::clone(&peer_store), + 3, + 3, + true, + vec![reserved_peer.clone()], + ); + assert!(peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr.clone()) + .is_err()); + peers_registry + .accept_inbound_peer(reserved_peer.clone(), addr.clone()) + .expect("accept"); +} + +#[test] +fn test_accept_inbound_peer_until_full() { + let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( + MemoryPeerStore::new(Default::default()), + ))); + let reserved_peer = random_peer_id().unwrap(); + let addr = "/ip4/127.0.0.1".to_multiaddr().unwrap(); + // accept node until inbound connections is full + let mut peers_registry = new_peers_registry( + Arc::clone(&peer_store), + 3, + 3, + false, + vec![reserved_peer.clone()], + ); + peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr.clone()) + .expect("accept"); + peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr.clone()) + .expect("accept"); + peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr.clone()) + .expect("accept"); + assert!(peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr.clone()) + .is_err(),); + // should still accept reserved peer + peers_registry + .accept_inbound_peer(reserved_peer.clone(), addr.clone()) + .expect("accept"); + // should refuse accept low score peer + assert!(peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr.clone()) + .is_err()); +} + +#[test] +fn test_accept_inbound_peer_eviction() { + // eviction inbound peer + // 1. should evict from largest network groups + // 2. should never evict reserved peer + // 3. should evict lowest scored peer + let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( + MemoryPeerStore::new(Default::default()), + ))); + let reserved_peer = random_peer_id().unwrap(); + let evict_target = random_peer_id().unwrap(); + let lowest_score_peer = random_peer_id().unwrap(); + let addr1 = "/ip4/127.0.0.1".to_multiaddr().unwrap(); + let addr2 = "/ip4/192.168.0.1".to_multiaddr().unwrap(); + let mut peers_registry = new_peers_registry( + Arc::clone(&peer_store), + 5, + 3, + false, + vec![reserved_peer.clone()], + ); + // setup 3 node and 1 reserved node from addr1 + peers_registry + .accept_inbound_peer(reserved_peer.clone(), addr1.clone()) + .expect("accept"); + peers_registry + .accept_inbound_peer(evict_target.clone(), addr1.clone()) + .expect("accept"); + peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr1.clone()) + .expect("accept"); + peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr1.clone()) + .expect("accept"); + // setup 2 node from addr2 + peers_registry + .accept_inbound_peer(lowest_score_peer.clone(), addr2.clone()) + .expect("accept"); + peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr2.clone()) + .expect("accept"); + // setup score + { + let mut peer_store = peer_store.write(); + peer_store.report(&lowest_score_peer, Behaviour::FailedToPing); + peer_store.report(&lowest_score_peer, Behaviour::FailedToPing); + peer_store.report(&lowest_score_peer, Behaviour::FailedToPing); + peer_store.report(&reserved_peer, Behaviour::FailedToPing); + peer_store.report(&reserved_peer, Behaviour::FailedToPing); + peer_store.report(&evict_target, Behaviour::FailedToPing); + } + // should evict evict target + assert!(peers_registry.get(&evict_target).is_some()); + peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr1.clone()) + .expect("accept"); + assert!(peers_registry.get(&evict_target).is_none()); +} From df414b0067f9c1f8c9f5ff49468c4c78e85fb62e Mon Sep 17 00:00:00 2001 From: jjy Date: Tue, 18 Dec 2018 15:06:53 +0800 Subject: [PATCH 25/45] refactor: use better expression --- network/src/memory_peer_store.rs | 13 ++++--- network/src/peers_registry.rs | 58 +++++++++++++---------------- network/src/tests/peers_registry.rs | 22 ++--------- 3 files changed, 36 insertions(+), 57 deletions(-) diff --git a/network/src/memory_peer_store.rs b/network/src/memory_peer_store.rs index 384794174d..ef92953352 100644 --- a/network/src/memory_peer_store.rs +++ b/network/src/memory_peer_store.rs @@ -86,12 +86,13 @@ impl PeerStore for MemoryPeerStore { if self.is_banned(peer_id) { return ReportResult::Banned; } - let behaviour_score = self.schema.get_score(behaviour); - if behaviour_score.is_none() { - debug!(target: "network", "behaviour {:?} is undefined", behaviour); - return ReportResult::Normal; - } - let behaviour_score = behaviour_score.unwrap(); + let behaviour_score = match self.schema.get_score(behaviour) { + Some(score) => score, + None => { + debug!(target: "network", "behaviour {:?} is undefined", behaviour); + return ReportResult::Normal; + } + }; // apply reported score let score = match self.peers.get_mut(peer_id) { Some(peer) => { diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index e17f3245d1..465db4112c 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -155,21 +155,21 @@ pub(crate) struct PeersRegistry { fn find_most_peers_in_same_network_group<'a>( peers: impl Iterator, ) -> Vec<&'a PeerId> { - let mut groups: FnvHashMap> = - FnvHashMap::with_capacity_and_hasher(16, Default::default()); - let mut largest_group_len = 0; - let mut largest_group: Group = Default::default(); - - for (peer_id, peer) in peers { - let group_name = peer.network_group(); - let group = groups.entry(group_name.clone()).or_insert_with(Vec::new); - group.push(peer_id); - if group.len() > largest_group_len { - largest_group_len = group.len(); - largest_group = group_name; - } - } - groups[&largest_group].clone() + peers + .fold( + FnvHashMap::with_capacity_and_hasher(16, Default::default()), + |mut groups, (peer_id, peer)| { + groups + .entry(peer.network_group()) + .or_insert_with(Vec::new) + .push(peer_id); + groups + }, + ) + .values() + .max_by_key(|group| group.len()) + .cloned() + .unwrap_or_else(Vec::new) } impl PeersRegistry { @@ -243,7 +243,7 @@ impl PeersRegistry { } fn try_evict_inbound_peer(&mut self, candidate_score: Score) -> bool { - let (peer_id, score) = { + let peer_id = { let inbound_peers = self .peers .iter() @@ -251,7 +251,8 @@ impl PeersRegistry { let candidate_peers = find_most_peers_in_same_network_group(inbound_peers); let peer_store = self.peer_store.read(); - let mut lowest_score = std::i32::MAX; + // must have less score than candidate_score + let mut lowest_score = candidate_score - 1; let mut low_score_peers = Vec::new(); for peer_id in candidate_peers { if let Some(score) = peer_store.peer_score(peer_id) { @@ -270,22 +271,15 @@ impl PeersRegistry { return false; } let mut rng = thread_rng(); - ( - low_score_peers[..] - .choose(&mut rng) - .unwrap() - .to_owned() - .to_owned(), - lowest_score, - ) + low_score_peers[..] + .choose(&mut rng) + .unwrap() + .to_owned() + .to_owned() }; - if score < candidate_score { - debug!("evict inbound peer {:?}", peer_id); - self.drop_peer(&peer_id); - true - } else { - false - } + debug!("evict inbound peer {:?}", peer_id); + self.drop_peer(&peer_id); + true } pub fn try_outbound_peer(&mut self, peer_id: PeerId, addr: Multiaddr) -> Result<(), Error> { diff --git a/network/src/tests/peers_registry.rs b/network/src/tests/peers_registry.rs index ebfd552286..613984823d 100644 --- a/network/src/tests/peers_registry.rs +++ b/network/src/tests/peers_registry.rs @@ -8,22 +8,6 @@ use ckb_util::RwLock; use std::default::Default; use std::sync::Arc; -fn new_peers_registry( - peer_store: Arc>>, - max_inbound: u32, - max_outbound: u32, - reserved_only: bool, - reserved_peers: Vec, -) -> PeersRegistry { - PeersRegistry::new( - peer_store, - max_inbound, - max_outbound, - reserved_only, - reserved_peers, - ) -} - #[test] fn test_accept_inbound_peer_in_reserve_only_mode() { let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( @@ -33,7 +17,7 @@ fn test_accept_inbound_peer_in_reserve_only_mode() { let addr = "/ip4/127.0.0.1".to_multiaddr().unwrap(); // reserved_only mode: only accept reserved_peer - let mut peers_registry = new_peers_registry( + let mut peers_registry = PeersRegistry::new( Arc::clone(&peer_store), 3, 3, @@ -56,7 +40,7 @@ fn test_accept_inbound_peer_until_full() { let reserved_peer = random_peer_id().unwrap(); let addr = "/ip4/127.0.0.1".to_multiaddr().unwrap(); // accept node until inbound connections is full - let mut peers_registry = new_peers_registry( + let mut peers_registry = PeersRegistry::new( Arc::clone(&peer_store), 3, 3, @@ -99,7 +83,7 @@ fn test_accept_inbound_peer_eviction() { let lowest_score_peer = random_peer_id().unwrap(); let addr1 = "/ip4/127.0.0.1".to_multiaddr().unwrap(); let addr2 = "/ip4/192.168.0.1".to_multiaddr().unwrap(); - let mut peers_registry = new_peers_registry( + let mut peers_registry = PeersRegistry::new( Arc::clone(&peer_store), 5, 3, From 366f0778ec3a93c9a41e9f8eca9dc24b57c81a94 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Tue, 18 Dec 2018 18:16:09 +0800 Subject: [PATCH 26/45] fix: sync header verify --- sync/src/synchronizer/headers_process.rs | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/sync/src/synchronizer/headers_process.rs b/sync/src/synchronizer/headers_process.rs index 622bca9b93..74d44b0885 100644 --- a/sync/src/synchronizer/headers_process.rs +++ b/sync/src/synchronizer/headers_process.rs @@ -126,18 +126,6 @@ where } fn is_continuous(&self, headers: &[Header]) -> bool { - debug!( - target: "sync", - "headers\n {:?}", - headers - .iter() - .map(|h| format!( - "{} hash({}) parent({})", - h.number(), - h.hash(), - h.parent_hash() - )).collect::>() - ); for window in headers.windows(2) { if let [parent, header] = &window { if header.parent_hash() != &parent.hash() { @@ -336,6 +324,7 @@ where } error => { debug!(target: "sync", "HeadersProcess accept {:?} {:?}", self.header.number(), error); + state.invalid(Some(ValidationError::Verify(error))); } }) } From 98750f195331fd19f29899cbc9121b3195147d41 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Tue, 18 Dec 2018 10:57:38 +0800 Subject: [PATCH 27/45] refactor: Use `size_of` replace the hardcode --- Cargo.lock | 68 ++++++++++++++++++++--------------------- core/src/script.rs | 6 ++-- core/src/transaction.rs | 2 +- 3 files changed, 39 insertions(+), 37 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index fcc6d2668f..4df8487b2d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -75,7 +75,7 @@ dependencies = [ "ckb-core 0.3.0-pre", "ckb-db 0.3.0-pre", "hash 0.3.0-pre", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -338,8 +338,8 @@ dependencies = [ "lazy_static 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)", "logger 0.3.0-pre", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -372,8 +372,8 @@ dependencies = [ "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)", "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -388,8 +388,8 @@ dependencies = [ "ckb-pow 0.3.0-pre", "ckb-protocol 0.3.0-pre", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -408,8 +408,8 @@ dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", "merkle-root 0.3.0-pre", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -423,7 +423,7 @@ dependencies = [ "ckb-core 0.3.0-pre", "ckb-util 0.3.0-pre", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.10.0 (git+https://github.com/nervosnetwork/rust-rocksdb)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -455,7 +455,7 @@ dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc 0.10.2 (git+https://github.com/quake/rust-jsonrpc)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -512,7 +512,7 @@ dependencies = [ "linked-hash-map 0.5.1 (git+https://github.com/nervosnetwork/linked-hash-map?rev=df27f21)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -526,7 +526,7 @@ dependencies = [ "ckb-core 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -542,8 +542,8 @@ dependencies = [ "ckb-util 0.3.0-pre", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "siphasher 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -569,7 +569,7 @@ dependencies = [ "jsonrpc-macros 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-server-utils 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", @@ -589,7 +589,7 @@ dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -611,8 +611,8 @@ dependencies = [ "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)", "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -643,8 +643,8 @@ dependencies = [ "lazy_static 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)", "multiaddr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -679,8 +679,8 @@ dependencies = [ "hash 0.3.0-pre", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "merkle-root 0.3.0-pre", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -940,7 +940,7 @@ dependencies = [ "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "secp256k1 0.9.1 (git+https://github.com/nervosnetwork/rust-secp256k1)", ] @@ -1869,7 +1869,7 @@ name = "merkle-root" version = "0.3.0-pre" dependencies = [ "hash 0.3.0-pre", - "numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2082,7 +2082,7 @@ dependencies = [ [[package]] name = "numext-constructor" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2092,26 +2092,26 @@ dependencies = [ [[package]] name = "numext-fixed-hash" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-constructor 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-constructor 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "numext-fixed-uint" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-constructor 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "numext-constructor 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3673,9 +3673,9 @@ dependencies = [ "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" "checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" "checksum number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf9993e59c894e3c08aa1c2712914e9e6bf1fcbfc6bef283e2183df345a4fee" -"checksum numext-constructor 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df99f0e1cefc5d336ccb29b369a318559964065747c687441e157c87ca62a79b" -"checksum numext-fixed-hash 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2c74c14999a7b325611200c3303dc580392d4815908a0922af479d475778be1e" -"checksum numext-fixed-uint 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4527605a7cc2e5db26b836ba306f4f9915f04db7ee1ead60af50b5e43ec03ee1" +"checksum numext-constructor 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0e938dadad7c0412ac4e2277846ba3b7241fae69c66e9b0389ea0fafa4be8e23" +"checksum numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b58badd890ecf25ccef71682442c89ec2139772c5174782a0e9301a045648a3e" +"checksum numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5dc24e4bed29ec6706d11ebe8ee5a77eb99de62b60e3af22ec704aae3f548c0d" "checksum openssl 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "a3605c298474a3aa69de92d21139fb5e2a81688d308262359d85cdd0d12a7985" "checksum openssl-sys 0.9.39 (registry+https://github.com/rust-lang/crates.io-index)" = "278c1ad40a89aa1e741a1eed089a2f60b18fab8089c3139b542140fc7d674106" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" diff --git a/core/src/script.rs b/core/src/script.rs index a9b13e6efd..f86473196a 100644 --- a/core/src/script.rs +++ b/core/src/script.rs @@ -2,6 +2,7 @@ use hash::sha3_256; use numext_fixed_hash::H256; use serde_derive::{Deserialize, Serialize}; use std::io::Write; +use std::mem; // TODO: when flatbuffer work is done, remove Serialize/Deserialize here and // implement proper From trait @@ -66,8 +67,9 @@ impl Script { } pub fn bytes_len(&self) -> usize { - 1 + self.args.iter().map(|a| a.len()).sum::() - + self.reference.as_ref().map_or(0, |_| 32) + mem::size_of::() + + self.args.iter().map(|a| a.len()).sum::() + + self.reference.as_ref().map_or(0, |_| H256::size_of()) + self.binary.as_ref().map_or(0, |script| script.len()) + self.signed_args.iter().map(|a| a.len()).sum::() } diff --git a/core/src/transaction.rs b/core/src/transaction.rs index e654482f51..ccaf942835 100644 --- a/core/src/transaction.rs +++ b/core/src/transaction.rs @@ -109,7 +109,7 @@ impl CellOutput { pub fn bytes_len(&self) -> usize { mem::size_of::() + self.data.len() - + self.lock.as_bytes().len() + + H256::size_of() + self.contract.as_ref().map_or(0, |s| s.bytes_len()) } } From 06a5e29edc89d3a29ef385340e23bb9e97227084 Mon Sep 17 00:00:00 2001 From: jjy Date: Wed, 19 Dec 2018 14:30:43 +0800 Subject: [PATCH 28/45] fix: fix calculation of headers sync timeout --- sync/src/synchronizer/mod.rs | 12 +++++++----- sync/src/synchronizer/peers.rs | 6 +++--- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 65d215aff7..9be44a27bc 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -188,10 +188,11 @@ impl Synchronizer { now_ms().saturating_sub(self.shared.tip_header().read().inner().timestamp()) > MAX_TIP_AGE } - pub fn get_headers_sync_timeout(&self, header: &Header) -> u64 { - HEADERS_DOWNLOAD_TIMEOUT_BASE + pub fn predict_headers_sync_time(&self, header: &Header) -> u64 { + let now = now_ms(); + now + HEADERS_DOWNLOAD_TIMEOUT_BASE + HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER - * (now_ms().saturating_sub(header.timestamp()) / POW_SPACE) + * (now.saturating_sub(header.timestamp()) / POW_SPACE) } pub fn mark_block_stored(&self, hash: H256) { @@ -480,7 +481,7 @@ impl Synchronizer { fn on_connected(&self, nc: &CKBProtocolContext, peer: PeerIndex) { let tip = self.tip_header(); - let timeout = self.get_headers_sync_timeout(&tip); + let predicted_headers_sync_time = self.predict_headers_sync_time(&tip); let protect_outbound = is_outbound(nc, peer).unwrap_or_else(|| false) && self.outbound_peers_with_protect.load(Ordering::Acquire) @@ -491,7 +492,8 @@ impl Synchronizer { .fetch_add(1, Ordering::Release); } - self.peers.on_connected(peer, timeout, protect_outbound); + self.peers + .on_connected(peer, predicted_headers_sync_time, protect_outbound); } pub fn send_getheaders_to_peer( diff --git a/sync/src/synchronizer/peers.rs b/sync/src/synchronizer/peers.rs index cffd5e1f63..87e25fcfd5 100644 --- a/sync/src/synchronizer/peers.rs +++ b/sync/src/synchronizer/peers.rs @@ -123,12 +123,12 @@ impl Peers { .or_insert_with(|| score); } - pub fn on_connected(&self, peer: PeerIndex, headers_sync_timeout: u64, protect: bool) { + pub fn on_connected(&self, peer: PeerIndex, predicted_headers_sync_time: u64, protect: bool) { self.state .write() .entry(peer) .and_modify(|state| { - state.headers_sync_timeout = Some(headers_sync_timeout); + state.headers_sync_timeout = Some(predicted_headers_sync_time); state.chain_sync.protect = protect; }) .or_insert_with(|| { @@ -138,7 +138,7 @@ impl Peers { negotiate: Negotiate::default(), sync_started: false, last_block_announcement: None, - headers_sync_timeout: Some(headers_sync_timeout), + headers_sync_timeout: Some(predicted_headers_sync_time), disconnect: false, chain_sync, } From 8c0dc2c39066dba32dacfb3e3e67876bce50592b Mon Sep 17 00:00:00 2001 From: quake wang Date: Wed, 19 Dec 2018 21:19:16 +0900 Subject: [PATCH 29/45] chore: remove unused dependencies in Cargo.toml (#109) * chore: remove unnecessary ckb-time dep * chore: remove more unused dependencies in Cargo.toml * chore: update Cargo.lock * chore: remove more unused dependencies --- Cargo.lock | 385 ++++++++++--------------- Cargo.toml | 4 - chain/Cargo.toml | 6 - core/Cargo.toml | 2 - db/Cargo.toml | 2 - devtools/release/dependencies_check.rb | 28 ++ miner/Cargo.toml | 1 - notify/Cargo.toml | 1 - pool/Cargo.toml | 3 - script/Cargo.toml | 2 - shared/Cargo.toml | 3 - sync/Cargo.toml | 2 - util/crypto/Cargo.toml | 1 - verification/Cargo.toml | 3 - 14 files changed, 178 insertions(+), 265 deletions(-) create mode 100644 devtools/release/dependencies_check.rb diff --git a/Cargo.lock b/Cargo.lock index 4df8487b2d..400d81252f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3,18 +3,17 @@ name = "aho-corasick" version = "0.6.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "aio-limited" version = "0.1.0" -source = "git+https://github.com/paritytech/aio-limited.git#1f42497dcd2a6f85b83af97cd80314b26a1e4a9e" +source = "git+https://github.com/paritytech/aio-limited.git#f01b01501c87c93d3005f9120cc35d0e576fa7a3" dependencies = [ "futures 0.1.25 (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)", - "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -35,7 +34,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "arrayvec" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "nodrop 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", @@ -62,11 +61,16 @@ name = "atty" version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "autocfg" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "avl-merkle" version = "0.3.0-pre" @@ -82,30 +86,26 @@ dependencies = [ [[package]] name = "backtrace" -version = "0.3.9" +version = "0.3.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace-sys 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "backtrace-sys" -version = "0.1.24" +version = "0.1.26" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "base-x" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "base64" version = "0.6.0" @@ -204,7 +204,7 @@ name = "blake2-rfc" version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -257,7 +257,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "cc" -version = "1.0.25" +version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -292,17 +292,7 @@ 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)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "cid" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "integer-encoding 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "multibase 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "multihash 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -321,12 +311,9 @@ dependencies = [ "ckb-pool 0.3.0-pre", "ckb-pow 0.3.0-pre", "ckb-rpc 0.3.0-pre", - "ckb-script 0.3.0-pre", "ckb-shared 0.3.0-pre", "ckb-sync 0.3.0-pre", - "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", - "ckb-verification 0.3.0-pre", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "config 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -335,7 +322,6 @@ dependencies = [ "dir 0.3.0-pre", "faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", - "lazy_static 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)", "logger 0.3.0-pre", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -358,8 +344,6 @@ dependencies = [ name = "ckb-chain" version = "0.3.0-pre" dependencies = [ - "avl-merkle 0.3.0-pre", - "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "ckb-chain-spec 0.3.0-pre", "ckb-core 0.3.0-pre", "ckb-db 0.3.0-pre", @@ -369,14 +353,10 @@ dependencies = [ "ckb-verification 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (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)", - "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -401,7 +381,6 @@ version = "0.3.0-pre" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "crypto 0.3.0-pre", @@ -410,7 +389,6 @@ dependencies = [ "merkle-root 0.3.0-pre", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -420,10 +398,8 @@ name = "ckb-db" version = "0.3.0-pre" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.3.0-pre", "ckb-util 0.3.0-pre", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.10.0 (git+https://github.com/nervosnetwork/rust-rocksdb)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -451,7 +427,6 @@ dependencies = [ "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc 0.10.2 (git+https://github.com/quake/rust-jsonrpc)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -485,7 +460,6 @@ name = "ckb-notify" version = "0.3.0-pre" dependencies = [ "ckb-core 0.3.0-pre", - "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.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)", @@ -495,7 +469,6 @@ dependencies = [ name = "ckb-pool" version = "0.3.0-pre" dependencies = [ - "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "ckb-chain 0.3.0-pre", "ckb-chain-spec 0.3.0-pre", "ckb-core 0.3.0-pre", @@ -503,7 +476,6 @@ dependencies = [ "ckb-notify 0.3.0-pre", "ckb-shared 0.3.0-pre", "ckb-time 0.3.0-pre", - "ckb-util 0.3.0-pre", "ckb-verification 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -513,7 +485,6 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -591,8 +562,6 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", - "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", - "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -604,12 +573,9 @@ dependencies = [ "ckb-chain-spec 0.3.0-pre", "ckb-core 0.3.0-pre", "ckb-db 0.3.0-pre", - "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", - "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (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)", "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -640,9 +606,7 @@ dependencies = [ "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 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)", - "multiaddr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -673,11 +637,8 @@ dependencies = [ "ckb-script 0.3.0-pre", "ckb-shared 0.3.0-pre", "ckb-time 0.3.0-pre", - "ckb-util 0.3.0-pre", - "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", - "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "merkle-root 0.3.0-pre", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -700,7 +661,7 @@ version = "0.21.2" 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.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "libloading 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -725,7 +686,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -748,7 +709,7 @@ dependencies = [ "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde-hjson 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", - "toml 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", "yaml-rust 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -760,7 +721,7 @@ dependencies = [ "atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "clicolors-control 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "termios 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -779,7 +740,7 @@ version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -787,7 +748,7 @@ name = "core-foundation-sys" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -799,7 +760,7 @@ dependencies = [ "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "criterion-plot 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", "criterion-stats 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", - "csv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "handlebars 0.32.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -830,7 +791,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "thread-scoped 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -841,7 +802,7 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -858,11 +819,11 @@ dependencies = [ [[package]] name = "crossbeam-deque" -version = "0.6.2" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-epoch 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -870,7 +831,7 @@ name = "crossbeam-epoch" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.6 (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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -879,27 +840,14 @@ dependencies = [ "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "crossbeam-epoch" -version = "0.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", - "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "crossbeam-epoch" version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -915,7 +863,7 @@ dependencies = [ [[package]] name = "crossbeam-utils" -version = "0.6.1" +version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -937,7 +885,6 @@ version = "0.3.0-pre" dependencies = [ "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", - "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -947,19 +894,19 @@ dependencies = [ [[package]] name = "csv" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "csv-core 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "csv-core" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1027,8 +974,8 @@ name = "eth-secp256k1" version = "0.5.7" source = "git+https://github.com/paritytech/rust-secp256k1#ccc06e7480148b723eb44ac56cf4d20eec380b6f" dependencies = [ - "arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1043,7 +990,7 @@ name = "failure" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1054,7 +1001,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", "synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1119,7 +1066,7 @@ 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)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1148,7 +1095,7 @@ dependencies = [ "aho-corasick 0.6.9 (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)", - "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1164,7 +1111,7 @@ dependencies = [ [[package]] name = "h2" -version = "0.1.13" +version = "0.1.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1243,8 +1190,8 @@ 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.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.41 (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)", "unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1253,20 +1200,20 @@ dependencies = [ [[package]] name = "hyper" -version = "0.12.16" +version = "0.12.19" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (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.13 (registry+https://github.com/rust-lang/crates.io-index)", + "h2 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "http 0.1.14 (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)", "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)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1314,7 +1261,7 @@ name = "iovec" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1367,7 +1314,7 @@ name = "jsonrpc-http-server" version = "9.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "hyper 0.12.16 (registry+https://github.com/rust-lang/crates.io-index)", + "hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-server-utils 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1405,7 +1352,7 @@ dependencies = [ "jsonrpc-core 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 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)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.13 (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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1442,7 +1389,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libc" -version = "0.2.44" +version = "0.2.45" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1564,7 +1511,7 @@ name = "libp2p-kad" version = "0.1.0" source = "git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0#cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0" dependencies = [ - "arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "arrayvec 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "bigint 4.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1694,7 +1641,7 @@ dependencies = [ "libp2p-core 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "multiaddr 0.3.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", - "tk-listen 0.2.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.10 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1748,7 +1695,7 @@ dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)", - "yamux 0.1.0 (git+https://github.com/paritytech/yamux)", + "yamux 0.1.3 (git+https://github.com/paritytech/yamux)", ] [[package]] @@ -1757,8 +1704,8 @@ version = "5.11.3" source = "git+https://github.com/nervosnetwork/rust-rocksdb#f4bdb623c1ff1eb7d7ec846986cb166090916c95" dependencies = [ "bindgen 0.29.1 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "make-cmd 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1846,16 +1793,16 @@ name = "memchr" version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "memchr" -version = "2.1.1" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1890,7 +1837,7 @@ dependencies = [ "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.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (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)", @@ -1904,7 +1851,7 @@ 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.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1931,33 +1878,6 @@ dependencies = [ "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "multiaddr" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cid 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "integer-encoding 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "multibase" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "base-x 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", -] - -[[package]] -name = "multihash" -version = "0.7.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "multihash" version = "0.8.1-pre" @@ -1987,7 +1907,7 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "openssl 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)", "schannel 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2001,7 +1921,7 @@ version = "0.2.33" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2011,9 +1931,9 @@ version = "0.11.0" 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.25 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2040,7 +1960,7 @@ name = "nom" version = "4.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2066,10 +1986,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "num_cpus" -version = "1.8.0" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2087,7 +2007,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2124,17 +2044,17 @@ dependencies = [ "bitflags 0.9.1 (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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "openssl-sys 0.9.39 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.40 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "openssl-sys" -version = "0.9.39" +version = "0.9.40" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2196,7 +2116,7 @@ name = "parking_lot_core" version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2207,7 +2127,7 @@ name = "parking_lot_core" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.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.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2219,7 +2139,7 @@ name = "parking_lot_core" version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (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.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2340,7 +2260,7 @@ version = "0.3.22" 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)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2350,7 +2270,7 @@ version = "0.4.3" 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)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2361,7 +2281,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-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2373,7 +2293,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-zircon 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand_hc 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2464,13 +2384,13 @@ 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.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "redox_syscall" -version = "0.1.43" +version = "0.1.44" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2478,7 +2398,7 @@ name = "redox_termios" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2487,7 +2407,7 @@ version = "0.2.11" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.5.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)", @@ -2499,7 +2419,7 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "aho-corasick 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", - "memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", + "memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex-syntax 0.6.4 (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)", @@ -2536,7 +2456,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "gcc 0.3.55 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2546,7 +2466,7 @@ name = "rocksdb" version = "0.10.0" source = "git+https://github.com/nervosnetwork/rust-rocksdb#f4bdb623c1ff1eb7d7ec846986cb166090916c95" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "librocksdb-sys 5.11.3 (git+https://github.com/nervosnetwork/rust-rocksdb)", ] @@ -2556,10 +2476,10 @@ version = "0.2.36" 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.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", - "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2569,7 +2489,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "rustc-demangle" -version = "0.1.9" +version = "0.1.11" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2664,7 +2584,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2672,8 +2592,8 @@ name = "secp256k1" version = "0.9.1" source = "git+https://github.com/nervosnetwork/rust-secp256k1#09bf257132def11f29fdf0f08b6af08850ac3cd4" dependencies = [ - "cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2684,7 +2604,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "security-framework-sys 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2694,7 +2614,7 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "core-foundation-sys 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2739,7 +2659,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2855,7 +2775,7 @@ dependencies = [ [[package]] name = "syn" -version = "0.15.22" +version = "0.15.23" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2878,7 +2798,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 0.4.24 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2896,7 +2816,7 @@ name = "syntex_errors" version = "0.58.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)", "syntex_pos 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2939,9 +2859,9 @@ version = "3.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", "remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2977,8 +2897,8 @@ name = "termion" version = "1.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", "redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2987,7 +2907,7 @@ name = "termios" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3013,11 +2933,11 @@ dependencies = [ [[package]] name = "time" -version = "0.1.40" +version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", - "redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", + "redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)", "winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3031,7 +2951,7 @@ dependencies = [ [[package]] name = "tk-listen" -version = "0.2.0" +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)", @@ -3048,7 +2968,7 @@ dependencies = [ "bytes 0.4.11 (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)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.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.4 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3143,12 +3063,12 @@ name = "tokio-reactor" version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 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)", "mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)", - "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3173,11 +3093,11 @@ name = "tokio-threadpool" version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-deque 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", - "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (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.8.0 (registry+https://github.com/rust-lang/crates.io-index)", + "num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3187,7 +3107,7 @@ name = "tokio-timer" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", "slab 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3226,7 +3146,7 @@ dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (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.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (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-uds 0.6.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3237,7 +3157,7 @@ dependencies = [ [[package]] name = "toml" -version = "0.4.9" +version = "0.4.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3323,7 +3243,7 @@ dependencies = [ [[package]] name = "unsigned-varint" version = "0.2.1" -source = "git+https://github.com/paritytech/unsigned-varint#219c05312f16575519f87a29034be3ffc68b9764" +source = "git+https://github.com/paritytech/unsigned-varint#6461ddf6ae97ab0585677374d6948aabbd9802ec" dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3383,7 +3303,7 @@ name = "wait-timeout" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -3492,8 +3412,8 @@ dependencies = [ [[package]] name = "yamux" -version = "0.1.0" -source = "git+https://github.com/paritytech/yamux#09f652346c65d182292d80dd6db0ee10c29b55f8" +version = "0.1.3" +source = "git+https://github.com/paritytech/yamux#152063358daeebc5efbae47ef1bc91558ed6fb45" dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3510,13 +3430,13 @@ dependencies = [ "checksum aio-limited 0.1.0 (git+https://github.com/paritytech/aio-limited.git)" = "" "checksum ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" -"checksum arrayvec 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "f405cc4c21cd8b784f6c8fc2adf9bc00f59558f0049b5ec21517f875963040cc" +"checksum arrayvec 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "d18513977c2d8261c448511c5c53dc66b26dfccbc3d4446672dea1e71a7d8a26" "checksum asn1_der 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)" = "766afdc5c6d7c15de1abe4c9c15e360be3aa972c363ba5b606be3c4271235886" "checksum aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfdf7355d9db158df68f976ed030ab0f6578af811f5a7bb6dcf221ec24e0e0" "checksum atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9a7d5b8723950951411ee34d271d99dddcc2035a16ab25310ea2c8cfd4369652" -"checksum backtrace 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)" = "89a47830402e9981c5c41223151efcced65a0510c13097c769cede7efb34782a" -"checksum backtrace-sys 0.1.24 (registry+https://github.com/rust-lang/crates.io-index)" = "c66d56ac8dabd07f6aacdaf633f4b8262f5b3601a810a0dcddffd5c22c69daa0" -"checksum base-x 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "5cda5d0f5584d129112ad8bf4775b9fd2b9f1e30738c7b1a25314ba2244d6a51" +"checksum autocfg 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4e5f34df7a019573fb8bdc7e24a2bfebe51a2a1d6bfdbaeccedb3c41fc574727" +"checksum backtrace 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)" = "b5b493b66e03090ebc4343eb02f94ff944e0cbc9ac6571491d170ba026741eb5" +"checksum backtrace-sys 0.1.26 (registry+https://github.com/rust-lang/crates.io-index)" = "3fcce89e5ad5c8949caa9434501f7b55415b3e7ad5270cb88c75a8d35e8f1279" "checksum base64 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "96434f987501f0ed4eb336a411e0631ecd1afa11574fe148587adc4ff96143c9" "checksum base64 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5032d51da2741729bfdaeb2664d9b8c6d9fd1e2b90715c660b6def36628499c2" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" @@ -3536,12 +3456,11 @@ dependencies = [ "checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" "checksum bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "40ade3d27603c2cb345eb0912aec461a6dec7e06a4ae48589904e808335c7afa" "checksum cast 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "926013f2860c46252efceabb19f4a6b308197505082c609025aa6706c011d427" -"checksum cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "f159dfd43363c4d08055a07703eb7a3406b0dac4d0584d96965a3262db3c9d16" +"checksum cc 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "155ed195f7bd722d1dfeb30365b9d0c1f6a078fa7ca4014497e5935d90993d6f" "checksum cexpr 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "42aac45e9567d97474a834efdee3081b3c942b2205be932092f53354ce503d6c" "checksum cfg-if 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "082bb9b28e00d3c9d39cc03e64ce4cea0f1bb9b3fde493f0cbc008472d22bdf4" "checksum chashmap 2.2.1 (git+https://github.com/redox-os/tfs)" = "" "checksum chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "45912881121cb26fad7c38c17ba7daa18764771836b34fab7d3fbd93ed633878" -"checksum cid 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d85ee025368e69063c420cbb2ed9f852cb03a5e69b73be021e65726ce03585b6" "checksum ckb-vm 0.1.0 (git+https://github.com/nervosnetwork/ckb-vm?rev=1622ba0)" = "" "checksum clang-sys 0.21.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e414af9726e1d11660801e73ccc7fb81803fb5f49e5903a25b348b2b3b480d2e" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" @@ -3557,16 +3476,15 @@ dependencies = [ "checksum criterion-stats 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ff43cac80562f91ead0b617c1be74edf350adfaa195809d355de98dfc8f9237d" "checksum crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5b2a9ea8f77c7f9efd317a8a5645f515d903a2d86ee14d2337a5facd1bd52c12" "checksum crossbeam-deque 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f739f8c5363aca78cfb059edf753d8f0d36908c348f3d8d1503f03d8b75d9cf3" -"checksum crossbeam-deque 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4fe1b6f945f824c7a25afe44f62e25d714c0cc523f8e99d8db5cd1026e1269d3" +"checksum crossbeam-deque 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "05e44b8cf3e1a625844d1750e1f7820da46044ff6d28f4d43e455ba3e5bb2c13" "checksum crossbeam-epoch 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "927121f5407de9956180ff5e936fe3cf4324279280001cd56b669d28ee7e9150" -"checksum crossbeam-epoch 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2449aaa4ec7ef96e5fb24db16024b935df718e9ae1cec0a1e68feeca2efca7b8" "checksum crossbeam-epoch 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f10a4f8f409aaac4b16a5474fb233624238fcdeefb9ba50d5ea059aab63ba31c" "checksum crossbeam-utils 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2760899e32a1d58d5abb31129f8fae5de75220bc2176e77ff7c627ae45c918d9" -"checksum crossbeam-utils 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)" = "c55913cc2799171a550e307918c0a360e8c16004820291bf3b638969b4a01816" +"checksum crossbeam-utils 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)" = "41ee4864f4797060e52044376f7d107429ce1fb43460021b126424b7180ee21a" "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 csv 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d54f6b0fd69128a2894b1a3e57af5849a0963c1cc77b165d30b896e40296452" -"checksum csv-core 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4dd8e6d86f7ba48b4276ef1317edc8cc36167546d8972feb4a2b5fec0b374105" +"checksum csv 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "9fd1c44c58078cfbeaf11fbb3eac9ae5534c23004ed770cc4bfb48e658ae4f04" +"checksum csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5cdef62f37e6ffe7d1f07a381bc0db32b7a3ff1cac0de56cb0d81e71f53d65" "checksum ctrlc 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "630391922b1b893692c6334369ff528dcc3a9d8061ccf4c803aa8f83cb13db5e" "checksum datastore 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)" = "" "checksum digest 0.7.6 (registry+https://github.com/rust-lang/crates.io-index)" = "03b072242a8cbaf9c145665af9d250c59af3b958f83ed6824e13533cf76d5b90" @@ -3592,14 +3510,14 @@ dependencies = [ "checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb" "checksum globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4743617a7464bbda3c8aec8558ff2f9429047e025771037df561d383337ff865" "checksum goblin 0.0.17 (registry+https://github.com/rust-lang/crates.io-index)" = "5911d7df7b8f65ab676c5327b50acea29d3c6a1a4ad05e444cf5dce321b26db2" -"checksum h2 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "7dd33bafe2e6370e6c8eb0cf1b8c5f93390b90acde7e9b03723f166b28b648ed" +"checksum h2 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "1ac030ae20dee464c5d0f36544d8b914a6bc606da44a57e052d2b0f5dae129e0" "checksum handlebars 0.32.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d89ec99d1594f285d4590fc32bac5f75cdab383f1123d504d27862c644a807dd" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum http 0.1.14 (registry+https://github.com/rust-lang/crates.io-index)" = "02096a6d2c55e63f7fcb800690e4f889a25f6ec342e3adb4594e293b625215ab" "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.16 (registry+https://github.com/rust-lang/crates.io-index)" = "0aeedb8ca5f0f96be00f84073c6d0d5f962ecad020ef543dff99a7c12717a60e" +"checksum hyper 0.12.19 (registry+https://github.com/rust-lang/crates.io-index)" = "f1ebec079129e43af5e234ef36ee3d7e6085687d145b7ea653b262d16c6b65f1" "checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" "checksum indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)" = "40ecd1e2ee08e6c255ce890f5a99d17000850e664e7acf119fb03b25b0575bfe" @@ -3619,7 +3537,7 @@ dependencies = [ "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" -"checksum libc 0.2.44 (registry+https://github.com/rust-lang/crates.io-index)" = "10923947f84a519a45c8fefb7dd1b3e8c08747993381adee176d7a82b4195311" +"checksum libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)" = "2d2857ec59fadc0773853c664d2d18e7198e83883e7060b63c924cb077bd5c74" "checksum libloading 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "fd38073de8f7965d0c17d30546d4bb6da311ab428d1c7a3fc71dff7f9d4979b9" "checksum libp2p 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)" = "" "checksum libp2p-core 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)" = "" @@ -3649,16 +3567,13 @@ dependencies = [ "checksum make-cmd 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a8ca8afbe8af1785e09636acb5a41e08a765f5f0340568716c18a8700ba3c0d3" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "148fab2e51b4f1cfc66da2a7c32981d1d3c083a803978268bb11fe4b86925e7a" -"checksum memchr 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0a3eb002f0535929f1199681417029ebea04aadc0c7a4224b46be99c7f5d6a16" +"checksum memchr 2.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "db4c41318937f6e76648f42826b1d9ade5c09cafb5aef7e351240a70f39206e9" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "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 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 multiaddr 0.3.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)" = "" -"checksum multiaddr 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b97d4088dff9e0a93617a3f00213c6c1e338342c45de23cf317e613eb8e04e36" -"checksum multibase 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b9c35dac080fd6e16a99924c8dfdef0af89d797dd851adab25feaffacf7850d6" -"checksum multihash 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7d49add5f49eb08bfc4d01ff286b84a48f53d45314f165c2d6efe477222d24f3" "checksum multihash 0.8.1-pre (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)" = "" "checksum multistream-select 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)" = "" "checksum native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f74dbadc8b43df7864539cedb7bc91345e532fdd913cfdc23ad94f4d2d40fbc0" @@ -3671,13 +3586,13 @@ dependencies = [ "checksum num-integer 0.1.39 (registry+https://github.com/rust-lang/crates.io-index)" = "e83d528d2677f0518c570baf2b7abdcf0cd2d248860b68507bdcb3e91d4c0cea" "checksum num-traits 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "92e5113e9fd4cc14ded8e499429f396a20f98c772a47cc8622a736e1ec843c31" "checksum num-traits 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0b3a5d7cc97d6d30d8b9bc8fa19bf45349ffe46241e8816f50f62f6d6aaabee1" -"checksum num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c51a3322e4bca9d212ad9a158a02abc6934d005490c054a2778df73a70aa0a30" +"checksum num_cpus 1.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5a69d464bdc213aaaff628444e99578ede64e9c854025aa43b9796530afa9238" "checksum number_prefix 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "dbf9993e59c894e3c08aa1c2712914e9e6bf1fcbfc6bef283e2183df345a4fee" "checksum numext-constructor 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "0e938dadad7c0412ac4e2277846ba3b7241fae69c66e9b0389ea0fafa4be8e23" "checksum numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b58badd890ecf25ccef71682442c89ec2139772c5174782a0e9301a045648a3e" "checksum numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5dc24e4bed29ec6706d11ebe8ee5a77eb99de62b60e3af22ec704aae3f548c0d" "checksum openssl 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "a3605c298474a3aa69de92d21139fb5e2a81688d308262359d85cdd0d12a7985" -"checksum openssl-sys 0.9.39 (registry+https://github.com/rust-lang/crates.io-index)" = "278c1ad40a89aa1e741a1eed089a2f60b18fab8089c3139b542140fc7d674106" +"checksum openssl-sys 0.9.40 (registry+https://github.com/rust-lang/crates.io-index)" = "1bb974e77de925ef426b6bc82fce15fd45bdcbeb5728bffcfc7cdeeb7ce1c2d6" "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 parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e" @@ -3716,7 +3631,7 @@ dependencies = [ "checksum rayon 0.8.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b614fe08b6665cb9a231d07ac1364b0ef3cb3698f1239ee0c4c3a88a524f54c8" "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 redox_syscall 0.1.43 (registry+https://github.com/rust-lang/crates.io-index)" = "679da7508e9a6390aeaf7fbd02a800fdc64b73fe2204dd2c8ae66d22d9d5ad5d" +"checksum redox_syscall 0.1.44 (registry+https://github.com/rust-lang/crates.io-index)" = "a84bcd297b87a545980a2d25a0beb72a1f490c31f0a9fde52fca35bfbb1ceb70" "checksum redox_termios 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7e891cfe48e9100a70a3b6eb652fef28920c117d366339687bd5576160db0f76" "checksum regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "9329abc99e39129fcceabd24cf5d85b4671ef7c29c50e972bc5afe32438ec384" "checksum regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37e7cbbd370869ce2e8dff25c7018702d10b21a20ef7135316f8daecd6c25b7f" @@ -3727,7 +3642,7 @@ dependencies = [ "checksum rocksdb 0.10.0 (git+https://github.com/nervosnetwork/rust-rocksdb)" = "" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" "checksum rust-ini 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ac66e816614e124a692b6ac1b8437237a518c9155a3aacab83a373982630c715" -"checksum rustc-demangle 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "bcfe5b13211b4d78e5c2cadfebd7769197d95c639c35a50057eb4c05de811395" +"checksum rustc-demangle 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "01b90379b8664dd83460d59bdc5dd1fd3172b8913788db483ed1325171eab2f7" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "138e3e0acb6c9fb258b19b67cb8abd63c00679d2851805ea151465464fe9030a" "checksum rusty-fork 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9591f190d2852720b679c21f66ad929f9f1d7bb09d1193c26167586029d8489c" @@ -3766,7 +3681,7 @@ dependencies = [ "checksum string 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "98998cced76115b1da46f63388b909d118a37ae0be0f82ad35773d4a4bc9d18d" "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum syn 0.11.11 (registry+https://github.com/rust-lang/crates.io-index)" = "d3b891b9015c88c576343b9b3e41c2c11a51c219ef067b264bd9c8aa9b441dad" -"checksum syn 0.15.22 (registry+https://github.com/rust-lang/crates.io-index)" = "ae8b29eb5210bc5cf63ed6149cbf9adfc82ac0be023d8735c176ee74a2db4da7" +"checksum syn 0.15.23 (registry+https://github.com/rust-lang/crates.io-index)" = "9545a6a093a3f0bd59adb472700acc08cad3776f860f16a897dfce8c88721cbc" "checksum synom 0.11.3 (registry+https://github.com/rust-lang/crates.io-index)" = "a393066ed9010ebaed60b9eafa373d4b1baac186dd7e008555b0f702b51945b6" "checksum synstructure 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "73687139bf99285483c96ac0add482c3776528beac1d97d444f6e91f203a2015" "checksum syntex 0.58.1 (registry+https://github.com/rust-lang/crates.io-index)" = "a8f5e3aaa79319573d19938ea38d068056b826db9883a5d47f86c1cecc688f0e" @@ -3783,9 +3698,9 @@ dependencies = [ "checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6" "checksum thread-scoped 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "bcbb6aa301e5d3b0b5ef639c9a9c7e2f1c944f177b460c04dc24c69b1fa2bd99" "checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" -"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b" +"checksum time 0.1.41 (registry+https://github.com/rust-lang/crates.io-index)" = "847da467bf0db05882a9e2375934a8a55cffdc9db0d128af1518200260ba1f6c" "checksum tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e9175261fbdb60781fcd388a4d6cc7e14764a2b629a7ad94abb439aed223a44f" -"checksum tk-listen 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "dec7ba6a80b7695fc2abb21af18bed445a362ffd80b64704771ce142d6d2151d" +"checksum tk-listen 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5462b0f968c0457efe38fcd2df7e487096b992419e4f5337b06775a614bbda4b" "checksum tokio 0.1.13 (registry+https://github.com/rust-lang/crates.io-index)" = "a7817d4c98cc5be21360b3b37d6036fe9b7aefa5b7a201b7b16ff33423822f7d" "checksum tokio-codec 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c501eceaf96f0e1793cf26beb63da3d11c738c4a943fdf3746d81d64684c39f" "checksum tokio-core 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "aeeffbbb94209023feaef3c196a41cbcdafa06b4a6f893f68779bb5e53796f71" @@ -3801,7 +3716,7 @@ dependencies = [ "checksum tokio-tls 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "772f4b04e560117fe3b0a53e490c16ddc8ba6ec437015d91fa385564996ed913" "checksum tokio-udp 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "66268575b80f4a4a710ef83d087fdfeeabdce9b74c797535fbac18a2cb906e92" "checksum tokio-uds 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)" = "99ce87382f6c1a24b513a72c048b2c8efe66cb5161c9061d00bee510f08dc168" -"checksum toml 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "19782e145d5abefb03758958f06ea35f7b1d8421b534140e0238fd3d0bfd66e3" +"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" "checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" @@ -3837,4 +3752,4 @@ dependencies = [ "checksum wincolor 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "561ed901ae465d6185fa7864d63fbd5720d0ef718366c9a4dc83cf6170d7e9ba" "checksum ws2_32-sys 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d59cefebd0c892fa2dd6de581e937301d8552cb44489cdff035c6187cb63fa5e" "checksum yaml-rust 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "95acf0db5515d07da9965ec0e0ba6cc2d825e2caeb7303b66ca441729801254e" -"checksum yamux 0.1.0 (git+https://github.com/paritytech/yamux)" = "" +"checksum yamux 0.1.3 (git+https://github.com/paritytech/yamux)" = "" diff --git a/Cargo.toml b/Cargo.toml index ede19cf1cb..9bb4d0f1ed 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,15 +25,11 @@ ckb-pow = { path = "pow" } ckb-network = { path = "network"} ckb-pool = { path = "pool"} ckb-rpc = { path = "rpc"} -ckb-verification = { path = "verification"} -ckb-time = { path = "util/time"} -ckb-script= { path = "script"} logger = { path = "util/logger" } numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } dir = { path = "util/dir" } ctrlc = { version = "3.1", features = ["termination"] } -lazy_static = "1.0" ckb-sync = { path = "sync"} serde_json = "1.0" crypto = { path = "util/crypto"} diff --git a/chain/Cargo.toml b/chain/Cargo.toml index 77328fdeee..0431fd65ea 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -6,9 +6,6 @@ authors = ["Nervos Core Dev "] edition = "2018" [dependencies] -serde = "1.0" -serde_derive = "1.0" -bincode = "1.0" log = "0.4" ckb-core = { path = "../core" } ckb-shared = { path = "../shared" } @@ -17,11 +14,8 @@ ckb-db = { path = "../db" } ckb-time = { path = "../util/time" } ckb-notify = { path = "../notify" } ckb-verification = { path = "../verification" } -avl-merkle = { path = "../util/avl" } numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } -lru-cache = { git = "https://github.com/nervosnetwork/lru-cache" } -fnv = "1.0.3" channel = { package= "crossbeam-channel", version = "0.3" } diff --git a/core/Cargo.toml b/core/Cargo.toml index 40008755e3..a2b6f8a57e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -13,10 +13,8 @@ numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heap numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } hash = {path = "../util/hash"} crypto = {path = "../util/crypto"} -ckb-time = { path = "../util/time" } bit-vec = "0.5.0" channel = { package= "crossbeam-channel", version = "0.3" } -rayon = "1.0" ckb-util = { path = "../util" } fnv = "1.0.3" merkle-root = {path = "../util/merkle-root"} diff --git a/db/Cargo.toml b/db/Cargo.toml index 6e4e6101ae..90996ca453 100644 --- a/db/Cargo.toml +++ b/db/Cargo.toml @@ -8,8 +8,6 @@ edition = "2018" [dependencies] bincode = "1.0" ckb-util = { path = "../util" } -ckb-core = { path = "../core" } -numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } rocksdb = { git = "https://github.com/nervosnetwork/rust-rocksdb" } fnv = "1.0.3" diff --git a/devtools/release/dependencies_check.rb b/devtools/release/dependencies_check.rb new file mode 100644 index 0000000000..9468712cf3 --- /dev/null +++ b/devtools/release/dependencies_check.rb @@ -0,0 +1,28 @@ +#!/usr/bin/env ruby +# find unused dependencies in Cargo.toml +# this is a rough checker, please double check the result for special cases, e.g. features / macro / crate_name::fn() + +require 'toml-rb' +require 'colorize' + +def crates_in_rust_files(folder) + Dir["#{folder}/**/*.rs"].inject([]) do |crates, file_name| + File.readlines(file_name).grep(/use (\w*)(?:::|;)/) {|_| crates << $1} + crates + end.uniq +end + +def crates_in_cargo_toml(folder) + (TomlRB.load_file(File.join(folder, 'Cargo.toml'))['dependencies'] || {}).keys.map{|s| s.gsub(/-/, '_')} +end + +def find_unused_dependencies(folder) + puts "checking #{folder}/Cargo.toml" + unused = crates_in_cargo_toml(folder) - crates_in_rust_files(folder) + puts unused.empty? ? "OK".green : "Found #{unused}".red +end + +folders = TomlRB.load_file(File.join(ARGV[0], 'Cargo.toml'))['workspace']['members'] + [ARGV[0]] +folders.each do |folder| + find_unused_dependencies(folder) +end diff --git a/miner/Cargo.toml b/miner/Cargo.toml index 98e1945909..2147537b61 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -15,7 +15,6 @@ ckb-util = { path = "../util" } ckb-notify = { path = "../notify" } ckb-pool = { path = "../pool" } ckb-time = { path = "../util/time" } -flatbuffers = "0.5.0" rand = "0.6" serde = "1.0" serde_derive = "1.0" diff --git a/notify/Cargo.toml b/notify/Cargo.toml index 027ad5c459..031f18cd35 100644 --- a/notify/Cargo.toml +++ b/notify/Cargo.toml @@ -7,7 +7,6 @@ edition = "2018" [dependencies] fnv = "1.0" -ckb-util = { path = "../util" } ckb-core = { path = "../core" } channel = { package= "crossbeam-channel", version = "0.3" } log = "0.4" diff --git a/pool/Cargo.toml b/pool/Cargo.toml index 921a59167f..496ba886d8 100644 --- a/pool/Cargo.toml +++ b/pool/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" ckb-core = { path = "../core" } ckb-shared = { path = "../shared" } ckb-chain-spec = { path = "../spec" } -ckb-util = { path = "../util" } ckb-time = { path = "../util/time" } ckb-notify = { path = "../notify" } ckb-verification = { path = "../verification" } @@ -18,8 +17,6 @@ lru-cache = { git = "https://github.com/nervosnetwork/lru-cache" } linked-hash-map = { git = "https://github.com/nervosnetwork/linked-hash-map", rev = "df27f21" } serde = "1.0" serde_derive = "1.0" -bincode = "1.0" -rand = "0.6" log = "0.4" fnv = "1.0.3" channel = { package= "crossbeam-channel", version = "0.3" } diff --git a/script/Cargo.toml b/script/Cargo.toml index 4439aae9f7..10248bba8c 100644 --- a/script/Cargo.toml +++ b/script/Cargo.toml @@ -10,8 +10,6 @@ numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heap byteorder = "1.2.2" crypto = {path = "../util/crypto"} ckb-core = { path = "../core" } -serde = "1.0" -serde_derive = "1.0" hash = {path = "../util/hash"} ckb-vm = { git = "https://github.com/nervosnetwork/ckb-vm", rev = "1622ba0" } faster-hex = "0.1" diff --git a/shared/Cargo.toml b/shared/Cargo.toml index 243ef4d79a..a7264ad65a 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -8,18 +8,15 @@ edition = "2018" serde = "1.0" serde_derive = "1.0" bincode = "1.0" -log = "0.4" ckb-core = { path = "../core" } ckb-chain-spec = { path = "../spec" } ckb-util = { path = "../util" } ckb-db = { path = "../db" } -ckb-time = { path = "../util/time" } avl = { package = "avl-merkle", path = "../util/avl" } numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } lru-cache = { git = "https://github.com/nervosnetwork/lru-cache" } fnv = "1.0.3" -crossbeam-channel = "0.3" [dev-dependencies] env_logger = "0.6" diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 4eee2d8432..2c987aa047 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -11,7 +11,6 @@ ckb-shared = { path = "../shared" } ckb-core = { path = "../core" } numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } -multiaddr = "0.3" ckb-network = { path = "../network" } log = "0.4" fnv = "1.0" @@ -19,7 +18,6 @@ ckb-protocol = { path = "../protocol" } ckb-util = { path = "../util" } ckb-pool = { path = "../pool" } ckb-time = { path = "../util/time" } -lazy_static = "1.0" bitflags = "1.0" ckb-verification = { path = "../verification" } serde = "1.0" diff --git a/util/crypto/Cargo.toml b/util/crypto/Cargo.toml index 2972211201..e68eb88d78 100644 --- a/util/crypto/Cargo.toml +++ b/util/crypto/Cargo.toml @@ -9,7 +9,6 @@ edition = "2018" secp256k1 = { git = "https://github.com/nervosnetwork/rust-secp256k1", optional = true, features = ["rand"] } lazy_static = "1.0" failure = "0.1.1" -failure_derive = "0.1.1" rand = "0.6" numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } faster-hex = "0.1" diff --git a/verification/Cargo.toml b/verification/Cargo.toml index 100f3193a0..630f5d993f 100644 --- a/verification/Cargo.toml +++ b/verification/Cargo.toml @@ -6,11 +6,9 @@ authors = ["Nervos Core Dev "] edition = "2018" [dependencies] -log = "0.4" ckb-core = { path = "../core" } ckb-time = { path = "../util/time" } ckb-shared = { path = "../shared" } -ckb-util = { path = "../util" } ckb-script = { path = "../script" } ckb-pow = { path = "../pow" } merkle-root = {path = "../util/merkle-root"} @@ -18,7 +16,6 @@ numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heap numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } rayon = "1.0" fnv = "1.0.3" -crossbeam-channel = "0.3" [dev-dependencies] ckb-db = { path = "../db" } From 95451e7c432d421c0eed9f04f23d0b3ca89b9546 Mon Sep 17 00:00:00 2001 From: jjy Date: Wed, 19 Dec 2018 22:24:06 +0800 Subject: [PATCH 30/45] fix: use new strategy to evict inbound peer --- Cargo.lock | 1 + network/Cargo.toml | 1 + network/src/ckb_service.rs | 2 + network/src/network.rs | 17 +++- network/src/network_group.rs | 24 +++-- network/src/peers_registry.rs | 142 +++++++++++++++++++--------- network/src/ping_service.rs | 12 ++- network/src/tests/peers_registry.rs | 69 ++++++++++++-- 8 files changed, 204 insertions(+), 64 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 196a47525a..db16161475 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -465,6 +465,7 @@ name = "ckb-network" version = "0.3.0-pre" dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", + "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", "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)", diff --git a/network/Cargo.toml b/network/Cargo.toml index 8c7da3cca1..e4a0dfcc20 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -18,3 +18,4 @@ tokio = "0.1.8" futures = { version = "0.1.19", features = ["use_std"] } snap = "0.2" libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev="cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] } +ckb-time = { path = "../util/time" } diff --git a/network/src/ckb_service.rs b/network/src/ckb_service.rs index eac2502b03..19a1909160 100644 --- a/network/src/ckb_service.rs +++ b/network/src/ckb_service.rs @@ -8,6 +8,7 @@ use crate::protocol_service::ProtocolService; use crate::CKBProtocolHandler; use crate::Network; use crate::PeerId; +use ckb_time::now_ms; use futures::future::{self, Future}; use futures::Stream; use libp2p::core::{Endpoint, Multiaddr, UniqueConnecState}; @@ -81,6 +82,7 @@ impl CKBService { move |data| { // update kad_system when we received data kad_system.update_kbuckets(peer_id.clone()); + network.modify_peer(&peer_id, |peer| peer.last_message_time = Some(now_ms())); let protocol_handler = Arc::clone(&protocol_handler); let network = Arc::clone(&network); let handle_received = future::lazy(move || { diff --git a/network/src/network.rs b/network/src/network.rs index 35d4cb0cbd..1b814a40d5 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -32,7 +32,6 @@ use std::boxed::Box; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; use std::sync::Arc; use std::time::Duration; -use std::time::Instant; use std::usize; use tokio::io::{AsyncRead, AsyncWrite}; @@ -51,7 +50,7 @@ pub struct SessionInfo { pub struct PeerInfo { pub peer_id: PeerId, pub endpoint_role: Endpoint, - pub last_ping_time: Option, + pub last_ping_time: Option, pub connected_addr: Multiaddr, pub identify_info: Option, } @@ -106,6 +105,20 @@ impl Network { peers_registry.connection_status() } + pub(crate) fn modify_peer(&self, peer_id: &PeerId, mut f: F) -> bool + where + F: FnMut(&mut PeerConnection) -> (), + { + let mut peers_registry = self.peers_registry.write(); + match peers_registry.get_mut(peer_id) { + Some(peer) => { + f(peer); + true + } + None => false, + } + } + pub(crate) fn get_peer_identify_info(&self, peer_id: &PeerId) -> Option { let peers_registry = self.peers_registry.read(); peers_registry diff --git a/network/src/network_group.rs b/network/src/network_group.rs index 8405f11171..9b9d1cdf06 100644 --- a/network/src/network_group.rs +++ b/network/src/network_group.rs @@ -1,7 +1,13 @@ use libp2p::core::{AddrComponent, Multiaddr}; use std::net::IpAddr; -pub type Group = Vec; +#[derive(Hash, Eq, PartialEq, Debug)] +pub enum Group { + NoGroup, + LocalNetwork, + IP4([u8; 2]), + IP6([u8; 4]), +} pub trait NetworkGroup { fn network_group(&self) -> Group; @@ -22,28 +28,30 @@ impl NetworkGroup for Multiaddr { fn network_group(&self) -> Group { if let Some(ip_addr) = extract_ip_addr(self) { if ip_addr.is_loopback() { - // Local NetworkGroup - return vec![1]; + return Group::LocalNetwork; } // TODO uncomment after ip feature stable // if !ip_addr.is_global() { // // Global NetworkGroup - // return vec![2] + // return Group::GlobalNetwork // } // IPv4 NetworkGroup if let IpAddr::V4(ipv4) = ip_addr { - return ipv4.octets()[0..2].to_vec(); + let bits = ipv4.octets(); + return Group::IP4([bits[0], bits[1]]); } // IPv6 NetworkGroup if let IpAddr::V6(ipv6) = ip_addr { if let Some(ipv4) = ipv6.to_ipv4() { - return ipv4.octets()[0..2].to_vec(); + let bits = ipv4.octets(); + return Group::IP4([bits[0], bits[1]]); } - return ipv6.octets()[0..4].to_vec(); + let bits = ipv6.octets(); + return Group::IP6([bits[0], bits[1], bits[2], bits[3]]); } } // Can't group addr - vec![0] + Group::NoGroup } } diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index 465db4112c..e10adbd9b2 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -1,7 +1,8 @@ use crate::network_group::{Group, NetworkGroup}; -use crate::peer_store::{PeerStore, Score}; +use crate::peer_store::PeerStore; use crate::{Error, ErrorKind, PeerId, PeerIndex, ProtocolId}; use bytes::Bytes; +use ckb_time::now_ms; use ckb_util::RwLock; use fnv::{FnvHashMap, FnvHashSet}; use futures::sync::mpsc::UnboundedSender; @@ -12,7 +13,8 @@ use rand::seq::SliceRandom; use rand::thread_rng; use std::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Arc; -use std::time::Instant; + +pub(crate) const EVICTION_PROTECT_PEERS: usize = 8; struct PeerConnections { id_allocator: AtomicUsize, @@ -97,7 +99,10 @@ pub struct PeerConnection { pub(crate) pinger_loader: UniqueConnec, pub identify_info: Option, pub(crate) ckb_protocols: Vec, - pub last_ping_time: Option, + pub last_ping_time: Option, + pub last_message_time: Option, + pub ping: Option, + pub connected_time: Option, } impl PeerConnection { @@ -108,7 +113,10 @@ impl PeerConnection { pinger_loader: UniqueConnec::empty(), identify_info: None, ckb_protocols: Vec::with_capacity(1), + ping: None, last_ping_time: None, + last_message_time: None, + connected_time: None, peer_index: None, } } @@ -172,6 +180,14 @@ fn find_most_peers_in_same_network_group<'a>( .unwrap_or_else(Vec::new) } +fn sort_then_drop_last_n_elements(list: &mut Vec, n: usize, compare: F) +where + F: FnMut(&T, &T) -> std::cmp::Ordering, +{ + list.sort_by(compare); + list.truncate(list.len().saturating_sub(n)); +} + impl PeersRegistry { pub fn new( peer_store: Arc>>, @@ -217,19 +233,16 @@ impl PeersRegistry { )) .into()); } - let candidate_score = { - let peer_store = self.peer_store.read(); - if peer_store.is_banned(&peer_id) { - return Err( - ErrorKind::InvalidNewPeer(format!("peer {:?} is denied", peer_id)).into(), - ); - } - peer_store.peer_score_or_default(&peer_id) - }; + if self.peer_store.read().is_banned(&peer_id) { + return Err( + ErrorKind::InvalidNewPeer(format!("peer {:?} is denied", peer_id)).into(), + ); + } + let connection_status = self.connection_status(); // check peers connection limitation if connection_status.unreserved_inbound >= self.max_inbound - && !self.try_evict_inbound_peer(candidate_score) + && !self.try_evict_inbound_peer() { return Err(ErrorKind::InvalidNewPeer(format!( "reach max inbound peers limitation, reject peer {:?}", @@ -242,42 +255,80 @@ impl PeersRegistry { Ok(()) } - fn try_evict_inbound_peer(&mut self, candidate_score: Score) -> bool { - let peer_id = { - let inbound_peers = self + fn try_evict_inbound_peer(&mut self) -> bool { + let peer_id: PeerId = { + let mut candidate_peers = self .peers .iter() - .filter(|(peer_id, peer)| peer.is_inbound() && !self.is_reserved(peer_id)); - let candidate_peers = find_most_peers_in_same_network_group(inbound_peers); + .filter(|(peer_id, peer)| peer.is_inbound() && !self.is_reserved(peer_id)) + .collect::>(); let peer_store = self.peer_store.read(); - - // must have less score than candidate_score - let mut lowest_score = candidate_score - 1; - let mut low_score_peers = Vec::new(); - for peer_id in candidate_peers { - if let Some(score) = peer_store.peer_score(peer_id) { - if score > lowest_score { - continue; - } - if score < lowest_score { - lowest_score = score; - low_score_peers.clear(); - } - low_score_peers.push(peer_id); - } - } - // failed to evict - if low_score_peers.is_empty() { - return false; - } + // Protect peers based on characteristics that an attacker hard to simulate or manipulate + // Protect peers which has the highest score + sort_then_drop_last_n_elements( + &mut candidate_peers, + EVICTION_PROTECT_PEERS, + |(peer_id1, _), (peer_id2, _)| { + let peer1_score = peer_store.peer_score(peer_id1).unwrap_or_default(); + let peer2_score = peer_store.peer_score(peer_id2).unwrap_or_default(); + peer1_score.cmp(&peer2_score) + }, + ); + + // Protect peers which has the lowest ping + sort_then_drop_last_n_elements( + &mut candidate_peers, + EVICTION_PROTECT_PEERS, + |(_, peer1), (_, peer2)| { + let peer1_ping = peer1.ping.unwrap_or_else(|| std::u64::MAX); + let peer2_ping = peer2.ping.unwrap_or_else(|| std::u64::MAX); + peer2_ping.cmp(&peer1_ping) + }, + ); + + // Protect peers which most recently sent messages + sort_then_drop_last_n_elements( + &mut candidate_peers, + EVICTION_PROTECT_PEERS, + |(_, peer1), (_, peer2)| { + let peer1_last_message_time = peer1.last_message_time.unwrap_or_default(); + let peer2_last_message_time = peer2.last_message_time.unwrap_or_default(); + peer1_last_message_time.cmp(&peer2_last_message_time) + }, + ); + candidate_peers.sort_by(|(_, peer1), (_, peer2)| { + let peer1_last_connected_at = peer1.connected_time.unwrap_or_else(|| std::u64::MAX); + let peer2_last_connected_at = peer2.connected_time.unwrap_or_else(|| std::u64::MAX); + peer2_last_connected_at.cmp(&peer1_last_connected_at) + }); + // Protect half peers which have the longest connection time + let protect_peers = candidate_peers.len() / 2; + sort_then_drop_last_n_elements( + &mut candidate_peers, + protect_peers, + |(_, peer1), (_, peer2)| { + let peer1_last_connected_at = + peer1.connected_time.unwrap_or_else(|| std::u64::MAX); + let peer2_last_connected_at = + peer2.connected_time.unwrap_or_else(|| std::u64::MAX); + peer2_last_connected_at.cmp(&peer1_last_connected_at) + }, + ); + + let mut evict_group = + find_most_peers_in_same_network_group(candidate_peers.into_iter()); let mut rng = thread_rng(); - low_score_peers[..] - .choose(&mut rng) - .unwrap() - .to_owned() - .to_owned() + evict_group.shuffle(&mut rng); + // randomly evict a lowest scored peer + match evict_group + .iter() + .min_by_key(|peer_id| peer_store.peer_score(peer_id).unwrap_or_default()) + { + Some(peer_id) => peer_id.to_owned().to_owned(), + None => return false, + } }; - debug!("evict inbound peer {:?}", peer_id); + debug!(target: "network", "evict inbound peer {:?}", peer_id); self.drop_peer(&peer_id); true } @@ -325,7 +376,8 @@ impl PeersRegistry { self.peer_store .write() .new_connected_peer(&peer_id, connected_addr.clone()); - let peer = PeerConnection::new(connected_addr, endpoint); + let mut peer = PeerConnection::new(connected_addr, endpoint); + peer.connected_time = Some(now_ms()); let peer_index = self.peers.or_insert(peer_id.clone(), peer); debug!(target: "network", "allocate peer_index {} to peer {:?}", peer_index, peer_id); peer_index diff --git a/network/src/ping_service.rs b/network/src/ping_service.rs index 0d08827f37..5d9ab0873a 100644 --- a/network/src/ping_service.rs +++ b/network/src/ping_service.rs @@ -4,6 +4,7 @@ use crate::protocol_service::ProtocolService; use crate::transport::TransportOutput; use crate::Network; use crate::PeerId; +use ckb_time::now_ms; use futures::future::{self, Future}; use futures::stream::FuturesUnordered; use futures::Stream; @@ -140,7 +141,7 @@ impl ProtocolService for PingService { }) } }); - let ping_start_time = Instant::now(); + let ping_start_time = now_ms(); let ping_future = Future::then(Timeout::new(ping_future, ping_timeout), { let network = Arc::clone(&network); @@ -148,13 +149,18 @@ impl ProtocolService for PingService { let mut peer_store = network.peer_store().write(); match result { Ok(peer_id) => { - let received_during = ping_start_time.elapsed(); + let now = now_ms(); + let ping = now - ping_start_time; + network.modify_peer(&peer_id, |peer| { + peer.ping = Some(ping); + peer.last_ping_time = Some(now); + }); peer_store.report(&peer_id, Behaviour::Ping); trace!( target: "network", "received pong from {:?} in {:?}", peer_id, - received_during + ping ); Ok(()) } diff --git a/network/src/tests/peers_registry.rs b/network/src/tests/peers_registry.rs index 613984823d..6f0bfcf022 100644 --- a/network/src/tests/peers_registry.rs +++ b/network/src/tests/peers_registry.rs @@ -1,9 +1,10 @@ use crate::{ memory_peer_store::MemoryPeerStore, peer_store::{Behaviour, PeerStore}, - peers_registry::PeersRegistry, - random_peer_id, PeerId, ToMultiaddr, + peers_registry::{PeersRegistry, EVICTION_PROTECT_PEERS}, + random_peer_id, ToMultiaddr, }; +use ckb_time::now_ms; use ckb_util::RwLock; use std::default::Default; use std::sync::Arc; @@ -83,13 +84,58 @@ fn test_accept_inbound_peer_eviction() { let lowest_score_peer = random_peer_id().unwrap(); let addr1 = "/ip4/127.0.0.1".to_multiaddr().unwrap(); let addr2 = "/ip4/192.168.0.1".to_multiaddr().unwrap(); + // prepare protected peers + let longest_connection_time_peers_count = 5; + let protected_peers_count = 3 * EVICTION_PROTECT_PEERS + longest_connection_time_peers_count; let mut peers_registry = PeersRegistry::new( Arc::clone(&peer_store), - 5, + (protected_peers_count + longest_connection_time_peers_count) as u32, 3, false, vec![reserved_peer.clone()], ); + for _ in 0..protected_peers_count { + assert!(peers_registry + .accept_inbound_peer(random_peer_id().unwrap(), addr2.clone()) + .is_ok()); + } + let mut peers_iter = peers_registry + .peers_iter() + .map(|(peer_id, _)| peer_id.to_owned()) + .collect::>() + .into_iter(); + // higest scored peers + { + let mut peer_store = peer_store.write(); + for _ in 0..EVICTION_PROTECT_PEERS { + let peer_id = peers_iter.next().unwrap(); + peer_store.report(&peer_id, Behaviour::Ping); + peer_store.report(&peer_id, Behaviour::Ping); + } + } + // lowest ping peers + for _ in 0..EVICTION_PROTECT_PEERS { + let peer_id = peers_iter.next().unwrap(); + let mut peer = peers_registry.get_mut(&peer_id).unwrap(); + peer.ping = Some(0); + } + // peers which most recently sent messages + let now = now_ms(); + for _ in 0..EVICTION_PROTECT_PEERS { + let peer_id = peers_iter.next().unwrap(); + let mut peer = peers_registry.get_mut(&peer_id).unwrap(); + peer.last_message_time = Some(now + 10000); + } + // protect 5 peers which have the longest connection time + for _ in 0..longest_connection_time_peers_count { + let peer_id = peers_iter.next().unwrap(); + let mut peer = peers_registry.get_mut(&peer_id).unwrap(); + peer.connected_time = Some(now.saturating_sub(10000)); + } + let mut new_peer_ids = (0..3) + .into_iter() + .map(|_| random_peer_id().unwrap()) + .collect::>(); // setup 3 node and 1 reserved node from addr1 peers_registry .accept_inbound_peer(reserved_peer.clone(), addr1.clone()) @@ -98,17 +144,17 @@ fn test_accept_inbound_peer_eviction() { .accept_inbound_peer(evict_target.clone(), addr1.clone()) .expect("accept"); peers_registry - .accept_inbound_peer(random_peer_id().unwrap(), addr1.clone()) + .accept_inbound_peer(new_peer_ids[0].clone(), addr1.clone()) .expect("accept"); peers_registry - .accept_inbound_peer(random_peer_id().unwrap(), addr1.clone()) + .accept_inbound_peer(new_peer_ids[1].clone(), addr1.clone()) .expect("accept"); // setup 2 node from addr2 peers_registry .accept_inbound_peer(lowest_score_peer.clone(), addr2.clone()) .expect("accept"); peers_registry - .accept_inbound_peer(random_peer_id().unwrap(), addr2.clone()) + .accept_inbound_peer(new_peer_ids[2].clone(), addr2.clone()) .expect("accept"); // setup score { @@ -120,6 +166,17 @@ fn test_accept_inbound_peer_eviction() { peer_store.report(&reserved_peer, Behaviour::FailedToPing); peer_store.report(&evict_target, Behaviour::FailedToPing); } + // make sure other peers should not protected by longest connection time rule + new_peer_ids.extend_from_slice(&[ + reserved_peer.clone(), + evict_target.clone(), + lowest_score_peer.clone(), + ]); + for peer_id in new_peer_ids { + let mut peer = peers_registry.get_mut(&peer_id).unwrap(); + // push the connected_time to make sure peer is unprotect + peer.connected_time = Some(now + 10000); + } // should evict evict target assert!(peers_registry.get(&evict_target).is_some()); peers_registry From 1e8841ec7958d1c89411bc3b20a3e4f9f5cd075a Mon Sep 17 00:00:00 2001 From: jjy Date: Thu, 20 Dec 2018 16:08:54 +0800 Subject: [PATCH 31/45] refactor: remove unnessacey code and clippy attributes --- network/src/memory_peer_store.rs | 6 +++--- network/src/network.rs | 2 +- network/src/peer_store.rs | 2 +- network/src/peers_registry.rs | 32 +++++++++++++++++--------------- sync/src/synchronizer/mod.rs | 2 +- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/network/src/memory_peer_store.rs b/network/src/memory_peer_store.rs index ef92953352..d048b7ec17 100644 --- a/network/src/memory_peer_store.rs +++ b/network/src/memory_peer_store.rs @@ -90,7 +90,7 @@ impl PeerStore for MemoryPeerStore { Some(score) => score, None => { debug!(target: "network", "behaviour {:?} is undefined", behaviour); - return ReportResult::Normal; + return ReportResult::Ok; } }; // apply reported score @@ -99,7 +99,7 @@ impl PeerStore for MemoryPeerStore { peer.score = peer.score.saturating_add(behaviour_score); peer.score } - None => return ReportResult::Normal, + None => return ReportResult::Ok, }; // ban peer is score is lower than ban_score if score < self.schema.ban_score() { @@ -107,7 +107,7 @@ impl PeerStore for MemoryPeerStore { self.ban_peer(peer_id.to_owned(), default_ban_timeout); return ReportResult::Banned; } - ReportResult::Normal + ReportResult::Ok } fn update_status(&mut self, peer_id: &PeerId, status: Status) { diff --git a/network/src/network.rs b/network/src/network.rs index 1b814a40d5..cc4e9210a9 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -62,7 +62,7 @@ impl PeerInfo { } #[inline] - pub fn is_incoming(&self) -> bool { + pub fn is_inbound(&self) -> bool { !self.is_outbound() } } diff --git a/network/src/peer_store.rs b/network/src/peer_store.rs index 5a14441c0a..f6d89c74b8 100644 --- a/network/src/peer_store.rs +++ b/network/src/peer_store.rs @@ -21,7 +21,7 @@ pub enum Status { #[derive(Debug, Copy, Clone, Eq, PartialEq)] pub enum ReportResult { - Normal, + Ok, Banned, } diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index e10adbd9b2..9bf0b66be6 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -24,18 +24,17 @@ struct PeerConnections { impl PeerConnections { #[inline] - fn get<'a>(&'a self, peer_id: &PeerId) -> Option<&'a PeerConnection> { + fn get(&self, peer_id: &PeerId) -> Option<&PeerConnection> { self.peers.get(peer_id) } - #[allow(clippy::needless_lifetimes)] #[inline] - fn get_peer_id<'a>(&'a self, peer_index: PeerIndex) -> Option<&'a PeerId> { + fn get_peer_id(&self, peer_index: PeerIndex) -> Option<&PeerId> { self.peer_id_by_index.get(&peer_index) } #[inline] - fn get_mut<'a>(&'a mut self, peer_id: &PeerId) -> Option<&'a mut PeerConnection> { + fn get_mut(&mut self, peer_id: &PeerId) -> Option<&mut PeerConnection> { self.peers.get_mut(peer_id) } @@ -48,9 +47,8 @@ impl PeerConnections { None } - #[allow(clippy::needless_lifetimes)] #[inline] - fn iter<'a>(&'a self) -> impl Iterator { + fn iter(&self) -> impl Iterator { self.peers.iter() } #[inline] @@ -68,6 +66,12 @@ impl PeerConnections { self.peer_id_by_index.entry(peer_index).or_insert(peer_id); peer_index } + + fn clear(&mut self) { + self.peers.clear(); + self.peer_id_by_index.clear(); + self.id_allocator.store(0, Ordering::Relaxed) + } } impl Default for PeerConnections { @@ -211,9 +215,8 @@ impl PeersRegistry { } } - #[allow(clippy::needless_lifetimes)] #[inline] - pub fn get_peer_id<'a>(&'a self, peer_index: PeerIndex) -> Option<&'a PeerId> { + pub fn get_peer_id(&self, peer_index: PeerIndex) -> Option<&PeerId> { self.peers.get_peer_id(peer_index) } @@ -383,19 +386,18 @@ impl PeersRegistry { peer_index } - #[allow(clippy::needless_lifetimes)] #[inline] - pub fn peers_iter<'a>(&'a self) -> impl Iterator { + pub fn peers_iter(&self) -> impl Iterator { self.peers.iter() } #[inline] - pub fn get<'a>(&'a self, peer_id: &PeerId) -> Option<&'a PeerConnection> { + pub fn get(&self, peer_id: &PeerId) -> Option<&PeerConnection> { self.peers.get(peer_id) } #[inline] - pub fn get_mut<'a>(&'a mut self, peer_id: &PeerId) -> Option<&'a mut PeerConnection> { + pub fn get_mut(&mut self, peer_id: &PeerId) -> Option<&mut PeerConnection> { self.peers.get_mut(peer_id) } @@ -424,8 +426,8 @@ impl PeersRegistry { } #[inline] - pub fn connected_peers_indexes<'a>(&'a self) -> impl Iterator + 'a { - Box::new(self.peers.peer_id_by_index.iter().map(|(k, _v)| *k)) + pub fn connected_peers_indexes(&self) -> impl Iterator + '_ { + self.peers.peer_id_by_index.iter().map(|(k, _v)| *k) } #[inline] @@ -436,6 +438,6 @@ impl PeersRegistry { #[inline] pub fn drop_all(&mut self) { debug!(target: "network", "drop_all"); - self.peers = Default::default(); + self.peers.clear() } } diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index 1ee14daeba..b51f105411 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -1034,7 +1034,7 @@ mod tests { peer_id: random_peer_id().unwrap(), endpoint_role: Endpoint::Dialer, last_ping_time: None, - connected_addr: "/ip4/127.0.0.1".to_multiaddr().unwrap(), + connected_addr: "/ip4/127.0.0.1".to_multiaddr().except("parse multiaddr"), identify_info: None, }, protocol_version: None, From 8eebc0a4f0d865aee9646492e4e4dfa92b5968c3 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Thu, 20 Dec 2018 17:01:19 +0800 Subject: [PATCH 32/45] refactor: get rid of redundant box --- network/src/memory_peer_store.rs | 8 +++++--- network/src/network.rs | 8 ++++---- network/src/network_service.rs | 3 +-- network/src/outbound_peer_service.rs | 1 - network/src/peer_store.rs | 7 ++++--- network/src/peers_registry.rs | 4 ++-- network/src/tests/peers_registry.rs | 15 ++++++--------- sync/src/synchronizer/mod.rs | 2 +- 8 files changed, 23 insertions(+), 25 deletions(-) diff --git a/network/src/memory_peer_store.rs b/network/src/memory_peer_store.rs index d048b7ec17..c0ca1f9793 100644 --- a/network/src/memory_peer_store.rs +++ b/network/src/memory_peer_store.rs @@ -134,7 +134,7 @@ impl PeerStore for MemoryPeerStore { self.add_peer(peer_id, vec![addr]); } - fn bootnodes<'a>(&'a self) -> Box + 'a> { + fn bootnodes<'a>(&'a self) -> Box + 'a> { let mut bootnodes = self .peers_to_attempt() .chain(self.bootnodes.iter().map(|(peer_id, addr)| (peer_id, addr))) @@ -147,7 +147,7 @@ impl PeerStore for MemoryPeerStore { fn peer_addrs<'a>( &'a self, peer_id: &'a PeerId, - ) -> Option + 'a>> { + ) -> Option + 'a>> { let iter = match self.peers.get(peer_id) { Some(peer) => peer.addresses.iter(), None => return None, @@ -155,7 +155,9 @@ impl PeerStore for MemoryPeerStore { Some(Box::new(iter) as Box<_>) } - fn peers_to_attempt<'a>(&'a self) -> Box + 'a> { + fn peers_to_attempt<'a>( + &'a self, + ) -> Box + 'a> { trace!( target: "network", "try fetch attempt peers from {:?}", diff --git a/network/src/network.rs b/network/src/network.rs index cc4e9210a9..d6cce5b71d 100644 --- a/network/src/network.rs +++ b/network/src/network.rs @@ -69,7 +69,7 @@ impl PeerInfo { pub struct Network { peers_registry: RwLock, - peer_store: Arc>>, + peer_store: Arc>, pub(crate) listened_addresses: RwLock>, pub(crate) original_listened_addresses: RwLock>, pub(crate) ckb_protocols: CKBProtocols>, @@ -181,7 +181,7 @@ impl Network { } #[inline] - pub(crate) fn peer_store<'a>(&'a self) -> &'a RwLock> { + pub(crate) fn peer_store(&self) -> &RwLock { &self.peer_store } @@ -475,13 +475,13 @@ impl Network { None => return Err(ErrorKind::Other("secret_key not set".to_owned()).into()), }; let listened_addresses = config.public_addresses.clone(); - let peer_store: Arc>> = { + let peer_store: Arc> = { let mut peer_store = MemoryPeerStore::new(Default::default()); let bootnodes = config.bootnodes()?; for (peer_id, addr) in bootnodes { peer_store.add_bootnode(peer_id, addr); } - Arc::new(RwLock::new(Box::new(peer_store))) + Arc::new(RwLock::new(peer_store)) }; let reserved_peers = config .reserved_peers()? diff --git a/network/src/network_service.rs b/network/src/network_service.rs index 7a688187a3..6e4dec23d5 100644 --- a/network/src/network_service.rs +++ b/network/src/network_service.rs @@ -9,7 +9,6 @@ use ckb_util::RwLock; use futures::future::Future; use futures::sync::oneshot; use log::{debug, info}; -use std::boxed::Box; use std::io::{Error as IoError, ErrorKind as IoErrorKind}; use std::sync::Arc; use std::thread; @@ -35,7 +34,7 @@ impl NetworkService { #[allow(dead_code)] #[inline] - pub(crate) fn peer_store<'a>(&'a self) -> &'a RwLock> { + pub(crate) fn peer_store(&self) -> &RwLock { &self.network.peer_store() } diff --git a/network/src/outbound_peer_service.rs b/network/src/outbound_peer_service.rs index 2b6f9b34b6..8c5b7f0e15 100644 --- a/network/src/outbound_peer_service.rs +++ b/network/src/outbound_peer_service.rs @@ -41,7 +41,6 @@ impl ProtocolService for OutboundPeerService { } // Periodicly connect to new peers - #[allow(clippy::let_and_return)] fn start_protocol( &self, network: Arc, diff --git a/network/src/peer_store.rs b/network/src/peer_store.rs index f6d89c74b8..17c997c46f 100644 --- a/network/src/peer_store.rs +++ b/network/src/peer_store.rs @@ -100,12 +100,13 @@ pub trait PeerStore: Send + Sync { fn peer_score(&self, peer_id: &PeerId) -> Option; fn add_bootnode(&mut self, peer_id: PeerId, addr: Multiaddr); // should return high scored nodes if possible, otherwise, return boostrap nodes - fn bootnodes<'a>(&'a self) -> Box + 'a>; + fn bootnodes<'a>(&'a self) -> Box + 'a>; fn peer_addrs<'a>( &'a self, peer_id: &'a PeerId, - ) -> Option + 'a>>; - fn peers_to_attempt<'a>(&'a self) -> Box + 'a>; + ) -> Option + 'a>>; + fn peers_to_attempt<'a>(&'a self) + -> Box + 'a>; fn ban_peer(&mut self, peer_id: PeerId, timeout: Duration); fn is_banned(&self, peer_id: &PeerId) -> bool; fn scoring_schema(&self) -> &ScoringSchema; diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index 9bf0b66be6..824448b8e3 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -153,7 +153,7 @@ pub struct ConnectionStatus { pub(crate) struct PeersRegistry { // store all known peers - peer_store: Arc>>, + peer_store: Arc>, peers: PeerConnections, // max inbound limitation max_inbound: u32, @@ -194,7 +194,7 @@ where impl PeersRegistry { pub fn new( - peer_store: Arc>>, + peer_store: Arc>, max_inbound: u32, max_outbound: u32, reserved_only: bool, diff --git a/network/src/tests/peers_registry.rs b/network/src/tests/peers_registry.rs index 6f0bfcf022..7ad30b3a5f 100644 --- a/network/src/tests/peers_registry.rs +++ b/network/src/tests/peers_registry.rs @@ -11,9 +11,8 @@ use std::sync::Arc; #[test] fn test_accept_inbound_peer_in_reserve_only_mode() { - let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( - MemoryPeerStore::new(Default::default()), - ))); + let peer_store: Arc> = + Arc::new(RwLock::new(MemoryPeerStore::new(Default::default()))); let reserved_peer = random_peer_id().unwrap(); let addr = "/ip4/127.0.0.1".to_multiaddr().unwrap(); @@ -35,9 +34,8 @@ fn test_accept_inbound_peer_in_reserve_only_mode() { #[test] fn test_accept_inbound_peer_until_full() { - let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( - MemoryPeerStore::new(Default::default()), - ))); + let peer_store: Arc> = + Arc::new(RwLock::new(MemoryPeerStore::new(Default::default()))); let reserved_peer = random_peer_id().unwrap(); let addr = "/ip4/127.0.0.1".to_multiaddr().unwrap(); // accept node until inbound connections is full @@ -76,9 +74,8 @@ fn test_accept_inbound_peer_eviction() { // 1. should evict from largest network groups // 2. should never evict reserved peer // 3. should evict lowest scored peer - let peer_store: Arc>> = Arc::new(RwLock::new(Box::new( - MemoryPeerStore::new(Default::default()), - ))); + let peer_store: Arc> = + Arc::new(RwLock::new(MemoryPeerStore::new(Default::default()))); let reserved_peer = random_peer_id().unwrap(); let evict_target = random_peer_id().unwrap(); let lowest_score_peer = random_peer_id().unwrap(); diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index b51f105411..8d2b641170 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -1034,7 +1034,7 @@ mod tests { peer_id: random_peer_id().unwrap(), endpoint_role: Endpoint::Dialer, last_ping_time: None, - connected_addr: "/ip4/127.0.0.1".to_multiaddr().except("parse multiaddr"), + connected_addr: "/ip4/127.0.0.1".to_multiaddr().expect("parse multiaddr"), identify_info: None, }, protocol_version: None, From 59e6ccc67ff21b5bc5e1e5947a293c0770a6a09a Mon Sep 17 00:00:00 2001 From: Keith Date: Fri, 21 Dec 2018 03:11:08 +0800 Subject: [PATCH 33/45] docs(rpc): fix layout and remove repeated doc --- rpc/doc.md | 50 +++++++++++++++----------------------------------- 1 file changed, 15 insertions(+), 35 deletions(-) diff --git a/rpc/doc.md b/rpc/doc.md index 07c8c58fe1..4718d63782 100644 --- a/rpc/doc.md +++ b/rpc/doc.md @@ -1,6 +1,6 @@ # get_block -Returns information about a block by hash. +Returns the information about a block by hash. ## Parameters @@ -126,11 +126,11 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_transaction","params": ["0xbd # get_block_hash -Returns hash of block in best-block-chain at ; index 0 is the genesis block. +Returns the hash of a block in the best-block-chain by block number; Block of No. 0 is the genesis block. ## Parameters - BlockNumber - number of a block. + BlockNumber - Number of a block. ## Examples @@ -148,7 +148,7 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_block_hash","params": [1]}' - # get_tip_header -Returns the information about the longest block chain tip header. +Returns the information about the tip header of the longest. ## Examples @@ -181,17 +181,15 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_tip_header","params": []}' -H } ``` - - # get_cells_by_type_hash Returns the information about cells collection by type_hash. ## Parameters - type_hash - cell type_hash. - from - start BlockNumber. - to - end BlockNumber. + Type_hash - Cell type_hash. + From - Start BlockNumber. + To - End BlockNumber. ## Examples @@ -251,7 +249,7 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_cells_by_type_hash","params": # get_current_cell -Returns the information about cell by out_point. +Returns the information about a cell by out_point. ## Parameters @@ -281,7 +279,7 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_current_cell","params": [{"ha # get_tip_block_number -Returns the number of blocks in the longest block chain. +Returns the number of blocks in the longest blockchain. ## Examples @@ -299,26 +297,7 @@ curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_tip_block_number","params": [ # local_node_id -Returns local node id. - -## Examples - -```shell -curl -d '{"id": 2, "jsonrpc": "2.0", "method":"local_node_id","params": []}' -H 'content-type:application/json' 'http://localhost:8114' -``` - -```json -{ - "jsonrpc": "2.0", - "result": "/ip4/0.0.0.0/tcp/8115/p2p/QmdSxB6iTcbhj6gbZNthvJrwRkJrwnsohNpVixY4FtcZwv", - "id": 2 -} -``` - - -# local_node_id - -Returns local node id. +Returns the local node id. ## Examples @@ -341,10 +320,11 @@ Creates new transaction. ## Parameters Transaction - The transaction object. - version - transaction version. - deps - dependent cell - inputs - transaction inputs. - outputs - transaction outputs. + + Version - Transaction version. + Deps - Dependent cells. + Inputs - Transaction inputs. + Outputs - Transaction outputs. ## Examples From 09e7cc7c194c4d38657406607ca1cf230f69b7ae Mon Sep 17 00:00:00 2001 From: Xuejie Xiao Date: Fri, 21 Dec 2018 11:41:10 +0800 Subject: [PATCH 34/45] fix: Regulate parameters used in syscalls --- script/src/syscalls/mod.rs | 46 +++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/script/src/syscalls/mod.rs b/script/src/syscalls/mod.rs index 02b4413099..4ea5bfef18 100644 --- a/script/src/syscalls/mod.rs +++ b/script/src/syscalls/mod.rs @@ -39,10 +39,10 @@ impl CellField { match i { 0 => Ok(CellField::Capacity), 1 => Ok(CellField::Data), - 2 => Ok(CellField::LockHash), - 3 => Ok(CellField::Contract), - 4 => Ok(CellField::ContractHash), - 5 => Ok(CellField::DataHash), + 2 => Ok(CellField::DataHash), + 3 => Ok(CellField::LockHash), + 4 => Ok(CellField::Contract), + 5 => Ok(CellField::ContractHash), _ => Err(Error::ParseError), } } @@ -75,9 +75,9 @@ enum Source { impl Source { fn parse_from_u64(i: u64) -> Result { match i { - 0 => Ok(Source::Input), - 1 => Ok(Source::Output), - 2 => Ok(Source::Current), + 0 => Ok(Source::Current), + 1 => Ok(Source::Input), + 2 => Ok(Source::Output), 3 => Ok(Source::Dep), _ => Err(Error::ParseError), } @@ -218,7 +218,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 1; //index - machine.registers_mut()[A4] = 0; //source: 0 input + machine.registers_mut()[A4] = 1; //source: 1 input machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number assert!(machine @@ -258,7 +258,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 0; //source: 0 input + machine.registers_mut()[A4] = 1; //source: 1 input machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number let output = CellOutput::new(100, data.clone(), H256::zero(), None); @@ -307,7 +307,7 @@ mod tests { // test output machine.registers_mut()[A0] = addr; // addr machine.registers_mut()[A1] = size_addr; // size_addr - machine.registers_mut()[A4] = 1; //source: 1 output + machine.registers_mut()[A4] = 2; //source: 2 output assert!(machine .memory_mut() .store64(size_addr as usize, output_correct_data.len() as u64 + 10) @@ -342,7 +342,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 0; //source: 0 input + machine.registers_mut()[A4] = 1; //source: 1 input machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number let output = CellOutput::new(100, data.clone(), H256::zero(), None); @@ -390,7 +390,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = offset as u64; // offset machine.registers_mut()[A3] = 0; // index - machine.registers_mut()[A4] = 0; // source: 0 input + machine.registers_mut()[A4] = 1; // source: 1 input machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number let output = CellOutput::new(100, data.clone(), H256::zero(), None); @@ -444,7 +444,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 1000; //index - machine.registers_mut()[A4] = 2; //source: 2 self + machine.registers_mut()[A4] = 0; //source: 0 current machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number let input_cell = CellOutput::new( @@ -498,7 +498,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 0; //source: 0 input + machine.registers_mut()[A4] = 1; //source: 1 input machine.registers_mut()[A5] = 0; //field: 0 capacity machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number @@ -539,8 +539,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 2; //source: 2 self - machine.registers_mut()[A5] = 2; //field: 2 lock hash + machine.registers_mut()[A4] = 0; //source: 0 current + machine.registers_mut()[A5] = 3; //field: 3 lock hash machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number let sha3_data = sha3_256(data); @@ -593,8 +593,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 1; //source: 1 output - machine.registers_mut()[A5] = 3; //field: 3 contract + machine.registers_mut()[A4] = 2; //source: 2 output + machine.registers_mut()[A5] = 4; //field: 4 contract machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number let output_cell = CellOutput::new(100, vec![], H256::default(), None); @@ -627,7 +627,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 0; //source: 0 input + machine.registers_mut()[A4] = 1; //source: 1 input machine.registers_mut()[A5] = 0; //field: 0 unlock machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number @@ -675,7 +675,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 1; //source: 1 output + machine.registers_mut()[A4] = 2; //source: 2 output machine.registers_mut()[A5] = 0; //field: 0 unlock machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number @@ -723,7 +723,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 2; //source: 2 self + machine.registers_mut()[A4] = 0; //source: 0 current machine.registers_mut()[A5] = 1; //field: 1 out_point machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number @@ -775,7 +775,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 2; //source: 2 self + machine.registers_mut()[A4] = 0; //source: 0 current machine.registers_mut()[A5] = 1; //field: 1 out_point machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number @@ -849,7 +849,7 @@ mod tests { machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index machine.registers_mut()[A4] = 3; //source: 3 dep - machine.registers_mut()[A5] = 5; //field: 5 data hash + machine.registers_mut()[A5] = 2; //field: 2 data hash machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number let input_cell = CellOutput::new(1000, vec![], H256::zero(), None); From 3af95355ed9a4723376c940879d2857887063b2d Mon Sep 17 00:00:00 2001 From: Xuejie Xiao Date: Fri, 21 Dec 2018 14:44:55 +0800 Subject: [PATCH 35/45] fix: assign numeric numbers for syscall parameters --- script/src/syscalls/mod.rs | 72 +++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 36 deletions(-) diff --git a/script/src/syscalls/mod.rs b/script/src/syscalls/mod.rs index 4ea5bfef18..bbf1f77b55 100644 --- a/script/src/syscalls/mod.rs +++ b/script/src/syscalls/mod.rs @@ -26,12 +26,12 @@ pub const DEBUG_PRINT_SYSCALL_NUMBER: u64 = 2177; #[derive(Debug, PartialEq, Clone, Copy, Eq)] enum CellField { - Capacity, - Data, - DataHash, - LockHash, - Contract, - ContractHash, + Capacity = 0, + Data = 1, + DataHash = 2, + LockHash = 3, + Contract = 4, + ContractHash = 5, } impl CellField { @@ -50,8 +50,8 @@ impl CellField { #[derive(Debug, PartialEq, Clone, Copy, Eq)] enum InputField { - Unlock, - OutPoint, + Unlock = 0, + OutPoint = 1, } impl InputField { @@ -66,10 +66,10 @@ impl InputField { #[derive(Debug, PartialEq, Clone, Copy, Eq)] enum Source { - Input, - Output, - Current, - Dep, + Current = 0, + Input = 1, + Output = 2, + Dep = 3, } impl Source { @@ -218,7 +218,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 1; //index - machine.registers_mut()[A4] = 1; //source: 1 input + machine.registers_mut()[A4] = Source::Input as u64; //source: 1 input machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number assert!(machine @@ -258,7 +258,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 1; //source: 1 input + machine.registers_mut()[A4] = Source::Input as u64; //source: 1 input machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number let output = CellOutput::new(100, data.clone(), H256::zero(), None); @@ -307,7 +307,7 @@ mod tests { // test output machine.registers_mut()[A0] = addr; // addr machine.registers_mut()[A1] = size_addr; // size_addr - machine.registers_mut()[A4] = 2; //source: 2 output + machine.registers_mut()[A4] = Source::Output as u64; //source: 2 output assert!(machine .memory_mut() .store64(size_addr as usize, output_correct_data.len() as u64 + 10) @@ -342,7 +342,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 1; //source: 1 input + machine.registers_mut()[A4] = Source::Input as u64; //source: 1 input machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number let output = CellOutput::new(100, data.clone(), H256::zero(), None); @@ -390,7 +390,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = offset as u64; // offset machine.registers_mut()[A3] = 0; // index - machine.registers_mut()[A4] = 1; // source: 1 input + machine.registers_mut()[A4] = Source::Input as u64; // source: 1 input machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number let output = CellOutput::new(100, data.clone(), H256::zero(), None); @@ -444,7 +444,7 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 1000; //index - machine.registers_mut()[A4] = 0; //source: 0 current + machine.registers_mut()[A4] = Source::Current as u64; //source: 0 current machine.registers_mut()[A7] = LOAD_CELL_SYSCALL_NUMBER; // syscall number let input_cell = CellOutput::new( @@ -498,8 +498,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 1; //source: 1 input - machine.registers_mut()[A5] = 0; //field: 0 capacity + machine.registers_mut()[A4] = Source::Input as u64; //source: 1 input + machine.registers_mut()[A5] = CellField::Capacity as u64; //field: 0 capacity machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number let input_cell = CellOutput::new(capacity, vec![], H256::zero(), None); @@ -539,8 +539,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 0; //source: 0 current - machine.registers_mut()[A5] = 3; //field: 3 lock hash + machine.registers_mut()[A4] = Source::Current as u64; //source: 0 current + machine.registers_mut()[A5] = CellField::LockHash as u64; //field: 3 lock hash machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number let sha3_data = sha3_256(data); @@ -593,8 +593,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 2; //source: 2 output - machine.registers_mut()[A5] = 4; //field: 4 contract + machine.registers_mut()[A4] = Source::Output as u64; //source: 2 output + machine.registers_mut()[A5] = CellField::Contract as u64; //field: 4 contract machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number let output_cell = CellOutput::new(100, vec![], H256::default(), None); @@ -627,8 +627,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 1; //source: 1 input - machine.registers_mut()[A5] = 0; //field: 0 unlock + machine.registers_mut()[A4] = Source::Input as u64; //source: 1 input + machine.registers_mut()[A5] = InputField::Unlock as u64; //field: 0 unlock machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number let unlock = Script::new(0, vec![], None, Some(data), vec![]); @@ -675,8 +675,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 2; //source: 2 output - machine.registers_mut()[A5] = 0; //field: 0 unlock + machine.registers_mut()[A4] = Source::Output as u64; //source: 2 output + machine.registers_mut()[A5] = InputField::Unlock as u64; //field: 0 unlock machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number let unlock = Script::new(0, vec![], None, Some(data), vec![]); @@ -723,8 +723,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 0; //source: 0 current - machine.registers_mut()[A5] = 1; //field: 1 out_point + machine.registers_mut()[A4] = Source::Current as u64; //source: 0 current + machine.registers_mut()[A5] = InputField::OutPoint as u64; //field: 1 out_point machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number let unlock = Script::new(0, vec![], None, Some(vec![]), vec![]); @@ -775,8 +775,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 0; //source: 0 current - machine.registers_mut()[A5] = 1; //field: 1 out_point + machine.registers_mut()[A4] = Source::Current as u64; //source: 0 current + machine.registers_mut()[A5] = InputField::OutPoint as u64; //field: 1 out_point machine.registers_mut()[A7] = LOAD_INPUT_BY_FIELD_SYSCALL_NUMBER; // syscall number let inputs = vec![]; @@ -803,8 +803,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 3; //source: 3 dep - machine.registers_mut()[A5] = 1; //field: 1 data + machine.registers_mut()[A4] = Source::Dep as u64; //source: 3 dep + machine.registers_mut()[A5] = CellField::Data as u64; //field: 1 data machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number let input_cell = CellOutput::new(1000, vec![], H256::zero(), None); @@ -848,8 +848,8 @@ mod tests { machine.registers_mut()[A1] = size_addr; // size_addr machine.registers_mut()[A2] = 0; // offset machine.registers_mut()[A3] = 0; //index - machine.registers_mut()[A4] = 3; //source: 3 dep - machine.registers_mut()[A5] = 2; //field: 2 data hash + machine.registers_mut()[A4] = Source::Dep as u64; //source: 3 dep + machine.registers_mut()[A5] = CellField::DataHash as u64; //field: 2 data hash machine.registers_mut()[A7] = LOAD_CELL_BY_FIELD_SYSCALL_NUMBER; // syscall number let input_cell = CellOutput::new(1000, vec![], H256::zero(), None); From bdf323f5e3d739646ce487e517bb3c1e4ed8c357 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Fri, 21 Dec 2018 15:29:51 +0800 Subject: [PATCH 36/45] fix: cli subcommand setting --- src/cli/args.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cli/args.rs b/src/cli/args.rs index de8abbf94c..65382b9f4e 100644 --- a/src/cli/args.rs +++ b/src/cli/args.rs @@ -88,7 +88,7 @@ fn arg_private_key() -> Arg<'static, 'static> { fn cli() -> App<'static, 'static> { SubCommand::with_name("cli") .about("Running ckb cli") - .setting(AppSettings::ArgRequiredElseHelp) + .setting(AppSettings::SubcommandRequiredElseHelp) .subcommand( SubCommand::with_name("sign") .about("Sign transaction using sha3-secp256k1 defined in system cell") From f87d9a195eca886bf6da0599f51d9dfd8e40a38e Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Fri, 21 Dec 2018 20:33:35 +0800 Subject: [PATCH 37/45] feat: jsonrpc API modules 1. jsonrpc API modules 2. fork original jsonrpc-macros, make change to support 2018-edition trait syntax 3. listen_addr -> listen_address 4. now, if `pow_engine is Clicker, jsonrpc load test module automatically, without conditional compilation. --- Cargo.lock | 7 +- Cargo.toml | 3 - Makefile | 9 +- nodes_template/default.json | 10 +- rpc/Cargo.toml | 9 +- rpc/src/config.rs | 31 ++++ rpc/src/integration_test.rs | 101 ------------- rpc/src/lib.rs | 39 +---- rpc/src/module/chain.rs | 106 +++++++++++++ rpc/src/module/miner.rs | 66 ++++++++ rpc/src/module/mod.rs | 11 ++ rpc/src/module/net.rs | 22 +++ rpc/src/module/pool.rs | 44 ++++++ rpc/src/module/test.rs | 32 ++++ rpc/src/server.rs | 294 ++++++++---------------------------- rpc/src/types.rs | 6 +- src/cli/run_impl.rs | 36 +---- 17 files changed, 409 insertions(+), 417 deletions(-) create mode 100644 rpc/src/config.rs delete mode 100644 rpc/src/integration_test.rs create mode 100644 rpc/src/module/chain.rs create mode 100644 rpc/src/module/miner.rs create mode 100644 rpc/src/module/mod.rs create mode 100644 rpc/src/module/net.rs create mode 100644 rpc/src/module/pool.rs create mode 100644 rpc/src/module/test.rs diff --git a/Cargo.lock b/Cargo.lock index 400d81252f..edb6a77636 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -537,9 +537,10 @@ dependencies = [ "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "jsonrpc-macros 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", + "jsonrpc-macros 9.0.0 (git+https://github.com/nervosnetwork/jsonrpc.git?branch=2018-edition)", "jsonrpc-server-utils 9.0.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.9.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1325,7 +1326,7 @@ dependencies = [ [[package]] name = "jsonrpc-macros" version = "9.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" +source = "git+https://github.com/nervosnetwork/jsonrpc.git?branch=2018-edition#e1a57c96219d72c1ba4e6a81d5b40981f728c0e1" dependencies = [ "jsonrpc-core 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-pubsub 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3529,7 +3530,7 @@ dependencies = [ "checksum jsonrpc 0.10.2 (git+https://github.com/quake/rust-jsonrpc)" = "" "checksum jsonrpc-core 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4e9cbeda300803d381390fb65e8158437728c39e6987ed23bee82728b73511a7" "checksum jsonrpc-http-server 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "385c2da14e89d4eae5fc48f75f4f1c260546356cfc29dd2d0e3a7a4f7684240e" -"checksum jsonrpc-macros 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8c9d25aa2af560453ffa9194e83bfc84b71dc9b1a1df6d2d2ba2a5167ce08077" +"checksum jsonrpc-macros 9.0.0 (git+https://github.com/nervosnetwork/jsonrpc.git?branch=2018-edition)" = "" "checksum jsonrpc-pubsub 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "37f809dddaf749229508c97efc8dcd7f3375a883ecbaedd6a9563eaff8b0e6d9" "checksum jsonrpc-server-utils 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "af60edf0926da92ddc453f55fcd02f461ea6efaa1d7ceb7334424ff261e379a7" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" diff --git a/Cargo.toml b/Cargo.toml index 9bb4d0f1ed..a5ef3831a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -38,9 +38,6 @@ hash = { path = "util/hash"} faster-hex = "0.1" build-info = { path = "util/build-info" } -[features] -integration_test = ["ckb-rpc/integration_test"] - [dev-dependencies] tempfile = "3.0" diff --git a/Makefile b/Makefile index 46dceb868a..79057c2148 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,6 @@ test: cargo test --all -- --nocapture -build-integration-test: - cargo build --all --features integration_test --no-default-features - doc: cargo doc --all --no-deps @@ -22,10 +19,10 @@ fmt: clippy: cargo clippy --all -- -D warnings -D clippy::clone_on_ref_ptr -D clippy::enum_glob_use -ci: fmt clippy test build-integration-test +ci: fmt clippy test git diff --exit-code Cargo.lock -ci-quick: test build-integration-test +ci-quick: test git diff --exit-code Cargo.lock info: @@ -47,6 +44,6 @@ security-audit: docker: build docker build -f docker/hub/Dockerfile -t nervos/ckb:latest . -.PHONY: build build-integration-test docker +.PHONY: build docker .PHONY: fmt test clippy proto doc doc-deps check stats .PHONY: ci ci-quick info security-audit diff --git a/nodes_template/default.json b/nodes_template/default.json index b1e6527d10..3c44416750 100644 --- a/nodes_template/default.json +++ b/nodes_template/default.json @@ -1,4 +1,11 @@ { + "__comments__": { + "rpc modules": [ + "List of API modules", + ["Net", "Pool", "Miner", "Chain"] + ] + }, + "data_dir": "default", "ckb": { "chain": "spec/dev.json" @@ -19,7 +26,8 @@ "nodes_file": "nodes.json" }, "rpc": { - "listen_addr": "0.0.0.0:8114" + "listen_address": "0.0.0.0:8114", + "modules": ["Net", "Pool", "Miner", "Chain"] }, "sync": { "verification_level": "Full", diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index e961a12b85..d183cfe8e3 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -3,6 +3,7 @@ name = "ckb-rpc" version = "0.3.0-pre" license = "MIT" authors = ["Nervos Core Dev "] +edition = "2018" [dependencies] numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } @@ -15,9 +16,9 @@ ckb-pool = { path = "../pool" } ckb-chain = { path = "../chain" } ckb-miner = { path = "../miner" } ckb-protocol = { path = "../protocol" } -ckb-pow = { path = "../pow", optional = true } +ckb-pow = { path = "../pow"} jsonrpc-core = "9.0" -jsonrpc-macros = "9.0" +jsonrpc-macros = { git = "https://github.com/nervosnetwork/jsonrpc.git", branch = "2018-edition" } jsonrpc-http-server = "9.0" jsonrpc-server-utils = "9.0" serde = "1.0" @@ -25,10 +26,8 @@ serde_derive = "1.0" serde_json = "1.0" log = "0.4" flatbuffers = "0.5.0" +num_cpus = "1.0" [dev-dependencies] ckb-db = { path = "../db" } ckb-verification = { path = "../verification" } - -[features] -integration_test = ["ckb-pow"] diff --git a/rpc/src/config.rs b/rpc/src/config.rs new file mode 100644 index 0000000000..a9503ddea4 --- /dev/null +++ b/rpc/src/config.rs @@ -0,0 +1,31 @@ +use serde_derive::Deserialize; + +const NET: &str = "Net"; +const CHAIN: &str = "Chain"; +const MINER: &str = "Miner"; +const POOL: &str = "Pool"; + +#[derive(Clone, Debug, PartialEq, Deserialize)] +pub struct Config { + pub listen_address: String, + pub threads: Option, + pub modules: Vec, +} + +impl Config { + pub(crate) fn net_enable(&self) -> bool { + self.modules.iter().any(|m| m == NET) + } + + pub(crate) fn chain_enable(&self) -> bool { + self.modules.iter().any(|m| m == CHAIN) + } + + pub(crate) fn miner_enable(&self) -> bool { + self.modules.iter().any(|m| m == MINER) + } + + pub(crate) fn pool_enable(&self) -> bool { + self.modules.iter().any(|m| m == POOL) + } +} diff --git a/rpc/src/integration_test.rs b/rpc/src/integration_test.rs deleted file mode 100644 index 746be47ea3..0000000000 --- a/rpc/src/integration_test.rs +++ /dev/null @@ -1,101 +0,0 @@ -use ckb_chain::chain::ChainController; -use ckb_miner::AgentController; -use ckb_network::NetworkService; -use ckb_pool::txs_pool::TransactionPoolController; -use ckb_pow::Clicker; -use ckb_shared::index::ChainIndex; -use ckb_shared::shared::Shared; -use jsonrpc_core::{IoHandler, Result}; -use jsonrpc_http_server::ServerBuilder; -use jsonrpc_server_utils::cors::AccessControlAllowOrigin; -use jsonrpc_server_utils::hosts::DomainsValidation; -use server::{ChainRpc, ChainRpcImpl, MinerRpc, MinerRpcImpl, PoolRpc, PoolRpcImpl}; -use std::sync::Arc; -use types::Config; - -build_rpc_trait! { - pub trait IntegrationTestRpc { - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"submit_solution","params": [1]}' -H 'content-type:application/json' 'http://localhost:8114' - #[rpc(name = "submit_pow_solution")] - fn submit_pow_solution(&self, u64) -> Result<()>; - - #[rpc(name = "add_node")] - fn add_node(&self, String) -> Result<()>; - } -} - -struct IntegrationTestRpcImpl { - pub network: Arc, - pub pow: Arc, -} - -impl IntegrationTestRpc for IntegrationTestRpcImpl { - fn submit_pow_solution(&self, nonce: u64) -> Result<()> { - self.pow.submit(nonce); - Ok(()) - } - - fn add_node(&self, _node_id: String) -> Result<()> { - unimplemented!() - } -} - -pub struct RpcServer { - pub config: Config, -} - -impl RpcServer { - pub fn start( - &self, - network: Arc, - shared: Shared, - tx_pool: TransactionPoolController, - pow: Arc, - chain: ChainController, - agent: AgentController, - ) where - CI: ChainIndex + 'static, - { - let mut io = IoHandler::new(); - io.extend_with( - IntegrationTestRpcImpl { - network: Arc::clone(&network), - pow, - } - .to_delegate(), - ); - io.extend_with( - ChainRpcImpl { - shared: shared.clone(), - } - .to_delegate(), - ); - io.extend_with( - PoolRpcImpl { - network: Arc::clone(&network), - tx_pool, - } - .to_delegate(), - ); - io.extend_with( - MinerRpcImpl { - network, - shared, - agent, - chain, - } - .to_delegate(), - ); - - let server = ServerBuilder::new(io) - .cors(DomainsValidation::AllowOnly(vec![ - AccessControlAllowOrigin::Null, - AccessControlAllowOrigin::Any, - ])) - .start_http(&self.config.listen_addr.parse().unwrap()) - .unwrap(); - - info!(target: "rpc", "Now listening on {:?}", server.address()); - server.wait(); - } -} diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index 44dc98534d..953060665d 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -1,38 +1,7 @@ -extern crate flatbuffers; -extern crate jsonrpc_core; -extern crate numext_fixed_hash; -#[macro_use] -extern crate jsonrpc_macros; -extern crate jsonrpc_http_server; -extern crate jsonrpc_server_utils; -#[macro_use] -extern crate log; -extern crate ckb_chain; -extern crate ckb_core; -#[cfg(test)] -extern crate ckb_db; -extern crate ckb_miner; -extern crate ckb_network; -extern crate ckb_pool; -extern crate ckb_protocol; -extern crate ckb_shared; -extern crate ckb_sync; -#[cfg(test)] -extern crate ckb_verification; -#[macro_use] -extern crate serde_derive; -#[cfg(feature = "integration_test")] -extern crate ckb_pow; - +mod config; +mod module; mod server; mod types; -pub use types::Config; - -#[cfg(feature = "integration_test")] -mod integration_test; - -#[cfg(feature = "integration_test")] -pub use integration_test::RpcServer; -#[cfg(not(feature = "integration_test"))] -pub use server::RpcServer; +pub use crate::config::Config; +pub use crate::server::RpcServer; diff --git a/rpc/src/module/chain.rs b/rpc/src/module/chain.rs new file mode 100644 index 0000000000..33c7696408 --- /dev/null +++ b/rpc/src/module/chain.rs @@ -0,0 +1,106 @@ +use crate::types::{BlockWithHash, CellOutputWithOutPoint, CellWithStatus, TransactionWithHash}; +use ckb_core::cell::CellProvider; +use ckb_core::header::{BlockNumber, Header}; +use ckb_core::transaction::OutPoint; +use ckb_shared::{ + index::ChainIndex, + shared::{ChainProvider, Shared}, +}; +use jsonrpc_core::{Error, Result}; +use jsonrpc_macros::build_rpc_trait; +use numext_fixed_hash::H256; + +build_rpc_trait! { + pub trait ChainRpc { + #[rpc(name = "get_block")] + fn get_block(&self, _hash: H256) -> Result>; + + #[rpc(name = "get_transaction")] + fn get_transaction(&self, _hash: H256) -> Result>; + + #[rpc(name = "get_block_hash")] + fn get_block_hash(&self, _number: u64) -> Result>; + + #[rpc(name = "get_tip_header")] + fn get_tip_header(&self) -> Result
; + + #[rpc(name = "get_cells_by_type_hash")] + fn get_cells_by_type_hash( + &self, + _type_hash: H256, + _from: BlockNumber, + _to: BlockNumber + ) -> Result>; + + #[rpc(name = "get_current_cell")] + fn get_current_cell(&self, _out_point: OutPoint) -> Result; + + #[rpc(name = "get_tip_block_number")] + fn get_tip_block_number(&self) -> Result; + } +} + +pub(crate) struct ChainRpcImpl { + pub shared: Shared, +} + +impl ChainRpc for ChainRpcImpl { + fn get_block(&self, hash: H256) -> Result> { + Ok(self.shared.block(&hash).map(Into::into)) + } + + fn get_transaction(&self, hash: H256) -> Result> { + Ok(self.shared.get_transaction(&hash).map(Into::into)) + } + + fn get_block_hash(&self, number: BlockNumber) -> Result> { + Ok(self.shared.block_hash(number)) + } + + fn get_tip_header(&self) -> Result
{ + Ok(self.shared.tip_header().read().inner().clone()) + } + + // TODO: we need to build a proper index instead of scanning every time + fn get_cells_by_type_hash( + &self, + type_hash: H256, + from: BlockNumber, + to: BlockNumber, + ) -> Result> { + let mut result = Vec::new(); + for block_number in from..=to { + if let Some(block_hash) = self.shared.block_hash(block_number) { + let block = self + .shared + .block(&block_hash) + .ok_or_else(Error::internal_error)?; + let tip_header = self.shared.tip_header().read(); + for transaction in block.commit_transactions() { + let transaction_meta = self + .shared + .get_transaction_meta(&tip_header.output_root(), &transaction.hash()) + .ok_or_else(Error::internal_error)?; + for (i, output) in transaction.outputs().iter().enumerate() { + if output.lock == type_hash && (!transaction_meta.is_spent(i)) { + result.push(CellOutputWithOutPoint { + out_point: OutPoint::new(transaction.hash().clone(), i as u32), + capacity: output.capacity, + lock: output.lock.clone(), + }); + } + } + } + } + } + Ok(result) + } + + fn get_current_cell(&self, out_point: OutPoint) -> Result { + Ok(self.shared.cell(&out_point).into()) + } + + fn get_tip_block_number(&self) -> Result { + Ok(self.shared.tip_header().read().number()) + } +} diff --git a/rpc/src/module/miner.rs b/rpc/src/module/miner.rs new file mode 100644 index 0000000000..5c3c32c7c2 --- /dev/null +++ b/rpc/src/module/miner.rs @@ -0,0 +1,66 @@ +use ckb_chain::chain::ChainController; +use ckb_core::block::Block; +use ckb_miner::{AgentController, BlockTemplate}; +use ckb_network::NetworkService; +use ckb_protocol::RelayMessage; +use ckb_shared::{index::ChainIndex, shared::Shared}; +use ckb_sync::RELAY_PROTOCOL_ID; +use flatbuffers::FlatBufferBuilder; +use jsonrpc_core::{Error, Result}; +use jsonrpc_macros::build_rpc_trait; +use log::debug; +use numext_fixed_hash::H256; +use std::collections::HashSet; +use std::sync::Arc; + +build_rpc_trait! { + pub trait MinerRpc { + // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_block_template","params": ["0x1b1c832d02fdb4339f9868c8a8636c3d9dd10bd53ac7ce99595825bd6beeffb3", 1000, 1000]}' -H 'content-type:application/json' 'http://localhost:8114' + #[rpc(name = "get_block_template")] + fn get_block_template(&self, _type_hash: H256, _max_txs: usize, _max_proposals: usize) -> Result; + + // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"submit_block","params": [{"header":{}, "uncles":[], "commit_transactions":[], "proposal_transactions":[]}]}' -H 'content-type:application/json' 'http://localhost:8114' + #[rpc(name = "submit_block")] + fn submit_block(&self, _block: Block) -> Result; + } +} + +pub(crate) struct MinerRpcImpl { + pub network: Arc, + pub shared: Shared, + pub agent: AgentController, + pub chain: ChainController, +} + +impl MinerRpc for MinerRpcImpl { + fn get_block_template( + &self, + type_hash: H256, + max_transactions: usize, + max_proposals: usize, + ) -> Result { + self.agent + .get_block_template(type_hash, max_transactions, max_proposals) + .map_err(|_| Error::internal_error()) + } + + fn submit_block(&self, block: Block) -> Result { + let block = Arc::new(block); + let ret = self.chain.process_block(Arc::clone(&block)); + if ret.is_ok() { + // announce new block + self.network.with_protocol_context(RELAY_PROTOCOL_ID, |nc| { + let fbb = &mut FlatBufferBuilder::new(); + let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); + fbb.finish(message, None); + for peer in nc.connected_peers() { + let _ = nc.send(peer, fbb.finished_data().to_vec()); + } + }); + Ok(block.header().hash().clone()) + } else { + debug!(target: "rpc", "submit_block process_block {:?}", ret); + Err(Error::internal_error()) + } + } +} diff --git a/rpc/src/module/mod.rs b/rpc/src/module/mod.rs new file mode 100644 index 0000000000..d66649fa0b --- /dev/null +++ b/rpc/src/module/mod.rs @@ -0,0 +1,11 @@ +mod chain; +mod miner; +mod net; +mod pool; +mod test; + +pub(crate) use self::chain::{ChainRpc, ChainRpcImpl}; +pub(crate) use self::miner::{MinerRpc, MinerRpcImpl}; +pub(crate) use self::net::{NetworkRpc, NetworkRpcImpl}; +pub(crate) use self::pool::{PoolRpc, PoolRpcImpl}; +pub(crate) use self::test::{IntegrationTestRpc, IntegrationTestRpcImpl}; diff --git a/rpc/src/module/net.rs b/rpc/src/module/net.rs new file mode 100644 index 0000000000..c9c147ad27 --- /dev/null +++ b/rpc/src/module/net.rs @@ -0,0 +1,22 @@ +use ckb_network::NetworkService; +use jsonrpc_core::Result; +use jsonrpc_macros::build_rpc_trait; +use std::sync::Arc; + +build_rpc_trait! { + pub trait NetworkRpc { + // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"send_transaction","params": [{"version":2, "deps":[], "inputs":[], "outputs":[]}]}' -H 'content-type:application/json' 'http://localhost:8114' + #[rpc(name = "local_node_id")] + fn local_node_id(&self) -> Result>; + } +} + +pub(crate) struct NetworkRpcImpl { + pub network: Arc, +} + +impl NetworkRpc for NetworkRpcImpl { + fn local_node_id(&self) -> Result> { + Ok(self.network.external_url()) + } +} diff --git a/rpc/src/module/pool.rs b/rpc/src/module/pool.rs new file mode 100644 index 0000000000..473ffd80f6 --- /dev/null +++ b/rpc/src/module/pool.rs @@ -0,0 +1,44 @@ +use ckb_core::transaction::Transaction; +use ckb_network::NetworkService; +use ckb_pool::txs_pool::TransactionPoolController; +use ckb_protocol::RelayMessage; +use ckb_sync::RELAY_PROTOCOL_ID; +use flatbuffers::FlatBufferBuilder; +use jsonrpc_core::Result; +use jsonrpc_macros::build_rpc_trait; +use log::debug; +use numext_fixed_hash::H256; +use std::sync::Arc; + +build_rpc_trait! { + pub trait PoolRpc { + // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"send_transaction","params": [{"version":2, "deps":[], "inputs":[], "outputs":[]}]}' -H 'content-type:application/json' 'http://localhost:8114' + #[rpc(name = "send_transaction")] + fn send_transaction(&self, _tx: Transaction) -> Result; + } +} + +pub(crate) struct PoolRpcImpl { + pub network: Arc, + pub tx_pool: TransactionPoolController, +} + +impl PoolRpc for PoolRpcImpl { + fn send_transaction(&self, tx: Transaction) -> Result { + let tx_hash = tx.hash().clone(); + let pool_result = self.tx_pool.add_transaction(tx.clone()); + debug!(target: "rpc", "send_transaction add to pool result: {:?}", pool_result); + + let fbb = &mut FlatBufferBuilder::new(); + let message = RelayMessage::build_transaction(fbb, &tx); + fbb.finish(message, None); + + self.network.with_protocol_context(RELAY_PROTOCOL_ID, |nc| { + for peer in nc.connected_peers() { + debug!(target: "rpc", "relay transaction {} to peer#{}", tx_hash, peer); + let _ = nc.send(peer, fbb.finished_data().to_vec()); + } + }); + Ok(tx_hash) + } +} diff --git a/rpc/src/module/test.rs b/rpc/src/module/test.rs new file mode 100644 index 0000000000..9604e2c6ef --- /dev/null +++ b/rpc/src/module/test.rs @@ -0,0 +1,32 @@ +use ckb_network::NetworkService; +use ckb_pow::Clicker; +use jsonrpc_core::Result; +use jsonrpc_macros::build_rpc_trait; +use std::sync::Arc; + +build_rpc_trait! { + pub trait IntegrationTestRpc { + // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"submit_solution","params": [1]}' -H 'content-type:application/json' 'http://localhost:8114' + #[rpc(name = "submit_pow_solution")] + fn submit_pow_solution(&self, _nonce: u64) -> Result<()>; + + #[rpc(name = "add_node")] + fn add_node(&self, _node_id: String) -> Result<()>; + } +} + +pub(crate) struct IntegrationTestRpcImpl { + pub network: Arc, + pub test_engine: Arc, +} + +impl IntegrationTestRpc for IntegrationTestRpcImpl { + fn submit_pow_solution(&self, nonce: u64) -> Result<()> { + self.test_engine.submit(nonce); + Ok(()) + } + + fn add_node(&self, _node_id: String) -> Result<()> { + unimplemented!() + } +} diff --git a/rpc/src/server.rs b/rpc/src/server.rs index 8c21121f4a..6783e32aa9 100644 --- a/rpc/src/server.rs +++ b/rpc/src/server.rs @@ -1,217 +1,22 @@ +use crate::config::Config; +use crate::module::{ + ChainRpc, ChainRpcImpl, IntegrationTestRpc, IntegrationTestRpcImpl, MinerRpc, MinerRpcImpl, + NetworkRpc, NetworkRpcImpl, PoolRpc, PoolRpcImpl, +}; use ckb_chain::chain::ChainController; -use ckb_core::block::Block; -use ckb_core::cell::CellProvider; -use ckb_core::header::{BlockNumber, Header}; -use ckb_core::transaction::{OutPoint, Transaction}; -use ckb_miner::{AgentController, BlockTemplate}; + +use ckb_miner::AgentController; use ckb_network::NetworkService; use ckb_pool::txs_pool::TransactionPoolController; -use ckb_protocol::RelayMessage; +use ckb_pow::Clicker; use ckb_shared::index::ChainIndex; -use ckb_shared::shared::{ChainProvider, Shared}; -use ckb_sync::RELAY_PROTOCOL_ID; -use flatbuffers::FlatBufferBuilder; -use jsonrpc_core::{Error, IoHandler, Result}; +use ckb_shared::shared::Shared; +use jsonrpc_core::IoHandler; use jsonrpc_http_server::ServerBuilder; use jsonrpc_server_utils::cors::AccessControlAllowOrigin; use jsonrpc_server_utils::hosts::DomainsValidation; -use numext_fixed_hash::H256; -use std::collections::HashSet; +use log::info; use std::sync::Arc; -use types::{BlockWithHash, CellOutputWithOutPoint, CellWithStatus, Config, TransactionWithHash}; - -build_rpc_trait! { - pub trait ChainRpc { - #[rpc(name = "get_block")] - fn get_block(&self, H256) -> Result>; - - #[rpc(name = "get_transaction")] - fn get_transaction(&self, H256) -> Result>; - - #[rpc(name = "get_block_hash")] - fn get_block_hash(&self, u64) -> Result>; - - #[rpc(name = "get_tip_header")] - fn get_tip_header(&self) -> Result
; - - #[rpc(name = "get_cells_by_type_hash")] - fn get_cells_by_type_hash(&self, H256, BlockNumber, BlockNumber) -> Result>; - - #[rpc(name = "get_current_cell")] - fn get_current_cell(&self, OutPoint) -> Result; - - #[rpc(name = "get_tip_block_number")] - fn get_tip_block_number(&self) -> Result; - } -} - -pub struct ChainRpcImpl { - pub shared: Shared, -} - -impl ChainRpc for ChainRpcImpl { - fn get_block(&self, hash: H256) -> Result> { - Ok(self.shared.block(&hash).map(Into::into)) - } - - fn get_transaction(&self, hash: H256) -> Result> { - Ok(self.shared.get_transaction(&hash).map(Into::into)) - } - - fn get_block_hash(&self, number: BlockNumber) -> Result> { - Ok(self.shared.block_hash(number)) - } - - fn get_tip_header(&self) -> Result
{ - Ok(self.shared.tip_header().read().inner().clone()) - } - - // TODO: we need to build a proper index instead of scanning every time - fn get_cells_by_type_hash( - &self, - type_hash: H256, - from: BlockNumber, - to: BlockNumber, - ) -> Result> { - let mut result = Vec::new(); - for block_number in from..=to { - if let Some(block_hash) = self.shared.block_hash(block_number) { - let block = self - .shared - .block(&block_hash) - .ok_or_else(Error::internal_error)?; - let tip_header = self.shared.tip_header().read(); - for transaction in block.commit_transactions() { - let transaction_meta = self - .shared - .get_transaction_meta(&tip_header.output_root(), &transaction.hash()) - .ok_or_else(Error::internal_error)?; - for (i, output) in transaction.outputs().iter().enumerate() { - if output.lock == type_hash && (!transaction_meta.is_spent(i)) { - result.push(CellOutputWithOutPoint { - out_point: OutPoint::new(transaction.hash().clone(), i as u32), - capacity: output.capacity, - lock: output.lock.clone(), - }); - } - } - } - } - } - Ok(result) - } - - fn get_current_cell(&self, out_point: OutPoint) -> Result { - Ok(self.shared.cell(&out_point).into()) - } - - fn get_tip_block_number(&self) -> Result { - Ok(self.shared.tip_header().read().number()) - } -} - -build_rpc_trait! { - pub trait PoolRpc { - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"send_transaction","params": [{"version":2, "deps":[], "inputs":[], "outputs":[]}]}' -H 'content-type:application/json' 'http://localhost:8114' - #[rpc(name = "send_transaction")] - fn send_transaction(&self, Transaction) -> Result; - } -} - -pub struct PoolRpcImpl { - pub network: Arc, - pub tx_pool: TransactionPoolController, -} - -impl PoolRpc for PoolRpcImpl { - fn send_transaction(&self, tx: Transaction) -> Result { - let tx_hash = tx.hash().clone(); - let pool_result = self.tx_pool.add_transaction(tx.clone()); - debug!(target: "rpc", "send_transaction add to pool result: {:?}", pool_result); - - let fbb = &mut FlatBufferBuilder::new(); - let message = RelayMessage::build_transaction(fbb, &tx); - fbb.finish(message, None); - - self.network.with_protocol_context(RELAY_PROTOCOL_ID, |nc| { - for peer in nc.connected_peers() { - debug!(target: "rpc", "relay transaction {} to peer#{}", tx_hash, peer); - let _ = nc.send(peer, fbb.finished_data().to_vec()); - } - }); - Ok(tx_hash) - } -} - -build_rpc_trait! { - pub trait MinerRpc { - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"get_block_template","params": ["0x1b1c832d02fdb4339f9868c8a8636c3d9dd10bd53ac7ce99595825bd6beeffb3", 1000, 1000]}' -H 'content-type:application/json' 'http://localhost:8114' - #[rpc(name = "get_block_template")] - fn get_block_template(&self, H256, usize, usize) -> Result; - - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"submit_block","params": [{"header":{}, "uncles":[], "commit_transactions":[], "proposal_transactions":[]}]}' -H 'content-type:application/json' 'http://localhost:8114' - #[rpc(name = "submit_block")] - fn submit_block(&self, Block) -> Result; - } -} - -pub struct MinerRpcImpl { - pub network: Arc, - pub shared: Shared, - pub agent: AgentController, - pub chain: ChainController, -} - -impl MinerRpc for MinerRpcImpl { - fn get_block_template( - &self, - type_hash: H256, - max_transactions: usize, - max_proposals: usize, - ) -> Result { - self.agent - .get_block_template(type_hash, max_transactions, max_proposals) - .map_err(|_| Error::internal_error()) - } - - fn submit_block(&self, block: Block) -> Result { - let block = Arc::new(block); - let ret = self.chain.process_block(Arc::clone(&block)); - if ret.is_ok() { - // announce new block - self.network.with_protocol_context(RELAY_PROTOCOL_ID, |nc| { - let fbb = &mut FlatBufferBuilder::new(); - let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); - fbb.finish(message, None); - for peer in nc.connected_peers() { - let _ = nc.send(peer, fbb.finished_data().to_vec()); - } - }); - Ok(block.header().hash().clone()) - } else { - debug!(target: "rpc", "submit_block process_block {:?}", ret); - Err(Error::internal_error()) - } - } -} - -build_rpc_trait! { - pub trait NetworkRpc { - // curl -d '{"id": 2, "jsonrpc": "2.0", "method":"send_transaction","params": [{"version":2, "deps":[], "inputs":[], "outputs":[]}]}' -H 'content-type:application/json' 'http://localhost:8114' - #[rpc(name = "local_node_id")] - fn local_node_id(&self) -> Result>; - } -} - -struct NetworkRpcImpl { - pub network: Arc, -} - -impl NetworkRpc for NetworkRpcImpl { - fn local_node_id(&self) -> Result> { - Ok(self.network.external_url()) - } -} pub struct RpcServer { pub config: Config, @@ -225,40 +30,69 @@ impl RpcServer { tx_pool: TransactionPoolController, chain: ChainController, agent: AgentController, + test_engine: Option>, ) where CI: ChainIndex, { let mut io = IoHandler::new(); - io.extend_with( - ChainRpcImpl { - shared: shared.clone(), - } - .to_delegate(), - ); - io.extend_with( - PoolRpcImpl { - network: Arc::clone(&network), - tx_pool, - } - .to_delegate(), - ); - io.extend_with( - MinerRpcImpl { - shared, - agent, - chain, - network: Arc::clone(&network), - } - .to_delegate(), - ); - io.extend_with(NetworkRpcImpl { network }.to_delegate()); + + if self.config.chain_enable() { + io.extend_with( + ChainRpcImpl { + shared: shared.clone(), + } + .to_delegate(), + ); + } + + if self.config.pool_enable() { + io.extend_with( + PoolRpcImpl { + network: Arc::clone(&network), + tx_pool, + } + .to_delegate(), + ); + } + + if self.config.miner_enable() { + io.extend_with( + MinerRpcImpl { + shared, + agent, + chain, + network: Arc::clone(&network), + } + .to_delegate(), + ); + } + + if self.config.net_enable() { + io.extend_with( + NetworkRpcImpl { + network: Arc::clone(&network), + } + .to_delegate(), + ); + } + + if test_engine.is_some() { + io.extend_with( + IntegrationTestRpcImpl { + network, + test_engine: test_engine.expect("pow engine supply"), + } + .to_delegate(), + ); + } let server = ServerBuilder::new(io) .cors(DomainsValidation::AllowOnly(vec![ AccessControlAllowOrigin::Null, AccessControlAllowOrigin::Any, ])) - .start_http(&self.config.listen_addr.parse().unwrap()) + .threads(self.config.threads.unwrap_or_else(|| num_cpus::get())) + .start_http(&self.config.listen_address.parse().unwrap()) .unwrap(); info!(target: "rpc", "Now listening on {:?}", server.address()); diff --git a/rpc/src/types.rs b/rpc/src/types.rs index ea9e762bfc..8052d455cc 100644 --- a/rpc/src/types.rs +++ b/rpc/src/types.rs @@ -3,6 +3,7 @@ use ckb_core::cell::CellStatus; use ckb_core::header::Header; use ckb_core::transaction::{Capacity, CellOutput, OutPoint, Transaction}; use numext_fixed_hash::H256; +use serde_derive::Serialize; #[derive(Serialize)] pub struct TransactionWithHash { @@ -69,8 +70,3 @@ impl From for CellWithStatus { } } } - -#[derive(Clone, Debug, PartialEq, Deserialize)] -pub struct Config { - pub listen_addr: String, -} diff --git a/src/cli/run_impl.rs b/src/cli/run_impl.rs index 6ab1316cc1..ae57b77532 100644 --- a/src/cli/run_impl.rs +++ b/src/cli/run_impl.rs @@ -95,7 +95,7 @@ pub fn run(setup: Setup) { setup_rpc( rpc_server, - Arc::clone(&pow_engine), + &pow_engine, Arc::clone(&network), shared, tx_pool_controller, @@ -108,10 +108,9 @@ pub fn run(setup: Setup) { info!(target: "main", "Finishing work, please wait..."); } -#[cfg(feature = "integration_test")] fn setup_rpc( server: RpcServer, - pow: Arc, + pow: &Arc, network: Arc, shared: Shared, tx_pool: TransactionPoolController, @@ -120,34 +119,15 @@ fn setup_rpc( ) { use ckb_pow::Clicker; - let pow = pow.as_ref().as_any(); + let pow = pow + .as_ref() + .as_any() + .downcast_ref::() + .map(|pow| Arc::new(pow.clone())); - let pow = match pow.downcast_ref::() { - Some(pow) => Arc::new(pow.clone()), - None => panic!("pow isn't a Clicker!"), - }; - - let _ = thread::Builder::new().name("rpc".to_string()).spawn({ - move || { - server.start(network, shared, tx_pool, pow, chain, agent); - } - }); -} - -#[cfg(not(feature = "integration_test"))] -#[allow(clippy::needless_pass_by_value)] -fn setup_rpc( - server: RpcServer, - _pow: Arc, - network: Arc, - shared: Shared, - tx_pool: TransactionPoolController, - chain: ChainController, - agent: AgentController, -) { let _ = thread::Builder::new().name("rpc".to_string()).spawn({ move || { - server.start(network, shared, tx_pool, chain, agent); + server.start(network, shared, tx_pool, chain, agent, pow); } }); } From aad811ca24a46cfac92f6f4d192ea3b0547f5c63 Mon Sep 17 00:00:00 2001 From: zhangsoledad <787953403@qq.com> Date: Fri, 21 Dec 2018 20:47:32 +0800 Subject: [PATCH 38/45] fix(config): boot_nodes -> bootnodes --- network/src/lib.rs | 4 ++-- nodes_template/default.json | 2 +- rpc/src/server.rs | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/network/src/lib.rs b/network/src/lib.rs index b84ce1e9a0..5590d41358 100644 --- a/network/src/lib.rs +++ b/network/src/lib.rs @@ -48,7 +48,7 @@ pub struct Config { pub secret_file: Option, pub nodes_file: Option, /// List of initial node addresses - pub boot_nodes: Vec, + pub bootnodes: Vec, /// List of reserved node addresses. pub reserved_nodes: Vec, /// The non-reserved peer mode. @@ -77,7 +77,7 @@ impl From for NetworkConfig { cfg.max_outgoing_peers = config.max_outgoing_peers(); cfg.max_incoming_peers = config.max_incoming_peers(); cfg.listen_addresses = config.listen_addresses; - cfg.bootnodes = config.boot_nodes; + cfg.bootnodes = config.bootnodes; cfg.reserved_peers = config.reserved_nodes; if let Some(value) = config.non_reserved_mode { cfg.reserved_only = match value.as_str() { diff --git a/nodes_template/default.json b/nodes_template/default.json index 3c44416750..ec30d28433 100644 --- a/nodes_template/default.json +++ b/nodes_template/default.json @@ -17,7 +17,7 @@ }, "network": { "listen_addresses": ["/ip4/0.0.0.0/tcp/8115"], - "boot_nodes": [], + "bootnodes": [], "reserved_nodes": [], "only_reserved_peers": false, "min_peers": 4, diff --git a/rpc/src/server.rs b/rpc/src/server.rs index 6783e32aa9..fc881fd4d9 100644 --- a/rpc/src/server.rs +++ b/rpc/src/server.rs @@ -91,7 +91,7 @@ impl RpcServer { AccessControlAllowOrigin::Null, AccessControlAllowOrigin::Any, ])) - .threads(self.config.threads.unwrap_or_else(|| num_cpus::get())) + .threads(self.config.threads.unwrap_or_else(num_cpus::get)) .start_http(&self.config.listen_address.parse().unwrap()) .unwrap(); From 1da17f000cfc5bd98acb454c278c0c68900d8c4a Mon Sep 17 00:00:00 2001 From: Rain Chen Date: Sat, 22 Dec 2018 12:11:39 +0800 Subject: [PATCH 39/45] doc: update README for using a simple shell command to modify the config file (#114) [skip ci] --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index d355be000d..abd8d368d8 100644 --- a/README.md +++ b/README.md @@ -156,6 +156,12 @@ Update `data_dir` configuration in config file to a different directory. "data_dir": "node2" ``` +or using a simple shell command to modify the config file: + +```shell +ex -sc '%s/"data_dir": "default"/"data_dir": "node2"/|x' nodes/node2.json +``` + Then start the new node using the new config file ```shell From 02f73ba2c6974829d90daeb4b6b81e10880008bf Mon Sep 17 00:00:00 2001 From: zhangyaning Date: Mon, 24 Dec 2018 19:07:24 +0800 Subject: [PATCH 40/45] chore: add cellbase maturity (#112) --- spec/src/consensus.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spec/src/consensus.rs b/spec/src/consensus.rs index 70ecb33cbf..090d0cc4db 100644 --- a/spec/src/consensus.rs +++ b/spec/src/consensus.rs @@ -11,6 +11,7 @@ pub const MAX_UNCLE_LEN: usize = 2; pub const MAX_UNCLE_AGE: usize = 6; pub const TRANSACTION_PROPAGATION_TIME: BlockNumber = 1; pub const TRANSACTION_PROPAGATION_TIMEOUT: BlockNumber = 10; +pub const CELLBASE_MATURITY: usize = 100; //TODO:find best ORPHAN_RATE_TARGET pub const ORPHAN_RATE_TARGET: f32 = 0.1; @@ -31,6 +32,10 @@ pub struct Consensus { pub transaction_propagation_timeout: BlockNumber, pub pow: Pow, pub verification: bool, + // For each input, if the referenced output transaction is cellbase, + // it must have at least `cellbase_maturity` confirmations; + // else reject this transaction. + pub cellbase_maturity: usize, } // genesis difficulty should not be zero @@ -52,6 +57,7 @@ impl Default for Consensus { transaction_propagation_timeout: TRANSACTION_PROPAGATION_TIMEOUT, pow: Pow::Dummy, verification: true, + cellbase_maturity: CELLBASE_MATURITY, } } } @@ -113,4 +119,8 @@ impl Consensus { pub fn pow_engine(&self) -> Arc { self.pow.engine() } + + pub fn cellbase_maturity(&self) -> usize { + self.cellbase_maturity + } } From 5adfd82833ff26e5c77b21e222f3d43d20aa5fa6 Mon Sep 17 00:00:00 2001 From: ian Date: Mon, 24 Dec 2018 19:08:36 +0800 Subject: [PATCH 41/45] feat: use crate faketime to fake time (#111) The time crate is moved into [a separate repository](https://github.com/nervosnetwork/faketime). To fake time in test: - Use `faketime::millis_tempfile` to create a temp timestamp file. - Enable faketime via `faketime::enable` in current thread. To fake time in child threads: - Use `faketime::millis_tempfile` to create a temp timestamp file. - Set child thread name to `FAKETIME=PATH`, where PATH is the path to the timestamp file. To fake time of the generated binary, set the environment variable ``` echo 123456 > /tmp/faketime FAKETIME=/tmp/faketime ckb run ``` --- Cargo.lock | 25 +- Makefile | 8 +- README.md | 2 +- chain/Cargo.toml | 2 +- chain/src/chain.rs | 6 +- miner/Cargo.toml | 2 +- miner/src/agent.rs | 4 +- network/Cargo.toml | 2 +- network/src/ckb_service.rs | 6 +- network/src/peers_registry.rs | 4 +- network/src/ping_service.rs | 6 +- network/src/tests/peers_registry.rs | 4 +- pool/Cargo.toml | 2 +- pool/src/tests/pool.rs | 4 +- sync/Cargo.toml | 3 +- sync/src/synchronizer/block_fetcher.rs | 4 +- sync/src/synchronizer/block_pool.rs | 4 +- sync/src/synchronizer/mod.rs | 33 +- sync/src/synchronizer/peers.rs | 6 +- sync/src/tests/mod.rs | 2 + sync/src/tests/relayer.rs | 413 ++++++++++++----------- sync/src/tests/synchronizer.rs | 51 +-- util/time/Cargo.toml | 9 - util/time/src/lib.rs | 46 --- verification/Cargo.toml | 3 +- verification/src/header_verifier.rs | 4 +- verification/src/tests/uncle_verifier.rs | 9 +- 27 files changed, 337 insertions(+), 327 deletions(-) delete mode 100644 util/time/Cargo.toml delete mode 100644 util/time/src/lib.rs diff --git a/Cargo.lock b/Cargo.lock index cfd89228ea..f2cd90c891 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -349,10 +349,10 @@ dependencies = [ "ckb-db 0.3.0-pre", "ckb-notify 0.3.0-pre", "ckb-shared 0.3.0-pre", - "ckb-time 0.3.0-pre", "ckb-verification 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "faketime 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)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -424,9 +424,9 @@ dependencies = [ "ckb-pool 0.3.0-pre", "ckb-pow 0.3.0-pre", "ckb-shared 0.3.0-pre", - "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc 0.10.2 (git+https://github.com/quake/rust-jsonrpc)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -442,8 +442,8 @@ name = "ckb-network" version = "0.3.0-pre" dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", + "faketime 0.2.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.25 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.1.0 (git+https://github.com/libp2p/rust-libp2p?rev=cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0)", @@ -476,10 +476,10 @@ dependencies = [ "ckb-db 0.3.0-pre", "ckb-notify 0.3.0-pre", "ckb-shared 0.3.0-pre", - "ckb-time 0.3.0-pre", "ckb-verification 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", "linked-hash-map 0.5.1 (git+https://github.com/nervosnetwork/linked-hash-map?rev=df27f21)", @@ -600,11 +600,11 @@ dependencies = [ "ckb-pool 0.3.0-pre", "ckb-protocol 0.3.0-pre", "ckb-shared 0.3.0-pre", - "ckb-time 0.3.0-pre", "ckb-util 0.3.0-pre", "ckb-verification 0.3.0-pre", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", + "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (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)", @@ -614,10 +614,6 @@ dependencies = [ "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ckb-time" -version = "0.3.0-pre" - [[package]] name = "ckb-util" version = "0.3.0-pre" @@ -637,7 +633,7 @@ dependencies = [ "ckb-pow 0.3.0-pre", "ckb-script 0.3.0-pre", "ckb-shared 0.3.0-pre", - "ckb-time 0.3.0-pre", + "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "hash 0.3.0-pre", "merkle-root 0.3.0-pre", @@ -1011,6 +1007,14 @@ name = "fake-simd" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "faketime" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "faster-hex" version = "0.1.1" @@ -3497,6 +3501,7 @@ dependencies = [ "checksum failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6dd377bcc1b1b7ce911967e3ec24fa19c3224394ec05b54aa7b083d498341ac7" "checksum failure_derive 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "64c2d913fe8ed3b6c6518eedf4538255b989945c14c2a7d5cbff62a5e2120596" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" +"checksum faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "17087bd8c5a4a3e8bd40ecd9d3bda587459abcf67ca94211df09ec8451404cf8" "checksum faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2ea2e4ecc921ec2cbb8b10f0d400fe448554779d2ac5e0bfbb065836d9d8483a" "checksum flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea0c34f669be9911826facafe996adfda978aeee67285a13556869e2d8b8331f" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" diff --git a/Makefile b/Makefile index 46dceb868a..f6bd176d0a 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,12 @@ check: build: cargo build --release +prod: + RUSTFLAGS="--cfg disable_faketime" cargo build --release + +prod-test: + RUSTFLAGS="--cfg disable_faketime" RUSTDOCFLAGS="--cfg disable_faketime" cargo test --all -- --nocapture + fmt: cargo fmt --all -- --check @@ -47,6 +53,6 @@ security-audit: docker: build docker build -f docker/hub/Dockerfile -t nervos/ckb:latest . -.PHONY: build build-integration-test docker +.PHONY: build build-integration-test prod prod-test docker .PHONY: fmt test clippy proto doc doc-deps check stats .PHONY: ci ci-quick info security-audit diff --git a/README.md b/README.md index abd8d368d8..7f2db81b43 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ git clone https://github.com/nervosnetwork/ckb.git cd ckb # build in release mode -cargo build --release +make build ``` You can run the full test suite, or just run a specific package test: diff --git a/chain/Cargo.toml b/chain/Cargo.toml index 0431fd65ea..ad3bee3f8a 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -11,9 +11,9 @@ ckb-core = { path = "../core" } ckb-shared = { path = "../shared" } ckb-chain-spec = { path = "../spec" } ckb-db = { path = "../db" } -ckb-time = { path = "../util/time" } ckb-notify = { path = "../notify" } ckb-verification = { path = "../verification" } +faketime = "0.2.0" numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } channel = { package= "crossbeam-channel", version = "0.3" } diff --git a/chain/src/chain.rs b/chain/src/chain.rs index 93214f9b2f..b55d0bb49c 100644 --- a/chain/src/chain.rs +++ b/chain/src/chain.rs @@ -10,8 +10,8 @@ use ckb_notify::{ForkBlocks, NotifyController, NotifyService}; use ckb_shared::error::SharedError; use ckb_shared::index::ChainIndex; use ckb_shared::shared::{ChainProvider, Shared, TipHeader}; -use ckb_time::now_ms; use ckb_verification::{BlockVerifier, Verifier}; +use faketime::unix_time_as_millis; use log::{self, debug, error, log_enabled}; use numext_fixed_hash::H256; use numext_fixed_uint::U256; @@ -149,7 +149,7 @@ impl ChainService { let cannon_total_difficulty = parent_ext.total_difficulty + block.header().difficulty(); let ext = BlockExt { - received_at: now_ms(), + received_at: unix_time_as_millis(), total_difficulty: cannon_total_difficulty.clone(), total_uncles_count: parent_ext.total_uncles_count + block.uncles().len() as u64, }; @@ -435,7 +435,7 @@ pub mod test { let cellbase = create_cellbase(number); let header = HeaderBuilder::default() .parent_hash(parent_header.hash().clone()) - .timestamp(now_ms()) + .timestamp(unix_time_as_millis()) .number(number) .difficulty(difficulty) .nonce(nonce) diff --git a/miner/Cargo.toml b/miner/Cargo.toml index 2147537b61..0d409b7abb 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -14,7 +14,7 @@ ckb-pow = { path = "../pow" } ckb-util = { path = "../util" } ckb-notify = { path = "../notify" } ckb-pool = { path = "../pool" } -ckb-time = { path = "../util/time" } +faketime = "0.2.0" rand = "0.6" serde = "1.0" serde_derive = "1.0" diff --git a/miner/src/agent.rs b/miner/src/agent.rs index 5d0d089fdf..4e00dcf38f 100644 --- a/miner/src/agent.rs +++ b/miner/src/agent.rs @@ -10,7 +10,7 @@ use ckb_pool::txs_pool::TransactionPoolController; use ckb_shared::error::SharedError; use ckb_shared::index::ChainIndex; use ckb_shared::shared::{ChainProvider, Shared}; -use ckb_time::now_ms; +use faketime::unix_time_as_millis; use fnv::{FnvHashMap, FnvHashSet}; use log::error; use numext_fixed_hash::H256; @@ -123,7 +123,7 @@ impl Agent { let (cellbase, commit_transactions, proposal_transactions, header_builder) = { let tip_header = self.shared.tip_header().read(); let header = tip_header.inner(); - let now = cmp::max(now_ms(), header.timestamp() + 1); + let now = cmp::max(unix_time_as_millis(), header.timestamp() + 1); let difficulty = self .shared .calculate_difficulty(header) diff --git a/network/Cargo.toml b/network/Cargo.toml index e4a0dfcc20..74f3e5cb88 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -18,4 +18,4 @@ tokio = "0.1.8" futures = { version = "0.1.19", features = ["use_std"] } snap = "0.2" libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev="cfdfca1a06fb2deb9ebcc15a63d715ebddb23bd0", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] } -ckb-time = { path = "../util/time" } +faketime = "0.2.0" diff --git a/network/src/ckb_service.rs b/network/src/ckb_service.rs index 19a1909160..850660b49d 100644 --- a/network/src/ckb_service.rs +++ b/network/src/ckb_service.rs @@ -8,7 +8,7 @@ use crate::protocol_service::ProtocolService; use crate::CKBProtocolHandler; use crate::Network; use crate::PeerId; -use ckb_time::now_ms; +use faketime::unix_time_as_millis; use futures::future::{self, Future}; use futures::Stream; use libp2p::core::{Endpoint, Multiaddr, UniqueConnecState}; @@ -82,7 +82,9 @@ impl CKBService { move |data| { // update kad_system when we received data kad_system.update_kbuckets(peer_id.clone()); - network.modify_peer(&peer_id, |peer| peer.last_message_time = Some(now_ms())); + network.modify_peer(&peer_id, |peer| { + peer.last_message_time = Some(unix_time_as_millis()) + }); let protocol_handler = Arc::clone(&protocol_handler); let network = Arc::clone(&network); let handle_received = future::lazy(move || { diff --git a/network/src/peers_registry.rs b/network/src/peers_registry.rs index 824448b8e3..08fa608d19 100644 --- a/network/src/peers_registry.rs +++ b/network/src/peers_registry.rs @@ -2,8 +2,8 @@ use crate::network_group::{Group, NetworkGroup}; use crate::peer_store::PeerStore; use crate::{Error, ErrorKind, PeerId, PeerIndex, ProtocolId}; use bytes::Bytes; -use ckb_time::now_ms; use ckb_util::RwLock; +use faketime::unix_time_as_millis; use fnv::{FnvHashMap, FnvHashSet}; use futures::sync::mpsc::UnboundedSender; use libp2p::core::{Endpoint, Multiaddr, UniqueConnec}; @@ -380,7 +380,7 @@ impl PeersRegistry { .write() .new_connected_peer(&peer_id, connected_addr.clone()); let mut peer = PeerConnection::new(connected_addr, endpoint); - peer.connected_time = Some(now_ms()); + peer.connected_time = Some(unix_time_as_millis()); let peer_index = self.peers.or_insert(peer_id.clone(), peer); debug!(target: "network", "allocate peer_index {} to peer {:?}", peer_index, peer_id); peer_index diff --git a/network/src/ping_service.rs b/network/src/ping_service.rs index 5d9ab0873a..64bc1b8f20 100644 --- a/network/src/ping_service.rs +++ b/network/src/ping_service.rs @@ -4,7 +4,7 @@ use crate::protocol_service::ProtocolService; use crate::transport::TransportOutput; use crate::Network; use crate::PeerId; -use ckb_time::now_ms; +use faketime::unix_time_as_millis; use futures::future::{self, Future}; use futures::stream::FuturesUnordered; use futures::Stream; @@ -141,7 +141,7 @@ impl ProtocolService for PingService { }) } }); - let ping_start_time = now_ms(); + let ping_start_time = unix_time_as_millis(); let ping_future = Future::then(Timeout::new(ping_future, ping_timeout), { let network = Arc::clone(&network); @@ -149,7 +149,7 @@ impl ProtocolService for PingService { let mut peer_store = network.peer_store().write(); match result { Ok(peer_id) => { - let now = now_ms(); + let now = unix_time_as_millis(); let ping = now - ping_start_time; network.modify_peer(&peer_id, |peer| { peer.ping = Some(ping); diff --git a/network/src/tests/peers_registry.rs b/network/src/tests/peers_registry.rs index 7ad30b3a5f..5fad5d2626 100644 --- a/network/src/tests/peers_registry.rs +++ b/network/src/tests/peers_registry.rs @@ -4,8 +4,8 @@ use crate::{ peers_registry::{PeersRegistry, EVICTION_PROTECT_PEERS}, random_peer_id, ToMultiaddr, }; -use ckb_time::now_ms; use ckb_util::RwLock; +use faketime::unix_time_as_millis; use std::default::Default; use std::sync::Arc; @@ -117,7 +117,7 @@ fn test_accept_inbound_peer_eviction() { peer.ping = Some(0); } // peers which most recently sent messages - let now = now_ms(); + let now = unix_time_as_millis(); for _ in 0..EVICTION_PROTECT_PEERS { let peer_id = peers_iter.next().unwrap(); let mut peer = peers_registry.get_mut(&peer_id).unwrap(); diff --git a/pool/Cargo.toml b/pool/Cargo.toml index 496ba886d8..f380a3b69f 100644 --- a/pool/Cargo.toml +++ b/pool/Cargo.toml @@ -9,9 +9,9 @@ edition = "2018" ckb-core = { path = "../core" } ckb-shared = { path = "../shared" } ckb-chain-spec = { path = "../spec" } -ckb-time = { path = "../util/time" } ckb-notify = { path = "../notify" } ckb-verification = { path = "../verification" } +faketime = "0.2.0" numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } lru-cache = { git = "https://github.com/nervosnetwork/lru-cache" } linked-hash-map = { git = "https://github.com/nervosnetwork/linked-hash-map", rev = "df27f21" } diff --git a/pool/src/tests/pool.rs b/pool/src/tests/pool.rs index 107d74bf3c..7c980e634d 100644 --- a/pool/src/tests/pool.rs +++ b/pool/src/tests/pool.rs @@ -14,7 +14,7 @@ use ckb_notify::{ForkBlocks, MsgNewTip, MsgSwitchFork, NotifyService}; use ckb_shared::index::ChainIndex; use ckb_shared::shared::{ChainProvider, Shared, SharedBuilder}; use ckb_shared::store::ChainKVStore; -use ckb_time::now_ms; +use faketime::unix_time_as_millis; use log::error; use numext_fixed_hash::H256; use std::fs::File; @@ -573,7 +573,7 @@ fn apply_transactions( let header_builder = HeaderBuilder::default() .parent_hash(parent.hash().clone()) .number(parent.number() + 1) - .timestamp(now_ms()) + .timestamp(unix_time_as_millis()) .cellbase_id(cellbase_id) .difficulty(pool.shared.calculate_difficulty(&parent).unwrap()); diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 2c987aa047..40786d5d51 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -17,7 +17,7 @@ fnv = "1.0" ckb-protocol = { path = "../protocol" } ckb-util = { path = "../util" } ckb-pool = { path = "../pool" } -ckb-time = { path = "../util/time" } +faketime = "0.2.0" bitflags = "1.0" ckb-verification = { path = "../verification" } serde = "1.0" @@ -28,6 +28,5 @@ ckb-chain-spec = { path = "../spec" } [dev-dependencies] ckb-notify = { path = "../notify" } ckb-db = { path = "../db" } -ckb-time = { path = "../util/time", features = ["mock_timer"] } env_logger = "0.6" crossbeam-channel = "0.3" diff --git a/sync/src/synchronizer/block_fetcher.rs b/sync/src/synchronizer/block_fetcher.rs index 463917642a..f39ca6fe16 100644 --- a/sync/src/synchronizer/block_fetcher.rs +++ b/sync/src/synchronizer/block_fetcher.rs @@ -8,8 +8,8 @@ use ckb_core::header::Header; use ckb_network::PeerIndex; use ckb_shared::index::ChainIndex; use ckb_shared::shared::{ChainProvider, TipHeader}; -use ckb_time::now_ms; use ckb_util::{try_option, RwLockUpgradableReadGuard}; +use faketime::unix_time_as_millis; use log::debug; use numext_fixed_hash::H256; use std::cmp; @@ -38,7 +38,7 @@ where .entry(self.peer) .or_insert_with(Default::default); - if inflight.timestamp < now_ms().saturating_sub(BLOCK_DOWNLOAD_TIMEOUT) { + if inflight.timestamp < unix_time_as_millis().saturating_sub(BLOCK_DOWNLOAD_TIMEOUT) { debug!(target: "sync", "[block downloader] inflight block download timeout"); inflight.clear(); } diff --git a/sync/src/synchronizer/block_pool.rs b/sync/src/synchronizer/block_pool.rs index 7c2fb3f780..e6cabf952d 100644 --- a/sync/src/synchronizer/block_pool.rs +++ b/sync/src/synchronizer/block_pool.rs @@ -62,14 +62,14 @@ mod tests { use ckb_chain_spec::consensus::Consensus; use ckb_core::block::BlockBuilder; use ckb_core::header::{Header, HeaderBuilder}; - use ckb_time::now_ms; + use faketime::unix_time_as_millis; use std::collections::HashSet; use std::iter::FromIterator; fn gen_block(parent_header: Header) -> Block { let header = HeaderBuilder::default() .parent_hash(parent_header.hash().clone()) - .timestamp(now_ms()) + .timestamp(unix_time_as_millis()) .number(parent_header.number() + 1) .nonce(parent_header.nonce() + 1) .build(); diff --git a/sync/src/synchronizer/mod.rs b/sync/src/synchronizer/mod.rs index e66e5599d4..e864959f1c 100644 --- a/sync/src/synchronizer/mod.rs +++ b/sync/src/synchronizer/mod.rs @@ -31,8 +31,8 @@ use ckb_network::{CKBProtocolContext, CKBProtocolHandler, PeerIndex, Severity, T use ckb_protocol::{SyncMessage, SyncPayload}; use ckb_shared::index::ChainIndex; use ckb_shared::shared::{ChainProvider, Shared}; -use ckb_time::now_ms; use ckb_util::{try_option, RwLock, RwLockUpgradableReadGuard}; +use faketime::unix_time_as_millis; use flatbuffers::{get_root, FlatBufferBuilder}; use log::{debug, info, warn}; use numext_fixed_hash::H256; @@ -185,11 +185,12 @@ impl Synchronizer { } pub fn is_initial_block_download(&self) -> bool { - now_ms().saturating_sub(self.shared.tip_header().read().inner().timestamp()) > MAX_TIP_AGE + unix_time_as_millis().saturating_sub(self.shared.tip_header().read().inner().timestamp()) + > MAX_TIP_AGE } pub fn predict_headers_sync_time(&self, header: &Header) -> u64 { - let now = now_ms(); + let now = unix_time_as_millis(); now + HEADERS_DOWNLOAD_TIMEOUT_BASE + HEADERS_DOWNLOAD_TIMEOUT_PER_HEADER * (now.saturating_sub(header.timestamp()) / POW_SPACE) @@ -523,7 +524,7 @@ impl Synchronizer { let is_initial_block_download = self.is_initial_block_download(); let mut eviction = Vec::new(); for (peer, state) in peer_state.iter_mut() { - let now = now_ms(); + let now = unix_time_as_millis(); // headers_sync_timeout if let Some(timeout) = state.headers_sync_timeout { if now > timeout && is_initial_block_download && !state.disconnect { @@ -725,8 +726,9 @@ mod tests { use ckb_shared::index::ChainIndex; use ckb_shared::shared::SharedBuilder; use ckb_shared::store::ChainKVStore; - use ckb_time::set_mock_timer; use ckb_util::Mutex; + #[cfg(not(disable_faketime))] + use faketime; use flatbuffers::FlatBufferBuilder; use fnv::{FnvHashMap, FnvHashSet}; use numext_fixed_uint::U256; @@ -1213,16 +1215,19 @@ mod tests { assert!(new_tip_receiver.recv().is_ok()); } + #[cfg(not(disable_faketime))] #[test] fn test_header_sync_timeout() { use std::iter::FromIterator; + let faketime_file = faketime::millis_tempfile(0).expect("create faketime file"); + faketime::enable(&faketime_file); let (chain_controller, shared, _notify) = start_chain(None, None); let synchronizer = gen_synchronizer(chain_controller.clone(), shared.clone()); let network_context = mock_network_context(5); - set_mock_timer(MAX_TIP_AGE * 2); + faketime::write_millis(&faketime_file, MAX_TIP_AGE * 2).expect("write millis"); assert!(synchronizer.is_initial_block_download()); let peers = synchronizer.peers(); // protect should not effect headers_timeout @@ -1236,9 +1241,13 @@ mod tests { &FnvHashSet::from_iter(vec![0, 1].into_iter()) ) } + + #[cfg(not(disable_faketime))] #[test] fn test_chain_sync_timeout() { use std::iter::FromIterator; + let faketime_file = faketime::millis_tempfile(0).expect("create faketime file"); + faketime::enable(&faketime_file); let consensus = Consensus::default(); let header = HeaderBuilder::default() @@ -1303,7 +1312,7 @@ mod tests { CHAIN_SYNC_TIMEOUT ); } - set_mock_timer(CHAIN_SYNC_TIMEOUT + 1); + faketime::write_millis(&faketime_file, CHAIN_SYNC_TIMEOUT + 1).expect("write millis"); synchronizer.eviction(&network_context); { let peer_state = peers.state.read(); @@ -1313,14 +1322,18 @@ mod tests { assert!({ network_context.disconnected.lock().is_empty() }); assert_eq!( peer_state.get(&3).unwrap().chain_sync.timeout, - now_ms() + EVICTION_HEADERS_RESPONSE_TIME + unix_time_as_millis() + EVICTION_HEADERS_RESPONSE_TIME ); assert_eq!( peer_state.get(&4).unwrap().chain_sync.timeout, - now_ms() + EVICTION_HEADERS_RESPONSE_TIME + unix_time_as_millis() + EVICTION_HEADERS_RESPONSE_TIME ); } - set_mock_timer(now_ms() + EVICTION_HEADERS_RESPONSE_TIME + 1); + faketime::write_millis( + &faketime_file, + unix_time_as_millis() + EVICTION_HEADERS_RESPONSE_TIME + 1, + ) + .expect("write millis"); synchronizer.eviction(&network_context); { // Peer(3,4) run out of time to catch up! diff --git a/sync/src/synchronizer/peers.rs b/sync/src/synchronizer/peers.rs index 87e25fcfd5..6083081027 100644 --- a/sync/src/synchronizer/peers.rs +++ b/sync/src/synchronizer/peers.rs @@ -3,8 +3,8 @@ use ckb_core::block::Block; use ckb_core::header::Header; use ckb_network::PeerIndex; use ckb_shared::shared::TipHeader; -use ckb_time::now_ms; use ckb_util::RwLock; +use faketime::unix_time_as_millis; use fnv::{FnvHashMap, FnvHashSet}; use log::debug; use numext_fixed_hash::H256; @@ -80,7 +80,7 @@ impl Default for BlocksInflight { fn default() -> Self { BlocksInflight { blocks: FnvHashSet::default(), - timestamp: now_ms(), + timestamp: unix_time_as_millis(), } } } @@ -103,7 +103,7 @@ impl BlocksInflight { } pub fn update_timestamp(&mut self) { - self.timestamp = now_ms(); + self.timestamp = unix_time_as_millis(); } pub fn clear(&mut self) { diff --git a/sync/src/tests/mod.rs b/sync/src/tests/mod.rs index 1611faefb9..ed6ffc3079 100644 --- a/sync/src/tests/mod.rs +++ b/sync/src/tests/mod.rs @@ -8,7 +8,9 @@ use std::sync::Arc; use std::thread; use std::time::Duration; +#[cfg(not(disable_faketime))] mod relayer; +#[cfg(not(disable_faketime))] mod synchronizer; #[derive(Default)] diff --git a/sync/src/tests/relayer.rs b/sync/src/tests/relayer.rs index fba8e82399..96a2aca180 100644 --- a/sync/src/tests/relayer.rs +++ b/sync/src/tests/relayer.rs @@ -13,7 +13,7 @@ use ckb_pool::txs_pool::{PoolConfig, TransactionPoolController, TransactionPoolS use ckb_protocol::RelayMessage; use ckb_shared::shared::{ChainProvider, Shared, SharedBuilder}; use ckb_shared::store::ChainKVStore; -use ckb_time::now_ms; +use faketime::{self, unix_time_as_millis}; use flatbuffers::get_root; use flatbuffers::FlatBufferBuilder; use numext_fixed_hash::H256; @@ -28,107 +28,117 @@ use std::{thread, time}; #[test] fn relay_compact_block_with_one_tx() { - let (mut node1, shared1, chain_controller1) = setup_node(3); - let (mut node2, shared2, _chain_controller2) = setup_node(3); + let faketime_file = faketime::millis_tempfile(0).expect("create faketime file"); + faketime::enable(&faketime_file); + let thread_name = format!("FAKETIME={}", faketime_file.display()); + + // Use the same thread name for all child threads, so the time is mocked in all these threads. + // This is required because the test relies on the determined timestamp. Now all the threads + // freeze the timestamp at UNIX EPOCH. + let (mut node1, shared1, chain_controller1) = setup_node(&thread_name, 3); + let (mut node2, shared2, _chain_controller2) = setup_node(&thread_name, 3); let barrier = Arc::new(Barrier::new(2)); node1.connect(&mut node2, RELAY_PROTOCOL_ID); let (signal_tx1, _) = channel(); let barrier1 = Arc::clone(&barrier); - thread::spawn(move || { - let last_block = shared1.block(&shared1.tip_header().read().hash()).unwrap(); - let last_cellbase = last_block.commit_transactions().first().unwrap(); - - // building tx and broadcast it - let tx = TransactionBuilder::default() - .input(CellInput::new( - OutPoint::new(last_cellbase.hash().clone(), 0), - create_valid_script(), - )) - .output(CellOutput::new(50, Vec::new(), H256::zero(), None)) - .build(); - - { - let fbb = &mut FlatBufferBuilder::new(); - let message = RelayMessage::build_transaction(fbb, &tx); - fbb.finish(message, None); - node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); - } - - // building 1st compact block with tx proposal and broadcast it - let block = { - let number = last_block.header().number() + 1; - let timestamp = last_block.header().timestamp() + 1; - let difficulty = shared1.calculate_difficulty(&last_block.header()).unwrap(); - let cellbase = TransactionBuilder::default() - .input(CellInput::new_cellbase_input(number)) - .output(CellOutput::default()) + thread::Builder::new() + .name(thread_name) + .spawn(move || { + let last_block = shared1.block(&shared1.tip_header().read().hash()).unwrap(); + let last_cellbase = last_block.commit_transactions().first().unwrap(); + + // building tx and broadcast it + let tx = TransactionBuilder::default() + .input(CellInput::new( + OutPoint::new(last_cellbase.hash().clone(), 0), + create_valid_script(), + )) + .output(CellOutput::new(50, Vec::new(), H256::zero(), None)) .build(); - let header_builder = HeaderBuilder::default() - .parent_hash(last_block.header().hash().clone()) - .number(number) - .timestamp(timestamp) - .difficulty(difficulty) - .cellbase_id(cellbase.hash().clone()); - - BlockBuilder::default() - .commit_transaction(cellbase) - .proposal_transaction(tx.proposal_short_id()) - .with_header_builder(header_builder) - }; - - { - chain_controller1 - .process_block(Arc::new(block.clone())) - .expect("process block should be OK"); - - let fbb = &mut FlatBufferBuilder::new(); - let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); - fbb.finish(message, None); - node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); - } - - // building 2nd compact block with tx and broadcast it - let last_block = block; - - let block = { - let number = last_block.header().number() + 1; - let timestamp = last_block.header().timestamp() + 1; - let difficulty = shared1.calculate_difficulty(&last_block.header()).unwrap(); - let cellbase = TransactionBuilder::default() - .input(CellInput::new_cellbase_input(number)) - .output(CellOutput::default()) - .build(); - - let header_builder = HeaderBuilder::default() - .parent_hash(last_block.header().hash().clone()) - .number(number) - .timestamp(timestamp) - .difficulty(difficulty) - .cellbase_id(cellbase.hash().clone()); - - BlockBuilder::default() - .commit_transaction(cellbase) - .commit_transaction(tx) - .with_header_builder(header_builder) - }; - - { - chain_controller1 - .process_block(Arc::new(block.clone())) - .expect("process block should be OK"); - - let fbb = &mut FlatBufferBuilder::new(); - let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); - fbb.finish(message, None); - node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); - } - - node1.start(signal_tx1, |_| false); - barrier1.wait(); - }); + { + let fbb = &mut FlatBufferBuilder::new(); + let message = RelayMessage::build_transaction(fbb, &tx); + fbb.finish(message, None); + node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); + } + + // building 1st compact block with tx proposal and broadcast it + let block = { + let number = last_block.header().number() + 1; + let timestamp = last_block.header().timestamp() + 1; + let difficulty = shared1.calculate_difficulty(&last_block.header()).unwrap(); + let cellbase = TransactionBuilder::default() + .input(CellInput::new_cellbase_input(number)) + .output(CellOutput::default()) + .build(); + + let header_builder = HeaderBuilder::default() + .parent_hash(last_block.header().hash().clone()) + .number(number) + .timestamp(timestamp) + .difficulty(difficulty) + .cellbase_id(cellbase.hash().clone()); + + BlockBuilder::default() + .commit_transaction(cellbase) + .proposal_transaction(tx.proposal_short_id()) + .with_header_builder(header_builder) + }; + + { + chain_controller1 + .process_block(Arc::new(block.clone())) + .expect("process block should be OK"); + + let fbb = &mut FlatBufferBuilder::new(); + let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); + fbb.finish(message, None); + node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); + } + + // building 2nd compact block with tx and broadcast it + let last_block = block; + + let block = { + let number = last_block.header().number() + 1; + let timestamp = last_block.header().timestamp() + 1; + let difficulty = shared1.calculate_difficulty(&last_block.header()).unwrap(); + let cellbase = TransactionBuilder::default() + .input(CellInput::new_cellbase_input(number)) + .output(CellOutput::default()) + .build(); + + let header_builder = HeaderBuilder::default() + .parent_hash(last_block.header().hash().clone()) + .number(number) + .timestamp(timestamp) + .difficulty(difficulty) + .cellbase_id(cellbase.hash().clone()); + + BlockBuilder::default() + .commit_transaction(cellbase) + .commit_transaction(tx) + .with_header_builder(header_builder) + }; + + { + chain_controller1 + .process_block(Arc::new(block.clone())) + .expect("process block should be OK"); + + let fbb = &mut FlatBufferBuilder::new(); + let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); + fbb.finish(message, None); + node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); + } + + node1.start(signal_tx1, |_| false); + barrier1.wait(); + }) + .expect("thread spawn"); let barrier2 = Arc::clone(&barrier); let (signal_tx2, signal_rx2) = channel(); @@ -155,108 +165,118 @@ fn relay_compact_block_with_one_tx() { #[test] fn relay_compact_block_with_missing_indexs() { - let (mut node1, shared1, chain_controller1) = setup_node(3); - let (mut node2, shared2, _chain_controller2) = setup_node(3); + let faketime_file = faketime::millis_tempfile(0).expect("create faketime file"); + faketime::enable(&faketime_file); + let thread_name = format!("FAKETIME={}", faketime_file.display()); + + // Use the same thread name for all child threads, so the time is mocked in all these threads. + // This is required because the test relies on the determined timestamp. Now all the threads + // freeze the timestamp at UNIX EPOCH. + let (mut node1, shared1, chain_controller1) = setup_node(&thread_name, 3); + let (mut node2, shared2, _chain_controller2) = setup_node(&thread_name, 3); node1.connect(&mut node2, RELAY_PROTOCOL_ID); let (signal_tx1, _) = channel(); - thread::spawn(move || { - let last_block = shared1.block(&shared1.tip_header().read().hash()).unwrap(); - let last_cellbase = last_block.commit_transactions().first().unwrap(); - - // building 10 txs and broadcast some - let txs = (0..10u8) - .map(|i| { - TransactionBuilder::default() - .input(CellInput::new( - OutPoint::new(last_cellbase.hash().clone(), i as u32), - create_valid_script(), - )) - .output(CellOutput::new(50, vec![i], H256::zero(), None)) - .build() - }) - .collect::>(); - - [3, 5].iter().for_each(|i| { - let fbb = &mut FlatBufferBuilder::new(); - let message = RelayMessage::build_transaction(fbb, txs.get(*i).unwrap()); - fbb.finish(message, None); - node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); - }); - - // building 1st compact block with tx proposal and broadcast it - let block = { - let number = last_block.header().number() + 1; - let timestamp = last_block.header().timestamp() + 1; - let difficulty = shared1.calculate_difficulty(&last_block.header()).unwrap(); - let cellbase = TransactionBuilder::default() - .input(CellInput::new_cellbase_input(number)) - .output(CellOutput::default()) - .build(); - - let header_builder = HeaderBuilder::default() - .parent_hash(last_block.header().hash().clone()) - .number(number) - .timestamp(timestamp) - .difficulty(difficulty) - .cellbase_id(cellbase.hash().clone()); - - BlockBuilder::default() - .commit_transaction(cellbase) - .proposal_transactions(txs.iter().map(|tx| tx.proposal_short_id()).collect()) - .with_header_builder(header_builder) - }; - - { - chain_controller1 - .process_block(Arc::new(block.clone())) - .expect("process block should be OK"); - - let fbb = &mut FlatBufferBuilder::new(); - let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); - fbb.finish(message, None); - node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); - } - - // building 2nd compact block with txs and broadcast it - let last_block = block; - - let block = { - let number = last_block.header().number() + 1; - let timestamp = last_block.header().timestamp() + 1; - let difficulty = shared1.calculate_difficulty(&last_block.header()).unwrap(); - let cellbase = TransactionBuilder::default() - .input(CellInput::new_cellbase_input(number)) - .output(CellOutput::default()) - .build(); - - let header_builder = HeaderBuilder::default() - .parent_hash(last_block.header().hash().clone()) - .number(number) - .timestamp(timestamp) - .difficulty(difficulty) - .cellbase_id(cellbase.hash().clone()); - - BlockBuilder::default() - .commit_transaction(cellbase) - .commit_transactions(txs) - .with_header_builder(header_builder) - }; - - { - chain_controller1 - .process_block(Arc::new(block.clone())) - .expect("process block should be OK"); - - let fbb = &mut FlatBufferBuilder::new(); - let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); - fbb.finish(message, None); - node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); - } - - node1.start(signal_tx1, |_| false); - }); + thread::Builder::new() + .name(thread_name) + .spawn(move || { + let last_block = shared1.block(&shared1.tip_header().read().hash()).unwrap(); + let last_cellbase = last_block.commit_transactions().first().unwrap(); + + // building 10 txs and broadcast some + let txs = (0..10u8) + .map(|i| { + TransactionBuilder::default() + .input(CellInput::new( + OutPoint::new(last_cellbase.hash().clone(), i as u32), + create_valid_script(), + )) + .output(CellOutput::new(50, vec![i], H256::zero(), None)) + .build() + }) + .collect::>(); + + [3, 5].iter().for_each(|i| { + let fbb = &mut FlatBufferBuilder::new(); + let message = RelayMessage::build_transaction(fbb, txs.get(*i).unwrap()); + fbb.finish(message, None); + node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); + }); + + // building 1st compact block with tx proposal and broadcast it + let block = { + let number = last_block.header().number() + 1; + let timestamp = last_block.header().timestamp() + 1; + let difficulty = shared1.calculate_difficulty(&last_block.header()).unwrap(); + let cellbase = TransactionBuilder::default() + .input(CellInput::new_cellbase_input(number)) + .output(CellOutput::default()) + .build(); + + let header_builder = HeaderBuilder::default() + .parent_hash(last_block.header().hash().clone()) + .number(number) + .timestamp(timestamp) + .difficulty(difficulty) + .cellbase_id(cellbase.hash().clone()); + + BlockBuilder::default() + .commit_transaction(cellbase) + .proposal_transactions(txs.iter().map(|tx| tx.proposal_short_id()).collect()) + .with_header_builder(header_builder) + }; + + { + chain_controller1 + .process_block(Arc::new(block.clone())) + .expect("process block should be OK"); + + let fbb = &mut FlatBufferBuilder::new(); + let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); + fbb.finish(message, None); + node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); + } + + // building 2nd compact block with txs and broadcast it + let last_block = block; + + let block = { + let number = last_block.header().number() + 1; + let timestamp = last_block.header().timestamp() + 1; + let difficulty = shared1.calculate_difficulty(&last_block.header()).unwrap(); + let cellbase = TransactionBuilder::default() + .input(CellInput::new_cellbase_input(number)) + .output(CellOutput::default()) + .build(); + + let header_builder = HeaderBuilder::default() + .parent_hash(last_block.header().hash().clone()) + .number(number) + .timestamp(timestamp) + .difficulty(difficulty) + .cellbase_id(cellbase.hash().clone()); + + BlockBuilder::default() + .commit_transaction(cellbase) + .commit_transactions(txs) + .with_header_builder(header_builder) + }; + + { + chain_controller1 + .process_block(Arc::new(block.clone())) + .expect("process block should be OK"); + + let fbb = &mut FlatBufferBuilder::new(); + let message = RelayMessage::build_compact_block(fbb, &block, &HashSet::new()); + fbb.finish(message, None); + node1.broadcast(RELAY_PROTOCOL_ID, fbb.finished_data().to_vec()); + } + + node1.start(signal_tx1, |_| false); + }) + .expect("thread spawn"); let (signal_tx2, signal_rx2) = channel(); thread::spawn(move || { @@ -276,6 +296,7 @@ fn relay_compact_block_with_missing_indexs() { } fn setup_node( + thread_name: &str, height: u64, ) -> ( TestNode, @@ -284,7 +305,7 @@ fn setup_node( ) { let mut block = BlockBuilder::default().with_header_builder( HeaderBuilder::default() - .timestamp(now_ms()) + .timestamp(unix_time_as_millis()) .difficulty(U256::from(1000u64)), ); let consensus = Consensus::default().set_genesis_block(block.clone()); @@ -295,16 +316,16 @@ fn setup_node( let (chain_controller, chain_receivers) = ChainController::build(); let (tx_pool_controller, tx_pool_receivers) = TransactionPoolController::build(); - let (_handle, notify) = NotifyService::default().start::<&str>(None); + let (_handle, notify) = NotifyService::default().start(Some(thread_name)); let tx_pool_service = TransactionPoolService::new(PoolConfig::default(), shared.clone(), notify.clone()); - let _handle = tx_pool_service.start::<&str>(None, tx_pool_receivers); + let _handle = tx_pool_service.start(Some(thread_name), tx_pool_receivers); let chain_service = ChainBuilder::new(shared.clone()) .notify(notify.clone()) .build(); - let _handle = chain_service.start::<&str>(None, chain_receivers); + let _handle = chain_service.start(Some(thread_name), chain_receivers); for _i in 0..height { let number = block.header().number() + 1; diff --git a/sync/src/tests/synchronizer.rs b/sync/src/tests/synchronizer.rs index 638ba3896d..464b5c060b 100644 --- a/sync/src/tests/synchronizer.rs +++ b/sync/src/tests/synchronizer.rs @@ -11,7 +11,7 @@ use ckb_notify::NotifyService; use ckb_protocol::SyncMessage; use ckb_shared::shared::{ChainProvider, Shared, SharedBuilder}; use ckb_shared::store::ChainKVStore; -use ckb_time::now_ms; +use faketime::{self, unix_time_as_millis}; use flatbuffers::get_root; use numext_fixed_uint::U256; use std::sync::mpsc::channel; @@ -20,26 +20,36 @@ use std::thread; #[test] fn basic_sync() { - let (mut node1, shared1) = setup_node(1); - let (mut node2, shared2) = setup_node(3); + let faketime_file = faketime::millis_tempfile(0).expect("create faketime file"); + faketime::enable(&faketime_file); + let thread_name = format!("FAKETIME={}", faketime_file.display()); + + let (mut node1, shared1) = setup_node(&thread_name, 1); + let (mut node2, shared2) = setup_node(&thread_name, 3); node1.connect(&mut node2, SYNC_PROTOCOL_ID); let (signal_tx1, signal_rx1) = channel(); - thread::spawn(move || { - node1.start(signal_tx1, |data| { - let msg = get_root::(data); - // terminate thread after 3 blocks - msg.payload_as_block() - .map(|block| block.header().unwrap().number() == 3) - .unwrap_or(false) - }); - }); + thread::Builder::new() + .name(thread_name.clone()) + .spawn(move || { + node1.start(signal_tx1, |data| { + let msg = get_root::(data); + // terminate thread after 3 blocks + msg.payload_as_block() + .map(|block| block.header().unwrap().number() == 3) + .unwrap_or(false) + }); + }) + .expect("thread spawn"); let (signal_tx2, _) = channel(); - thread::spawn(move || { - node2.start(signal_tx2, |_| false); - }); + thread::Builder::new() + .name(thread_name) + .spawn(move || { + node2.start(signal_tx2, |_| false); + }) + .expect("thread spawn"); // Wait node1 receive block from node2 let _ = signal_rx1.recv(); @@ -51,10 +61,13 @@ fn basic_sync() { ); } -fn setup_node(height: u64) -> (TestNode, Shared>) { +fn setup_node( + thread_name: &str, + height: u64, +) -> (TestNode, Shared>) { let mut block = BlockBuilder::default().with_header_builder( HeaderBuilder::default() - .timestamp(now_ms()) + .timestamp(unix_time_as_millis()) .difficulty(U256::from(1000u64)), ); @@ -63,12 +76,12 @@ fn setup_node(height: u64) -> (TestNode, Shared>) .consensus(consensus) .build(); let (chain_controller, chain_receivers) = ChainController::build(); - let (_handle, notify) = NotifyService::default().start::<&str>(None); + let (_handle, notify) = NotifyService::default().start(Some(thread_name)); let chain_service = ChainBuilder::new(shared.clone()) .notify(notify.clone()) .build(); - let _handle = chain_service.start::<&str>(None, chain_receivers); + let _handle = chain_service.start(Some(thread_name), chain_receivers); for _i in 0..height { let number = block.header().number() + 1; diff --git a/util/time/Cargo.toml b/util/time/Cargo.toml deleted file mode 100644 index 6f7ef8e995..0000000000 --- a/util/time/Cargo.toml +++ /dev/null @@ -1,9 +0,0 @@ -[package] -name = "ckb-time" -version = "0.3.0-pre" -license = "MIT" -authors = ["Nervos Core Dev "] -edition = "2018" - -[features] -mock_timer = [] diff --git a/util/time/src/lib.rs b/util/time/src/lib.rs deleted file mode 100644 index 1f1ca78315..0000000000 --- a/util/time/src/lib.rs +++ /dev/null @@ -1,46 +0,0 @@ -#[cfg(feature = "mock_timer")] -use std::cell::Cell; -use std::time::Duration; -#[cfg(not(feature = "mock_timer"))] -use std::time::{SystemTime, UNIX_EPOCH}; - -#[cfg(feature = "mock_timer")] -thread_local! { - pub static MOCK_TIMER: Cell = Cell::new(Duration::from_millis(0)); -} - -#[cfg(feature = "mock_timer")] -pub fn now() -> Duration { - MOCK_TIMER.with(|t| t.get()) -} - -#[cfg(feature = "mock_timer")] -pub fn set_mock_timer(ms: u64) { - MOCK_TIMER.with(|t| { - t.replace(Duration::from_millis(ms)); - }); -} - -#[cfg(not(feature = "mock_timer"))] -pub fn now() -> Duration { - SystemTime::now() - .duration_since(UNIX_EPOCH) - .expect("Time went backwards") -} - -pub fn now_ms() -> u64 { - let duration = now(); - duration.as_secs() * 1000 + u64::from(duration.subsec_millis()) -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_mock_timer() { - assert_eq!(now_ms(), 0); - set_mock_timer(100); - assert_eq!(now_ms(), 100); - } -} diff --git a/verification/Cargo.toml b/verification/Cargo.toml index 630f5d993f..681dd9f502 100644 --- a/verification/Cargo.toml +++ b/verification/Cargo.toml @@ -7,10 +7,10 @@ edition = "2018" [dependencies] ckb-core = { path = "../core" } -ckb-time = { path = "../util/time" } ckb-shared = { path = "../shared" } ckb-script = { path = "../script" } ckb-pow = { path = "../pow" } +faketime = "0.2.0" merkle-root = {path = "../util/merkle-root"} numext-fixed-hash = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } numext-fixed-uint = { version = "0.1", features = ["support_rand", "support_heapsize", "support_serde"] } @@ -20,7 +20,6 @@ fnv = "1.0.3" [dev-dependencies] ckb-db = { path = "../db" } ckb-notify = { path = "../notify" } -ckb-time = { path = "../util/time", features = ["mock_timer"] } ckb-chain = { path = "../chain" } ckb-chain-spec = { path = "../spec" } hash = {path = "../util/hash"} diff --git a/verification/src/header_verifier.rs b/verification/src/header_verifier.rs index 2c43991436..2b3f0db96b 100644 --- a/verification/src/header_verifier.rs +++ b/verification/src/header_verifier.rs @@ -3,7 +3,7 @@ use crate::error::{DifficultyError, Error, NumberError, PowError, TimestampError use crate::shared::ALLOWED_FUTURE_BLOCKTIME; use ckb_core::header::Header; use ckb_pow::PowEngine; -use ckb_time::now_ms; +use faketime::unix_time_as_millis; use numext_fixed_uint::U256; use std::marker::PhantomData; use std::sync::Arc; @@ -58,7 +58,7 @@ impl<'a> TimestampVerifier<'a> { TimestampVerifier { parent, header, - now: now_ms(), + now: unix_time_as_millis(), } } diff --git a/verification/src/tests/uncle_verifier.rs b/verification/src/tests/uncle_verifier.rs index b952bd60e2..6f8cddcab8 100644 --- a/verification/src/tests/uncle_verifier.rs +++ b/verification/src/tests/uncle_verifier.rs @@ -11,7 +11,8 @@ use ckb_core::BlockNumber; use ckb_db::memorydb::MemoryKeyValueDB; use ckb_shared::shared::{ChainProvider, Shared, SharedBuilder}; use ckb_shared::store::ChainKVStore; -use ckb_time::set_mock_timer; +#[cfg(not(disable_faketime))] +use faketime; use numext_fixed_hash::H256; use numext_fixed_uint::U256; use std::sync::Arc; @@ -56,8 +57,12 @@ fn create_cellbase(number: BlockNumber) -> Transaction { .build() } +#[cfg(not(disable_faketime))] #[test] fn test_uncle_verifier() { + let faketime_file = faketime::millis_tempfile(0).expect("create faketime file"); + faketime::enable(&faketime_file); + let mut consensus = Consensus::default(); consensus.pow_time_span = 10; consensus.pow_spacing = 1; @@ -69,7 +74,7 @@ fn test_uncle_verifier() { let mut chain1: Vec = Vec::new(); let mut chain2: Vec = Vec::new(); - set_mock_timer(10); + faketime::write_millis(&faketime_file, 10).expect("write millis"); let mut parent = shared.block_header(&shared.block_hash(0).unwrap()).unwrap(); for i in 1..number { From 986638f0722d0bf8c763e4d09413bb8f8f5ab973 Mon Sep 17 00:00:00 2001 From: ian Date: Mon, 24 Dec 2018 19:38:26 +0800 Subject: [PATCH 42/45] doc: remove deps.rs badge It can no longer parse this repository after upgrading to edition 2018 Refs https://github.com/srijs/deps.rs/pull/33 --- README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/README.md b/README.md index 7f2db81b43..d862bbcaee 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ # [Nervos CKB](https://www.nervos.org/) - The Common Knowledge Base [![TravisCI](https://travis-ci.com/nervosnetwork/ckb.svg?token=y9uR6ygmT3geQaMJ4jpJ&branch=develop)](https://travis-ci.com/nervosnetwork/ckb) -[![dependency status](https://deps.rs/repo/github/nervosnetwork/ckb/status.svg)](https://deps.rs/repo/github/nervosnetwork/ckb) [![Telegram Group](https://cdn.rawgit.com/Patrolavia/telegram-badge/8fe3382b/chat.svg)](https://t.me/nervos_ckb_dev) --- From 42736d98b0e4ff375520ed0c89904e718020a386 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 25 Dec 2018 14:06:45 +0800 Subject: [PATCH 43/45] chore: CHANGELOG for v0.3.0 --- CHANGELOG.md | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f48f59411e..be63bd3712 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,42 @@ All notable changes to this project will be documented in this file. See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. +# [v0.3.0](https://github.com/nervosnetwork/ckb/compare/v0.2.0...v0.3.0) (2019-01-02) + + +### Bug Fixes + +* **config:** boot\_nodes -> bootnodes ([aad811c](https://github.com/nervosnetwork/ckb/commit/aad811c)) +* add `tests/peers_registry` ([9616a18](https://github.com/nervosnetwork/ckb/commit/9616a18)) +* assign numeric numbers for syscall parameters ([3af9535](https://github.com/nervosnetwork/ckb/commit/3af9535)) +* cli panic ([c55e076](https://github.com/nervosnetwork/ckb/commit/c55e076)) +* cli subcommand setting ([bdf323f](https://github.com/nervosnetwork/ckb/commit/bdf323f)) +* fix calculation of headers sync timeout ([06a5e29](https://github.com/nervosnetwork/ckb/commit/06a5e29)) +* regulate parameters used in syscalls ([09e7cc7](https://github.com/nervosnetwork/ckb/commit/09e7cc7)) +* resolve mining old block issue ([#87](https://github.com/nervosnetwork/ckb/issues/87)) ([e5da1ae](https://github.com/nervosnetwork/ckb/commit/e5da1ae)) +* sync header verify ([366f077](https://github.com/nervosnetwork/ckb/commit/366f077)) +* uncheck subtract overflow ([#88](https://github.com/nervosnetwork/ckb/issues/88)) ([36b541f](https://github.com/nervosnetwork/ckb/commit/36b541f)) +* use new strategy to evict inbound peer ([95451e7](https://github.com/nervosnetwork/ckb/commit/95451e7)) + + +### Features + +* add `DATA_HASH` field type in Load Cell By Field ([2d0a378](https://github.com/nervosnetwork/ckb/commit/2d0a378)) +* add dep cell loading support in syscalls ([cae937f](https://github.com/nervosnetwork/ckb/commit/cae937f)) +* impl NetworkGroup for peer and multiaddr ([e1e5750](https://github.com/nervosnetwork/ckb/commit/e1e5750)) +* jsonrpc API modules ([f87d9a1](https://github.com/nervosnetwork/ckb/commit/f87d9a1)) +* try evict inbound peers when inbound slots is full ([d0db77e](https://github.com/nervosnetwork/ckb/commit/d0db77e)) +* use crate faketime to fake time ([#111](https://github.com/nervosnetwork/ckb/issues/111)) ([5adfd82](https://github.com/nervosnetwork/ckb/commit/5adfd82)) +* peerStore implement scoring interface ([d160d1e](https://github.com/nervosnetwork/ckb/commit/d160d1e)) +* rename outpoint to out\_point as its type is OutPoint (#93) ([3abf2b1](https://github.com/nervosnetwork/ckb/commit/3abf2b1))) +* use serialized flatbuffer format in referenced cell ([49fc513](https://github.com/nervosnetwork/ckb/commit/49fc513)) + + +### BREAKING CHANGES + +* In P2P and RPC, field `outpoint` is renamed to `out_point`. + + # [v0.2.0](https://github.com/nervosnetwork/ckb/compare/v0.1.0...v0.2.0) (2018-12-17) In this release, we have upgraded to Rust 2018. We also did 2 important refactoring: From 257daaf7013bd5c753771825288b13aef725ddb1 Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 25 Dec 2018 14:06:54 +0800 Subject: [PATCH 44/45] chore: bump to v0.3.0 --- Cargo.lock | 270 ++++++++++++++++++------------------ Cargo.toml | 2 +- benches/Cargo.toml | 2 +- chain/Cargo.toml | 2 +- core/Cargo.toml | 2 +- db/Cargo.toml | 2 +- miner/Cargo.toml | 2 +- network/Cargo.toml | 2 +- notify/Cargo.toml | 2 +- pool/Cargo.toml | 2 +- pow/Cargo.toml | 2 +- protocol/Cargo.toml | 2 +- rpc/Cargo.toml | 2 +- script/Cargo.toml | 2 +- shared/Cargo.toml | 2 +- spec/Cargo.toml | 2 +- sync/Cargo.toml | 2 +- util/Cargo.toml | 2 +- util/avl/Cargo.toml | 2 +- util/build-info/Cargo.toml | 2 +- util/crypto/Cargo.toml | 2 +- util/dir/Cargo.toml | 2 +- util/hash/Cargo.toml | 2 +- util/instrument/Cargo.toml | 2 +- util/logger/Cargo.toml | 2 +- util/merkle-root/Cargo.toml | 2 +- verification/Cargo.toml | 2 +- 27 files changed, 161 insertions(+), 161 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index cb153e1110..2dc5640a0d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -73,12 +73,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "avl-merkle" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.3.0-pre", - "ckb-db 0.3.0-pre", - "hash 0.3.0-pre", + "ckb-core 0.3.0", + "ckb-db 0.3.0", + "hash 0.3.0", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -224,7 +224,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "build-info" -version = "0.3.0-pre" +version = "0.3.0" [[package]] name = "byte-tools" @@ -297,33 +297,33 @@ dependencies = [ [[package]] name = "ckb" -version = "0.3.0-pre" -dependencies = [ - "build-info 0.3.0-pre", - "ckb-chain 0.3.0-pre", - "ckb-chain-spec 0.3.0-pre", - "ckb-core 0.3.0-pre", - "ckb-db 0.3.0-pre", - "ckb-instrument 0.3.0-pre", - "ckb-miner 0.3.0-pre", - "ckb-network 0.3.0-pre", - "ckb-notify 0.3.0-pre", - "ckb-pool 0.3.0-pre", - "ckb-pow 0.3.0-pre", - "ckb-rpc 0.3.0-pre", - "ckb-shared 0.3.0-pre", - "ckb-sync 0.3.0-pre", - "ckb-util 0.3.0-pre", +version = "0.3.0" +dependencies = [ + "build-info 0.3.0", + "ckb-chain 0.3.0", + "ckb-chain-spec 0.3.0", + "ckb-core 0.3.0", + "ckb-db 0.3.0", + "ckb-instrument 0.3.0", + "ckb-miner 0.3.0", + "ckb-network 0.3.0", + "ckb-notify 0.3.0", + "ckb-pool 0.3.0", + "ckb-pow 0.3.0", + "ckb-rpc 0.3.0", + "ckb-shared 0.3.0", + "ckb-sync 0.3.0", + "ckb-util 0.3.0", "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", "config 0.9.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "crypto 0.3.0-pre", + "crypto 0.3.0", "ctrlc 3.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "dir 0.3.0-pre", + "dir 0.3.0", "faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.3.0-pre", + "hash 0.3.0", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", - "logger 0.3.0-pre", + "logger 0.3.0", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -334,22 +334,22 @@ dependencies = [ [[package]] name = "ckb-benches" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ - "ckb-pow 0.3.0-pre", + "ckb-pow 0.3.0", "criterion 0.2.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ckb-chain" -version = "0.3.0-pre" -dependencies = [ - "ckb-chain-spec 0.3.0-pre", - "ckb-core 0.3.0-pre", - "ckb-db 0.3.0-pre", - "ckb-notify 0.3.0-pre", - "ckb-shared 0.3.0-pre", - "ckb-verification 0.3.0-pre", +version = "0.3.0" +dependencies = [ + "ckb-chain-spec 0.3.0", + "ckb-core 0.3.0", + "ckb-db 0.3.0", + "ckb-notify 0.3.0", + "ckb-shared 0.3.0", + "ckb-verification 0.3.0", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -362,11 +362,11 @@ dependencies = [ [[package]] name = "ckb-chain-spec" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ - "ckb-core 0.3.0-pre", - "ckb-pow 0.3.0-pre", - "ckb-protocol 0.3.0-pre", + "ckb-core 0.3.0", + "ckb-pow 0.3.0", + "ckb-protocol 0.3.0", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -377,16 +377,16 @@ dependencies = [ [[package]] name = "ckb-core" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "bit-vec 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-util 0.3.0-pre", + "ckb-util 0.3.0", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "crypto 0.3.0-pre", + "crypto 0.3.0", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.3.0-pre", - "merkle-root 0.3.0-pre", + "hash 0.3.0", + "merkle-root 0.3.0", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)", @@ -395,10 +395,10 @@ dependencies = [ [[package]] name = "ckb-db" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-util 0.3.0-pre", + "ckb-util 0.3.0", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.10.0 (git+https://github.com/nervosnetwork/rust-rocksdb)", "tempfile 3.0.5 (registry+https://github.com/rust-lang/crates.io-index)", @@ -406,25 +406,25 @@ dependencies = [ [[package]] name = "ckb-instrument" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ - "ckb-chain 0.3.0-pre", - "ckb-core 0.3.0-pre", - "ckb-shared 0.3.0-pre", + "ckb-chain 0.3.0", + "ckb-core 0.3.0", + "ckb-shared 0.3.0", "indicatif 0.10.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ckb-miner" -version = "0.3.0-pre" -dependencies = [ - "ckb-core 0.3.0-pre", - "ckb-notify 0.3.0-pre", - "ckb-pool 0.3.0-pre", - "ckb-pow 0.3.0-pre", - "ckb-shared 0.3.0-pre", - "ckb-util 0.3.0-pre", +version = "0.3.0" +dependencies = [ + "ckb-core 0.3.0", + "ckb-notify 0.3.0", + "ckb-pool 0.3.0", + "ckb-pow 0.3.0", + "ckb-shared 0.3.0", + "ckb-util 0.3.0", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -439,10 +439,10 @@ dependencies = [ [[package]] name = "ckb-network" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "bytes 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-util 0.3.0-pre", + "ckb-util 0.3.0", "faketime 0.2.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.25 (registry+https://github.com/rust-lang/crates.io-index)", @@ -458,9 +458,9 @@ dependencies = [ [[package]] name = "ckb-notify" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ - "ckb-core 0.3.0-pre", + "ckb-core 0.3.0", "crossbeam-channel 0.3.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)", @@ -468,20 +468,20 @@ dependencies = [ [[package]] name = "ckb-pool" -version = "0.3.0-pre" -dependencies = [ - "ckb-chain 0.3.0-pre", - "ckb-chain-spec 0.3.0-pre", - "ckb-core 0.3.0-pre", - "ckb-db 0.3.0-pre", - "ckb-notify 0.3.0-pre", - "ckb-shared 0.3.0-pre", - "ckb-verification 0.3.0-pre", +version = "0.3.0" +dependencies = [ + "ckb-chain 0.3.0", + "ckb-chain-spec 0.3.0", + "ckb-core 0.3.0", + "ckb-db 0.3.0", + "ckb-notify 0.3.0", + "ckb-shared 0.3.0", + "ckb-verification 0.3.0", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.3.0-pre", + "hash 0.3.0", "linked-hash-map 0.5.1 (git+https://github.com/nervosnetwork/linked-hash-map?rev=df27f21)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", @@ -492,12 +492,12 @@ dependencies = [ [[package]] name = "ckb-pow" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.3.0-pre", + "ckb-core 0.3.0", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.3.0-pre", + "hash 0.3.0", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -507,13 +507,13 @@ dependencies = [ [[package]] name = "ckb-protocol" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.3.0-pre", - "ckb-util 0.3.0-pre", + "ckb-core 0.3.0", + "ckb-util 0.3.0", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.3.0-pre", + "hash 0.3.0", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -522,19 +522,19 @@ dependencies = [ [[package]] name = "ckb-rpc" -version = "0.3.0-pre" -dependencies = [ - "ckb-chain 0.3.0-pre", - "ckb-core 0.3.0-pre", - "ckb-db 0.3.0-pre", - "ckb-miner 0.3.0-pre", - "ckb-network 0.3.0-pre", - "ckb-pool 0.3.0-pre", - "ckb-pow 0.3.0-pre", - "ckb-protocol 0.3.0-pre", - "ckb-shared 0.3.0-pre", - "ckb-sync 0.3.0-pre", - "ckb-verification 0.3.0-pre", +version = "0.3.0" +dependencies = [ + "ckb-chain 0.3.0", + "ckb-core 0.3.0", + "ckb-db 0.3.0", + "ckb-miner 0.3.0", + "ckb-network 0.3.0", + "ckb-pool 0.3.0", + "ckb-pow 0.3.0", + "ckb-protocol 0.3.0", + "ckb-shared 0.3.0", + "ckb-sync 0.3.0", + "ckb-verification 0.3.0", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-http-server 9.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -550,17 +550,17 @@ dependencies = [ [[package]] name = "ckb-script" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-core 0.3.0-pre", - "ckb-protocol 0.3.0-pre", + "ckb-core 0.3.0", + "ckb-protocol 0.3.0", "ckb-vm 0.1.0 (git+https://github.com/nervosnetwork/ckb-vm?rev=1622ba0)", - "crypto 0.3.0-pre", + "crypto 0.3.0", "faster-hex 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "flatbuffers 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.3.0-pre", + "hash 0.3.0", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -568,14 +568,14 @@ dependencies = [ [[package]] name = "ckb-shared" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ - "avl-merkle 0.3.0-pre", + "avl-merkle 0.3.0", "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-chain-spec 0.3.0-pre", - "ckb-core 0.3.0-pre", - "ckb-db 0.3.0-pre", - "ckb-util 0.3.0-pre", + "ckb-chain-spec 0.3.0", + "ckb-core 0.3.0", + "ckb-db 0.3.0", + "ckb-util 0.3.0", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "lru-cache 0.1.0 (git+https://github.com/nervosnetwork/lru-cache)", @@ -589,20 +589,20 @@ dependencies = [ [[package]] name = "ckb-sync" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", - "ckb-chain 0.3.0-pre", - "ckb-chain-spec 0.3.0-pre", - "ckb-core 0.3.0-pre", - "ckb-db 0.3.0-pre", - "ckb-network 0.3.0-pre", - "ckb-notify 0.3.0-pre", - "ckb-pool 0.3.0-pre", - "ckb-protocol 0.3.0-pre", - "ckb-shared 0.3.0-pre", - "ckb-util 0.3.0-pre", - "ckb-verification 0.3.0-pre", + "ckb-chain 0.3.0", + "ckb-chain-spec 0.3.0", + "ckb-core 0.3.0", + "ckb-db 0.3.0", + "ckb-network 0.3.0", + "ckb-notify 0.3.0", + "ckb-pool 0.3.0", + "ckb-protocol 0.3.0", + "ckb-shared 0.3.0", + "ckb-util 0.3.0", + "ckb-verification 0.3.0", "crossbeam-channel 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -617,27 +617,27 @@ dependencies = [ [[package]] name = "ckb-util" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "ckb-verification" -version = "0.3.0-pre" -dependencies = [ - "ckb-chain 0.3.0-pre", - "ckb-chain-spec 0.3.0-pre", - "ckb-core 0.3.0-pre", - "ckb-db 0.3.0-pre", - "ckb-notify 0.3.0-pre", - "ckb-pow 0.3.0-pre", - "ckb-script 0.3.0-pre", - "ckb-shared 0.3.0-pre", +version = "0.3.0" +dependencies = [ + "ckb-chain 0.3.0", + "ckb-chain-spec 0.3.0", + "ckb-core 0.3.0", + "ckb-db 0.3.0", + "ckb-notify 0.3.0", + "ckb-pow 0.3.0", + "ckb-script 0.3.0", + "ckb-shared 0.3.0", "faketime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "hash 0.3.0-pre", - "merkle-root 0.3.0-pre", + "hash 0.3.0", + "merkle-root 0.3.0", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "numext-fixed-uint 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -879,7 +879,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "crypto" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "crunchy 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -939,7 +939,7 @@ dependencies = [ [[package]] name = "dir" -version = "0.3.0-pre" +version = "0.3.0" [[package]] name = "either" @@ -1149,7 +1149,7 @@ dependencies = [ [[package]] name = "hash" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1761,7 +1761,7 @@ dependencies = [ [[package]] name = "logger" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1819,9 +1819,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "merkle-root" -version = "0.3.0-pre" +version = "0.3.0" dependencies = [ - "hash 0.3.0-pre", + "hash 0.3.0", "numext-fixed-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] diff --git a/Cargo.toml b/Cargo.toml index a5ef3831a7..94f73ab7fc 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/benches/Cargo.toml b/benches/Cargo.toml index c86ce0bfd8..feb28d7bf8 100644 --- a/benches/Cargo.toml +++ b/benches/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-benches" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/chain/Cargo.toml b/chain/Cargo.toml index ad3bee3f8a..f134046cdb 100644 --- a/chain/Cargo.toml +++ b/chain/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-chain" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/core/Cargo.toml b/core/Cargo.toml index a2b6f8a57e..7748a7a96e 100644 --- a/core/Cargo.toml +++ b/core/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-core" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/db/Cargo.toml b/db/Cargo.toml index 90996ca453..ea3ee7e4a9 100644 --- a/db/Cargo.toml +++ b/db/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-db" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/miner/Cargo.toml b/miner/Cargo.toml index 0d409b7abb..669cd5fe0f 100644 --- a/miner/Cargo.toml +++ b/miner/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-miner" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/network/Cargo.toml b/network/Cargo.toml index 74f3e5cb88..31727a9a31 100644 --- a/network/Cargo.toml +++ b/network/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-network" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/notify/Cargo.toml b/notify/Cargo.toml index 031f18cd35..13eab3707f 100644 --- a/notify/Cargo.toml +++ b/notify/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-notify" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/pool/Cargo.toml b/pool/Cargo.toml index f380a3b69f..5f64010536 100644 --- a/pool/Cargo.toml +++ b/pool/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-pool" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/pow/Cargo.toml b/pow/Cargo.toml index 72c21da3c3..9303172846 100644 --- a/pow/Cargo.toml +++ b/pow/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-pow" -version = "0.3.0-pre" +version = "0.3.0" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/protocol/Cargo.toml b/protocol/Cargo.toml index f0a283c988..57661091ce 100644 --- a/protocol/Cargo.toml +++ b/protocol/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-protocol" -version = "0.3.0-pre" +version = "0.3.0" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/rpc/Cargo.toml b/rpc/Cargo.toml index d183cfe8e3..f6860f3459 100644 --- a/rpc/Cargo.toml +++ b/rpc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-rpc" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/script/Cargo.toml b/script/Cargo.toml index 10248bba8c..ad022549ea 100644 --- a/script/Cargo.toml +++ b/script/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-script" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/shared/Cargo.toml b/shared/Cargo.toml index a7264ad65a..9ae0982a9d 100644 --- a/shared/Cargo.toml +++ b/shared/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-shared" -version = "0.3.0-pre" +version = "0.3.0" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/spec/Cargo.toml b/spec/Cargo.toml index b35a8ca91a..c9c297d161 100644 --- a/spec/Cargo.toml +++ b/spec/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-chain-spec" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/sync/Cargo.toml b/sync/Cargo.toml index 40786d5d51..3b3ae9cb4d 100644 --- a/sync/Cargo.toml +++ b/sync/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-sync" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/Cargo.toml b/util/Cargo.toml index 88e58f376f..8a62d59c13 100644 --- a/util/Cargo.toml +++ b/util/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-util" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/avl/Cargo.toml b/util/avl/Cargo.toml index 87dc568e5b..5538e15cf3 100644 --- a/util/avl/Cargo.toml +++ b/util/avl/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "avl-merkle" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/build-info/Cargo.toml b/util/build-info/Cargo.toml index b129bfb4a4..675900f6a2 100644 --- a/util/build-info/Cargo.toml +++ b/util/build-info/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "build-info" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/crypto/Cargo.toml b/util/crypto/Cargo.toml index e68eb88d78..0fb0a3d388 100644 --- a/util/crypto/Cargo.toml +++ b/util/crypto/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "crypto" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/dir/Cargo.toml b/util/dir/Cargo.toml index 86f204ddd4..6541f13e30 100644 --- a/util/dir/Cargo.toml +++ b/util/dir/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "dir" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/hash/Cargo.toml b/util/hash/Cargo.toml index 1181a06f3f..8a1d252559 100644 --- a/util/hash/Cargo.toml +++ b/util/hash/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "hash" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/instrument/Cargo.toml b/util/instrument/Cargo.toml index 6c4671b7c5..f10a766131 100644 --- a/util/instrument/Cargo.toml +++ b/util/instrument/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-instrument" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/util/logger/Cargo.toml b/util/logger/Cargo.toml index 38112e4a46..afa74b903f 100644 --- a/util/logger/Cargo.toml +++ b/util/logger/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "logger" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos "] edition = "2018" diff --git a/util/merkle-root/Cargo.toml b/util/merkle-root/Cargo.toml index 40bde4a60b..35e746aa1a 100644 --- a/util/merkle-root/Cargo.toml +++ b/util/merkle-root/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "merkle-root" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" diff --git a/verification/Cargo.toml b/verification/Cargo.toml index 681dd9f502..734a095cd4 100644 --- a/verification/Cargo.toml +++ b/verification/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "ckb-verification" -version = "0.3.0-pre" +version = "0.3.0" license = "MIT" authors = ["Nervos Core Dev "] edition = "2018" From 53e281b7f74e30d1e137909da62fc50ce69f45bb Mon Sep 17 00:00:00 2001 From: ian Date: Tue, 25 Dec 2018 14:15:44 +0800 Subject: [PATCH 45/45] fixup! chore: CHANGELOG for v0.3.0 --- CHANGELOG.md | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index be63bd3712..977898a966 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,35 +7,35 @@ See [Conventional Commits](https://conventionalcommits.org) for commit guideline ### Bug Fixes -* **config:** boot\_nodes -> bootnodes ([aad811c](https://github.com/nervosnetwork/ckb/commit/aad811c)) -* add `tests/peers_registry` ([9616a18](https://github.com/nervosnetwork/ckb/commit/9616a18)) -* assign numeric numbers for syscall parameters ([3af9535](https://github.com/nervosnetwork/ckb/commit/3af9535)) +* **consensus**: resolve mining old block issue ([#87](https://github.com/nervosnetwork/ckb/issues/87)) ([e5da1ae](https://github.com/nervosnetwork/ckb/commit/e5da1ae)) +* **p2p framework**: use new strategy to evict inbound peer ([95451e7](https://github.com/nervosnetwork/ckb/commit/95451e7)) +* **p2p protocol**: fix calculation of headers sync timeout ([06a5e29](https://github.com/nervosnetwork/ckb/commit/06a5e29)) +* **p2p protocol**: sync header verification ([366f077](https://github.com/nervosnetwork/ckb/commit/366f077)) +* **scripting**: regulate parameters used in syscalls ([09e7cc7](https://github.com/nervosnetwork/ckb/commit/09e7cc7)) * cli panic ([c55e076](https://github.com/nervosnetwork/ckb/commit/c55e076)) * cli subcommand setting ([bdf323f](https://github.com/nervosnetwork/ckb/commit/bdf323f)) -* fix calculation of headers sync timeout ([06a5e29](https://github.com/nervosnetwork/ckb/commit/06a5e29)) -* regulate parameters used in syscalls ([09e7cc7](https://github.com/nervosnetwork/ckb/commit/09e7cc7)) -* resolve mining old block issue ([#87](https://github.com/nervosnetwork/ckb/issues/87)) ([e5da1ae](https://github.com/nervosnetwork/ckb/commit/e5da1ae)) -* sync header verify ([366f077](https://github.com/nervosnetwork/ckb/commit/366f077)) * uncheck subtract overflow ([#88](https://github.com/nervosnetwork/ckb/issues/88)) ([36b541f](https://github.com/nervosnetwork/ckb/commit/36b541f)) -* use new strategy to evict inbound peer ([95451e7](https://github.com/nervosnetwork/ckb/commit/95451e7)) - ### Features -* add `DATA_HASH` field type in Load Cell By Field ([2d0a378](https://github.com/nervosnetwork/ckb/commit/2d0a378)) -* add dep cell loading support in syscalls ([cae937f](https://github.com/nervosnetwork/ckb/commit/cae937f)) -* impl NetworkGroup for peer and multiaddr ([e1e5750](https://github.com/nervosnetwork/ckb/commit/e1e5750)) -* jsonrpc API modules ([f87d9a1](https://github.com/nervosnetwork/ckb/commit/f87d9a1)) -* try evict inbound peers when inbound slots is full ([d0db77e](https://github.com/nervosnetwork/ckb/commit/d0db77e)) -* use crate faketime to fake time ([#111](https://github.com/nervosnetwork/ckb/issues/111)) ([5adfd82](https://github.com/nervosnetwork/ckb/commit/5adfd82)) -* peerStore implement scoring interface ([d160d1e](https://github.com/nervosnetwork/ckb/commit/d160d1e)) -* rename outpoint to out\_point as its type is OutPoint (#93) ([3abf2b1](https://github.com/nervosnetwork/ckb/commit/3abf2b1))) -* use serialized flatbuffer format in referenced cell ([49fc513](https://github.com/nervosnetwork/ckb/commit/49fc513)) +* **cell model**: rename outpoint to out\_point as its type is OutPoint (#93) ([3abf2b1](https://github.com/nervosnetwork/ckb/commit/3abf2b1))) +* **p2p framework**: add peers registry for tests([9616a18](https://github.com/nervosnetwork/ckb/commit/9616a18)) +* **p2p framework**: impl NetworkGroup for peer and multiaddr ([e1e5750](https://github.com/nervosnetwork/ckb/commit/e1e5750)) +* **p2p framework**: peerStore implements scoring interface ([d160d1e](https://github.com/nervosnetwork/ckb/commit/d160d1e)) +* **p2p framework**: try evict inbound peers when inbound slots is full ([d0db77e](https://github.com/nervosnetwork/ckb/commit/d0db77e)) +* **peripheral**: jsonrpc API modules ([f87d9a1](https://github.com/nervosnetwork/ckb/commit/f87d9a1)) +* **peripheral**: use crate faketime to fake time ([#111](https://github.com/nervosnetwork/ckb/issues/111)) ([5adfd82](https://github.com/nervosnetwork/ckb/commit/5adfd82)) +* **scripting**: add `DATA_HASH` field type in syscall *Load Cell By Field* ([2d0a378](https://github.com/nervosnetwork/ckb/commit/2d0a378)) +* **scripting**: add dep cell loading support in syscalls ([cae937f](https://github.com/nervosnetwork/ckb/commit/cae937f)) +* **scripting**: assign numeric numbers for syscall parameters ([3af9535](https://github.com/nervosnetwork/ckb/commit/3af9535)) +* **scripting**: use serialized flatbuffer format in referenced cell ([49fc513](https://github.com/nervosnetwork/ckb/commit/49fc513)) ### BREAKING CHANGES * In P2P and RPC, field `outpoint` is renamed to `out_point`. +* Config has changed, please see the + [diff](https://github.com/nervosnetwork/ckb/compare/v0.2.0...9faa91a#diff-315cb39dece2d25661200bb13db8458c). # [v0.2.0](https://github.com/nervosnetwork/ckb/compare/v0.1.0...v0.2.0) (2018-12-17)