diff --git a/Cargo.lock b/Cargo.lock index 2c665a7de..fe59b17b9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -67,6 +67,29 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "backtrace" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "backtrace-sys" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "base-x" version = "0.2.2" @@ -159,6 +182,11 @@ dependencies = [ "rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "byteorder" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "byteorder" version = "1.0.0" @@ -225,6 +253,14 @@ dependencies = [ "unicode-normalization 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "conv" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cookie" version = "0.3.1" @@ -275,6 +311,11 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "custom_derive" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "daemonize" version = "0.2.2" @@ -283,6 +324,15 @@ dependencies = [ "libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "dbghelp-sys" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "deque" version = "0.3.1" @@ -335,6 +385,14 @@ dependencies = [ "regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "error-chain" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "eth-secp256k1" version = "0.5.6" @@ -406,7 +464,7 @@ dependencies = [ "native-contracts 0.1.0", "num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-wasm 0.12.1 (git+http://github.com/nikvolf/parity-wasm)", + "parity-wasm 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", "rlp 0.2.0", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1061,7 +1119,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "jsonrpc-core" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ "futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1073,7 +1131,7 @@ dependencies = [ [[package]] name = "jsonrpc-http-server" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ "hyper 0.10.0-a.0 (git+https://github.com/paritytech/hyper)", "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", @@ -1086,7 +1144,7 @@ dependencies = [ [[package]] name = "jsonrpc-ipc-server" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ "bytes 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", @@ -1099,7 +1157,7 @@ dependencies = [ [[package]] name = "jsonrpc-macros" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "jsonrpc-pubsub 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", @@ -1109,7 +1167,7 @@ dependencies = [ [[package]] name = "jsonrpc-minihttp-server" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ "bytes 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", @@ -1124,7 +1182,7 @@ dependencies = [ [[package]] name = "jsonrpc-pubsub" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1134,8 +1192,9 @@ dependencies = [ [[package]] name = "jsonrpc-server-utils" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ + "bytes 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "globset 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1146,7 +1205,7 @@ dependencies = [ [[package]] name = "jsonrpc-tcp-server" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ "bytes 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", @@ -1160,11 +1219,13 @@ dependencies = [ [[package]] name = "jsonrpc-ws-server" version = "7.0.0" -source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#d12476f42ee672fa9d023f66fcfa5981d9aaba3a" +source = "git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7#5e79be8a098cdda221713992f4a46b41a1d4d8f0" dependencies = [ "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "jsonrpc-server-utils 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "slab 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "ws 0.7.1 (git+https://github.com/tomusdrw/ws-rs)", ] @@ -1464,6 +1525,19 @@ name = "nom" version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "ntp" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", + "conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", + "custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", + "error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "num" version = "0.1.32" @@ -1624,6 +1698,7 @@ dependencies = [ "ethsync 1.7.0", "fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-cpupool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "isatty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1666,12 +1741,14 @@ dependencies = [ "ethcore-util 1.7.0", "fetch 0.1.0", "futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-cpupool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "jsonrpc-http-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "linked-hash-map 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", "mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "mime_guess 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)", + "ntp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "parity-hash-fetch 1.7.0", "parity-reactor 0.1.0", @@ -1775,6 +1852,7 @@ dependencies = [ "ethsync 1.7.0", "fetch 0.1.0", "futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)", + "futures-cpupool 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "jsonrpc-http-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", "jsonrpc-ipc-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)", @@ -1883,7 +1961,7 @@ dependencies = [ [[package]] name = "parity-wasm" version = "0.12.1" -source = "git+http://github.com/nikvolf/parity-wasm#98311ec7333e0d3dc9e45c9df673cc79e41acb83" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2235,6 +2313,11 @@ dependencies = [ "time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "rustc-demangle" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "rustc-hex" version = "1.0.0" @@ -2872,13 +2955,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "wasm-utils" version = "0.1.0" -source = "git+https://github.com/paritytech/wasm-utils#357a5deed635938e79553227bfab976959ca3523" +source = "git+https://github.com/paritytech/wasm-utils#fee06b6d5826c2dc1fc1aa183b0c2c75e3e140c3" dependencies = [ "clap 2.24.2 (registry+https://github.com/rust-lang/crates.io-index)", "env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", - "parity-wasm 0.12.1 (git+http://github.com/nikvolf/parity-wasm)", + "parity-wasm 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2957,6 +3040,8 @@ dependencies = [ "checksum arrayvec 0.3.20 (registry+https://github.com/rust-lang/crates.io-index)" = "d89f1b0e242270b5b797778af0c8d182a1a2ccac5d8d6fadf414223cc0fab096" "checksum aster 0.41.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4ccfdf7355d9db158df68f976ed030ab0f6578af811f5a7bb6dcf221ec24e0e0" "checksum atty 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d912da0db7fa85514874458ca3651fe2cddace8d0b0505571dbdcd41ab490159" +"checksum backtrace 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "346d7644f0b5f9bc73082d3b2236b69a05fd35cce0cfa3724e184e6a5c9e2a2f" +"checksum backtrace-sys 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)" = "3a0d842ea781ce92be2bf78a9b38883948542749640b8378b3b2f03d1fd9f1ff" "checksum base-x 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2f59103b47307f76e03bef1633aec7fa9e29bfb5aa6daf5a334f94233c71f6c1" "checksum base32 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1b9605ba46d61df0410d8ac686b0007add8172eba90e8e909c347856fe794d8c" "checksum bigint 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0673c930652d3d4d6dcd5c45b5db4fa5f8f33994d7323618c43c083b223e8c" @@ -2971,6 +3056,7 @@ dependencies = [ "checksum blastfig 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "09640e0509d97d5cdff03a9f5daf087a8e04c735c3b113a75139634a19cfc7b2" "checksum bloomchain 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3f421095d2a76fc24cd3fb3f912b90df06be7689912b1bdb423caefae59c258d" "checksum bn 0.4.4 (git+https://github.com/paritytech/bn)" = "" +"checksum byteorder 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0fc10e8cc6b2580fda3f36eb6dc5316657f812a3df879a44a66fc9f0fdbc4855" "checksum byteorder 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c40977b0ee6b9885c9013cd41d9feffdd22deb3bb4dc3a71d901cc7a77de18c8" "checksum bytes 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "8b24f16593f445422331a5eed46b72f7f171f910fead4f2ea8f17e727e9c5c14" "checksum cfg-if 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "de1e760d7b6535af4241fca8bd8adf68e2e7edacc6b29f5d399050c5e48cf88c" @@ -2978,13 +3064,16 @@ dependencies = [ "checksum clap 2.24.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6b8f69e518f967224e628896b54e41ff6acfb4dcfefc5076325c36525dac900f" "checksum clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "5b4fabf979ddf6419a313c1c0ada4a5b95cfd2049c56e8418d622d27b4b6ff32" "checksum clippy_lints 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)" = "ce96ec05bfe018a0d5d43da115e54850ea2217981ff0f2e462780ab9d594651a" +"checksum conv 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "78ff10625fd0ac447827aa30ea8b861fead473bb60aeb73af6c1c58caf0d1299" "checksum cookie 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "d53b80dde876f47f03cda35303e368a79b91c70b0d65ecba5fd5280944a08591" "checksum core-foundation 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "20a6d0448d3a99d977ae4a2aa5a98d886a923e863e81ad9ff814645b6feb3bbd" "checksum core-foundation-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "05eed248dc504a5391c63794fe4fb64f46f071280afaa1b73308f3c0ce4574c5" "checksum crossbeam 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)" = "0c5ea215664ca264da8a9d9c3be80d2eaf30923c259d03e870388eb927508f97" "checksum crypt32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e34988f7e069e0b2f3bfc064295161e489b2d4e04a2e4248fb94360cdf00b4ec" "checksum ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)" = "" +"checksum custom_derive 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef8ae57c4978a2acd8b869ce6b9ca1dfe817bff704c220209fdef2c0b75a01b9" "checksum daemonize 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "271ec51b7e0bee92f0d04601422c73eb76ececf197026711c97ad25038a010cf" +"checksum dbghelp-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "97590ba53bcb8ac28279161ca943a924d1fd4a8fb3fa63302591647c4fc5b850" "checksum deque 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1614659040e711785ed8ea24219140654da1729f3ec8a47a9719d041112fe7bf" "checksum difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3304d19798a8e067e48d8e69b2c37f0b5e9b4e462504ad9e27e9f3fce02bba8" "checksum docopt 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3b5b93718f8b3e5544fcc914c43de828ca6c6ace23e0332c6080a2977b49787a" @@ -2992,6 +3081,7 @@ dependencies = [ "checksum either 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3d2b503c86dad62aaf414ecf2b8c527439abedb3f8d812537f0b12bfd6f32a91" "checksum elastic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "258ff6a9a94f648d0379dbd79110e057edbb53eb85cc237e33eadf8e5a30df85" "checksum env_logger 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e3856f1697098606fc6cb97a93de88ca3f3bc35bb878c725920e6e82ecf05e83" +"checksum error-chain 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bd5c82c815138e278b8dcdeffc49f27ea6ffb528403e9dea4194f2e3dd40b143" "checksum eth-secp256k1 0.5.6 (git+https://github.com/paritytech/rust-secp256k1)" = "" "checksum ethabi 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0c3d62319ee0f35abf20afe8859dd2668195912614346447bb2dee9fb8da7c62" "checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa" @@ -3062,6 +3152,7 @@ dependencies = [ "checksum net2 0.2.29 (registry+https://github.com/rust-lang/crates.io-index)" = "bc01404e7568680f1259aa5729539f221cb1e6d047a0d9053cab4be8a73b5d67" "checksum nodrop 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "52cd74cd09beba596430cc6e3091b74007169a56246e1262f0ba451ea95117b2" "checksum nom 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6caab12c5f97aa316cb249725aa32115118e1522b445e26c257dd77cad5ffd4e" +"checksum ntp 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d23f30ae7da76e2c6c2f5de53f298aa9a3911d3955ab2c349eb944caedceb088" "checksum num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "c04bd954dbf96f76bab6e5bd6cef6f1ce1262d15268ce4f926d2b5b778fa7af2" "checksum num-bigint 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "41655c8d667be847a0b72fe0888857a7b3f052f691cf40852be5fcf87b274a65" "checksum num-complex 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)" = "ccac67baf893ac97474f8d70eff7761dabb1f6c66e71f8f1c67a6859218db810" @@ -3080,7 +3171,7 @@ dependencies = [ "checksum parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1d06f6ee0fda786df3784a96ee3f0629f529b91cbfb7d142f6410e6bcd1ce2c" "checksum parity-tokio-ipc 0.1.5 (git+https://github.com/nikvolf/parity-tokio-ipc)" = "" "checksum parity-ui-precompiled 1.4.0 (git+https://github.com/paritytech/js-precompiled.git)" = "" -"checksum parity-wasm 0.12.1 (git+http://github.com/nikvolf/parity-wasm)" = "" +"checksum parity-wasm 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "51104c8b8da5cd0ebe0ab765dfab37bc1927b4a01a3d870b0fe09d9ee65e35ea" "checksum parity-wordlist 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "52142d717754f7ff7ef0fc8da1bdce4f302dd576fb9bf8b727d6a5fdef33348d" "checksum parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "aebb68eebde2c99f89592d925288600fde220177e46b5c9a91ca218d245aeedf" "checksum parking_lot_core 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fb1b97670a2ffadce7c397fb80a3d687c4f3060140b885621ef1653d0e5d5068" @@ -3117,6 +3208,7 @@ dependencies = [ "checksum rpassword 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5d3a99497c5c544e629cc8b359ae5ede321eba5fa8e5a8078f3ced727a976c3f" "checksum rpassword 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ab6e42be826e215f30ff830904f8f4a0933c6e2ae890e1af8b408f5bae60081e" "checksum rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)" = "f76d05d3993fd5f4af9434e8e436db163a12a9d40e1a58a726f27a01dfd12a2a" +"checksum rustc-demangle 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3058a43ada2c2d0b92b3ae38007a2d0fa5e9db971be260e0171408a4ff471c95" "checksum rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0ceb8ce7a5e520de349e1fa172baeba4a9e8d5ef06c47471863530bc4972ee1e" "checksum rustc-serialize 0.3.19 (registry+https://github.com/rust-lang/crates.io-index)" = "6159e4e6e559c81bd706afe9c8fd68f547d3e851ce12e76b1de7914bab61691b" "checksum rustc_version 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "c5f5376ea5e30ce23c03eb77cbe4962b988deead10910c372b226388b594c084" diff --git a/Cargo.toml b/Cargo.toml index 429ea0dd4..93341b564 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ serde_json = "1.0" serde_derive = "1.0" app_dirs = "1.1.1" futures = "0.1" +futures-cpupool = "0.1" fdlimit = "0.1" ws2_32-sys = "0.2" ctrlc = { git = "https://github.com/paritytech/rust-ctrlc.git" } diff --git a/dapps/Cargo.toml b/dapps/Cargo.toml index f34335d2f..a0d63b6e3 100644 --- a/dapps/Cargo.toml +++ b/dapps/Cargo.toml @@ -11,11 +11,13 @@ authors = ["Parity Technologies "] base32 = "0.3" env_logger = "0.4" futures = "0.1" +futures-cpupool = "0.1" linked-hash-map = "0.3" log = "0.3" parity-dapps-glue = "1.7" mime = "0.2" mime_guess = "1.6.1" +ntp = "0.2.0" rand = "0.3" rustc-hex = "1.0" serde = "1.0" diff --git a/dapps/src/api/api.rs b/dapps/src/api/api.rs index d377ebe57..7d38e288f 100644 --- a/dapps/src/api/api.rs +++ b/dapps/src/api/api.rs @@ -18,23 +18,36 @@ use std::sync::Arc; use hyper::{server, net, Decoder, Encoder, Next, Control}; use hyper::method::Method; +use hyper::status::StatusCode; -use api::types::ApiError; -use api::response; +use api::{response, types}; +use api::time::TimeChecker; use apps::fetcher::Fetcher; - -use handlers::extract_url; +use handlers::{self, extract_url}; use endpoint::{Endpoint, Handler, EndpointPath}; +use parity_reactor::Remote; +use {SyncStatus}; #[derive(Clone)] pub struct RestApi { fetcher: Arc, + sync_status: Arc, + time: TimeChecker, + remote: Remote, } impl RestApi { - pub fn new(fetcher: Arc) -> Box { + pub fn new( + fetcher: Arc, + sync_status: Arc, + time: TimeChecker, + remote: Remote, + ) -> Box { Box::new(RestApi { - fetcher: fetcher, + fetcher, + sync_status, + time, + remote, }) } } @@ -58,11 +71,11 @@ impl RestApiRouter { path: Some(path), control: Some(control), api: api, - handler: response::as_json_error(&ApiError { + handler: Box::new(response::as_json_error(StatusCode::NotFound, &types::ApiError { code: "404".into(), title: "Not Found".into(), detail: "Resource you requested has not been found.".into(), - }), + })), } } @@ -75,6 +88,78 @@ impl RestApiRouter { _ => None } } + + fn health(&self, control: Control) -> Box { + use self::types::{HealthInfo, HealthStatus, Health}; + + trace!(target: "dapps", "Checking node health."); + // Check timediff + let sync_status = self.api.sync_status.clone(); + let map = move |time| { + // Check peers + let peers = { + let (connected, max) = sync_status.peers(); + let (status, message) = match connected { + 0 => { + (HealthStatus::Bad, "You are not connected to any peers. There is most likely some network issue. Fix connectivity.".into()) + }, + 1 => (HealthStatus::NeedsAttention, "You are connected to only one peer. Your node might not be reliable. Check your network connection.".into()), + _ => (HealthStatus::Ok, "".into()), + }; + HealthInfo { status, message, details: (connected, max) } + }; + + // Check sync + let sync = { + let is_syncing = sync_status.is_major_importing(); + let (status, message) = if is_syncing { + (HealthStatus::NeedsAttention, "Your node is still syncing, the values you see might be outdated. Wait until it's fully synced.".into()) + } else { + (HealthStatus::Ok, "".into()) + }; + HealthInfo { status, message, details: is_syncing } + }; + + // Check time + let time = { + const MAX_DRIFT: i64 = 500; + let (status, message, details) = match time { + Ok(Ok(diff)) if diff < MAX_DRIFT && diff > -MAX_DRIFT => { + (HealthStatus::Ok, "".into(), diff) + }, + Ok(Ok(diff)) => { + (HealthStatus::Bad, format!( + "Your clock is not in sync. Detected difference is too big for the protocol to work: {}ms. Synchronize your clock.", + diff, + ), diff) + }, + Ok(Err(err)) => { + (HealthStatus::NeedsAttention, format!( + "Unable to reach time API: {}. Make sure that your clock is synchronized.", + err, + ), 0) + }, + Err(_) => { + (HealthStatus::NeedsAttention, "Time API request timed out. Make sure that the clock is synchronized.".into(), 0) + }, + }; + + HealthInfo { status, message, details, } + }; + + let status = if [&peers.status, &sync.status, &time.status].iter().any(|x| *x != &HealthStatus::Ok) { + StatusCode::PreconditionFailed // HTTP 412 + } else { + StatusCode::Ok // HTTP 200 + }; + + response::as_json(status, &Health { peers, sync, time }) + }; + + let time = self.api.time.time_drift(); + let remote = self.api.remote.clone(); + Box::new(handlers::AsyncHandler::new(time, map, remote, control)) + } } impl server::Handler for RestApiRouter { @@ -103,6 +188,7 @@ impl server::Handler for RestApiRouter { let handler = endpoint.and_then(|v| match v { "ping" => Some(response::ping()), + "health" => Some(self.health(control)), "content" => self.resolve_content(hash, path, control), _ => None }); diff --git a/dapps/src/api/mod.rs b/dapps/src/api/mod.rs index 4ffb9f791..59c634399 100644 --- a/dapps/src/api/mod.rs +++ b/dapps/src/api/mod.rs @@ -18,6 +18,8 @@ mod api; mod response; +mod time; mod types; pub use self::api::RestApi; +pub use self::time::TimeChecker; diff --git a/dapps/src/api/response.rs b/dapps/src/api/response.rs index 2da2d0c14..6ecc2df60 100644 --- a/dapps/src/api/response.rs +++ b/dapps/src/api/response.rs @@ -16,6 +16,8 @@ use serde::Serialize; use serde_json; +use hyper::status::StatusCode; + use endpoint::Handler; use handlers::{ContentHandler, EchoHandler}; @@ -23,10 +25,16 @@ pub fn empty() -> Box { Box::new(ContentHandler::ok("".into(), mime!(Text/Plain))) } -pub fn as_json_error(val: &T) -> Box { +pub fn as_json(status: StatusCode, val: &T) -> ContentHandler { let json = serde_json::to_string(val) .expect("serialization to string is infallible; qed"); - Box::new(ContentHandler::not_found(json, mime!(Application/Json))) + ContentHandler::new(status, json, mime!(Application/Json)) +} + +pub fn as_json_error(status: StatusCode, val: &T) -> ContentHandler { + let json = serde_json::to_string(val) + .expect("serialization to string is infallible; qed"); + ContentHandler::new(status, json, mime!(Application/Json)) } pub fn ping() -> Box { diff --git a/dapps/src/api/time.rs b/dapps/src/api/time.rs new file mode 100644 index 000000000..084890dc9 --- /dev/null +++ b/dapps/src/api/time.rs @@ -0,0 +1,264 @@ +// Copyright 2015-2017 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity 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. + +// Parity 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 Parity. If not, see . + +//! Periodically checks node's time drift using [SNTP](https://tools.ietf.org/html/rfc1769). +//! +//! An NTP packet is sent to the server with a local timestamp, the server then completes the packet, yielding the +//! following timestamps: +//! +//! Timestamp Name ID When Generated +//! ------------------------------------------------------------ +//! Originate Timestamp T1 time request sent by client +//! Receive Timestamp T2 time request received at server +//! Transmit Timestamp T3 time reply sent by server +//! Destination Timestamp T4 time reply received at client +//! +//! The drift is defined as: +//! +//! drift = ((T2 - T1) + (T3 - T4)) / 2. +//! + +use std::io; +use std::{fmt, mem, time}; + +use std::collections::VecDeque; +use futures::{self, Future, BoxFuture}; +use futures_cpupool::CpuPool; +use ntp; +use time::{Duration, Timespec}; +use util::{Arc, RwLock}; + +/// Time checker error. +#[derive(Debug, Clone, PartialEq)] +pub enum Error { + /// There was an error when trying to reach the NTP server. + Ntp(String), + /// IO error when reading NTP response. + Io(String), +} + +impl fmt::Display for Error { + fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + use self::Error::*; + + match *self { + Ntp(ref err) => write!(fmt, "NTP error: {}", err), + Io(ref err) => write!(fmt, "Connection Error: {}", err), + } + } +} + +impl From for Error { + fn from(err: io::Error) -> Self { Error::Io(format!("{}", err)) } +} + +impl From for Error { + fn from(err: ntp::errors::Error) -> Self { Error::Ntp(format!("{}", err)) } +} + +/// NTP time drift checker. +pub trait Ntp { + /// Returns the current time drift. + fn drift(&self) -> BoxFuture; +} + +/// NTP client using the SNTP algorithm for calculating drift. +#[derive(Clone)] +pub struct SimpleNtp { + address: Arc, + pool: CpuPool, +} + +impl fmt::Debug for SimpleNtp { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "Ntp {{ address: {} }}", self.address) + } +} + +impl SimpleNtp { + fn new(address: &str, pool: CpuPool) -> SimpleNtp { + SimpleNtp { + address: Arc::new(address.to_owned()), + pool: pool, + } + } +} + +impl Ntp for SimpleNtp { + fn drift(&self) -> BoxFuture { + let address = self.address.clone(); + self.pool.spawn_fn(move || { + let packet = ntp::request(&*address)?; + let dest_time = ::time::now_utc().to_timespec(); + let orig_time = Timespec::from(packet.orig_time); + let recv_time = Timespec::from(packet.recv_time); + let transmit_time = Timespec::from(packet.transmit_time); + + let drift = ((recv_time - orig_time) + (transmit_time - dest_time)) / 2; + + Ok(drift) + }).boxed() + } +} + +const MAX_RESULTS: usize = 4; +const UPDATE_TIMEOUT_OK_SECS: u64 = 30; +const UPDATE_TIMEOUT_ERR_SECS: u64 = 2; + +#[derive(Debug, Clone)] +/// A time checker. +pub struct TimeChecker { + ntp: N, + last_result: Arc>)>>, +} + +impl TimeChecker { + /// Creates new time checker given the NTP server address. + pub fn new(ntp_address: String, pool: CpuPool) -> Self { + let last_result = Arc::new(RwLock::new( + // Assume everything is ok at the very beginning. + (time::Instant::now(), vec![Ok(0)].into()) + )); + + let ntp = SimpleNtp::new(&ntp_address, pool); + + TimeChecker { + ntp, + last_result, + } + } +} + +impl TimeChecker { + /// Updates the time + pub fn update(&self) -> BoxFuture { + let last_result = self.last_result.clone(); + self.ntp.drift().then(move |res| { + let mut results = mem::replace(&mut last_result.write().1, VecDeque::new()); + let valid_till = time::Instant::now() + time::Duration::from_secs( + if res.is_ok() && results.len() == MAX_RESULTS { + UPDATE_TIMEOUT_OK_SECS + } else { + UPDATE_TIMEOUT_ERR_SECS + } + ); + + // Push the result. + results.push_back(res.map(|d| d.num_milliseconds())); + while results.len() > MAX_RESULTS { + results.pop_front(); + } + + // Select a response and update last result. + let res = select_result(results.iter()); + *last_result.write() = (valid_till, results); + res + }).boxed() + } + + /// Returns a current time drift or error if last request to NTP server failed. + pub fn time_drift(&self) -> BoxFuture { + // return cached result + { + let res = self.last_result.read(); + if res.0 > time::Instant::now() { + return futures::done(select_result(res.1.iter())).boxed(); + } + } + // or update and return result + self.update() + } +} + +fn select_result<'a, T: Iterator>>(results: T) -> Result { + let mut min = None; + for res in results { + min = Some(match (min.take(), res) { + (Some(Ok(min)), &Ok(ref new)) => Ok(::std::cmp::min(min, *new)), + (Some(Ok(old)), &Err(_)) => Ok(old), + (_, ref new) => (*new).clone(), + }) + } + + min.unwrap_or_else(|| Err(Error::Ntp("NTP server unavailable.".into()))) +} + +#[cfg(test)] +mod tests { + use std::sync::Arc; + use std::cell::{Cell, RefCell}; + use std::time::Instant; + use time::Duration; + use futures::{self, BoxFuture, Future}; + use super::{Ntp, TimeChecker, Error}; + use util::RwLock; + + #[derive(Clone)] + struct FakeNtp(RefCell>, Cell); + impl FakeNtp { + fn new() -> FakeNtp { + FakeNtp( + RefCell::new(vec![Duration::milliseconds(150)]), + Cell::new(0)) + } + } + + impl Ntp for FakeNtp { + fn drift(&self) -> BoxFuture { + self.1.set(self.1.get() + 1); + futures::future::ok(self.0.borrow_mut().pop().expect("Unexpected call to drift().")).boxed() + } + } + + fn time_checker() -> TimeChecker { + let last_result = Arc::new(RwLock::new( + (Instant::now(), vec![Err(Error::Ntp("NTP server unavailable.".into()))].into()) + )); + + TimeChecker { + ntp: FakeNtp::new(), + last_result: last_result, + } + } + + #[test] + fn should_fetch_time_on_start() { + // given + let time = time_checker(); + + // when + let diff = time.time_drift().wait().unwrap(); + + // then + assert_eq!(diff, 150); + assert_eq!(time.ntp.1.get(), 1); + } + + #[test] + fn should_not_fetch_twice_if_timeout_has_not_passed() { + // given + let time = time_checker(); + + // when + let diff1 = time.time_drift().wait().unwrap(); + let diff2 = time.time_drift().wait().unwrap(); + + // then + assert_eq!(diff1, 150); + assert_eq!(diff2, 150); + assert_eq!(time.ntp.1.get(), 1); + } +} diff --git a/dapps/src/api/types.rs b/dapps/src/api/types.rs index 549186955..a61964143 100644 --- a/dapps/src/api/types.rs +++ b/dapps/src/api/types.rs @@ -14,11 +14,54 @@ // You should have received a copy of the GNU General Public License // along with Parity. If not, see . +/// A structure representing any error in REST API. #[derive(Debug, PartialEq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub struct ApiError { + /// Error code. pub code: String, + /// Human-readable error summary. pub title: String, + /// More technical error details. pub detail: String, } +/// Health API endpoint status. +#[derive(Debug, PartialEq, Serialize)] +pub enum HealthStatus { + /// Everything's OK. + #[serde(rename = "ok")] + Ok, + /// Node health need attention + /// (the issue is not critical, but may need investigation) + #[serde(rename = "needsAttention")] + NeedsAttention, + /// There is something bad detected with the node. + #[serde(rename = "bad")] + Bad +} + +/// Represents a single check in node health. +/// Cointains the status of that check and apropriate message and details. +#[derive(Debug, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct HealthInfo { + /// Check status. + pub status: HealthStatus, + /// Human-readable message. + pub message: String, + /// Technical details of the check. + pub details: T, +} + +/// Node Health status. +#[derive(Debug, PartialEq, Serialize)] +#[serde(deny_unknown_fields)] +pub struct Health { + /// Status of peers. + pub peers: HealthInfo<(usize, usize)>, + /// Sync status. + pub sync: HealthInfo, + /// Time diff info. + pub time: HealthInfo, +} diff --git a/dapps/src/apps/fetcher/mod.rs b/dapps/src/apps/fetcher/mod.rs index cbc2ab212..347799ccf 100644 --- a/dapps/src/apps/fetcher/mod.rs +++ b/dapps/src/apps/fetcher/mod.rs @@ -271,6 +271,7 @@ mod tests { use endpoint::EndpointInfo; use page::LocalPageEndpoint; use super::{ContentFetcher, Fetcher}; + use {SyncStatus}; #[derive(Clone)] struct FakeResolver; @@ -280,11 +281,17 @@ mod tests { } } + struct FakeSync(bool); + impl SyncStatus for FakeSync { + fn is_major_importing(&self) -> bool { self.0 } + fn peers(&self) -> (usize, usize) { (0, 5) } + } + #[test] fn should_true_if_contains_the_app() { // given let path = env::temp_dir(); - let fetcher = ContentFetcher::new(FakeResolver, Arc::new(|| false), Remote::new_sync(), Client::new().unwrap()) + let fetcher = ContentFetcher::new(FakeResolver, Arc::new(FakeSync(false)), Remote::new_sync(), Client::new().unwrap()) .allow_dapps(true); let handler = LocalPageEndpoint::new(path, EndpointInfo { name: "fake".into(), diff --git a/dapps/src/handlers/async.rs b/dapps/src/handlers/async.rs new file mode 100644 index 000000000..d68c55cce --- /dev/null +++ b/dapps/src/handlers/async.rs @@ -0,0 +1,112 @@ +// Copyright 2015-2017 Parity Technologies (UK) Ltd. +// This file is part of Parity. + +// Parity 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. + +// Parity 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 Parity. If not, see . + +//! Async Content Handler +//! Temporary solution until we switch to future-based server. +//! Wraps a future and converts it to hyper::server::Handler; + +use std::{mem, time}; +use std::sync::mpsc; +use futures::Future; +use hyper::{server, Decoder, Encoder, Next, Control}; +use hyper::net::HttpStream; + +use handlers::ContentHandler; +use parity_reactor::Remote; + +const TIMEOUT_SECS: u64 = 15; + +enum State { + Initial(F, M, Remote, Control), + Waiting(mpsc::Receiver>, M), + Done(ContentHandler), + Invalid, +} + +pub struct AsyncHandler { + state: State, +} + +impl AsyncHandler { + pub fn new(future: F, map: M, remote: Remote, control: Control) -> Self { + AsyncHandler { + state: State::Initial(future, map, remote, control), + } + } +} + +impl server::Handler for AsyncHandler, M> where + F: Future + Send + 'static, + M: FnOnce(Result, ()>) -> ContentHandler, + T: Send + 'static, + E: Send + 'static, +{ + fn on_request(&mut self, _request: server::Request) -> Next { + if let State::Initial(future, map, remote, control) = mem::replace(&mut self.state, State::Invalid) { + let (tx, rx) = mpsc::sync_channel(1); + let control2 = control.clone(); + let tx2 = tx.clone(); + remote.spawn_with_timeout(move || future.then(move |result| { + // Send a result (ignore errors if the connection was dropped) + let _ = tx.send(Ok(result)); + // Resume handler + let _ = control.ready(Next::read()); + + Ok(()) + }), time::Duration::from_secs(TIMEOUT_SECS), move || { + // Notify about error + let _ = tx2.send(Err(())); + // Resume handler + let _ = control2.ready(Next::read()); + }); + + self.state = State::Waiting(rx, map); + } + + Next::wait() + } + + fn on_request_readable(&mut self, _decoder: &mut Decoder) -> Next { + if let State::Waiting(rx, map) = mem::replace(&mut self.state, State::Invalid) { + match rx.try_recv() { + Ok(result) => { + self.state = State::Done(map(result)); + }, + Err(err) => { + warn!("Resuming handler in incorrect state: {:?}", err); + } + } + } + + Next::write() + } + + fn on_response(&mut self, res: &mut server::Response) -> Next { + if let State::Done(ref mut handler) = self.state { + handler.on_response(res) + } else { + Next::end() + } + } + + fn on_response_writable(&mut self, encoder: &mut Encoder) -> Next { + if let State::Done(ref mut handler) = self.state { + handler.on_response_writable(encoder) + } else { + Next::end() + } + } +} diff --git a/dapps/src/handlers/content.rs b/dapps/src/handlers/content.rs index 5e0658c23..700e9819e 100644 --- a/dapps/src/handlers/content.rs +++ b/dapps/src/handlers/content.rs @@ -39,10 +39,6 @@ impl ContentHandler { Self::new(StatusCode::Ok, content, mimetype) } - pub fn not_found(content: String, mimetype: Mime) -> Self { - Self::new(StatusCode::NotFound, content, mimetype) - } - pub fn html(code: StatusCode, content: String, embeddable_on: Option<(String, u16)>) -> Self { Self::new_embeddable(code, content, mime!(Text/Html), embeddable_on) } diff --git a/dapps/src/handlers/mod.rs b/dapps/src/handlers/mod.rs index 56b013800..41e787336 100644 --- a/dapps/src/handlers/mod.rs +++ b/dapps/src/handlers/mod.rs @@ -16,12 +16,14 @@ //! Hyper handlers implementations. +mod async; mod content; mod echo; mod fetch; mod redirect; mod streaming; +pub use self::async::AsyncHandler; pub use self::content::ContentHandler; pub use self::echo::EchoHandler; pub use self::fetch::{ContentFetcherHandler, ContentValidator, FetchControl, ValidatorResponse}; diff --git a/dapps/src/lib.rs b/dapps/src/lib.rs index 0b93f4e39..7f7dbe0ac 100644 --- a/dapps/src/lib.rs +++ b/dapps/src/lib.rs @@ -21,8 +21,10 @@ extern crate base32; extern crate futures; +extern crate futures_cpupool; extern crate linked_hash_map; extern crate mime_guess; +extern crate ntp; extern crate rand; extern crate rustc_hex; extern crate serde; @@ -74,6 +76,7 @@ use std::collections::HashMap; use jsonrpc_http_server::{self as http, hyper, Origin}; use fetch::Fetch; +use futures_cpupool::CpuPool; use parity_reactor::Remote; pub use hash_fetch::urlhint::ContractClient; @@ -82,10 +85,9 @@ pub use hash_fetch::urlhint::ContractClient; pub trait SyncStatus: Send + Sync { /// Returns true if there is a major sync happening. fn is_major_importing(&self) -> bool; -} -impl SyncStatus for F where F: Fn() -> bool + Send + Sync { - fn is_major_importing(&self) -> bool { self() } + /// Returns number of connected and ideal peers. + fn peers(&self) -> (usize, usize); } /// Validates Web Proxy tokens @@ -127,21 +129,29 @@ impl Middleware { } /// Creates new middleware for UI server. - pub fn ui( + pub fn ui( + ntp_server: &str, + pool: CpuPool, remote: Remote, + dapps_domain: &str, registrar: Arc, sync_status: Arc, fetch: F, - dapps_domain: String, ) -> Self { let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new( hash_fetch::urlhint::URLHintContract::new(registrar), - sync_status, + sync_status.clone(), remote.clone(), fetch.clone(), ).embeddable_on(None).allow_dapps(false)); let special = { - let mut special = special_endpoints(content_fetcher.clone()); + let mut special = special_endpoints( + ntp_server, + pool, + content_fetcher.clone(), + remote.clone(), + sync_status.clone(), + ); special.insert(router::SpecialEndpoint::Home, Some(apps::ui())); special }; @@ -150,7 +160,7 @@ impl Middleware { None, special, None, - dapps_domain, + dapps_domain.to_owned(), ); Middleware { @@ -160,12 +170,14 @@ impl Middleware { } /// Creates new Dapps server middleware. - pub fn dapps( + pub fn dapps( + ntp_server: &str, + pool: CpuPool, remote: Remote, ui_address: Option<(String, u16)>, dapps_path: PathBuf, extra_dapps: Vec, - dapps_domain: String, + dapps_domain: &str, registrar: Arc, sync_status: Arc, web_proxy_tokens: Arc, @@ -173,14 +185,14 @@ impl Middleware { ) -> Self { let content_fetcher = Arc::new(apps::fetcher::ContentFetcher::new( hash_fetch::urlhint::URLHintContract::new(registrar), - sync_status, + sync_status.clone(), remote.clone(), fetch.clone(), ).embeddable_on(ui_address.clone()).allow_dapps(true)); let endpoints = apps::all_endpoints( dapps_path, extra_dapps, - dapps_domain.clone(), + dapps_domain.to_owned(), ui_address.clone(), web_proxy_tokens, remote.clone(), @@ -188,7 +200,13 @@ impl Middleware { ); let special = { - let mut special = special_endpoints(content_fetcher.clone()); + let mut special = special_endpoints( + ntp_server, + pool, + content_fetcher.clone(), + remote.clone(), + sync_status, + ); special.insert(router::SpecialEndpoint::Home, Some(apps::ui_redirection(ui_address.clone()))); special }; @@ -198,7 +216,7 @@ impl Middleware { Some(endpoints.clone()), special, ui_address, - dapps_domain, + dapps_domain.to_owned(), ); Middleware { @@ -214,11 +232,22 @@ impl http::RequestMiddleware for Middleware { } } -fn special_endpoints(content_fetcher: Arc) -> HashMap>> { +fn special_endpoints( + ntp_server: &str, + pool: CpuPool, + content_fetcher: Arc, + remote: Remote, + sync_status: Arc, +) -> HashMap>> { let mut special = HashMap::new(); special.insert(router::SpecialEndpoint::Rpc, None); special.insert(router::SpecialEndpoint::Utils, Some(apps::utils())); - special.insert(router::SpecialEndpoint::Api, Some(api::RestApi::new(content_fetcher))); + special.insert(router::SpecialEndpoint::Api, Some(api::RestApi::new( + content_fetcher, + sync_status, + api::TimeChecker::new(ntp_server.into(), pool), + remote, + ))); special } diff --git a/dapps/src/tests/helpers/mod.rs b/dapps/src/tests/helpers/mod.rs index 060420792..955c3c890 100644 --- a/dapps/src/tests/helpers/mod.rs +++ b/dapps/src/tests/helpers/mod.rs @@ -26,6 +26,7 @@ use jsonrpc_http_server::{self as http, Host, DomainsValidation}; use devtools::http_client; use hash_fetch::urlhint::ContractClient; use fetch::{Fetch, Client as FetchClient}; +use futures_cpupool::CpuPool; use parity_reactor::Remote; use {Middleware, SyncStatus, WebProxyTokens}; @@ -38,6 +39,12 @@ use self::fetch::FakeFetch; const SIGNER_PORT: u16 = 18180; +struct FakeSync(bool); +impl SyncStatus for FakeSync { + fn is_major_importing(&self) -> bool { self.0 } + fn peers(&self) -> (usize, usize) { (0, 5) } +} + fn init_logger() { // Initialize logger if let Ok(log) = env::var("RUST_LOG") { @@ -82,7 +89,7 @@ pub fn serve_with_registrar() -> (Server, Arc) { pub fn serve_with_registrar_and_sync() -> (Server, Arc) { init_server(|builder| { - builder.sync_status(Arc::new(|| true)) + builder.sync_status(Arc::new(FakeSync(true))) }, Default::default(), Remote::new_sync()) } @@ -148,7 +155,7 @@ impl ServerBuilder { ServerBuilder { dapps_path: dapps_path.as_ref().to_owned(), registrar: registrar, - sync_status: Arc::new(|| false), + sync_status: Arc::new(FakeSync(false)), web_proxy_tokens: Arc::new(|_| None), signer_address: None, allowed_hosts: DomainsValidation::Disabled, @@ -248,6 +255,8 @@ impl Server { fetch: F, ) -> Result { let middleware = Middleware::dapps( + "pool.ntp.org:123", + CpuPool::new(4), remote, signer_address, dapps_path, @@ -290,4 +299,3 @@ impl Drop for Server { self.server.take().unwrap().close() } } - diff --git a/ethcore/Cargo.toml b/ethcore/Cargo.toml index cda69be57..90baf5c9b 100644 --- a/ethcore/Cargo.toml +++ b/ethcore/Cargo.toml @@ -52,7 +52,7 @@ semver = "0.6" stats = { path = "../util/stats" } time = "0.1" transient-hashmap = "0.4" -parity-wasm = { git = "https://github.com/nikvolf/parity-wasm" } +parity-wasm = "0.12" wasm-utils = { git = "https://github.com/paritytech/wasm-utils" } [dev-dependencies] diff --git a/ethcore/src/spec/spec.rs b/ethcore/src/spec/spec.rs index 5bbf7f7c3..d97aca7ff 100644 --- a/ethcore/src/spec/spec.rs +++ b/ethcore/src/spec/spec.rs @@ -467,6 +467,19 @@ mod tests { assert!(Spec::load(::std::env::temp_dir(), &[] as &[u8]).is_err()); } + #[test] + fn all_spec_files_valid() { + Spec::new_test(); + Spec::new_null(); + Spec::new_test_constructor(); + Spec::new_instant(); + Spec::new_test_round(); + Spec::new_test_tendermint(); + Spec::new_validator_safe_contract(); + Spec::new_validator_contract(); + Spec::new_validator_multi(); + } + #[test] fn test_chain() { let test_spec = Spec::new_test(); diff --git a/evmbin/src/main.rs b/evmbin/src/main.rs index 98d61b417..ac060d586 100644 --- a/evmbin/src/main.rs +++ b/evmbin/src/main.rs @@ -134,10 +134,10 @@ impl Args { Ok(match self.flag_spec { Some(ref filename) => { let file = fs::File::open(filename).map_err(|e| format!("{}", e))?; - spec::Spec::load(file)? + spec::Spec::load(::std::env::temp_dir(), file)? }, None => { - ethcore::ethereum::new_foundation() + ethcore::ethereum::new_foundation(&::std::env::temp_dir()) }, }) } diff --git a/js/src/shared/redux/providers/status.js b/js/src/shared/redux/providers/status.js index 06da36bfc..cd9f9b739 100644 --- a/js/src/shared/redux/providers/status.js +++ b/js/src/shared/redux/providers/status.js @@ -26,6 +26,10 @@ import { statusBlockNumber, statusCollection } from './statusActions'; const log = getLogger(LOG_KEYS.Signer); let instance = null; +const STATUS_OK = 'ok'; +const STATUS_WARN = 'needsAttention'; +const STATUS_BAD = 'bad'; + export default class Status { _apiStatus = {}; _status = {}; @@ -200,13 +204,16 @@ export default class Status { const statusPromises = [ this._api.eth.syncing(), - this._api.parity.netPeers() + this._api.parity.netPeers(), + this._fetchHealth() ]; return Promise .all(statusPromises) - .then(([ syncing, netPeers ]) => { - const status = { netPeers, syncing }; + .then(([ syncing, netPeers, health ]) => { + const status = { netPeers, syncing, health }; + + health.overall = this._overallStatus(health); if (!isEqual(status, this._status)) { this._store.dispatch(statusCollection(status)); @@ -221,6 +228,33 @@ export default class Status { }); } + _overallStatus = (health) => { + const all = [health.peers, health.sync, health.time].filter(x => x); + const statuses = all.map(x => x.status); + const bad = statuses.find(x => x === STATUS_BAD); + const needsAttention = statuses.find(x => x === STATUS_WARN); + const message = all.map(x => x.message).filter(x => x); + + if (all.length) { + return { + status: bad || needsAttention || STATUS_OK, + message + }; + } + + return { + status: STATUS_BAD, + message: ['Unable to fetch node health.'] + }; + } + + _fetchHealth = () => { + // Support Parity-Extension. + const uiUrl = this._api.transport.uiUrlWithProtocol || ''; + + return fetch(`${uiUrl}/api/health`).then(res => res.json()); + } + /** * The data fetched here should not change * unless Parity is restarted. They are thus diff --git a/js/src/shared/redux/providers/statusReducer.js b/js/src/shared/redux/providers/statusReducer.js index 3a6968548..23da8616f 100644 --- a/js/src/shared/redux/providers/statusReducer.js +++ b/js/src/shared/redux/providers/statusReducer.js @@ -18,11 +18,28 @@ import BigNumber from 'bignumber.js'; import { handleActions } from 'redux-actions'; const DEFAULT_NETCHAIN = '(unknown)'; +const DEFAULT_STATUS = 'needsAttention'; const initialState = { blockNumber: new BigNumber(0), blockTimestamp: new Date(), clientVersion: '', gasLimit: new BigNumber(0), + health: { + peers: { + status: DEFAULT_STATUS + }, + sync: { + status: DEFAULT_STATUS + }, + time: { + status: DEFAULT_STATUS + }, + overall: { + isReady: false, + status: DEFAULT_STATUS, + message: [] + } + }, netChain: DEFAULT_NETCHAIN, netPeers: { active: new BigNumber(0), diff --git a/js/src/shell/ParityBar/parityBar.js b/js/src/shell/ParityBar/parityBar.js index e6300f0a5..9a058a552 100644 --- a/js/src/shell/ParityBar/parityBar.js +++ b/js/src/shell/ParityBar/parityBar.js @@ -23,7 +23,7 @@ import { Link } from 'react-router'; import { connect } from 'react-redux'; import store from 'store'; -import { AccountCard, Badge, Button, ContainerTitle, IdentityIcon, SelectionList } from '@parity/ui'; +import { AccountCard, Badge, Button, ContainerTitle, IdentityIcon, SelectionList, StatusIndicator } from '@parity/ui'; import { CancelIcon, FingerprintIcon } from '@parity/ui/Icons'; import imagesEthcoreBlock from '@parity/shared/assets/images/parity-logo-white-no-text.svg'; @@ -52,7 +52,8 @@ class ParityBar extends Component { static propTypes = { dapp: PropTypes.bool, externalLink: PropTypes.string, - pending: PropTypes.array + pending: PropTypes.array, + health: PropTypes.object }; state = { @@ -212,7 +213,7 @@ class ParityBar extends Component { } renderBar () { - const { dapp } = this.props; + const { dapp, health } = this.props; if (!dapp) { return null; @@ -220,6 +221,13 @@ class ParityBar extends Component { return (
+