diff --git a/Cargo.lock b/Cargo.lock index b4e5117..fb734b1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -817,7 +817,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "fork-tree" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1007,6 +1007,11 @@ name = "hex" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "hex" +version = "0.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "hex-literal" version = "0.1.4" @@ -3318,7 +3323,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "sr-api-macros" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3330,7 +3335,7 @@ dependencies = [ [[package]] name = "sr-io" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3347,7 +3352,7 @@ dependencies = [ [[package]] name = "sr-primitives" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "integer-sqrt 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3362,7 +3367,7 @@ dependencies = [ [[package]] name = "sr-std" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -3370,7 +3375,7 @@ dependencies = [ [[package]] name = "sr-version" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "impl-serde 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3382,7 +3387,7 @@ dependencies = [ [[package]] name = "srml-consensus" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3398,7 +3403,7 @@ dependencies = [ [[package]] name = "srml-executive" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3430,7 +3435,7 @@ dependencies = [ [[package]] name = "srml-indices" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3449,7 +3454,7 @@ dependencies = [ [[package]] name = "srml-metadata" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3460,7 +3465,7 @@ dependencies = [ [[package]] name = "srml-session" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3478,7 +3483,7 @@ dependencies = [ [[package]] name = "srml-support" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "bitmask 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3497,7 +3502,7 @@ dependencies = [ [[package]] name = "srml-support-procedural" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3509,7 +3514,7 @@ dependencies = [ [[package]] name = "srml-support-procedural-tools" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "proc-macro-crate 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3521,7 +3526,7 @@ dependencies = [ [[package]] name = "srml-support-procedural-tools-derive" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "proc-macro2 0.4.30 (registry+https://github.com/rust-lang/crates.io-index)", "quote 0.6.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3531,7 +3536,7 @@ dependencies = [ [[package]] name = "srml-system" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3547,7 +3552,7 @@ dependencies = [ [[package]] name = "srml-timestamp" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3679,7 +3684,7 @@ dependencies = [ [[package]] name = "substrate-basic-authorship" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3707,7 +3712,7 @@ dependencies = [ [[package]] name = "substrate-cli" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", "app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3741,7 +3746,7 @@ dependencies = [ [[package]] name = "substrate-client" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3771,7 +3776,7 @@ dependencies = [ [[package]] name = "substrate-client-db" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)", @@ -3794,7 +3799,7 @@ dependencies = [ [[package]] name = "substrate-consensus-aura-primitives" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "sr-primitives 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", "substrate-client 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", @@ -3803,7 +3808,7 @@ dependencies = [ [[package]] name = "substrate-consensus-authorities" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "sr-io 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", @@ -3818,7 +3823,7 @@ dependencies = [ [[package]] name = "substrate-consensus-common" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3838,7 +3843,7 @@ dependencies = [ [[package]] name = "substrate-executor" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3861,7 +3866,7 @@ dependencies = [ [[package]] name = "substrate-inherents" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3872,7 +3877,7 @@ dependencies = [ [[package]] name = "substrate-keyring" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3884,7 +3889,7 @@ dependencies = [ [[package]] name = "substrate-keystore" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3898,7 +3903,7 @@ dependencies = [ [[package]] name = "substrate-network" version = "0.1.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-channel 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3927,7 +3932,7 @@ dependencies = [ [[package]] name = "substrate-network-libp2p" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "byteorder 1.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3953,7 +3958,7 @@ dependencies = [ [[package]] name = "substrate-offchain" version = "0.1.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3971,7 +3976,7 @@ dependencies = [ [[package]] name = "substrate-offchain-primitives" version = "0.1.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "sr-primitives 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", "substrate-client 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", @@ -3980,7 +3985,7 @@ dependencies = [ [[package]] name = "substrate-panic-handler" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "backtrace 0.3.31 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3989,7 +3994,7 @@ dependencies = [ [[package]] name = "substrate-peerset" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "libp2p 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4002,7 +4007,7 @@ dependencies = [ [[package]] name = "substrate-primitives" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4032,7 +4037,7 @@ dependencies = [ [[package]] name = "substrate-rpc" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4057,7 +4062,7 @@ dependencies = [ [[package]] name = "substrate-rpc-servers" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "jsonrpc-http-server 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-pubsub 10.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4071,7 +4076,7 @@ dependencies = [ [[package]] name = "substrate-serializer" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.39 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4080,7 +4085,7 @@ dependencies = [ [[package]] name = "substrate-service" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4113,7 +4118,7 @@ dependencies = [ [[package]] name = "substrate-state-db" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4124,7 +4129,7 @@ dependencies = [ [[package]] name = "substrate-state-machine" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4142,7 +4147,7 @@ dependencies = [ [[package]] name = "substrate-telemetry" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4159,7 +4164,7 @@ dependencies = [ [[package]] name = "substrate-test-client" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4177,7 +4182,7 @@ dependencies = [ [[package]] name = "substrate-test-runtime" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4202,7 +4207,7 @@ dependencies = [ [[package]] name = "substrate-transaction-graph" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4217,7 +4222,7 @@ dependencies = [ [[package]] name = "substrate-transaction-pool" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", @@ -4233,7 +4238,7 @@ dependencies = [ [[package]] name = "substrate-trie" version = "1.0.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "hash-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", "memory-db 0.12.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5162,7 +5167,7 @@ dependencies = [ [[package]] name = "yee" -version = "1.1.1" +version = "1.2.0" dependencies = [ "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5200,12 +5205,16 @@ name = "yee-cli" version = "0.4.0" dependencies = [ "ansi_term 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", + "app_dirs 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "crfg-primitives 0.4.0", "ctrlc 3.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "exit-future 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "finality-grandpa 0.6.0", "finality-tracker 0.4.0", + "fork-tree 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", + "hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "hyper 0.11.27 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 12.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5324,6 +5333,7 @@ dependencies = [ "fork-tree 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", "futures 0.1.27 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "parity-codec 3.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -5488,13 +5498,14 @@ dependencies = [ "substrate-network 0.1.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", "substrate-peerset 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", "substrate-primitives 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", + "substrate-service 1.0.0 (git+https://github.com/yeeco/substrate.git?branch=yee-v1.0)", "tokio 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "yee-merkle" version = "0.4.0" -source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#d50272d115e433f24ff5543ce4fe6453cee41790" +source = "git+https://github.com/yeeco/substrate.git?branch=yee-v1.0#64d7aad0aa770528561d70bf8be44f7e47618802" dependencies = [ "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", "merkle_light 0.3.1 (git+https://github.com/yeeco/merkle_light.git?branch=yee)", @@ -6032,6 +6043,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" +"checksum hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" "checksum hex-literal 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "ddc2928beef125e519d69ae1baa8c37ea2e0d3848545217f6db0179c5eb1d639" "checksum hex-literal 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "961de220ec9a91af2e1e5bd80d02109155695e516771762381ef8581317066e0" "checksum hex-literal-impl 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "520870c3213943eb8d7803e80180d12a6c7ceb4ae74602544529d1643dc4ddda" diff --git a/Cargo.toml b/Cargo.toml index b24310e..85bf5c1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "yee" -version = "1.1.1" +version = "1.2.0" authors = ["YeeCo "] build = "build.rs" edition = "2018" diff --git a/build.sh b/build.sh index 86b778e..dec859d 100644 --- a/build.sh +++ b/build.sh @@ -1,6 +1,8 @@ #!/usr/bin/env bash set -e - -cp -f prebuilt/yee_runtime/mainnet.wasm runtime/wasm/target/wasm32-unknown-unknown/release/yee_runtime_wasm.compact.wasm - +if [ "$1" == "test" ];then + cp -f prebuilt/yee_runtime/upgrade/mainnet_v5.wasm runtime/wasm/target/wasm32-unknown-unknown/release/yee_runtime_wasm.compact.wasm +else + cp -f prebuilt/yee_runtime/mainnet.wasm runtime/wasm/target/wasm32-unknown-unknown/release/yee_runtime_wasm.compact.wasm +fi cargo build --release diff --git a/cli/Cargo.toml b/cli/Cargo.toml index d6b2813..f0405b5 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -7,6 +7,7 @@ license = "GPL-3.0" [dependencies] hyper = "0.11" +app_dirs = "1.2" tokio-proto = "0.1" serde = "1.0" serde_json = "1.0" @@ -27,6 +28,7 @@ tokio = "0.1" exit-future = "0.1" parking_lot = "0.7.1" hex-literal = "0.1" +hex = "0.4.2" parity-codec = "3.2" trie-root = "0.12.0" yee-runtime = { path = "../runtime" } @@ -46,6 +48,7 @@ runtime_primitives = { package = "sr-primitives", git = "https://github.com/yeec state_machine = { package = "substrate-state-machine", git = "https://github.com/yeeco/substrate.git", branch = "yee-v1.0" } fg_primitives = { package = "crfg-primitives", path = "../core/crfg/primitives" } crfg = { package = "yee-crfg", path = "../core/crfg" } +finality-grandpa = { package = "finality-grandpa", path = "../core/finality-grandpa" } structopt = "0.2" ansi_term = "0.11" yee-switch = { package = "yee-switch", path = "../switch" } @@ -64,6 +67,7 @@ foreign_chain = { package = "yee-foreign-chain", path = "../foreign/chain" } signal-hook = { version = "0.1.11", features = ["tokio-support"] } yee-context = { package = "yee-context", path = "../core/context" } finality-tracker = { package = "finality-tracker", path = "../core/finality-tracker" } +fork-tree = { git = "https://github.com/yeeco/substrate.git", branch = "yee-v1.0"} [features] custom-wasm-code = [] diff --git a/cli/src/chain_revert.rs b/cli/src/chain_revert.rs new file mode 100644 index 0000000..7521a6b --- /dev/null +++ b/cli/src/chain_revert.rs @@ -0,0 +1,240 @@ +use std::io; +use std::path::{Path, PathBuf}; + +use app_dirs::{AppDataType, AppInfo}; +use log::info; +use parity_codec::{Decode, Encode}; +use parity_codec::alloc::collections::HashMap; +use primitives::{H256, ed25519::Public as AuthorityId}; +use runtime_primitives::generic::{BlockId, DigestItem}; +use runtime_primitives::traits::{Block as BlockT, Digest, DigestItemFor, Header as HeaderT, NumberFor}; +use runtime_primitives::traits::As; +use serde_json::Value; +use structopt::StructOpt; +use substrate_cli::SharedParams; +use substrate_cli::VersionInfo; +use substrate_client::backend::AuxStore; +use substrate_service::{ChainSpec, Configuration, FactoryFullConfiguration, FactoryGenesis, new_full_client, new_light_client, RuntimeGenesis, ServiceFactory}; +use fork_tree::ForkTree; +use crfg::{authorities, aux_schema, CrfgChangeDigestItem, ScheduledChange}; +use finality_grandpa::round::State; +use yee_foreign_network::message::generic::Message::Status; + +use crate::chain_spec; +use crate::error; + +/// The `revert` command used revert the chain to a previos state. +#[derive(Debug, StructOpt, Clone)] +pub struct RevertCmd { + /// Specify shard number + #[structopt(long = "shard-num", value_name = "SHARD_NUM")] + pub shard_num: u16, + + /// Number of blocks to revert. + #[structopt(long = "target", value_name = "TARGET")] + pub target: String, + + #[allow(missing_docs)] + #[structopt(flatten)] + pub shared_params: SharedParams, +} + +impl substrate_cli::GetLogFilter for RevertCmd { + fn get_log_filter(&self) -> Option { + None + } +} + +pub fn revert_chain(cli: RevertCmd, version: VersionInfo, spec_factory: S) -> error::Result<()> where + F: ServiceFactory, + S: FnOnce(&str) -> Result>>, String>, + u64: From<<::Header as HeaderT>::Number>, + <<<::Block as BlockT>::Header as HeaderT>::Digest as Digest>::Item: CrfgChangeDigestItem<<<::Block as BlockT>::Header as HeaderT>::Number>, +{ + let target = match serde_json::from_str(cli.target.as_str()) { + Ok(v) => { + let r: HashMap = v; + r + } + _ => { + panic!("Args: target format error."); + } + }; + let (spec_id, mut config) = create_config::(spec_factory, &cli.shared_params, &version); + + let base_path = base_path(&cli.shared_params, &version); + for (shard, number) in target { + let empty: Vec = vec![]; + let empty = empty.encode(); + if shard == cli.shard_num { + config.database_path = db_path(&base_path, spec_id.as_str(), true, shard).to_string_lossy().into(); + let client = new_full_client::(&config)?; + let best: <::Header as HeaderT>::Number = match client.best_block_header() { + Ok(h) => *h.number(), + Err(e) => panic!("{:?}", e) + }; + if number > best.into() { + info!("Shard#{}. Target({}) > Best({})", shard, number, best); + continue; + } + let best = client.revert(As::sa(number))?; + let header = client.header(&BlockId::Number(best))?.expect("can't get header"); + let hash = header.hash(); + + let authorities = match get_authorities::(header, number) { + Ok(v) => v, + Err(e) => panic!("{:?}", e) + }; + client.insert_aux(&[(aux_schema::AUTHORITY_SET_KEY, authorities.encode().as_slice())], &[])?; + + let state = State { + prevote_ghost: Some((hash, number)), + finalized: Some((hash, number)), + estimate: Some((hash, number)), + completable: true, + }; + let set_state = aux_schema::VoterSetState::Live(0u64, state).encode(); + client.insert_aux(&[(aux_schema::SET_STATE_KEY, set_state.as_slice())], &[])?; + client.insert_aux(&[(aux_schema::CONSENSUS_CHANGES_KEY, empty.as_slice())], &[])?; + client.insert_aux(&[(aux_schema::PENDING_SKIP_KEY, empty.as_slice())], &[])?; + info!("Reverted shard: {}. Best: #{}", shard, best); + } else { + config.database_path = db_path(&base_path, spec_id.as_str(), false, shard).to_string_lossy().into(); + let client = new_light_client::(&config)?; + let best = match client.best_block_header() { + Ok(h) => *h.number(), + Err(e) => panic!("{:?}", e) + }; + if number > best.into() { + info!("Shard#{}. Target({}) > Best({})", shard, number, best); + continue; + } + let best = client.revert(As::sa(number))?; + let header = client.header(&BlockId::Number(best))?.expect("can't get header"); + let hash = header.hash(); + let authorities = match get_authorities::(header, number) { + Ok(v) => v, + Err(e) => panic!("{:?}", e) + }; + client.insert_aux(&[(aux_schema::AUTHORITY_SET_KEY, authorities.encode().as_slice())], &[])?; + let state = State { + prevote_ghost: Some((hash, number)), + finalized: Some((hash, number)), + estimate: Some((hash, number)), + completable: true, + }; + let set_state = aux_schema::VoterSetState::Live(0u64, state); + client.insert_aux(&[(aux_schema::SET_STATE_KEY, set_state.encode().as_slice())], &[])?; + client.insert_aux(&[(aux_schema::CONSENSUS_CHANGES_KEY, empty.as_slice())], &[])?; + client.insert_aux(&[(aux_schema::PENDING_SKIP_KEY, empty.as_slice())], &[])?; + info!("Reverted shard: {}. Best: #{}", shard, best); + } + } + + Ok(()) +} + +fn create_config( + spec_factory: S, cli: &SharedParams, _version: &VersionInfo, +) -> (String, FactoryFullConfiguration) + where + F: ServiceFactory, + S: FnOnce(&str) -> Result>>, String>, +{ + let spec = match load_spec(cli, spec_factory) { + Ok(v) => v, + Err(e) => { + panic!("{:?}", e); + } + }; + + (spec.id().to_string(), Configuration::default_with_spec(spec.clone())) +} + +fn load_spec(cli: &SharedParams, factory: F) -> error::Result> + where G: RuntimeGenesis, F: FnOnce(&str) -> Result>, String>, +{ + let chain_key = get_chain_key(cli); + let spec = match factory(&chain_key)? { + Some(spec) => spec, + None => ChainSpec::from_json_file(PathBuf::from(chain_key))? + }; + Ok(spec) +} + +fn base_path(cli: &SharedParams, version: &VersionInfo) -> PathBuf { + cli.base_path.clone() + .unwrap_or_else(|| + app_dirs::get_app_root( + AppDataType::UserData, + &AppInfo { + name: version.executable_name, + author: version.author, + }, + ).expect("app directories exist on all supported platforms; qed") + ) +} + +fn get_chain_key(cli: &SharedParams) -> String { + match cli.chain { + Some(ref chain) => chain.clone(), + None => if cli.dev { "dev".into() } else { "".into() } + } +} + +fn db_path(base_path: &Path, chain_id: &str, is_full: bool, shard_num: u16) -> PathBuf { + let mut path = base_path.to_owned(); + path.push("chains"); + path.push(chain_id); + if is_full { + path.push("db"); + } else { + path.push(format!("db-{}", shard_num)); + } + path +} + +type Hash = [u8; 32]; + +fn get_authorities(header: B::Header, number: u64) -> Result, String> +where + DigestItemFor: CrfgChangeDigestItem>, + <<::Header as HeaderT>::Digest as Digest>::Item: CrfgChangeDigestItem<<::Header as HeaderT>::Number>, +{ + let change: Option::Number>> = header.digest().logs().iter() + .filter_map(CrfgChangeDigestItem::as_change) + .next(); + + match change { + Some(v) => { + let authorities = aggregate_authorities(v.next_authorities); + let mut authority_set = authorities::AuthoritySet:: { + current_authorities: authorities, + set_id: number, + pending_standard_changes: ForkTree::new(), + pending_forced_changes: Vec::new(), + }; + authority_set.pending_standard_changes.best_finalized_number = Some(number); + Ok(authority_set) + } + None => Err(String::from("can't get ScheduledChange")) + } +} + +fn aggregate_authorities(authorities: Vec<(AuthorityId, u64)>) -> Vec<(AuthorityId, u64)> { + let mut polymer: Vec<(AuthorityId, u64)> = Vec::new(); + + for author in authorities { + match polymer.iter().position(|x| x.0 == author.0){ + Some(pos) => { + let reappear = polymer.get_mut(pos); + reappear.unwrap().1 += 1; + }, + None => { + polymer.push((author.0, author.1)); + } + } + } + + polymer +} \ No newline at end of file diff --git a/cli/src/custom_command.rs b/cli/src/custom_command.rs index 4371546..7e3f161 100644 --- a/cli/src/custom_command.rs +++ b/cli/src/custom_command.rs @@ -21,12 +21,17 @@ use structopt::{StructOpt, clap::{SubCommand}}; use yee_switch; use yee_bootnodes_router; use substrate_cli::VersionInfo; +use substrate_service::{ChainSpec, FactoryGenesis, ServiceFactory}; +use crate::chain_revert::{RevertCmd, revert_chain}; +use runtime_primitives::traits::{Block as BlockT, Digest, DigestItemFor, Header as HeaderT, NumberFor}; +use crfg::{aux_schema, authorities, CrfgChangeDigestItem, ScheduledChange}; //use yee_switch::SwitchCommandCmd; #[derive(Clone, Debug)] pub enum CustomCommand { SwitchCommandCmd(yee_switch::params::SwitchCommandCmd), BootnodesRouterCommandCmd(yee_bootnodes_router::params::BootnodesRouterCommandCmd), + Revert(RevertCmd), None, } @@ -39,6 +44,10 @@ impl StructOpt for CustomCommand { .subcommand( yee_bootnodes_router::params::BootnodesRouterCommandCmd::augment_clap(SubCommand::with_name("bootnodes-router")) .about("Yee bootnodes router")) + .subcommand( + RevertCmd::augment_clap(SubCommand::with_name("revert")) + .about("Yee revert block") + ) } fn from_clap(matches: &::structopt::clap::ArgMatches) -> Self { @@ -47,6 +56,8 @@ impl StructOpt for CustomCommand { CustomCommand::SwitchCommandCmd(yee_switch::params::SwitchCommandCmd::from_clap(matches)), ("bootnodes-router", Some(matches)) => CustomCommand::BootnodesRouterCommandCmd(yee_bootnodes_router::params::BootnodesRouterCommandCmd::from_clap(matches)), + ("revert", Some(matches)) => + CustomCommand::Revert(RevertCmd::from_clap(matches)), (_, Some(_)) => CustomCommand::None, (_, None) => CustomCommand::None, } @@ -58,17 +69,24 @@ impl GetLogFilter for CustomCommand { match self { CustomCommand::SwitchCommandCmd(cmd) => cmd.get_log_filter(), CustomCommand::BootnodesRouterCommandCmd(cmd) => cmd.get_log_filter(), + CustomCommand::Revert(cmd) => cmd.get_log_filter(), CustomCommand::None => None } } } -pub fn run_custom_command(params : Option<(CustomCommand, S, E, VersionInfo)>) -> substrate_cli::error::Result<()> { +pub fn run_custom_command(params : Option<(CustomCommand, S, E, VersionInfo)>) -> substrate_cli::error::Result<()> where + F: ServiceFactory, + S: FnOnce(&str) -> Result>>, String>, + u64: From<<::Header as HeaderT>::Number>, + <<<::Block as BlockT>::Header as HeaderT>::Digest as Digest>::Item: CrfgChangeDigestItem<<<::Block as BlockT>::Header as HeaderT>::Number>, +{ match params{ - Some((custom_command, _spec_factory, _exit, version))=> match custom_command{ + Some((custom_command, spec_factory, _exit, version))=> match custom_command{ CustomCommand::SwitchCommandCmd(cmd) => Ok(yee_switch::run(cmd, version).map_err(|e| format!("{:?}", e))?), CustomCommand::BootnodesRouterCommandCmd(cmd) => Ok(yee_bootnodes_router::run(cmd, version).map_err(|e| format!("{:?}", e))?), + CustomCommand::Revert(cmd) => Ok(revert_chain::(cmd, version, spec_factory).map_err(|e|format!("{:?}", e))?), CustomCommand::None => Ok(()) }, None => Ok(()) diff --git a/cli/src/custom_param.rs b/cli/src/custom_param.rs index 7002a87..4fdd878 100644 --- a/cli/src/custom_param.rs +++ b/cli/src/custom_param.rs @@ -30,7 +30,7 @@ use substrate_service::{ use substrate_client::ChainHead; use runtime_primitives::{ generic::BlockId, - traits::{ProvideRuntimeApi, Header, Digest as DigestT, DigestItemFor, Zero, Block as BlockT, NumberFor}, + traits::{ProvideRuntimeApi, Header, Digest as DigestT, DigestItemFor, Zero, Block as BlockT, NumberFor, As}, }; use crate::error; use crate::service::{NodeConfig, NativeExecutor}; @@ -96,6 +96,10 @@ pub struct YeeCliConfig { #[structopt(long = "import-until")] pub import_until: Option, + /// Max leading blocks. + #[structopt(long = "import-leading")] + pub import_leading: Option, + /// Pow job cache size #[structopt(long = "job-cache-size")] pub job_cache_size: Option, @@ -216,6 +220,7 @@ where config.custom.foreign_in_peers = custom_args.foreign_in_peers; config.custom.mine = custom_args.mine; config.custom.import_until = get_import_until::(&custom_args.import_until).ok(); + config.custom.import_leading = custom_args.import_leading.map(As::sa); config.custom.job_cache_size = custom_args.job_cache_size; config.custom.context = Some(context); @@ -231,6 +236,7 @@ where info!(" bootnodes router conf: {:?}", config.custom.bootnodes_router_conf); info!(" mine: {:?}", config.custom.mine); info!(" import_until: {:?}", config.custom.import_until); + info!(" import_leading: {:?}", config.custom.import_leading); register_inherent_data_provider(&config.custom.inherent_data_providers, shard_num, shard_count, scale_out) .map_err(|e| format!("Inherent data error: {:?}", e))?; diff --git a/cli/src/lib.rs b/cli/src/lib.rs index fc6d773..670c041 100644 --- a/cli/src/lib.rs +++ b/cli/src/lib.rs @@ -4,6 +4,7 @@ mod custom_param; mod dev_param; mod service; mod chain_spec; +mod chain_revert; pub use crate::service::Factory; pub use crate::service::NodeConfig; diff --git a/cli/src/service.rs b/cli/src/service.rs index e72fe3b..b8bc8ef 100644 --- a/cli/src/service.rs +++ b/cli/src/service.rs @@ -25,7 +25,7 @@ use { consensus_common::import_queue::ImportQueue, foreign_chain::{ForeignChain, ForeignChainConfig}, substrate_service::{ - NetworkProviderParams, FactoryBlock, NetworkProvider, ServiceFactory, ComponentExHash, + NetworkProviderParams, FactoryBlock, NetworkProvider, Network, ServiceFactory, ComponentExHash, }, yee_runtime::{ self, GenesisConfig, opaque::Block, RuntimeApi, @@ -55,7 +55,7 @@ use crfg; use yee_primitives::Hrp; use crate::{CliTriggerExit, CliSignal}; use yee_context::{Context}; -use crfg::CrfgState; +use crfg::CrfgStateProvider; use yee_foreign_network::SyncProvider; use crate::custom_param::NodeKeyParams; @@ -93,9 +93,11 @@ pub struct NodeConfig { pub bootnodes_router_conf: Option, pub job_manager: Arc::Public>>>>>>, pub recommit_relay_sender: Arc::Hash>>>>>, - pub crfg_state: Arc::Hash, NumberFor>>>>, + pub crfg_state_provider: Arc::Hash, NumberFor>>>>>, + pub import_crfg_state_providers: Arc::Hash, NumberFor>>>>>, pub mine: bool, pub import_until: Option>>, + pub import_leading: Option>, pub job_cache_size: Option, pub foreign_chains: Arc>>>, pub foreign_network: Arc>>>>>>, @@ -120,9 +122,11 @@ impl Default for NodeConfig { bootnodes_router_conf: Default::default(), job_manager: Arc::new(RwLock::new(None)), recommit_relay_sender: Arc::new(RwLock::new(None)), - crfg_state: Arc::new(RwLock::new(None)), + crfg_state_provider: Arc::new(RwLock::new(None)), + import_crfg_state_providers: Arc::new(RwLock::new(HashMap::new())), mine: Default::default(), import_until: Default::default(), + import_leading: Default::default(), job_cache_size: Default::default(), foreign_chains: Arc::new(RwLock::new(None)), foreign_network: Arc::new(RwLock::new(None)), @@ -147,20 +151,22 @@ impl Clone for NodeConfig { foreign_node_key_params: self.foreign_node_key_params.clone(), mine: self.mine, import_until: self.import_until.clone(), + import_leading: self.import_leading.clone(), job_cache_size: self.job_cache_size, hrp: self.hrp.clone(), scale_out: self.scale_out.clone(), trigger_exit: self.trigger_exit.clone(), context: self.context.clone(), + job_manager: self.job_manager.clone(), + recommit_relay_sender: self.recommit_relay_sender.clone(), + crfg_state_provider: self.crfg_state_provider.clone(), + import_crfg_state_providers: self.import_crfg_state_providers.clone(), + foreign_chains: self.foreign_chains.clone(), + foreign_network: self.foreign_network.clone(), // cloned config SHALL NOT SHARE some items with original config inherent_data_providers: Default::default(), bootnodes_router_conf: None, - job_manager: Arc::new(RwLock::new(None)), - recommit_relay_sender: Arc::new(RwLock::new(None)), - crfg_state: Arc::new(RwLock::new(None)), - foreign_chains: Arc::new(RwLock::new(None)), - foreign_network: Arc::new(RwLock::new(None)), } } } @@ -190,8 +196,12 @@ impl ProvideRpcExtra::Public>, F::Block, Co self.recommit_relay_sender.clone() } - fn provide_crfg_state(&self) -> Arc::Hash, NumberFor>>>> { - self.crfg_state.clone() + fn provide_crfg_state_provider(&self) -> Arc::Hash, NumberFor>>>>> { + self.crfg_state_provider.clone() + } + + fn provide_import_crfg_state_providers(&self) -> Arc::Hash, NumberFor>>>>>{ + self.import_crfg_state_providers.clone() } fn provide_foreign_network(&self) -> Arc>>>>>> { @@ -202,7 +212,11 @@ impl ProvideRpcExtra::Public>, F::Block, Co let hrp = self.hrp.clone(); let coinbase = self.coinbase.as_ref().map(|x|x.to_address(hrp.clone()).expect("qed").0); let job_cache_size = self.job_cache_size; + let shard_num = self.shard_num; + let shard_count = self.shard_count; let config = Config { + shard_num, + shard_count, coinbase, job_cache_size, }; @@ -233,7 +247,7 @@ impl NetworkProvider for NetworkWrapper where params: NetworkProviderParams, protocol_id: network::ProtocolId, import_queue: Box>>, - ) -> Result>, network::Error> { + ) -> Result<(Arc>, network::NetworkChan>), network::Error> { self.inner.provide_network(network_id, params, protocol_id, import_queue) } } @@ -361,7 +375,7 @@ construct_service_factory! { crfg::NetworkBridge::new(service.network()), service.config.custom.inherent_data_providers.clone(), service.on_exit(), - service.config.custom.crfg_state.clone(), + service.config.custom.crfg_state_provider.clone(), )?); // pow @@ -411,11 +425,13 @@ construct_service_factory! { let validator = config.roles == Roles::AUTHORITY; let shard_num = config.custom.shard_num; let import_until = config.custom.import_until.as_ref().and_then(|x| x.get(&shard_num).cloned()); + let import_leading = config.custom.import_leading; let (block_import, link_half) = crfg::block_import::<_, _, _, RuntimeApi, FullClient>( - client.clone(), client.clone(), validator, import_until, + client.clone(), client.clone(), validator, import_until, import_leading, config.chain_spec.id().to_string(), config.custom.shard_num, + config.custom.import_crfg_state_providers.clone(), )?; let block_import = Arc::new(block_import); @@ -449,11 +465,13 @@ construct_service_factory! { let shard_num = config.custom.shard_num; let import_until = config.custom.import_until.as_ref().and_then(|x| x.get(&shard_num).cloned()); + let import_leading = config.custom.import_leading; let (block_import, _) = crfg::block_import::<_, _, _, RuntimeApi, LightClient>( - client.clone(), client.clone(), false, import_until, + client.clone(), client.clone(), false, import_until, import_leading, config.chain_spec.id().to_string(), config.custom.shard_num, + config.custom.import_crfg_state_providers.clone(), )?; let block_import = Arc::new(block_import); diff --git a/core/crfg/Cargo.toml b/core/crfg/Cargo.toml index b26d91e..b0aada4 100644 --- a/core/crfg/Cargo.toml +++ b/core/crfg/Cargo.toml @@ -27,6 +27,7 @@ srml-finality-tracker = { package = "srml-finality-tracker", path = "../../srml/ ansi_term = "0.11" yee-consensus-pow = { path = "../consensus/pow"} hex = "0.3.1" +lazy_static = "1.2" [dev-dependencies] consensus_common = { package = "substrate-consensus-common", git = "https://github.com/yeeco/substrate.git", branch = "yee-v1.0" } diff --git a/core/crfg/src/authorities.rs b/core/crfg/src/authorities.rs index 93231a1..8890204 100644 --- a/core/crfg/src/authorities.rs +++ b/core/crfg/src/authorities.rs @@ -29,7 +29,7 @@ use std::fmt::Debug; use std::ops::Add; use std::sync::Arc; -use ed25519::Public as AuthorityId; +pub use ed25519::Public as AuthorityId; /// A shared authority set. pub(crate) struct SharedAuthoritySet { @@ -87,17 +87,17 @@ pub(crate) struct Status { /// A set of authorities. #[derive(Debug, Clone, Encode, Decode, PartialEq)] -pub(crate) struct AuthoritySet { - pub(crate) current_authorities: Vec<(AuthorityId, u64)>, - pub(crate) set_id: u64, +pub struct AuthoritySet { + pub current_authorities: Vec<(AuthorityId, u64)>, + pub set_id: u64, // Tree of pending standard changes across forks. Standard changes are // enacted on finality and must be enacted (i.e. finalized) in-order across // a given branch - pub(crate) pending_standard_changes: ForkTree>, + pub pending_standard_changes: ForkTree>, // Pending forced changes across different forks (at most one per fork). // Forced changes are enacted on block depth (not finality), for this reason // only one forced change should exist per fork. - pub(crate) pending_forced_changes: Vec>, + pub pending_forced_changes: Vec>, } impl AuthoritySet @@ -377,7 +377,7 @@ where /// Kinds of delays for pending changes. #[derive(Debug, Clone, Encode, Decode, PartialEq)] -pub(crate) enum DelayKind { +pub enum DelayKind { /// Depth in finalized chain. Finalized, /// Depth in best chain. The median last finalized block is calculated at the time the @@ -390,18 +390,18 @@ pub(crate) enum DelayKind { /// This will be applied when the announcing block is at some depth within /// the finalized or unfinalized chain. #[derive(Debug, Clone, Encode, PartialEq)] -pub(crate) struct PendingChange { +pub struct PendingChange { /// The new authorities and weights to apply. - pub(crate) next_authorities: Vec<(AuthorityId, u64)>, + pub next_authorities: Vec<(AuthorityId, u64)>, /// How deep in the chain the announcing block must be /// before the change is applied. - pub(crate) delay: N, + pub delay: N, /// The announcing block's height. - pub(crate) canon_height: N, + pub canon_height: N, /// The announcing block's hash. - pub(crate) canon_hash: H, + pub canon_hash: H, /// The delay kind. - pub(crate) delay_kind: DelayKind, + pub delay_kind: DelayKind, } impl Decode for PendingChange { diff --git a/core/crfg/src/aux_schema.rs b/core/crfg/src/aux_schema.rs index 90e61d2..621c72d 100644 --- a/core/crfg/src/aux_schema.rs +++ b/core/crfg/src/aux_schema.rs @@ -32,10 +32,10 @@ use crate::NewAuthoritySet; use substrate_primitives::ed25519::Public as AuthorityId; const VERSION_KEY: &[u8] = b"crfg_schema_version"; -const SET_STATE_KEY: &[u8] = b"crfg_completed_round"; -const AUTHORITY_SET_KEY: &[u8] = b"crfg_voters"; -const CONSENSUS_CHANGES_KEY: &[u8] = b"crfg_consensus_changes"; -const PENDING_SKIP_KEY: &[u8] = b"crfg_pending_skip"; +pub const SET_STATE_KEY: &[u8] = b"crfg_completed_round"; +pub const AUTHORITY_SET_KEY: &[u8] = b"crfg_voters"; +pub const CONSENSUS_CHANGES_KEY: &[u8] = b"crfg_consensus_changes"; +pub const PENDING_SKIP_KEY: &[u8] = b"crfg_pending_skip"; const CURRENT_VERSION: u32 = 1; @@ -62,18 +62,18 @@ impl VoterSetState { type V0VoterSetState = (u64, RoundState); #[derive(Debug, Clone, Encode, Decode, PartialEq)] -struct V0PendingChange { - next_authorities: Vec<(AuthorityId, u64)>, - delay: N, - canon_height: N, - canon_hash: H, +pub struct V0PendingChange { + pub next_authorities: Vec<(AuthorityId, u64)>, + pub delay: N, + pub canon_height: N, + pub canon_hash: H, } #[derive(Debug, Clone, Encode, Decode, PartialEq)] -struct V0AuthoritySet { - current_authorities: Vec<(AuthorityId, u64)>, - set_id: u64, - pending_changes: Vec>, +pub struct V0AuthoritySet { + pub current_authorities: Vec<(AuthorityId, u64)>, + pub set_id: u64, + pub pending_changes: Vec>, } impl Into> for V0AuthoritySet @@ -129,7 +129,7 @@ pub(crate) struct PersistentData { pub(crate) authority_set: SharedAuthoritySet, pub(crate) consensus_changes: SharedConsensusChanges, pub(crate) set_state: VoterSetState, - pub(crate) pending_skip: SharedPendingSkip, + pub(crate) pending_skip: SharedPendingSkip, } /// Load or initialize persistent data from backend. @@ -150,7 +150,7 @@ pub(crate) fn load_persistent( let consensus_changes = load_decode(backend, CONSENSUS_CHANGES_KEY)? .unwrap_or_else(ConsensusChanges::::empty); let pending_skip = load_decode(backend, PENDING_SKIP_KEY)? - .unwrap_or_else(Vec::::new); + .unwrap_or_else(Vec::<(H, N, N)>::new); let make_genesis_round = move || RoundState::genesis((genesis_hash, genesis_number)); diff --git a/core/crfg/src/consensus_changes.rs b/core/crfg/src/consensus_changes.rs index b9903e0..0cdf997 100644 --- a/core/crfg/src/consensus_changes.rs +++ b/core/crfg/src/consensus_changes.rs @@ -72,4 +72,4 @@ impl ConsensusChanges { /// Thread-safe consensus changes tracker reference. pub(crate) type SharedConsensusChanges = Arc>>; -pub(crate) type SharedPendingSkip = Arc>>; +pub(crate) type SharedPendingSkip = Arc>>; diff --git a/core/crfg/src/environment.rs b/core/crfg/src/environment.rs index ffa6f20..25233be 100644 --- a/core/crfg/src/environment.rs +++ b/core/crfg/src/environment.rs @@ -88,7 +88,7 @@ pub(crate) struct Environment, RA> { pub(crate) network: N, pub(crate) set_id: u64, pub(crate) last_completed: LastCompletedRound>, - pub(crate) pending_skip: SharedPendingSkip>, + pub(crate) pending_skip: SharedPendingSkip>, } impl, B, E, N, RA> grandpa::Chain> for Environment where @@ -344,7 +344,7 @@ pub(crate) fn finalize_block, E, RA>( hash: Block::Hash, number: NumberFor, justification_or_commit: JustificationOrCommit, - pending_skip: &SharedPendingSkip>, + pending_skip: &SharedPendingSkip>, ) -> Result<(), CommandOrError>> where B: Backend, E: CallExecutor + Send + Sync, @@ -365,7 +365,7 @@ pub(crate) fn finalize_block, E, RA>( canonical_at_height(client, (hash, number), true, canon_number) }; - let mut pending_skip = pending_skip.lock(); + let mut pending_skip = pending_skip.write(); let update_res: Result<_, Error> = client.lock_import_and_run(|import_op| { @@ -396,7 +396,7 @@ pub(crate) fn finalize_block, E, RA>( } // pending skip - pending_skip.retain(|x| x>=&number ); + pending_skip.retain(|(_block_hash, _block_number, skip_number)| skip_number>=&number ); debug!(target: "afg", "Finalizing pending skip: {:?}", *pending_skip); let write_result = crate::aux_schema::update_pending_skip(&*pending_skip, diff --git a/core/crfg/src/import.rs b/core/crfg/src/import.rs index 39065e1..854a978 100644 --- a/core/crfg/src/import.rs +++ b/core/crfg/src/import.rs @@ -17,7 +17,7 @@ use std::{sync::Arc, collections::HashMap}; use log::{debug, trace, info, warn}; -use parity_codec::Encode; +use parity_codec::{Encode, Decode}; use futures::sync::mpsc; use parking_lot::{RwLockWriteGuard, RwLock}; @@ -38,7 +38,7 @@ use runtime_primitives::traits::{ }; use substrate_primitives::{H256, ed25519, Blake2Hasher}; -use crate::{Error, CommandOrError, NewAuthoritySet, VoterCommand}; +use crate::{Error, CommandOrError, NewAuthoritySet, VoterCommand, CrfgStateProvider, CrfgState}; use crate::authorities::{AuthoritySet, SharedAuthoritySet, DelayKind, PendingChange}; use crate::consensus_changes::{SharedConsensusChanges, SharedPendingSkip}; use crate::environment::{finalize_block, is_descendent_of}; @@ -49,11 +49,14 @@ use crate::digest::{CrfgChangeDigestItem, CrfgForceChangeDigestItem, CrfgSkipDig use runtime_primitives::traits::Digest; use std::time; use std::cell::Cell; -use fg_primitives::BLOCK_FINAL_LATENCY; use yee_consensus_pow::fork::FORK_CONF; +use crate::skip::SKIP_CONF; +use std::ops::Add; +use std::fmt::Debug; const DEFAULT_FINALIZE_BLOCK: u64 = 1; const FINALIZE_TIMEOUT: time::Duration = time::Duration::from_secs(30); +const DEFAULT_IMPORT_LEADING: u64 = 2880; /// A block-import handler for CRFG. /// @@ -73,7 +76,8 @@ pub struct CrfgBlockImport, RA, PRA> { validator: bool, finalize_status: Arc, time::Instant)>>>, import_until: Option>, - pending_skip: SharedPendingSkip>, + import_leading: Option>, + pending_skip: SharedPendingSkip>, chain_spec_id: String, shard_num: u16, } @@ -121,55 +125,11 @@ impl, RA, PRA> JustificationImport // since the delay of crfg is always 0, effective_block_hash = pending_change.canon_hash // the above code can be replaced with the following code // to avoid using best_containing( which contains unimplemented for light client) - link.request_justification(&pending_change.canon_hash, pending_change.canon_height, false); + link.request_justification(&pending_change.canon_hash, pending_change.canon_height); } } } - fn on_tick(&self, link: &(dyn ::consensus_common::import_queue::Link)) { - /* - let info = match self.inner.info(){ - Ok(info) => info, - Err(e) => { - warn!(target: "afg", "Justification import encounters error on tick: {:?}", e); - return; - } - }; - let best_number = info.chain.best_number; - let finalized_number = info.chain.finalized_number; - let (status, updated) = match self.finalize_status.read().as_ref(){ - Some((f, i)) => { - if f != &finalized_number { - ((finalized_number, time::Instant::now()), true) - }else{ - ((f.clone(), i.clone()), false) - } - }, - None => ((finalized_number, time::Instant::now()), true) - }; - if updated { - *self.finalize_status.write() = Some(status); - } - - if best_number - finalized_number > As::sa(BLOCK_FINAL_LATENCY + 2 ) && status.1.elapsed() > FINALIZE_TIMEOUT { - info!(target: "afg", "Finalize stalls, finalized_number: {} elapsed: {:?}", finalized_number, status.1.elapsed()); - - let authorities = self.authority_set.inner().read(); - for pending_change in authorities.pending_changes() { - if pending_change.delay_kind == DelayKind::Finalized && - pending_change.effective_number() > finalized_number && - pending_change.effective_number() <= best_number - { - link.request_justification(&pending_change.canon_hash, pending_change.canon_height, true); - } - } - //clear status to avoid request justification too often - *self.finalize_status.write() = None; - } - */ - - } - fn import_justification( &self, hash: Block::Hash, @@ -324,38 +284,48 @@ impl, RA, PRA> CrfgBlockImport, finalized_number: NumberFor) - -> Result>, ConsensusError> { - let header = &block.header; let digest = header.digest(); - let maybe_skip : Result<_, String> = Ok(digest.logs().iter().filter_map(CrfgSkipDigestItem::as_skip).next()); + let maybe_skip = digest.logs().iter().filter_map(CrfgSkipDigestItem::as_skip).next(); let maybe_skip = match maybe_skip { - Err(e) => Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), - Ok(Some(skip_number)) => { - debug!(target: "afg", "Skip: {:?}", skip_number); + Some(skip_number) => { + let block_hash = block.post_header().hash(); + let block_number = header.number().clone(); + Some((block_hash, block_number, skip_number)) + }, + None => { + let block_number = header.number().clone(); + let skip = SKIP_CONF.get(&(&self.chain_spec_id, self.shard_num, As::as_(block_number))) + .map(|(block_hash, skip_number)| { - let mut pending_skip = self.pending_skip.lock(); - pending_skip.push(skip_number); + let block_hash = hex::decode(block_hash.trim_start_matches("0x")).expect("qed"); + let block_hash = Decode::decode(&mut &block_hash[..]).expect("qed"); - Ok(Some(skip_number)) + (block_hash, block_number, As::sa(*skip_number)) + }); + skip } - Ok(None) => Ok(None), }; + if let Some(skip) = maybe_skip { + debug!(target: "afg", "Skip: block_hash: {:?}, block_number: {}, skip_number: {}", skip.0, skip.1, skip.2); + let mut pending_skip = self.pending_skip.write(); + pending_skip.push(skip); + } + // update aux - let mut pending_skip = self.pending_skip.lock(); - pending_skip.retain(|x| x>=&finalized_number ); + let mut pending_skip = self.pending_skip.write(); + pending_skip.retain(|(_block_hash, _block_number, skip_number)| skip_number>=&finalized_number ); crate::aux_schema::update_pending_skip(&*pending_skip, |insert| block.auxiliary.extend( insert.iter().map(|(k, v)| (k.to_vec(), Some(v.to_vec())) ))); debug!(target: "afg", "Pending skip: {:?}", *pending_skip); - maybe_skip } fn make_authorities_changes<'a>(&'a self, block: &mut ImportBlock, hash: Block::Hash) @@ -528,7 +498,7 @@ impl, RA, PRA> BlockImport type Error = ConsensusError; fn import_block(&self, mut block: ImportBlock, new_cache: HashMap>) - -> Result + -> Result>, Self::Error> { let hash = block.post_header().hash(); let number = block.header.number().clone(); @@ -537,12 +507,6 @@ impl, RA, PRA> BlockImport debug!(target: "afg", "Import block, number: {}, hash: {}, origin: {:?}", number, hash, block.origin); - if let Some(import_until) = self.import_until { - if number > import_until { - return Err(ConsensusErrorKind::ClientImport("Exceed max block number".to_string()).into()); - } - } - // early exit if block already in chain, otherwise the check for // authority changes will error when trying to re-import a change block match self.inner.backend().blockchain().status(BlockId::Hash(hash)) { @@ -558,8 +522,7 @@ impl, RA, PRA> BlockImport let finalized_number = chain_info.finalized_number; // check skip - debug!(target: "afg", "Check skip, number: {}, hash: {}, finalized_number: {}", number, hash, finalized_number); - let skip = self.check_skip(&mut block, finalized_number)?; + self.check_skip(&mut block, finalized_number); // check pending_changes let pending_changes = self.make_authorities_changes(&mut block, hash)?; @@ -614,19 +577,42 @@ impl, RA, PRA> BlockImport // execute skip if maybe_fork.is_none() && finalized_number + As::sa(srml_finality_tracker::STALL_LATENCY) <= number { - if self.pending_skip.lock().contains(&finalized_number) { - let next_number = finalized_number + As::sa(1); - let next_hash = match self.inner.hash(next_number){ - Ok(Some(hash)) => hash, - Ok(None) => return Err(ConsensusErrorKind::ClientImport("Unknown block number".to_string()).into()), - Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), - }; - debug!(target: "afg", "Execute skip, next_number: {}, next_hash: {}", &next_number, next_hash); - match self.skip(next_hash, next_number){ - Ok(_) => (), - Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), + + let mut work_finalized_number = finalized_number; + let mut skipped = Vec::new(); + loop { + let maybe_skip = self.pending_skip.read().iter().find(|(block_hash, block_number, skip_number)| { + let result = skip_number == &work_finalized_number && + block_number.clone() + As::sa(2) <= number && + (match self.inner.hash(block_number.clone()) { + Ok(Some(h)) => &h == block_hash, + _ => false + }); + result + }).cloned(); + + if let Some((_block_hash, _block_number, skip_number)) = maybe_skip { + let next_number = work_finalized_number + As::sa(1); + let next_hash = match self.inner.hash(next_number) { + Ok(Some(hash)) => hash, + Ok(None) => return Err(ConsensusErrorKind::ClientImport("Unknown block number".to_string()).into()), + Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), + }; + info!(target: "afg", "Execute skip, next_number: {}, next_hash: {}", &next_number, next_hash); + work_finalized_number = match self.skip(next_hash, next_number) { + Ok(number) => number, + Err(e) => { + debug!(target: "afg", "Execute skip, failed, next_number: {}, next_hash: {}, e: {}", &next_number, next_hash, e); + return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()) + }, + }; + skipped.push((next_hash, next_number)); + + } else { + break; } } + imported_aux.skip_justification_requests = skipped; } // execute fork @@ -635,6 +621,7 @@ impl, RA, PRA> BlockImport return Err(ConsensusErrorKind::ClientImport("fork hash not match".to_string()).into()); } // skip from finalized_number + 1 to fork_block_number + let mut skipped = Vec::new(); let mut current_number = finalized_number + As::sa(1); while current_number <= fork_block_number { let current_hash = match self.inner.hash(current_number){ @@ -651,9 +638,11 @@ impl, RA, PRA> BlockImport return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()) }, } + skipped.push((current_hash, current_number)); current_number = current_number + As::sa(1); } + imported_aux.skip_justification_requests = skipped; } // Send the pause signal after import but BEFORE sending a `ChangeAuthorities` message. @@ -702,9 +691,7 @@ impl, RA, PRA> BlockImport return Ok(ImportResult::Imported(imported_aux)); } - - - debug!(target: "afg", "Import justification, number: {}, hash: {}, has_justification: {}", number, hash, justification.is_some()); + debug!(target: "afg", "Import block process justification, number: {}, hash: {}, has_justification: {}", number, hash, justification.is_some()); match justification { Some(justification) => { @@ -716,7 +703,6 @@ impl, RA, PRA> BlockImport }); }, None => { - use runtime_primitives::traits::As; if number.as_() == DEFAULT_FINALIZE_BLOCK { let justification= CrfgJustification::::default_justification(hash, number); self.import_justification(hash, number, justification.encode(), needs_justification).unwrap_or_else(|err| { @@ -752,9 +738,28 @@ impl, RA, PRA> BlockImport fn check_block( &self, hash: Block::Hash, + number: NumberFor, parent_hash: Block::Hash, - ) -> Result { - self.inner.check_block(hash, parent_hash) + ) -> Result>, Self::Error> { + + if let Some(import_until) = self.import_until { + if number > import_until { + return Ok(ImportResult::Hold); + } + } + + let chain_info = match self.inner.info() { + Ok(info) => info.chain, + Err(e) => return Err(ConsensusErrorKind::ClientImport(e.to_string()).into()), + }; + let finalized_number = chain_info.finalized_number; + + let import_leading = self.import_leading.unwrap_or(As::sa(DEFAULT_IMPORT_LEADING)); + if finalized_number + import_leading < number { + return Ok(ImportResult::Hold); + } + + self.inner.check_block(hash, number, parent_hash) } } @@ -767,10 +772,19 @@ impl, RA, PRA> CrfgBlockImport, validator: bool, import_until: Option>, - pending_skip: SharedPendingSkip>, + import_leading: Option>, + pending_skip: SharedPendingSkip>, chain_spec_id: String, shard_num: u16, + crfg_state_providers: Arc>>>>>, ) -> CrfgBlockImport { + + let mut providers = crfg_state_providers.write(); + providers.insert(shard_num, Arc::new(ImportCrfgStateProvider{ + authority_set: authority_set.clone(), + pending_skip: pending_skip.clone(), + })); + CrfgBlockImport { inner, authority_set, @@ -780,6 +794,7 @@ impl, RA, PRA> CrfgBlockImport, RA, PRA> CrfgBlockImport, - ) -> Result<(), ConsensusError> { + ) -> Result, ConsensusError> { let justification = CrfgJustification::default_justification(hash.clone(), number); @@ -878,7 +893,7 @@ impl, RA, PRA> CrfgBlockImport { debug!(target: "afg", "Skip for block #{} that triggers \ command {}, signaling voter.", number, command); @@ -888,20 +903,63 @@ impl, RA, PRA> CrfgBlockImport { - return Err(match e { - Error::Crfg(error) => ConsensusErrorKind::ClientImport(error.to_string()), - Error::Network(error) => ConsensusErrorKind::ClientImport(error), - Error::Blockchain(error) => ConsensusErrorKind::ClientImport(error), - Error::Client(error) => ConsensusErrorKind::ClientImport(error.to_string()), - Error::Safety(error) => ConsensusErrorKind::ClientImport(error), - Error::Timer(error) => ConsensusErrorKind::ClientImport(error.to_string()), - }.into()); + + // finalized_number is some if skipped + let finalized_number = match self.inner.info() { + Ok(info) => { + let finalized_number = info.chain.finalized_number; + if finalized_number >= number{ + Some(finalized_number) + } else { + None + } + }, + Err(e) => None, + }; + match finalized_number { + Some(finalized_number) => finalized_number, + None => { + return Err(match e { + Error::Crfg(error) => ConsensusErrorKind::ClientImport(error.to_string()), + Error::Network(error) => ConsensusErrorKind::ClientImport(error), + Error::Blockchain(error) => ConsensusErrorKind::ClientImport(error), + Error::Client(error) => ConsensusErrorKind::ClientImport(error.to_string()), + Error::Safety(error) => ConsensusErrorKind::ClientImport(error), + Error::Timer(error) => ConsensusErrorKind::ClientImport(error.to_string()), + }.into()); + } + } }, - Ok(_) => (), - } + Ok(_) => number, + }; - Ok(()) + Ok(finalized_number) + } +} + +struct ImportCrfgStateProvider { + pub authority_set: SharedAuthoritySet, + pub pending_skip: SharedPendingSkip, +} + +impl CrfgStateProvider for ImportCrfgStateProvider +where + N: Add + Ord + Clone + Send + Sync + Debug, + H: Eq + Clone + Send + Sync + Debug +{ + fn crfg_state(&self) -> CrfgState { + let set_id = self.authority_set.set_id(); + let voters = self.authority_set.current_authorities(); + let pending_skip = (*self.pending_skip.read()).clone(); + CrfgState { + config: None, + set_id, + voters, + set_status: None, + pending_skip, + } } } diff --git a/core/crfg/src/lib.rs b/core/crfg/src/lib.rs index 65c9303..50ef286 100644 --- a/core/crfg/src/lib.rs +++ b/core/crfg/src/lib.rs @@ -90,8 +90,8 @@ use ansi_term::Colour; pub use fg_primitives::ScheduledChange; use std::collections::HashMap; -mod authorities; -mod aux_schema; +pub mod authorities; +pub mod aux_schema; mod communication; mod consensus_changes; mod environment; @@ -100,6 +100,8 @@ mod import; mod justification; mod until_imported; mod digest; +pub use digest::CrfgChangeDigestItem; +mod skip; #[cfg(feature="service-integration")] mod service_integration; @@ -115,6 +117,7 @@ use until_imported::UntilCommitBlocksImported; use ed25519::{Public as AuthorityId, Signature as AuthoritySignature}; use parking_lot::RwLock; +use crate::consensus_changes::SharedPendingSkip; #[cfg(test)] mod tests; @@ -664,8 +667,10 @@ pub fn block_import, RA, PRA>( api: Arc, validator: bool, import_until: Option>, + import_leading: Option>, chain_spec_id: String, shard_num: u16, + crfg_state_providers: Arc>>>>>, ) -> Result<(CrfgBlockImport, LinkHalf), ClientError> where B: Backend + 'static, @@ -704,9 +709,11 @@ pub fn block_import, RA, PRA>( api, validator, import_until, + import_leading, persistent_data.pending_skip.clone(), chain_spec_id, shard_num, + crfg_state_providers, ), LinkHalf { client, @@ -806,7 +813,7 @@ pub fn run_crfg, N, RA>( network: N, inherent_data_providers: InherentDataProviders, on_exit: impl Future + Send + 'static, - crfg_state: Arc>>>>, + crfg_state_provider: Arc>>>>>, ) -> ::client::error::Result + Send + 'static> where Block::Hash: Ord, B: Backend + 'static, @@ -850,6 +857,17 @@ pub fn run_crfg, N, RA>( info!("{} set new crfg authority key", Colour::Green.paint("crfg:")); } + let run_crfg_state_provider = Arc::new(RwLock::new(RunCrfgStateProvider{ + config: Some(config.clone()), + set_id: initial_environment.set_id, + voters: initial_environment.voters.clone(), + set_status: Some(set_state.clone()), + pending_skip: initial_environment.pending_skip.clone(), + })); + + let mut provider = crfg_state_provider.write(); + *provider = Some(Arc::new(run_crfg_state_provider.clone())); + let initial_state = (initial_environment, set_state, voter_commands_rx.into_future()); let voter_work = future::loop_fn(initial_state, move |params| { let (env, set_state, voter_commands_rx) = params; @@ -860,13 +878,10 @@ pub fn run_crfg, N, RA>( ); { - let mut state = crfg_state.write(); - *state = Some(CrfgState { - config: config.clone(), - set_id: env.set_id, - voters: env.voters.clone(), - set_status: set_state.clone(), - }); + let mut provider = run_crfg_state_provider.write(); + provider.set_id = env.set_id; + provider.voters = env.voters.clone(); + provider.set_status = Some(set_state.clone()); } let voters = authority_set.clone().current_authorities(); @@ -1043,8 +1058,35 @@ pub fn inherent_to_common_error(err: RuntimeString) -> consensus_common::Error { #[derive(Clone)] pub struct CrfgState { - pub config: Config, + pub config: Option, + pub set_id: u64, + pub voters: VoterSet, + pub set_status: Option>, + pub pending_skip: Vec<(H, N, N)>, +} + +pub trait CrfgStateProvider: Send + Sync { + fn crfg_state(&self) -> CrfgState; +} + +struct RunCrfgStateProvider { + pub config: Option, pub set_id: u64, pub voters: Arc>, - pub set_status: VoterSetState, + pub set_status: Option>, + pub pending_skip: SharedPendingSkip, +} + +impl CrfgStateProvider for Arc>> { + fn crfg_state(&self) -> CrfgState { + let read = self.read(); + let pending_skip = (*read.pending_skip.read()).clone(); + CrfgState { + config: read.config.clone(), + set_id: read.set_id, + voters: (*read.voters).clone(), + set_status: read.set_status.clone(), + pending_skip, + } + } } diff --git a/core/crfg/src/skip.rs b/core/crfg/src/skip.rs new file mode 100644 index 0000000..60d2b27 --- /dev/null +++ b/core/crfg/src/skip.rs @@ -0,0 +1,36 @@ +// Copyright (C) 2019 Yee Foundation. +// +// This file is part of YeeChain. +// +// YeeChain is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// YeeChain is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with YeeChain. If not, see . + +use lazy_static::lazy_static; +use std::collections::HashMap; + +lazy_static! { + /// (chain_spec_id, shard_num, block_number) => (block_hash, skip_number) + pub static ref SKIP_CONF: HashMap<(&'static str, u16, u64), (&'static str, u64)> = { + let mut m = HashMap::new(); + m.insert(("mainnet", 0, 155699), ("0x80efb2876ef10c381bbb7193824b40b1177922234009b147eb6394d176ceb05a", 155673)); + m.insert(("mainnet", 0, 160595), ("0x544ebd2fce52a00375994984b8ff89032a61716e8f2b383c0ce9efaeeaec79a5", 160564)); + + m.insert(("mainnet", 1, 160624), ("0xdd62ef02370b79de9160604a4cd6234ac68651a4efc673bf9aae7e0cfc77c348", 160593)); + + m.insert(("mainnet", 2, 160503), ("0x22eb3b842f3a8ad5a3445037688ec36f5330e59720cc4d724f59115d6916b82c", 160472)); + m.insert(("mainnet", 2, 165579), ("0x5501ca5222b478f7fdf8428a32ca2eb18da931379af0d569065a6ba2f7532c1a", 165520)); + + m.insert(("mainnet", 3, 158788), ("0x7761c0ca109e9b2a251cdcaac0e328b35b5ce781a9f21b18f6666494aa5168f4", 158757)); + m + }; +} diff --git a/foreign/network/src/service.rs b/foreign/network/src/service.rs index dcdd4f7..7ef2e61 100644 --- a/foreign/network/src/service.rs +++ b/foreign/network/src/service.rs @@ -880,7 +880,7 @@ impl substrate_service::NetworkProvider for Service, protocol_id: substrate_network::ProtocolId, import_queue: Box>>, - ) -> Result>, substrate_network::Error>{ + ) -> Result<(Arc>, substrate_network::NetworkChan>), substrate_network::Error>{ let shard_num = network_id as u16; @@ -901,7 +901,7 @@ impl substrate_service::NetworkProvider for Service VProtocol { ) -> error::Result { let config = ProtocolConfig { roles: Roles::FULL, - max_leading_blocks: 0, }; let info = chain.info()?; let peers: Arc>>> = Arc::new(Default::default()); diff --git a/foreign/network/vnetwork/Cargo.toml b/foreign/network/vnetwork/Cargo.toml index 14cf27a..a57ded6 100644 --- a/foreign/network/vnetwork/Cargo.toml +++ b/foreign/network/vnetwork/Cargo.toml @@ -26,6 +26,7 @@ peerset = { package = "substrate-peerset", git = "https://github.com/yeeco/subst tokio = "0.1.11" keyring = { package = "substrate-keyring", git = "https://github.com/yeeco/substrate.git", branch = "yee-v1.0", optional = true } substrate_network = { package = "substrate-network", git = "https://github.com/yeeco/substrate.git", branch = "yee-v1.0" } +substrate_service = { package = "substrate-service", git = "https://github.com/yeeco/substrate.git", branch = "yee-v1.0" } [dev-dependencies] env_logger = { version = "0.6" } diff --git a/foreign/network/vnetwork/src/service.rs b/foreign/network/vnetwork/src/service.rs index eaf85bd..2af8f73 100644 --- a/foreign/network/vnetwork/src/service.rs +++ b/foreign/network/vnetwork/src/service.rs @@ -294,6 +294,19 @@ impl, I: IdentifySpecialization } } +impl substrate_service::Network for Service where + B: BlockT, + S: NetworkSpecialization, + I: IdentifySpecialization, +{ + fn on_block_imported(&self, hash: B::Hash, header: B::Header) { + self.on_block_imported(hash, header); + } + fn on_block_finalized(&self, hash: B::Hash, header: B::Header) { + self.on_block_finalized(hash, header); + } +} + /// A link implementation that connects to the network. #[derive(Clone)] pub struct NetworkLink> { @@ -318,7 +331,7 @@ impl> Link for NetworkLink { fn justification_imported(&self, who: PeerId, hash: &B::Hash, number: NumberFor, success: bool) { let _ = self.protocol_sender.send(ProtocolMsg::JustificationImportResult(hash.clone(), number, success)); if !success { - let reason = Severity::Bad(format!("Invalid justification provided for #{}", hash).to_string()); + let reason = Severity::Useless(format!("Invalid justification provided for #{}", hash).to_string()); let _ = self.network_sender.send(NetworkMsg::ReportPeer(who, reason)); } } @@ -327,8 +340,8 @@ impl> Link for NetworkLink { let _ = self.protocol_sender.send(ProtocolMsg::ClearJustificationRequests); } - fn request_justification(&self, hash: &B::Hash, number: NumberFor, force: bool) { - let _ = self.protocol_sender.send(ProtocolMsg::RequestJustification(hash.clone(), number, force)); + fn request_justification(&self, hash: &B::Hash, number: NumberFor) { + let _ = self.protocol_sender.send(ProtocolMsg::RequestJustification(hash.clone(), number)); } fn useless_peer(&self, who: PeerId, reason: &str) { @@ -346,6 +359,14 @@ impl> Link for NetworkLink { fn restart(&self) { let _ = self.protocol_sender.send(ProtocolMsg::RestartSync); } + + fn hold(&self) { + let _ = self.protocol_sender.send(ProtocolMsg::HoldSync); + } + + fn skip_justification_requests(&self, justifications: Vec<(B::Hash, NumberFor)>) { + let _ = self.protocol_sender.send(ProtocolMsg::SkipJustificationRequests(justifications)); + } } /// Create a ImportQueuePort/Chan pair. diff --git a/rpc/src/lib.rs b/rpc/src/lib.rs index a2f6919..36691e4 100644 --- a/rpc/src/lib.rs +++ b/rpc/src/lib.rs @@ -43,9 +43,10 @@ use parity_codec::{Decode, Encode, Codec}; use serde::de::Unexpected::Other; use futures::sync::mpsc; use yee_primitives::{RecommitRelay, Hrp}; -use crfg::CrfgState; +use crfg::CrfgStateProvider; use yee_foreign_network::SyncProvider; use serde::Serialize; +use parity_codec::alloc::collections::HashMap; pub struct FullRpcHandlerConstructor; @@ -58,7 +59,9 @@ where B: BlockT fn provide_recommit_relay_sender(&self) -> Arc>>>>; - fn provide_crfg_state(&self) -> Arc>>>>; + fn provide_crfg_state_provider(&self) -> Arc>>>>>; + + fn provide_import_crfg_state_providers(&self) -> Arc>>>>>; fn provide_foreign_network(&self) -> Arc>>>>; @@ -68,6 +71,8 @@ where B: BlockT #[derive(Clone, Serialize)] pub struct Config { + pub shard_num: u16, + pub shard_count: u16, pub coinbase: Option, pub job_cache_size: Option, } @@ -77,7 +82,8 @@ pub struct FullRpcExtra where B: BlockT { job_manager: Arc>>>>, recommit_relay_sender: Arc>>>>, - crfg_state: Arc>>>>, + crfg_state_provider: Arc>>>>>, + import_crfg_state_providers: Arc>>>>>, foreign_network: Arc>>>>, config: Arc, } @@ -101,7 +107,8 @@ impl RpcHandlerConstructor for FullRpcHandlerConstructor where FullRpcExtra{ job_manager: config.custom.provide_job_manager(), recommit_relay_sender: config.custom.provide_recommit_relay_sender(), - crfg_state: config.custom.provide_crfg_state(), + crfg_state_provider: config.custom.provide_crfg_state_provider(), + import_crfg_state_providers: config.custom.provide_import_crfg_state_providers(), foreign_network: config.custom.provide_foreign_network(), config: config.custom.provide_config(), } @@ -143,8 +150,10 @@ impl RpcHandlerConstructor for FullRpcHandlerConstructor where let misc = Misc::new( extra.recommit_relay_sender.clone(), - extra.crfg_state.clone(), + extra.crfg_state_provider.clone(), + extra.import_crfg_state_providers.clone(), transaction_pool.clone(), + network.clone(), extra.foreign_network.clone(), client.clone(), extra.config.clone(), diff --git a/rpc/src/misc/mod.rs b/rpc/src/misc/mod.rs index f9d4e5a..b55b4fd 100644 --- a/rpc/src/misc/mod.rs +++ b/rpc/src/misc/mod.rs @@ -11,7 +11,7 @@ use std::marker::PhantomData; use yee_primitives::RecommitRelay; use futures::sync::mpsc; use parking_lot::RwLock; -use crfg::CrfgState; +use crfg::CrfgStateProvider; use std::time::Duration; use substrate_primitives::{Bytes, H256, Blake2Hasher}; use transaction_pool::txpool::{Pool, ChainApi as PoolChainApi}; @@ -40,18 +40,25 @@ pub trait MiscApi { #[rpc(name = "system_config")] fn system_config(&self) -> errors::Result; + #[rpc(name = "system_syncState")] + fn sync_state(&self) -> errors::Result>>; + #[rpc(name = "crfg_state")] fn crfg_state(&self) -> errors::Result>>; #[rpc(name = "chain_getRelayProof")] fn get_relay_proof(&self, hash: Option) -> errors::Result>; + + } pub struct Misc { recommit_relay_sender: Arc>>>>, - crfg_state: Arc>>>>, + crfg_state_provider: Arc>>>>>, + import_crfg_state_providers: Arc>>>>>, pool: Arc>, + network: Arc>, foreign_network: Arc>>>>, client: Arc>, config: Arc, @@ -67,16 +74,20 @@ where { pub fn new( recommit_relay_sender: Arc>>>>, - crfg_state: Arc>>>>, + crfg_state_provider: Arc>>>>>, + import_crfg_state_providers: Arc>>>>>, pool: Arc>, + network: Arc>, foreign_network: Arc>>>>, client: Arc>, config: Arc, ) -> Self { Self { recommit_relay_sender, - crfg_state, + crfg_state_provider, + import_crfg_state_providers, pool, + network, foreign_network, client, config, @@ -126,10 +137,25 @@ impl MiscApi> for Misc = HashMap::new(); + peer_count_map.insert(self.config.shard_num, main_peer_count); + for (_peer_id, peer) in &network_state.connected_peers { + match peer.shard_num { + Some(shard_num) => { + let count = peer_count_map.entry(shard_num).or_insert(0); + *count = *count + 1; + } + None => {} + } + } let status = client_info.into_iter().map(|(k, v)|{ let status = v.map(|v|{ ForeignStatus { + peer_count: *peer_count_map.get(&k).unwrap_or(&0u32), best_number: v.chain.best_number, best_hash: v.chain.best_hash, finalized_number: v.chain.finalized_number, @@ -149,7 +175,7 @@ impl MiscApi> for Misc errors::Result>>> { - let state = self.crfg_state.read().as_ref().cloned().map(|x|x.into()); + let state = self.crfg_state_provider.read().as_ref().cloned().map(|x|x.crfg_state().into()); Ok(state) } @@ -159,6 +185,13 @@ impl MiscApi> for Misc errors::Result>>> { + let state = self.import_crfg_state_providers.read().iter().map(|(k, v)|{ + (*k, v.crfg_state().into()) + }).collect::>(); + Ok(state) + } } mod types { @@ -175,10 +208,11 @@ mod types { #[derive(Serialize)] pub struct CrfgState { - pub config: Config, + pub config: Option, pub set_id: u64, pub voters: VoterSet, - pub set_status: VoterSetState, + pub set_status: Option>, + pub pending_skip: Vec<(H, N, N)>, } #[derive(Serialize)] @@ -190,6 +224,11 @@ mod types { pub name: Option, } + #[derive(Serialize)] + pub struct SyncState { + pub pending_skip: Vec<(H, N, N)>, + } + #[derive(Serialize)] pub struct VoterInfo { canon_idx: usize, @@ -219,6 +258,7 @@ mod types { #[derive(Serialize)] pub struct ForeignStatus { + pub peer_count: u32, pub best_number: N, pub best_hash: H, pub finalized_number: N, @@ -231,10 +271,11 @@ mod types { { fn from(t: crfg::CrfgState) -> CrfgState { CrfgState { - config: t.config.into(), + config: t.config.map(Into::into), set_id: t.set_id, voters: t.voters.into(), - set_status: t.set_status.into(), + set_status: t.set_status.map(Into::into), + pending_skip: t.pending_skip, } } } @@ -251,8 +292,8 @@ mod types { } } - impl From>> for VoterSet { - fn from(t: Arc>) -> VoterSet { + impl From> for VoterSet { + fn from(t: grandpa::VoterSet) -> VoterSet { VoterSet { weights: t.weights.iter().map(|(k, v)| (Public(k.0.to_vec()), v.clone().into())).collect(), voters: t.voters.iter().map(|(l, r)| (Public(l.0.to_vec()), *r)).collect(),