diff --git a/substrate/.gitignore b/substrate/.gitignore index 1b70fb7bcb..2e0651ba43 100644 --- a/substrate/.gitignore +++ b/substrate/.gitignore @@ -1,4 +1,4 @@ -/target/ +**/target/ **/*.rs.bk *.swp .wasm-binaries diff --git a/substrate/Cargo.lock b/substrate/Cargo.lock index feca17eb64..21e7829a7b 100644 --- a/substrate/Cargo.lock +++ b/substrate/Cargo.lock @@ -252,11 +252,11 @@ dependencies = [ [[package]] name = "cid" version = "0.2.3" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "integer-encoding 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "multibase 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "multihash 0.8.1-pre (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multihash 0.8.1-pre (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", ] [[package]] @@ -401,7 +401,7 @@ dependencies = [ [[package]] name = "datastore" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "base64 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "chashmap 2.2.1 (git+https://github.com/redox-os/tfs)", @@ -603,11 +603,6 @@ dependencies = [ "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "ethcore-bytes" -version = "0.1.0" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" - [[package]] name = "ethcore-crypto" version = "0.1.0" @@ -724,17 +719,19 @@ dependencies = [ [[package]] name = "fixed-hash" -version = "0.1.3" -source = "git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm#8dc457899afdaf968ff7f16140b03d1e37b01d71" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ + "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "fixed-hash" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" +version = "0.2.2" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", @@ -829,11 +826,10 @@ dependencies = [ [[package]] name = "hashdb" -version = "0.1.1" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" +version = "0.2.1" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1044,15 +1040,6 @@ dependencies = [ "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "keccak-hash" -version = "0.1.2" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" -dependencies = [ - "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "kernel32-sys" version = "0.2.2" @@ -1065,35 +1052,34 @@ dependencies = [ [[package]] name = "kvdb" version = "0.1.0" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)", + "parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common)", ] [[package]] name = "kvdb-memorydb" version = "0.1.0" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ - "kvdb 0.1.0 (git+https://github.com/paritytech/parity.git)", - "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common)", + "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "kvdb-rocksdb" version = "0.1.0" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "fs-swap 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "interleaved-ordered 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "kvdb 0.1.0 (git+https://github.com/paritytech/parity.git)", + "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)", - "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", + "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", "rocksdb 0.4.5 (git+https://github.com/paritytech/rust-rocksdb)", ] @@ -1126,26 +1112,26 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "libp2p" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-dns 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-floodsub 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-identify 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-kad 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-mplex 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-peerstore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-ping 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-ratelimit 0.1.1 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-relay 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-secio 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-tcp-transport 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-transport-timeout 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-websocket 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-yamux 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-dns 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-floodsub 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-identify 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-kad 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-mplex 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-peerstore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-ping 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-ratelimit 0.1.1 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-relay 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-secio 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-tcp-transport 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-transport-timeout 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-websocket 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-yamux 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "stdweb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-current-thread 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1155,20 +1141,20 @@ dependencies = [ [[package]] name = "libp2p-core" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bs58 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "multihash 0.8.1-pre (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "multistream-select 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "multihash 0.8.1-pre (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "multistream-select 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "rw-stream-sink 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "smallvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1176,12 +1162,12 @@ dependencies = [ [[package]] name = "libp2p-dns" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "tokio-dns-unofficial 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1189,60 +1175,60 @@ dependencies = [ [[package]] name = "libp2p-floodsub" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bs58 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.6.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", ] [[package]] name = "libp2p-identify" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-peerstore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-peerstore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", ] [[package]] name = "libp2p-kad" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)", "bigint 4.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "bs58 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "datastore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "datastore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-identify 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-ping 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-identify 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-ping 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1250,35 +1236,35 @@ dependencies = [ "tokio-codec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", - "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", ] [[package]] name = "libp2p-mplex" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", ] [[package]] name = "libp2p-peerstore" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bs58 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", - "datastore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "datastore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1287,14 +1273,14 @@ dependencies = [ [[package]] name = "libp2p-ping" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "multistream-select 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "multistream-select 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1304,11 +1290,11 @@ dependencies = [ [[package]] name = "libp2p-ratelimit" version = "0.1.1" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "aio-limited 0.1.0 (git+https://github.com/paritytech/aio-limited.git)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-executor 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1317,37 +1303,37 @@ dependencies = [ [[package]] name = "libp2p-relay" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "libp2p-peerstore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "libp2p-peerstore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "protobuf 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-codec 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", ] [[package]] name = "libp2p-secio" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "asn1_der 0.5.4 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "protobuf 2.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)", "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", - "rw-stream-sink 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "rw-stream-sink 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1355,12 +1341,12 @@ dependencies = [ [[package]] name = "libp2p-tcp-transport" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "tk-listen 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-tcp 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1369,10 +1355,10 @@ dependencies = [ [[package]] name = "libp2p-transport-timeout" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-timer 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1380,13 +1366,13 @@ dependencies = [ [[package]] name = "libp2p-websocket" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", - "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", - "rw-stream-sink 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", + "rw-stream-sink 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "stdweb 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "websocket 0.20.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1395,11 +1381,11 @@ dependencies = [ [[package]] name = "libp2p-yamux" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", "yamux 0.1.0 (git+https://github.com/paritytech/yamux)", @@ -1475,16 +1461,14 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "memorydb" -version = "0.1.1" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" +version = "0.2.1" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.1.1 (git+https://github.com/paritytech/parity.git)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (git+https://github.com/paritytech/parity.git)", - "plain_hasher 0.1.0 (git+https://github.com/paritytech/parity.git)", - "rlp 0.2.1 (git+https://github.com/paritytech/parity.git)", + "plain_hasher 0.2.0 (git+https://github.com/paritytech/parity-common)", + "rlp 0.2.1 (git+https://github.com/paritytech/parity-common)", ] [[package]] @@ -1535,10 +1519,10 @@ dependencies = [ [[package]] name = "multiaddr" version = "0.3.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "byteorder 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "cid 0.2.3 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "cid 0.2.3 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "integer-encoding 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1553,7 +1537,7 @@ dependencies = [ [[package]] name = "multihash" version = "0.8.1-pre" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "sha1 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "sha2 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1563,14 +1547,14 @@ dependencies = [ [[package]] name = "multistream-select" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "tokio-io 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", - "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", ] [[package]] @@ -1685,6 +1669,23 @@ dependencies = [ "stable_deref_trait 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "parity-bytes" +version = "0.1.0" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" + +[[package]] +name = "parity-crypto" +version = "0.1.0" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" +dependencies = [ + "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quick-error 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)", + "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "parity-wasm" version = "0.31.0" @@ -1743,20 +1744,14 @@ dependencies = [ [[package]] name = "patricia-trie" -version = "0.1.0" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" +version = "0.2.1" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)", - "ethcore-logger 1.12.0 (git+https://github.com/paritytech/parity.git)", - "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.1.1 (git+https://github.com/paritytech/parity.git)", - "keccak-hash 0.1.2 (git+https://github.com/paritytech/parity.git)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "memorydb 0.1.1 (git+https://github.com/paritytech/parity.git)", + "parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "rlp 0.2.1 (git+https://github.com/paritytech/parity.git)", - "triehash 0.1.0 (git+https://github.com/paritytech/parity.git)", ] [[package]] @@ -1771,11 +1766,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "plain_hasher" -version = "0.1.0" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" +version = "0.2.0" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2021,7 +2015,7 @@ dependencies = [ [[package]] name = "rlp" version = "0.2.1" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" dependencies = [ "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2104,7 +2098,7 @@ dependencies = [ [[package]] name = "rw-stream-sink" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2388,6 +2382,7 @@ dependencies = [ "substrate-runtime-primitives 0.1.0", "substrate-service 0.3.0", "substrate-telemetry 0.3.0", + "sysinfo 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2400,9 +2395,13 @@ dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", + "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "patricia-trie 0.2.1 (git+https://github.com/paritytech/parity-common)", + "rlp 0.2.1 (git+https://github.com/paritytech/parity-common)", "slog 2.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-bft 0.1.0", "substrate-codec 0.1.0", @@ -2422,15 +2421,13 @@ dependencies = [ name = "substrate-client-db" version = "0.1.0" dependencies = [ - "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.1.1 (git+https://github.com/paritytech/parity.git)", - "kvdb 0.1.0 (git+https://github.com/paritytech/parity.git)", - "kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity.git)", - "kvdb-rocksdb 0.1.0 (git+https://github.com/paritytech/parity.git)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", + "kvdb 0.1.0 (git+https://github.com/paritytech/parity-common)", + "kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity-common)", + "kvdb-rocksdb 0.1.0 (git+https://github.com/paritytech/parity-common)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "memorydb 0.1.1 (git+https://github.com/paritytech/parity.git)", + "memorydb 0.2.1 (git+https://github.com/paritytech/parity-common)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "patricia-trie 0.1.0 (git+https://github.com/paritytech/parity.git)", "substrate-client 0.1.0", "substrate-codec 0.1.0", "substrate-codec-derive 0.1.0", @@ -2467,6 +2464,7 @@ dependencies = [ "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "ed25519 0.1.0", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2479,6 +2477,7 @@ dependencies = [ "substrate-runtime-version 0.1.0", "substrate-serializer 0.1.0", "substrate-state-machine 0.1.0", + "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "triehash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "wabt 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2495,7 +2494,7 @@ dependencies = [ "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", - "transaction-pool 1.12.1 (registry+https://github.com/rust-lang/crates.io-index)", + "transaction-pool 1.12.3 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2513,8 +2512,8 @@ version = "0.1.0" dependencies = [ "ed25519 0.1.0", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-crypto 0.1.0 (git+https://github.com/paritytech/parity.git)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-crypto 0.1.0 (git+https://github.com/paritytech/parity-common)", "rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2567,7 +2566,6 @@ dependencies = [ "assert_matches 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)", "ethcore-io 1.12.0 (git+https://github.com/paritytech/parity.git)", "ethcore-logger 1.12.0 (git+https://github.com/paritytech/parity.git)", "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2575,8 +2573,9 @@ dependencies = [ "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", "futures 0.1.21 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", - "libp2p 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)", + "libp2p 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common)", "parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)", "rand 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)", "tokio 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2592,8 +2591,14 @@ dependencies = [ "blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)", + "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "fixed-hash 0.2.2 (git+https://github.com/paritytech/parity-common)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", + "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", + "patricia-trie 0.2.1 (git+https://github.com/paritytech/parity-common)", + "plain_hasher 0.2.0 (git+https://github.com/paritytech/parity-common)", "pretty_assertions 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", + "rlp 0.2.1 (git+https://github.com/paritytech/parity-common)", "rustc-hex 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2601,8 +2606,9 @@ dependencies = [ "substrate-codec-derive 0.1.0", "substrate-runtime-std 0.1.0", "substrate-serializer 0.1.0", + "tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", - "uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)", + "uint 0.3.0 (git+https://github.com/paritytech/parity-common)", "wasmi 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2638,6 +2644,7 @@ dependencies = [ "jsonrpc-pubsub 8.0.1 (git+https://github.com/paritytech/jsonrpc.git)", "jsonrpc-ws-server 8.0.0 (git+https://github.com/paritytech/jsonrpc.git)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-rpc 0.1.0", "substrate-runtime-primitives 0.1.0", ] @@ -2668,6 +2675,7 @@ dependencies = [ "serde 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.70 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", + "substrate-primitives 0.1.0", "substrate-runtime-consensus 0.1.0", "substrate-runtime-io 0.1.0", "substrate-runtime-primitives 0.1.0", @@ -2959,15 +2967,16 @@ name = "substrate-state-machine" version = "0.1.0" dependencies = [ "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "hashdb 0.1.1 (git+https://github.com/paritytech/parity.git)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", + "heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", - "memorydb 0.1.1 (git+https://github.com/paritytech/parity.git)", + "memorydb 0.2.1 (git+https://github.com/paritytech/parity-common)", "parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "patricia-trie 0.1.0 (git+https://github.com/paritytech/parity.git)", + "patricia-trie 0.2.1 (git+https://github.com/paritytech/parity-common)", + "rlp 0.2.1 (git+https://github.com/paritytech/parity-common)", "substrate-primitives 0.1.0", - "triehash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "triehash 0.2.0 (git+https://github.com/paritytech/parity-common)", ] [[package]] @@ -2988,6 +2997,7 @@ dependencies = [ name = "substrate-test-client" version = "0.1.0" dependencies = [ + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", "rhododendron 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-bft 0.1.0", "substrate-client 0.1.0", @@ -3035,6 +3045,17 @@ dependencies = [ "unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "sysinfo" +version = "0.5.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)", + "rayon 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "take" version = "0.1.0" @@ -3340,26 +3361,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "transaction-pool" -version = "1.12.1" +version = "1.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", - "log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)", "smallvec 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)", "trace-time 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "triehash" -version = "0.1.0" -source = "git+https://github.com/paritytech/parity.git#4145be863bec10038fc0ac5d36a41365b5087344" -dependencies = [ - "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", - "ethereum-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "keccak-hash 0.1.2 (git+https://github.com/paritytech/parity.git)", - "rlp 0.2.1 (git+https://github.com/paritytech/parity.git)", -] - [[package]] name = "triehash" version = "0.1.2" @@ -3371,6 +3381,16 @@ dependencies = [ "rlp 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "triehash" +version = "0.2.0" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" +dependencies = [ + "elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", + "rlp 0.2.1 (git+https://github.com/paritytech/parity-common)", +] + [[package]] name = "try-lock" version = "0.1.0" @@ -3399,16 +3419,6 @@ name = "ucd-util" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "uint" -version = "0.1.2" -source = "git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm#8dc457899afdaf968ff7f16140b03d1e37b01d71" -dependencies = [ - "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", - "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "uint" version = "0.2.1" @@ -3420,6 +3430,16 @@ dependencies = [ "rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "uint" +version = "0.3.0" +source = "git+https://github.com/paritytech/parity-common#22209e14805e5764f7fe81259324d34eab179264" +dependencies = [ + "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", + "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "rustc-hex 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "unicase" version = "1.4.2" @@ -3500,7 +3520,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "varint" version = "0.1.0" -source = "git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2#6aa139a12dbea3d75d898ce0b2af7fcec129e294" +source = "git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294#6aa139a12dbea3d75d898ce0b2af7fcec129e294" dependencies = [ "bytes 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "error-chain 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -3704,7 +3724,7 @@ dependencies = [ "checksum cfg-if 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "405216fd8fe65f718daa7102ea808a946b6ce40c742998fbfd3463645552de18" "checksum chashmap 2.2.1 (git+https://github.com/redox-os/tfs)" = "" "checksum chrono 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1cce36c92cb605414e9b824f866f5babe0a0368e39ea07393b9b63cf3844c0e6" -"checksum cid 0.2.3 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" +"checksum cid 0.2.3 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" "checksum clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b957d88f4b6a63b9d70d5f454ac8011819c6efa7727858f458ab71c756ce2d3e" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" "checksum cmake 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "95470235c31c726d72bf2e1f421adc1e65b9d561bf5529612cbe1a72da1467b3" @@ -3721,7 +3741,7 @@ dependencies = [ "checksum crossbeam-utils 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "d636a8b3bcc1b409d7ffd3facef8f21dcb4009626adbd0c5e6c4305c07253c7b" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" "checksum ctrlc 1.1.1 (git+https://github.com/paritytech/rust-ctrlc.git)" = "" -"checksum datastore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" +"checksum datastore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" "checksum difference 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b3304d19798a8e067e48d8e69b2c37f0b5e9b4e462504ad9e27e9f3fce02bba8" "checksum digest 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)" = "3cae2388d706b52f2f2f9afe280f9d768be36544bd71d1b8120cb34ea6450b55" "checksum dtoa 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "09c3753c3db574d215cba4ea76018483895d7bff25a31b49ba45db21c48e50ab" @@ -3733,7 +3753,6 @@ dependencies = [ "checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02" "checksum eth-secp256k1 0.5.7 (git+https://github.com/paritytech/rust-secp256k1)" = "" "checksum ethbloom 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1a93a43ce2e9f09071449da36bfa7a1b20b950ee344b6904ff23de493b03b386" -"checksum ethcore-bytes 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" "checksum ethcore-crypto 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" "checksum ethcore-io 1.12.0 (git+https://github.com/paritytech/parity.git)" = "" "checksum ethcore-logger 1.12.0 (git+https://github.com/paritytech/parity.git)" = "" @@ -3744,8 +3763,8 @@ dependencies = [ "checksum exit-future 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "9aa7b56cef68c4182db7212dece19cc9f6e2916cf9412e57e6cea53ec02f316d" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" "checksum fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b1ee15a7050e5580b3712877157068ea713b245b080ff302ae2ca973cfcd9baa" -"checksum fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "" "checksum fixed-hash 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18d6fd718fb4396e7a9c93ac59ba7143501467ca7a143c145b5555a571d5576" +"checksum fixed-hash 0.2.2 (git+https://github.com/paritytech/parity-common)" = "" "checksum fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "2fad85553e09a6f881f739c29f0b00b0f01357c743266d478b68951ce23285f3" "checksum foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f6f339eb8adc052cd2ca78910fda869aefa38d22d5cb648e6485e4d3fc06f3b1" "checksum foreign-types-shared 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" @@ -3758,7 +3777,7 @@ dependencies = [ "checksum generic-array 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef25c5683767570c2bbd7deba372926a55eaae9982d7726ee2a1050239d45b9d" "checksum getopts 0.2.17 (registry+https://github.com/rust-lang/crates.io-index)" = "b900c08c1939860ce8b54dc6a89e26e00c04c380fd0e09796799bd7f12861e05" "checksum globset 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "142754da2c9b3722affd909f9e27f2a6700a7a303f362971e0a74c652005a43d" -"checksum hashdb 0.1.1 (git+https://github.com/paritytech/parity.git)" = "" +"checksum hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)" = "" "checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" "checksum hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4da5f0e01bd8a71a224a4eedecaacfcabda388dbb7a80faf04d3514287572d95" @@ -3780,32 +3799,31 @@ dependencies = [ "checksum jsonrpc-server-utils 8.0.1 (git+https://github.com/paritytech/jsonrpc.git)" = "" "checksum jsonrpc-ws-server 8.0.0 (git+https://github.com/paritytech/jsonrpc.git)" = "" "checksum keccak-hash 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b7f51f30d7986536accaec4a6a288008dfb3dbffe8a2863a65292bc395a3ae7" -"checksum keccak-hash 0.1.2 (git+https://github.com/paritytech/parity.git)" = "" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum kvdb 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" -"checksum kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" -"checksum kvdb-rocksdb 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" +"checksum kvdb 0.1.0 (git+https://github.com/paritytech/parity-common)" = "" +"checksum kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity-common)" = "" +"checksum kvdb-rocksdb 0.1.0 (git+https://github.com/paritytech/parity-common)" = "" "checksum language-tags 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a91d884b6667cd606bb5a69aa0c99ba811a115fc68915e7056ec08a46e93199a" "checksum lazy_static 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "76f033c7ad61445c5b347c7382dd1237847eb1bce590fe50365dcb33d546be73" "checksum lazy_static 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e6412c5e2ad9584b0b8e979393122026cdd6d2a80b933f890dcd694ddbe73739" "checksum lazycell 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a6f08839bc70ef4a3fe1d566d5350f519c5912ea86be0df1740a7d247c7fc0ef" "checksum libc 0.2.41 (registry+https://github.com/rust-lang/crates.io-index)" = "ac8ebf8343a981e2fa97042b14768f02ed3e1d602eac06cae6166df3c8ced206" -"checksum libp2p 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-dns 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-floodsub 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-identify 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-kad 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-mplex 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-peerstore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-ping 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-ratelimit 0.1.1 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-relay 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-secio 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-tcp-transport 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-transport-timeout 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-websocket 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum libp2p-yamux 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" +"checksum libp2p 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-core 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-dns 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-floodsub 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-identify 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-kad 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-mplex 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-peerstore 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-ping 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-ratelimit 0.1.1 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-relay 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-secio 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-tcp-transport 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-transport-timeout 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-websocket 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum libp2p-yamux 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" "checksum linked-hash-map 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "70fb39025bc7cdd76305867c4eccf2f2dcf6e9a57f5b21a93e1c2d86cd03ec9e" "checksum local-encoding 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1ceb20f39ff7ae42f3ff9795f3986b1daad821caaa1e1732a0944103a5a1a66" "checksum lock_api 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "949826a5ccf18c1b3a7c3d57692778d21768b79e46eb9dd07bfc4c2160036c54" @@ -3816,15 +3834,15 @@ dependencies = [ "checksum memchr 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "796fba70e76612589ed2ce7f45282f5af869e0fdd7cc6199fa1aa1f1d591ba9d" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" -"checksum memorydb 0.1.1 (git+https://github.com/paritytech/parity.git)" = "" +"checksum memorydb 0.2.1 (git+https://github.com/paritytech/parity-common)" = "" "checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0" "checksum mime 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "0b28683d0b09bbc20be1c9b3f6f24854efb1356ffcffee08ea3f6e65596e85fa" "checksum mio 0.6.14 (registry+https://github.com/rust-lang/crates.io-index)" = "6d771e3ef92d58a8da8df7d6976bfca9371ed1de6619d9d5a5ce5b1f29b85bfe" "checksum miow 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8c1f2f3b1cf331de6896aabf6e9d55dca90356cc9960cca7eaaf408a355ae919" -"checksum multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" +"checksum multiaddr 0.3.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" "checksum multibase 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b9c35dac080fd6e16a99924c8dfdef0af89d797dd851adab25feaffacf7850d6" -"checksum multihash 0.8.1-pre (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" -"checksum multistream-select 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" +"checksum multihash 0.8.1-pre (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" +"checksum multistream-select 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" "checksum names 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ef320dab323286b50fb5cdda23f61c796a72a89998ab565ca32525c5c556f2da" "checksum nan-preserving-float 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "34d4f00fcc2f4c9efa8cc971db0da9e28290e28e97af47585e48691ef10ff31f" "checksum native-tls 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "f74dbadc8b43df7864539cedb7bc91345e532fdd913cfdc23ad94f4d2d40fbc0" @@ -3838,16 +3856,18 @@ dependencies = [ "checksum openssl 0.9.24 (registry+https://github.com/rust-lang/crates.io-index)" = "a3605c298474a3aa69de92d21139fb5e2a81688d308262359d85cdd0d12a7985" "checksum openssl-sys 0.9.33 (registry+https://github.com/rust-lang/crates.io-index)" = "d8abc04833dcedef24221a91852931df2f63e3369ae003134e70aff3645775cc" "checksum owning_ref 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "cdf84f41639e037b484f93433aa3897863b561ed65c6e59c7073d7c561710f37" +"checksum parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common)" = "" +"checksum parity-crypto 0.1.0 (git+https://github.com/paritytech/parity-common)" = "" "checksum parity-wasm 0.31.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e1c91199d14bd5b78ecade323d4a891d094799749c1b9e82d9c590c2e2849a40" "checksum parity-wordlist 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1d0dec124478845b142f68b446cbee953d14d4b41f1bc0425024417720dce693" "checksum parking_lot 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "149d8f5b97f3c1133e3cfcd8886449959e856b557ff281e292b733d7c69e005e" "checksum parking_lot 0.5.5 (registry+https://github.com/rust-lang/crates.io-index)" = "d4d05f1349491390b1730afba60bb20d55761bef489a954546b58b4b34e1e2ac" "checksum parking_lot 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "901d6514273469bb17380c1ac3f51fb3ce54be1f960e51a6f04901eba313ab8d" "checksum parking_lot_core 0.2.14 (registry+https://github.com/rust-lang/crates.io-index)" = "4db1a8ccf734a7bce794cc19b3df06ed87ab2f3907036b693c68f56b4d4537fa" -"checksum patricia-trie 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" +"checksum patricia-trie 0.2.1 (git+https://github.com/paritytech/parity-common)" = "" "checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pkg-config 0.3.11 (registry+https://github.com/rust-lang/crates.io-index)" = "110d5ee3593dbb73f56294327fe5668bcc997897097cbc76b51e7aed3f52452f" -"checksum plain_hasher 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" +"checksum plain_hasher 0.2.0 (git+https://github.com/paritytech/parity-common)" = "" "checksum pretty_assertions 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28ea5118e2f41bfbc974b28d88c07621befd1fa5d6ec23549be96302a1a59dd2" "checksum proc-macro-hack 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ba8d4f9257b85eb6cdf13f055cea3190520aab1409ca2ab43493ea4820c25f0" "checksum proc-macro-hack-impl 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d5cb6f960ad471404618e9817c0e5d10b1ae74cfdf01fab89ea0641fe7fb2892" @@ -3875,7 +3895,7 @@ dependencies = [ "checksum remove_dir_all 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3488ba1b9a2084d38645c4c08276a1752dcbf2c7130d74f1569681ad5d2799c5" "checksum rhododendron 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "3d2b4c928dfb981e491432f0809e93c99857112b0a348a93eee6b13e0bf0f0f3" "checksum ring 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6f7d28b30a72c01b458428e0ae988d4149c20d902346902be881e3edc4bb325c" -"checksum rlp 0.2.1 (git+https://github.com/paritytech/parity.git)" = "" +"checksum rlp 0.2.1 (git+https://github.com/paritytech/parity-common)" = "" "checksum rlp 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "89db7f8dfdd5eb7ab3ac3ece7a07fd273a680b4b224cb231181280e8996f9f0b" "checksum rocksdb 0.4.5 (git+https://github.com/paritytech/rust-rocksdb)" = "" "checksum rocksdb-sys 0.3.0 (git+https://github.com/paritytech/rust-rocksdb)" = "" @@ -3885,7 +3905,7 @@ dependencies = [ "checksum rustc-hex 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2b03280c2813907a030785570c577fb27d3deec8da4c18566751ade94de0ace" "checksum rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)" = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" "checksum rustc_version 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a54aa04a10c68c1c4eacb4337fd883b435997ede17a9385784b990777686b09a" -"checksum rw-stream-sink 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" +"checksum rw-stream-sink 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" "checksum safe-mix 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7f7bf422d23a88c16d5090d455f182bc99c60af4df6a345c63428acf5129e347" "checksum safemem 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e27a8b19b835f7aea908818e871f5cc3a5a186550c30773be987e155e8163d8f" "checksum schannel 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "85fd9df495640643ad2d00443b3d78aae69802ad488debab4f1dd52fc1806ade" @@ -3919,6 +3939,7 @@ dependencies = [ "checksum strsim 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bb4f380125926a99e52bc279241539c018323fab05ad6368b56f93d9369ff550" "checksum subtle 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "dc7f6353c2ee5407358d063a14cccc1630804527090a6fb5a9489ce4924280fb" "checksum syn 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)" = "6dfd71b2be5a58ee30a6f8ea355ba8290d397131c00dfa55c3d34e6e13db5101" +"checksum sysinfo 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "394abcf30852ac00878ab01642b13668db48d166d945f250c7bdbb9e12d75ad0" "checksum take 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b157868d8ac1f56b64604539990685fa7611d8fa9e5476cf0c02cf34d32917c5" "checksum take_mut 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "f764005d11ee5f36500a149ace24e00e3da98b0158b3e2d53a7495660d3f4d60" "checksum target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c63f48baada5c52e65a29eef93ab4f8982681b67f9e8d29c7b05abcfec2b9ffe" @@ -3949,16 +3970,16 @@ dependencies = [ "checksum tokio-udp 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "137bda266504893ac4774e0ec4c2108f7ccdbcb7ac8dced6305fe9e4e0b5041a" "checksum trace-time 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5aea07da6582e957c6e737eeb63a5af79e648eeeaaaba8fd9a417f1124bafa41" "checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079" -"checksum transaction-pool 1.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "be1efb673ddf49ab4a99893eb3af02f6563636033fb832c2b7f937641ad62b17" -"checksum triehash 0.1.0 (git+https://github.com/paritytech/parity.git)" = "" +"checksum transaction-pool 1.12.3 (registry+https://github.com/rust-lang/crates.io-index)" = "0f1fc049d9f039d3e9264f97f978309b94b5a5c56a5c18d28f91f469cef2b367" "checksum triehash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2033893a813c70e7d8a739ca6c36dc0a7a2c913ec718d7cbf84a3837bbe3c7ce" +"checksum triehash 0.2.0 (git+https://github.com/paritytech/parity-common)" = "" "checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2" "checksum twox-hash 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "475352206e7a290c5fccc27624a163e8d0d115f7bb60ca18a64fc9ce056d7435" "checksum typeable 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1410f6f91f21d1612654e7cc69193b0334f909dcf2c790c4826254fbb86f8887" "checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" "checksum ucd-util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "fd2be2d6639d0f8fe6cdda291ad456e23629558d466e2789d2c3e9892bda285d" -"checksum uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "" "checksum uint 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "38051a96565903d81c9a9210ce11076b2218f3b352926baa1f5f6abbdfce8273" +"checksum uint 0.3.0 (git+https://github.com/paritytech/parity-common)" = "" "checksum unicase 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7f4765f83163b74f957c797ad9253caf97f103fb064d3999aea9568d09fc8a33" "checksum unicase 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "284b6d3db520d67fbe88fd778c21510d1b0ba4a551e5d0fbb023d33405f6de8a" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" @@ -3970,7 +3991,7 @@ dependencies = [ "checksum untrusted 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f392d7819dbe58833e26872f5f6f0d68b7bbbe90fc3667e98731c4a15ad9a7ae" "checksum url 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "f808aadd8cfec6ef90e4a14eb46f24511824d1ac596b9682703c87056c8678b7" "checksum utf8-ranges 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "662fab6525a98beff2921d7f61a39e7d59e0b425ebc7d0d9e66d316e55124122" -"checksum varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?branch=polkadot-2)" = "" +"checksum varint 0.1.0 (git+https://github.com/tomaka/libp2p-rs?rev=6aa139a12dbea3d75d898ce0b2af7fcec129e294)" = "" "checksum vcpkg 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "7ed0f6789c8a85ca41bbc1c9d175422116a9869bd1cf31bb08e1493ecce60380" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "6b772017e347561807c1aa192438c5fd74242a670a6cffacc40f2defd1dc069d" diff --git a/substrate/demo/cli/src/lib.rs b/substrate/demo/cli/src/lib.rs index 7a8869db84..27a317e45f 100644 --- a/substrate/demo/cli/src/lib.rs +++ b/substrate/demo/cli/src/lib.rs @@ -59,6 +59,7 @@ use demo_executor::NativeExecutor; struct DummyPool; impl extrinsic_pool::api::ExtrinsicPool for DummyPool { type Error = extrinsic_pool::txpool::Error; + type InPool = (); fn submit(&self, _block: BlockId, _: Vec) -> Result, Self::Error> @@ -79,6 +80,10 @@ impl extrinsic_pool::api::ExtrinsicPool for D fn import_notification_stream(&self) -> extrinsic_pool::api::EventStream { unreachable!() } + + fn all(&self) -> Self::InPool { + unreachable!() + } } struct DummySystem; @@ -176,7 +181,7 @@ pub fn run(args: I) -> error::Result<()> where let state = rpc::apis::state::State::new(client.clone(), runtime.executor()); let chain = rpc::apis::chain::Chain::new(client.clone(), runtime.executor()); let author = rpc::apis::author::Author::new(client.clone(), Arc::new(DummyPool), runtime.executor()); - rpc::rpc_handler::(state, chain, author, DummySystem) + rpc::rpc_handler::(state, chain, author, DummySystem) }; let http_address = "127.0.0.1:9933".parse().unwrap(); let ws_address = "127.0.0.1:9944".parse().unwrap(); diff --git a/substrate/demo/executor/src/lib.rs b/substrate/demo/executor/src/lib.rs index 5ebece1f60..ed028a5c20 100644 --- a/substrate/demo/executor/src/lib.rs +++ b/substrate/demo/executor/src/lib.rs @@ -47,7 +47,7 @@ mod tests { use keyring::Keyring; use runtime_support::{Hashable, StorageValue, StorageMap}; use state_machine::{CodeExecutor, TestExternalities}; - use primitives::twox_128; + use primitives::{twox_128, KeccakHasher}; use demo_primitives::{Hash, BlockNumber, AccountId}; use runtime_primitives::traits::Header as HeaderT; use runtime_primitives::{ApplyOutcome, ApplyError, ApplyResult, MaybeUnsigned}; @@ -100,7 +100,7 @@ mod tests { #[test] fn panic_execution_with_foreign_code_gives_error() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![70u8; 8], twox_128(>::key()).to_vec() => vec![0u8; 8], @@ -119,7 +119,7 @@ mod tests { #[test] fn bad_extrinsic_with_native_equivalent_code_gives_error() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![70u8; 8], twox_128(>::key()).to_vec() => vec![0u8; 8], @@ -138,7 +138,7 @@ mod tests { #[test] fn successful_execution_with_native_equivalent_code_gives_ok() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![0u8; 8], twox_128(>::key()).to_vec() => vec![0u8; 8], @@ -161,7 +161,7 @@ mod tests { #[test] fn successful_execution_with_foreign_code_gives_ok() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![0u8; 8], twox_128(>::key()).to_vec() => vec![0u8; 8], @@ -182,7 +182,7 @@ mod tests { }); } - fn new_test_ext() -> TestExternalities { + fn new_test_ext() -> TestExternalities { use keyring::Keyring::*; let three = [3u8; 32].into(); GenesisConfig { @@ -212,7 +212,7 @@ mod tests { democracy: Some(Default::default()), council: Some(Default::default()), timestamp: Some(Default::default()), - }.build_storage().unwrap() + }.build_storage().unwrap().into() } fn construct_block(number: BlockNumber, parent_hash: Hash, state_root: Hash, extrinsics: Vec) -> (Vec, Hash) { @@ -247,7 +247,10 @@ mod tests { construct_block( 1, [69u8; 32].into(), - hex!("b97d52254fc967bb94bed485de6a738e9fad05decfda3453711677b8becf6d0a").into(), + // Blake + // hex!("3437bf4b182ab17bb322af5c67e55f6be487a77084ad2b4e27ddac7242e4ad21").into(), + // Keccak + hex!("c563199c60df7d914262b1775b284870f3a5da2f24b56d2c6288b37c815a6cd9").into(), vec![BareExtrinsic { signed: alice(), index: 0, @@ -260,7 +263,43 @@ mod tests { construct_block( 2, block1().1, - hex!("a1f018d2faa339f72f5ee29050b4670d971e2e271cc06c41ee9cbe1f4c6feec9").into(), + // Blake + // hex!("741fcb660e6fa9f625fbcd993b49f6c1cc4040f5e0cc8727afdedf11fd3c464b").into(), + // Keccak + hex!("83f71d5475f63350825b0301de322233d3711a9f3fcfd74050d1534af47a36b3").into(), + vec![ + BareExtrinsic { + signed: bob(), + index: 0, + function: Call::Staking(staking::Call::transfer(alice().into(), 5)), + }, + BareExtrinsic { + signed: alice(), + index: 1, + function: Call::Staking(staking::Call::transfer(bob().into(), 15)), + } + ] + ) + } + + fn block1_wasm() -> (Vec, Hash) { + construct_block( + 1, + [69u8; 32].into(), + hex!("b97d52254fc967bb94bed485de6a738e9fad05decfda3453711677b8becf6d0a").into(), + vec![BareExtrinsic { + signed: alice(), + index: 0, + function: Call::Staking(staking::Call::transfer(bob().into(), 69)), + }] + ) + } + + fn block2_wasm() -> (Vec, Hash) { + construct_block( + 2, + block1().1, + hex!("b820fe09935dba41d200b627c11bd7dd9ebff39c319dee18be3ee4f99fc1eab4").into(), vec![ BareExtrinsic { signed: bob(), @@ -280,7 +319,10 @@ mod tests { construct_block( 1, [69u8; 32].into(), - hex!("41d07010f49aa29b2c9aca542cbaa6f59aafd3dda53cdf711c51ddb7d386912e").into(), + // Blake + // hex!("2c7231a9c210a7aa4bea169d944bc4aaacd517862b244b8021236ffa7f697991").into(), + // Keccak + hex!("06d026c0d687ec583660a6052de6f89acdb24ea964d06be3831c837c3c426966").into(), vec![BareExtrinsic { signed: alice(), index: 0, @@ -312,14 +354,14 @@ mod tests { fn full_wasm_block_import_works() { let mut t = new_test_ext(); - WasmExecutor::new(8).call(&mut t, COMPACT_CODE, "execute_block", &block1().0).unwrap(); + WasmExecutor::new(8).call(&mut t, COMPACT_CODE, "execute_block", &block1_wasm().0).unwrap(); runtime_io::with_externalities(&mut t, || { assert_eq!(Staking::voting_balance(&alice()), 41); assert_eq!(Staking::voting_balance(&bob()), 69); }); - WasmExecutor::new(8).call(&mut t, COMPACT_CODE, "execute_block", &block2().0).unwrap(); + WasmExecutor::new(8).call(&mut t, COMPACT_CODE, "execute_block", &block2_wasm().0).unwrap(); runtime_io::with_externalities(&mut t, || { assert_eq!(Staking::voting_balance(&alice()), 30); @@ -353,7 +395,7 @@ mod tests { #[test] fn panic_execution_gives_error() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![69u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![70u8; 8], twox_128(>::key()).to_vec() => vec![0u8; 8], @@ -373,7 +415,7 @@ mod tests { #[test] fn successful_execution_gives_ok() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ twox_128(&>::key_for(alice())).to_vec() => vec![111u8, 0, 0, 0, 0, 0, 0, 0], twox_128(>::key()).to_vec() => vec![0u8; 8], twox_128(>::key()).to_vec() => vec![0u8; 8], diff --git a/substrate/substrate/cli/Cargo.toml b/substrate/substrate/cli/Cargo.toml index 723c568ba3..176d59bbe7 100644 --- a/substrate/substrate/cli/Cargo.toml +++ b/substrate/substrate/cli/Cargo.toml @@ -22,6 +22,7 @@ tokio = "0.1.7" futures = "0.1.17" fdlimit = "0.1" exit-future = "0.1" +sysinfo = "0.5.7" substrate-client = { path = "../../substrate/client" } substrate-extrinsic-pool = { path = "../../substrate/extrinsic-pool" } substrate-network = { path = "../../substrate/network" } diff --git a/substrate/substrate/cli/src/informant.rs b/substrate/substrate/cli/src/informant.rs index d980e74bb8..2cc61a8e83 100644 --- a/substrate/substrate/cli/src/informant.rs +++ b/substrate/substrate/cli/src/informant.rs @@ -22,6 +22,7 @@ use futures::{Future, Stream}; use service::{Service, Components}; use tokio::runtime::TaskExecutor; use tokio::timer::Interval; +use sysinfo::{get_current_pid, ProcessExt, System, SystemExt}; use network::{SyncState, SyncProvider}; use client::BlockchainEvents; use runtime_primitives::traits::{Header, As}; @@ -41,6 +42,9 @@ pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExe let txpool = service.extrinsic_pool(); let mut last_number = None; + let mut sys = System::new(); + let self_pid = get_current_pid(); + let display_notifications = interval.map_err(|e| debug!("Timer error: {:?}", e)).for_each(move |_| { let sync_status = network.status(); @@ -65,17 +69,27 @@ pub fn start(service: &Service, exit: ::exit_future::Exit, handle: TaskExe Colour::White.paint(format!("{}", best_number)), hash ); + + // get cpu usage and memory usage of this process + let (cpu_usage, memory) = if sys.refresh_process(self_pid) { + let proc = sys.get_process(self_pid).expect("Above refresh_process succeeds, this should be Some(), qed"); + (proc.cpu_usage(), proc.memory()) + } else { (0.0, 0) }; + telemetry!( "system.interval"; "status" => format!("{}{}", status, target), "peers" => num_peers, "height" => best_number, "best" => ?hash, - "txcount" => txpool_status.transaction_count + "txcount" => txpool_status.transaction_count, + "cpu" => cpu_usage, + "memory" => memory ); } else { warn!("Error getting best block information"); } + Ok(()) }); diff --git a/substrate/substrate/cli/src/lib.rs b/substrate/substrate/cli/src/lib.rs index a1064cccc4..f2dee51e45 100644 --- a/substrate/substrate/cli/src/lib.rs +++ b/substrate/substrate/cli/src/lib.rs @@ -30,6 +30,7 @@ extern crate futures; extern crate tokio; extern crate names; extern crate backtrace; +extern crate sysinfo; extern crate substrate_client as client; extern crate substrate_network as network; diff --git a/substrate/substrate/client/Cargo.toml b/substrate/substrate/client/Cargo.toml index 5b34739576..59ab16ba48 100644 --- a/substrate/substrate/client/Cargo.toml +++ b/substrate/substrate/client/Cargo.toml @@ -13,6 +13,7 @@ hex-literal = "0.1" futures = "0.1.17" ed25519 = { path = "../ed25519" } slog = "^2" +heapsize = "0.4" substrate-bft = { path = "../bft" } substrate-codec = { path = "../codec" } substrate-executor = { path = "../executor" } @@ -23,6 +24,9 @@ substrate-runtime-primitives = { path = "../runtime/primitives" } substrate-state-machine = { path = "../state-machine" } substrate-keyring = { path = "../../substrate/keyring" } substrate-telemetry = { path = "../telemetry" } +hashdb = { git = "https://github.com/paritytech/parity-common" } +patricia-trie = { git = "https://github.com/paritytech/parity-common" } +rlp = { git = "https://github.com/paritytech/parity-common" } [dev-dependencies] substrate-test-client = { path = "../test-client" } diff --git a/substrate/substrate/client/db/Cargo.toml b/substrate/substrate/client/db/Cargo.toml index 52805843aa..6fc8242335 100644 --- a/substrate/substrate/client/db/Cargo.toml +++ b/substrate/substrate/client/db/Cargo.toml @@ -6,12 +6,10 @@ authors = ["Parity Technologies "] [dependencies] parking_lot = "0.4" log = "0.3" -kvdb = { git = "https://github.com/paritytech/parity.git" } -kvdb-rocksdb = { git = "https://github.com/paritytech/parity.git" } -ethereum-types = "0.3" -hashdb = { git = "https://github.com/paritytech/parity.git" } -patricia-trie = { git = "https://github.com/paritytech/parity.git" } -memorydb = { git = "https://github.com/paritytech/parity.git" } +kvdb = { git = "https://github.com/paritytech/parity-common" } +kvdb-rocksdb = { git = "https://github.com/paritytech/parity-common" } +hashdb = { git = "https://github.com/paritytech/parity-common" } +memorydb = { git = "https://github.com/paritytech/parity-common" } substrate-primitives = { path = "../../../substrate/primitives" } substrate-runtime-primitives = { path = "../../../substrate/runtime/primitives" } substrate-client = { path = "../../../substrate/client" } @@ -23,4 +21,4 @@ substrate-executor = { path = "../../../substrate/executor" } substrate-state-db = { path = "../../../substrate/state-db" } [dev-dependencies] -kvdb-memorydb = { git = "https://github.com/paritytech/parity.git" } +kvdb-memorydb = { git = "https://github.com/paritytech/parity-common" } diff --git a/substrate/substrate/client/db/src/lib.rs b/substrate/substrate/client/db/src/lib.rs index 46ab7e654b..2fa5fb6151 100644 --- a/substrate/substrate/client/db/src/lib.rs +++ b/substrate/substrate/client/db/src/lib.rs @@ -46,19 +46,21 @@ mod utils; use std::sync::Arc; use std::path::PathBuf; +use std::io; use codec::{Decode, Encode}; +use hashdb::Hasher; use kvdb::{KeyValueDB, DBTransaction}; use memorydb::MemoryDB; use parking_lot::RwLock; -use primitives::{H256, AuthorityId}; +use primitives::{H256, AuthorityId, KeccakHasher, RlpCodec}; use runtime_primitives::generic::BlockId; use runtime_primitives::bft::Justification; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, As, Hash, HashFor, NumberFor, Zero}; use runtime_primitives::BuildStorage; use state_machine::backend::Backend as StateBackend; use executor::RuntimeInfo; -use state_machine::{CodeExecutor, TrieH256, DBValue, ExecutionStrategy}; +use state_machine::{CodeExecutor, DBValue, ExecutionStrategy}; use utils::{Meta, db_err, meta_keys, number_to_db_key, open_database, read_db, read_id, read_meta}; use state_db::StateDb; pub use state_db::PruningMode; @@ -66,7 +68,7 @@ pub use state_db::PruningMode; const FINALIZATION_WINDOW: u64 = 32; /// DB-backed patricia trie state, transaction type is an overlay of changes to commit. -pub type DbState = state_machine::TrieBackend; +pub type DbState = state_machine::TrieBackend; /// Database settings. pub struct DatabaseSettings { @@ -87,7 +89,7 @@ pub fn new_client( ) -> Result, client::LocalCallExecutor, E>, Block>, client::error::Error> where Block: BlockT, - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo, S: BuildStorage, { let backend = Arc::new(Backend::new(settings, FINALIZATION_WINDOW)?); @@ -116,7 +118,7 @@ struct PendingBlock { struct StateMetaDb<'a>(&'a KeyValueDB); impl<'a> state_db::MetaDb for StateMetaDb<'a> { - type Error = kvdb::Error; + type Error = io::Error; fn get_meta(&self, key: &[u8]) -> Result>, Self::Error> { self.0.get(columns::STATE_META, key).map(|r| r.map(|v| v.to_vec())) @@ -215,13 +217,16 @@ impl client::blockchain::Backend for BlockchainDb { } /// Database transaction -pub struct BlockImportOperation { +pub struct BlockImportOperation { old_state: DbState, - updates: MemoryDB, + updates: MemoryDB, pending_block: Option>, } -impl client::backend::BlockImportOperation for BlockImportOperation { +impl client::backend::BlockImportOperation +for BlockImportOperation +where Block: BlockT, +{ type State = DbState; fn state(&self) -> Result, client::error::Error> { @@ -243,7 +248,7 @@ impl client::backend::BlockImportOperation for BlockImport // currently authorities are not cached on full nodes } - fn update_storage(&mut self, update: MemoryDB) -> Result<(), client::error::Error> { + fn update_storage(&mut self, update: MemoryDB) -> Result<(), client::error::Error> { self.updates = update; Ok(()) } @@ -261,15 +266,15 @@ struct StorageDb { pub state_db: StateDb, } -impl state_machine::Storage for StorageDb { - fn get(&self, key: &TrieH256) -> Result, String> { +impl state_machine::Storage for StorageDb { + fn get(&self, key: &H256) -> Result, String> { self.state_db.get(&key.0.into(), self).map(|r| r.map(|v| DBValue::from_slice(&v))) .map_err(|e| format!("Database backend error: {:?}", e)) } } impl state_db::HashDb for StorageDb { - type Error = kvdb::Error; + type Error = io::Error; type Hash = H256; fn get(&self, key: &H256) -> Result>, Self::Error> { @@ -305,7 +310,7 @@ impl Backend { fn from_kvdb(db: Arc, pruning: PruningMode, finalization_window: u64) -> Result { let blockchain = BlockchainDb::new(db.clone())?; - let map_e = |e: state_db::Error| ::client::error::Error::from(format!("State database error: {:?}", e)); + let map_e = |e: state_db::Error| ::client::error::Error::from(format!("State database error: {:?}", e)); let state_db: StateDb = StateDb::new(pruning, &StateMetaDb(&*db)).map_err(map_e)?; let storage_db = StorageDb { db, @@ -335,8 +340,8 @@ fn apply_state_commit(transaction: &mut DBTransaction, commit: state_db::CommitS } } -impl client::backend::Backend for Backend { - type BlockImportOperation = BlockImportOperation; +impl client::backend::Backend for Backend where Block: BlockT { + type BlockImportOperation = BlockImportOperation; type Blockchain = BlockchainDb; type State = DbState; @@ -450,14 +455,14 @@ impl client::backend::Backend for Backend { } self.blockchain.header(block).and_then(|maybe_hdr| maybe_hdr.map(|hdr| { - let root: TrieH256 = TrieH256::from_slice(hdr.state_root().as_ref()); + let root: H256 = H256::from_slice(hdr.state_root().as_ref()); DbState::with_storage(self.storage.clone(), root) }).ok_or_else(|| client::error::ErrorKind::UnknownBlock(format!("{:?}", block)).into())) } } -impl client::backend::LocalBackend for Backend -{} +impl client::backend::LocalBackend for Backend +where Block: BlockT {} #[cfg(test)] mod tests { diff --git a/substrate/substrate/client/db/src/utils.rs b/substrate/substrate/client/db/src/utils.rs index ea5a8f2e77..cc735950db 100644 --- a/substrate/substrate/client/db/src/utils.rs +++ b/substrate/substrate/client/db/src/utils.rs @@ -18,8 +18,9 @@ //! full and light storages. use std::sync::Arc; +use std::io; -use kvdb::{self, KeyValueDB, DBTransaction}; +use kvdb::{KeyValueDB, DBTransaction}; use kvdb_rocksdb::{Database, DatabaseConfig}; use client; @@ -83,20 +84,15 @@ pub fn db_key_to_number(key: &[u8]) -> client::error::Result where N: As client::error::Error { +pub fn db_err(err: io::Error) -> client::error::Error { use std::error::Error; - match err.kind() { - &kvdb::ErrorKind::Io(ref err) => client::error::ErrorKind::Backend(err.description().into()).into(), - &kvdb::ErrorKind::Msg(ref m) => client::error::ErrorKind::Backend(m.clone()).into(), - _ => client::error::ErrorKind::Backend("Unknown backend error".into()).into(), - } + client::error::ErrorKind::Backend(err.description().into()).into() } /// Open RocksDB database. pub fn open_database(config: &DatabaseSettings, db_type: &str) -> client::error::Result> { let mut db_config = DatabaseConfig::with_columns(Some(NUM_COLUMNS)); db_config.memory_budget = config.cache_size; - db_config.wal = true; let path = config.path.to_str().ok_or_else(|| client::error::ErrorKind::Backend("Invalid database path".into()))?; let db = Database::open(&db_config, &path).map_err(db_err)?; diff --git a/substrate/substrate/client/src/backend.rs b/substrate/substrate/client/src/backend.rs index 8de27a39b4..4509f3d190 100644 --- a/substrate/substrate/client/src/backend.rs +++ b/substrate/substrate/client/src/backend.rs @@ -22,11 +22,18 @@ use runtime_primitives::bft::Justification; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{Block as BlockT, NumberFor}; use state_machine::backend::Backend as StateBackend; +use patricia_trie::NodeCodec; +use hashdb::Hasher; /// Block insertion operation. Keeps hold if the inserted block state and data. -pub trait BlockImportOperation { +pub trait BlockImportOperation +where + Block: BlockT, + H: Hasher, + C: NodeCodec, +{ /// Associated state backend type. - type State: StateBackend; + type State: StateBackend; /// Returns pending state. Returns None for backends with locally-unavailable state data. fn state(&self) -> error::Result>; @@ -43,7 +50,7 @@ pub trait BlockImportOperation { /// has been used to check justification of this block). fn update_authorities(&mut self, authorities: Vec); /// Inject storage data into the database. - fn update_storage(&mut self, update: ::Transaction) -> error::Result<()>; + fn update_storage(&mut self, update: >::Transaction) -> error::Result<()>; /// Inject storage data into the database replacing any existing data. fn reset_storage, Vec)>>(&mut self, iter: I) -> error::Result<()>; } @@ -56,13 +63,18 @@ pub trait BlockImportOperation { /// /// The same applies for live `BlockImportOperation`s: while an import operation building on a parent `P` /// is alive, the state for `P` should not be pruned. -pub trait Backend: Send + Sync { +pub trait Backend: Send + Sync +where + Block: BlockT, + H: Hasher, + C: NodeCodec, +{ /// Associated block insertion operation type. - type BlockImportOperation: BlockImportOperation; + type BlockImportOperation: BlockImportOperation; /// Associated blockchain backend type. type Blockchain: ::blockchain::Backend; /// Associated state backend type. - type State: StateBackend; + type State: StateBackend; /// Begin a new block insertion transaction with given parent block id. /// When constructing the genesis, this is called with all-zero hash. @@ -79,7 +91,17 @@ pub trait Backend: Send + Sync { } /// Mark for all Backend implementations, that are making use of state data, stored locally. -pub trait LocalBackend: Backend {} +pub trait LocalBackend: Backend +where + Block: BlockT, + H: Hasher, + C: NodeCodec, +{} /// Mark for all Backend implementations, that are fetching required state data from remote nodes. -pub trait RemoteBackend: Backend {} +pub trait RemoteBackend: Backend +where + Block: BlockT, + H: Hasher, + C: NodeCodec, +{} diff --git a/substrate/substrate/client/src/block_builder.rs b/substrate/substrate/client/src/block_builder.rs index bc5c29a37f..30216f4157 100644 --- a/substrate/substrate/client/src/block_builder.rs +++ b/substrate/substrate/client/src/block_builder.rs @@ -23,12 +23,20 @@ use runtime_primitives::traits::{Header as HeaderT, Hash, Block as BlockT, One, use runtime_primitives::generic::BlockId; use {backend, error, Client, CallExecutor}; use runtime_primitives::{ApplyResult, ApplyOutcome}; +use patricia_trie::NodeCodec; +use primitives::{KeccakHasher, RlpCodec}; +use hashdb::Hasher; +use rlp::Encodable; /// Utility for building new (valid) blocks from a stream of extrinsics. -pub struct BlockBuilder where - B: backend::Backend, - E: CallExecutor + Clone, +pub struct BlockBuilder +where + B: backend::Backend, + E: CallExecutor + Clone, Block: BlockT, + H: Hasher, + H::Out: Encodable + Ord, + C: NodeCodec, { header: ::Header, extrinsics: Vec<::Extrinsic>, @@ -37,9 +45,10 @@ pub struct BlockBuilder where changes: state_machine::OverlayedChanges, } -impl BlockBuilder where - B: backend::Backend, - E: CallExecutor + Clone, +impl BlockBuilder +where + B: backend::Backend, + E: CallExecutor + Clone, Block: BlockT, { /// Create a new instance of builder from the given client, building on the latest block. diff --git a/substrate/substrate/client/src/call_executor.rs b/substrate/substrate/client/src/call_executor.rs index ac561b5a54..6da6d0a04f 100644 --- a/substrate/substrate/client/src/call_executor.rs +++ b/substrate/substrate/client/src/call_executor.rs @@ -15,12 +15,17 @@ // along with Polkadot. If not, see . use std::sync::Arc; +use std::cmp::Ord; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::Block as BlockT; -use state_machine::{self, OverlayedChanges, Ext, +use state_machine::{self, OverlayedChanges, Ext, CodeExecutor, ExecutionManager, native_when_possible}; use runtime_io::Externalities; use executor::{RuntimeVersion, RuntimeInfo}; +use patricia_trie::NodeCodec; +use primitives::{KeccakHasher, RlpCodec}; +use hashdb::Hasher; +use rlp::Encodable; use backend; use error; @@ -35,7 +40,13 @@ pub struct CallResult { } /// Method call executor. -pub trait CallExecutor { +pub trait CallExecutor +where + B: BlockT, + H: Hasher, + H::Out: Ord + Encodable, + C: NodeCodec, +{ /// Externalities error type. type Error: state_machine::Error; @@ -57,7 +68,7 @@ pub trait CallExecutor { /// /// No changes are made. fn call_at_state< - S: state_machine::Backend, + S: state_machine::Backend, F: FnOnce(Result, Self::Error>, Result, Self::Error>) -> Result, Self::Error>, >(&self, state: &S, @@ -70,7 +81,7 @@ pub trait CallExecutor { /// Execute a call to a contract on top of given state, gathering execution proof. /// /// No changes are made. - fn prove_at_state(&self, + fn prove_at_state>(&self, state: S, overlay: &mut OverlayedChanges, method: &str, @@ -104,11 +115,11 @@ impl Clone for LocalCallExecutor where E: Clone { } } -impl CallExecutor for LocalCallExecutor - where - B: backend::LocalBackend, - E: CodeExecutor + RuntimeInfo, - Block: BlockT, +impl CallExecutor for LocalCallExecutor +where + B: backend::LocalBackend, + E: CodeExecutor + RuntimeInfo, + Block: BlockT, { type Error = E::Error; @@ -140,7 +151,7 @@ impl CallExecutor for LocalCallExecutor } fn call_at_state< - S: state_machine::Backend, + S: state_machine::Backend, F: FnOnce(Result, Self::Error>, Result, Self::Error>) -> Result, Self::Error>, >(&self, state: &S, @@ -159,7 +170,7 @@ impl CallExecutor for LocalCallExecutor ).map_err(Into::into) } - fn prove_at_state(&self, + fn prove_at_state>(&self, state: S, changes: &mut OverlayedChanges, method: &str, diff --git a/substrate/substrate/client/src/client.rs b/substrate/substrate/client/src/client.rs index 4ae139c729..2bd8e9f8a6 100644 --- a/substrate/substrate/client/src/client.rs +++ b/substrate/substrate/client/src/client.rs @@ -23,6 +23,7 @@ use primitives::AuthorityId; use runtime_primitives::{bft::Justification, generic::{BlockId, SignedBlock, Block as RuntimeBlock}}; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, One, As, NumberFor}; use runtime_primitives::BuildStorage; +use primitives::{KeccakHasher, RlpCodec}; use primitives::storage::{StorageKey, StorageData}; use codec::Decode; use state_machine::{ @@ -163,9 +164,9 @@ impl JustifiedHeader { pub fn new_in_mem( executor: E, genesis_storage: S, -) -> error::Result, LocalCallExecutor, E>, Block>> +) -> error::Result, LocalCallExecutor, E>, Block>> where - E: CodeExecutor + RuntimeInfo, + E: CodeExecutor + RuntimeInfo, S: BuildStorage, Block: BlockT, { @@ -175,8 +176,8 @@ pub fn new_in_mem( } impl Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { /// Creates new Substrate Client with given blockchain and code executor. @@ -284,12 +285,16 @@ impl Client where } /// Create a new block, built on the head of the chain. - pub fn new_block(&self) -> error::Result> where E: Clone { + pub fn new_block(&self) -> error::Result> + where E: Clone + { block_builder::BlockBuilder::new(self) } /// Create a new block, built on top of `parent`. - pub fn new_block_at(&self, parent: &BlockId) -> error::Result> where E: Clone { + pub fn new_block_at(&self, parent: &BlockId) -> error::Result> + where E: Clone + { block_builder::BlockBuilder::at_block(parent, &self) } @@ -504,8 +509,8 @@ impl Client where impl bft::BlockImport for Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { fn import_block( @@ -527,8 +532,8 @@ impl bft::BlockImport for Client impl bft::Authorities for Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { fn authorities(&self, at: &BlockId) -> Result, bft::Error> { @@ -549,9 +554,9 @@ impl bft::Authorities for Client } impl BlockchainEvents for Client - where - E: CallExecutor, - Block: BlockT, +where + E: CallExecutor, + Block: BlockT, { /// Get block import event stream. fn import_notification_stream(&self) -> BlockchainEventStream { @@ -567,10 +572,10 @@ impl BlockchainEvents for Client } impl ChainHead for Client - where - B: backend::Backend, - E: CallExecutor, - Block: BlockT, +where + B: backend::Backend, + E: CallExecutor, + Block: BlockT, { fn best_block_header(&self) -> error::Result<::Header> { Client::best_block_header(self) @@ -579,8 +584,8 @@ impl ChainHead for Client impl BlockBody for Client where - B: backend::Backend, - E: CallExecutor, + B: backend::Backend, + E: CallExecutor, Block: BlockT, { fn block_body(&self, id: &BlockId) -> error::Result::Extrinsic>>> { diff --git a/substrate/substrate/client/src/genesis.rs b/substrate/substrate/client/src/genesis.rs index 1062ba92c5..88d99e88e4 100644 --- a/substrate/substrate/client/src/genesis.rs +++ b/substrate/substrate/client/src/genesis.rs @@ -51,6 +51,7 @@ mod tests { use test_client::runtime::genesismap::{GenesisConfig, additional_storage_with_genesis}; use test_client::runtime::{Hash, Transfer, Block, BlockNumber, Header, Digest, Extrinsic}; use ed25519::{Public, Pair}; + use primitives::{KeccakHasher, RlpCodec}; native_executor_instance!(Executor, test_client::runtime::api::dispatch, test_client::runtime::VERSION, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm")); @@ -58,7 +59,7 @@ mod tests { NativeExecutionDispatch::with_heap_pages(8) } - fn construct_block(backend: &InMemory, number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec) -> (Vec, Hash) { + fn construct_block(backend: &InMemory, number: BlockNumber, parent_hash: Hash, state_root: Hash, txs: Vec) -> (Vec, Hash) { use triehash::ordered_trie_root; let transactions = txs.into_iter().map(|tx| { @@ -115,7 +116,7 @@ mod tests { (vec![].and(&Block { header, extrinsics: transactions }), hash) } - fn block1(genesis_hash: Hash, backend: &InMemory) -> (Vec, Hash) { + fn block1(genesis_hash: Hash, backend: &InMemory) -> (Vec, Hash) { construct_block( backend, 1, diff --git a/substrate/substrate/client/src/in_mem.rs b/substrate/substrate/client/src/in_mem.rs index a12323610a..e42e83f75f 100644 --- a/substrate/substrate/client/src/in_mem.rs +++ b/substrate/substrate/client/src/in_mem.rs @@ -28,6 +28,9 @@ use runtime_primitives::traits::{Block as BlockT, Header as HeaderT, Zero, Numbe use runtime_primitives::bft::Justification; use blockchain::{self, BlockStatus}; use state_machine::backend::{Backend as StateBackend, InMemory}; +use patricia_trie::NodeCodec; +use hashdb::Hasher; +use heapsize::HeapSizeOf; struct PendingBlock { block: StoredBlock, @@ -248,15 +251,21 @@ impl light::blockchain::Storage for Blockchain { } /// In-memory operation. -pub struct BlockImportOperation { +pub struct BlockImportOperation> { pending_block: Option>, pending_authorities: Option>, - old_state: InMemory, - new_state: Option, + old_state: InMemory, + new_state: Option>, } -impl backend::BlockImportOperation for BlockImportOperation { - type State = InMemory; +impl backend::BlockImportOperation for BlockImportOperation +where + Block: BlockT, + H: Hasher, + C: NodeCodec, + H::Out: HeapSizeOf, +{ + type State = InMemory; fn state(&self) -> error::Result> { Ok(Some(&self.old_state)) @@ -281,7 +290,7 @@ impl backend::BlockImportOperation for BlockImportOperatio self.pending_authorities = Some(authorities); } - fn update_storage(&mut self, update: ::Transaction) -> error::Result<()> { + fn update_storage(&mut self, update: as StateBackend>::Transaction) -> error::Result<()> { self.new_state = Some(self.old_state.update(update)); Ok(()) } @@ -293,18 +302,24 @@ impl backend::BlockImportOperation for BlockImportOperatio } /// In-memory backend. Keeps all states and blocks in memory. Useful for testing. -pub struct Backend where +pub struct Backend +where Block: BlockT, + H: Hasher, + C: NodeCodec { - states: RwLock>, + states: RwLock>>, blockchain: Blockchain, } -impl Backend where +impl Backend +where Block: BlockT, + H: Hasher, + C: NodeCodec { /// Create a new instance of in-mem backend. - pub fn new() -> Backend { + pub fn new() -> Backend { Backend { states: RwLock::new(HashMap::new()), blockchain: Blockchain::new(), @@ -312,12 +327,16 @@ impl Backend where } } -impl backend::Backend for Backend where +impl backend::Backend for Backend +where Block: BlockT, + H: Hasher, + H::Out: HeapSizeOf, + C: NodeCodec + Send + Sync, { - type BlockImportOperation = BlockImportOperation; + type BlockImportOperation = BlockImportOperation; type Blockchain = Blockchain; - type State = InMemory; + type State = InMemory; fn begin_operation(&self, block: BlockId) -> error::Result { let state = match block { @@ -366,7 +385,13 @@ impl backend::Backend for Backend where } } -impl backend::LocalBackend for Backend {} +impl backend::LocalBackend for Backend +where + Block: BlockT, + H: Hasher, + H::Out: HeapSizeOf, + C: NodeCodec + Send + Sync, +{} impl Cache { fn insert(&self, at: Block::Hash, authorities: Option>) { diff --git a/substrate/substrate/client/src/lib.rs b/substrate/substrate/client/src/lib.rs index 0032fc64e4..457502b3d6 100644 --- a/substrate/substrate/client/src/lib.rs +++ b/substrate/substrate/client/src/lib.rs @@ -36,6 +36,10 @@ extern crate fnv; extern crate futures; extern crate parking_lot; extern crate triehash; +extern crate patricia_trie; +extern crate hashdb; +extern crate rlp; +extern crate heapsize; #[macro_use] extern crate error_chain; #[macro_use] extern crate log; diff --git a/substrate/substrate/client/src/light/backend.rs b/substrate/substrate/client/src/light/backend.rs index 03b188b5f6..9187566f5b 100644 --- a/substrate/substrate/client/src/light/backend.rs +++ b/substrate/substrate/client/src/light/backend.rs @@ -24,14 +24,19 @@ use parking_lot::RwLock; use primitives::AuthorityId; use runtime_primitives::{bft::Justification, generic::BlockId}; use runtime_primitives::traits::{Block as BlockT, NumberFor}; -use state_machine::{Backend as StateBackend, TrieBackend as StateTrieBackend, - TryIntoTrieBackend as TryIntoStateTrieBackend}; +use state_machine::{ + Backend as StateBackend, + TrieBackend as StateTrieBackend, + TryIntoTrieBackend as TryIntoStateTrieBackend +}; use backend::{Backend as ClientBackend, BlockImportOperation, RemoteBackend}; use blockchain::HeaderBackend as BlockchainHeaderBackend; use error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as ClientResult}; use light::blockchain::{Blockchain, Storage as BlockchainStorage}; use light::fetcher::{Fetcher, RemoteReadRequest}; +use patricia_trie::NodeCodec; +use hashdb::Hasher; /// Light client backend. pub struct Backend { @@ -66,10 +71,12 @@ impl Backend { } } -impl ClientBackend for Backend where +impl ClientBackend for Backend where Block: BlockT, S: BlockchainStorage, - F: Fetcher + F: Fetcher, + H: Hasher, + C: NodeCodec, { type BlockImportOperation = ImportOperation; type Blockchain = Blockchain; @@ -112,13 +119,22 @@ impl ClientBackend for Backend where } } -impl RemoteBackend for Backend where Block: BlockT, S: BlockchainStorage, F: Fetcher {} +impl RemoteBackend for Backend +where + Block: BlockT, + S: BlockchainStorage, + F: Fetcher, + H: Hasher, + C: NodeCodec, +{} -impl BlockImportOperation for ImportOperation - where - Block: BlockT, - S: BlockchainStorage, - F: Fetcher, +impl BlockImportOperation for ImportOperation +where + Block: BlockT, + F: Fetcher, + S: BlockchainStorage, + H: Hasher, + C: NodeCodec, { type State = OnDemandState; @@ -143,7 +159,7 @@ impl BlockImportOperation for ImportOperation self.authorities = Some(authorities); } - fn update_storage(&mut self, _update: ::Transaction) -> ClientResult<()> { + fn update_storage(&mut self, _update: >::Transaction) -> ClientResult<()> { // we're not storing anything locally => ignore changes Ok(()) } @@ -154,11 +170,13 @@ impl BlockImportOperation for ImportOperation } } -impl StateBackend for OnDemandState +impl StateBackend for OnDemandState where Block: BlockT, S: BlockchainStorage, F: Fetcher, + H: Hasher, + C: NodeCodec, { type Error = ClientError; type Transaction = (); @@ -186,9 +204,9 @@ impl StateBackend for OnDemandState // whole state is not available on light node } - fn storage_root(&self, _delta: I) -> ([u8; 32], Self::Transaction) + fn storage_root(&self, _delta: I) -> (H::Out, Self::Transaction) where I: IntoIterator, Option>)> { - ([0; 32], ()) + (H::Out::default(), ()) } fn pairs(&self) -> Vec<(Vec, Vec)> { @@ -197,8 +215,14 @@ impl StateBackend for OnDemandState } } -impl TryIntoStateTrieBackend for OnDemandState where Block: BlockT, F: Fetcher { - fn try_into_trie_backend(self) -> Option { +impl TryIntoStateTrieBackend for OnDemandState +where + Block: BlockT, + F: Fetcher, + H: Hasher, + C: NodeCodec, +{ + fn try_into_trie_backend(self) -> Option> { None } } @@ -214,6 +238,7 @@ pub mod tests { use light::new_fetch_checker; use light::fetcher::{Fetcher, FetchChecker, RemoteCallRequest}; use super::*; + use primitives::{KeccakHasher, RlpCodec}; pub type OkCallFetcher = Mutex; @@ -246,7 +271,7 @@ pub mod tests { // check remote read proof locally let local_executor = test_client::LocalExecutor::with_heap_pages(8); - let local_checker = new_fetch_checker(local_executor); + let local_checker = new_fetch_checker::<_, KeccakHasher, RlpCodec>(local_executor); let request = RemoteReadRequest { block: remote_block_hash, header: remote_block_header, diff --git a/substrate/substrate/client/src/light/call_executor.rs b/substrate/substrate/client/src/light/call_executor.rs index 13355f5d7c..cdbd7ac727 100644 --- a/substrate/substrate/client/src/light/call_executor.rs +++ b/substrate/substrate/client/src/light/call_executor.rs @@ -23,7 +23,12 @@ use futures::{IntoFuture, Future}; use runtime_primitives::generic::BlockId; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT}; use state_machine::{Backend as StateBackend, CodeExecutor, OverlayedChanges, - execution_proof_check, TrieH256, ExecutionManager}; + execution_proof_check, ExecutionManager}; +use primitives::H256; +use patricia_trie::NodeCodec; +use hashdb::Hasher; +use rlp::Encodable; +use primitives::{KeccakHasher, RlpCodec}; use blockchain::Backend as ChainBackend; use call_executor::{CallExecutor, CallResult}; @@ -31,6 +36,7 @@ use error::{Error as ClientError, ErrorKind as ClientErrorKind, Result as Client use light::fetcher::{Fetcher, RemoteCallRequest}; use executor::RuntimeVersion; use codec::Decode; +use heapsize::HeapSizeOf; /// Call executor that executes methods on remote node, querying execution proof /// and checking proof by re-executing locally. @@ -46,7 +52,7 @@ impl RemoteCallExecutor { } } -impl CallExecutor for RemoteCallExecutor +impl CallExecutor for RemoteCallExecutor where Block: BlockT, B: ChainBackend, @@ -77,19 +83,25 @@ impl CallExecutor for RemoteCallExecutor } fn call_at_state< - S: StateBackend, - H: FnOnce(Result, Self::Error>, Result, Self::Error>) -> Result, Self::Error> + S: StateBackend, + FF: FnOnce(Result, Self::Error>, Result, Self::Error>) -> Result, Self::Error> >(&self, _state: &S, _changes: &mut OverlayedChanges, _method: &str, _call_data: &[u8], - _m: ExecutionManager + _m: ExecutionManager ) -> ClientResult<(Vec, S::Transaction)> { Err(ClientErrorKind::NotAvailableOnLightClient.into()) } - fn prove_at_state(&self, _state: S, _changes: &mut OverlayedChanges, _method: &str, _call_data: &[u8]) -> ClientResult<(Vec, Vec>)> { + fn prove_at_state>( + &self, + _state: S, + _changes: &mut OverlayedChanges, + _method: &str, + _call_data: &[u8] + ) -> ClientResult<(Vec, Vec>)> { Err(ClientErrorKind::NotAvailableOnLightClient.into()) } @@ -99,20 +111,23 @@ impl CallExecutor for RemoteCallExecutor } /// Check remote execution proof using given backend. -pub fn check_execution_proof( +pub fn check_execution_proof( executor: &E, request: &RemoteCallRequest
, remote_proof: Vec> ) -> ClientResult where Header: HeaderT, - E: CodeExecutor, + E: CodeExecutor, + H: Hasher, + H::Out: Ord + Encodable + HeapSizeOf + From, + C: NodeCodec, { let local_state_root = request.header.state_root(); let mut changes = OverlayedChanges::default(); - let (local_result, _) = execution_proof_check( - TrieH256::from_slice(local_state_root.as_ref()).into(), + let (local_result, _) = execution_proof_check::( + H256::from_slice(local_state_root.as_ref()).into(), remote_proof, &mut changes, executor, @@ -127,6 +142,7 @@ mod tests { use test_client; use executor::NativeExecutionDispatch; use super::*; + use primitives::RlpCodec; #[test] fn execution_proof_is_generated_and_checked() { @@ -138,10 +154,10 @@ mod tests { // 'fetch' execution proof from remote node let remote_execution_proof = remote_client.execution_proof(&remote_block_id, "authorities", &[]).unwrap().1; - + // check remote execution proof locally let local_executor = test_client::LocalExecutor::with_heap_pages(8); - check_execution_proof(&local_executor, &RemoteCallRequest { + check_execution_proof::<_, _, _, RlpCodec>(&local_executor, &RemoteCallRequest { block: test_client::runtime::Hash::default(), header: test_client::runtime::Header { state_root: remote_block_storage_root.into(), diff --git a/substrate/substrate/client/src/light/fetcher.rs b/substrate/substrate/client/src/light/fetcher.rs index 07c26a471d..694abeb8f1 100644 --- a/substrate/substrate/client/src/light/fetcher.rs +++ b/substrate/substrate/client/src/light/fetcher.rs @@ -18,8 +18,14 @@ use futures::IntoFuture; +use primitives::H256; +use hashdb::Hasher; +use patricia_trie::NodeCodec; +use rlp::Encodable; +use heapsize::HeapSizeOf; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT}; use state_machine::{CodeExecutor, read_proof_check}; +use std::marker::PhantomData; use call_executor::CallResult; use error::{Error as ClientError, Result as ClientResult}; @@ -83,24 +89,29 @@ pub trait FetchChecker: Send + Sync { } /// Remote data checker. -pub struct LightDataChecker { +pub struct LightDataChecker { executor: E, + _hasher: PhantomData, + _codec: PhantomData, } -impl LightDataChecker { +impl LightDataChecker { /// Create new light data checker. pub fn new(executor: E) -> Self { Self { - executor, + executor, _hasher: PhantomData, _codec: PhantomData } } } -impl FetchChecker for LightDataChecker +impl FetchChecker for LightDataChecker where Block: BlockT, - Block::Hash: Into<[u8; 32]>, - E: CodeExecutor, + Block::Hash: Into, + E: CodeExecutor, + H: Hasher, + C: NodeCodec + Sync + Send, + H::Out: Ord + Encodable + HeapSizeOf + From, { fn check_read_proof( &self, @@ -108,7 +119,7 @@ impl FetchChecker for LightDataChecker remote_proof: Vec> ) -> ClientResult>> { let local_state_root = request.header.state_root().clone(); - read_proof_check(local_state_root.into(), remote_proof, &request.key).map_err(Into::into) + read_proof_check::(local_state_root.into(), remote_proof, &request.key).map_err(Into::into) } fn check_execution_proof( @@ -116,6 +127,6 @@ impl FetchChecker for LightDataChecker request: &RemoteCallRequest, remote_proof: Vec> ) -> ClientResult { - check_execution_proof(&self.executor, request, remote_proof) + check_execution_proof::<_, _, H, C>(&self.executor, request, remote_proof) } } diff --git a/substrate/substrate/client/src/light/mod.rs b/substrate/substrate/client/src/light/mod.rs index 57bd8ce45b..ba175b14a8 100644 --- a/substrate/substrate/client/src/light/mod.rs +++ b/substrate/substrate/client/src/light/mod.rs @@ -33,6 +33,8 @@ use light::backend::Backend; use light::blockchain::{Blockchain, Storage as BlockchainStorage}; use light::call_executor::RemoteCallExecutor; use light::fetcher::{Fetcher, LightDataChecker}; +use hashdb::Hasher; +use patricia_trie::NodeCodec; /// Create an instance of light client blockchain backend. pub fn new_light_blockchain, F>(storage: S) -> Arc> { @@ -62,11 +64,13 @@ pub fn new_light( } /// Create an instance of fetch data checker. -pub fn new_fetch_checker( +pub fn new_fetch_checker( executor: E, -) -> LightDataChecker +) -> LightDataChecker where - E: CodeExecutor, + E: CodeExecutor, + H: Hasher, + C: NodeCodec, { LightDataChecker::new(executor) } diff --git a/substrate/substrate/executor/Cargo.toml b/substrate/substrate/executor/Cargo.toml index 11294d23ef..a90c2065c6 100644 --- a/substrate/substrate/executor/Cargo.toml +++ b/substrate/substrate/executor/Cargo.toml @@ -21,6 +21,8 @@ twox-hash = "1.1.0" lazy_static = "1.0" parking_lot = "*" log = "0.3" +hashdb = { git = "https://github.com/paritytech/parity-common" } +tiny-keccak = "1.4" [dev-dependencies] assert_matches = "1.1" diff --git a/substrate/substrate/executor/src/lib.rs b/substrate/substrate/executor/src/lib.rs index 3a399e7e3a..f0605849d5 100644 --- a/substrate/substrate/executor/src/lib.rs +++ b/substrate/substrate/executor/src/lib.rs @@ -42,6 +42,9 @@ extern crate byteorder; extern crate triehash; extern crate parking_lot; extern crate twox_hash; +extern crate hashdb; +extern crate tiny_keccak; + #[macro_use] extern crate log; #[macro_use] @@ -73,6 +76,7 @@ pub use native_executor::{with_native_environment, NativeExecutor, NativeExecuti pub use state_machine::Externalities; pub use runtime_version::RuntimeVersion; pub use codec::Codec; +use primitives::KeccakHasher; /// Provides runtime information. pub trait RuntimeInfo { @@ -80,7 +84,7 @@ pub trait RuntimeInfo { const NATIVE_VERSION: Option; /// Extract RuntimeVersion of given :code block - fn runtime_version ( + fn runtime_version> ( &self, ext: &mut E, code: &[u8] diff --git a/substrate/substrate/executor/src/native_executor.rs b/substrate/substrate/executor/src/native_executor.rs index 0b132ae9ab..c1bd44fd93 100644 --- a/substrate/substrate/executor/src/native_executor.rs +++ b/substrate/substrate/executor/src/native_executor.rs @@ -25,6 +25,7 @@ use twox_hash::XxHash; use std::hash::Hasher; use parking_lot::{Mutex, MutexGuard}; use RuntimeInfo; +use primitives::KeccakHasher; // For the internal Runtime Cache: // Is it compatible enough to run this natively or do we need to fall back on the WasmModule @@ -56,7 +57,7 @@ fn gen_cache_key(code: &[u8]) -> u64 { /// fetch a runtime version from the cache or if there is no cached version yet, create /// the runtime version entry for `code`, determines whether `Compatibility::IsCompatible` /// can be used by by comparing returned RuntimeVersion to `ref_version` -fn fetch_cached_runtime_version<'a, E: Externalities>( +fn fetch_cached_runtime_version<'a, E: Externalities>( wasm_executor: &WasmExecutor, cache: &'a mut MutexGuard, ext: &mut E, @@ -94,8 +95,8 @@ fn safe_call(f: F) -> Result /// Set up the externalities and safe calling environment to execute calls to a native runtime. /// /// If the inner closure panics, it will be caught and return an error. -pub fn with_native_environment(ext: &mut Externalities, f: F) -> Result - where F: ::std::panic::UnwindSafe + FnOnce() -> U +pub fn with_native_environment(ext: &mut Externalities, f: F) -> Result +where F: ::std::panic::UnwindSafe + FnOnce() -> U { ::runtime_io::with_externalities(ext, move || safe_call(f)) } @@ -107,7 +108,8 @@ pub trait NativeExecutionDispatch: Send + Sync { /// Dispatch a method and input data to be executed natively. Returns `Some` result or `None` /// if the `method` is unknown. Panics if there's an unrecoverable error. - fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result>; + // fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result>; + fn dispatch(ext: &mut Externalities, method: &str, data: &[u8]) -> Result>; /// Get native runtime version. const VERSION: RuntimeVersion; @@ -150,7 +152,7 @@ impl Clone for NativeExecutor { impl RuntimeInfo for NativeExecutor { const NATIVE_VERSION: Option = Some(D::VERSION); - fn runtime_version( + fn runtime_version>( &self, ext: &mut E, code: &[u8], @@ -163,10 +165,10 @@ impl RuntimeInfo for NativeExecutor { } } -impl CodeExecutor for NativeExecutor { +impl CodeExecutor for NativeExecutor { type Error = Error; - fn call( + fn call>( &self, ext: &mut E, code: &[u8], @@ -195,6 +197,8 @@ macro_rules! native_executor_instance { native_executor_instance!(IMPL $name, $dispatcher, $version, $code); }; (IMPL $name:ident, $dispatcher:path, $version:path, $code:expr) => { + // TODO: this is not so great – I think I should go back to have dispatch take a type param and modify this macro to accept a type param and then pass it in from the test-client instead + use primitives::KeccakHasher as _KeccakHasher; impl $crate::NativeExecutionDispatch for $name { const VERSION: $crate::RuntimeVersion = $version; fn native_equivalent() -> &'static [u8] { @@ -202,8 +206,7 @@ macro_rules! native_executor_instance { // get a proper build script, this must be strictly adhered to or things will go wrong. $code } - - fn dispatch(ext: &mut $crate::Externalities, method: &str, data: &[u8]) -> $crate::error::Result> { + fn dispatch(ext: &mut $crate::Externalities<_KeccakHasher>, method: &str, data: &[u8]) -> $crate::error::Result> { $crate::with_native_environment(ext, move || $dispatcher(method, data))? .ok_or_else(|| $crate::error::ErrorKind::MethodNotFound(method.to_owned()).into()) } diff --git a/substrate/substrate/executor/src/wasm_executor.rs b/substrate/substrate/executor/src/wasm_executor.rs index 7ea33bea3b..2b222d3ac0 100644 --- a/substrate/substrate/executor/src/wasm_executor.rs +++ b/substrate/substrate/executor/src/wasm_executor.rs @@ -18,6 +18,7 @@ use std::cmp::Ordering; use std::collections::HashMap; + use wasmi::{ Module, ModuleInstance, MemoryInstance, MemoryRef, TableRef, ImportsBuilder }; @@ -29,8 +30,11 @@ use wasm_utils::UserError; use primitives::{blake2_256, twox_128, twox_256}; use primitives::hexdisplay::HexDisplay; use primitives::sandbox as sandbox_primitives; +use primitives::KeccakHasher; use triehash::ordered_trie_root; use sandbox; +use tiny_keccak::keccak256; + struct Heap { end: u32, @@ -71,7 +75,7 @@ macro_rules! debug_trace { ( $( $x:tt )* ) => () } -struct FunctionExecutor<'e, E: Externalities + 'e> { +struct FunctionExecutor<'e, E: Externalities + 'e> { sandbox_store: sandbox::Store, heap: Heap, memory: MemoryRef, @@ -80,7 +84,7 @@ struct FunctionExecutor<'e, E: Externalities + 'e> { hash_lookup: HashMap, Vec>, } -impl<'e, E: Externalities> FunctionExecutor<'e, E> { +impl<'e, E: Externalities> FunctionExecutor<'e, E> { fn new(m: MemoryRef, heap_pages: usize, t: Option, e: &'e mut E) -> Result { Ok(FunctionExecutor { sandbox_store: sandbox::Store::new(), @@ -93,7 +97,7 @@ impl<'e, E: Externalities> FunctionExecutor<'e, E> { } } -impl<'e, E: Externalities> sandbox::SandboxCapabilities for FunctionExecutor<'e, E> { +impl<'e, E: Externalities> sandbox::SandboxCapabilities for FunctionExecutor<'e, E> { fn store(&self) -> &sandbox::Store { &self.sandbox_store } @@ -138,6 +142,7 @@ impl ReadPrimitive for MemoryInstance { } } +// TODO: this macro does not support `where` clauses and that seems somewhat tricky to add impl_function_executor!(this: FunctionExecutor<'e, E>, ext_print_utf8(utf8_data: *const u8, utf8_len: u32) => { if let Ok(utf8) = this.memory.get(utf8_data, utf8_len as usize) { @@ -285,7 +290,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, }, ext_storage_root(result: *mut u8) => { let r = this.ext.storage_root(); - this.memory.set(result, &r[..]).map_err(|_| UserError("Invalid attempt to set memory in ext_storage_root"))?; + this.memory.set(result, r.as_ref()).map_err(|_| UserError("Invalid attempt to set memory in ext_storage_root"))?; Ok(()) }, ext_enumerated_trie_root(values_data: *const u8, lens_data: *const u32, lens_len: u32, result: *mut u8) => { @@ -348,6 +353,15 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, this.memory.set(out, &result).map_err(|_| UserError("Invalid attempt to set result in ext_blake2_256"))?; Ok(()) }, + ext_keccak256(data: *const u8, len: u32, out: *mut u8) => { + let result = if len == 0 { + keccak256(&[0u8; 0]) + } else { + keccak256(&this.memory.get(data, len as usize).map_err(|_| UserError("Invalid attempt to get data in ext_keccak256"))?) + }; + this.memory.set(out, &result).map_err(|_| UserError("Invalid attempt to set result in ext_keccak256"))?; + Ok(()) + }, ext_ed25519_verify(msg_data: *const u8, msg_len: u32, sig_data: *const u8, pubkey_data: *const u8) -> u32 => { let mut sig = [0u8; 64]; this.memory.get_into(sig_data, &mut sig[..]).map_err(|_| UserError("Invalid attempt to get signature in ext_ed25519_verify"))?; @@ -476,7 +490,7 @@ impl_function_executor!(this: FunctionExecutor<'e, E>, this.sandbox_store.memory_teardown(memory_idx)?; Ok(()) }, - => <'e, E: Externalities + 'e> + => <'e, E: Externalities + 'e> ); /// Wasm rust executor for contracts. @@ -508,7 +522,7 @@ impl WasmExecutor { /// Call a given method in the given code. /// This should be used for tests only. - pub fn call( + pub fn call>( &self, ext: &mut E, code: &[u8], @@ -520,7 +534,7 @@ impl WasmExecutor { } /// Call a given method in the given wasm-module runtime. - pub fn call_in_wasm_module( + pub fn call_in_wasm_module>( &self, ext: &mut E, module: &Module, @@ -632,7 +646,7 @@ mod tests { assert_eq!(output, b"all ok!".to_vec()); - let expected: HashMap<_, _> = map![ + let expected : TestExternalities<_> = map![ b"input".to_vec() => b"Hello world".to_vec(), b"foo".to_vec() => b"bar".to_vec(), b"baz".to_vec() => b"bar".to_vec() @@ -655,7 +669,7 @@ mod tests { assert_eq!(output, b"all ok!".to_vec()); - let expected: HashMap<_, _> = map![ + let expected: TestExternalities<_> = map![ b"aaa".to_vec() => b"1".to_vec(), b"aab".to_vec() => b"2".to_vec(), b"bbb".to_vec() => b"5".to_vec() diff --git a/substrate/substrate/executor/wasm/Cargo.lock b/substrate/substrate/executor/wasm/Cargo.lock index 9d2f6ce2ef..c1f049b09a 100644 --- a/substrate/substrate/executor/wasm/Cargo.lock +++ b/substrate/substrate/executor/wasm/Cargo.lock @@ -18,14 +18,27 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "fixed-hash" -version = "0.1.3" -source = "git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm#8dc457899afdaf968ff7f16140b03d1e37b01d71" +version = "0.2.2" +source = "git+https://github.com/paritytech/parity-common#9bcbfa0f10fee1852791ce07338d664817f69521" + +[[package]] +name = "hashdb" +version = "0.2.1" +source = "git+https://github.com/paritytech/parity-common#9bcbfa0f10fee1852791ce07338d664817f69521" [[package]] name = "nodrop" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "plain_hasher" +version = "0.2.0" +source = "git+https://github.com/paritytech/parity-common#9bcbfa0f10fee1852791ce07338d664817f69521" +dependencies = [ + "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "proc-macro2" version = "0.4.9" @@ -115,13 +128,15 @@ version = "0.1.0" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", - "fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)", + "fixed-hash 0.2.2 (git+https://github.com/paritytech/parity-common)", + "hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)", + "plain_hasher 0.2.0 (git+https://github.com/paritytech/parity-common)", "rustc-hex 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)", "substrate-codec 0.1.0", "substrate-codec-derive 0.1.0", "substrate-runtime-std 0.1.0", - "uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)", + "uint 0.2.2 (git+https://github.com/paritytech/parity-common)", ] [[package]] @@ -166,8 +181,8 @@ dependencies = [ [[package]] name = "uint" -version = "0.1.2" -source = "git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm#8dc457899afdaf968ff7f16140b03d1e37b01d71" +version = "0.2.2" +source = "git+https://github.com/paritytech/parity-common#9bcbfa0f10fee1852791ce07338d664817f69521" dependencies = [ "byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "rustc_version 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -182,8 +197,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum arrayvec 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "a1e964f9e24d588183fcb43503abda40d288c8657dfc27311516ce2f05675aef" "checksum byteorder 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "652805b7e73fada9d85e9a6682a4abd490cb52d96aeecc12e33a0de34dfd0d23" "checksum crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a2f4a431c5c9f662e1200b7c7f02c34e91361150e382089a8f2dec3ba680cbda" -"checksum fixed-hash 0.1.3 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "" +"checksum fixed-hash 0.2.2 (git+https://github.com/paritytech/parity-common)" = "" +"checksum hashdb 0.2.1 (git+https://github.com/paritytech/parity-common)" = "" "checksum nodrop 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "9a2228dca57108069a5262f2ed8bd2e82496d2e074a06d1ccc7ce1687b6ae0a2" +"checksum plain_hasher 0.2.0 (git+https://github.com/paritytech/parity-common)" = "" "checksum proc-macro2 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)" = "cccdc7557a98fe98453030f077df7f3a042052fae465bb61d2c2c41435cfd9b6" "checksum quote 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3372dc35766b36a99ce2352bd1b6ea0137c38d215cc0c8780bf6de6df7842ba9" "checksum rustc-hex 2.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d2b03280c2813907a030785570c577fb27d3deec8da4c18566751ade94de0ace" @@ -192,5 +209,5 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum semver-parser 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" "checksum serde 1.0.27 (registry+https://github.com/rust-lang/crates.io-index)" = "db99f3919e20faa51bb2996057f5031d8685019b5a06139b1ce761da671b8526" "checksum syn 0.14.7 (registry+https://github.com/rust-lang/crates.io-index)" = "e2e13df71f29f9440b50261a5882c86eac334f1badb3134ec26f0de2f1418e44" -"checksum uint 0.1.2 (git+https://github.com/rphmeier/primitives.git?branch=compile-for-wasm)" = "" +"checksum uint 0.2.2 (git+https://github.com/paritytech/parity-common)" = "" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" diff --git a/substrate/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm b/substrate/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm index fae5a8dbb5..ad7e8d7ad1 100644 Binary files a/substrate/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm and b/substrate/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.compact.wasm differ diff --git a/substrate/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm b/substrate/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm index 62077bffa0..4dd7ec49e4 100755 Binary files a/substrate/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm and b/substrate/substrate/executor/wasm/target/wasm32-unknown-unknown/release/runtime_test.wasm differ diff --git a/substrate/substrate/extrinsic-pool/src/api.rs b/substrate/substrate/extrinsic-pool/src/api.rs index 0d8bcfbf22..148ab49e4f 100644 --- a/substrate/substrate/extrinsic-pool/src/api.rs +++ b/substrate/substrate/extrinsic-pool/src/api.rs @@ -16,6 +16,9 @@ //! External API for extrinsic pool. +use std::fmt::Debug; + +use serde::{Serialize, de::DeserializeOwned}; use txpool; use futures::sync::mpsc; @@ -43,6 +46,9 @@ pub trait ExtrinsicPool: Send + Sync + 'static { /// Error type type Error: Error; + /// Pooled extrinsics + type InPool: Debug + Serialize + DeserializeOwned + Send + Sync + 'static; + /// Submit a collection of extrinsics to the pool. fn submit(&self, block: BlockId, xt: Vec) -> Result, Self::Error>; @@ -54,4 +60,7 @@ pub trait ExtrinsicPool: Send + Sync + 'static { /// Return an event stream of transactions imported to the pool. fn import_notification_stream(&self) -> EventStream; + + /// Return all extrinsics in the pool aggregated by the sender. + fn all(&self) -> Self::InPool; } diff --git a/substrate/substrate/extrinsic-pool/src/pool.rs b/substrate/substrate/extrinsic-pool/src/pool.rs index 2fffc1442e..e874086f8d 100644 --- a/substrate/substrate/extrinsic-pool/src/pool.rs +++ b/substrate/substrate/extrinsic-pool/src/pool.rs @@ -149,4 +149,19 @@ impl Pool where { f(self.pool.read().pending(ready)) } + + /// Retrieve all transactions in the pool. The transactions might be unordered. + pub fn all(&self, f: F) -> T where + F: FnOnce(txpool::UnorderedIterator) -> T, + { + f(self.pool.read().unordered_pending(AlwaysReady)) + } +} + +/// A Readiness implementation that returns `Ready` for all transactions. +pub struct AlwaysReady; +impl txpool::Ready for AlwaysReady { + fn is_ready(&mut self, _tx: &VEx) -> txpool::Readiness { + txpool::Readiness::Ready + } } diff --git a/substrate/substrate/keystore/Cargo.toml b/substrate/substrate/keystore/Cargo.toml index 88ec623f34..5aa791ca4d 100644 --- a/substrate/substrate/keystore/Cargo.toml +++ b/substrate/substrate/keystore/Cargo.toml @@ -4,7 +4,7 @@ version = "0.1.0" authors = ["Parity Technologies "] [dependencies] -ethcore-crypto = { git = "https://github.com/paritytech/parity.git", default_features = false } +parity-crypto = { git = "https://github.com/paritytech/parity-common.git", default_features = false } ed25519 = { path = "../ed25519" } error-chain = "0.12" hex = "0.3" diff --git a/substrate/substrate/keystore/src/lib.rs b/substrate/substrate/keystore/src/lib.rs index 14033b4109..015cad74e9 100644 --- a/substrate/substrate/keystore/src/lib.rs +++ b/substrate/substrate/keystore/src/lib.rs @@ -16,7 +16,7 @@ //! Keystore (and session key management) for ed25519 based chains like Polkadot. -extern crate ethcore_crypto as crypto; +extern crate parity_crypto as crypto; extern crate subtle; extern crate ed25519; extern crate rand; diff --git a/substrate/substrate/network-libp2p/Cargo.toml b/substrate/substrate/network-libp2p/Cargo.toml index ef8c5b911d..2ff26882e6 100644 --- a/substrate/substrate/network-libp2p/Cargo.toml +++ b/substrate/substrate/network-libp2p/Cargo.toml @@ -11,7 +11,8 @@ bytes = "0.4" error-chain = { version = "0.12", default-features = false } fnv = "1.0" futures = "0.1" -libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "polkadot-2", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] } +# libp2p = { git = "https://github.com/tomaka/libp2p-rs", branch = "polkadot-2", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] } +libp2p = { git = "https://github.com/tomaka/libp2p-rs", rev = "6aa139a12dbea3d75d898ce0b2af7fcec129e294", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] } ethcore-io = { git = "https://github.com/paritytech/parity.git" } ethkey = { git = "https://github.com/paritytech/parity.git" } ethereum-types = "0.3" @@ -26,6 +27,6 @@ unsigned-varint = { version = "0.1", features = ["codec"] } [dev-dependencies] assert_matches = "1.2" -ethcore-bytes = { git = "https://github.com/paritytech/parity.git" } +parity-bytes = { git = "https://github.com/paritytech/parity-common.git" } ethcore-io = { git = "https://github.com/paritytech/parity.git" } ethcore-logger = { git = "https://github.com/paritytech/parity.git" } diff --git a/substrate/substrate/network-libp2p/tests/tests.rs b/substrate/substrate/network-libp2p/tests/tests.rs index 5016b61b37..a747721719 100644 --- a/substrate/substrate/network-libp2p/tests/tests.rs +++ b/substrate/substrate/network-libp2p/tests/tests.rs @@ -15,7 +15,7 @@ // along with Parity. If not, see . extern crate parking_lot; -extern crate ethcore_bytes; +extern crate parity_bytes; extern crate ethcore_io as io; extern crate ethcore_logger; extern crate substrate_network_libp2p; @@ -26,7 +26,7 @@ use std::sync::Arc; use std::thread; use std::time::*; use parking_lot::Mutex; -use ethcore_bytes::Bytes; +use parity_bytes::Bytes; use substrate_network_libp2p::*; use ethkey::{Random, Generator}; use io::TimerToken; diff --git a/substrate/substrate/network/src/chain.rs b/substrate/substrate/network/src/chain.rs index d698ab0900..bc8cee13ec 100644 --- a/substrate/substrate/network/src/chain.rs +++ b/substrate/substrate/network/src/chain.rs @@ -21,6 +21,7 @@ use client::error::Error; use runtime_primitives::traits::{Block as BlockT, Header as HeaderT}; use runtime_primitives::generic::BlockId; use runtime_primitives::bft::Justification; +use primitives::{KeccakHasher, RlpCodec}; /// Local client abstraction for the network. pub trait Client: Send + Sync { @@ -53,8 +54,8 @@ pub trait Client: Send + Sync { } impl Client for SubstrateClient where - B: client::backend::Backend + Send + Sync + 'static, - E: CallExecutor + Send + Sync + 'static, + B: client::backend::Backend + Send + Sync + 'static, + E: CallExecutor + Send + Sync + 'static, Block: BlockT, { fn import(&self, origin: BlockOrigin, header: Block::Header, justification: Justification, body: Option>) -> Result { diff --git a/substrate/substrate/network/src/test/mod.rs b/substrate/substrate/network/src/test/mod.rs index 5a8d82d448..9d98a66d94 100644 --- a/substrate/substrate/network/src/test/mod.rs +++ b/substrate/substrate/network/src/test/mod.rs @@ -26,6 +26,7 @@ use runtime_primitives::traits::Block as BlockT; use runtime_primitives::generic::BlockId; use io::SyncIo; use protocol::{Context, Protocol}; +use primitives::{KeccakHasher, RlpCodec}; use config::ProtocolConfig; use service::TransactionPool; use network_libp2p::{NodeIndex, SessionInfo, Severity}; @@ -172,7 +173,9 @@ impl Peer { fn flush(&self) { } - fn generate_blocks(&self, count: usize, mut edit_block: F) where F: FnMut(&mut BlockBuilder) { + fn generate_blocks(&self, count: usize, mut edit_block: F) + where F: FnMut(&mut BlockBuilder) + { for _ in 0 .. count { let mut builder = self.client.new_block().unwrap(); edit_block(&mut builder); diff --git a/substrate/substrate/primitives/Cargo.toml b/substrate/substrate/primitives/Cargo.toml index ebfbb71cae..9e2a882846 100644 --- a/substrate/substrate/primitives/Cargo.toml +++ b/substrate/substrate/primitives/Cargo.toml @@ -8,19 +8,28 @@ crunchy = "0.1" substrate-runtime-std = { path = "../runtime-std", default_features = false } substrate-codec = { path = "../codec", default_features = false } substrate-codec-derive = { path = "../codec/derive", default_features = false } -fixed-hash = { git = "https://github.com/rphmeier/primitives.git", branch = "compile-for-wasm", default_features = false } +elastic-array = {version = "0.10", optional = true } +fixed-hash = { git = "https://github.com/paritytech/parity-common", default_features = false } rustc-hex = { version = "2.0", default_features = false } serde = { version = "1.0", default_features = false } serde_derive = { version = "1.0", optional = true } -uint = { git = "https://github.com/rphmeier/primitives.git", branch = "compile-for-wasm", default_features = false } +uint = { git = "https://github.com/paritytech/parity-common", default_features = false } +rlp = { git = "https://github.com/paritytech/parity-common", optional = true } twox-hash = { version = "1.1.0", optional = true } byteorder = { version = "1.1", default_features = false } -blake2-rfc = { version = "0.2.18", optional = true } wasmi = { version = "0.4", optional = true } +hashdb = { git = "https://github.com/paritytech/parity-common", default_features = false } +patricia-trie = { git = "https://github.com/paritytech/parity-common", optional = true } +plain_hasher = { git = "https://github.com/paritytech/parity-common", default_features = false } + +blake2-rfc = { version = "0.2.18", optional = true } +# Switch back to Blake after PoC-3 is out and remove this +tiny-keccak = { version = "1.4", optional = true } [dev-dependencies] substrate-serializer = { path = "../serializer" } pretty_assertions = "0.4" +heapsize = "0.4" [features] default = ["std"] @@ -28,12 +37,18 @@ std = [ "wasmi", "uint/std", "fixed-hash/std", + "fixed-hash/heapsizeof", + "fixed-hash/libc", "substrate-codec/std", "substrate-runtime-std/std", "serde/std", "rustc-hex/std", "twox-hash", "blake2-rfc", + "tiny-keccak", "serde_derive", - "byteorder/std" + "byteorder/std", + "patricia-trie", + "rlp", + "elastic-array", ] diff --git a/substrate/substrate/primitives/src/hash.rs b/substrate/substrate/primitives/src/hash.rs index a0dc5f4c1c..89f2961b95 100644 --- a/substrate/substrate/primitives/src/hash.rs +++ b/substrate/substrate/primitives/src/hash.rs @@ -21,6 +21,10 @@ use serde::{Serialize, Serializer, Deserialize, Deserializer}; #[cfg(feature = "std")] use bytes; +#[cfg(feature = "std")] +use core::cmp; +#[cfg(feature = "std")] +use rlp::{Rlp, RlpStream, DecoderError}; macro_rules! impl_rest { ($name: ident, $len: expr) => { @@ -49,6 +53,29 @@ macro_rules! impl_rest { <[u8; $len] as ::codec::Decode>::decode(input).map($name) } } + + #[cfg(feature = "std")] + impl ::rlp::Encodable for $name { + fn rlp_append(&self, s: &mut RlpStream) { + s.encoder().encode_value(self); + } + } + + #[cfg(feature = "std")] + impl ::rlp::Decodable for $name { + fn decode(rlp: &Rlp) -> Result { + rlp.decoder().decode_value(|bytes| match bytes.len().cmp(&$len) { + cmp::Ordering::Less => Err(DecoderError::RlpIsTooShort), + cmp::Ordering::Greater => Err(DecoderError::RlpIsTooBig), + cmp::Ordering::Equal => { + let mut t = [0u8; $len]; + t.copy_from_slice(bytes); + Ok($name(t)) + } + }) + } + } + } } @@ -63,6 +90,26 @@ impl_rest!(H512, 64); mod tests { use super::*; use substrate_serializer as ser; + use rlp::{Encodable, RlpStream}; + + #[test] + fn test_hash_is_encodable() { + let h = H160::from(21); + let mut s = RlpStream::new(); + h.rlp_append(&mut s); + assert_eq!(s.drain().into_vec(), &[148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21]); + } + + #[test] + fn test_hash_is_decodable() { + let data = vec![148, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 123]; + let res = ::rlp::decode::(&data); + assert!(res.is_ok()); + assert_eq!(res.unwrap(), H160::from(123)); + + let res = ::rlp::decode::(&data); + assert!(res.is_err()); + } #[test] fn test_h160() { @@ -109,4 +156,11 @@ mod tests { assert!(ser::from_str::("\"0\"").unwrap_err().is_data()); assert!(ser::from_str::("\"10\"").unwrap_err().is_data()); } + + #[test] + fn test_heapsizeof() { + use heapsize::HeapSizeOf; + let h = H256::new(); + assert_eq!(h.heap_size_of_children(), 0); + } } diff --git a/substrate/substrate/primitives/src/hasher.rs b/substrate/substrate/primitives/src/hasher.rs new file mode 100644 index 0000000000..6096540aa3 --- /dev/null +++ b/substrate/substrate/primitives/src/hasher.rs @@ -0,0 +1,88 @@ +// Copyright 2018 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Polkadot Blake2b Hasher implementation + +use hashdb::Hasher; +use plain_hasher::PlainHasher; +use hash::H256; + +// Use this when switching to Blake2 after PoC-3 +// pub mod blake { +// use super::{Hasher, PlainHasher, H256}; +// #[cfg(feature = "std")] +// use hashing::blake2_256; + +// #[cfg(not(feature = "std"))] +// extern "C" { +// fn ext_blake2_256(data: *const u8, len: u32, out: *mut u8); +// } +// #[cfg(not(feature = "std"))] +// fn blake2_256(data: &[u8]) -> [u8; 32] { +// let mut result: [u8; 32] = Default::default(); +// unsafe { +// ext_blake2_256(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); +// } +// result +// } + +// /// Concrete implementation of Hasher using Blake2b 256-bit hashes +// #[derive(Debug)] +// pub struct BlakeHasher; + +// impl Hasher for BlakeHasher { +// type Out = H256; +// type StdHasher = PlainHasher; +// const LENGTH:usize = 32; +// fn hash(x: &[u8]) -> Self::Out { +// blake2_256(x).into() +// } +// } +// } + +pub mod keccak { + use super::{Hasher, PlainHasher, H256}; + + #[cfg(feature = "std")] + use tiny_keccak::keccak256; + + #[cfg(not(feature = "std"))] + extern "C" { + fn ext_keccak256(data: *const u8, len: u32, out: *mut u8); + } + + #[cfg(not(feature = "std"))] + fn keccak256(data: &[u8]) -> [u8; 32] { + let mut result: [u8; 32] = Default::default(); + unsafe { + ext_keccak256(data.as_ptr(), data.len() as u32, result.as_mut_ptr()); + } + result + } + + /// Concrete implementation of Hasher using Keccak 256-bit hashes + #[derive(Debug)] + pub struct KeccakHasher; + + impl Hasher for KeccakHasher { + type Out = H256; + type StdHasher = PlainHasher; + const LENGTH : usize = 32; + fn hash(x: &[u8]) -> Self::Out { + keccak256(x).into() + } + } +} \ No newline at end of file diff --git a/substrate/substrate/primitives/src/lib.rs b/substrate/substrate/primitives/src/lib.rs index 4ead8c4633..07f658dd8a 100644 --- a/substrate/substrate/primitives/src/lib.rs +++ b/substrate/substrate/primitives/src/lib.rs @@ -33,13 +33,20 @@ extern crate substrate_codec_derive; extern crate rustc_hex; extern crate byteorder; extern crate substrate_codec as codec; +#[cfg(feature = "std")] +extern crate rlp; #[cfg(feature = "std")] extern crate serde; #[cfg(feature = "std")] extern crate twox_hash; + #[cfg(feature = "std")] extern crate blake2_rfc; +// Switch back to Blake after PoC-3 is out +#[cfg(feature = "std")] +extern crate tiny_keccak; + #[cfg(feature = "std")] #[macro_use] extern crate serde_derive; @@ -47,12 +54,21 @@ extern crate serde_derive; extern crate core; #[cfg(feature = "std")] extern crate wasmi; +extern crate hashdb; +extern crate plain_hasher; +#[cfg(feature = "std")] +extern crate patricia_trie; +#[cfg(feature = "std")] +extern crate elastic_array; extern crate substrate_runtime_std as rstd; #[cfg(test)] extern crate substrate_serializer; +#[cfg(test)] +extern crate heapsize; + #[cfg(test)] #[macro_use] extern crate pretty_assertions; @@ -77,18 +93,28 @@ pub use hashing::{blake2_256, twox_128, twox_256}; pub mod hexdisplay; pub mod hash; +mod hasher; pub mod sandbox; pub mod storage; pub mod uint; mod authority_id; +#[cfg(feature = "std")] +mod rlp_codec; #[cfg(test)] mod tests; pub use self::hash::{H160, H256, H512}; -pub use self::uint::{U256, U512}; +pub use self::uint::U256; pub use authority_id::AuthorityId; +// Switch back to Blake after PoC-3 is out +// pub use self::hasher::blake::BlakeHasher; +pub use self::hasher::keccak::KeccakHasher; + +#[cfg(feature = "std")] +pub use self::rlp_codec::RlpCodec; + /// A 512-bit value interpreted as a signature. pub type Signature = hash::H512; diff --git a/substrate/substrate/primitives/src/rlp_codec.rs b/substrate/substrate/primitives/src/rlp_codec.rs new file mode 100644 index 0000000000..5a779cb738 --- /dev/null +++ b/substrate/substrate/primitives/src/rlp_codec.rs @@ -0,0 +1,129 @@ +// Copyright 2018 Parity Technologies (UK) Ltd. +// This file is part of Polkadot. + +// Polkadot 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. + +// Polkadot 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 Polkadot. If not, see . + +//! Polkadot Blake2b (trie) NodeCodec implementation + +use elastic_array::{ElasticArray1024, ElasticArray128}; +use hashdb::Hasher; +use rlp::{DecoderError, RlpStream, Rlp, Prototype}; +use core::marker::PhantomData; +use patricia_trie::{NibbleSlice, NodeCodec, node::Node, ChildReference}; + +use hash::H256; +// When switching to Blake2, use this instead: +// use BlakeHasher; +use KeccakHasher; + +/// Concrete implementation of a `NodeCodec` with Rlp encoding, generic over the `Hasher` +pub struct RlpNodeCodec {mark: PhantomData} + +/// Convenience type for a Keccak/Rlp flavoured NodeCodec +pub type RlpCodec = RlpNodeCodec; +// When switching to Blake2, use this instead: +// pub type RlpCodec = RlpNodeCodec; + +impl NodeCodec for RlpCodec { + type Error = DecoderError; + // When switching to Blake2, use this null node + // const HASHED_NULL_NODE : H256 = H256( [0x45, 0xb0, 0xcf, 0xc2, 0x20, 0xce, 0xec, 0x5b, 0x7c, 0x1c, 0x62, 0xc4, 0xd4, 0x19, 0x3d, 0x38, 0xe4, 0xeb, 0xa4, 0x8e, 0x88, 0x15, 0x72, 0x9c, 0xe7, 0x5f, 0x9c, 0xa, 0xb0, 0xe4, 0xc1, 0xc0] ); + const HASHED_NULL_NODE : H256 = H256( [0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21] ); + fn decode(data: &[u8]) -> ::std::result::Result { + let r = Rlp::new(data); + match r.prototype()? { + // either leaf or extension - decode first item with NibbleSlice::??? + // and use is_leaf return to figure out which. + // if leaf, second item is a value (is_data()) + // if extension, second item is a node (either SHA3 to be looked up and + // fed back into this function or inline RLP which can be fed back into this function). + Prototype::List(2) => match NibbleSlice::from_encoded(r.at(0)?.data()?) { + (slice, true) => Ok(Node::Leaf(slice, r.at(1)?.data()?)), + (slice, false) => Ok(Node::Extension(slice, r.at(1)?.as_raw())), + }, + // branch - first 16 are nodes, 17th is a value (or empty). + Prototype::List(17) => { + let mut nodes = [&[] as &[u8]; 16]; + for i in 0..16 { + nodes[i] = r.at(i)?.as_raw(); + } + Ok(Node::Branch(nodes, if r.at(16)?.is_empty() { None } else { Some(r.at(16)?.data()?) })) + }, + // an empty branch index. + Prototype::Data(0) => Ok(Node::Empty), + // something went wrong. + _ => Err(DecoderError::Custom("Rlp is not valid.")) + } + } + fn try_decode_hash(data: &[u8]) -> Option<::Out> { + let r = Rlp::new(data); + if r.is_data() && r.size() == KeccakHasher::LENGTH { + Some(r.as_val().expect("Hash is the correct size; qed")) + } else { + None + } + } + fn is_empty_node(data: &[u8]) -> bool { + Rlp::new(data).is_empty() + } + fn empty_node() -> ElasticArray1024 { + let mut stream = RlpStream::new(); + stream.append_empty_data(); + stream.drain() + } + + fn leaf_node(partial: &[u8], value: &[u8]) -> ElasticArray1024 { + let mut stream = RlpStream::new_list(2); + stream.append(&partial); + stream.append(&value); + stream.drain() + } + + fn ext_node(partial: &[u8], child_ref: ChildReference<::Out>) -> ElasticArray1024 { + let mut stream = RlpStream::new_list(2); + stream.append(&partial); + match child_ref { + ChildReference::Hash(h) => stream.append(&h), + ChildReference::Inline(inline_data, len) => { + let bytes = &AsRef::<[u8]>::as_ref(&inline_data)[..len]; + stream.append_raw(bytes, 1) + }, + }; + stream.drain() + } + + fn branch_node(children: I, value: Option>) -> ElasticArray1024 + where I: IntoIterator::Out>>> + { + let mut stream = RlpStream::new_list(17); + for child_ref in children { + match child_ref { + Some(c) => match c { + ChildReference::Hash(h) => stream.append(&h), + ChildReference::Inline(inline_data, len) => { + let bytes = &AsRef::<[u8]>::as_ref(&inline_data)[..len]; + stream.append_raw(bytes, 1) + }, + }, + None => stream.append_empty_data() + }; + } + if let Some(value) = value { + stream.append(&&*value); + } else { + stream.append_empty_data(); + } + stream.drain() + } +} \ No newline at end of file diff --git a/substrate/substrate/primitives/src/uint.rs b/substrate/substrate/primitives/src/uint.rs index b14a8aa4fd..92ab73b70a 100644 --- a/substrate/substrate/primitives/src/uint.rs +++ b/substrate/substrate/primitives/src/uint.rs @@ -44,9 +44,7 @@ macro_rules! impl_serde { } construct_uint!(U256, 4); -construct_uint!(U512, 8); impl_serde!(U256, 4); -impl_serde!(U512, 8); #[cfg(test)] mod tests { @@ -68,7 +66,7 @@ mod tests { ($name::from(1_000), "0x3e8"), ($name::from(100_000), "0x186a0"), ($name::from(u64::max_value()), "0xffffffffffffffff"), - ($name::from(u64::max_value()) + 1.into(), "0x10000000000000000"), + ($name::from(u64::max_value()) + $name::from(1), "0x10000000000000000"), ]; for (number, expected) in tests { @@ -87,7 +85,6 @@ mod tests { } test!(U256, test_u256); - test!(U512, test_u512); #[test] fn test_large_values() { diff --git a/substrate/substrate/rpc-servers/Cargo.toml b/substrate/substrate/rpc-servers/Cargo.toml index dec067b409..6b7038d44a 100644 --- a/substrate/substrate/rpc-servers/Cargo.toml +++ b/substrate/substrate/rpc-servers/Cargo.toml @@ -9,5 +9,6 @@ jsonrpc-http-server = { git = "https://github.com/paritytech/jsonrpc.git" } jsonrpc-pubsub = { git = "https://github.com/paritytech/jsonrpc.git" } jsonrpc-ws-server = { git = "https://github.com/paritytech/jsonrpc.git" } log = "0.3" +serde = "1.0" substrate-rpc = { path = "../rpc", version = "0.1" } substrate-runtime-primitives = { path = "../runtime/primitives" } diff --git a/substrate/substrate/rpc-servers/src/lib.rs b/substrate/substrate/rpc-servers/src/lib.rs index 11fa9aa9b6..e42996ff6c 100644 --- a/substrate/substrate/rpc-servers/src/lib.rs +++ b/substrate/substrate/rpc-servers/src/lib.rs @@ -24,6 +24,7 @@ extern crate jsonrpc_core as rpc; extern crate jsonrpc_http_server as http; extern crate jsonrpc_pubsub as pubsub; extern crate jsonrpc_ws_server as ws; +extern crate serde; extern crate substrate_runtime_primitives; #[macro_use] @@ -38,16 +39,17 @@ pub type HttpServer = http::Server; pub type WsServer = ws::Server; /// Construct rpc `IoHandler` -pub fn rpc_handler( +pub fn rpc_handler( state: S, chain: C, author: A, system: Y, ) -> RpcHandler where - Block: 'static, + Block: BlockT + 'static, + PendingExtrinsics: serde::Serialize + serde::de::DeserializeOwned + Send + Sync + 'static, S: apis::state::StateApi, - C: apis::chain::ChainApi, - A: apis::author::AuthorApi, + C: apis::chain::ChainApi, + A: apis::author::AuthorApi, Y: apis::system::SystemApi, { let mut io = pubsub::PubSubHandler::default(); diff --git a/substrate/substrate/rpc/src/author/mod.rs b/substrate/substrate/rpc/src/author/mod.rs index 9077abdc3f..d63bf95a63 100644 --- a/substrate/substrate/rpc/src/author/mod.rs +++ b/substrate/substrate/rpc/src/author/mod.rs @@ -26,7 +26,7 @@ use extrinsic_pool::{ }; use jsonrpc_macros::pubsub; use jsonrpc_pubsub::SubscriptionId; -use primitives::Bytes; +use primitives::{Bytes, KeccakHasher, RlpCodec}; use rpc::futures::{Sink, Stream, Future}; use runtime_primitives::{generic, traits}; use subscriptions::Subscriptions; @@ -41,7 +41,7 @@ use self::error::Result; build_rpc_trait! { /// Substrate authoring RPC API - pub trait AuthorApi { + pub trait AuthorApi { type Metadata; /// Submit extrinsic for inclusion in block. @@ -51,6 +51,10 @@ build_rpc_trait! { #[rpc(name = "author_submitExtrinsic")] fn submit_extrinsic(&self, Bytes) -> Result; + /// Returns all pending extrinsics, potentially grouped by sender. + #[rpc(name = "author_pendingExtrinsics")] + fn pending_extrinsics(&self) -> Result; + #[pubsub(name = "author_extrinsicUpdate")] { /// Submit an extrinsic to watch. #[rpc(name = "author_submitAndWatchExtrinsic")] @@ -60,7 +64,6 @@ build_rpc_trait! { #[rpc(name = "author_unwatchExtrinsic")] fn unwatch_extrinsic(&self, SubscriptionId) -> Result; } - } } @@ -85,12 +88,13 @@ impl Author { } } -impl AuthorApi for Author where - B: client::backend::Backend + Send + Sync + 'static, - E: client::CallExecutor + Send + Sync + 'static, +impl AuthorApi for Author where + B: client::backend::Backend + Send + Sync + 'static, + E: client::CallExecutor + Send + Sync + 'static, Block: traits::Block + 'static, - Hash: traits::MaybeSerializeDebug + Sync + Send + 'static, - P: ExtrinsicPool, Hash>, + Hash: traits::MaybeSerializeDebug + Send + Sync + 'static, + InPool: traits::MaybeSerializeDebug + Send + Sync + 'static, + P: ExtrinsicPool, Hash, InPool=InPool>, P::Error: 'static, Ex: Codec, { @@ -112,6 +116,10 @@ impl AuthorApi for Author wh ) } + fn pending_extrinsics(&self) -> Result { + Ok(self.pool.all()) + } + fn watch_extrinsic(&self, _metadata: Self::Metadata, subscriber: pubsub::Subscriber>, xt: Bytes) { let submit = || -> Result<_> { @@ -146,3 +154,4 @@ impl AuthorApi for Author wh Ok(self.subscriptions.cancel(id)) } } + diff --git a/substrate/substrate/rpc/src/author/tests.rs b/substrate/substrate/rpc/src/author/tests.rs index 116ca7ea2c..ebca4596ad 100644 --- a/substrate/substrate/rpc/src/author/tests.rs +++ b/substrate/substrate/rpc/src/author/tests.rs @@ -46,6 +46,7 @@ impl fmt::Display for Error { impl api::ExtrinsicPool for DummyTxPool { type Error = Error; + type InPool = Vec; /// Submit extrinsic for inclusion in block. fn submit(&self, _block: BlockHash, xt: Vec) -> Result, Self::Error> { @@ -79,6 +80,10 @@ impl api::ExtrinsicPool for DummyTxPool { fn import_notification_stream(&self) -> api::EventStream { unreachable!() } + + fn all(&self) -> Self::InPool { + vec![1, 2, 3, 4, 5] + } } #[test] @@ -143,3 +148,18 @@ fn should_watch_extrinsic() { Some(r#"{"jsonrpc":"2.0","method":"test","params":{"result":{"usurped":5},"subscription":0}}"#.into()) ); } + +#[test] +fn should_return_pending_extrinsics() { + let runtime = runtime::Runtime::new().unwrap(); + let p = Author { + client: Arc::new(test_client::new()), + pool: Arc::new(DummyTxPool::default()), + subscriptions: Subscriptions::new(runtime.executor()), + }; + + assert_matches!( + p.pending_extrinsics(), + Ok(ref expected) if expected == &[1u8, 2, 3, 4, 5] + ); +} diff --git a/substrate/substrate/rpc/src/chain/mod.rs b/substrate/substrate/rpc/src/chain/mod.rs index 3c0491c422..5662a5a0b3 100644 --- a/substrate/substrate/rpc/src/chain/mod.rs +++ b/substrate/substrate/rpc/src/chain/mod.rs @@ -23,9 +23,10 @@ use jsonrpc_macros::pubsub; use jsonrpc_pubsub::SubscriptionId; use rpc::Result as RpcResult; use rpc::futures::{stream, Future, Sink, Stream}; -use runtime_primitives::generic::BlockId; +use runtime_primitives::generic::{BlockId, SignedBlock}; use runtime_primitives::traits::Block as BlockT; use tokio::runtime::TaskExecutor; +use primitives::{KeccakHasher, RlpCodec}; use subscriptions::Subscriptions; @@ -37,13 +38,17 @@ use self::error::Result; build_rpc_trait! { /// Polkadot blockchain API - pub trait ChainApi { + pub trait ChainApi { type Metadata; /// Get header of a relay chain block. #[rpc(name = "chain_getHeader")] fn header(&self, Hash) -> Result>; + /// Get header and body of a relay chain block. + #[rpc(name = "chain_getBlock")] + fn block(&self, Hash) -> Result>>; + /// Get hash of the head. #[rpc(name = "chain_getHead")] fn head(&self) -> Result; @@ -78,10 +83,10 @@ impl Chain { } } -impl ChainApi for Chain where +impl ChainApi for Chain where Block: BlockT + 'static, - B: client::backend::Backend + Send + Sync + 'static, - E: client::CallExecutor + Send + Sync + 'static, + B: client::backend::Backend + Send + Sync + 'static, + E: client::CallExecutor + Send + Sync + 'static, { type Metadata = ::metadata::Metadata; @@ -89,6 +94,10 @@ impl ChainApi for Chain wh Ok(self.client.header(&BlockId::Hash(hash))?) } + fn block(&self, hash: Block::Hash) -> Result>> { + Ok(self.client.block(&BlockId::Hash(hash))?) + } + fn head(&self) -> Result { Ok(self.client.info()?.chain.best_hash) } diff --git a/substrate/substrate/rpc/src/chain/tests.rs b/substrate/substrate/rpc/src/chain/tests.rs index 1f0a3a9d01..eac9abd5c4 100644 --- a/substrate/substrate/rpc/src/chain/tests.rs +++ b/substrate/substrate/rpc/src/chain/tests.rs @@ -18,7 +18,7 @@ use super::*; use jsonrpc_macros::pubsub; use client::BlockOrigin; use test_client::{self, TestClient}; -use test_client::runtime::Header; +use test_client::runtime::{Block, Header}; #[test] fn should_return_header() { @@ -46,6 +46,47 @@ fn should_return_header() { ); } +#[test] +fn should_return_a_block() { + let core = ::tokio::runtime::Runtime::new().unwrap(); + let remote = core.executor(); + + let api = Chain { + client: Arc::new(test_client::new()), + subscriptions: Subscriptions::new(remote), + }; + + let block = api.client.new_block().unwrap().bake().unwrap(); + let block_hash = block.hash(); + api.client.justify_and_import(BlockOrigin::Own, block).unwrap(); + + + // Genesis block is not justified, so we can't query it? + assert_matches!( + api.block(api.client.genesis_hash()), + Ok(None) + ); + + assert_matches!( + api.block(block_hash), + Ok(Some(ref x)) if x.block == Block { + header: Header { + parent_hash: api.client.genesis_hash(), + number: 1, + state_root: x.block.header.state_root.clone(), + extrinsics_root: "56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421".into(), + digest: Default::default(), + }, + extrinsics: vec![], + } + ); + + assert_matches!( + api.block(5.into()), + Ok(None) + ); +} + #[test] fn should_notify_about_latest_block() { let mut core = ::tokio::runtime::Runtime::new().unwrap(); diff --git a/substrate/substrate/rpc/src/state/mod.rs b/substrate/substrate/rpc/src/state/mod.rs index 0ae462452f..28aa017109 100644 --- a/substrate/substrate/rpc/src/state/mod.rs +++ b/substrate/substrate/rpc/src/state/mod.rs @@ -27,6 +27,7 @@ use jsonrpc_macros::pubsub; use jsonrpc_pubsub::SubscriptionId; use primitives::hexdisplay::HexDisplay; use primitives::storage::{StorageKey, StorageData, StorageChangeSet}; +use primitives::{KeccakHasher, RlpCodec}; use rpc::Result as RpcResult; use rpc::futures::{stream, Future, Sink, Stream}; use runtime_primitives::generic::BlockId; @@ -101,8 +102,8 @@ impl State { impl State where Block: BlockT + 'static, - B: client::backend::Backend + Send + Sync + 'static, - E: CallExecutor + Send + Sync + 'static, + B: client::backend::Backend + Send + Sync + 'static, + E: CallExecutor + Send + Sync + 'static, { fn unwrap_or_best(&self, hash: Trailing) -> Result { Ok(match hash.into() { @@ -114,8 +115,8 @@ impl State where impl StateApi for State where Block: BlockT + 'static, - B: client::backend::Backend + Send + Sync + 'static, - E: CallExecutor + Send + Sync + 'static, + B: client::backend::Backend + Send + Sync + 'static, + E: CallExecutor + Send + Sync + 'static, { type Metadata = ::metadata::Metadata; diff --git a/substrate/substrate/runtime-io/with_std.rs b/substrate/substrate/runtime-io/with_std.rs index 3d3b255208..f543b8ae2c 100644 --- a/substrate/substrate/runtime-io/with_std.rs +++ b/substrate/substrate/runtime-io/with_std.rs @@ -29,12 +29,16 @@ pub extern crate substrate_codec as codec; // re-export hashing functions. pub use primitives::{blake2_256, twox_128, twox_256}; +pub use primitives::KeccakHasher; +// Switch to this after PoC-3 +// pub use primitives::BlakeHasher; pub use substrate_state_machine::{Externalities, TestExternalities}; use primitives::hexdisplay::HexDisplay; +use primitives::H256; // TODO: use the real error, not NoError. -environmental!(ext: trait Externalities); +environmental!(ext: trait Externalities); /// Get `key` from storage and return a `Vec`, empty if there's a problem. pub fn storage(key: &[u8]) -> Option> { @@ -90,10 +94,10 @@ pub fn chain_id() -> u64 { } /// "Commit" all existing operations and get the resultant storage root. -pub fn storage_root() -> [u8; 32] { +pub fn storage_root() -> H256 { ext::with(|ext| ext.storage_root() - ).unwrap_or([0u8; 32]) + ).unwrap_or(H256::new()) } /// A trie root formed from the enumerated items. @@ -125,7 +129,8 @@ pub fn ed25519_verify>(sig: &[u8; 64], msg: &[u8], pubkey: P) -> /// Execute the given closure with global function available whose functionality routes into the /// externalities `ext`. Forwards the value that the closure returns. -pub fn with_externalities R>(ext: &mut Externalities, f: F) -> R { +// NOTE: need a concrete hasher here due to limitations of the `environmental!` macro, otherwise a type param would have been fine I think. +pub fn with_externalities R>(ext: &mut Externalities, f: F) -> R { ext::using(ext, f) } @@ -191,7 +196,7 @@ mod std_tests { #[test] fn storage_works() { - let mut t = TestExternalities::new(); + let mut t = TestExternalities::::new(); assert!(with_externalities(&mut t, || { assert_eq!(storage(b"hello"), None); set_storage(b"hello", b"world"); @@ -212,7 +217,7 @@ mod std_tests { #[test] fn read_storage_works() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ b":test".to_vec() => b"\x0b\0\0\0Hello world".to_vec() ]; @@ -228,7 +233,7 @@ mod std_tests { #[test] fn clear_prefix_works() { - let mut t: TestExternalities = map![ + let mut t: TestExternalities = map![ b":a".to_vec() => b"\x0b\0\0\0Hello world".to_vec(), b":abcd".to_vec() => b"\x0b\0\0\0Hello world".to_vec(), b":abc".to_vec() => b"\x0b\0\0\0Hello world".to_vec(), diff --git a/substrate/substrate/runtime/consensus/src/lib.rs b/substrate/substrate/runtime/consensus/src/lib.rs index 13d40afe5e..3b9e2554b4 100644 --- a/substrate/substrate/runtime/consensus/src/lib.rs +++ b/substrate/substrate/runtime/consensus/src/lib.rs @@ -45,6 +45,11 @@ use runtime_support::storage::unhashed::StorageVec; use primitives::traits::{RefInto, MaybeSerializeDebug, MaybeEmpty}; use primitives::bft::MisbehaviorReport; +#[cfg(any(feature = "std", test))] +use substrate_primitives::KeccakHasher; +#[cfg(any(feature = "std", test))] +use std::collections::HashMap; + pub const AUTHORITY_AT: &'static [u8] = b":auth:"; pub const AUTHORITY_COUNT: &'static [u8] = b":auth:len"; @@ -146,14 +151,14 @@ impl Default for GenesisConfig { #[cfg(any(feature = "std", test))] impl primitives::BuildStorage for GenesisConfig { - fn build_storage(self) -> ::std::result::Result { + fn build_storage(self) -> ::std::result::Result, Vec>, String> { use codec::{Encode, KeyedVec}; let auth_count = self.authorities.len() as u32; - let mut r: runtime_io::TestExternalities = self.authorities.into_iter().enumerate().map(|(i, v)| + let mut r: runtime_io::TestExternalities = self.authorities.into_iter().enumerate().map(|(i, v)| ((i as u32).to_keyed_vec(AUTHORITY_AT), v.encode()) ).collect(); r.insert(AUTHORITY_COUNT.to_vec(), auth_count.encode()); r.insert(CODE.to_vec(), self.code); - Ok(r) + Ok(r.into()) } } diff --git a/substrate/substrate/runtime/contract/Cargo.toml b/substrate/substrate/runtime/contract/Cargo.toml index 23291d4d67..0658425c06 100644 --- a/substrate/substrate/runtime/contract/Cargo.toml +++ b/substrate/substrate/runtime/contract/Cargo.toml @@ -7,6 +7,7 @@ authors = ["Parity Technologies "] serde = { version = "1.0", default_features = false } serde_derive = { version = "1.0", optional = true } substrate-codec = { path = "../../codec", default_features = false } +substrate-primitives = { path = "../../primitives" } substrate-runtime-consensus = { path = "../../runtime/consensus", default_features = false } substrate-runtime-primitives = { path = "../../runtime/primitives" } substrate-runtime-io = { path = "../../runtime-io", default_features = false } diff --git a/substrate/substrate/runtime/contract/src/gas.rs b/substrate/substrate/runtime/contract/src/gas.rs index 662ddc4fbd..2f2b82d6b0 100644 --- a/substrate/substrate/runtime/contract/src/gas.rs +++ b/substrate/substrate/runtime/contract/src/gas.rs @@ -136,6 +136,7 @@ pub fn buy_gas( return Err("not enough funds for transaction fee"); } >::set_free_balance(transactor, b - cost); + >::decrease_total_stake_by(cost); Ok(GasMeter { gas_left: gas_limit, gas_price, @@ -147,4 +148,5 @@ pub fn refund_unused_gas(transactor: &T::AccountId, gas_meter: GasMete let b = >::free_balance(transactor); let refund = >::as_(gas_meter.gas_left) * gas_meter.gas_price; >::set_free_balance(transactor, b + refund); + >::increase_total_stake_by(refund); } diff --git a/substrate/substrate/runtime/contract/src/genesis_config.rs b/substrate/substrate/runtime/contract/src/genesis_config.rs index d841f22806..89f94b40b9 100644 --- a/substrate/substrate/runtime/contract/src/genesis_config.rs +++ b/substrate/substrate/runtime/contract/src/genesis_config.rs @@ -22,6 +22,8 @@ use runtime_primitives; use runtime_io::{self, twox_128}; use runtime_support::StorageValue; use codec::Encode; +use std::collections::HashMap; +use substrate_primitives::KeccakHasher; #[derive(Serialize, Deserialize)] #[serde(rename_all = "camelCase")] @@ -35,14 +37,14 @@ pub struct GenesisConfig { } impl runtime_primitives::BuildStorage for GenesisConfig { - fn build_storage(self) -> Result { - let r: runtime_io::TestExternalities = map![ + fn build_storage(self) -> ::std::result::Result, Vec>, String> { + let r: runtime_io::TestExternalities = map![ twox_128(>::key()).to_vec() => self.contract_fee.encode(), twox_128(>::key()).to_vec() => self.call_base_fee.encode(), twox_128(>::key()).to_vec() => self.create_base_fee.encode(), twox_128(>::key()).to_vec() => self.gas_price.encode(), twox_128(>::key()).to_vec() => self.max_depth.encode() ]; - Ok(r) + Ok(r.into()) } } diff --git a/substrate/substrate/runtime/contract/src/lib.rs b/substrate/substrate/runtime/contract/src/lib.rs index 123574b27c..6761c03442 100644 --- a/substrate/substrate/runtime/contract/src/lib.rs +++ b/substrate/substrate/runtime/contract/src/lib.rs @@ -65,6 +65,7 @@ extern crate substrate_runtime_session as session; extern crate substrate_runtime_support as runtime_support; extern crate substrate_runtime_primitives as runtime_primitives; +extern crate substrate_primitives; #[cfg(test)] #[macro_use] diff --git a/substrate/substrate/runtime/contract/src/tests.rs b/substrate/substrate/runtime/contract/src/tests.rs index f79b155cf5..53a324907e 100644 --- a/substrate/substrate/runtime/contract/src/tests.rs +++ b/substrate/substrate/runtime/contract/src/tests.rs @@ -20,6 +20,7 @@ use runtime_primitives::testing::{Digest, H256, Header}; use runtime_primitives::traits::{BlakeTwo256, HasPublicAux, Identity}; use runtime_primitives::BuildStorage; use runtime_support::StorageMap; +use substrate_primitives::KeccakHasher; use wabt; use { consensus, runtime_io, session, staking, system, timestamp, CodeOf, ContractAddressFor, @@ -73,7 +74,7 @@ impl ContractAddressFor for DummyContractAddressFor { } } -fn new_test_ext(existential_deposit: u64, gas_price: u64) -> runtime_io::TestExternalities { +fn new_test_ext(existential_deposit: u64, gas_price: u64) -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default() .build_storage() .unwrap(); @@ -126,7 +127,7 @@ fn new_test_ext(existential_deposit: u64, gas_price: u64) -> runtime_io::TestExt }.build_storage() .unwrap(), ); - t + t.into() } const CODE_TRANSFER: &str = r#" @@ -162,7 +163,9 @@ fn contract_transfer() { >::insert(1, code_transfer.to_vec()); Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); Staking::set_free_balance(&1, 11); + Staking::increase_total_stake_by(11); assert_ok!(Contract::call(&0, 1, 3, 100_000, Vec::new())); @@ -195,7 +198,9 @@ fn contract_transfer_oog() { >::insert(1, code_transfer.to_vec()); Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); Staking::set_free_balance(&1, 11); + Staking::increase_total_stake_by(11); assert_err!( Contract::call(&0, 1, 3, 276, Vec::new()), @@ -232,7 +237,9 @@ fn contract_transfer_max_depth() { >::insert(CONTRACT_SHOULD_TRANSFER_TO, code_transfer.to_vec()); Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); Staking::set_free_balance(&CONTRACT_SHOULD_TRANSFER_TO, 11); + Staking::increase_total_stake_by(11); assert_err!( Contract::call(&0, CONTRACT_SHOULD_TRANSFER_TO, 3, 100_000, Vec::new()), @@ -331,8 +338,10 @@ fn contract_create() { with_externalities(&mut new_test_ext(0, 2), || { Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); Staking::set_free_balance(&1, 0); Staking::set_free_balance(&9, 30); + Staking::increase_total_stake_by(30); >::insert(1, code_create.to_vec()); @@ -383,7 +392,9 @@ fn top_level_create() { ); Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); Staking::set_free_balance(&derived_address, 30); + Staking::increase_total_stake_by(30); assert_ok!(Contract::create( &0, @@ -423,6 +434,7 @@ fn refunds_unused_gas() { >::insert(1, code_nop.to_vec()); Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); assert_ok!(Contract::call(&0, 1, 0, 100_000, Vec::new(),)); @@ -436,6 +448,7 @@ fn call_with_zero_value() { >::insert(1, vec![]); Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); assert_ok!(Contract::call(&0, 1, 0, 100_000, Vec::new(),)); @@ -449,6 +462,7 @@ fn create_with_zero_endowment() { with_externalities(&mut new_test_ext(0, 2), || { Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); assert_ok!(Contract::create(&0, 0, 100_000, code_nop, Vec::new(),)); @@ -467,10 +481,12 @@ fn account_removal_removes_storage() { // Setup two accounts with free balance above than exsistential threshold. { Staking::set_free_balance(&1, 110); + Staking::increase_total_stake_by(110); >::insert(1, b"foo".to_vec(), b"1".to_vec()); >::insert(1, b"bar".to_vec(), b"2".to_vec()); Staking::set_free_balance(&2, 110); + Staking::increase_total_stake_by(110); >::insert(2, b"hello".to_vec(), b"3".to_vec()); >::insert(2, b"world".to_vec(), b"4".to_vec()); } @@ -515,6 +531,7 @@ fn top_level_call_refunds_even_if_fails() { >::insert(1, code_unreachable.to_vec()); Staking::set_free_balance(&0, 100_000_000); + Staking::increase_total_stake_by(100_000_000); assert_err!( Contract::call(&0, 1, 0, 100_000, Vec::new()), diff --git a/substrate/substrate/runtime/council/src/lib.rs b/substrate/substrate/runtime/council/src/lib.rs index 1fd210021a..78be6c1804 100644 --- a/substrate/substrate/runtime/council/src/lib.rs +++ b/substrate/substrate/runtime/council/src/lib.rs @@ -46,6 +46,8 @@ use primitives::traits::{Zero, One, RefInto, As, AuxLookup}; use substrate_runtime_support::{StorageValue, StorageMap}; use substrate_runtime_support::dispatch::Result; use staking::address::Address; +#[cfg(any(feature = "std", test))] +use std::collections::HashMap; pub mod voting; @@ -590,7 +592,7 @@ impl Default for GenesisConfig { #[cfg(any(feature = "std", test))] impl primitives::BuildStorage for GenesisConfig { - fn build_storage(self) -> ::std::result::Result { + fn build_storage(self) -> ::std::result::Result, Vec>, String> { use codec::Encode; Ok(map![ @@ -614,12 +616,14 @@ impl primitives::BuildStorage for GenesisConfig #[cfg(test)] mod tests { + // These re-exports are here for a reason, edit with care pub use super::*; pub use runtime_io::with_externalities; pub use substrate_primitives::H256; use primitives::BuildStorage; use primitives::traits::{HasPublicAux, Identity, BlakeTwo256}; use primitives::testing::{Digest, Header}; + use substrate_primitives::KeccakHasher; impl_outer_dispatch! { #[derive(Debug, Clone, Eq, Serialize, Deserialize, PartialEq)] @@ -667,7 +671,7 @@ mod tests { } impl Trait for Test {} - pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities { + pub fn new_test_ext(with_council: bool) -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(consensus::GenesisConfig::{ code: vec![], @@ -718,7 +722,7 @@ mod tests { voting_period: 1, }.build_storage().unwrap()); t.extend(timestamp::GenesisConfig::::default().build_storage().unwrap()); - t + t.into() } pub type System = system::Module; @@ -784,7 +788,7 @@ mod tests { }); } - fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities { + fn new_test_ext_with_candidate_holes() -> runtime_io::TestExternalities { let mut t = new_test_ext(false); with_externalities(&mut t, || { >::put(vec![0, 0, 1]); diff --git a/substrate/substrate/runtime/democracy/src/lib.rs b/substrate/substrate/runtime/democracy/src/lib.rs index 6e07a1991b..2c07d5b0d0 100644 --- a/substrate/substrate/runtime/democracy/src/lib.rs +++ b/substrate/substrate/runtime/democracy/src/lib.rs @@ -51,6 +51,9 @@ use primitives::traits::{Zero, Executable, RefInto, As, MaybeSerializeDebug}; use substrate_runtime_support::{StorageValue, StorageMap, Parameter, Dispatchable, IsSubType}; use substrate_runtime_support::dispatch::Result; +#[cfg(any(feature = "std", test))] +use std::collections::HashMap; + mod vote_threshold; pub use vote_threshold::{Approved, VoteThreshold}; @@ -339,7 +342,7 @@ impl Default for GenesisConfig { #[cfg(any(feature = "std", test))] impl primitives::BuildStorage for GenesisConfig { - fn build_storage(self) -> ::std::result::Result { + fn build_storage(self) -> ::std::result::Result, Vec>, String> { use codec::Encode; Ok(map![ @@ -357,7 +360,7 @@ impl primitives::BuildStorage for GenesisConfig mod tests { use super::*; use runtime_io::with_externalities; - use substrate_primitives::H256; + use substrate_primitives::{H256, KeccakHasher}; use primitives::BuildStorage; use primitives::traits::{HasPublicAux, Identity, BlakeTwo256}; use primitives::testing::{Digest, Header}; @@ -409,7 +412,7 @@ mod tests { type Proposal = Proposal; } - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(consensus::GenesisConfig::{ code: vec![], @@ -442,7 +445,7 @@ mod tests { minimum_deposit: 1, }.build_storage().unwrap()); t.extend(timestamp::GenesisConfig::::default().build_storage().unwrap()); - t + t.into() } type System = system::Module; diff --git a/substrate/substrate/runtime/executive/src/lib.rs b/substrate/substrate/runtime/executive/src/lib.rs index a918f062e8..6910f65ee3 100644 --- a/substrate/substrate/runtime/executive/src/lib.rs +++ b/substrate/substrate/runtime/executive/src/lib.rs @@ -218,7 +218,7 @@ mod tests { use super::*; use staking::Call; use runtime_io::with_externalities; - use substrate_primitives::H256; + use substrate_primitives::{H256, KeccakHasher}; use primitives::BuildStorage; use primitives::traits::{HasPublicAux, Identity, Header as HeaderT, BlakeTwo256, AuxLookup}; use primitives::testing::{Digest, Header, Block}; @@ -289,6 +289,7 @@ mod tests { session_reward: 0, }.build_storage().unwrap()); let xt = primitives::testing::TestXt((1, 0, Call::transfer(2.into(), 69))); + let mut t = runtime_io::TestExternalities::from(t); with_externalities(&mut t, || { Executive::initialise_block(&Header::new(1, H256::default(), H256::default(), [69u8; 32].into(), Digest::default())); Executive::apply_extrinsic(xt).unwrap(); @@ -297,13 +298,13 @@ mod tests { }); } - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(consensus::GenesisConfig::::default().build_storage().unwrap()); t.extend(session::GenesisConfig::::default().build_storage().unwrap()); t.extend(staking::GenesisConfig::::default().build_storage().unwrap()); t.extend(timestamp::GenesisConfig::::default().build_storage().unwrap()); - t + t.into() } #[test] @@ -313,8 +314,11 @@ mod tests { header: Header { parent_hash: [69u8; 32].into(), number: 1, + // Blake + // state_root: hex!("02532989c613369596025dfcfc821339fc9861987003924913a5a1382f87034a").into(), + // Keccak state_root: hex!("8fad93b6b9e5251a2e4913598fd0d74a138c0e486eb1133ff8081b429b0c56f2").into(), - extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), + extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), // REVIEW: I expected this to be wrong with a different hasher? digest: Digest { logs: vec![], }, }, extrinsics: vec![], diff --git a/substrate/substrate/runtime/session/src/lib.rs b/substrate/substrate/runtime/session/src/lib.rs index 9870b81f9a..59ba338e77 100644 --- a/substrate/substrate/runtime/session/src/lib.rs +++ b/substrate/substrate/runtime/session/src/lib.rs @@ -50,6 +50,9 @@ use primitives::traits::{Zero, One, RefInto, MaybeEmpty, Executable, Convert, As use runtime_support::{StorageValue, StorageMap}; use runtime_support::dispatch::Result; +#[cfg(any(feature = "std", test))] +use std::collections::HashMap; + /// A session has changed. pub trait OnSessionChange { /// Session has changed. @@ -265,7 +268,8 @@ impl Default for GenesisConfig { #[cfg(any(feature = "std", test))] impl primitives::BuildStorage for GenesisConfig { - fn build_storage(self) -> ::std::result::Result { + fn build_storage(self) -> ::std::result::Result, Vec>, String> { + use codec::Encode; use primitives::traits::As; Ok(map![ @@ -282,7 +286,7 @@ impl primitives::BuildStorage for GenesisConfig mod tests { use super::*; use runtime_io::with_externalities; - use substrate_primitives::H256; + use substrate_primitives::{H256, KeccakHasher}; use primitives::BuildStorage; use primitives::traits::{HasPublicAux, Identity, BlakeTwo256}; use primitives::testing::{Digest, Header}; @@ -320,7 +324,7 @@ mod tests { type Timestamp = timestamp::Module; type Session = Module; - fn new_test_ext() -> runtime_io::TestExternalities { + fn new_test_ext() -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(consensus::GenesisConfig::{ code: vec![], @@ -334,7 +338,7 @@ mod tests { validators: vec![1, 2, 3], broken_percent_late: 30, }.build_storage().unwrap()); - t + t.into() } #[test] diff --git a/substrate/substrate/runtime/staking/src/genesis_config.rs b/substrate/substrate/runtime/staking/src/genesis_config.rs index 2987725b7a..af221cc386 100644 --- a/substrate/substrate/runtime/staking/src/genesis_config.rs +++ b/substrate/substrate/runtime/staking/src/genesis_config.rs @@ -18,10 +18,12 @@ #![cfg(feature = "std")] +use std::collections::HashMap; use rstd::prelude::*; use codec::Encode; use runtime_support::{StorageValue, StorageMap}; use primitives::traits::{Zero, As}; +use substrate_primitives::KeccakHasher; use {runtime_io, primitives}; use super::{Trait, ENUM_SET_SIZE, EnumSet, NextEnumSet, Intentions, CurrentEra, BondingDuration, CreationFee, TransferFee, ReclaimRebate, @@ -118,10 +120,10 @@ impl Default for GenesisConfig { } impl primitives::BuildStorage for GenesisConfig { - fn build_storage(self) -> Result { + fn build_storage(self) -> ::std::result::Result, Vec>, String> { let total_stake: T::Balance = self.balances.iter().fold(Zero::zero(), |acc, &(_, n)| acc + n); - let mut r: runtime_io::TestExternalities = map![ + let mut r: runtime_io::TestExternalities = map![ Self::hash(>::key()).to_vec() => T::AccountIndex::sa(self.balances.len() / ENUM_SET_SIZE).encode(), Self::hash(>::key()).to_vec() => self.intentions.encode(), Self::hash(>::key()).to_vec() => self.sessions_per_era.encode(), @@ -147,6 +149,6 @@ impl primitives::BuildStorage for GenesisConfig { for (who, value) in self.balances.into_iter() { r.insert(Self::hash(&>::key_for(who)).to_vec(), value.encode()); } - Ok(r) + Ok(r.into()) } } diff --git a/substrate/substrate/runtime/staking/src/lib.rs b/substrate/substrate/runtime/staking/src/lib.rs index 825a09f171..bb89c2be8b 100644 --- a/substrate/substrate/runtime/staking/src/lib.rs +++ b/substrate/substrate/runtime/staking/src/lib.rs @@ -302,7 +302,8 @@ impl Module { }; if transactor != &dest { - Self::set_free_balance(transactor, new_from_balance); + Self::set_free_balance(transactor, new_from_balance); + Self::decrease_total_stake_by(fee); Self::set_free_balance_creating(&dest, new_to_balance); } @@ -424,6 +425,7 @@ impl Module { /// In that case it will return `AccountKilled`. pub fn set_reserved_balance(who: &T::AccountId, balance: T::Balance) -> UpdateBalanceOutcome { if balance < Self::existential_deposit() { + >::insert(who, balance); Self::on_reserved_too_low(who); UpdateBalanceOutcome::AccountKilled } else { @@ -443,6 +445,7 @@ impl Module { // Commented out for no - but consider it instructive. // assert!(!Self::voting_balance(who).is_zero()); if balance < Self::existential_deposit() { + >::insert(who, balance); Self::on_free_too_low(who); UpdateBalanceOutcome::AccountKilled } else { @@ -472,7 +475,7 @@ impl Module { // value of which makes even the `free_balance` unspendable. // TODO: enforce this for the other balance-altering functions. if balance < ed { - Self::on_free_too_low(who); + Self::set_free_balance(who, balance); UpdateBalanceOutcome::AccountKilled } else { if !>::exists(who) { @@ -481,10 +484,12 @@ impl Module { NewAccountOutcome::GoodHint => balance + >::reclaim_rebate(), _ => balance, }; - >::insert(who, credit); - } else { - >::insert(who, balance); + Self::set_free_balance(who, credit); + Self::increase_total_stake_by(credit - balance); + } else { + Self::set_free_balance(who, balance); } + UpdateBalanceOutcome::Updated } } @@ -493,11 +498,12 @@ impl Module { /// free balance. This function cannot fail. /// /// As much funds up to `value` will be deducted as possible. If this is less than `value`, - /// then `Some(remaining)` will be retutned. Full completion is given by `None`. + /// then `Some(remaining)` will be returned. Full completion is given by `None`. pub fn slash(who: &T::AccountId, value: T::Balance) -> Option { let free_balance = Self::free_balance(who); let free_slash = cmp::min(free_balance, value); Self::set_free_balance(who, free_balance - free_slash); + Self::decrease_total_stake_by(free_slash); if free_slash < value { Self::slash_reserved(who, value - free_slash) } else { @@ -513,6 +519,7 @@ impl Module { return Err("beneficiary account must pre-exist"); } Self::set_free_balance(who, Self::free_balance(who) + value); + Self::increase_total_stake_by(value); Ok(()) } @@ -536,7 +543,7 @@ impl Module { /// Moves up to `value` from reserved balance to balance. This function cannot fail. /// /// As much funds up to `value` will be deducted as possible. If this is less than `value`, - /// then `Some(remaining)` will be retutned. Full completion is given by `None`. + /// then `Some(remaining)` will be returned. Full completion is given by `None`. /// NOTE: This is different to `reserve`. pub fn unreserve(who: &T::AccountId, value: T::Balance) -> Option { let b = Self::reserved_balance(who); @@ -553,11 +560,12 @@ impl Module { /// Deducts up to `value` from reserved balance of `who`. This function cannot fail. /// /// As much funds up to `value` will be deducted as possible. If this is less than `value`, - /// then `Some(remaining)` will be retutned. Full completion is given by `None`. + /// then `Some(remaining)` will be returned. Full completion is given by `None`. pub fn slash_reserved(who: &T::AccountId, value: T::Balance) -> Option { let b = Self::reserved_balance(who); let slash = cmp::min(b, value); Self::set_reserved_balance(who, b - slash); + Self::decrease_total_stake_by(slash); if value == slash { None } else { @@ -570,7 +578,7 @@ impl Module { /// returned. /// /// As much funds up to `value` will be moved as possible. If this is less than `value`, then - /// `Ok(Some(remaining))` will be retutned. Full completion is given by `Ok(None)`. + /// `Ok(Some(remaining))` will be returned. Full completion is given by `Ok(None)`. pub fn transfer_reserved( slashed: &T::AccountId, beneficiary: &T::AccountId, @@ -785,6 +793,7 @@ impl Module { /// Kill an account's free portion. fn on_free_too_low(who: &T::AccountId) { + Self::decrease_total_stake_by(Self::free_balance(who)); >::remove(who); >::remove(who); T::OnAccountKill::on_account_kill(who); @@ -796,11 +805,25 @@ impl Module { /// Kill an account's reserved portion. fn on_reserved_too_low(who: &T::AccountId) { + Self::decrease_total_stake_by(Self::reserved_balance(who)); >::remove(who); if Self::free_balance(who).is_zero() { >::remove(who); } } + + /// Increase TotalStake by Value. + pub fn increase_total_stake_by(value: T::Balance) { + if >::exists() { + >::put(>::total_stake() + value); + } + } + /// Decrease TotalStake by Value. + pub fn decrease_total_stake_by(value: T::Balance) { + if >::exists() { + >::put(>::total_stake() - value); + } + } } impl Executable for Module { @@ -832,7 +855,8 @@ impl MakePayment for Module { if b < transaction_fee + Self::existential_deposit() { return Err("not enough funds for transaction fee"); } - >::insert(transactor, b - transaction_fee); + Self::set_free_balance(transactor, b - transaction_fee); + Self::decrease_total_stake_by(transaction_fee); Ok(()) } } diff --git a/substrate/substrate/runtime/staking/src/mock.rs b/substrate/substrate/runtime/staking/src/mock.rs index dcc96b0373..2f3024d78d 100644 --- a/substrate/substrate/runtime/staking/src/mock.rs +++ b/substrate/substrate/runtime/staking/src/mock.rs @@ -21,7 +21,7 @@ use primitives::BuildStorage; use primitives::traits::{HasPublicAux, Identity}; use primitives::testing::{Digest, Header}; -use substrate_primitives::H256; +use substrate_primitives::{H256, KeccakHasher}; use runtime_io; use {GenesisConfig, Module, Trait, consensus, session, system, timestamp}; @@ -59,7 +59,7 @@ impl Trait for Test { type OnAccountKill = (); } -pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64, current_era: u64, monied: bool, reward: u64) -> runtime_io::TestExternalities { +pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64, current_era: u64, monied: bool, reward: u64) -> runtime_io::TestExternalities { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); let balance_factor = if ext_deposit > 0 { 256 @@ -102,7 +102,7 @@ pub fn new_test_ext(ext_deposit: u64, session_length: u64, sessions_per_era: u64 t.extend(timestamp::GenesisConfig::{ period: 5 }.build_storage().unwrap()); - t + t.into() } pub type System = system::Module; diff --git a/substrate/substrate/runtime/staking/src/tests.rs b/substrate/substrate/runtime/staking/src/tests.rs index 36549d534f..b8e11cd98f 100644 --- a/substrate/substrate/runtime/staking/src/tests.rs +++ b/substrate/substrate/runtime/staking/src/tests.rs @@ -28,6 +28,7 @@ fn reward_should_work() { assert_eq!(Staking::voting_balance(&10), 1); assert_ok!(Staking::reward(&10, 10)); assert_eq!(Staking::voting_balance(&10), 11); + assert_eq!(>::get(), 112); }); } @@ -408,7 +409,7 @@ fn staking_eras_work() { #[test] fn staking_balance_works() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 42); + Staking::set_free_balance(&1, 42); assert_eq!(Staking::free_balance(&1), 42); assert_eq!(Staking::reserved_balance(&1), 0); assert_eq!(Staking::voting_balance(&1), 42); @@ -421,7 +422,8 @@ fn staking_balance_works() { #[test] fn staking_balance_transfer_works() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); + Staking::increase_total_stake_by(111); assert_ok!(Staking::transfer(&1, 2.into(), 69)); assert_eq!(Staking::voting_balance(&1), 42); assert_eq!(Staking::voting_balance(&2), 69); @@ -431,7 +433,7 @@ fn staking_balance_transfer_works() { #[test] fn staking_balance_transfer_when_bonded_should_not_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); assert_ok!(Staking::stake(&1)); assert_noop!(Staking::transfer(&1, 2.into(), 69), "bondage too high to send value"); }); @@ -440,7 +442,7 @@ fn staking_balance_transfer_when_bonded_should_not_work() { #[test] fn reserving_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); assert_eq!(Staking::voting_balance(&1), 111); assert_eq!(Staking::free_balance(&1), 111); @@ -457,7 +459,7 @@ fn reserving_balance_should_work() { #[test] fn staking_balance_transfer_when_reserved_should_not_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); assert_ok!(Staking::reserve(&1, 69)); assert_noop!(Staking::transfer(&1, 2.into(), 69), "balance too low to send value"); }); @@ -466,7 +468,7 @@ fn staking_balance_transfer_when_reserved_should_not_work() { #[test] fn deducting_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); assert_ok!(Staking::reserve(&1, 69)); assert_eq!(Staking::free_balance(&1), 42); }); @@ -475,7 +477,7 @@ fn deducting_balance_should_work() { #[test] fn deducting_balance_when_bonded_should_not_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); >::insert(1, 2); System::set_block_number(1); assert_eq!(Staking::unlock_block(&1), LockStatus::LockedUntil(2)); @@ -486,8 +488,8 @@ fn deducting_balance_when_bonded_should_not_work() { #[test] fn refunding_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 42); - >::insert(1, 69); + Staking::set_free_balance(&1, 42); + Staking::set_reserved_balance(&1, 69); Staking::unreserve(&1, 69); assert_eq!(Staking::free_balance(&1), 111); assert_eq!(Staking::reserved_balance(&1), 0); @@ -497,29 +499,33 @@ fn refunding_balance_should_work() { #[test] fn slashing_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); + Staking::increase_total_stake_by(111); assert_ok!(Staking::reserve(&1, 69)); assert!(Staking::slash(&1, 69).is_none()); assert_eq!(Staking::free_balance(&1), 0); assert_eq!(Staking::reserved_balance(&1), 42); + assert_eq!(>::get(), 44); }); } #[test] fn slashing_incomplete_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 42); + Staking::set_free_balance(&1, 42); + Staking::increase_total_stake_by(42); assert_ok!(Staking::reserve(&1, 21)); assert!(Staking::slash(&1, 69).is_some()); assert_eq!(Staking::free_balance(&1), 0); assert_eq!(Staking::reserved_balance(&1), 0); + assert_eq!(>::get(), 2); }); } #[test] fn unreserving_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); assert_ok!(Staking::reserve(&1, 111)); Staking::unreserve(&1, 42); assert_eq!(Staking::reserved_balance(&1), 69); @@ -530,30 +536,34 @@ fn unreserving_balance_should_work() { #[test] fn slashing_reserved_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); + Staking::increase_total_stake_by(111); assert_ok!(Staking::reserve(&1, 111)); assert!(Staking::slash_reserved(&1, 42).is_none()); assert_eq!(Staking::reserved_balance(&1), 69); assert_eq!(Staking::free_balance(&1), 0); + assert_eq!(>::get(), 71); }); } #[test] fn slashing_incomplete_reserved_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); + Staking::increase_total_stake_by(111); assert_ok!(Staking::reserve(&1, 42)); assert!(Staking::slash_reserved(&1, 69).is_some()); assert_eq!(Staking::free_balance(&1), 69); assert_eq!(Staking::reserved_balance(&1), 0); + assert_eq!(>::get(), 71); }); } #[test] fn transferring_reserved_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 110); - >::insert(2, 1); + Staking::set_free_balance(&1, 110); + Staking::set_free_balance(&2, 1); assert_ok!(Staking::reserve(&1, 110)); assert_ok!(Staking::transfer_reserved(&1, &2, 41), None); assert_eq!(Staking::reserved_balance(&1), 69); @@ -566,7 +576,7 @@ fn transferring_reserved_balance_should_work() { #[test] fn transferring_reserved_balance_to_nonexistent_should_fail() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 111); + Staking::set_free_balance(&1, 111); assert_ok!(Staking::reserve(&1, 111)); assert_noop!(Staking::transfer_reserved(&1, &2, 42), "beneficiary account must pre-exist"); }); @@ -575,8 +585,8 @@ fn transferring_reserved_balance_to_nonexistent_should_fail() { #[test] fn transferring_incomplete_reserved_balance_should_work() { with_externalities(&mut new_test_ext(0, 1, 3, 1, false, 0), || { - >::insert(1, 110); - >::insert(2, 1); + Staking::set_free_balance(&1, 110); + Staking::set_free_balance(&2, 1); assert_ok!(Staking::reserve(&1, 41)); assert!(Staking::transfer_reserved(&1, &2, 69).unwrap().is_some()); assert_eq!(Staking::reserved_balance(&1), 0); @@ -599,5 +609,32 @@ fn transferring_too_high_value_should_not_panic() { assert_eq!(Staking::free_balance(&1), u64::max_value()); assert_eq!(Staking::free_balance(&2), 1); + }); +} + +#[test] +fn account_removal_on_free_too_low() { + with_externalities(&mut new_test_ext(100, 1, 3, 1, false, 0), || { + // Setup two accounts with free balance above the exsistential threshold. + { + Staking::set_free_balance(&1, 110); + Staking::increase_total_stake_by(110); + + Staking::set_free_balance(&2, 110); + Staking::increase_total_stake_by(110); + + assert_eq!(>::get(), 732); + } + + // Transfer funds from account 1 of such amount that after this transfer + // the balance of account 1 will be below the exsistential threshold. + // This should lead to the removal of all balance of this account. + assert_ok!(Staking::transfer(&1, 2.into(), 20)); + + // Verify free balance removal of account 1. + assert_eq!(Staking::free_balance(&1), 0); + + // Verify that TotalStake tracks balance removal when free balance is too low. + assert_eq!(>::get(), 642); }); } diff --git a/substrate/substrate/runtime/system/src/lib.rs b/substrate/substrate/runtime/system/src/lib.rs index 002c540590..60dd6059b4 100644 --- a/substrate/substrate/runtime/system/src/lib.rs +++ b/substrate/substrate/runtime/system/src/lib.rs @@ -49,7 +49,7 @@ use rstd::marker::PhantomData; use codec::Encode; #[cfg(any(feature = "std", test))] -use runtime_io::{twox_128, TestExternalities}; +use runtime_io::{twox_128, TestExternalities, KeccakHasher}; /// Compute the extrinsics root of a list of extrinsics. pub fn extrinsics_root(extrinsics: &[E]) -> H::Output { @@ -142,7 +142,7 @@ impl Module { /// Get the basic externalities for this module, useful for tests. #[cfg(any(feature = "std", test))] - pub fn externalities() -> TestExternalities { + pub fn externalities() -> TestExternalities { map![ twox_128(&>::key_for(T::BlockNumber::zero())).to_vec() => [69u8; 32].encode(), // TODO: replace with Hash::default().encode twox_128(>::key()).to_vec() => T::BlockNumber::one().encode(), @@ -207,7 +207,7 @@ impl Default for GenesisConfig { #[cfg(any(feature = "std", test))] impl primitives::BuildStorage for GenesisConfig { - fn build_storage(self) -> Result { + fn build_storage(self) -> Result { use codec::Encode; Ok(map![ diff --git a/substrate/substrate/runtime/timestamp/Cargo.toml b/substrate/substrate/runtime/timestamp/Cargo.toml index 1b5637a2c3..c87da900bf 100644 --- a/substrate/substrate/runtime/timestamp/Cargo.toml +++ b/substrate/substrate/runtime/timestamp/Cargo.toml @@ -26,6 +26,7 @@ std = [ "substrate-runtime-io/std", "substrate-runtime-support/std", "substrate-runtime-primitives/std", + "substrate-runtime-consensus/std", "serde/std", "serde_derive", "substrate-codec/std", diff --git a/substrate/substrate/runtime/timestamp/src/lib.rs b/substrate/substrate/runtime/timestamp/src/lib.rs index 0d20bd6b58..21a1e8ee84 100644 --- a/substrate/substrate/runtime/timestamp/src/lib.rs +++ b/substrate/substrate/runtime/timestamp/src/lib.rs @@ -173,7 +173,7 @@ mod tests { fn timestamp_works() { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(GenesisConfig:: { period: 0 }.build_storage().unwrap()); - + let mut t = runtime_io::TestExternalities::from(t); with_externalities(&mut t, || { Timestamp::set_timestamp(42); assert_ok!(Timestamp::aux_dispatch(Call::set(69), &0)); @@ -186,7 +186,7 @@ mod tests { fn double_timestamp_should_fail() { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(GenesisConfig:: { period: 5 }.build_storage().unwrap()); - + let mut t = runtime_io::TestExternalities::from(t); with_externalities(&mut t, || { Timestamp::set_timestamp(42); assert_ok!(Timestamp::aux_dispatch(Call::set(69), &0)); @@ -199,7 +199,7 @@ mod tests { fn block_period_is_enforced() { let mut t = system::GenesisConfig::::default().build_storage().unwrap(); t.extend(GenesisConfig:: { period: 5 }.build_storage().unwrap()); - + let mut t = runtime_io::TestExternalities::from(t); with_externalities(&mut t, || { Timestamp::set_timestamp(42); let _ = Timestamp::aux_dispatch(Call::set(46), &0); diff --git a/substrate/substrate/service/src/components.rs b/substrate/substrate/service/src/components.rs index a6c83db888..d653168fbb 100644 --- a/substrate/substrate/service/src/components.rs +++ b/substrate/substrate/service/src/components.rs @@ -28,6 +28,7 @@ use substrate_executor::{NativeExecutor, NativeExecutionDispatch}; use extrinsic_pool::{txpool::Options as ExtrinsicPoolOptions, api::ExtrinsicPool as ExtrinsicPoolApi}; use runtime_primitives::{traits::Block as BlockT, traits::Header as HeaderT, generic::BlockId, BuildStorage}; use config::Configuration; +use primitives::{KeccakHasher, RlpCodec, H256}; // Type aliases. // These exist mainly to avoid typing `::Foo` all over the code. @@ -152,9 +153,9 @@ pub trait Components { /// Associated service factory. type Factory: ServiceFactory; /// Client backend. - type Backend: 'static + client::backend::Backend>; + type Backend: 'static + client::backend::Backend, KeccakHasher, RlpCodec>; /// Client executor. - type Executor: 'static + client::CallExecutor> + Send + Sync; + type Executor: 'static + client::CallExecutor, KeccakHasher, RlpCodec> + Send + Sync; /// Extrinsic pool type. type ExtrinsicPool: ExtrinsicPool>; @@ -215,7 +216,7 @@ pub struct LightComponents { impl Components for LightComponents where - <::Block as BlockT>::Hash: Into<[u8; 32]>, + <::Block as BlockT>::Hash: Into, { type Factory = Factory; type Executor = LightExecutor; @@ -239,7 +240,7 @@ impl Components for LightComponents }; let db_storage = client_db::light::LightStorage::new(db_settings)?; let light_blockchain = client::light::new_light_blockchain(db_storage); - let fetch_checker = Arc::new(client::light::new_fetch_checker(executor)); + let fetch_checker = Arc::new(client::light::new_fetch_checker::<_, KeccakHasher, RlpCodec>(executor)); let fetcher = Arc::new(network::OnDemand::new(fetch_checker)); let client_backend = client::light::new_light_backend(light_blockchain, fetcher.clone()); let client = client::light::new_light(client_backend, fetcher.clone(), &config.chain_spec)?; diff --git a/substrate/substrate/service/src/lib.rs b/substrate/substrate/service/src/lib.rs index 9fcd157f73..a265ec41e1 100644 --- a/substrate/substrate/service/src/lib.rs +++ b/substrate/substrate/service/src/lib.rs @@ -210,7 +210,8 @@ impl Service let chain = rpc::apis::chain::Chain::new(client.clone(), task_executor.clone()); let state = rpc::apis::state::State::new(client.clone(), task_executor.clone()); let author = rpc::apis::author::Author::new(client.clone(), extrinsic_pool.api(), task_executor.clone()); - rpc::rpc_handler::, _, _, _, _>( + + rpc::rpc_handler::, _, _, _, _, _>( state, chain, author, diff --git a/substrate/substrate/state-machine/Cargo.toml b/substrate/substrate/state-machine/Cargo.toml index 17b072c4c6..6e199f429b 100644 --- a/substrate/substrate/state-machine/Cargo.toml +++ b/substrate/substrate/state-machine/Cargo.toml @@ -6,14 +6,15 @@ description = "Substrate State Machine" [dependencies] byteorder = "1.1" -ethereum-types = "0.3" hex-literal = "0.1.0" log = "0.3" parking_lot = "0.4" -triehash = "0.1" +heapsize = "0.4" substrate-primitives = { path = "../primitives", version = "0.1.0" } -hashdb = { git = "https://github.com/paritytech/parity.git" } -memorydb = { git = "https://github.com/paritytech/parity.git" } -patricia-trie = { git = "https://github.com/paritytech/parity.git" } +hashdb = { git = "https://github.com/paritytech/parity-common" } +memorydb = { git = "https://github.com/paritytech/parity-common" } +patricia-trie = { git = "https://github.com/paritytech/parity-common" } +triehash = { git = "https://github.com/paritytech/parity-common" } +rlp = { git = "https://github.com/paritytech/parity-common" } diff --git a/substrate/substrate/state-machine/src/backend.rs b/substrate/substrate/state-machine/src/backend.rs index 1d3b2108f9..7db1e64d3f 100644 --- a/substrate/substrate/state-machine/src/backend.rs +++ b/substrate/substrate/state-machine/src/backend.rs @@ -17,15 +17,22 @@ //! State machine backends. These manage the code and storage of contracts. use std::{error, fmt}; +use std::cmp::Ord; use std::collections::HashMap; +use std::marker::PhantomData; use std::sync::Arc; + +use hashdb::Hasher; +use rlp::Encodable; use trie_backend::{TryIntoTrieBackend, TrieBackend}; +use patricia_trie::{TrieDBMut, TrieMut, NodeCodec}; +use heapsize::HeapSizeOf; /// A state backend is used to read state data and can have changes committed /// to it. /// /// The clone operation (if implemented) should be cheap. -pub trait Backend: TryIntoTrieBackend { +pub trait Backend>: TryIntoTrieBackend { /// An error type when fetching data is not possible. type Error: super::Error; @@ -46,8 +53,10 @@ pub trait Backend: TryIntoTrieBackend { /// Calculate the storage root, with given delta over what is already stored in /// the backend, and produce a "transaction" that can be used to commit. - fn storage_root(&self, delta: I) -> ([u8; 32], Self::Transaction) - where I: IntoIterator, Option>)>; + fn storage_root(&self, delta: I) -> (H::Out, Self::Transaction) + where + I: IntoIterator, Option>)>, + H::Out: Ord + Encodable; /// Get all key/value pairs into a Vec. fn pairs(&self) -> Vec<(Vec, Vec)>; @@ -70,22 +79,40 @@ impl error::Error for Void { /// In-memory backend. Fully recomputes tries on each commit but useful for /// tests. -#[derive(Clone, PartialEq, Eq)] -pub struct InMemory { +#[derive(Eq)] +pub struct InMemory { inner: Arc, Vec>>, + _hasher: PhantomData, + _codec: PhantomData, } -impl Default for InMemory { +impl Default for InMemory { fn default() -> Self { InMemory { inner: Arc::new(Default::default()), + _hasher: PhantomData, + _codec: PhantomData, } } } -impl InMemory { +impl Clone for InMemory { + fn clone(&self) -> Self { + InMemory { + inner: self.inner.clone(), _hasher: PhantomData, _codec: PhantomData, + } + } +} + +impl PartialEq for InMemory { + fn eq(&self, other: &Self) -> bool { + self.inner.eq(&other.inner) + } +} + +impl> InMemory where H::Out: HeapSizeOf { /// Copy the state, with applied updates - pub fn update(&self, changes: ::Transaction) -> Self { + pub fn update(&self, changes: >::Transaction) -> Self { let mut inner: HashMap<_, _> = (&*self.inner).clone(); for (key, val) in changes { match val { @@ -98,17 +125,17 @@ impl InMemory { } } -impl From, Vec>> for InMemory { +impl From, Vec>> for InMemory { fn from(inner: HashMap, Vec>) -> Self { InMemory { - inner: Arc::new(inner), + inner: Arc::new(inner), _hasher: PhantomData, _codec: PhantomData } } } impl super::Error for Void {} -impl Backend for InMemory { +impl> Backend for InMemory where H::Out: HeapSizeOf { type Error = Void; type Transaction = Vec<(Vec, Option>)>; @@ -124,17 +151,19 @@ impl Backend for InMemory { self.inner.keys().filter(|key| key.starts_with(prefix)).map(|k| &**k).for_each(f); } - fn storage_root(&self, delta: I) -> ([u8; 32], Self::Transaction) - where I: IntoIterator, Option>)> + fn storage_root(&self, delta: I) -> (H::Out, Self::Transaction) + where + I: IntoIterator, Option>)>, + ::Out: Ord + Encodable, { let existing_pairs = self.inner.iter().map(|(k, v)| (k.clone(), Some(v.clone()))); let transaction: Vec<_> = delta.into_iter().collect(); - let root = ::triehash::trie_root(existing_pairs.chain(transaction.iter().cloned()) + let root = ::triehash::trie_root::(existing_pairs.chain(transaction.iter().cloned()) .collect::>() .into_iter() .filter_map(|(k, maybe_val)| maybe_val.map(|val| (k, val))) - ).0; + ); (root, transaction) } @@ -144,16 +173,13 @@ impl Backend for InMemory { } } -impl TryIntoTrieBackend for InMemory { - fn try_into_trie_backend(self) -> Option { - use ethereum_types::H256 as TrieH256; +impl> TryIntoTrieBackend for InMemory where H::Out: HeapSizeOf { + fn try_into_trie_backend(self) -> Option> { use memorydb::MemoryDB; - use patricia_trie::{TrieDBMut, TrieMut}; - - let mut root = TrieH256::default(); - let mut mdb = MemoryDB::default(); + let mut root = ::Out::default(); + let mut mdb = MemoryDB::new(); { - let mut trie = TrieDBMut::new(&mut mdb, &mut root); + let mut trie = TrieDBMut::::new(&mut mdb, &mut root); for (key, value) in self.inner.iter() { if let Err(e) = trie.insert(&key, &value) { warn!(target: "trie", "Failed to write to trie: {}", e); diff --git a/substrate/substrate/state-machine/src/ext.rs b/substrate/substrate/state-machine/src/ext.rs index 5a8ba096f5..43129e9894 100644 --- a/substrate/substrate/state-machine/src/ext.rs +++ b/substrate/substrate/state-machine/src/ext.rs @@ -16,9 +16,12 @@ //! Conrete externalities implementation. -use std::{error, fmt}; +use std::{error, fmt, cmp::Ord}; use backend::Backend; use {Externalities, OverlayedChanges}; +use hashdb::Hasher; +use rlp::Encodable; +use patricia_trie::NodeCodec; /// Errors that can occur when interacting with the externalities. #[derive(Debug, Copy, Clone)] @@ -50,16 +53,27 @@ impl error::Error for Error { } /// Wraps a read-only backend, call executor, and current overlayed changes. -pub struct Ext<'a, B: 'a + Backend> { +pub struct Ext<'a, H, C, B> +where + H: Hasher, + C: NodeCodec, + B: 'a + Backend, +{ // The overlayed changes to write to. overlay: &'a mut OverlayedChanges, // The storage backend to read from. backend: &'a B, // The transaction necessary to commit to the backend. - transaction: Option<(B::Transaction, [u8; 32])>, + transaction: Option<(B::Transaction, H::Out)>, } -impl<'a, B: 'a + Backend> Ext<'a, B> { +impl<'a, H, C, B> Ext<'a, H, C, B> +where + H: Hasher, + C: NodeCodec, + B: 'a + Backend, + H::Out: Ord + Encodable +{ /// Create a new `Ext` from overlayed changes and read-only backend pub fn new(overlay: &'a mut OverlayedChanges, backend: &'a B) -> Self { Ext { @@ -84,7 +98,12 @@ impl<'a, B: 'a + Backend> Ext<'a, B> { } #[cfg(test)] -impl<'a, B: 'a + Backend> Ext<'a, B> { +impl<'a, H, C, B> Ext<'a, H, C, B> +where + H: Hasher, + C: NodeCodec, + B: 'a + Backend, +{ pub fn storage_pairs(&self) -> Vec<(Vec, Vec)> { use std::collections::HashMap; @@ -99,8 +118,12 @@ impl<'a, B: 'a + Backend> Ext<'a, B> { } } -impl<'a, B: 'a> Externalities for Ext<'a, B> - where B: Backend +impl<'a, B: 'a, H, C> Externalities for Ext<'a, H, C, B> +where + H: Hasher, + C: NodeCodec, + B: 'a + Backend, + H::Out: Ord + Encodable { fn storage(&self, key: &[u8]) -> Option> { self.overlay.storage(key).map(|x| x.map(|x| x.to_vec())).unwrap_or_else(|| @@ -131,7 +154,7 @@ impl<'a, B: 'a> Externalities for Ext<'a, B> 42 } - fn storage_root(&mut self) -> [u8; 32] { + fn storage_root(&mut self) -> H::Out { if let Some((_, ref root)) = self.transaction { return root.clone(); } diff --git a/substrate/substrate/state-machine/src/lib.rs b/substrate/substrate/state-machine/src/lib.rs index 9b0afc37bb..17ccc41228 100644 --- a/substrate/substrate/state-machine/src/lib.rs +++ b/substrate/substrate/state-machine/src/lib.rs @@ -24,17 +24,23 @@ extern crate hex_literal; #[macro_use] extern crate log; -extern crate ethereum_types; extern crate hashdb; extern crate memorydb; extern crate triehash; extern crate patricia_trie; - extern crate byteorder; extern crate parking_lot; +extern crate rlp; +extern crate heapsize; +#[cfg(test)] +extern crate substrate_primitives as primitives; use std::collections::HashMap; use std::fmt; +use hashdb::Hasher; +use patricia_trie::NodeCodec; +use rlp::Encodable; +use heapsize::HeapSizeOf; pub mod backend; mod ext; @@ -45,7 +51,7 @@ mod trie_backend; pub use testing::TestExternalities; pub use ext::Ext; pub use backend::Backend; -pub use trie_backend::{TryIntoTrieBackend, TrieBackend, TrieH256, Storage, DBValue}; +pub use trie_backend::{TryIntoTrieBackend, TrieBackend, Storage, DBValue}; /// The overlayed changes to state to be queried on top of the backend. /// @@ -158,7 +164,7 @@ impl fmt::Display for ExecutionError { } /// Externalities: pinned to specific active address. -pub trait Externalities { +pub trait Externalities { /// Read storage of current contract being called. fn storage(&self, key: &[u8]) -> Option>; @@ -187,17 +193,17 @@ pub trait Externalities { fn chain_id(&self) -> u64; /// Get the trie root of the current storage map. - fn storage_root(&mut self) -> [u8; 32]; + fn storage_root(&mut self) -> H::Out where H::Out: Ord + Encodable; } /// Code execution engine. -pub trait CodeExecutor: Sized + Send + Sync { +pub trait CodeExecutor: Sized + Send + Sync { /// Externalities error type. type Error: Error; /// Call a given method in the runtime. Returns a tuple of the result (either the output data /// or an execution error) together with a `bool`, which is true if native execution was used. - fn call( + fn call>( &self, ext: &mut E, code: &[u8], @@ -256,14 +262,21 @@ pub fn always_wasm() -> ExecutionManager, E>, Result( +pub fn execute( backend: &B, overlay: &mut OverlayedChanges, exec: &Exec, method: &str, call_data: &[u8], strategy: ExecutionStrategy, -) -> Result<(Vec, B::Transaction), Box> { +) -> Result<(Vec, B::Transaction), Box> +where + H: Hasher, + C: NodeCodec, + Exec: CodeExecutor, + B: Backend, + H::Out: Ord + Encodable +{ execute_using_consensus_failure_handler( backend, overlay, @@ -289,18 +302,22 @@ pub fn execute( /// /// Note: changes to code will be in place if this call is made again. For running partial /// blocks (e.g. a transaction at a time), ensure a different method is used. -pub fn execute_using_consensus_failure_handler< - B: backend::Backend, - Exec: CodeExecutor, - Handler: FnOnce(Result, Exec::Error>, Result, Exec::Error>) -> Result, Exec::Error> ->( +pub fn execute_using_consensus_failure_handler( backend: &B, overlay: &mut OverlayedChanges, exec: &Exec, method: &str, call_data: &[u8], manager: ExecutionManager, -) -> Result<(Vec, B::Transaction), Box> { +) -> Result<(Vec, B::Transaction), Box> +where + H: Hasher, + C: NodeCodec, + Exec: CodeExecutor, + B: Backend, + H::Out: Ord + Encodable, + Handler: FnOnce(Result, Exec::Error>, Result, Exec::Error>) -> Result, Exec::Error> +{ let strategy: ExecutionStrategy = (&manager).into(); // make a copy. @@ -378,55 +395,77 @@ pub fn execute_using_consensus_failure_handler< /// /// Note: changes to code will be in place if this call is made again. For running partial /// blocks (e.g. a transaction at a time), ensure a different method is used. -pub fn prove_execution( +pub fn prove_execution( backend: B, overlay: &mut OverlayedChanges, exec: &Exec, method: &str, call_data: &[u8], -) -> Result<(Vec, Vec>, ::Transaction), Box> { +) -> Result<(Vec, Vec>, as Backend>::Transaction), Box> +where + H: Hasher, + Exec: CodeExecutor, + C: NodeCodec, + B: TryIntoTrieBackend, + H::Out: Ord + Encodable + HeapSizeOf, +{ let trie_backend = backend.try_into_trie_backend() .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; let proving_backend = proving_backend::ProvingBackend::new(trie_backend); - let (result, transaction) = execute(&proving_backend, overlay, exec, method, call_data, ExecutionStrategy::NativeWhenPossible)?; + let (result, transaction) = execute::(&proving_backend, overlay, exec, method, call_data, ExecutionStrategy::NativeWhenPossible)?; let proof = proving_backend.extract_proof(); Ok((result, proof, transaction)) } /// Check execution proof, generated by `prove_execution` call. -pub fn execution_proof_check( - root: [u8; 32], +pub fn execution_proof_check( + root: H::Out, proof: Vec>, overlay: &mut OverlayedChanges, exec: &Exec, method: &str, call_data: &[u8], -) -> Result<(Vec, memorydb::MemoryDB), Box> { - let backend = proving_backend::create_proof_check_backend(root.into(), proof)?; - execute(&backend, overlay, exec, method, call_data, ExecutionStrategy::NativeWhenPossible) +) -> Result<(Vec, memorydb::MemoryDB), Box> +where +H: Hasher, +C: NodeCodec, +Exec: CodeExecutor, +H::Out: Ord + Encodable + HeapSizeOf, +{ + let backend = proving_backend::create_proof_check_backend::(root.into(), proof)?; + execute::(&backend, overlay, exec, method, call_data, ExecutionStrategy::NativeWhenPossible) } /// Generate storage read proof. -pub fn prove_read( +pub fn prove_read( backend: B, - key: &[u8], + key: &[u8] ) -> Result<(Option>, Vec>), Box> +where + B: TryIntoTrieBackend, + H: Hasher, + C: NodeCodec, + H::Out: Ord + Encodable + HeapSizeOf { let trie_backend = backend.try_into_trie_backend() .ok_or_else(|| Box::new(ExecutionError::UnableToGenerateProof) as Box)?; - let proving_backend = proving_backend::ProvingBackend::new(trie_backend); + let proving_backend = proving_backend::ProvingBackend::::new(trie_backend); let result = proving_backend.storage(key).map_err(|e| Box::new(e) as Box)?; Ok((result, proving_backend.extract_proof())) } /// Check storage read proof, generated by `prove_read` call. -pub fn read_proof_check( - root: [u8; 32], +pub fn read_proof_check( + root: H::Out, proof: Vec>, key: &[u8], ) -> Result>, Box> +where + H: Hasher, + C: NodeCodec, + H::Out: Ord + Encodable + HeapSizeOf { - let backend = proving_backend::create_proof_check_backend(root.into(), proof)?; + let backend = proving_backend::create_proof_check_backend::(root, proof)?; backend.storage(key).map_err(|e| Box::new(e) as Box) } @@ -435,6 +474,7 @@ mod tests { use super::*; use super::backend::InMemory; use super::ext::Ext; + use primitives::{KeccakHasher, RlpCodec, H256}; struct DummyCodeExecutor { native_available: bool, @@ -442,10 +482,10 @@ mod tests { fallback_succeeds: bool, } - impl CodeExecutor for DummyCodeExecutor { + impl CodeExecutor for DummyCodeExecutor { type Error = u8; - fn call( + fn call>( &self, ext: &mut E, _code: &[u8], @@ -506,7 +546,7 @@ mod tests { b"dogglesworth".to_vec() => b"catXXX".to_vec(), b"doug".to_vec() => b"notadog".to_vec() ]; - let backend = InMemory::from(initial); + let backend = InMemory::::from(initial); let mut overlay = OverlayedChanges { committed: map![ b"dog".to_vec() => Some(b"puppy".to_vec()), @@ -519,8 +559,11 @@ mod tests { ], }; let mut ext = Ext::new(&mut overlay, &backend); + // Blake + // const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b"); + // Keccak const ROOT: [u8; 32] = hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"); - assert_eq!(ext.storage_root(), ROOT); + assert_eq!(ext.storage_root(), H256(ROOT)); } #[test] @@ -576,7 +619,7 @@ mod tests { &mut Default::default(), &executor, "test", &[]).unwrap(); // check proof locally - let (local_result, _) = execution_proof_check(remote_root, remote_proof, + let (local_result, _) = execution_proof_check::(remote_root, remote_proof, &mut Default::default(), &executor, "test", &[]).unwrap(); // check that both results are correct @@ -592,7 +635,7 @@ mod tests { b"abc".to_vec() => b"2".to_vec(), b"bbb".to_vec() => b"3".to_vec() ]; - let backend = InMemory::from(initial).try_into_trie_backend().unwrap(); + let backend = InMemory::::from(initial).try_into_trie_backend().unwrap(); let mut overlay = OverlayedChanges { committed: map![ b"aba".to_vec() => Some(b"1312".to_vec()), @@ -631,8 +674,8 @@ mod tests { let remote_root = remote_backend.storage_root(::std::iter::empty()).0; let remote_proof = prove_read(remote_backend, b"value2").unwrap().1; // check proof locally - let local_result1 = read_proof_check(remote_root, remote_proof.clone(), b"value2").unwrap(); - let local_result2 = read_proof_check(remote_root, remote_proof.clone(), &[0xff]).is_ok(); + let local_result1 = read_proof_check::(remote_root, remote_proof.clone(), b"value2").unwrap(); + let local_result2 = read_proof_check::(remote_root, remote_proof.clone(), &[0xff]).is_ok(); // check that results are correct assert_eq!(local_result1, Some(vec![24])); assert_eq!(local_result2, false); diff --git a/substrate/substrate/state-machine/src/proving_backend.rs b/substrate/substrate/state-machine/src/proving_backend.rs index 70961adc96..db8d142452 100644 --- a/substrate/substrate/state-machine/src/proving_backend.rs +++ b/substrate/substrate/state-machine/src/proving_backend.rs @@ -17,23 +17,24 @@ //! Proving state machine backend. use std::cell::RefCell; -use ethereum_types::H256 as TrieH256; -use hashdb::HashDB; +use hashdb::{Hasher, HashDB}; use memorydb::MemoryDB; -use patricia_trie::{TrieDB, TrieError, Trie, Recorder}; +use patricia_trie::{TrieDB, Trie, Recorder, NodeCodec}; use trie_backend::{TrieBackend, Ephemeral}; use {Error, ExecutionError, Backend, TryIntoTrieBackend}; +use rlp::Encodable; +use heapsize::HeapSizeOf; /// Patricia trie-based backend which also tracks all touched storage trie values. /// These can be sent to remote node and used as a proof of execution. -pub struct ProvingBackend { - backend: TrieBackend, - proof_recorder: RefCell, +pub struct ProvingBackend> { + backend: TrieBackend, + proof_recorder: RefCell>, } -impl ProvingBackend { +impl> ProvingBackend { /// Create new proving backend. - pub fn new(backend: TrieBackend) -> Self { + pub fn new(backend: TrieBackend) -> Self { ProvingBackend { backend, proof_recorder: RefCell::new(Recorder::new()), @@ -50,22 +51,26 @@ impl ProvingBackend { } } -impl Backend for ProvingBackend { +impl Backend for ProvingBackend +where + H: Hasher, + C: NodeCodec, + H::Out: Ord + Encodable + HeapSizeOf +{ type Error = String; - type Transaction = MemoryDB; + type Transaction = MemoryDB; fn storage(&self, key: &[u8]) -> Result>, Self::Error> { - let mut read_overlay = MemoryDB::default(); + let mut read_overlay = MemoryDB::new(); let eph = Ephemeral::new( self.backend.backend_storage(), &mut read_overlay, ); - - let map_e = |e: Box| format!("Trie lookup error: {}", e); + let map_e = |e| format!("Trie lookup error: {}", e); let mut proof_recorder = self.proof_recorder.try_borrow_mut() .expect("only fails when already borrowed; storage() is non-reentrant; qed"); - TrieDB::new(&eph, &self.backend.root()).map_err(map_e)? + TrieDB::::new(&eph, &self.backend.root()).map_err(map_e)? .get_with(key, &mut *proof_recorder).map(|x| x.map(|val| val.to_vec())).map_err(map_e) } @@ -77,21 +82,29 @@ impl Backend for ProvingBackend { self.backend.pairs() } - fn storage_root(&self, delta: I) -> ([u8; 32], MemoryDB) + fn storage_root(&self, delta: I) -> (H::Out, MemoryDB) where I: IntoIterator, Option>)> { self.backend.storage_root(delta) } } -impl TryIntoTrieBackend for ProvingBackend { - fn try_into_trie_backend(self) -> Option { +impl> TryIntoTrieBackend for ProvingBackend { + fn try_into_trie_backend(self) -> Option> { None } } /// Create proof check backend. -pub fn create_proof_check_backend(root: TrieH256, proof: Vec>) -> Result> { +pub fn create_proof_check_backend( + root: H::Out, + proof: Vec> +) -> Result, Box> +where + H: Hasher, + C: NodeCodec, + H::Out: HeapSizeOf, +{ let mut db = MemoryDB::new(); for item in proof { db.insert(&item); @@ -110,8 +123,9 @@ mod tests { use backend::{InMemory}; use trie_backend::tests::test_trie; use super::*; + use primitives::{KeccakHasher, RlpCodec}; - fn test_proving() -> ProvingBackend { + fn test_proving() -> ProvingBackend { ProvingBackend::new(test_trie()) } @@ -129,7 +143,7 @@ mod tests { #[test] fn proof_is_invalid_when_does_not_contains_root() { - assert!(create_proof_check_backend(1.into(), vec![]).is_err()); + assert!(create_proof_check_backend::(1.into(), vec![]).is_err()); } #[test] @@ -148,7 +162,7 @@ mod tests { #[test] fn proof_recorded_and_checked() { let contents = (0..64).map(|i| (vec![i], Some(vec![i]))).collect::>(); - let in_memory = InMemory::default(); + let in_memory = InMemory::::default(); let in_memory = in_memory.update(contents); let in_memory_root = in_memory.storage_root(::std::iter::empty()).0; (0..64).for_each(|i| assert_eq!(in_memory.storage(&[i]).unwrap().unwrap(), vec![i])); @@ -163,7 +177,7 @@ mod tests { let proof = proving.extract_proof(); - let proof_check = create_proof_check_backend(in_memory_root.into(), proof).unwrap(); + let proof_check = create_proof_check_backend::(in_memory_root.into(), proof).unwrap(); assert_eq!(proof_check.storage(&[42]).unwrap().unwrap(), vec![42]); } } diff --git a/substrate/substrate/state-machine/src/testing.rs b/substrate/substrate/state-machine/src/testing.rs index 7b85b523cd..955cb77464 100644 --- a/substrate/substrate/state-machine/src/testing.rs +++ b/substrate/substrate/state-machine/src/testing.rs @@ -17,48 +17,105 @@ //! Test implementation for Externalities. use std::collections::HashMap; +use std::cmp::Ord; use super::Externalities; use triehash::trie_root; +use hashdb::Hasher; +use rlp::Encodable; +use std::marker::PhantomData; +use std::iter::FromIterator; -/// Simple HashMap based Externalities impl. -pub type TestExternalities = HashMap, Vec>; +/// Simple HashMap-based Externalities impl. +#[derive(Debug)] +pub struct TestExternalities { + inner: HashMap, Vec>, + _hasher: PhantomData, +} -impl Externalities for TestExternalities { +impl TestExternalities { + /// Create a new instance of `TestExternalities` + pub fn new() -> Self { + TestExternalities {inner: HashMap::new(), _hasher: PhantomData} + } + /// Insert key/value + pub fn insert(&mut self, k: Vec, v: Vec) -> Option> { + self.inner.insert(k, v) + } +} + +impl PartialEq for TestExternalities { + fn eq(&self, other: &TestExternalities) -> bool { + self.inner.eq(&other.inner) + } +} + +impl FromIterator<(Vec, Vec)> for TestExternalities { + fn from_iter, Vec)>>(iter: I) -> Self { + let mut t = Self::new(); + for i in iter { + t.inner.insert(i.0, i.1); + } + t + } +} + +impl Default for TestExternalities { + fn default() -> Self { Self::new() } +} + +impl From> for HashMap, Vec> { + fn from(tex: TestExternalities) -> Self { + tex.inner.into() + } +} + +impl From< HashMap, Vec> > for TestExternalities { + fn from(hashmap: HashMap, Vec>) -> Self { + TestExternalities { inner: hashmap, _hasher: PhantomData } + } +} + + +impl Externalities for TestExternalities where H::Out: Ord + Encodable { fn storage(&self, key: &[u8]) -> Option> { - self.get(key).map(|x| x.to_vec()) + self.inner.get(key).map(|x| x.to_vec()) } fn place_storage(&mut self, key: Vec, maybe_value: Option>) { match maybe_value { - Some(value) => { self.insert(key, value); } - None => { self.remove(&key); } + Some(value) => { self.inner.insert(key, value); } + None => { self.inner.remove(&key); } } } fn clear_prefix(&mut self, prefix: &[u8]) { - self.retain(|key, _| + self.inner.retain(|key, _| !key.starts_with(prefix) ) } fn chain_id(&self) -> u64 { 42 } - fn storage_root(&mut self) -> [u8; 32] { - trie_root(self.clone()).0 + fn storage_root(&mut self) -> H::Out { + trie_root::(self.inner.clone()) } } #[cfg(test)] mod tests { use super::*; + use primitives::{KeccakHasher, H256}; #[test] fn commit_should_work() { - let mut ext = TestExternalities::new(); + let mut ext = TestExternalities::::new(); ext.set_storage(b"doe".to_vec(), b"reindeer".to_vec()); ext.set_storage(b"dog".to_vec(), b"puppy".to_vec()); ext.set_storage(b"dogglesworth".to_vec(), b"cat".to_vec()); + // Blake + // const ROOT: [u8; 32] = hex!("6ca394ff9b13d6690a51dea30b1b5c43108e52944d30b9095227c49bae03ff8b"); + // Keccak const ROOT: [u8; 32] = hex!("8aad789dff2f538bca5d8ea56e8abe10f4c7ba3a5dea95fea4cd6e7c3a1168d3"); - assert_eq!(ext.storage_root(), ROOT); + assert_eq!(ext.storage_root(), H256(ROOT)); } } diff --git a/substrate/substrate/state-machine/src/trie_backend.rs b/substrate/substrate/state-machine/src/trie_backend.rs index 629dd3ddb3..b9d45d45a7 100644 --- a/substrate/substrate/state-machine/src/trie_backend.rs +++ b/substrate/substrate/state-machine/src/trie_backend.rs @@ -15,101 +15,104 @@ // along with Substrate. If not, see . //! Trie-based state machine backend. - +use Backend; +use hashdb::{Hasher, HashDB, AsHashDB}; +use memorydb::MemoryDB; +use patricia_trie::{TrieDB, TrieDBMut, TrieError, Trie, TrieMut, NodeCodec}; use std::collections::HashMap; use std::sync::Arc; -use hashdb::HashDB; -use memorydb::MemoryDB; -use patricia_trie::{TrieDB, TrieDBMut, TrieError, Trie, TrieMut}; -use {Backend}; -pub use ethereum_types::H256 as TrieH256; +use std::marker::PhantomData; +use heapsize::HeapSizeOf; + pub use hashdb::DBValue; /// Backend trie storage trait. -pub trait Storage: Send + Sync { +pub trait Storage: Send + Sync { /// Get a trie node. - fn get(&self, key: &TrieH256) -> Result, String>; + fn get(&self, key: &H::Out) -> Result, String>; } /// Try convert into trie-based backend. -pub trait TryIntoTrieBackend { +pub trait TryIntoTrieBackend> { /// Try to convert self into trie backend. - fn try_into_trie_backend(self) -> Option; + fn try_into_trie_backend(self) -> Option>; } /// Patricia trie-based backend. Transaction type is an overlay of changes to commit. #[derive(Clone)] -pub struct TrieBackend { - storage: TrieBackendStorage, - root: TrieH256, +pub struct TrieBackend> { + storage: TrieBackendStorage, + root: H::Out, + _codec: PhantomData } -impl TrieBackend { +impl> TrieBackend where H::Out: HeapSizeOf { /// Create new trie-based backend. - pub fn with_storage(db: Arc, root: TrieH256) -> Self { + pub fn with_storage(db: Arc>, root: H::Out) -> Self { TrieBackend { storage: TrieBackendStorage::Storage(db), root, + _codec: PhantomData, } } /// Create new trie-based backend for genesis block. - pub fn with_storage_for_genesis(db: Arc) -> Self { - let mut root = TrieH256::default(); - let mut mdb = MemoryDB::default(); - TrieDBMut::new(&mut mdb, &mut root); + pub fn with_storage_for_genesis(db: Arc>) -> Self { + let mut root = ::Out::default(); + let mut mdb = MemoryDB::::new(); + TrieDBMut::::new(&mut mdb, &mut root); Self::with_storage(db, root) } /// Create new trie-based backend backed by MemoryDb storage. - pub fn with_memorydb(db: MemoryDB, root: TrieH256) -> Self { + pub fn with_memorydb(db: MemoryDB, root: H::Out) -> Self { // TODO: check that root is a part of db??? TrieBackend { storage: TrieBackendStorage::MemoryDb(db), root, + _codec: PhantomData, } } /// Get backend storage reference. - pub fn backend_storage(&self) -> &TrieBackendStorage { + pub fn backend_storage(&self) -> &TrieBackendStorage { &self.storage } /// Get trie root. - pub fn root(&self) -> &TrieH256 { + pub fn root(&self) -> &H::Out { &self.root } } impl super::Error for String {} -impl Backend for TrieBackend { +impl> Backend for TrieBackend where H::Out: HeapSizeOf { type Error = String; - type Transaction = MemoryDB; + type Transaction = MemoryDB; fn storage(&self, key: &[u8]) -> Result>, Self::Error> { - let mut read_overlay = MemoryDB::default(); + let mut read_overlay = MemoryDB::new(); let eph = Ephemeral { storage: &self.storage, overlay: &mut read_overlay, }; - let map_e = |e: Box| format!("Trie lookup error: {}", e); - - TrieDB::new(&eph, &self.root).map_err(map_e)? + let map_e = |e| format!("Trie lookup error: {}", e); + TrieDB::::new(&eph, &self.root).map_err(map_e)? .get(key).map(|x| x.map(|val| val.to_vec())).map_err(map_e) } fn for_keys_with_prefix(&self, prefix: &[u8], mut f: F) { - let mut read_overlay = MemoryDB::default(); + let mut read_overlay = MemoryDB::new(); let eph = Ephemeral { storage: &self.storage, overlay: &mut read_overlay, }; - let mut iter = move || -> Result<(), Box> { - let trie = TrieDB::new(&eph, &self.root)?; + let mut iter = move || -> Result<(), Box>> { + let trie = TrieDB::::new(&eph, &self.root)?; let mut iter = trie.iter()?; iter.seek(prefix)?; @@ -133,14 +136,14 @@ impl Backend for TrieBackend { } fn pairs(&self) -> Vec<(Vec, Vec)> { - let mut read_overlay = MemoryDB::default(); + let mut read_overlay = MemoryDB::new(); let eph = Ephemeral { storage: &self.storage, overlay: &mut read_overlay, }; - let collect_all = || -> Result<_, Box> { - let trie = TrieDB::new(&eph, &self.root)?; + let collect_all = || -> Result<_, Box>> { + let trie = TrieDB::::new(&eph, &self.root)?; let mut v = Vec::new(); for x in trie.iter()? { let (key, value) = x?; @@ -159,10 +162,10 @@ impl Backend for TrieBackend { } } - fn storage_root(&self, delta: I) -> ([u8; 32], MemoryDB) + fn storage_root(&self, delta: I) -> (H::Out, MemoryDB) where I: IntoIterator, Option>)> { - let mut write_overlay = MemoryDB::default(); + let mut write_overlay = MemoryDB::new(); let mut root = self.root; { let mut eph = Ephemeral { @@ -170,7 +173,7 @@ impl Backend for TrieBackend { overlay: &mut write_overlay, }; - let mut trie = TrieDBMut::from_existing(&mut eph, &mut root).expect("prior state root to exist"); // TODO: handle gracefully + let mut trie = TrieDBMut::::from_existing(&mut eph, &mut root).expect("prior state root to exist"); // TODO: handle gracefully for (key, change) in delta { let result = match change { Some(val) => trie.insert(&key, &val), @@ -183,23 +186,28 @@ impl Backend for TrieBackend { } } - (root.0.into(), write_overlay) + (root, write_overlay) } } -impl TryIntoTrieBackend for TrieBackend { - fn try_into_trie_backend(self) -> Option { +impl> TryIntoTrieBackend for TrieBackend { + fn try_into_trie_backend(self) -> Option> { Some(self) } } -pub struct Ephemeral<'a> { - storage: &'a TrieBackendStorage, - overlay: &'a mut MemoryDB, +pub struct Ephemeral<'a, H: 'a + Hasher> { + storage: &'a TrieBackendStorage, + overlay: &'a mut MemoryDB, } -impl<'a> Ephemeral<'a> { - pub fn new(storage: &'a TrieBackendStorage, overlay: &'a mut MemoryDB) -> Self { +impl<'a, H: Hasher> AsHashDB for Ephemeral<'a, H> where H::Out: HeapSizeOf { + fn as_hashdb(&self) -> &HashDB { self } + fn as_hashdb_mut(&mut self) -> &mut HashDB { self } +} + +impl<'a, H: Hasher> Ephemeral<'a, H> { + pub fn new(storage: &'a TrieBackendStorage, overlay: &'a mut MemoryDB) -> Self { Ephemeral { storage, overlay, @@ -207,12 +215,12 @@ impl<'a> Ephemeral<'a> { } } -impl<'a> HashDB for Ephemeral<'a> { - fn keys(&self) -> HashMap { +impl<'a, H: Hasher> HashDB for Ephemeral<'a, H> where H::Out: HeapSizeOf { + fn keys(&self) -> HashMap { self.overlay.keys() // TODO: iterate backing } - fn get(&self, key: &TrieH256) -> Option { + fn get(&self, key: &H::Out) -> Option { match self.overlay.raw(key) { Some((val, i)) => { if i <= 0 { @@ -221,7 +229,7 @@ impl<'a> HashDB for Ephemeral<'a> { Some(val) } } - None => match self.storage.get(&key) { + None => match self.storage.get(key) { Ok(x) => x, Err(e) => { warn!(target: "trie", "Failed to read from DB: {}", e); @@ -231,33 +239,33 @@ impl<'a> HashDB for Ephemeral<'a> { } } - fn contains(&self, key: &TrieH256) -> bool { + fn contains(&self, key: &H::Out) -> bool { self.get(key).is_some() } - fn insert(&mut self, value: &[u8]) -> TrieH256 { + fn insert(&mut self, value: &[u8]) -> H::Out { self.overlay.insert(value) } - fn emplace(&mut self, key: TrieH256, value: DBValue) { + fn emplace(&mut self, key: H::Out, value: DBValue) { self.overlay.emplace(key, value) } - fn remove(&mut self, key: &TrieH256) { + fn remove(&mut self, key: &H::Out) { self.overlay.remove(key) } } #[derive(Clone)] -pub enum TrieBackendStorage { +pub enum TrieBackendStorage { /// Key value db + storage column. - Storage(Arc), + Storage(Arc>), /// Hash db. - MemoryDb(MemoryDB), + MemoryDb(MemoryDB), } -impl TrieBackendStorage { - pub fn get(&self, key: &TrieH256) -> Result, String> { +impl TrieBackendStorage { + pub fn get(&self, key: &H::Out) -> Result, String> { match *self { TrieBackendStorage::Storage(ref db) => db.get(key) @@ -272,24 +280,25 @@ impl TrieBackendStorage { pub mod tests { use super::*; use std::collections::HashSet; + use primitives::{KeccakHasher, RlpCodec, H256}; - fn test_db() -> (MemoryDB, TrieH256) { - let mut root = TrieH256::default(); - let mut mdb = MemoryDB::default(); + fn test_db() -> (MemoryDB, H256) { + let mut root = H256::default(); + let mut mdb = MemoryDB::::new(); { - let mut trie = TrieDBMut::new(&mut mdb, &mut root); - trie.insert(b"key", b"value").unwrap(); - trie.insert(b"value1", &[42]).unwrap(); - trie.insert(b"value2", &[24]).unwrap(); - trie.insert(b":code", b"return 42").unwrap(); - for i in 128u8..255u8 { - trie.insert(&[i], &[i]).unwrap(); - } + let mut trie = TrieDBMut::<_, RlpCodec>::new(&mut mdb, &mut root); + trie.insert(b"key", b"value").expect("insert failed"); + trie.insert(b"value1", &[42]).expect("insert failed"); + trie.insert(b"value2", &[24]).expect("insert failed"); + trie.insert(b":code", b"return 42").expect("insert failed"); + for i in 128u8..255u8 { + trie.insert(&[i], &[i]).unwrap(); + } } (mdb, root) } - pub fn test_trie() -> TrieBackend { + pub(crate) fn test_trie() -> TrieBackend { let (mdb, root) = test_db(); TrieBackend::with_memorydb(mdb, root) } @@ -311,12 +320,16 @@ pub mod tests { #[test] fn pairs_are_empty_on_empty_storage() { - assert!(TrieBackend::with_memorydb(MemoryDB::new(), Default::default()).pairs().is_empty()); + let db = TrieBackend::::with_memorydb( + MemoryDB::new(), + Default::default() + ); + assert!(db.pairs().is_empty()); } #[test] fn storage_root_is_non_default() { - assert!(test_trie().storage_root(::std::iter::empty()).0 != [0; 32]); + assert!(test_trie().storage_root(::std::iter::empty()).0 != H256([0; 32])); } #[test] diff --git a/substrate/substrate/telemetry/src/lib.rs b/substrate/substrate/telemetry/src/lib.rs index 4782f244e1..1054b7b397 100644 --- a/substrate/substrate/telemetry/src/lib.rs +++ b/substrate/substrate/telemetry/src/lib.rs @@ -14,7 +14,7 @@ // You should have received a copy of the GNU General Public License // along with Substrate. If not, see . -//! Telemtetry utils. +//! Telemetry utils. //! //! `telemetry` macro be used from whereever in the Substrate codebase //! in order to send real-time logging information to the telemetry diff --git a/substrate/substrate/test-client/Cargo.toml b/substrate/substrate/test-client/Cargo.toml index 69920cb485..461a29cac8 100644 --- a/substrate/substrate/test-client/Cargo.toml +++ b/substrate/substrate/test-client/Cargo.toml @@ -14,3 +14,5 @@ substrate-primitives = { path = "../primitives" } substrate-runtime-support = { path = "../runtime-support" } substrate-test-runtime = { path = "../test-runtime" } substrate-runtime-primitives = { path = "../runtime/primitives" } +hashdb = { git = "https://github.com/paritytech/parity-common" } + diff --git a/substrate/substrate/test-client/src/block_builder_ext.rs b/substrate/substrate/test-client/src/block_builder_ext.rs index 17fdbeba0a..a1894f5fa6 100644 --- a/substrate/substrate/test-client/src/block_builder_ext.rs +++ b/substrate/substrate/test-client/src/block_builder_ext.rs @@ -22,6 +22,7 @@ use keyring; use runtime; use {Backend, Executor}; +use primitives::{KeccakHasher, RlpCodec}; /// Extension trait for test block builder. pub trait BlockBuilderExt { @@ -29,7 +30,7 @@ pub trait BlockBuilderExt { fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error>; } -impl BlockBuilderExt for client::block_builder::BlockBuilder { +impl BlockBuilderExt for client::block_builder::BlockBuilder { fn push_transfer(&mut self, transfer: runtime::Transfer) -> Result<(), client::error::Error> { self.push(sign_tx(transfer)) } diff --git a/substrate/substrate/test-client/src/lib.rs b/substrate/substrate/test-client/src/lib.rs index a0709210ec..6a7e52a201 100644 --- a/substrate/substrate/test-client/src/lib.rs +++ b/substrate/substrate/test-client/src/lib.rs @@ -25,6 +25,7 @@ extern crate substrate_primitives as primitives; extern crate substrate_runtime_support as runtime_support; extern crate substrate_runtime_primitives as runtime_primitives; #[macro_use] extern crate substrate_executor as executor; +extern crate hashdb; pub extern crate substrate_client as client; pub extern crate substrate_keyring as keyring; @@ -36,10 +37,12 @@ mod block_builder_ext; pub use client_ext::TestClient; pub use block_builder_ext::BlockBuilderExt; +use primitives::{KeccakHasher, RlpCodec}; + mod local_executor { #![allow(missing_docs)] use super::runtime; - + // TODO: change the macro and pass in the `BlakeHasher` that dispatch needs from here instead native_executor_instance!(pub LocalExecutor, runtime::api::dispatch, runtime::VERSION, include_bytes!("../../test-runtime/wasm/target/wasm32-unknown-unknown/release/substrate_test_runtime.compact.wasm")); } @@ -47,7 +50,7 @@ mod local_executor { pub use local_executor::LocalExecutor; /// Test client database backend. -pub type Backend = client::in_mem::Backend; +pub type Backend = client::in_mem::Backend; /// Test client executor. pub type Executor = client::LocalCallExecutor>; diff --git a/substrate/substrate/test-runtime/src/system.rs b/substrate/substrate/test-runtime/src/system.rs index cb5ae23eb6..fcb2b951b6 100644 --- a/substrate/substrate/test-runtime/src/system.rs +++ b/substrate/substrate/test-runtime/src/system.rs @@ -171,8 +171,9 @@ mod tests { use codec::{Joiner, KeyedVec}; use keyring::Keyring; use ::{Header, Digest, Extrinsic, Transfer}; + use primitives::KeccakHasher; - fn new_test_ext() -> TestExternalities { + fn new_test_ext() -> TestExternalities { map![ twox_128(b"latest").to_vec() => vec![69u8; 32], twox_128(b":auth:len").to_vec() => vec![].and(&3u32), @@ -195,6 +196,9 @@ mod tests { let h = Header { parent_hash: [69u8; 32].into(), number: 1, + // Blake + // state_root: hex!("0c22599e15fb5e052c84f79a2aab179ba6bb238218fd86bdd4a74ebcc87adfcd").into(), + // Keccak state_root: hex!("97dfcd1f8cbf8845fcb544f89332f1a94c1137f7d1b199ef0b0a6ed217015c3e").into(), extrinsics_root: hex!("56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421").into(), digest: Digest { logs: vec![], }, @@ -223,6 +227,9 @@ mod tests { header: Header { parent_hash: [69u8; 32].into(), number: 1, + // Blake + // state_root: hex!("0425393fd07e2a806cfd7e990ee91dc92fe6bba34eab2bf45d5be7d67e24d467").into(), + // Keccak state_root: hex!("0dd8210adaf581464cc68555814a787ed491f8c608d0a0dbbf2208a6d44190b1").into(), extrinsics_root: hex!("951508f2cc0071500a74765ab0fb2f280fdcdd329d5f989dda675010adee99d6").into(), digest: Digest { logs: vec![], }, @@ -248,6 +255,9 @@ mod tests { header: Header { parent_hash: b.header.hash(), number: 2, + // Blake + // state_root: hex!("e32dd1d84d9133ca48078d2d83f2b0db19f9d47229ba98bf5ced0e9f86fac2c7").into(), + // Keccak state_root: hex!("c93f2fd494c386fa32ee76b6198a7ccf5db12c02c3a79755fd2d4646ec2bf8d7").into(), extrinsics_root: hex!("3563642676d7e042c894eedc579ba2d6eeedf9a6c66d9d557599effc9f674372").into(), digest: Digest { logs: vec![], },