Merge branch 'master' into light-poa
This commit is contained in:
commit
372779915f
70
Cargo.lock
generated
70
Cargo.lock
generated
@ -196,7 +196,7 @@ name = "bloomable"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethcore-bigint 0.1.3",
|
||||
"tiny-keccak 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -301,6 +301,7 @@ dependencies = [
|
||||
"bloomable 0.1.0",
|
||||
"ethcore-util 1.8.0",
|
||||
"ethjson 0.1.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
"rlp_derive 0.1.0",
|
||||
@ -481,16 +482,17 @@ name = "ethash"
|
||||
version = "1.8.0"
|
||||
dependencies = [
|
||||
"crunchy 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"primal 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha3 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ethcore"
|
||||
version = "1.8.0"
|
||||
dependencies = [
|
||||
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bit-set 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"bloomable 0.1.0",
|
||||
"bloomchain 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -517,6 +519,7 @@ dependencies = [
|
||||
"evm 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hardware-wallet 1.8.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hyper 0.10.0-a.0 (git+https://github.com/paritytech/hyper)",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -527,17 +530,20 @@ dependencies = [
|
||||
"native-contracts 0.1.0",
|
||||
"num 0.1.32 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"num_cpus 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"price-info 1.7.0",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
"rlp_derive 0.1.0",
|
||||
"rust-crypto 0.2.36 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"semantic_version 0.1.0",
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"stats 0.1.0",
|
||||
"table 0.1.0",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"transient-hashmap 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"triehash 0.1.0",
|
||||
"using_queue 0.1.0",
|
||||
"vm 0.1.0",
|
||||
"wasm 0.1.0",
|
||||
@ -654,9 +660,11 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"evm 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
"rlp_derive 0.1.0",
|
||||
@ -665,6 +673,7 @@ dependencies = [
|
||||
"smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"stats 0.1.0",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"triehash 0.1.0",
|
||||
"vm 0.1.0",
|
||||
]
|
||||
|
||||
@ -696,6 +705,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"ethcrypto 0.1.0",
|
||||
"ethkey 0.2.0",
|
||||
"hash 0.1.0",
|
||||
"igd 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipnetwork 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -730,6 +740,7 @@ dependencies = [
|
||||
"ethkey 0.2.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-cpupool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"hyper 0.10.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -758,11 +769,13 @@ dependencies = [
|
||||
"ethcore-logger 1.8.0",
|
||||
"ethcore-util 1.8.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-macros 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-tcp-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tokio-core 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -780,6 +793,7 @@ dependencies = [
|
||||
"ethcore-bloom-journal 0.1.0",
|
||||
"ethcore-devtools 1.8.0",
|
||||
"ethcore-logger 1.8.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -792,10 +806,10 @@ dependencies = [
|
||||
"rust-crypto 0.2.36 (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.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"sha3 0.1.0",
|
||||
"target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tiny-keccak 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"triehash 0.1.0",
|
||||
"vergen 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
@ -901,6 +915,7 @@ dependencies = [
|
||||
"ethcore-network 1.8.0",
|
||||
"ethcore-util 1.8.0",
|
||||
"ethkey 0.2.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ipnetwork 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -910,6 +925,7 @@ dependencies = [
|
||||
"semver 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallvec 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"triehash 0.1.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -923,10 +939,12 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"ethjson 0.1.0",
|
||||
"evmjit 1.8.0",
|
||||
"hash 0.1.0",
|
||||
"heapsize 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-wasm 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"vm 0.1.0",
|
||||
@ -1066,6 +1084,16 @@ dependencies = [
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "hash"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethcore-bigint 0.1.3",
|
||||
"gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tempdir 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tiny-keccak 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "heapsize"
|
||||
version = "0.4.0"
|
||||
@ -1630,6 +1658,7 @@ dependencies = [
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"native-contracts 0.1.0",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -1851,6 +1880,7 @@ dependencies = [
|
||||
"fdlimit 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-cpupool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"ipnetwork 0.12.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"isatty 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@ -1869,6 +1899,7 @@ dependencies = [
|
||||
"parity-rpc-client 1.4.0",
|
||||
"parity-updater 1.8.0",
|
||||
"parity-whisper 0.1.0",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"path 0.1.0",
|
||||
"pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1898,6 +1929,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"fetch 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-http-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@ -1910,6 +1942,7 @@ dependencies = [
|
||||
"parity-hash-fetch 1.8.0",
|
||||
"parity-reactor 0.1.0",
|
||||
"parity-ui 1.8.0",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -1943,11 +1976,13 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"fetch 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mime 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"mime_guess 1.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"native-contracts 0.1.0",
|
||||
"parity-reactor 0.1.0",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rustc-hex 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -1992,6 +2027,7 @@ dependencies = [
|
||||
name = "parity-rpc"
|
||||
version = "1.8.0"
|
||||
dependencies = [
|
||||
"ansi_term 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"cid 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"clippy 0.0.103 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ethash 1.8.0",
|
||||
@ -2010,6 +2046,7 @@ dependencies = [
|
||||
"fetch 0.1.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"futures-cpupool 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"itertools 0.5.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-http-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
@ -2024,6 +2061,7 @@ dependencies = [
|
||||
"order-stat 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-reactor 0.1.0",
|
||||
"parity-updater 1.8.0",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"pretty_assertions 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
@ -2046,11 +2084,13 @@ version = "1.4.0"
|
||||
dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"futures 0.1.11 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hash 0.1.0",
|
||||
"jsonrpc-core 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"jsonrpc-ws-server 7.0.0 (git+https://github.com/paritytech/jsonrpc.git?branch=parity-1.7)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"matches 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-rpc 1.8.0",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rand 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
@ -2094,7 +2134,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "parity-ui-precompiled"
|
||||
version = "1.4.0"
|
||||
source = "git+https://github.com/paritytech/js-precompiled.git#d809723e58bcb36c0f8d2eca5ca94abbb3690544"
|
||||
source = "git+https://github.com/paritytech/js-precompiled.git#f34bdb63272fd59edf2062dda44113831964d800"
|
||||
dependencies = [
|
||||
"parity-dapps-glue 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -2114,6 +2154,7 @@ dependencies = [
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"parity-hash-fetch 1.8.0",
|
||||
"parity-reactor 0.1.0",
|
||||
"parking_lot 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"path 0.1.0",
|
||||
"target_info 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
@ -2609,6 +2650,10 @@ dependencies = [
|
||||
"libc 0.2.21 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "semantic_version"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "semver"
|
||||
version = "0.1.20"
|
||||
@ -2694,13 +2739,6 @@ name = "sha1"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "sha3"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"gcc 0.3.51 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "shell32-sys"
|
||||
version = "0.1.1"
|
||||
@ -3072,6 +3110,15 @@ dependencies = [
|
||||
"time 0.1.35 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "triehash"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"ethcore-bigint 0.1.3",
|
||||
"hash 0.1.0",
|
||||
"rlp 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "typeable"
|
||||
version = "0.1.2"
|
||||
@ -3185,6 +3232,7 @@ dependencies = [
|
||||
"ethcore-util 1.8.0",
|
||||
"ethjson 0.1.0",
|
||||
"evmjit 1.8.0",
|
||||
"hash 0.1.0",
|
||||
"lazy_static 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rlp 0.2.0",
|
||||
|
@ -17,6 +17,7 @@ number_prefix = "0.2"
|
||||
rpassword = "0.2.1"
|
||||
semver = "0.6"
|
||||
ansi_term = "0.9"
|
||||
parking_lot = "0.4"
|
||||
regex = "0.2"
|
||||
isatty = "0.1"
|
||||
toml = "0.4"
|
||||
@ -57,6 +58,7 @@ parity-updater = { path = "updater" }
|
||||
parity-whisper = { path = "whisper" }
|
||||
path = { path = "util/path" }
|
||||
panic_hook = { path = "panic_hook" }
|
||||
hash = { path = "util/hash" }
|
||||
|
||||
parity-dapps = { path = "dapps", optional = true }
|
||||
clippy = { version = "0.0.103", optional = true}
|
||||
|
@ -13,6 +13,7 @@ futures = "0.1"
|
||||
linked-hash-map = "0.3"
|
||||
log = "0.3"
|
||||
parity-dapps-glue = "1.7"
|
||||
parking_lot = "0.4"
|
||||
mime = "0.2"
|
||||
mime_guess = "1.6.1"
|
||||
rand = "0.3"
|
||||
@ -35,6 +36,7 @@ node-health = { path = "./node-health" }
|
||||
parity-hash-fetch = { path = "../hash-fetch" }
|
||||
parity-reactor = { path = "../util/reactor" }
|
||||
parity-ui = { path = "./ui" }
|
||||
hash = { path = "../util/hash" }
|
||||
|
||||
clippy = { version = "0.0.103", optional = true}
|
||||
|
||||
|
@ -19,9 +19,9 @@ use std::{fs, fmt};
|
||||
use std::io::{self, Read, Write};
|
||||
use std::path::PathBuf;
|
||||
use fetch::{self, Mime};
|
||||
use hash::keccak_buffer;
|
||||
use util::H256;
|
||||
|
||||
use util::sha3::sha3;
|
||||
use page::{LocalPageEndpoint, PageCache};
|
||||
use handlers::{ContentValidator, ValidatorResponse};
|
||||
use apps::manifest::{MANIFEST_FILENAME, deserialize_manifest, serialize_manifest, Manifest};
|
||||
@ -57,9 +57,9 @@ fn write_response_and_check_hash(
|
||||
file.flush()?;
|
||||
|
||||
// Validate hash
|
||||
// TODO [ToDr] calculate sha3 in-flight while reading the response
|
||||
// TODO [ToDr] calculate keccak in-flight while reading the response
|
||||
let mut file = io::BufReader::new(fs::File::open(&content_path)?);
|
||||
let hash = sha3(&mut file)?;
|
||||
let hash = keccak_buffer(&mut file)?;
|
||||
if id == hash {
|
||||
Ok((file.into_inner(), content_path))
|
||||
} else {
|
||||
|
@ -32,7 +32,7 @@ use hyper;
|
||||
use hyper::status::StatusCode;
|
||||
|
||||
use {Embeddable, SyncStatus, random_filename};
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
use page::LocalPageEndpoint;
|
||||
use handlers::{ContentHandler, ContentFetcherHandler};
|
||||
use endpoint::{Endpoint, EndpointPath, Handler};
|
||||
|
@ -23,7 +23,7 @@ use std::time::{Instant, Duration};
|
||||
use fetch::{self, Fetch};
|
||||
use futures::Future;
|
||||
use parity_reactor::Remote;
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use hyper::{server, Decoder, Encoder, Next, Method, Control};
|
||||
use hyper::net::HttpStream;
|
||||
|
@ -24,6 +24,7 @@ extern crate futures;
|
||||
extern crate itertools;
|
||||
extern crate linked_hash_map;
|
||||
extern crate mime_guess;
|
||||
extern crate parking_lot;
|
||||
extern crate rand;
|
||||
extern crate rustc_hex;
|
||||
extern crate serde;
|
||||
@ -43,6 +44,7 @@ extern crate parity_dapps_glue as parity_dapps;
|
||||
extern crate parity_hash_fetch as hash_fetch;
|
||||
extern crate parity_reactor;
|
||||
extern crate parity_ui;
|
||||
extern crate hash;
|
||||
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
@ -72,7 +74,7 @@ use std::collections::HashMap;
|
||||
use std::mem;
|
||||
use std::path::PathBuf;
|
||||
use std::sync::Arc;
|
||||
use util::RwLock;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
use jsonrpc_http_server::{self as http, hyper, Origin};
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
use std::{io, thread, time};
|
||||
use std::sync::{atomic, mpsc, Arc};
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use futures::{self, Future};
|
||||
use fetch::{self, Fetch};
|
||||
|
@ -20,7 +20,8 @@ use std::collections::HashMap;
|
||||
use rustc_hex::FromHex;
|
||||
|
||||
use hash_fetch::urlhint::ContractClient;
|
||||
use util::{Bytes, Address, Mutex, H256, ToPretty};
|
||||
use parking_lot::Mutex;
|
||||
use util::{Bytes, Address, H256, ToPretty};
|
||||
|
||||
const REGISTRAR: &'static str = "8e4e9b13d4b45cb0befc93c3061b1408f67316b2";
|
||||
const URLHINT: &'static str = "deadbeefcafe0000000000000000000000000000";
|
||||
|
@ -7,7 +7,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
||||
|
||||
[dependencies]
|
||||
log = "0.3"
|
||||
sha3 = { path = "../util/sha3" }
|
||||
hash = { path = "../util/hash" }
|
||||
primal = "0.2.3"
|
||||
parking_lot = "0.4"
|
||||
crunchy = "0.1.0"
|
||||
|
@ -23,7 +23,7 @@ use primal::is_prime;
|
||||
use std::cell::Cell;
|
||||
use std::mem;
|
||||
use std::ptr;
|
||||
use sha3;
|
||||
use hash;
|
||||
use std::slice;
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::io::{self, Read, Write};
|
||||
@ -200,7 +200,7 @@ impl SeedHashCompute {
|
||||
#[inline]
|
||||
pub fn resume_compute_seedhash(mut hash: H256, start_epoch: u64, end_epoch: u64) -> H256 {
|
||||
for _ in start_epoch..end_epoch {
|
||||
unsafe { sha3::sha3_256(hash[..].as_mut_ptr(), 32, hash[..].as_ptr(), 32) };
|
||||
unsafe { hash::keccak_256(hash[..].as_mut_ptr(), 32, hash[..].as_ptr(), 32) };
|
||||
}
|
||||
hash
|
||||
}
|
||||
@ -214,14 +214,14 @@ fn fnv_hash(x: u32, y: u32) -> u32 {
|
||||
return x.wrapping_mul(FNV_PRIME) ^ y;
|
||||
}
|
||||
|
||||
fn sha3_512(input: &[u8], output: &mut [u8]) {
|
||||
unsafe { sha3::sha3_512(output.as_mut_ptr(), output.len(), input.as_ptr(), input.len()) };
|
||||
fn keccak_512(input: &[u8], output: &mut [u8]) {
|
||||
unsafe { hash::keccak_512(output.as_mut_ptr(), output.len(), input.as_ptr(), input.len()) };
|
||||
}
|
||||
|
||||
fn sha3_512_inplace(input: &mut [u8]) {
|
||||
// This is safe since `sha3_*` uses an internal buffer and copies the result to the output. This
|
||||
fn keccak_512_inplace(input: &mut [u8]) {
|
||||
// This is safe since `keccak_*` uses an internal buffer and copies the result to the output. This
|
||||
// means that we can reuse the input buffer for both input and output.
|
||||
unsafe { sha3::sha3_512(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len()) };
|
||||
unsafe { hash::keccak_512(input.as_mut_ptr(), input.len(), input.as_ptr(), input.len()) };
|
||||
}
|
||||
|
||||
fn get_cache_size(block_number: u64) -> usize {
|
||||
@ -250,23 +250,23 @@ fn get_data_size(block_number: u64) -> usize {
|
||||
/// Boundary recovered from mix hash
|
||||
pub fn quick_get_difficulty(header_hash: &H256, nonce: u64, mix_hash: &H256) -> H256 {
|
||||
unsafe {
|
||||
// This is safe - the `sha3_512` call below reads the first 40 bytes (which we explicitly set
|
||||
// This is safe - the `keccak_512` call below reads the first 40 bytes (which we explicitly set
|
||||
// with two `copy_nonoverlapping` calls) but writes the first 64, and then we explicitly write
|
||||
// the next 32 bytes before we read the whole thing with `sha3_256`.
|
||||
// the next 32 bytes before we read the whole thing with `keccak_256`.
|
||||
//
|
||||
// This cannot be elided by the compiler as it doesn't know the implementation of
|
||||
// `sha3_512`.
|
||||
// `keccak_512`.
|
||||
let mut buf: [u8; 64 + 32] = mem::uninitialized();
|
||||
|
||||
ptr::copy_nonoverlapping(header_hash.as_ptr(), buf.as_mut_ptr(), 32);
|
||||
ptr::copy_nonoverlapping(mem::transmute(&nonce), buf[32..].as_mut_ptr(), 8);
|
||||
|
||||
sha3::sha3_512(buf.as_mut_ptr(), 64, buf.as_ptr(), 40);
|
||||
hash::keccak_512(buf.as_mut_ptr(), 64, buf.as_ptr(), 40);
|
||||
ptr::copy_nonoverlapping(mix_hash.as_ptr(), buf[64..].as_mut_ptr(), 32);
|
||||
|
||||
// This is initialized in `sha3_256`
|
||||
// This is initialized in `keccak_256`
|
||||
let mut hash: [u8; 32] = mem::uninitialized();
|
||||
sha3::sha3_256(hash.as_mut_ptr(), hash.len(), buf.as_ptr(), buf.len());
|
||||
hash::keccak_256(hash.as_mut_ptr(), hash.len(), buf.as_ptr(), buf.len());
|
||||
|
||||
hash
|
||||
}
|
||||
@ -320,7 +320,7 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64)
|
||||
half_mix: unsafe {
|
||||
// Pack `header_hash` and `nonce` together
|
||||
// We explicitly write the first 40 bytes, leaving the last 24 as uninitialized. Then
|
||||
// `sha3_512` reads the first 40 bytes (4th parameter) and overwrites the entire array,
|
||||
// `keccak_512` reads the first 40 bytes (4th parameter) and overwrites the entire array,
|
||||
// leaving it fully initialized.
|
||||
let mut out: [u8; NODE_BYTES] = mem::uninitialized();
|
||||
|
||||
@ -335,8 +335,8 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64)
|
||||
mem::size_of::<u64>(),
|
||||
);
|
||||
|
||||
// compute sha3-512 hash and replicate across mix
|
||||
sha3::sha3_512(
|
||||
// compute keccak-512 hash and replicate across mix
|
||||
hash::keccak_512(
|
||||
out.as_mut_ptr(),
|
||||
NODE_BYTES,
|
||||
out.as_ptr(),
|
||||
@ -427,10 +427,10 @@ fn hash_compute(light: &Light, full_size: usize, header_hash: &H256, nonce: u64)
|
||||
let value: H256 = unsafe {
|
||||
// We can interpret the buffer as an array of `u8`s, since it's `repr(C)`.
|
||||
let read_ptr: *const u8 = mem::transmute(&buf);
|
||||
// We overwrite the second half since `sha3_256` has an internal buffer and so allows
|
||||
// We overwrite the second half since `keccak_256` has an internal buffer and so allows
|
||||
// overlapping arrays as input.
|
||||
let write_ptr: *mut u8 = mem::transmute(&mut buf.compress_bytes);
|
||||
sha3::sha3_256(
|
||||
hash::keccak_256(
|
||||
write_ptr,
|
||||
buf.compress_bytes.len(),
|
||||
read_ptr,
|
||||
@ -450,7 +450,7 @@ fn calculate_dag_item(node_index: u32, cache: &[Node]) -> Node {
|
||||
let mut ret = cache[node_index as usize % num_parent_nodes].clone();
|
||||
ret.as_words_mut()[0] ^= node_index;
|
||||
|
||||
sha3_512_inplace(&mut ret.bytes);
|
||||
keccak_512_inplace(&mut ret.bytes);
|
||||
|
||||
debug_assert_eq!(NODE_WORDS, 16);
|
||||
for i in 0..ETHASH_DATASET_PARENTS as u32 {
|
||||
@ -467,7 +467,7 @@ fn calculate_dag_item(node_index: u32, cache: &[Node]) -> Node {
|
||||
}
|
||||
}
|
||||
|
||||
sha3_512_inplace(&mut ret.bytes);
|
||||
keccak_512_inplace(&mut ret.bytes);
|
||||
|
||||
ret
|
||||
}
|
||||
@ -485,9 +485,9 @@ fn light_new<T: AsRef<Path>>(cache_dir: T, block_number: u64) -> Light {
|
||||
// Use uninit instead of unnecessarily writing `size_of::<Node>() * num_nodes` 0s
|
||||
nodes.set_len(num_nodes);
|
||||
|
||||
sha3_512(&seedhash[0..32], &mut nodes.get_unchecked_mut(0).bytes);
|
||||
keccak_512(&seedhash[0..32], &mut nodes.get_unchecked_mut(0).bytes);
|
||||
for i in 1..num_nodes {
|
||||
sha3::sha3_512(nodes.get_unchecked_mut(i).bytes.as_mut_ptr(), NODE_BYTES, nodes.get_unchecked(i - 1).bytes.as_ptr(), NODE_BYTES);
|
||||
hash::keccak_512(nodes.get_unchecked_mut(i).bytes.as_mut_ptr(), NODE_BYTES, nodes.get_unchecked(i - 1).bytes.as_ptr(), NODE_BYTES);
|
||||
}
|
||||
|
||||
debug_assert_eq!(NODE_WORDS, 16);
|
||||
@ -504,7 +504,7 @@ fn light_new<T: AsRef<Path>>(cache_dir: T, block_number: u64) -> Light {
|
||||
}
|
||||
}
|
||||
|
||||
sha3_512(&data.bytes, &mut nodes.get_unchecked_mut(i).bytes);
|
||||
keccak_512(&data.bytes, &mut nodes.get_unchecked_mut(i).bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,7 +20,7 @@
|
||||
#![cfg_attr(feature = "benches", feature(test))]
|
||||
|
||||
extern crate primal;
|
||||
extern crate sha3;
|
||||
extern crate hash;
|
||||
extern crate parking_lot;
|
||||
|
||||
#[macro_use]
|
||||
|
@ -11,6 +11,7 @@ build = "build.rs"
|
||||
"ethcore-ipc-codegen" = { path = "../ipc/codegen" }
|
||||
|
||||
[dependencies]
|
||||
ansi_term = "0.9"
|
||||
bit-set = "0.4"
|
||||
bloomchain = "0.1"
|
||||
bn = { git = "https://github.com/paritytech/bn" }
|
||||
@ -45,6 +46,7 @@ lru-cache = "0.1.0"
|
||||
native-contracts = { path = "native_contracts" }
|
||||
num = "0.1"
|
||||
num_cpus = "1.2"
|
||||
parking_lot = "0.4"
|
||||
price-info = { path = "../price-info" }
|
||||
rand = "0.3"
|
||||
rlp = { path = "../util/rlp" }
|
||||
@ -60,6 +62,9 @@ table = { path = "../util/table" }
|
||||
bloomable = { path = "../util/bloomable" }
|
||||
vm = { path = "vm" }
|
||||
wasm = { path = "wasm" }
|
||||
hash = { path = "../util/hash" }
|
||||
triehash = { path = "../util/triehash" }
|
||||
semantic_version = { path = "../util/semantic_version" }
|
||||
|
||||
[dev-dependencies]
|
||||
native-contracts = { path = "native_contracts", features = ["test_contracts"] }
|
||||
|
@ -16,8 +16,10 @@ log = "0.3"
|
||||
rlp = { path = "../../util/rlp" }
|
||||
vm = { path = "../vm" }
|
||||
parity-wasm = "0.12"
|
||||
parking_lot = "0.4"
|
||||
ethcore-logger = { path = "../../logger" }
|
||||
wasm-utils = { git = "https://github.com/paritytech/wasm-utils" }
|
||||
hash = { path = "../../util/hash" }
|
||||
|
||||
[dev-dependencies]
|
||||
rustc-hex = "1.0"
|
||||
|
@ -26,6 +26,7 @@ mod shared_cache;
|
||||
use std::marker::PhantomData;
|
||||
use std::{cmp, mem};
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
|
||||
use vm::{
|
||||
self, ActionParams, ActionValue, CallType, MessageCallResult,
|
||||
@ -180,7 +181,7 @@ impl<Cost: CostType> vm::Vm for Interpreter<Cost> {
|
||||
match result {
|
||||
InstructionResult::JumpToPosition(position) => {
|
||||
if valid_jump_destinations.is_none() {
|
||||
let code_hash = params.code_hash.clone().unwrap_or_else(|| code.sha3());
|
||||
let code_hash = params.code_hash.clone().unwrap_or_else(|| keccak(code.as_ref()));
|
||||
valid_jump_destinations = Some(self.cache.jump_destinations(&code_hash, code));
|
||||
}
|
||||
let jump_destinations = valid_jump_destinations.as_ref().expect("jump_destinations are initialized on first jump; qed");
|
||||
@ -464,8 +465,8 @@ impl<Cost: CostType> Interpreter<Cost> {
|
||||
instructions::SHA3 => {
|
||||
let offset = stack.pop_back();
|
||||
let size = stack.pop_back();
|
||||
let sha3 = self.mem.read_slice(offset, size).sha3();
|
||||
stack.push(U256::from(&*sha3));
|
||||
let k = keccak(self.mem.read_slice(offset, size));
|
||||
stack.push(U256::from(&*k));
|
||||
},
|
||||
instructions::SLOAD => {
|
||||
let key = H256::from(&stack.pop_back());
|
||||
@ -880,7 +881,7 @@ mod tests {
|
||||
use rustc_hex::FromHex;
|
||||
use vmtype::VMType;
|
||||
use factory::Factory;
|
||||
use vm::{self, ActionParams, ActionValue};
|
||||
use vm::{ActionParams, ActionValue};
|
||||
use vm::tests::{FakeExt, test_finalize};
|
||||
|
||||
#[test]
|
||||
|
@ -15,9 +15,10 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use std::sync::Arc;
|
||||
use hash::KECCAK_EMPTY;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{H256, Mutex};
|
||||
use util::sha3::*;
|
||||
use parking_lot::Mutex;
|
||||
use util::H256;
|
||||
use util::cache::MemoryLruCache;
|
||||
use bit_set::BitSet;
|
||||
use super::super::instructions;
|
||||
@ -50,7 +51,7 @@ impl SharedCache {
|
||||
|
||||
/// Get jump destinations bitmap for a contract.
|
||||
pub fn jump_destinations(&self, code_hash: &H256, code: &[u8]) -> Arc<BitSet> {
|
||||
if code_hash == &SHA3_EMPTY {
|
||||
if code_hash == &KECCAK_EMPTY {
|
||||
return Self::find_jump_destinations(code);
|
||||
}
|
||||
|
||||
|
@ -23,10 +23,12 @@ extern crate ethcore_util as util;
|
||||
extern crate ethjson;
|
||||
extern crate rlp;
|
||||
extern crate parity_wasm;
|
||||
extern crate parking_lot;
|
||||
extern crate wasm_utils;
|
||||
extern crate ethcore_logger;
|
||||
extern crate heapsize;
|
||||
extern crate vm;
|
||||
extern crate hash;
|
||||
|
||||
#[macro_use]
|
||||
extern crate lazy_static;
|
||||
|
@ -31,7 +31,10 @@ itertools = "0.5"
|
||||
bincode = "0.8.0"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
parking_lot = "0.4"
|
||||
stats = { path = "../../util/stats" }
|
||||
hash = { path = "../../util/hash" }
|
||||
triehash = { path = "../../util/triehash" }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
|
@ -130,7 +130,7 @@ pub fn compute_root<I>(cht_num: u64, iterable: I) -> Option<H256>
|
||||
}
|
||||
|
||||
if v.len() == SIZE as usize {
|
||||
Some(::util::triehash::trie_root(v))
|
||||
Some(::triehash::trie_root(v))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -43,11 +43,11 @@ use ethcore::engines::epoch::{
|
||||
|
||||
use rlp::{Encodable, Decodable, DecoderError, RlpStream, Rlp, UntrustedRlp};
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{H256, H256FastMap, H264, U256, RwLock};
|
||||
use util::{H256, H256FastMap, H264, U256};
|
||||
use util::kvdb::{DBTransaction, KeyValueDB};
|
||||
|
||||
use cache::Cache;
|
||||
use util::Mutex;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
|
||||
use smallvec::SmallVec;
|
||||
|
||||
@ -664,7 +664,7 @@ impl HeaderChain {
|
||||
|
||||
/// Get the genesis hash.
|
||||
pub fn genesis_hash(&self) -> H256 {
|
||||
::util::Hashable::sha3(&self.genesis_header)
|
||||
self.genesis_header.hash()
|
||||
}
|
||||
|
||||
/// Get the best block's data.
|
||||
@ -782,7 +782,7 @@ mod tests {
|
||||
use cache::Cache;
|
||||
|
||||
use time::Duration;
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
fn make_db() -> Arc<::util::KeyValueDB> {
|
||||
Arc::new(::util::kvdb::in_memory(0))
|
||||
|
@ -30,10 +30,11 @@ use ethcore::spec::Spec;
|
||||
use ethcore::service::ClientIoMessage;
|
||||
use ethcore::encoded;
|
||||
use io::IoChannel;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
|
||||
use futures::{IntoFuture, Future};
|
||||
|
||||
use util::{Address, H256, U256, Mutex, RwLock};
|
||||
use util::{Address, H256, U256};
|
||||
use util::kvdb::{KeyValueDB, CompactionProfile};
|
||||
|
||||
use self::fetch::ChainDataFetcher;
|
||||
|
@ -28,7 +28,7 @@ use io::{IoContext, IoError, IoHandler, IoService};
|
||||
use util::kvdb::{Database, DatabaseConfig};
|
||||
|
||||
use cache::Cache;
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
use super::{ChainDataFetcher, Client, Config as ClientConfig};
|
||||
|
||||
@ -126,7 +126,7 @@ mod tests {
|
||||
use cache::Cache;
|
||||
use client::fetch;
|
||||
use time::Duration;
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
|
||||
#[test]
|
||||
fn it_works() {
|
||||
|
@ -77,6 +77,7 @@ extern crate futures;
|
||||
extern crate itertools;
|
||||
extern crate rand;
|
||||
extern crate rlp;
|
||||
extern crate parking_lot;
|
||||
#[macro_use]
|
||||
extern crate rlp_derive;
|
||||
extern crate serde;
|
||||
@ -84,6 +85,8 @@ extern crate smallvec;
|
||||
extern crate stats;
|
||||
extern crate time;
|
||||
extern crate vm;
|
||||
extern crate hash;
|
||||
extern crate triehash;
|
||||
|
||||
#[cfg(feature = "ipc")]
|
||||
extern crate ethcore_ipc as ipc;
|
||||
|
@ -32,7 +32,7 @@ use request::{CompleteRequest, Kind};
|
||||
|
||||
use bincode;
|
||||
use time;
|
||||
use util::{RwLock, Mutex};
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
|
||||
/// Number of time periods samples should be kept for.
|
||||
pub const MOVING_SAMPLE_SIZE: usize = 256;
|
||||
|
@ -24,7 +24,8 @@ use io::TimerToken;
|
||||
use network::{HostInfo, NetworkProtocolHandler, NetworkContext, PeerId};
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
use util::hash::H256;
|
||||
use util::{DBValue, Mutex, RwLock, U256};
|
||||
use util::{DBValue, U256};
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use time::{Duration, SteadyTime};
|
||||
|
||||
use std::collections::{HashMap, HashSet};
|
||||
@ -287,7 +288,7 @@ pub type PeerMap = HashMap<PeerId, Mutex<Peer>>;
|
||||
mod id_guard {
|
||||
|
||||
use network::PeerId;
|
||||
use util::RwLockReadGuard;
|
||||
use parking_lot::RwLockReadGuard;
|
||||
|
||||
use super::{PeerMap, ReqId};
|
||||
|
||||
|
@ -656,7 +656,7 @@ fn id_guard() {
|
||||
pending_requests.insert(req_id_1, req.clone(), 0.into(), ::time::SteadyTime::now());
|
||||
pending_requests.insert(req_id_2, req, 1.into(), ::time::SteadyTime::now());
|
||||
|
||||
proto.peers.write().insert(peer_id, ::util::Mutex::new(Peer {
|
||||
proto.peers.write().insert(peer_id, ::parking_lot::Mutex::new(Peer {
|
||||
local_credits: flow_params.create_credits(),
|
||||
status: status(provider.client.chain_info()),
|
||||
capabilities: capabilities.clone(),
|
||||
|
@ -27,7 +27,7 @@ use ethcore::executed::{Executed, ExecutionError};
|
||||
use futures::{Async, Poll, Future};
|
||||
use futures::sync::oneshot::{self, Sender, Receiver, Canceled};
|
||||
use network::PeerId;
|
||||
use util::{RwLock, Mutex};
|
||||
use parking_lot::{RwLock, Mutex};
|
||||
|
||||
use net::{
|
||||
self, Handler, PeerStatus, Status, Capabilities,
|
||||
|
@ -25,13 +25,14 @@ use ethcore::receipt::Receipt;
|
||||
use ethcore::state::{self, ProvedExecution};
|
||||
use ethcore::transaction::SignedTransaction;
|
||||
use vm::EnvInfo;
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak};
|
||||
|
||||
use request::{self as net_request, IncompleteRequest, CompleteRequest, Output, OutputKind, Field};
|
||||
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
use util::{Address, Bytes, DBValue, HashDB, Mutex, H256, U256};
|
||||
use parking_lot::Mutex;
|
||||
use util::{Address, Bytes, DBValue, HashDB, H256, U256};
|
||||
use util::memorydb::MemoryDB;
|
||||
use util::sha3::{Hashable, SHA3_NULL_RLP, SHA3_EMPTY, SHA3_EMPTY_LIST_RLP};
|
||||
use util::trie::{Trie, TrieDB, TrieError};
|
||||
|
||||
const SUPPLIED_MATCHES: &'static str = "supplied responses always match produced requests; enforced by `check_response`; qed";
|
||||
@ -280,7 +281,7 @@ impl From<Request> for CheckedRequest {
|
||||
Request::Account(req) => {
|
||||
let net_req = net_request::IncompleteAccountRequest {
|
||||
block_hash: req.header.field(),
|
||||
address_hash: ::util::Hashable::sha3(&req.address).into(),
|
||||
address_hash: ::hash::keccak(&req.address).into(),
|
||||
};
|
||||
CheckedRequest::Account(req, net_req)
|
||||
}
|
||||
@ -377,7 +378,7 @@ impl CheckedRequest {
|
||||
}
|
||||
CheckedRequest::Receipts(ref check, ref req) => {
|
||||
// empty transactions -> no receipts
|
||||
if check.0.as_ref().ok().map_or(false, |hdr| hdr.receipts_root() == SHA3_NULL_RLP) {
|
||||
if check.0.as_ref().ok().map_or(false, |hdr| hdr.receipts_root() == KECCAK_NULL_RLP) {
|
||||
return Some(Response::Receipts(Vec::new()));
|
||||
}
|
||||
|
||||
@ -388,7 +389,7 @@ impl CheckedRequest {
|
||||
CheckedRequest::Body(ref check, ref req) => {
|
||||
// check for empty body.
|
||||
if let Some(hdr) = check.0.as_ref().ok() {
|
||||
if hdr.transactions_root() == SHA3_NULL_RLP && hdr.uncles_hash() == SHA3_EMPTY_LIST_RLP {
|
||||
if hdr.transactions_root() == KECCAK_NULL_RLP && hdr.uncles_hash() == KECCAK_EMPTY_LIST_RLP {
|
||||
let mut stream = RlpStream::new_list(3);
|
||||
stream.append_raw(hdr.rlp().as_raw(), 1);
|
||||
stream.begin_list(0);
|
||||
@ -433,7 +434,7 @@ impl CheckedRequest {
|
||||
})
|
||||
}
|
||||
CheckedRequest::Code(_, ref req) => {
|
||||
if req.code_hash.as_ref().map_or(false, |&h| h == SHA3_EMPTY) {
|
||||
if req.code_hash.as_ref().map_or(false, |&h| h == KECCAK_EMPTY) {
|
||||
Some(Response::Code(Vec::new()))
|
||||
} else {
|
||||
None
|
||||
@ -590,8 +591,8 @@ impl net_request::ResponseLike for Response {
|
||||
match *self {
|
||||
Response::HeaderProof((ref hash, _)) => f(0, Output::Hash(*hash)),
|
||||
Response::Account(None) => {
|
||||
f(0, Output::Hash(SHA3_EMPTY)); // code hash
|
||||
f(1, Output::Hash(SHA3_NULL_RLP)); // storage root.
|
||||
f(0, Output::Hash(KECCAK_EMPTY)); // code hash
|
||||
f(1, Output::Hash(KECCAK_NULL_RLP)); // storage root.
|
||||
}
|
||||
Response::Account(Some(ref acc)) => {
|
||||
f(0, Output::Hash(acc.code_hash));
|
||||
@ -707,7 +708,7 @@ impl HeaderByHash {
|
||||
};
|
||||
|
||||
let header = headers.get(0).ok_or(Error::Empty)?;
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
match hash == expected_hash {
|
||||
true => {
|
||||
cache.lock().insert_block_header(hash, header.clone());
|
||||
@ -727,12 +728,12 @@ impl Body {
|
||||
pub fn check_response(&self, cache: &Mutex<::cache::Cache>, body: &encoded::Body) -> Result<encoded::Block, Error> {
|
||||
// check the integrity of the the body against the header
|
||||
let header = self.0.as_ref()?;
|
||||
let tx_root = ::util::triehash::ordered_trie_root(body.rlp().at(0).iter().map(|r| r.as_raw().to_vec()));
|
||||
let tx_root = ::triehash::ordered_trie_root(body.rlp().at(0).iter().map(|r| r.as_raw().to_vec()));
|
||||
if tx_root != header.transactions_root() {
|
||||
return Err(Error::WrongTrieRoot(header.transactions_root(), tx_root));
|
||||
}
|
||||
|
||||
let uncles_hash = body.rlp().at(1).as_raw().sha3();
|
||||
let uncles_hash = keccak(body.rlp().at(1).as_raw());
|
||||
if uncles_hash != header.uncles_hash() {
|
||||
return Err(Error::WrongHash(header.uncles_hash(), uncles_hash));
|
||||
}
|
||||
@ -757,7 +758,7 @@ impl BlockReceipts {
|
||||
/// Check a response with receipts against the stored header.
|
||||
pub fn check_response(&self, cache: &Mutex<::cache::Cache>, receipts: &[Receipt]) -> Result<Vec<Receipt>, Error> {
|
||||
let receipts_root = self.0.as_ref()?.receipts_root();
|
||||
let found_root = ::util::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).into_vec()));
|
||||
let found_root = ::triehash::ordered_trie_root(receipts.iter().map(|r| ::rlp::encode(r).into_vec()));
|
||||
|
||||
match receipts_root == found_root {
|
||||
true => {
|
||||
@ -787,7 +788,7 @@ impl Account {
|
||||
let mut db = MemoryDB::new();
|
||||
for node in proof { db.insert(&node[..]); }
|
||||
|
||||
match TrieDB::new(&db, &state_root).and_then(|t| t.get(&self.address.sha3()))? {
|
||||
match TrieDB::new(&db, &state_root).and_then(|t| t.get(&keccak(&self.address)))? {
|
||||
Some(val) => {
|
||||
let rlp = UntrustedRlp::new(&val);
|
||||
Ok(Some(BasicAccount {
|
||||
@ -819,7 +820,7 @@ impl Code {
|
||||
code_hash: &H256,
|
||||
code: &[u8]
|
||||
) -> Result<Vec<u8>, Error> {
|
||||
let found_hash = code.sha3();
|
||||
let found_hash = keccak(code);
|
||||
if &found_hash == code_hash {
|
||||
Ok(code.to_vec())
|
||||
} else {
|
||||
@ -890,9 +891,11 @@ impl Signal {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use util::{MemoryDB, Address, Mutex, H256};
|
||||
use parking_lot::Mutex;
|
||||
use util::{MemoryDB, Address, H256};
|
||||
use util::trie::{Trie, TrieMut, SecTrieDB, SecTrieDBMut};
|
||||
use util::trie::recorder::Recorder;
|
||||
use hash::keccak;
|
||||
|
||||
use ethcore::client::{BlockChainClient, TestBlockChainClient, EachBlockWith};
|
||||
use ethcore::header::Header;
|
||||
@ -973,7 +976,7 @@ mod tests {
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
let mut header = Header::new();
|
||||
let receipts_root = ::util::triehash::ordered_trie_root(
|
||||
let receipts_root = ::triehash::ordered_trie_root(
|
||||
receipts.iter().map(|x| ::rlp::encode(x).into_vec())
|
||||
);
|
||||
|
||||
@ -1038,7 +1041,7 @@ mod tests {
|
||||
#[test]
|
||||
fn check_code() {
|
||||
let code = vec![1u8; 256];
|
||||
let code_hash = ::util::Hashable::sha3(&code);
|
||||
let code_hash = keccak(&code);
|
||||
let header = Header::new();
|
||||
let req = Code {
|
||||
header: encoded::Header::new(::rlp::encode(&header).into_vec()).into(),
|
||||
|
@ -22,7 +22,8 @@ use ethcore::header::{Header, Seal};
|
||||
use futures::Future;
|
||||
use network::{PeerId, NodeId};
|
||||
use net::*;
|
||||
use util::{H256, Mutex};
|
||||
use parking_lot::Mutex;
|
||||
use util::H256;
|
||||
use time::Duration;
|
||||
use ::request::{self as basic_request, Response};
|
||||
|
||||
|
@ -24,7 +24,8 @@ use ethcore::client::{BlockChainClient, ProvingBlockChainClient};
|
||||
use ethcore::transaction::PendingTransaction;
|
||||
use ethcore::ids::BlockId;
|
||||
use ethcore::encoded;
|
||||
use util::{RwLock, H256};
|
||||
use parking_lot::RwLock;
|
||||
use util::H256;
|
||||
|
||||
use cht::{self, BlockInfo};
|
||||
use client::{LightChainClient, AsLightClient};
|
||||
|
@ -14,3 +14,4 @@ ethcore-network = { path = "../../util/network" }
|
||||
native-contracts = { path = "../native_contracts" }
|
||||
futures = "0.1"
|
||||
log = "0.3"
|
||||
parking_lot = "0.4"
|
||||
|
@ -21,6 +21,7 @@ extern crate ethcore_util as util;
|
||||
extern crate ethcore_network as network;
|
||||
extern crate native_contracts;
|
||||
extern crate futures;
|
||||
extern crate parking_lot;
|
||||
#[cfg(test)] extern crate ethcore_io as io;
|
||||
#[macro_use] extern crate log;
|
||||
|
||||
@ -29,7 +30,8 @@ use std::collections::HashMap;
|
||||
use native_contracts::PeerSet as Contract;
|
||||
use network::{NodeId, ConnectionFilter, ConnectionDirection};
|
||||
use ethcore::client::{BlockChainClient, BlockId, ChainNotify};
|
||||
use util::{Mutex, Address, H256, Bytes};
|
||||
use util::{Address, H256, Bytes};
|
||||
use parking_lot::Mutex;
|
||||
use futures::Future;
|
||||
|
||||
const MAX_CACHE_SIZE: usize = 4096;
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
//! DB backend wrapper for Account trie
|
||||
use std::collections::HashMap;
|
||||
use hash::{KECCAK_NULL_RLP, keccak};
|
||||
use util::*;
|
||||
use rlp::NULL_RLP;
|
||||
|
||||
@ -79,7 +80,7 @@ impl<'db> AccountDB<'db> {
|
||||
/// Create a new AccountDB from an address.
|
||||
#[cfg(test)]
|
||||
pub fn new(db: &'db HashDB, address: &Address) -> Self {
|
||||
Self::from_hash(db, address.sha3())
|
||||
Self::from_hash(db, keccak(address))
|
||||
}
|
||||
|
||||
/// Create a new AcountDB from an address' hash.
|
||||
@ -97,14 +98,14 @@ impl<'db> HashDB for AccountDB<'db>{
|
||||
}
|
||||
|
||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return Some(DBValue::from_slice(&NULL_RLP));
|
||||
}
|
||||
self.db.get(&combine_key(&self.address_hash, key))
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H256) -> bool {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return true;
|
||||
}
|
||||
self.db.contains(&combine_key(&self.address_hash, key))
|
||||
@ -133,7 +134,7 @@ impl<'db> AccountDBMut<'db> {
|
||||
/// Create a new AccountDB from an address.
|
||||
#[cfg(test)]
|
||||
pub fn new(db: &'db mut HashDB, address: &Address) -> Self {
|
||||
Self::from_hash(db, address.sha3())
|
||||
Self::from_hash(db, keccak(address))
|
||||
}
|
||||
|
||||
/// Create a new AcountDB from an address' hash.
|
||||
@ -156,14 +157,14 @@ impl<'db> HashDB for AccountDBMut<'db>{
|
||||
}
|
||||
|
||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return Some(DBValue::from_slice(&NULL_RLP));
|
||||
}
|
||||
self.db.get(&combine_key(&self.address_hash, key))
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H256) -> bool {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return true;
|
||||
}
|
||||
self.db.contains(&combine_key(&self.address_hash, key))
|
||||
@ -171,16 +172,16 @@ impl<'db> HashDB for AccountDBMut<'db>{
|
||||
|
||||
fn insert(&mut self, value: &[u8]) -> H256 {
|
||||
if value == &NULL_RLP {
|
||||
return SHA3_NULL_RLP.clone();
|
||||
return KECCAK_NULL_RLP.clone();
|
||||
}
|
||||
let k = value.sha3();
|
||||
let k = keccak(value);
|
||||
let ak = combine_key(&self.address_hash, &k);
|
||||
self.db.emplace(ak, DBValue::from_slice(value));
|
||||
k
|
||||
}
|
||||
|
||||
fn emplace(&mut self, key: H256, value: DBValue) {
|
||||
if key == SHA3_NULL_RLP {
|
||||
if key == KECCAK_NULL_RLP {
|
||||
return;
|
||||
}
|
||||
let key = combine_key(&self.address_hash, &key);
|
||||
@ -188,7 +189,7 @@ impl<'db> HashDB for AccountDBMut<'db>{
|
||||
}
|
||||
|
||||
fn remove(&mut self, key: &H256) {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return;
|
||||
}
|
||||
let key = combine_key(&self.address_hash, key);
|
||||
@ -204,14 +205,14 @@ impl<'db> HashDB for Wrapping<'db> {
|
||||
}
|
||||
|
||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return Some(DBValue::from_slice(&NULL_RLP));
|
||||
}
|
||||
self.0.get(key)
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H256) -> bool {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return true;
|
||||
}
|
||||
self.0.contains(key)
|
||||
@ -238,14 +239,14 @@ impl<'db> HashDB for WrappingMut<'db>{
|
||||
}
|
||||
|
||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return Some(DBValue::from_slice(&NULL_RLP));
|
||||
}
|
||||
self.0.get(key)
|
||||
}
|
||||
|
||||
fn contains(&self, key: &H256) -> bool {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return true;
|
||||
}
|
||||
self.0.contains(key)
|
||||
@ -253,20 +254,20 @@ impl<'db> HashDB for WrappingMut<'db>{
|
||||
|
||||
fn insert(&mut self, value: &[u8]) -> H256 {
|
||||
if value == &NULL_RLP {
|
||||
return SHA3_NULL_RLP.clone();
|
||||
return KECCAK_NULL_RLP.clone();
|
||||
}
|
||||
self.0.insert(value)
|
||||
}
|
||||
|
||||
fn emplace(&mut self, key: H256, value: DBValue) {
|
||||
if key == SHA3_NULL_RLP {
|
||||
if key == KECCAK_NULL_RLP {
|
||||
return;
|
||||
}
|
||||
self.0.emplace(key, value)
|
||||
}
|
||||
|
||||
fn remove(&mut self, key: &H256) {
|
||||
if key == &SHA3_NULL_RLP {
|
||||
if key == &KECCAK_NULL_RLP {
|
||||
return;
|
||||
}
|
||||
self.0.remove(key)
|
||||
|
@ -23,7 +23,7 @@ use self::stores::{AddressBook, DappsSettingsStore, NewDappsPolicy};
|
||||
use std::fmt;
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::time::{Instant, Duration};
|
||||
use util::{RwLock};
|
||||
use parking_lot::RwLock;
|
||||
use ethstore::{
|
||||
SimpleSecretStore, SecretStore, Error as SSError, EthStore, EthMultiStore,
|
||||
random_string, SecretVaultRef, StoreAccountRef, OpaqueSecret,
|
||||
|
@ -19,9 +19,11 @@
|
||||
use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashSet;
|
||||
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP};
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
use rlp::{UntrustedRlp, RlpStream, Encodable, Decodable, DecoderError};
|
||||
use util::{Bytes, Address, Hashable, U256, H256, ordered_trie_root, SHA3_NULL_RLP, SHA3_EMPTY_LIST_RLP};
|
||||
use util::{Bytes, Address, U256, H256};
|
||||
use util::error::{Mismatch, OutOfBounds};
|
||||
|
||||
use basic_types::{LogBloom, Seal};
|
||||
@ -404,7 +406,7 @@ impl<'x> OpenBlock<'x> {
|
||||
}
|
||||
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
|
||||
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
|
||||
s.block.header.set_uncles_hash(uncle_bytes.sha3());
|
||||
s.block.header.set_uncles_hash(keccak(&uncle_bytes));
|
||||
s.block.header.set_state_root(s.block.state.root().clone());
|
||||
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
|
||||
s.block.header.set_log_bloom(s.block.receipts.iter().fold(LogBloom::zero(), |mut b, r| {b = &b | &r.log_bloom; b})); //TODO: use |= operator
|
||||
@ -429,14 +431,14 @@ impl<'x> OpenBlock<'x> {
|
||||
if let Err(e) = s.block.state.commit() {
|
||||
warn!("Encountered error on state commit: {}", e);
|
||||
}
|
||||
if s.block.header.transactions_root().is_zero() || s.block.header.transactions_root() == &SHA3_NULL_RLP {
|
||||
if s.block.header.transactions_root().is_zero() || s.block.header.transactions_root() == &KECCAK_NULL_RLP {
|
||||
s.block.header.set_transactions_root(ordered_trie_root(s.block.transactions.iter().map(|e| e.rlp_bytes().into_vec())));
|
||||
}
|
||||
let uncle_bytes = s.block.uncles.iter().fold(RlpStream::new_list(s.block.uncles.len()), |mut s, u| {s.append_raw(&u.rlp(Seal::With), 1); s} ).out();
|
||||
if s.block.header.uncles_hash().is_zero() || s.block.header.uncles_hash() == &SHA3_EMPTY_LIST_RLP {
|
||||
s.block.header.set_uncles_hash(uncle_bytes.sha3());
|
||||
if s.block.header.uncles_hash().is_zero() || s.block.header.uncles_hash() == &KECCAK_EMPTY_LIST_RLP {
|
||||
s.block.header.set_uncles_hash(keccak(&uncle_bytes));
|
||||
}
|
||||
if s.block.header.receipts_root().is_zero() || s.block.header.receipts_root() == &SHA3_NULL_RLP {
|
||||
if s.block.header.receipts_root().is_zero() || s.block.header.receipts_root() == &KECCAK_NULL_RLP {
|
||||
s.block.header.set_receipts_root(ordered_trie_root(s.block.receipts.iter().map(|r| r.rlp_bytes().into_vec())));
|
||||
}
|
||||
|
||||
@ -469,7 +471,7 @@ impl<'x> IsBlock for LockedBlock {
|
||||
|
||||
impl ClosedBlock {
|
||||
/// Get the hash of the header without seal arguments.
|
||||
pub fn hash(&self) -> H256 { self.header().rlp_sha3(Seal::Without) }
|
||||
pub fn hash(&self) -> H256 { self.header().rlp_keccak(Seal::Without) }
|
||||
|
||||
/// Turn this into a `LockedBlock`, unable to be reopened again.
|
||||
pub fn lock(self) -> LockedBlock {
|
||||
@ -494,7 +496,7 @@ impl ClosedBlock {
|
||||
|
||||
impl LockedBlock {
|
||||
/// Get the hash of the header without seal arguments.
|
||||
pub fn hash(&self) -> H256 { self.header().rlp_sha3(Seal::Without) }
|
||||
pub fn hash(&self) -> H256 { self.header().rlp_keccak(Seal::Without) }
|
||||
|
||||
/// Provide a valid seal in order to turn this into a `SealedBlock`.
|
||||
///
|
||||
|
@ -22,6 +22,7 @@ use std::mem;
|
||||
use itertools::Itertools;
|
||||
use bloomchain as bc;
|
||||
use heapsize::HeapSizeOf;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use header::*;
|
||||
@ -41,6 +42,7 @@ use db::{self, Writable, Readable, CacheUpdatePolicy};
|
||||
use cache_manager::CacheManager;
|
||||
use encoded;
|
||||
use engines::epoch::{Transition as EpochTransition, PendingTransition as PendingEpochTransition};
|
||||
use ansi_term::Colour;
|
||||
|
||||
const LOG_BLOOMS_LEVELS: usize = 3;
|
||||
const LOG_BLOOMS_ELEMENTS_PER_INDEX: usize = 16;
|
||||
@ -512,7 +514,7 @@ impl BlockChain {
|
||||
// we need to insert genesis into the cache
|
||||
let block = BlockView::new(genesis);
|
||||
let header = block.header_view();
|
||||
let hash = block.sha3();
|
||||
let hash = block.hash();
|
||||
|
||||
let details = BlockDetails {
|
||||
number: header.number(),
|
||||
@ -764,7 +766,7 @@ impl BlockChain {
|
||||
pub fn insert_unordered_block(&self, batch: &mut DBTransaction, bytes: &[u8], receipts: Vec<Receipt>, parent_td: Option<U256>, is_best: bool, is_ancient: bool) -> bool {
|
||||
let block = BlockView::new(bytes);
|
||||
let header = block.header_view();
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
|
||||
if self.is_known(&hash) {
|
||||
return false;
|
||||
@ -966,7 +968,7 @@ impl BlockChain {
|
||||
// create views onto rlp
|
||||
let block = BlockView::new(bytes);
|
||||
let header = block.header_view();
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
|
||||
if self.is_known_child(&header.parent_hash(), &hash) {
|
||||
return ImportRoute::none();
|
||||
@ -1005,7 +1007,7 @@ impl BlockChain {
|
||||
|
||||
/// Get inserted block info which is critical to prepare extras updates.
|
||||
fn block_info(&self, header: &HeaderView) -> BlockInfo {
|
||||
let hash = header.sha3();
|
||||
let hash = header.hash();
|
||||
let number = header.number();
|
||||
let parent_hash = header.parent_hash();
|
||||
let parent_details = self.block_details(&parent_hash).unwrap_or_else(|| panic!("Invalid parent hash: {:?}", parent_hash));
|
||||
@ -1466,9 +1468,9 @@ mod tests {
|
||||
#![cfg_attr(feature="dev", allow(similar_names))]
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use util::kvdb::KeyValueDB;
|
||||
use util::hash::*;
|
||||
use util::sha3::Hashable;
|
||||
use receipt::Receipt;
|
||||
use blockchain::{BlockProvider, BlockChain, Config, ImportRoute};
|
||||
use tests::helpers::*;
|
||||
@ -1518,8 +1520,8 @@ mod tests {
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@ -1549,7 +1551,7 @@ mod tests {
|
||||
let mut canon_chain = ChainGenerator::default();
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@ -1558,7 +1560,7 @@ mod tests {
|
||||
let mut batch = db.transaction();
|
||||
for _ in 0..10 {
|
||||
let block = canon_chain.generate(&mut finalizer).unwrap();
|
||||
block_hashes.push(BlockView::new(&block).header_view().sha3());
|
||||
block_hashes.push(BlockView::new(&block).header_view().hash());
|
||||
bc.insert_block(&mut batch, &block, vec![]);
|
||||
bc.commit();
|
||||
}
|
||||
@ -1607,14 +1609,14 @@ mod tests {
|
||||
|
||||
assert_eq!(
|
||||
[&b4b, &b3b, &b2b].iter().map(|b| BlockView::new(b).header()).collect::<Vec<_>>(),
|
||||
bc.find_uncle_headers(&BlockView::new(&b4a).header_view().sha3(), 3).unwrap()
|
||||
bc.find_uncle_headers(&BlockView::new(&b4a).header_view().hash(), 3).unwrap()
|
||||
);
|
||||
|
||||
// TODO: insert block that already includes one of them as an uncle to check it's not allowed.
|
||||
}
|
||||
|
||||
fn secret() -> Secret {
|
||||
"".sha3().into()
|
||||
keccak("").into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -1646,8 +1648,8 @@ mod tests {
|
||||
let b2 = fork_chain
|
||||
.generate(&mut fork_finalizer).unwrap();
|
||||
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().sha3();
|
||||
let b2_hash = BlockView::new(&b2).header_view().sha3();
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().hash();
|
||||
let b2_hash = BlockView::new(&b2).header_view().hash();
|
||||
|
||||
let t1_hash = t1.hash();
|
||||
|
||||
@ -1730,9 +1732,9 @@ mod tests {
|
||||
.with_transaction(t3.clone())
|
||||
.generate(&mut fork_finalizer).unwrap();
|
||||
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().sha3();
|
||||
let b1b_hash = BlockView::new(&b1b).header_view().sha3();
|
||||
let b2_hash = BlockView::new(&b2).header_view().sha3();
|
||||
let b1a_hash = BlockView::new(&b1a).header_view().hash();
|
||||
let b1b_hash = BlockView::new(&b1b).header_view().hash();
|
||||
let b2_hash = BlockView::new(&b2).header_view().hash();
|
||||
|
||||
let t1_hash = t1.hash();
|
||||
let t2_hash = t2.hash();
|
||||
@ -1790,11 +1792,11 @@ mod tests {
|
||||
let b3b = canon_chain.fork(1).generate(&mut finalizer.fork()).unwrap();
|
||||
let b3a = canon_chain.generate(&mut finalizer).unwrap();
|
||||
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let b1_hash= BlockView::new(&b1).header_view().sha3();
|
||||
let b2_hash= BlockView::new(&b2).header_view().sha3();
|
||||
let b3a_hash= BlockView::new(&b3a).header_view().sha3();
|
||||
let b3b_hash= BlockView::new(&b3b).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let b1_hash= BlockView::new(&b1).header_view().hash();
|
||||
let b2_hash= BlockView::new(&b2).header_view().hash();
|
||||
let b3a_hash= BlockView::new(&b3a).header_view().hash();
|
||||
let b3b_hash= BlockView::new(&b3b).header_view().hash();
|
||||
|
||||
// b3a is a part of canon chain, whereas b3b is part of sidechain
|
||||
let best_block_hash = b3a_hash.clone();
|
||||
@ -1910,8 +1912,8 @@ mod tests {
|
||||
let mut finalizer = BlockFinalizer::default();
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
let db = new_db();
|
||||
|
||||
{
|
||||
@ -2226,9 +2228,9 @@ mod tests {
|
||||
let genesis = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let first = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let second = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().sha3();
|
||||
let first_hash = BlockView::new(&first).header_view().sha3();
|
||||
let second_hash = BlockView::new(&second).header_view().sha3();
|
||||
let genesis_hash = BlockView::new(&genesis).header_view().hash();
|
||||
let first_hash = BlockView::new(&first).header_view().hash();
|
||||
let second_hash = BlockView::new(&second).header_view().hash();
|
||||
|
||||
let db = new_db();
|
||||
let bc = new_chain(&genesis, db.clone());
|
||||
@ -2266,7 +2268,7 @@ mod tests {
|
||||
// create a longer fork
|
||||
for i in 0..5 {
|
||||
let canon_block = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let hash = BlockView::new(&canon_block).header_view().sha3();
|
||||
let hash = BlockView::new(&canon_block).header_view().hash();
|
||||
|
||||
bc.insert_block(&mut batch, &canon_block, vec![]);
|
||||
bc.insert_epoch_transition(&mut batch, i, EpochTransition {
|
||||
@ -2279,7 +2281,7 @@ mod tests {
|
||||
|
||||
assert_eq!(bc.best_block_number(), 5);
|
||||
|
||||
let hash = BlockView::new(&uncle).header_view().sha3();
|
||||
let hash = BlockView::new(&uncle).header_view().hash();
|
||||
bc.insert_block(&mut batch, &uncle, vec![]);
|
||||
bc.insert_epoch_transition(&mut batch, 999, EpochTransition {
|
||||
block_hash: hash,
|
||||
|
@ -16,7 +16,6 @@
|
||||
|
||||
use util::hash::H256;
|
||||
use util::bytes::Bytes;
|
||||
use util::sha3::Hashable;
|
||||
use views::BlockView;
|
||||
|
||||
#[derive(Default, Clone)]
|
||||
@ -46,7 +45,7 @@ impl<'a, I> Iterator for Complete<'a, I> where I: Iterator, <I as Iterator>::Ite
|
||||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.iter.next().map(|item| {
|
||||
let rlp = item.complete(self.finalizer.parent_hash.clone());
|
||||
self.finalizer.parent_hash = BlockView::new(&rlp).header_view().sha3();
|
||||
self.finalizer.parent_hash = BlockView::new(&rlp).header_view().hash();
|
||||
rlp
|
||||
})
|
||||
}
|
||||
|
@ -111,7 +111,6 @@ impl Iterator for ChainGenerator {
|
||||
|
||||
mod tests {
|
||||
use util::hash::{H256, H2048};
|
||||
use util::sha3::Hashable;
|
||||
use views::BlockView;
|
||||
use blockchain::generator::{ChainIterator, ChainGenerator, BlockFinalizer};
|
||||
|
||||
@ -129,7 +128,7 @@ mod tests {
|
||||
let b1_rlp = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let b1 = BlockView::new(&b1_rlp);
|
||||
|
||||
assert_eq!(b1.header_view().parent_hash(), genesis.header_view().sha3());
|
||||
assert_eq!(b1.header_view().parent_hash(), genesis.header_view().hash());
|
||||
assert_eq!(b1.header_view().number(), 1);
|
||||
|
||||
let mut fork_chain = canon_chain.fork(1);
|
||||
@ -137,13 +136,13 @@ mod tests {
|
||||
let b2_rlp_fork = fork_chain.generate(&mut finalizer.fork()).unwrap();
|
||||
let b2_fork = BlockView::new(&b2_rlp_fork);
|
||||
|
||||
assert_eq!(b2_fork.header_view().parent_hash(), b1.header_view().sha3());
|
||||
assert_eq!(b2_fork.header_view().parent_hash(), b1.header_view().hash());
|
||||
assert_eq!(b2_fork.header_view().number(), 2);
|
||||
|
||||
let b2_rlp = canon_chain.generate(&mut finalizer).unwrap();
|
||||
let b2 = BlockView::new(&b2_rlp);
|
||||
|
||||
assert_eq!(b2.header_view().parent_hash(), b1.header_view().sha3());
|
||||
assert_eq!(b2.header_view().parent_hash(), b1.header_view().hash());
|
||||
assert_eq!(b2.header_view().number(), 2);
|
||||
assert!(b2.header_view().difficulty() > b2_fork.header_view().difficulty());
|
||||
}
|
||||
@ -163,7 +162,7 @@ mod tests {
|
||||
assert_eq!(block0.header_view().parent_hash(), H256::default());
|
||||
|
||||
assert_eq!(block1.header_view().number(), 1);
|
||||
assert_eq!(block1.header_view().parent_hash(), block0.header_view().sha3());
|
||||
assert_eq!(block1.header_view().parent_hash(), block0.header_view().hash());
|
||||
|
||||
}
|
||||
|
||||
|
@ -23,7 +23,8 @@ use crypto::ripemd160::Ripemd160 as Ripemd160Digest;
|
||||
use crypto::digest::Digest;
|
||||
use num::{BigUint, Zero, One};
|
||||
|
||||
use util::{U256, H256, Hashable, BytesRef};
|
||||
use hash::keccak;
|
||||
use util::{U256, H256, BytesRef};
|
||||
use ethkey::{Signature, recover as ec_recover};
|
||||
use ethjson;
|
||||
|
||||
@ -228,7 +229,7 @@ impl Impl for EcRecover {
|
||||
let s = Signature::from_rsv(&r, &s, bit);
|
||||
if s.is_valid() {
|
||||
if let Ok(p) = ec_recover(&s, &hash) {
|
||||
let r = p.sha3();
|
||||
let r = keccak(p);
|
||||
output.write(0, &[0; 12]);
|
||||
output.write(12, &r[12..r.len()]);
|
||||
}
|
||||
@ -266,6 +267,34 @@ impl Impl for Ripemd160 {
|
||||
}
|
||||
}
|
||||
|
||||
// calculate modexp: exponentiation by squaring. the `num` crate has pow, but not modular.
|
||||
fn modexp(mut base: BigUint, mut exp: BigUint, modulus: BigUint) -> BigUint {
|
||||
use num::Integer;
|
||||
|
||||
match (base.is_zero(), exp.is_zero()) {
|
||||
(_, true) => return BigUint::one(), // n^0 % m
|
||||
(true, false) => return BigUint::zero(), // 0^n % m, n>0
|
||||
(false, false) if modulus <= BigUint::one() => return BigUint::zero(), // a^b % 1 = 0.
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let mut result = BigUint::one();
|
||||
base = base % &modulus;
|
||||
|
||||
// fast path for base divisible by modulus.
|
||||
if base.is_zero() { return BigUint::zero() }
|
||||
while !exp.is_zero() {
|
||||
if exp.is_odd() {
|
||||
result = (result * &base) % &modulus;
|
||||
}
|
||||
|
||||
exp = exp >> 1;
|
||||
base = (base.clone() * base) % &modulus;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
impl Impl for ModexpImpl {
|
||||
fn execute(&self, input: &[u8], output: &mut BytesRef) -> Result<(), Error> {
|
||||
let mut reader = input.chain(io::repeat(0));
|
||||
@ -294,34 +323,6 @@ impl Impl for ModexpImpl {
|
||||
let exp = read_num(exp_len);
|
||||
let modulus = read_num(mod_len);
|
||||
|
||||
// calculate modexp: exponentiation by squaring. the `num` crate has pow, but not modular.
|
||||
fn modexp(mut base: BigUint, mut exp: BigUint, modulus: BigUint) -> BigUint {
|
||||
use num::Integer;
|
||||
|
||||
match (base.is_zero(), exp.is_zero()) {
|
||||
(_, true) => return BigUint::one(), // n^0 % m
|
||||
(true, false) => return BigUint::zero(), // 0^n % m, n>0
|
||||
(false, false) if modulus <= BigUint::one() => return BigUint::zero(), // a^b % 1 = 0.
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let mut result = BigUint::one();
|
||||
base = base % &modulus;
|
||||
|
||||
// fast path for base divisible by modulus.
|
||||
if base.is_zero() { return result }
|
||||
while !exp.is_zero() {
|
||||
if exp.is_odd() {
|
||||
result = (result * &base) % &modulus;
|
||||
}
|
||||
|
||||
exp = exp >> 1;
|
||||
base = (base.clone() * base) % &modulus;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
|
||||
// write output to given memory, left padded and same length as the modulus.
|
||||
let bytes = modexp(base, exp, modulus).to_bytes_be();
|
||||
|
||||
@ -503,10 +504,44 @@ impl Impl for Bn128PairingImpl {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp};
|
||||
use super::{Builtin, Linear, ethereum_builtin, Pricer, Modexp, modexp as me};
|
||||
use ethjson;
|
||||
use util::{U256, BytesRef};
|
||||
use rustc_hex::FromHex;
|
||||
use num::{BigUint, Zero, One};
|
||||
|
||||
#[test]
|
||||
fn modexp_func() {
|
||||
// n^0 % m == 1
|
||||
let mut base = BigUint::parse_bytes(b"12345", 10).unwrap();
|
||||
let mut exp = BigUint::zero();
|
||||
let mut modulus = BigUint::parse_bytes(b"789", 10).unwrap();
|
||||
assert_eq!(me(base, exp, modulus), BigUint::one());
|
||||
|
||||
// 0^n % m == 0
|
||||
base = BigUint::zero();
|
||||
exp = BigUint::parse_bytes(b"12345", 10).unwrap();
|
||||
modulus = BigUint::parse_bytes(b"789", 10).unwrap();
|
||||
assert_eq!(me(base, exp, modulus), BigUint::zero());
|
||||
|
||||
// n^m % 1 == 0
|
||||
base = BigUint::parse_bytes(b"12345", 10).unwrap();
|
||||
exp = BigUint::parse_bytes(b"789", 10).unwrap();
|
||||
modulus = BigUint::one();
|
||||
assert_eq!(me(base, exp, modulus), BigUint::zero());
|
||||
|
||||
// if n % d == 0, then n^m % d == 0
|
||||
base = BigUint::parse_bytes(b"12345", 10).unwrap();
|
||||
exp = BigUint::parse_bytes(b"789", 10).unwrap();
|
||||
modulus = BigUint::parse_bytes(b"15", 10).unwrap();
|
||||
assert_eq!(me(base, exp, modulus), BigUint::zero());
|
||||
|
||||
// others
|
||||
base = BigUint::parse_bytes(b"12345", 10).unwrap();
|
||||
exp = BigUint::parse_bytes(b"789", 10).unwrap();
|
||||
modulus = BigUint::parse_bytes(b"97", 10).unwrap();
|
||||
assert_eq!(me(base, exp, modulus), BigUint::parse_bytes(b"55", 10).unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn identity() {
|
||||
@ -572,14 +607,6 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn ecrecover() {
|
||||
/*let k = KeyPair::from_secret(b"test".sha3()).unwrap();
|
||||
let a: Address = From::from(k.public().sha3());
|
||||
println!("Address: {}", a);
|
||||
let m = b"hello world".sha3();
|
||||
println!("Message: {}", m);
|
||||
let s = k.sign(&m).unwrap();
|
||||
println!("Signed: {}", s);*/
|
||||
|
||||
let f = ethereum_builtin("ecrecover");
|
||||
|
||||
let i = FromHex::from_hex("47173285a8d7341e5e972fc677286384f802f8ef42a5ec5f03bbfa254cb01fad000000000000000000000000000000000000000000000000000000000000001b650acf9d3f5f0a2c799776a1254355d5f4061762a237396a99a0e0e3fc2bcd6729514a0dacb2e623ac4abd157cb18163ff942280db4d5caad66ddf941ba12e03").unwrap();
|
||||
|
@ -23,7 +23,7 @@ use engines::{Engine, EpochVerifier};
|
||||
use header::Header;
|
||||
|
||||
use rand::Rng;
|
||||
use util::RwLock;
|
||||
use parking_lot::RwLock;
|
||||
|
||||
// do "heavy" verification on ~1/50 blocks, randomly sampled.
|
||||
const HEAVY_VERIFY_RATE: f32 = 0.02;
|
||||
|
@ -23,7 +23,9 @@ use time::precise_time_ns;
|
||||
use itertools::Itertools;
|
||||
|
||||
// util
|
||||
use util::{Bytes, PerfTimer, Mutex, RwLock, MutexGuard, Hashable};
|
||||
use hash::keccak;
|
||||
use timer::PerfTimer;
|
||||
use util::Bytes;
|
||||
use util::{journaldb, DBValue, TrieFactory, Trie};
|
||||
use util::{U256, H256, Address, H2048};
|
||||
use util::trie::TrieSpec;
|
||||
@ -54,6 +56,7 @@ use io::*;
|
||||
use log_entry::LocalizedLogEntry;
|
||||
use miner::{Miner, MinerService, TransactionImportResult};
|
||||
use native_contracts::Registry;
|
||||
use parking_lot::{Mutex, RwLock, MutexGuard};
|
||||
use rand::OsRng;
|
||||
use receipt::{Receipt, LocalizedReceipt};
|
||||
use rlp::UntrustedRlp;
|
||||
@ -652,7 +655,7 @@ impl Client {
|
||||
.map(Into::into)
|
||||
.collect();
|
||||
|
||||
assert_eq!(header.hash(), BlockView::new(block_data).header_view().sha3());
|
||||
assert_eq!(header.hash(), BlockView::new(block_data).header_view().hash());
|
||||
|
||||
//let traces = From::from(block.traces().clone().unwrap_or_else(Vec::new));
|
||||
|
||||
@ -1503,7 +1506,7 @@ impl BlockChainClient for Client {
|
||||
};
|
||||
|
||||
let (_, db) = state.drop();
|
||||
let account_db = self.factories.accountdb.readonly(db.as_hashdb(), account.sha3());
|
||||
let account_db = self.factories.accountdb.readonly(db.as_hashdb(), keccak(account));
|
||||
let trie = match self.factories.trie.readonly(account_db.as_hashdb(), &root) {
|
||||
Ok(trie) => trie,
|
||||
_ => {
|
||||
@ -1591,7 +1594,7 @@ impl BlockChainClient for Client {
|
||||
use verification::queue::kind::BlockLike;
|
||||
use verification::queue::kind::blocks::Unverified;
|
||||
|
||||
// create unverified block here so the `sha3` calculation can be cached.
|
||||
// create unverified block here so the `keccak` calculation can be cached.
|
||||
let unverified = Unverified::new(bytes);
|
||||
|
||||
{
|
||||
@ -1792,7 +1795,7 @@ impl BlockChainClient for Client {
|
||||
let dispatch = move |reg_addr, data| {
|
||||
future::done(self.call_contract(BlockId::Latest, reg_addr, data))
|
||||
};
|
||||
r.get_address(dispatch, name.as_bytes().sha3(), "A".to_string()).wait().ok()
|
||||
r.get_address(dispatch, keccak(name.as_bytes()), "A".to_string()).wait().ok()
|
||||
})
|
||||
.and_then(|a| if a.is_zero() { None } else { Some(a) })
|
||||
}
|
||||
@ -2085,16 +2088,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn should_return_correct_log_index() {
|
||||
use hash::keccak;
|
||||
use super::transaction_receipt;
|
||||
use ethkey::KeyPair;
|
||||
use log_entry::{LogEntry, LocalizedLogEntry};
|
||||
use receipt::{Receipt, LocalizedReceipt};
|
||||
use transaction::{Transaction, LocalizedTransaction, Action};
|
||||
use util::Hashable;
|
||||
use tests::helpers::TestEngine;
|
||||
|
||||
// given
|
||||
let key = KeyPair::from_secret_slice(&"test".sha3()).unwrap();
|
||||
let key = KeyPair::from_secret_slice(&keccak("test")).unwrap();
|
||||
let secret = key.secret();
|
||||
let engine = TestEngine::new(0);
|
||||
|
||||
|
@ -22,6 +22,8 @@ use std::collections::{HashMap, BTreeMap};
|
||||
use std::mem;
|
||||
use itertools::Itertools;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use ethkey::{Generator, Random};
|
||||
@ -241,7 +243,7 @@ impl TestBlockChainClient {
|
||||
uncle_header.set_parent_hash(self.last_hash.read().clone());
|
||||
uncle_header.set_number(n as BlockNumber);
|
||||
uncles.append(&uncle_header);
|
||||
header.set_uncles_hash(uncles.as_raw().sha3());
|
||||
header.set_uncles_hash(keccak(uncles.as_raw()));
|
||||
uncles
|
||||
},
|
||||
_ => RlpStream::new_list(0)
|
||||
|
@ -19,7 +19,8 @@
|
||||
use std::ops::Deref;
|
||||
use std::hash::Hash;
|
||||
use std::collections::HashMap;
|
||||
use util::{DBTransaction, KeyValueDB, RwLock};
|
||||
use parking_lot::RwLock;
|
||||
use util::{DBTransaction, KeyValueDB};
|
||||
|
||||
use rlp;
|
||||
|
||||
|
@ -28,8 +28,9 @@ use header::{BlockNumber, Header as FullHeader};
|
||||
use transaction::UnverifiedTransaction;
|
||||
use views;
|
||||
|
||||
use hash::keccak;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{Address, Hashable, H256, H2048, U256};
|
||||
use util::{Address, H256, H2048, U256};
|
||||
use rlp::Rlp;
|
||||
|
||||
/// Owning header view.
|
||||
@ -65,7 +66,7 @@ impl Header {
|
||||
// forwarders to borrowed view.
|
||||
impl Header {
|
||||
/// Returns the header hash.
|
||||
pub fn hash(&self) -> H256 { self.sha3() }
|
||||
pub fn hash(&self) -> H256 { keccak(&self.0) }
|
||||
|
||||
/// Returns the parent hash.
|
||||
pub fn parent_hash(&self) -> H256 { self.view().parent_hash() }
|
||||
@ -110,12 +111,6 @@ impl Header {
|
||||
pub fn seal(&self) -> Vec<Vec<u8>> { self.view().seal() }
|
||||
}
|
||||
|
||||
impl Hashable for Header {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.0.sha3()
|
||||
}
|
||||
}
|
||||
|
||||
/// Owning block body view.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[cfg_attr(feature = "ipc", binary)]
|
||||
@ -219,7 +214,7 @@ impl Block {
|
||||
// forwarders to borrowed header view.
|
||||
impl Block {
|
||||
/// Returns the header hash.
|
||||
pub fn hash(&self) -> H256 { self.header_view().sha3() }
|
||||
pub fn hash(&self) -> H256 { self.header_view().hash() }
|
||||
|
||||
/// Returns the parent hash.
|
||||
pub fn parent_hash(&self) -> H256 { self.header_view().parent_hash() }
|
||||
|
@ -42,6 +42,8 @@ use ethkey::{verify_address, Signature};
|
||||
use io::{IoContext, IoHandler, TimerToken, IoService};
|
||||
use itertools::{self, Itertools};
|
||||
use rlp::{UntrustedRlp, encode};
|
||||
use semantic_version::SemanticVersion;
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use util::*;
|
||||
|
||||
mod finality;
|
||||
@ -837,6 +839,7 @@ impl Engine for AuthorityRound {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use header::Header;
|
||||
use error::{Error, BlockError};
|
||||
@ -891,8 +894,8 @@ mod tests {
|
||||
#[test]
|
||||
fn generates_seal_and_does_not_double_propose() {
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let addr1 = tap.insert_account("1".sha3().into(), "1").unwrap();
|
||||
let addr2 = tap.insert_account("2".sha3().into(), "2").unwrap();
|
||||
let addr1 = tap.insert_account(keccak("1").into(), "1").unwrap();
|
||||
let addr2 = tap.insert_account(keccak("2").into(), "2").unwrap();
|
||||
|
||||
let spec = Spec::new_test_round();
|
||||
let engine = &*spec.engine;
|
||||
@ -923,7 +926,7 @@ mod tests {
|
||||
#[test]
|
||||
fn proposer_switching() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
|
||||
let addr = tap.insert_account(keccak("0").into(), "0").unwrap();
|
||||
let mut parent_header: Header = Header::default();
|
||||
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
|
||||
parent_header.set_gas_limit("222222".parse::<U256>().unwrap());
|
||||
@ -948,7 +951,7 @@ mod tests {
|
||||
#[test]
|
||||
fn rejects_future_block() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
|
||||
let addr = tap.insert_account(keccak("0").into(), "0").unwrap();
|
||||
|
||||
let mut parent_header: Header = Header::default();
|
||||
parent_header.set_seal(vec![encode(&0usize).into_vec()]);
|
||||
@ -974,7 +977,7 @@ mod tests {
|
||||
#[test]
|
||||
fn rejects_step_backwards() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
|
||||
let addr = tap.insert_account(keccak("0").into(), "0").unwrap();
|
||||
|
||||
let mut parent_header: Header = Header::default();
|
||||
parent_header.set_seal(vec![encode(&4usize).into_vec()]);
|
||||
|
@ -19,6 +19,7 @@
|
||||
use std::sync::{Weak, Arc};
|
||||
use std::collections::BTreeMap;
|
||||
use std::cmp;
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
use ethkey::{recover, public_to_address, Signature};
|
||||
use account_provider::AccountProvider;
|
||||
@ -31,6 +32,7 @@ use evm::Schedule;
|
||||
use ethjson;
|
||||
use header::{Header, BlockNumber};
|
||||
use client::EngineClient;
|
||||
use semantic_version::SemanticVersion;
|
||||
use super::signer::EngineSigner;
|
||||
use super::validator_set::{ValidatorSet, SimpleList, new_validator_set};
|
||||
|
||||
@ -252,6 +254,7 @@ impl Engine for BasicAuthority {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use block::*;
|
||||
use error::{BlockError, Error};
|
||||
@ -308,7 +311,7 @@ mod tests {
|
||||
#[test]
|
||||
fn can_generate_seal() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let addr = tap.insert_account("".sha3().into(), "").unwrap();
|
||||
let addr = tap.insert_account(keccak("").into(), "").unwrap();
|
||||
|
||||
let spec = new_test_authority();
|
||||
let engine = &*spec.engine;
|
||||
@ -326,7 +329,7 @@ mod tests {
|
||||
#[test]
|
||||
fn seals_internally() {
|
||||
let tap = AccountProvider::transient_provider();
|
||||
let authority = tap.insert_account("".sha3().into(), "").unwrap();
|
||||
let authority = tap.insert_account(keccak("").into(), "").unwrap();
|
||||
|
||||
let engine = new_test_authority().engine;
|
||||
assert!(!engine.seals_internally().unwrap());
|
||||
|
@ -54,6 +54,7 @@ use spec::CommonParams;
|
||||
use transaction::{UnverifiedTransaction, SignedTransaction};
|
||||
|
||||
use ethkey::Signature;
|
||||
use semantic_version::SemanticVersion;
|
||||
use util::*;
|
||||
|
||||
/// Default EIP-210 contrat code.
|
||||
|
@ -17,6 +17,7 @@
|
||||
//! Tendermint message handling.
|
||||
|
||||
use std::cmp;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use super::{Height, View, BlockHash, Step};
|
||||
use error::Error;
|
||||
@ -99,7 +100,7 @@ impl ConsensusMessage {
|
||||
pub fn verify(&self) -> Result<Address, Error> {
|
||||
let full_rlp = ::rlp::encode(self);
|
||||
let block_info = Rlp::new(&full_rlp).at(1);
|
||||
let public_key = recover(&self.signature.into(), &block_info.as_raw().sha3())?;
|
||||
let public_key = recover(&self.signature.into(), &keccak(block_info.as_raw()))?;
|
||||
Ok(public_to_address(&public_key))
|
||||
}
|
||||
}
|
||||
@ -194,12 +195,13 @@ pub fn message_full_rlp(signature: &H520, vote_info: &Bytes) -> Bytes {
|
||||
}
|
||||
|
||||
pub fn message_hash(vote_step: VoteStep, block_hash: H256) -> H256 {
|
||||
message_info_rlp(&vote_step, Some(block_hash)).sha3()
|
||||
keccak(message_info_rlp(&vote_step, Some(block_hash)))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use account_provider::AccountProvider;
|
||||
@ -228,7 +230,7 @@ mod tests {
|
||||
view: 123,
|
||||
step: Step::Precommit,
|
||||
},
|
||||
block_hash: Some("1".sha3())
|
||||
block_hash: Some(keccak("1")),
|
||||
};
|
||||
let raw_rlp = ::rlp::encode(&message).into_vec();
|
||||
let rlp = Rlp::new(&raw_rlp);
|
||||
@ -251,12 +253,12 @@ mod tests {
|
||||
#[test]
|
||||
fn generate_and_verify() {
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let addr = tap.insert_account("0".sha3().into(), "0").unwrap();
|
||||
let addr = tap.insert_account(keccak("0").into(), "0").unwrap();
|
||||
tap.unlock_account_permanently(addr, "0".into()).unwrap();
|
||||
|
||||
let mi = message_info_rlp(&VoteStep::new(123, 2, Step::Precommit), Some(H256::default()));
|
||||
|
||||
let raw_rlp = message_full_rlp(&tap.sign(addr, None, mi.sha3()).unwrap().into(), &mi);
|
||||
let raw_rlp = message_full_rlp(&tap.sign(addr, None, keccak(&mi)).unwrap().into(), &mi);
|
||||
|
||||
let rlp = UntrustedRlp::new(&raw_rlp);
|
||||
let message: ConsensusMessage = rlp.as_val().unwrap();
|
||||
|
@ -28,7 +28,9 @@ mod params;
|
||||
use std::sync::{Weak, Arc};
|
||||
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
|
||||
use std::collections::{HashSet, BTreeMap, HashMap};
|
||||
use hash::keccak;
|
||||
use std::cmp;
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
use client::EngineClient;
|
||||
use error::{Error, BlockError};
|
||||
@ -47,6 +49,7 @@ use super::transition::TransitionHandler;
|
||||
use super::vote_collector::VoteCollector;
|
||||
use self::message::*;
|
||||
use self::params::TendermintParams;
|
||||
use semantic_version::SemanticVersion;
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
|
||||
pub enum Step {
|
||||
@ -213,7 +216,7 @@ impl Tendermint {
|
||||
let r = self.view.load(AtomicOrdering::SeqCst);
|
||||
let s = *self.step.read();
|
||||
let vote_info = message_info_rlp(&VoteStep::new(h, r, s), block_hash);
|
||||
match (self.signer.read().address(), self.sign(vote_info.sha3()).map(Into::into)) {
|
||||
match (self.signer.read().address(), self.sign(keccak(&vote_info)).map(Into::into)) {
|
||||
(Some(validator), Ok(signature)) => {
|
||||
let message_rlp = message_full_rlp(&signature, &vote_info);
|
||||
let message = ConsensusMessage::new(signature, h, r, s, block_hash);
|
||||
@ -498,7 +501,7 @@ impl Engine for Tendermint {
|
||||
let view = self.view.load(AtomicOrdering::SeqCst);
|
||||
let bh = Some(header.bare_hash());
|
||||
let vote_info = message_info_rlp(&VoteStep::new(height, view, Step::Propose), bh.clone());
|
||||
if let Ok(signature) = self.sign(vote_info.sha3()).map(Into::into) {
|
||||
if let Ok(signature) = self.sign(keccak(&vote_info)).map(Into::into) {
|
||||
// Insert Propose vote.
|
||||
debug!(target: "engine", "Submitting proposal {} at height {} view {}.", header.bare_hash(), height, view);
|
||||
self.votes.vote(ConsensusMessage::new(signature, height, view, Step::Propose, bh), author);
|
||||
@ -522,7 +525,7 @@ impl Engine for Tendermint {
|
||||
let rlp = UntrustedRlp::new(rlp);
|
||||
let message: ConsensusMessage = rlp.as_val()?;
|
||||
if !self.votes.is_old_or_known(&message) {
|
||||
let sender = public_to_address(&recover(&message.signature.into(), &rlp.at(1)?.as_raw().sha3())?);
|
||||
let sender = public_to_address(&recover(&message.signature.into(), &keccak(rlp.at(1)?.as_raw()))?);
|
||||
if !self.is_authority(&sender) {
|
||||
return Err(EngineError::NotAuthorized(sender).into());
|
||||
}
|
||||
@ -804,7 +807,7 @@ mod tests {
|
||||
|
||||
fn vote<F>(engine: &Engine, signer: F, height: usize, view: usize, step: Step, block_hash: Option<H256>) -> Bytes where F: FnOnce(H256) -> Result<H520, ::account_provider::SignError> {
|
||||
let mi = message_info_rlp(&VoteStep::new(height, view, step), block_hash);
|
||||
let m = message_full_rlp(&signer(mi.sha3()).unwrap().into(), &mi);
|
||||
let m = message_full_rlp(&signer(keccak(&mi)).unwrap().into(), &mi);
|
||||
engine.handle_message(&m).unwrap();
|
||||
m
|
||||
}
|
||||
@ -812,7 +815,7 @@ mod tests {
|
||||
fn proposal_seal(tap: &Arc<AccountProvider>, header: &Header, view: View) -> Vec<Bytes> {
|
||||
let author = header.author();
|
||||
let vote_info = message_info_rlp(&VoteStep::new(header.number() as Height, view, Step::Propose), Some(header.bare_hash()));
|
||||
let signature = tap.sign(*author, None, vote_info.sha3()).unwrap();
|
||||
let signature = tap.sign(*author, None, keccak(vote_info)).unwrap();
|
||||
vec![
|
||||
::rlp::encode(&view).into_vec(),
|
||||
::rlp::encode(&H520::from(signature)).into_vec(),
|
||||
@ -821,7 +824,7 @@ mod tests {
|
||||
}
|
||||
|
||||
fn insert_and_unlock(tap: &Arc<AccountProvider>, acc: &str) -> Address {
|
||||
let addr = tap.insert_account(acc.sha3().into(), acc).unwrap();
|
||||
let addr = tap.insert_account(keccak(acc).into(), acc).unwrap();
|
||||
tap.unlock_account_permanently(addr, acc.into()).unwrap();
|
||||
addr
|
||||
}
|
||||
@ -928,7 +931,7 @@ mod tests {
|
||||
let mut seal = proposal_seal(&tap, &header, 0);
|
||||
|
||||
let vote_info = message_info_rlp(&VoteStep::new(2, 0, Step::Precommit), Some(header.bare_hash()));
|
||||
let signature1 = tap.sign(proposer, None, vote_info.sha3()).unwrap();
|
||||
let signature1 = tap.sign(proposer, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
seal[1] = ::rlp::NULL_RLP.to_vec();
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]).into_vec();
|
||||
@ -941,7 +944,7 @@ mod tests {
|
||||
}
|
||||
|
||||
let voter = insert_and_unlock(&tap, "0");
|
||||
let signature0 = tap.sign(voter, None, vote_info.sha3()).unwrap();
|
||||
let signature0 = tap.sign(voter, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone()), H520::from(signature0.clone())]).into_vec();
|
||||
header.set_seal(seal.clone());
|
||||
@ -949,7 +952,7 @@ mod tests {
|
||||
assert!(engine.verify_block_external(&header, None).is_ok());
|
||||
|
||||
let bad_voter = insert_and_unlock(&tap, "101");
|
||||
let bad_signature = tap.sign(bad_voter, None, vote_info.sha3()).unwrap();
|
||||
let bad_signature = tap.sign(bad_voter, None, keccak(vote_info)).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]).into_vec();
|
||||
header.set_seal(seal);
|
||||
@ -1081,10 +1084,10 @@ mod tests {
|
||||
let mut seal = proposal_seal(&tap, &header, 0);
|
||||
|
||||
let vote_info = message_info_rlp(&VoteStep::new(2, 0, Step::Precommit), Some(header.bare_hash()));
|
||||
let signature1 = tap.sign(proposer, None, vote_info.sha3()).unwrap();
|
||||
let signature1 = tap.sign(proposer, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
let voter = insert_and_unlock(&tap, "0");
|
||||
let signature0 = tap.sign(voter, None, vote_info.sha3()).unwrap();
|
||||
let signature0 = tap.sign(voter, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
seal[1] = ::rlp::NULL_RLP.to_vec();
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1.clone())]).into_vec();
|
||||
@ -1121,7 +1124,7 @@ mod tests {
|
||||
assert!(epoch_verifier.verify_light(&header).is_ok());
|
||||
|
||||
let bad_voter = insert_and_unlock(&tap, "101");
|
||||
let bad_signature = tap.sign(bad_voter, None, vote_info.sha3()).unwrap();
|
||||
let bad_signature = tap.sign(bad_voter, None, keccak(&vote_info)).unwrap();
|
||||
|
||||
seal[2] = ::rlp::encode_list(&vec![H520::from(signature1), H520::from(bad_signature)]).into_vec();
|
||||
header.set_seal(seal);
|
||||
|
@ -18,6 +18,7 @@
|
||||
/// It can also report validators for misbehaviour with two levels: `reportMalicious` and `reportBenign`.
|
||||
|
||||
use std::sync::Weak;
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
|
||||
use futures::Future;
|
||||
@ -128,6 +129,7 @@ impl ValidatorSet for ValidatorContract {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use rlp::encode;
|
||||
use spec::Spec;
|
||||
@ -153,7 +155,7 @@ mod tests {
|
||||
#[test]
|
||||
fn reports_validators() {
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let v1 = tap.insert_account("1".sha3().into(), "").unwrap();
|
||||
let v1 = tap.insert_account(keccak("1").into(), "").unwrap();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_contract, Some(tap.clone()));
|
||||
client.engine().register_client(Arc::downgrade(&client) as _);
|
||||
let validator_contract = "0000000000000000000000000000000000000005".parse::<Address>().unwrap();
|
||||
|
@ -19,7 +19,8 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Weak;
|
||||
use engines::{Call, Engine};
|
||||
use util::{Bytes, H256, Address, RwLock};
|
||||
use parking_lot::RwLock;
|
||||
use util::{Bytes, H256, Address};
|
||||
use ids::BlockId;
|
||||
use header::{BlockNumber, Header};
|
||||
use client::EngineClient;
|
||||
@ -144,6 +145,7 @@ impl ValidatorSet for Multi {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::collections::BTreeMap;
|
||||
use hash::keccak;
|
||||
use account_provider::AccountProvider;
|
||||
use client::BlockChainClient;
|
||||
use engines::EpochChange;
|
||||
@ -163,9 +165,9 @@ mod tests {
|
||||
let _ = ::env_logger::init();
|
||||
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let s0: Secret = "0".sha3().into();
|
||||
let s0: Secret = keccak("0").into();
|
||||
let v0 = tap.insert_account(s0.clone(), "").unwrap();
|
||||
let v1 = tap.insert_account("1".sha3().into(), "").unwrap();
|
||||
let v1 = tap.insert_account(keccak("1").into(), "").unwrap();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_multi, Some(tap));
|
||||
client.engine().register_client(Arc::downgrade(&client) as _);
|
||||
|
||||
|
@ -19,7 +19,9 @@
|
||||
use std::sync::{Weak, Arc};
|
||||
use futures::Future;
|
||||
use native_contracts::ValidatorSet as Provider;
|
||||
use hash::keccak;
|
||||
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use util::*;
|
||||
use util::cache::MemoryLruCache;
|
||||
use rlp::{UntrustedRlp, RlpStream};
|
||||
@ -41,7 +43,7 @@ const MEMOIZE_CAPACITY: usize = 500;
|
||||
const EVENT_NAME: &'static [u8] = &*b"InitiateChange(bytes32,address[])";
|
||||
|
||||
lazy_static! {
|
||||
static ref EVENT_NAME_HASH: H256 = EVENT_NAME.sha3();
|
||||
static ref EVENT_NAME_HASH: H256 = keccak(EVENT_NAME);
|
||||
}
|
||||
|
||||
// state-dependent proofs for the safe contract:
|
||||
@ -383,7 +385,7 @@ impl ValidatorSet for ValidatorSafeContract {
|
||||
|
||||
// ensure receipts match header.
|
||||
// TODO: optimize? these were just decoded.
|
||||
let found_root = ::util::triehash::ordered_trie_root(
|
||||
let found_root = ::triehash::ordered_trie_root(
|
||||
receipts.iter().map(::rlp::encode).map(|x| x.to_vec())
|
||||
);
|
||||
if found_root != *old_header.receipts_root() {
|
||||
@ -456,6 +458,7 @@ impl ValidatorSet for ValidatorSafeContract {
|
||||
mod tests {
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use types::ids::BlockId;
|
||||
use spec::Spec;
|
||||
@ -481,9 +484,9 @@ mod tests {
|
||||
#[test]
|
||||
fn knows_validators() {
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let s0: Secret = "1".sha3().into();
|
||||
let s0: Secret = keccak("1").into();
|
||||
let v0 = tap.insert_account(s0.clone(), "").unwrap();
|
||||
let v1 = tap.insert_account("0".sha3().into(), "").unwrap();
|
||||
let v1 = tap.insert_account(keccak("0").into(), "").unwrap();
|
||||
let chain_id = Spec::new_validator_safe_contract().chain_id();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(Spec::new_validator_safe_contract, Some(tap));
|
||||
client.engine().register_client(Arc::downgrade(&client) as _);
|
||||
|
@ -19,6 +19,7 @@
|
||||
use std::fmt::Debug;
|
||||
use std::collections::{BTreeMap, HashSet, HashMap};
|
||||
use std::hash::Hash;
|
||||
use parking_lot:: RwLock;
|
||||
use util::*;
|
||||
use rlp::{Encodable, RlpStream};
|
||||
|
||||
@ -206,6 +207,7 @@ impl <M: Message + Default + Encodable + Debug> VoteCollector<M> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use rlp::*;
|
||||
use super::*;
|
||||
@ -251,7 +253,7 @@ mod tests {
|
||||
#[test]
|
||||
fn seal_retrieval() {
|
||||
let collector = VoteCollector::default();
|
||||
let bh = Some("1".sha3());
|
||||
let bh = Some(keccak("1"));
|
||||
let mut signatures = Vec::new();
|
||||
for _ in 0..5 {
|
||||
signatures.push(H520::random());
|
||||
@ -263,9 +265,9 @@ mod tests {
|
||||
// Good proposal
|
||||
random_vote(&collector, signatures[0].clone(), propose_round.clone(), bh.clone());
|
||||
// Wrong block proposal.
|
||||
random_vote(&collector, signatures[0].clone(), propose_round.clone(), Some("0".sha3()));
|
||||
random_vote(&collector, signatures[0].clone(), propose_round.clone(), Some(keccak("0")));
|
||||
// Wrong block commit.
|
||||
random_vote(&collector, signatures[3].clone(), commit_round.clone(), Some("0".sha3()));
|
||||
random_vote(&collector, signatures[3].clone(), commit_round.clone(), Some(keccak("0")));
|
||||
// Wrong round.
|
||||
random_vote(&collector, signatures[0].clone(), 6, bh.clone());
|
||||
// Wrong round.
|
||||
@ -291,22 +293,22 @@ mod tests {
|
||||
let round1 = 1;
|
||||
let round3 = 3;
|
||||
// good 1
|
||||
random_vote(&collector, H520::random(), round1, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), 0, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), round1, Some(keccak("0")));
|
||||
random_vote(&collector, H520::random(), 0, Some(keccak("0")));
|
||||
// good 3
|
||||
random_vote(&collector, H520::random(), round3, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), 2, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), round3, Some(keccak("0")));
|
||||
random_vote(&collector, H520::random(), 2, Some(keccak("0")));
|
||||
// good prevote
|
||||
random_vote(&collector, H520::random(), round1, Some("1".sha3()));
|
||||
random_vote(&collector, H520::random(), round1, Some(keccak("1")));
|
||||
// good prevote
|
||||
let same_sig = H520::random();
|
||||
random_vote(&collector, same_sig.clone(), round1, Some("1".sha3()));
|
||||
random_vote(&collector, same_sig, round1, Some("1".sha3()));
|
||||
random_vote(&collector, same_sig.clone(), round1, Some(keccak("1")));
|
||||
random_vote(&collector, same_sig, round1, Some(keccak("1")));
|
||||
// good precommit
|
||||
random_vote(&collector, H520::random(), round3, Some("1".sha3()));
|
||||
random_vote(&collector, H520::random(), round3, Some(keccak("1")));
|
||||
// good prevote
|
||||
random_vote(&collector, H520::random(), round1, Some("0".sha3()));
|
||||
random_vote(&collector, H520::random(), 4, Some("2".sha3()));
|
||||
random_vote(&collector, H520::random(), round1, Some(keccak("0")));
|
||||
random_vote(&collector, H520::random(), 4, Some(keccak("2")));
|
||||
|
||||
assert_eq!(collector.count_round_votes(&round1), 4);
|
||||
assert_eq!(collector.count_round_votes(&round3), 2);
|
||||
@ -314,7 +316,7 @@ mod tests {
|
||||
let message = TestMessage {
|
||||
signature: H520::default(),
|
||||
step: round1,
|
||||
block_hash: Some("1".sha3())
|
||||
block_hash: Some(keccak("1"))
|
||||
};
|
||||
assert_eq!(collector.count_aligned_votes(&message), 2);
|
||||
}
|
||||
@ -325,11 +327,11 @@ mod tests {
|
||||
let vote = |round, hash| {
|
||||
random_vote(&collector, H520::random(), round, hash);
|
||||
};
|
||||
vote(6, Some("0".sha3()));
|
||||
vote(3, Some("0".sha3()));
|
||||
vote(7, Some("0".sha3()));
|
||||
vote(8, Some("1".sha3()));
|
||||
vote(1, Some("1".sha3()));
|
||||
vote(6, Some(keccak("0")));
|
||||
vote(3, Some(keccak("0")));
|
||||
vote(7, Some(keccak("0")));
|
||||
vote(8, Some(keccak("1")));
|
||||
vote(1, Some(keccak("1")));
|
||||
|
||||
collector.throw_out_old(&7);
|
||||
assert_eq!(collector.len(), 2);
|
||||
@ -340,9 +342,9 @@ mod tests {
|
||||
let collector = VoteCollector::default();
|
||||
let round = 3;
|
||||
// Vote is inserted fine.
|
||||
assert!(full_vote(&collector, H520::random(), round, Some("0".sha3()), &Address::default()));
|
||||
assert!(full_vote(&collector, H520::random(), round, Some(keccak("0")), &Address::default()));
|
||||
// Returns the double voting address.
|
||||
assert!(!full_vote(&collector, H520::random(), round, Some("1".sha3()), &Address::default()));
|
||||
assert!(!full_vote(&collector, H520::random(), round, Some(keccak("1")), &Address::default()));
|
||||
assert_eq!(collector.count_round_votes(&round), 1);
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ use std::path::Path;
|
||||
use std::cmp;
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use std::sync::Arc;
|
||||
use hash::{KECCAK_EMPTY_LIST_RLP};
|
||||
use ethash::{quick_get_difficulty, slow_get_seedhash, EthashManager};
|
||||
use util::*;
|
||||
use block::*;
|
||||
@ -34,6 +35,7 @@ use evm::Schedule;
|
||||
use ethjson;
|
||||
use rlp::{self, UntrustedRlp};
|
||||
use vm::LastHashes;
|
||||
use semantic_version::SemanticVersion;
|
||||
|
||||
/// Parity tries to round block.gas_limit to multiple of this constant
|
||||
pub const PARITY_GAS_LIMIT_DETERMINANT: U256 = U256([37, 0, 0, 0]);
|
||||
@ -481,7 +483,7 @@ impl Ethash {
|
||||
panic!("Can't calculate genesis block difficulty");
|
||||
}
|
||||
|
||||
let parent_has_uncles = parent.uncles_hash() != &sha3::SHA3_EMPTY_LIST_RLP;
|
||||
let parent_has_uncles = parent.uncles_hash() != &KECCAK_EMPTY_LIST_RLP;
|
||||
|
||||
let min_difficulty = self.ethash_params.minimum_difficulty;
|
||||
|
||||
|
@ -119,7 +119,7 @@ mod tests {
|
||||
|
||||
assert_eq!(morden.state_root(), "f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9".into());
|
||||
let genesis = morden.genesis_block();
|
||||
assert_eq!(BlockView::new(&genesis).header_view().sha3(), "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".into());
|
||||
assert_eq!(BlockView::new(&genesis).header_view().hash(), "0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303".into());
|
||||
|
||||
let _ = morden.engine;
|
||||
}
|
||||
@ -130,7 +130,7 @@ mod tests {
|
||||
|
||||
assert_eq!(frontier.state_root(), "d7f8974fb5ac78d9ac099b9ad5018bedc2ce0a72dad1827a1709da30580f0544".into());
|
||||
let genesis = frontier.genesis_block();
|
||||
assert_eq!(BlockView::new(&genesis).header_view().sha3(), "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".into());
|
||||
assert_eq!(BlockView::new(&genesis).header_view().hash(), "d4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3".into());
|
||||
|
||||
let _ = frontier.engine;
|
||||
}
|
||||
|
@ -17,6 +17,7 @@
|
||||
//! Transaction Execution environment.
|
||||
use std::cmp;
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use state::{Backend as StateBackend, State, Substate, CleanupMode};
|
||||
use engines::Engine;
|
||||
@ -47,20 +48,20 @@ pub fn contract_address(address_scheme: CreateContractAddress, sender: &Address,
|
||||
let mut stream = RlpStream::new_list(2);
|
||||
stream.append(sender);
|
||||
stream.append(nonce);
|
||||
(From::from(stream.as_raw().sha3()), None)
|
||||
(From::from(keccak(stream.as_raw())), None)
|
||||
},
|
||||
CreateContractAddress::FromCodeHash => {
|
||||
let code_hash = code.sha3();
|
||||
let code_hash = keccak(code);
|
||||
let mut buffer = [0xffu8; 20 + 32];
|
||||
&mut buffer[20..].copy_from_slice(&code_hash[..]);
|
||||
(From::from((&buffer[..]).sha3()), Some(code_hash))
|
||||
(From::from(keccak(&buffer[..])), Some(code_hash))
|
||||
},
|
||||
CreateContractAddress::FromSenderAndCodeHash => {
|
||||
let code_hash = code.sha3();
|
||||
let code_hash = keccak(code);
|
||||
let mut buffer = [0u8; 20 + 32];
|
||||
&mut buffer[..20].copy_from_slice(&sender[..]);
|
||||
&mut buffer[20..].copy_from_slice(&code_hash[..]);
|
||||
(From::from((&buffer[..]).sha3()), Some(code_hash))
|
||||
(From::from(keccak(&buffer[..])), Some(code_hash))
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -1307,8 +1308,8 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
evm_test!{test_sha3: test_sha3_jit, test_sha3_int}
|
||||
fn test_sha3(factory: Factory) {
|
||||
evm_test!{test_keccak: test_keccak_jit, test_keccak_int}
|
||||
fn test_keccak(factory: Factory) {
|
||||
let code = "6064640fffffffff20600055".from_hex().unwrap();
|
||||
|
||||
let sender = Address::from_str("0f572e5295c57f15886f9b263e2f6d2d6c7b5ec6").unwrap();
|
||||
|
@ -18,6 +18,7 @@
|
||||
|
||||
use std::cmp;
|
||||
use std::cell::RefCell;
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY_LIST_RLP, keccak};
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::*;
|
||||
use basic_types::{LogBloom, ZERO_LOGBLOOM};
|
||||
@ -101,12 +102,12 @@ impl Default for Header {
|
||||
number: 0,
|
||||
author: Address::default(),
|
||||
|
||||
transactions_root: SHA3_NULL_RLP,
|
||||
uncles_hash: SHA3_EMPTY_LIST_RLP,
|
||||
transactions_root: KECCAK_NULL_RLP,
|
||||
uncles_hash: KECCAK_EMPTY_LIST_RLP,
|
||||
extra_data: vec![],
|
||||
|
||||
state_root: SHA3_NULL_RLP,
|
||||
receipts_root: SHA3_NULL_RLP,
|
||||
state_root: KECCAK_NULL_RLP,
|
||||
receipts_root: KECCAK_NULL_RLP,
|
||||
log_bloom: ZERO_LOGBLOOM.clone(),
|
||||
gas_used: U256::default(),
|
||||
gas_limit: U256::default(),
|
||||
@ -195,13 +196,13 @@ impl Header {
|
||||
/// Set the seal field of the header.
|
||||
pub fn set_seal(&mut self, a: Vec<Bytes>) { self.seal = a; self.note_dirty(); }
|
||||
|
||||
/// Get the hash of this header (sha3 of the RLP).
|
||||
/// Get the hash of this header (keccak of the RLP).
|
||||
pub fn hash(&self) -> H256 {
|
||||
let mut hash = self.hash.borrow_mut();
|
||||
match &mut *hash {
|
||||
&mut Some(ref h) => h.clone(),
|
||||
hash @ &mut None => {
|
||||
let h = self.rlp_sha3(Seal::With);
|
||||
let h = self.rlp_keccak(Seal::With);
|
||||
*hash = Some(h.clone());
|
||||
h
|
||||
}
|
||||
@ -214,7 +215,7 @@ impl Header {
|
||||
match &mut *hash {
|
||||
&mut Some(ref h) => h.clone(),
|
||||
hash @ &mut None => {
|
||||
let h = self.rlp_sha3(Seal::Without);
|
||||
let h = self.rlp_keccak(Seal::Without);
|
||||
*hash = Some(h.clone());
|
||||
h
|
||||
}
|
||||
@ -259,7 +260,7 @@ impl Header {
|
||||
}
|
||||
|
||||
/// Get the SHA3 (Keccak) of this header, optionally `with_seal`.
|
||||
pub fn rlp_sha3(&self, with_seal: Seal) -> H256 { self.rlp(with_seal).sha3() }
|
||||
pub fn rlp_keccak(&self, with_seal: Seal) -> H256 { keccak(self.rlp(with_seal)) }
|
||||
|
||||
/// Encode the header, getting a type-safe wrapper around the RLP.
|
||||
pub fn encoded(&self) -> ::encoded::Header {
|
||||
@ -284,7 +285,7 @@ impl Decodable for Header {
|
||||
timestamp: cmp::min(r.val_at::<U256>(11)?, u64::max_value().into()).as_u64(),
|
||||
extra_data: r.val_at(12)?,
|
||||
seal: vec![],
|
||||
hash: RefCell::new(Some(r.as_raw().sha3())),
|
||||
hash: RefCell::new(Some(keccak(r.as_raw()))),
|
||||
bare_hash: RefCell::new(None),
|
||||
};
|
||||
|
||||
|
@ -98,10 +98,15 @@ extern crate lru_cache;
|
||||
extern crate native_contracts;
|
||||
extern crate num_cpus;
|
||||
extern crate num;
|
||||
extern crate parking_lot;
|
||||
extern crate price_info;
|
||||
extern crate rand;
|
||||
extern crate rlp;
|
||||
extern crate hash;
|
||||
extern crate heapsize;
|
||||
extern crate triehash;
|
||||
extern crate ansi_term;
|
||||
extern crate semantic_version;
|
||||
|
||||
#[macro_use]
|
||||
extern crate rlp_derive;
|
||||
@ -149,6 +154,7 @@ pub mod service;
|
||||
pub mod snapshot;
|
||||
pub mod spec;
|
||||
pub mod state;
|
||||
pub mod timer;
|
||||
pub mod trace;
|
||||
pub mod transaction;
|
||||
pub mod verification;
|
||||
|
@ -23,14 +23,14 @@ use util::Bytes;
|
||||
use util::{Address, H256};
|
||||
use util::kvdb::Database;
|
||||
use util::migration::{Batch, Config, Error, Migration, SimpleMigration, Progress};
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
use std::sync::Arc;
|
||||
|
||||
use rlp::{decode, Rlp, RlpStream};
|
||||
|
||||
// attempt to migrate a key, value pair. None if migration not possible.
|
||||
fn attempt_migrate(mut key_h: H256, val: &[u8]) -> Option<H256> {
|
||||
let val_hash = val.sha3();
|
||||
let val_hash = keccak(val);
|
||||
|
||||
if key_h != val_hash {
|
||||
// this is a key which has been xor'd with an address.
|
||||
@ -43,7 +43,7 @@ fn attempt_migrate(mut key_h: H256, val: &[u8]) -> Option<H256> {
|
||||
return None;
|
||||
}
|
||||
|
||||
let address_hash = Address::from(address).sha3();
|
||||
let address_hash = keccak(Address::from(address));
|
||||
|
||||
// create the xor'd key in place.
|
||||
key_h.copy_from_slice(&*val_hash);
|
||||
|
@ -24,7 +24,8 @@ use transient_hashmap::TransientHashMap;
|
||||
use miner::{TransactionQueue, TransactionQueueDetailsProvider, TransactionImportResult, TransactionOrigin};
|
||||
use miner::transaction_queue::QueuingInstant;
|
||||
use error::{Error, TransactionError};
|
||||
use util::{U256, H256, Address, Hashable};
|
||||
use util::{U256, H256, Address};
|
||||
use hash::keccak;
|
||||
|
||||
type Count = u16;
|
||||
|
||||
@ -103,7 +104,7 @@ impl BanningTransactionQueue {
|
||||
|
||||
// Check code
|
||||
if let Action::Create = transaction.action {
|
||||
let code_hash = transaction.data.sha3();
|
||||
let code_hash = keccak(&transaction.data);
|
||||
let count = self.codes_bans.direct().get(&code_hash).cloned().unwrap_or(0);
|
||||
if count > threshold {
|
||||
debug!(target: "txqueue", "Ignoring transaction {:?} because code is banned.", transaction.hash());
|
||||
@ -131,7 +132,7 @@ impl BanningTransactionQueue {
|
||||
self.ban_recipient(recipient)
|
||||
},
|
||||
Action::Create => {
|
||||
self.ban_codehash(transaction.data.sha3())
|
||||
self.ban_codehash(keccak(&transaction.data))
|
||||
},
|
||||
};
|
||||
sender_banned || recipient_or_code_banned
|
||||
@ -210,13 +211,14 @@ impl DerefMut for BanningTransactionQueue {
|
||||
mod tests {
|
||||
use std::time::Duration;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use super::{BanningTransactionQueue, Threshold};
|
||||
use ethkey::{Random, Generator};
|
||||
use transaction::{Transaction, SignedTransaction, Action};
|
||||
use error::{Error, TransactionError};
|
||||
use client::TransactionImportResult;
|
||||
use miner::{TransactionQueue, TransactionOrigin};
|
||||
use util::{U256, Address, Hashable};
|
||||
use util::{U256, Address};
|
||||
use miner::transaction_queue::test::DummyTransactionDetailsProvider;
|
||||
|
||||
fn queue() -> BanningTransactionQueue {
|
||||
@ -310,7 +312,7 @@ mod tests {
|
||||
fn should_not_accept_transactions_with_banned_code() {
|
||||
// given
|
||||
let tx = transaction(Action::Create);
|
||||
let codehash = tx.data.sha3();
|
||||
let codehash = keccak(&tx.data);
|
||||
let mut txq = queue();
|
||||
// Banlist once (threshold not reached)
|
||||
let banlist1 = txq.ban_codehash(codehash);
|
||||
|
@ -17,7 +17,8 @@
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use std::time::{Instant, Duration};
|
||||
use util::{Mutex, U256, H256};
|
||||
use util::{U256, H256};
|
||||
use parking_lot::Mutex;
|
||||
|
||||
/// External miner interface.
|
||||
pub trait ExternalMinerService: Send + Sync {
|
||||
|
@ -18,7 +18,9 @@ use std::time::{Instant, Duration};
|
||||
use std::collections::{BTreeMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
|
||||
use parking_lot::{Mutex, RwLock};
|
||||
use util::*;
|
||||
use timer::PerfTimer;
|
||||
use using_queue::{UsingQueue, GetAction};
|
||||
use account_provider::{AccountProvider, SignError as AccountError};
|
||||
use state::State;
|
||||
@ -40,6 +42,7 @@ use miner::service_transaction_checker::ServiceTransactionChecker;
|
||||
use price_info::{Client as PriceInfoClient, PriceInfo};
|
||||
use price_info::fetch::Client as FetchClient;
|
||||
use header::{Header, BlockNumber};
|
||||
use ansi_term::Colour;
|
||||
|
||||
/// Different possible definitions for pending transaction set.
|
||||
#[derive(Debug, PartialEq)]
|
||||
@ -1235,6 +1238,7 @@ mod tests {
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use super::super::{MinerService, PrioritizationStrategy};
|
||||
use super::*;
|
||||
use block::IsBlock;
|
||||
@ -1418,7 +1422,7 @@ mod tests {
|
||||
fn should_fail_setting_engine_signer_on_pow() {
|
||||
let spec = Spec::new_pow_test_spec;
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let addr = tap.insert_account("1".sha3().into(), "").unwrap();
|
||||
let addr = tap.insert_account(keccak("1").into(), "").unwrap();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(spec, Some(tap.clone()));
|
||||
assert!(match client.miner().set_engine_signer(addr, "".into()) { Err(AccountError::InappropriateChain) => true, _ => false })
|
||||
}
|
||||
@ -1427,7 +1431,7 @@ mod tests {
|
||||
fn should_fail_setting_engine_signer_without_account_provider() {
|
||||
let spec = Spec::new_instant;
|
||||
let tap = Arc::new(AccountProvider::transient_provider());
|
||||
let addr = tap.insert_account("1".sha3().into(), "").unwrap();
|
||||
let addr = tap.insert_account(keccak("1").into(), "").unwrap();
|
||||
let client = generate_dummy_client_with_spec_and_accounts(spec, None);
|
||||
assert!(match client.miner().set_engine_signer(addr, "".into()) { Err(AccountError::NotFound) => true, _ => false });
|
||||
}
|
||||
|
@ -20,7 +20,8 @@ use types::ids::BlockId;
|
||||
|
||||
use futures::{future, Future};
|
||||
use native_contracts::ServiceTransactionChecker as Contract;
|
||||
use util::{U256, Mutex};
|
||||
use parking_lot::Mutex;
|
||||
use util::U256;
|
||||
|
||||
const SERVICE_TRANSACTION_CONTRACT_REGISTRY_NAME: &'static str = "service_transaction_checker";
|
||||
|
||||
|
@ -28,7 +28,7 @@ use std::fmt;
|
||||
use util::{H256, U256, H64, clean_0x};
|
||||
use ethereum::ethash::Ethash;
|
||||
use ethash::SeedHashCompute;
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
use miner::{self, Miner, MinerService};
|
||||
use client::Client;
|
||||
use block::IsBlock;
|
||||
|
@ -24,6 +24,7 @@ use hyper::{Next};
|
||||
use hyper::net::HttpStream;
|
||||
use ethash::SeedHashCompute;
|
||||
use hyper::Url;
|
||||
use parking_lot::Mutex;
|
||||
use util::*;
|
||||
use ethereum::ethash::Ethash;
|
||||
|
||||
|
@ -17,6 +17,8 @@
|
||||
use std::fmt;
|
||||
use std::collections::BTreeMap;
|
||||
use itertools::Itertools;
|
||||
use hash::{keccak};
|
||||
use triehash::sec_trie_root;
|
||||
use util::*;
|
||||
use state::Account;
|
||||
use ethjson;
|
||||
@ -61,7 +63,7 @@ impl PodAccount {
|
||||
stream.append(&self.nonce);
|
||||
stream.append(&self.balance);
|
||||
stream.append(&sec_trie_root(self.storage.iter().map(|(k, v)| (k.to_vec(), rlp::encode(&U256::from(&**v)).to_vec())).collect()));
|
||||
stream.append(&self.code.as_ref().unwrap_or(&vec![]).sha3());
|
||||
stream.append(&keccak(&self.code.as_ref().unwrap_or(&vec![])));
|
||||
stream.out()
|
||||
}
|
||||
|
||||
@ -117,7 +119,7 @@ impl fmt::Display for PodAccount {
|
||||
self.balance,
|
||||
self.nonce,
|
||||
self.code.as_ref().map_or(0, |c| c.len()),
|
||||
self.code.as_ref().map_or_else(H256::new, |c| c.sha3()),
|
||||
self.code.as_ref().map_or_else(H256::new, |c| keccak(c)),
|
||||
self.storage.len(),
|
||||
)
|
||||
}
|
||||
|
@ -19,6 +19,7 @@
|
||||
use std::fmt;
|
||||
use std::collections::BTreeMap;
|
||||
use itertools::Itertools;
|
||||
use triehash::sec_trie_root;
|
||||
use util::*;
|
||||
use pod_account::{self, PodAccount};
|
||||
use types::state_diff::StateDiff;
|
||||
|
@ -28,6 +28,7 @@ use miner::Miner;
|
||||
use snapshot::ManifestData;
|
||||
use snapshot::service::{Service as SnapshotService, ServiceParams as SnapServiceParams};
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use ansi_term::Colour;
|
||||
|
||||
#[cfg(feature="ipc")]
|
||||
use nanoipc;
|
||||
|
@ -19,8 +19,9 @@
|
||||
use account_db::{AccountDB, AccountDBMut};
|
||||
use basic_account::BasicAccount;
|
||||
use snapshot::Error;
|
||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP};
|
||||
|
||||
use util::{U256, H256, Bytes, HashDB, SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::{U256, H256, Bytes, HashDB};
|
||||
use util::trie::{TrieDB, Trie};
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
|
||||
@ -30,8 +31,8 @@ use std::collections::HashSet;
|
||||
const ACC_EMPTY: BasicAccount = BasicAccount {
|
||||
nonce: U256([0, 0, 0, 0]),
|
||||
balance: U256([0, 0, 0, 0]),
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
code_hash: SHA3_EMPTY,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
};
|
||||
|
||||
// whether an encoded account has code and how it is referred to.
|
||||
@ -78,7 +79,7 @@ pub fn to_fat_rlps(account_hash: &H256, acc: &BasicAccount, acct_db: &AccountDB,
|
||||
.append(&acc.balance);
|
||||
|
||||
// [has_code, code_hash].
|
||||
if acc.code_hash == SHA3_EMPTY {
|
||||
if acc.code_hash == KECCAK_EMPTY {
|
||||
account_stream.append(&CodeState::Empty.raw()).append_empty_data();
|
||||
} else if used_code.contains(&acc.code_hash) {
|
||||
account_stream.append(&CodeState::Hash.raw()).append(&acc.code_hash);
|
||||
@ -164,7 +165,7 @@ pub fn from_fat_rlp(
|
||||
|
||||
// load the code if it exists.
|
||||
let (code_hash, new_code) = match code_state {
|
||||
CodeState::Empty => (SHA3_EMPTY, None),
|
||||
CodeState::Empty => (KECCAK_EMPTY, None),
|
||||
CodeState::Inline => {
|
||||
let code: Bytes = rlp.val_at(3)?;
|
||||
let code_hash = acct_db.insert(&code);
|
||||
@ -210,8 +211,8 @@ mod tests {
|
||||
use tests::helpers::get_temp_state_db;
|
||||
use snapshot::tests::helpers::fill_storage;
|
||||
|
||||
use util::sha3::{SHA3_EMPTY, SHA3_NULL_RLP};
|
||||
use util::{Address, H256, HashDB, DBValue, Hashable};
|
||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||
use util::{Address, H256, HashDB, DBValue};
|
||||
use rlp::UntrustedRlp;
|
||||
|
||||
use std::collections::HashSet;
|
||||
@ -226,14 +227,14 @@ mod tests {
|
||||
let account = BasicAccount {
|
||||
nonce: 50.into(),
|
||||
balance: 123456789.into(),
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
code_hash: SHA3_EMPTY,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
};
|
||||
|
||||
let thin_rlp = ::rlp::encode(&account);
|
||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp), account);
|
||||
|
||||
let fat_rlps = to_fat_rlps(&addr.sha3(), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlps = to_fat_rlps(&keccak(&addr), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp = UntrustedRlp::new(&fat_rlps[0]).at(1).unwrap();
|
||||
assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp, H256::zero()).unwrap().0, account);
|
||||
}
|
||||
@ -245,20 +246,20 @@ mod tests {
|
||||
|
||||
let account = {
|
||||
let acct_db = AccountDBMut::new(db.as_hashdb_mut(), &addr);
|
||||
let mut root = SHA3_NULL_RLP;
|
||||
let mut root = KECCAK_NULL_RLP;
|
||||
fill_storage(acct_db, &mut root, &mut H256::zero());
|
||||
BasicAccount {
|
||||
nonce: 25.into(),
|
||||
balance: 987654321.into(),
|
||||
storage_root: root,
|
||||
code_hash: SHA3_EMPTY,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
}
|
||||
};
|
||||
|
||||
let thin_rlp = ::rlp::encode(&account);
|
||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp), account);
|
||||
|
||||
let fat_rlp = to_fat_rlps(&addr.sha3(), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp = to_fat_rlps(&keccak(&addr), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp = UntrustedRlp::new(&fat_rlp[0]).at(1).unwrap();
|
||||
assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp, H256::zero()).unwrap().0, account);
|
||||
}
|
||||
@ -270,21 +271,21 @@ mod tests {
|
||||
|
||||
let account = {
|
||||
let acct_db = AccountDBMut::new(db.as_hashdb_mut(), &addr);
|
||||
let mut root = SHA3_NULL_RLP;
|
||||
let mut root = KECCAK_NULL_RLP;
|
||||
fill_storage(acct_db, &mut root, &mut H256::zero());
|
||||
BasicAccount {
|
||||
nonce: 25.into(),
|
||||
balance: 987654321.into(),
|
||||
storage_root: root,
|
||||
code_hash: SHA3_EMPTY,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
}
|
||||
};
|
||||
|
||||
let thin_rlp = ::rlp::encode(&account);
|
||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp), account);
|
||||
|
||||
let fat_rlps = to_fat_rlps(&addr.sha3(), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), 500, 1000).unwrap();
|
||||
let mut root = SHA3_NULL_RLP;
|
||||
let fat_rlps = to_fat_rlps(&keccak(addr), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), 500, 1000).unwrap();
|
||||
let mut root = KECCAK_NULL_RLP;
|
||||
let mut restored_account = None;
|
||||
for rlp in fat_rlps {
|
||||
let fat_rlp = UntrustedRlp::new(&rlp).at(1).unwrap();
|
||||
@ -314,21 +315,21 @@ mod tests {
|
||||
let account1 = BasicAccount {
|
||||
nonce: 50.into(),
|
||||
balance: 123456789.into(),
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
code_hash: code_hash,
|
||||
};
|
||||
|
||||
let account2 = BasicAccount {
|
||||
nonce: 400.into(),
|
||||
balance: 98765432123456789usize.into(),
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
code_hash: code_hash,
|
||||
};
|
||||
|
||||
let mut used_code = HashSet::new();
|
||||
|
||||
let fat_rlp1 = to_fat_rlps(&addr1.sha3(), &account1, &AccountDB::new(db.as_hashdb(), &addr1), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp2 = to_fat_rlps(&addr2.sha3(), &account2, &AccountDB::new(db.as_hashdb(), &addr2), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp1 = to_fat_rlps(&keccak(&addr1), &account1, &AccountDB::new(db.as_hashdb(), &addr1), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
|
||||
let fat_rlp2 = to_fat_rlps(&keccak(&addr2), &account2, &AccountDB::new(db.as_hashdb(), &addr2), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
|
||||
assert_eq!(used_code.len(), 1);
|
||||
|
||||
let fat_rlp1 = UntrustedRlp::new(&fat_rlp1[0]).at(1).unwrap();
|
||||
|
@ -18,11 +18,12 @@
|
||||
|
||||
use block::Block;
|
||||
use header::Header;
|
||||
use hash::keccak;
|
||||
|
||||
use views::BlockView;
|
||||
use rlp::{DecoderError, RlpStream, UntrustedRlp};
|
||||
use util::{Bytes, Hashable, H256};
|
||||
use util::triehash::ordered_trie_root;
|
||||
use util::{Bytes, H256};
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
const HEADER_FIELDS: usize = 8;
|
||||
const BLOCK_FIELDS: usize = 2;
|
||||
@ -111,7 +112,7 @@ impl AbridgedBlock {
|
||||
|
||||
let mut uncles_rlp = RlpStream::new();
|
||||
uncles_rlp.append_list(&uncles);
|
||||
header.set_uncles_hash(uncles_rlp.as_raw().sha3());
|
||||
header.set_uncles_hash(keccak(uncles_rlp.as_raw()));
|
||||
|
||||
let mut seal_fields = Vec::new();
|
||||
for i in (HEADER_FIELDS + BLOCK_FIELDS)..rlp.item_count()? {
|
||||
@ -189,7 +190,7 @@ mod tests {
|
||||
b.transactions.push(t2.into());
|
||||
|
||||
let receipts_root = b.header.receipts_root().clone();
|
||||
b.header.set_transactions_root(::util::triehash::ordered_trie_root(
|
||||
b.header.set_transactions_root(::triehash::ordered_trie_root(
|
||||
b.transactions.iter().map(::rlp::encode).map(|out| out.into_vec())
|
||||
));
|
||||
|
||||
|
@ -222,7 +222,7 @@ impl Rebuilder for PowRebuilder {
|
||||
use views::BlockView;
|
||||
use snapshot::verify_old_block;
|
||||
use util::U256;
|
||||
use util::triehash::ordered_trie_root;
|
||||
use triehash::ordered_trie_root;
|
||||
|
||||
let rlp = UntrustedRlp::new(chunk);
|
||||
let item_count = rlp.item_count()?;
|
||||
|
@ -342,7 +342,7 @@ impl SnapshotReader for LooseReader {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use devtools::RandomTempPath;
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
|
||||
use snapshot::ManifestData;
|
||||
use super::{SnapshotWriter, SnapshotReader, PackedWriter, PackedReader, LooseWriter, LooseReader, SNAPSHOT_VERSION};
|
||||
@ -359,24 +359,24 @@ mod tests {
|
||||
let mut block_hashes = Vec::new();
|
||||
|
||||
for chunk in STATE_CHUNKS {
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
state_hashes.push(hash.clone());
|
||||
writer.write_state_chunk(hash, chunk).unwrap();
|
||||
}
|
||||
|
||||
for chunk in BLOCK_CHUNKS {
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
block_hashes.push(hash.clone());
|
||||
writer.write_block_chunk(chunk.sha3(), chunk).unwrap();
|
||||
writer.write_block_chunk(keccak(&chunk), chunk).unwrap();
|
||||
}
|
||||
|
||||
let manifest = ManifestData {
|
||||
version: SNAPSHOT_VERSION,
|
||||
state_hashes: state_hashes,
|
||||
block_hashes: block_hashes,
|
||||
state_root: b"notarealroot".sha3(),
|
||||
state_root: keccak(b"notarealroot"),
|
||||
block_number: 12345678987654321,
|
||||
block_hash: b"notarealblock".sha3(),
|
||||
block_hash: keccak(b"notarealblock"),
|
||||
};
|
||||
|
||||
writer.finish(manifest.clone()).unwrap();
|
||||
@ -398,24 +398,24 @@ mod tests {
|
||||
let mut block_hashes = Vec::new();
|
||||
|
||||
for chunk in STATE_CHUNKS {
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
state_hashes.push(hash.clone());
|
||||
writer.write_state_chunk(hash, chunk).unwrap();
|
||||
}
|
||||
|
||||
for chunk in BLOCK_CHUNKS {
|
||||
let hash = chunk.sha3();
|
||||
let hash = keccak(&chunk);
|
||||
block_hashes.push(hash.clone());
|
||||
writer.write_block_chunk(chunk.sha3(), chunk).unwrap();
|
||||
writer.write_block_chunk(keccak(&chunk), chunk).unwrap();
|
||||
}
|
||||
|
||||
let manifest = ManifestData {
|
||||
version: SNAPSHOT_VERSION,
|
||||
state_hashes: state_hashes,
|
||||
block_hashes: block_hashes,
|
||||
state_root: b"notarealroot".sha3(),
|
||||
state_root: keccak(b"notarealroot"),
|
||||
block_number: 12345678987654321,
|
||||
block_hash: b"notarealblock".sha3(),
|
||||
block_hash: keccak(b"notarealblock)"),
|
||||
};
|
||||
|
||||
writer.finish(manifest.clone()).unwrap();
|
||||
|
@ -22,6 +22,7 @@
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, AtomicUsize, Ordering};
|
||||
use hash::{keccak, KECCAK_NULL_RLP, KECCAK_EMPTY};
|
||||
|
||||
use account_db::{AccountDB, AccountDBMut};
|
||||
use blockchain::{BlockChain, BlockProvider};
|
||||
@ -29,13 +30,12 @@ use engines::Engine;
|
||||
use header::Header;
|
||||
use ids::BlockId;
|
||||
|
||||
use util::{Bytes, Hashable, HashDB, DBValue, snappy, U256};
|
||||
use util::Mutex;
|
||||
use util::{Bytes, HashDB, DBValue, snappy, U256};
|
||||
use parking_lot::Mutex;
|
||||
use util::hash::{H256};
|
||||
use util::journaldb::{self, Algorithm, JournalDB};
|
||||
use util::kvdb::KeyValueDB;
|
||||
use util::trie::{TrieDB, TrieDBMut, Trie, TrieMut};
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
use rlp::{RlpStream, UntrustedRlp};
|
||||
use bloom_journal::Bloom;
|
||||
|
||||
@ -183,7 +183,7 @@ pub fn chunk_secondary<'a>(mut chunker: Box<SnapshotComponents>, chain: &'a Bloc
|
||||
let mut chunk_sink = |raw_data: &[u8]| {
|
||||
let compressed_size = snappy::compress_into(raw_data, &mut snappy_buffer);
|
||||
let compressed = &snappy_buffer[..compressed_size];
|
||||
let hash = compressed.sha3();
|
||||
let hash = keccak(&compressed);
|
||||
let size = compressed.len();
|
||||
|
||||
writer.lock().write_block_chunk(hash, compressed)?;
|
||||
@ -240,7 +240,7 @@ impl<'a> StateChunker<'a> {
|
||||
|
||||
let compressed_size = snappy::compress_into(&raw_data, &mut self.snappy_buffer);
|
||||
let compressed = &self.snappy_buffer[..compressed_size];
|
||||
let hash = compressed.sha3();
|
||||
let hash = keccak(&compressed);
|
||||
|
||||
self.writer.lock().write_state_chunk(hash, compressed)?;
|
||||
trace!(target: "snapshot", "wrote state chunk. size: {}, uncompressed size: {}", compressed_size, raw_data.len());
|
||||
@ -318,7 +318,7 @@ impl StateRebuilder {
|
||||
pub fn new(db: Arc<KeyValueDB>, pruning: Algorithm) -> Self {
|
||||
StateRebuilder {
|
||||
db: journaldb::new(db.clone(), pruning, ::db::COL_STATE),
|
||||
state_root: SHA3_NULL_RLP,
|
||||
state_root: KECCAK_NULL_RLP,
|
||||
known_code: HashMap::new(),
|
||||
missing_code: HashMap::new(),
|
||||
bloom: StateDB::load_bloom(&*db),
|
||||
@ -362,7 +362,7 @@ impl StateRebuilder {
|
||||
|
||||
// batch trie writes
|
||||
{
|
||||
let mut account_trie = if self.state_root != SHA3_NULL_RLP {
|
||||
let mut account_trie = if self.state_root != KECCAK_NULL_RLP {
|
||||
TrieDBMut::from_existing(self.db.as_hashdb_mut(), &mut self.state_root)?
|
||||
} else {
|
||||
TrieDBMut::new(self.db.as_hashdb_mut(), &mut self.state_root)
|
||||
@ -443,7 +443,7 @@ fn rebuild_accounts(
|
||||
// new inline code
|
||||
Some(code) => status.new_code.push((code_hash, code, hash)),
|
||||
None => {
|
||||
if code_hash != ::util::SHA3_EMPTY {
|
||||
if code_hash != KECCAK_EMPTY {
|
||||
// see if this code has already been included inline
|
||||
match known_code.get(&code_hash) {
|
||||
Some(&first_with) => {
|
||||
|
@ -35,7 +35,8 @@ use service::ClientIoMessage;
|
||||
|
||||
use io::IoChannel;
|
||||
|
||||
use util::{Bytes, H256, Mutex, RwLock, RwLockReadGuard, UtilError};
|
||||
use parking_lot::{Mutex, RwLock, RwLockReadGuard};
|
||||
use util::{Bytes, H256, UtilError};
|
||||
use util::journaldb::Algorithm;
|
||||
use util::kvdb::{Database, DatabaseConfig};
|
||||
use util::snappy;
|
||||
|
@ -18,6 +18,7 @@
|
||||
//! which can be queried before and after a full snapshot/restore cycle.
|
||||
|
||||
use std::sync::Arc;
|
||||
use hash::{KECCAK_NULL_RLP};
|
||||
|
||||
use account_db::AccountDBMut;
|
||||
use basic_account::BasicAccount;
|
||||
@ -36,7 +37,6 @@ use util::hashdb::HashDB;
|
||||
use util::journaldb;
|
||||
use util::trie::{Alphabet, StandardMap, SecTrieDBMut, TrieMut, ValueMode};
|
||||
use util::trie::{TrieDB, TrieDBMut, Trie};
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
|
||||
// the proportion of accounts we will alter each tick.
|
||||
const ACCOUNT_CHURN: f32 = 0.01;
|
||||
@ -51,7 +51,7 @@ impl StateProducer {
|
||||
/// Create a new `StateProducer`.
|
||||
pub fn new() -> Self {
|
||||
StateProducer {
|
||||
state_root: SHA3_NULL_RLP,
|
||||
state_root: KECCAK_NULL_RLP,
|
||||
storage_seed: H256::zero(),
|
||||
}
|
||||
}
|
||||
@ -115,7 +115,7 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) {
|
||||
count: 100,
|
||||
};
|
||||
{
|
||||
let mut trie = if *root == SHA3_NULL_RLP {
|
||||
let mut trie = if *root == KECCAK_NULL_RLP {
|
||||
SecTrieDBMut::new(&mut db, root)
|
||||
} else {
|
||||
SecTrieDBMut::from_existing(&mut db, root).unwrap()
|
||||
|
@ -30,7 +30,7 @@ use spec::Spec;
|
||||
use tests::helpers;
|
||||
use transaction::{Transaction, Action, SignedTransaction};
|
||||
|
||||
use util::{Address, Hashable};
|
||||
use util::Address;
|
||||
use util::kvdb;
|
||||
|
||||
const PASS: &'static str = "";
|
||||
@ -38,14 +38,14 @@ const TRANSITION_BLOCK_1: usize = 2; // block at which the contract becomes acti
|
||||
const TRANSITION_BLOCK_2: usize = 10; // block at which the second contract activates.
|
||||
|
||||
macro_rules! secret {
|
||||
($e: expr) => { Secret::from_slice(&$e.sha3()) }
|
||||
($e: expr) => { Secret::from_slice(&$crate::hash::keccak($e)) }
|
||||
}
|
||||
|
||||
lazy_static! {
|
||||
// contract addresses.
|
||||
static ref CONTRACT_ADDR_1: Address = Address::from_str("0000000000000000000000000000000000000005").unwrap();
|
||||
static ref CONTRACT_ADDR_2: Address = Address::from_str("0000000000000000000000000000000000000006").unwrap();
|
||||
// secret: `sha3(1)`, and initial validator.
|
||||
// secret: `keccak(1)`, and initial validator.
|
||||
static ref RICH_ADDR: Address = Address::from_str("7d577a597b2742b498cb5cf0c26cdcd726d39e6e").unwrap();
|
||||
// rich address' secret.
|
||||
static ref RICH_SECRET: Secret = secret!("1");
|
||||
@ -53,7 +53,7 @@ lazy_static! {
|
||||
|
||||
|
||||
/// Contract code used here: https://gist.github.com/anonymous/2a43783647e0f0dfcc359bd6fd81d6d9
|
||||
/// Account with secrets "1".sha3() is initially the validator.
|
||||
/// Account with secrets keccak("1") is initially the validator.
|
||||
/// Transitions to the contract at block 2, initially same validator set.
|
||||
/// Create a new Spec with AuthorityRound which uses a contract at address 5 to determine the current validators using `getValidators`.
|
||||
/// `native_contracts::test_contracts::ValidatorSet` provides a native wrapper for the ABi.
|
||||
|
@ -24,7 +24,8 @@ use blockchain::BlockChain;
|
||||
use snapshot::{chunk_secondary, Error as SnapshotError, Progress, SnapshotComponents};
|
||||
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter};
|
||||
|
||||
use util::{Mutex, snappy};
|
||||
use parking_lot::Mutex;
|
||||
use util::snappy;
|
||||
use util::kvdb::{self, KeyValueDB, DBTransaction};
|
||||
|
||||
use std::sync::Arc;
|
||||
@ -71,7 +72,7 @@ fn chunk_and_restore(amount: u64) {
|
||||
version: 2,
|
||||
state_hashes: Vec::new(),
|
||||
block_hashes: block_hashes,
|
||||
state_root: ::util::sha3::SHA3_NULL_RLP,
|
||||
state_root: ::hash::KECCAK_NULL_RLP,
|
||||
block_number: amount,
|
||||
block_hash: best_hash,
|
||||
};
|
||||
@ -134,7 +135,7 @@ fn checks_flag() {
|
||||
version: 2,
|
||||
state_hashes: Vec::new(),
|
||||
block_hashes: Vec::new(),
|
||||
state_root: ::util::sha3::SHA3_NULL_RLP,
|
||||
state_root: ::hash::KECCAK_NULL_RLP,
|
||||
block_number: 102,
|
||||
block_hash: H256::default(),
|
||||
};
|
||||
|
@ -29,13 +29,12 @@ use util::hash::H256;
|
||||
use util::journaldb::{self, Algorithm};
|
||||
use util::kvdb::{Database, DatabaseConfig};
|
||||
use util::memorydb::MemoryDB;
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
use devtools::RandomTempPath;
|
||||
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::AtomicBool;
|
||||
use hash::{KECCAK_NULL_RLP, keccak};
|
||||
|
||||
#[test]
|
||||
fn snap_and_restore() {
|
||||
@ -98,7 +97,7 @@ fn snap_and_restore() {
|
||||
fn get_code_from_prev_chunk() {
|
||||
use std::collections::HashSet;
|
||||
use rlp::RlpStream;
|
||||
use util::{HashDB, H256, U256, Hashable};
|
||||
use util::{HashDB, H256, U256};
|
||||
|
||||
use account_db::{AccountDBMut, AccountDB};
|
||||
|
||||
@ -107,8 +106,8 @@ fn get_code_from_prev_chunk() {
|
||||
let mut acc_stream = RlpStream::new_list(4);
|
||||
acc_stream.append(&U256::default())
|
||||
.append(&U256::default())
|
||||
.append(&SHA3_NULL_RLP)
|
||||
.append(&code.sha3());
|
||||
.append(&KECCAK_NULL_RLP)
|
||||
.append(&keccak(code));
|
||||
|
||||
let (h1, h2) = (H256::random(), H256::random());
|
||||
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
//! Watcher for snapshot-related chain events.
|
||||
|
||||
use util::Mutex;
|
||||
use parking_lot::Mutex;
|
||||
use client::{BlockChainClient, Client, ChainNotify};
|
||||
use ids::BlockId;
|
||||
use service::ClientIoMessage;
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use util::{Address, H256, U256};
|
||||
use util::sha3::SHA3_NULL_RLP;
|
||||
use hash::KECCAK_NULL_RLP;
|
||||
use ethjson;
|
||||
use super::seal::Seal;
|
||||
|
||||
@ -54,8 +54,8 @@ impl From<ethjson::spec::Genesis> for Genesis {
|
||||
timestamp: g.timestamp.map_or(0, Into::into),
|
||||
parent_hash: g.parent_hash.map_or_else(H256::zero, Into::into),
|
||||
gas_limit: g.gas_limit.into(),
|
||||
transactions_root: g.transactions_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into),
|
||||
receipts_root: g.receipts_root.map_or_else(|| SHA3_NULL_RLP.clone(), Into::into),
|
||||
transactions_root: g.transactions_root.map_or_else(|| KECCAK_NULL_RLP.clone(), Into::into),
|
||||
receipts_root: g.receipts_root.map_or_else(|| KECCAK_NULL_RLP.clone(), Into::into),
|
||||
state_root: g.state_root.map(Into::into),
|
||||
gas_used: g.gas_used.map_or_else(U256::zero, Into::into),
|
||||
extra_data: g.extra_data.map_or_else(Vec::new, Into::into),
|
||||
|
@ -21,6 +21,7 @@ use std::collections::BTreeMap;
|
||||
use std::path::Path;
|
||||
use std::sync::Arc;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::{KECCAK_NULL_RLP, keccak};
|
||||
use super::genesis::Genesis;
|
||||
use super::seal::Generic as GenericSeal;
|
||||
|
||||
@ -38,6 +39,7 @@ use rlp::{Rlp, RlpStream};
|
||||
use state::{Backend, State, Substate};
|
||||
use state::backend::Basic as BasicBackend;
|
||||
use trace::{NoopTracer, NoopVMTracer};
|
||||
use parking_lot::RwLock;
|
||||
use util::*;
|
||||
|
||||
/// Parameters common to ethereum-like blockchains.
|
||||
@ -202,9 +204,9 @@ pub struct Spec {
|
||||
pub gas_used: U256,
|
||||
/// The genesis block's timestamp field.
|
||||
pub timestamp: u64,
|
||||
/// Transactions root of the genesis block. Should be SHA3_NULL_RLP.
|
||||
/// Transactions root of the genesis block. Should be KECCAK_NULL_RLP.
|
||||
pub transactions_root: H256,
|
||||
/// Receipts root of the genesis block. Should be SHA3_NULL_RLP.
|
||||
/// Receipts root of the genesis block. Should be KECCAK_NULL_RLP.
|
||||
pub receipts_root: H256,
|
||||
/// The genesis block's extra data field.
|
||||
pub extra_data: Bytes,
|
||||
@ -286,7 +288,7 @@ impl Spec {
|
||||
|
||||
// given a pre-constructor state, run all the given constructors and produce a new state and state root.
|
||||
fn run_constructors<T: Backend>(&self, factories: &Factories, mut db: T) -> Result<T, Error> {
|
||||
let mut root = SHA3_NULL_RLP;
|
||||
let mut root = KECCAK_NULL_RLP;
|
||||
|
||||
// basic accounts in spec.
|
||||
{
|
||||
@ -300,7 +302,7 @@ impl Spec {
|
||||
for (address, account) in self.genesis_state.get().iter() {
|
||||
db.note_non_null_account(address);
|
||||
account.insert_additional(
|
||||
&mut *factories.accountdb.create(db.as_hashdb_mut(), address.sha3()),
|
||||
&mut *factories.accountdb.create(db.as_hashdb_mut(), keccak(address)),
|
||||
&factories.trie
|
||||
);
|
||||
}
|
||||
@ -332,7 +334,7 @@ impl Spec {
|
||||
trace!(target: "spec", " .. root before = {}", state.root());
|
||||
let params = ActionParams {
|
||||
code_address: address.clone(),
|
||||
code_hash: Some(constructor.sha3()),
|
||||
code_hash: Some(keccak(constructor)),
|
||||
address: address.clone(),
|
||||
sender: from.clone(),
|
||||
origin: from.clone(),
|
||||
@ -398,7 +400,7 @@ impl Spec {
|
||||
header.set_number(0);
|
||||
header.set_author(self.author.clone());
|
||||
header.set_transactions_root(self.transactions_root.clone());
|
||||
header.set_uncles_hash(RlpStream::new_list(0).out().sha3());
|
||||
header.set_uncles_hash(keccak(RlpStream::new_list(0).out()));
|
||||
header.set_extra_data(self.extra_data.clone());
|
||||
header.set_state_root(self.state_root());
|
||||
header.set_receipts_root(self.receipts_root.clone());
|
||||
@ -485,7 +487,7 @@ impl Spec {
|
||||
/// Create a new Spec which conforms to the Frontier-era Morden chain except that it's a NullEngine consensus with applying reward on block close.
|
||||
pub fn new_test_with_reward() -> Spec { load_bundled!("null_morden_with_reward") }
|
||||
|
||||
/// Create a new Spec which is a NullEngine consensus with a premine of address whose secret is sha3('').
|
||||
/// Create a new Spec which is a NullEngine consensus with a premine of address whose secret is keccak('').
|
||||
pub fn new_null() -> Spec { load_bundled!("null") }
|
||||
|
||||
/// Create a new Spec which constructs a contract at address 5 with storage at 0 equal to 1.
|
||||
@ -495,15 +497,15 @@ impl Spec {
|
||||
pub fn new_instant() -> Spec { load_bundled!("instant_seal") }
|
||||
|
||||
/// Create a new Spec with AuthorityRound consensus which does internal sealing (not requiring work).
|
||||
/// Accounts with secrets "0".sha3() and "1".sha3() are the validators.
|
||||
/// Accounts with secrets keccak("0") and keccak("1") are the validators.
|
||||
pub fn new_test_round() -> Self { load_bundled!("authority_round") }
|
||||
|
||||
/// Create a new Spec with Tendermint consensus which does internal sealing (not requiring work).
|
||||
/// Account "0".sha3() and "1".sha3() are a authorities.
|
||||
/// Account keccak("0") and keccak("1") are a authorities.
|
||||
pub fn new_test_tendermint() -> Self { load_bundled!("tendermint") }
|
||||
|
||||
/// TestList.sol used in both specs: https://github.com/paritytech/contracts/pull/30/files
|
||||
/// Accounts with secrets "0".sha3() and "1".sha3() are initially the validators.
|
||||
/// Accounts with secrets keccak("0") and keccak("1") are initially the validators.
|
||||
/// Create a new Spec with BasicAuthority which uses a contract at address 5 to determine the current validators using `getValidators`.
|
||||
/// Second validator can be removed with "0xbfc708a000000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1" and added back in using "0x4d238c8e00000000000000000000000082a978b3f5962a5b0957d9ee9eef472ee55b42f1".
|
||||
pub fn new_validator_safe_contract() -> Self { load_bundled!("validator_safe_contract") }
|
||||
@ -514,7 +516,7 @@ impl Spec {
|
||||
pub fn new_validator_contract() -> Self { load_bundled!("validator_contract") }
|
||||
|
||||
/// Create a new Spec with BasicAuthority which uses multiple validator sets changing with height.
|
||||
/// Account with secrets "0".sha3() is the validator for block 1 and with "1".sha3() onwards.
|
||||
/// Account with secrets keccak("0") is the validator for block 1 and with keccak("1") onwards.
|
||||
pub fn new_validator_multi() -> Self { load_bundled!("validator_multi") }
|
||||
|
||||
/// Create a new spec for a PoW chain
|
||||
@ -542,7 +544,7 @@ mod tests {
|
||||
|
||||
assert_eq!(test_spec.state_root(), H256::from_str("f3f4696bbf3b3b07775128eb7a3763279a394e382130f27c21e70233e04946a9").unwrap());
|
||||
let genesis = test_spec.genesis_block();
|
||||
assert_eq!(BlockView::new(&genesis).header_view().sha3(), H256::from_str("0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303").unwrap());
|
||||
assert_eq!(BlockView::new(&genesis).header_view().hash(), H256::from_str("0cd786a2425d16f152c658316c423e6ce1181e15c3295826d7c9904cba9ce303").unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -19,6 +19,7 @@
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use std::collections::HashMap;
|
||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||
use util::*;
|
||||
use pod_account::*;
|
||||
use rlp::*;
|
||||
@ -81,10 +82,10 @@ impl Account {
|
||||
Account {
|
||||
balance: balance,
|
||||
nonce: nonce,
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
storage_cache: Self::empty_storage_cache(),
|
||||
storage_changes: storage,
|
||||
code_hash: code.sha3(),
|
||||
code_hash: keccak(&code),
|
||||
code_size: Some(code.len()),
|
||||
code_cache: Arc::new(code),
|
||||
code_filth: Filth::Dirty,
|
||||
@ -101,10 +102,10 @@ impl Account {
|
||||
Account {
|
||||
balance: pod.balance,
|
||||
nonce: pod.nonce,
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
storage_cache: Self::empty_storage_cache(),
|
||||
storage_changes: pod.storage.into_iter().collect(),
|
||||
code_hash: pod.code.as_ref().map_or(SHA3_EMPTY, |c| c.sha3()),
|
||||
code_hash: pod.code.as_ref().map_or(KECCAK_EMPTY, |c| keccak(c)),
|
||||
code_filth: Filth::Dirty,
|
||||
code_size: Some(pod.code.as_ref().map_or(0, |c| c.len())),
|
||||
code_cache: Arc::new(pod.code.map_or_else(|| { warn!("POD account with unknown code is being created! Assuming no code."); vec![] }, |c| c)),
|
||||
@ -117,10 +118,10 @@ impl Account {
|
||||
Account {
|
||||
balance: balance,
|
||||
nonce: nonce,
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
storage_cache: Self::empty_storage_cache(),
|
||||
storage_changes: HashMap::new(),
|
||||
code_hash: SHA3_EMPTY,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
code_cache: Arc::new(vec![]),
|
||||
code_size: Some(0),
|
||||
code_filth: Filth::Clean,
|
||||
@ -140,10 +141,10 @@ impl Account {
|
||||
Account {
|
||||
balance: balance,
|
||||
nonce: nonce,
|
||||
storage_root: SHA3_NULL_RLP,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
storage_cache: Self::empty_storage_cache(),
|
||||
storage_changes: HashMap::new(),
|
||||
code_hash: SHA3_EMPTY,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
code_cache: Arc::new(vec![]),
|
||||
code_size: None,
|
||||
code_filth: Filth::Clean,
|
||||
@ -154,7 +155,7 @@ impl Account {
|
||||
/// Set this account's code to the given code.
|
||||
/// NOTE: Account should have been created with `new_contract()`
|
||||
pub fn init_code(&mut self, code: Bytes) {
|
||||
self.code_hash = code.sha3();
|
||||
self.code_hash = keccak(&code);
|
||||
self.code_cache = Arc::new(code);
|
||||
self.code_size = Some(self.code_cache.len());
|
||||
self.code_filth = Filth::Dirty;
|
||||
@ -211,7 +212,7 @@ impl Account {
|
||||
pub fn address_hash(&self, address: &Address) -> H256 {
|
||||
let hash = self.address_hash.get();
|
||||
hash.unwrap_or_else(|| {
|
||||
let hash = address.sha3();
|
||||
let hash = keccak(address);
|
||||
self.address_hash.set(Some(hash.clone()));
|
||||
hash
|
||||
})
|
||||
@ -220,7 +221,7 @@ impl Account {
|
||||
/// returns the account's code. If `None` then the code cache isn't available -
|
||||
/// get someone who knows to call `note_code`.
|
||||
pub fn code(&self) -> Option<Arc<Bytes>> {
|
||||
if self.code_hash != SHA3_EMPTY && self.code_cache.is_empty() {
|
||||
if self.code_hash != KECCAK_EMPTY && self.code_cache.is_empty() {
|
||||
return None;
|
||||
}
|
||||
Some(self.code_cache.clone())
|
||||
@ -235,7 +236,7 @@ impl Account {
|
||||
#[cfg(test)]
|
||||
/// Provide a byte array which hashes to the `code_hash`. returns the hash as a result.
|
||||
pub fn note_code(&mut self, code: Bytes) -> Result<(), H256> {
|
||||
let h = code.sha3();
|
||||
let h = keccak(&code);
|
||||
if self.code_hash == h {
|
||||
self.code_cache = Arc::new(code);
|
||||
self.code_size = Some(self.code_cache.len());
|
||||
@ -247,7 +248,7 @@ impl Account {
|
||||
|
||||
/// Is `code_cache` valid; such that code is going to return Some?
|
||||
pub fn is_cached(&self) -> bool {
|
||||
!self.code_cache.is_empty() || (self.code_cache.is_empty() && self.code_hash == SHA3_EMPTY)
|
||||
!self.code_cache.is_empty() || (self.code_cache.is_empty() && self.code_hash == KECCAK_EMPTY)
|
||||
}
|
||||
|
||||
/// Provide a database to get `code_hash`. Should not be called if it is a contract without code.
|
||||
@ -284,7 +285,7 @@ impl Account {
|
||||
// TODO: fill out self.code_cache;
|
||||
trace!("Account::cache_code_size: ic={}; self.code_hash={:?}, self.code_cache={}", self.is_cached(), self.code_hash, self.code_cache.pretty());
|
||||
self.code_size.is_some() ||
|
||||
if self.code_hash != SHA3_EMPTY {
|
||||
if self.code_hash != KECCAK_EMPTY {
|
||||
match db.get(&self.code_hash) {
|
||||
Some(x) => {
|
||||
self.code_size = Some(x.len());
|
||||
@ -308,19 +309,19 @@ impl Account {
|
||||
/// NOTE: Will panic if `!self.storage_is_clean()`
|
||||
pub fn is_empty(&self) -> bool {
|
||||
assert!(self.storage_is_clean(), "Account::is_empty() may only legally be called when storage is clean.");
|
||||
self.is_null() && self.storage_root == SHA3_NULL_RLP
|
||||
self.is_null() && self.storage_root == KECCAK_NULL_RLP
|
||||
}
|
||||
|
||||
/// Check if account has zero nonce, balance, no code.
|
||||
pub fn is_null(&self) -> bool {
|
||||
self.balance.is_zero() &&
|
||||
self.nonce.is_zero() &&
|
||||
self.code_hash == SHA3_EMPTY
|
||||
self.code_hash == KECCAK_EMPTY
|
||||
}
|
||||
|
||||
/// Check if account is basic (Has no code).
|
||||
pub fn is_basic(&self) -> bool {
|
||||
self.code_hash == SHA3_EMPTY
|
||||
self.code_hash == KECCAK_EMPTY
|
||||
}
|
||||
|
||||
/// Return the storage root associated with this account or None if it has been altered via the overlay.
|
||||
@ -592,8 +593,8 @@ mod tests {
|
||||
assert_eq!(a.rlp().to_hex(), "f8448045a056e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421a0c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470");
|
||||
assert_eq!(a.balance(), &U256::from(69u8));
|
||||
assert_eq!(a.nonce(), &U256::from(0u8));
|
||||
assert_eq!(a.code_hash(), SHA3_EMPTY);
|
||||
assert_eq!(a.storage_root().unwrap(), &SHA3_NULL_RLP);
|
||||
assert_eq!(a.code_hash(), KECCAK_EMPTY);
|
||||
assert_eq!(a.storage_root().unwrap(), &KECCAK_NULL_RLP);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -25,7 +25,8 @@ use std::collections::{HashSet, HashMap};
|
||||
use std::sync::Arc;
|
||||
|
||||
use state::Account;
|
||||
use util::{Address, MemoryDB, Mutex, H256};
|
||||
use parking_lot::Mutex;
|
||||
use util::{Address, MemoryDB, H256};
|
||||
use util::hashdb::{AsHashDB, HashDB, DBValue};
|
||||
|
||||
/// State backend. See module docs for more details.
|
||||
|
@ -24,6 +24,7 @@ use std::collections::hash_map::Entry;
|
||||
use std::collections::{HashMap, BTreeMap, HashSet};
|
||||
use std::fmt;
|
||||
use std::sync::Arc;
|
||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY};
|
||||
|
||||
use receipt::Receipt;
|
||||
use engines::Engine;
|
||||
@ -590,7 +591,7 @@ impl<B: Backend> State<B> {
|
||||
/// Get an account's code hash.
|
||||
pub fn code_hash(&self, a: &Address) -> trie::Result<H256> {
|
||||
self.ensure_cached(a, RequireCache::None, true,
|
||||
|a| a.as_ref().map_or(SHA3_EMPTY, |a| a.code_hash()))
|
||||
|a| a.as_ref().map_or(KECCAK_EMPTY, |a| a.code_hash()))
|
||||
}
|
||||
|
||||
/// Get accounts' code size.
|
||||
@ -976,7 +977,7 @@ impl<B: Backend> State<B> {
|
||||
/// Returns a merkle proof of the account's trie node omitted or an encountered trie error.
|
||||
/// If the account doesn't exist in the trie, prove that and return defaults.
|
||||
/// Requires a secure trie to be used for accurate results.
|
||||
/// `account_key` == sha3(address)
|
||||
/// `account_key` == keccak(address)
|
||||
pub fn prove_account(&self, account_key: H256) -> trie::Result<(Vec<Bytes>, BasicAccount)> {
|
||||
let mut recorder = Recorder::new();
|
||||
let trie = TrieDB::new(self.db.as_hashdb(), &self.root)?;
|
||||
@ -987,8 +988,8 @@ impl<B: Backend> State<B> {
|
||||
let account = maybe_account.unwrap_or_else(|| BasicAccount {
|
||||
balance: 0.into(),
|
||||
nonce: self.account_start_nonce,
|
||||
code_hash: SHA3_EMPTY,
|
||||
storage_root: ::util::sha3::SHA3_NULL_RLP,
|
||||
code_hash: KECCAK_EMPTY,
|
||||
storage_root: KECCAK_NULL_RLP,
|
||||
});
|
||||
|
||||
Ok((recorder.drain().into_iter().map(|r| r.data).collect(), account))
|
||||
@ -997,11 +998,11 @@ impl<B: Backend> State<B> {
|
||||
/// Prove an account's storage key's existence or nonexistence in the state.
|
||||
/// Returns a merkle proof of the account's storage trie.
|
||||
/// Requires a secure trie to be used for correctness.
|
||||
/// `account_key` == sha3(address)
|
||||
/// `storage_key` == sha3(key)
|
||||
/// `account_key` == keccak(address)
|
||||
/// `storage_key` == keccak(key)
|
||||
pub fn prove_storage(&self, account_key: H256, storage_key: H256) -> trie::Result<(Vec<Bytes>, H256)> {
|
||||
// TODO: probably could look into cache somehow but it's keyed by
|
||||
// address, not sha3(address).
|
||||
// address, not keccak(address).
|
||||
let trie = TrieDB::new(self.db.as_hashdb(), &self.root)?;
|
||||
let acc = match trie.get_with(&account_key, Account::from_rlp)? {
|
||||
Some(acc) => acc,
|
||||
@ -1046,13 +1047,13 @@ impl Clone for State<StateDB> {
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use std::sync::Arc;
|
||||
use std::str::FromStr;
|
||||
use rustc_hex::FromHex;
|
||||
use hash::keccak;
|
||||
use super::*;
|
||||
use ethkey::Secret;
|
||||
use util::{U256, H256, Address, Hashable};
|
||||
use util::{U256, H256, Address};
|
||||
use tests::helpers::*;
|
||||
use vm::EnvInfo;
|
||||
use spec::*;
|
||||
@ -1062,7 +1063,7 @@ mod tests {
|
||||
use evm::CallType;
|
||||
|
||||
fn secret() -> Secret {
|
||||
"".sha3().into()
|
||||
keccak("").into()
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -24,7 +24,9 @@ use util::hash::{H256};
|
||||
use util::hashdb::HashDB;
|
||||
use state::{self, Account};
|
||||
use header::BlockNumber;
|
||||
use util::{Address, DBTransaction, UtilError, Mutex, Hashable};
|
||||
use hash::keccak;
|
||||
use parking_lot::Mutex;
|
||||
use util::{Address, DBTransaction, UtilError};
|
||||
use bloom_journal::{Bloom, BloomJournal};
|
||||
use db::COL_ACCOUNT_BLOOM;
|
||||
use byteorder::{LittleEndian, ByteOrder};
|
||||
@ -443,13 +445,13 @@ impl state::Backend for StateDB {
|
||||
fn note_non_null_account(&self, address: &Address) {
|
||||
trace!(target: "account_bloom", "Note account bloom: {:?}", address);
|
||||
let mut bloom = self.account_bloom.lock();
|
||||
bloom.set(&*address.sha3());
|
||||
bloom.set(&*keccak(address));
|
||||
}
|
||||
|
||||
fn is_known_null(&self, address: &Address) -> bool {
|
||||
trace!(target: "account_bloom", "Check account bloom: {:?}", address);
|
||||
let bloom = self.account_bloom.lock();
|
||||
let is_null = !bloom.check(&*address.sha3());
|
||||
let is_null = !bloom.check(&*keccak(address));
|
||||
is_null
|
||||
}
|
||||
}
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use io::IoChannel;
|
||||
use client::{BlockChainClient, MiningBlockChainClient, Client, ClientConfig, BlockId};
|
||||
use state::{self, State, CleanupMode};
|
||||
@ -254,7 +255,7 @@ fn can_mine() {
|
||||
|
||||
let b = client.prepare_open_block(Address::default(), (3141562.into(), 31415620.into()), vec![]).close();
|
||||
|
||||
assert_eq!(*b.block().header().parent_hash(), BlockView::new(&dummy_blocks[0]).header_view().sha3());
|
||||
assert_eq!(*b.block().header().parent_hash(), BlockView::new(&dummy_blocks[0]).header_view().hash());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -298,7 +299,7 @@ fn change_history_size() {
|
||||
|
||||
#[test]
|
||||
fn does_not_propagate_delayed_transactions() {
|
||||
let key = KeyPair::from_secret("test".sha3().into()).unwrap();
|
||||
let key = KeyPair::from_secret(keccak("test").into()).unwrap();
|
||||
let secret = key.secret();
|
||||
let tx0 = PendingTransaction::new(Transaction {
|
||||
nonce: 0.into(),
|
||||
|
@ -1,6 +1,7 @@
|
||||
//! Tests of EVM integration with transaction execution.
|
||||
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use vm::{EnvInfo, ActionParams, ActionValue, CallType};
|
||||
use evm::{Factory, VMType};
|
||||
use executive::Executive;
|
||||
@ -16,11 +17,11 @@ use util::*;
|
||||
evm_test!{test_blockhash_eip210: test_blockhash_eip210_jit, test_blockhash_eip210_int}
|
||||
fn test_blockhash_eip210(factory: Factory) {
|
||||
let get_prev_hash_code = Arc::new("600143034060205260206020f3".from_hex().unwrap()); // this returns previous block hash
|
||||
let get_prev_hash_code_hash = get_prev_hash_code.sha3();
|
||||
let get_prev_hash_code_hash = keccak(get_prev_hash_code.as_ref());
|
||||
// This is same as DEFAULT_BLOCKHASH_CONTRACT except for metropolis transition block check removed.
|
||||
let test_blockhash_contract = "73fffffffffffffffffffffffffffffffffffffffe33141561007a57600143036020526000356101006020510755600061010060205107141561005057600035610100610100602051050761010001555b6000620100006020510714156100755760003561010062010000602051050761020001555b61014a565b4360003512151561009057600060405260206040f35b610100600035430312156100b357610100600035075460605260206060f3610149565b62010000600035430312156100d157600061010060003507146100d4565b60005b156100f6576101006101006000350507610100015460805260206080f3610148565b630100000060003543031215610116576000620100006000350714610119565b60005b1561013c57610100620100006000350507610200015460a052602060a0f3610147565b600060c052602060c0f35b5b5b5b5b";
|
||||
let blockhash_contract_code = Arc::new(test_blockhash_contract.from_hex().unwrap());
|
||||
let blockhash_contract_code_hash = blockhash_contract_code.sha3();
|
||||
let blockhash_contract_code_hash = keccak(blockhash_contract_code.as_ref());
|
||||
let engine = TestEngine::new_metropolis();
|
||||
let mut env_info = EnvInfo::default();
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::Arc;
|
||||
use hash::keccak;
|
||||
use ethkey::KeyPair;
|
||||
use io::*;
|
||||
use client::{BlockChainClient, Client, ClientConfig};
|
||||
@ -178,7 +179,7 @@ pub fn generate_dummy_client_with_spec_accounts_and_data<F>(get_test_spec: F, ac
|
||||
let mut last_hashes = vec![];
|
||||
let mut last_header = genesis_header.clone();
|
||||
|
||||
let kp = KeyPair::from_secret_slice(&"".sha3()).unwrap();
|
||||
let kp = KeyPair::from_secret_slice(&keccak("")).unwrap();
|
||||
let author = kp.address();
|
||||
|
||||
let mut n = 0;
|
||||
|
@ -17,6 +17,7 @@
|
||||
//! Client tests of tracing
|
||||
|
||||
use ethkey::KeyPair;
|
||||
use hash::keccak;
|
||||
use block::*;
|
||||
use util::*;
|
||||
use io::*;
|
||||
@ -69,7 +70,7 @@ fn can_trace_block_and_uncle_reward() {
|
||||
let mut last_header = genesis_header.clone();
|
||||
last_hashes.push(last_header.hash());
|
||||
|
||||
let kp = KeyPair::from_secret_slice(&"".sha3()).unwrap();
|
||||
let kp = KeyPair::from_secret_slice(&keccak("")).unwrap();
|
||||
let author = kp.address();
|
||||
|
||||
// Add root block first
|
||||
|
@ -21,7 +21,8 @@ use std::sync::Arc;
|
||||
use bloomchain::{Number, Config as BloomConfig};
|
||||
use bloomchain::group::{BloomGroupDatabase, BloomGroupChain, GroupPosition, BloomGroup};
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{H256, H264, KeyValueDB, DBTransaction, RwLock};
|
||||
use parking_lot::RwLock;
|
||||
use util::{H256, H264, KeyValueDB, DBTransaction};
|
||||
use header::BlockNumber;
|
||||
use trace::{LocalizedTrace, Config, Filter, Database as TraceDatabase, ImportRequest, DatabaseExtras};
|
||||
use db::{self, Key, Writable, Readable, CacheUpdatePolicy};
|
||||
|
@ -18,8 +18,8 @@
|
||||
|
||||
use std::ops::Range;
|
||||
use bloomchain::{Filter as BloomFilter, Bloom, Number};
|
||||
use hash::keccak;
|
||||
use util::Address;
|
||||
use util::sha3::Hashable;
|
||||
use bloomable::Bloomable;
|
||||
use basic_types::LogBloom;
|
||||
use trace::flat::FlatTrace;
|
||||
@ -55,7 +55,7 @@ impl AddressesFilter {
|
||||
match self.list.is_empty() {
|
||||
true => vec![LogBloom::default()],
|
||||
false => self.list.iter()
|
||||
.map(|address| LogBloom::from_bloomed(&address.sha3()))
|
||||
.map(|address| LogBloom::from_bloomed(&keccak(address)))
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
@ -67,7 +67,7 @@ impl AddressesFilter {
|
||||
false => blooms
|
||||
.into_iter()
|
||||
.flat_map(|bloom| self.list.iter()
|
||||
.map(|address| bloom.with_bloomed(&address.sha3()))
|
||||
.map(|address| bloom.with_bloomed(&keccak(address)))
|
||||
.collect::<Vec<_>>())
|
||||
.collect(),
|
||||
}
|
||||
@ -139,7 +139,7 @@ impl Filter {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use util::Address;
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
use bloomable::Bloomable;
|
||||
use trace::trace::{Action, Call, Res, Create, CreateResult, Suicide, Reward};
|
||||
use trace::flat::FlatTrace;
|
||||
@ -169,9 +169,9 @@ mod tests {
|
||||
let blooms = filter.bloom_possibilities();
|
||||
assert_eq!(blooms.len(), 1);
|
||||
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(2))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(3))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -185,8 +185,8 @@ mod tests {
|
||||
let blooms = filter.bloom_possibilities();
|
||||
assert_eq!(blooms.len(), 1);
|
||||
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(2))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -200,8 +200,8 @@ mod tests {
|
||||
let blooms = filter.bloom_possibilities();
|
||||
assert_eq!(blooms.len(), 1);
|
||||
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(2))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
@ -215,25 +215,25 @@ mod tests {
|
||||
let blooms = filter.bloom_possibilities();
|
||||
assert_eq!(blooms.len(), 4);
|
||||
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(!blooms[0].contains_bloomed(&Address::from(4).sha3()));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(blooms[0].contains_bloomed(&keccak(Address::from(2))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(3))));
|
||||
assert!(!blooms[0].contains_bloomed(&keccak(Address::from(4))));
|
||||
|
||||
assert!(blooms[1].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(blooms[1].contains_bloomed(&Address::from(4).sha3()));
|
||||
assert!(!blooms[1].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(!blooms[1].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(blooms[1].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(blooms[1].contains_bloomed(&keccak(Address::from(4))));
|
||||
assert!(!blooms[1].contains_bloomed(&keccak(Address::from(2))));
|
||||
assert!(!blooms[1].contains_bloomed(&keccak(Address::from(3))));
|
||||
|
||||
assert!(blooms[2].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(blooms[2].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(!blooms[2].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(!blooms[2].contains_bloomed(&Address::from(4).sha3()));
|
||||
assert!(blooms[2].contains_bloomed(&keccak(Address::from(2))));
|
||||
assert!(blooms[2].contains_bloomed(&keccak(Address::from(3))));
|
||||
assert!(!blooms[2].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(!blooms[2].contains_bloomed(&keccak(Address::from(4))));
|
||||
|
||||
assert!(blooms[3].contains_bloomed(&Address::from(3).sha3()));
|
||||
assert!(blooms[3].contains_bloomed(&Address::from(4).sha3()));
|
||||
assert!(!blooms[3].contains_bloomed(&Address::from(1).sha3()));
|
||||
assert!(!blooms[3].contains_bloomed(&Address::from(2).sha3()));
|
||||
assert!(blooms[3].contains_bloomed(&keccak(Address::from(3))));
|
||||
assert!(blooms[3].contains_bloomed(&keccak(Address::from(4))));
|
||||
assert!(!blooms[3].contains_bloomed(&keccak(Address::from(1))));
|
||||
assert!(!blooms[3].contains_bloomed(&keccak(Address::from(2))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -17,7 +17,7 @@
|
||||
//! Tracing datatypes.
|
||||
|
||||
use util::{U256, Bytes, Address};
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
use bloomable::Bloomable;
|
||||
use rlp::*;
|
||||
|
||||
@ -51,7 +51,7 @@ pub struct CreateResult {
|
||||
impl CreateResult {
|
||||
/// Returns bloom.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.address.sha3())
|
||||
LogBloom::from_bloomed(&keccak(&self.address))
|
||||
}
|
||||
}
|
||||
|
||||
@ -90,8 +90,8 @@ impl Call {
|
||||
/// Returns call action bloom.
|
||||
/// The bloom contains from and to addresses.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.from.sha3())
|
||||
.with_bloomed(&self.to.sha3())
|
||||
LogBloom::from_bloomed(&keccak(&self.from))
|
||||
.with_bloomed(&keccak(&self.to))
|
||||
}
|
||||
}
|
||||
|
||||
@ -124,7 +124,7 @@ impl Create {
|
||||
/// Returns bloom create action bloom.
|
||||
/// The bloom contains only from address.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.from.sha3())
|
||||
LogBloom::from_bloomed(&keccak(&self.from))
|
||||
}
|
||||
}
|
||||
|
||||
@ -173,7 +173,7 @@ pub struct Reward {
|
||||
impl Reward {
|
||||
/// Return reward action bloom.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.author.sha3())
|
||||
LogBloom::from_bloomed(&keccak(&self.author))
|
||||
}
|
||||
}
|
||||
|
||||
@ -214,8 +214,8 @@ pub struct Suicide {
|
||||
impl Suicide {
|
||||
/// Return suicide action bloom.
|
||||
pub fn bloom(&self) -> LogBloom {
|
||||
LogBloom::from_bloomed(&self.address.sha3())
|
||||
.with_bloomed(&self.refund_address.sha3())
|
||||
LogBloom::from_bloomed(&keccak(self.address))
|
||||
.with_bloomed(&keccak(self.refund_address))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -18,7 +18,7 @@
|
||||
|
||||
use std::ops::Deref;
|
||||
use rlp::*;
|
||||
use util::sha3::Hashable;
|
||||
use hash::keccak;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::{H256, Address, U256, Bytes};
|
||||
use ethkey::{Signature, Secret, Public, recover, public_to_address, Error as EthkeyError};
|
||||
@ -167,7 +167,7 @@ impl Transaction {
|
||||
pub fn hash(&self, chain_id: Option<u64>) -> H256 {
|
||||
let mut stream = RlpStream::new();
|
||||
self.rlp_append_unsigned_transaction(&mut stream, chain_id);
|
||||
stream.as_raw().sha3()
|
||||
keccak(stream.as_raw())
|
||||
}
|
||||
|
||||
/// Signs the transaction as coming from `sender`.
|
||||
@ -274,7 +274,7 @@ impl Decodable for UnverifiedTransaction {
|
||||
if d.item_count()? != 9 {
|
||||
return Err(DecoderError::RlpIncorrectListLen);
|
||||
}
|
||||
let hash = d.as_raw().sha3();
|
||||
let hash = keccak(d.as_raw());
|
||||
Ok(UnverifiedTransaction {
|
||||
unsigned: Transaction {
|
||||
nonce: d.val_at(0)?,
|
||||
@ -299,7 +299,7 @@ impl Encodable for UnverifiedTransaction {
|
||||
impl UnverifiedTransaction {
|
||||
/// Used to compute hash of created transactions
|
||||
fn compute_hash(mut self) -> UnverifiedTransaction {
|
||||
let hash = (&*self.rlp_bytes()).sha3();
|
||||
let hash = keccak(&*self.rlp_bytes());
|
||||
self.hash = hash;
|
||||
self
|
||||
}
|
||||
@ -357,7 +357,7 @@ impl UnverifiedTransaction {
|
||||
}
|
||||
}
|
||||
|
||||
/// Get the hash of this header (sha3 of the RLP).
|
||||
/// Get the hash of this header (keccak of the RLP).
|
||||
pub fn hash(&self) -> H256 {
|
||||
self.hash
|
||||
}
|
||||
@ -545,7 +545,8 @@ impl From<SignedTransaction> for PendingTransaction {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use util::{Hashable, U256};
|
||||
use util::{U256};
|
||||
use hash::keccak;
|
||||
|
||||
#[test]
|
||||
fn sender_test() {
|
||||
@ -575,7 +576,7 @@ mod tests {
|
||||
value: U256::from(1),
|
||||
data: b"Hello!".to_vec()
|
||||
}.sign(&key.secret(), None);
|
||||
assert_eq!(Address::from(key.public().sha3()), t.sender());
|
||||
assert_eq!(Address::from(keccak(key.public())), t.sender());
|
||||
assert_eq!(t.chain_id(), None);
|
||||
}
|
||||
|
||||
@ -609,7 +610,7 @@ mod tests {
|
||||
value: U256::from(1),
|
||||
data: b"Hello!".to_vec()
|
||||
}.sign(&key.secret(), Some(69));
|
||||
assert_eq!(Address::from(key.public().sha3()), t.sender());
|
||||
assert_eq!(Address::from(keccak(key.public())), t.sender());
|
||||
assert_eq!(t.chain_id(), Some(69));
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ use std::sync::{Condvar as SCondvar, Mutex as SMutex, Arc};
|
||||
use std::cmp;
|
||||
use std::collections::{VecDeque, HashSet, HashMap};
|
||||
use heapsize::HeapSizeOf;
|
||||
use parking_lot::{Condvar, Mutex, RwLock};
|
||||
use util::*;
|
||||
use io::*;
|
||||
use error::*;
|
||||
|
@ -22,6 +22,8 @@
|
||||
//! 3. Final verification against the blockchain done before enactment.
|
||||
|
||||
use std::collections::HashSet;
|
||||
use hash::keccak;
|
||||
use triehash::ordered_trie_root;
|
||||
use heapsize::HeapSizeOf;
|
||||
use util::*;
|
||||
use engines::Engine;
|
||||
@ -257,7 +259,7 @@ fn verify_block_integrity(block: &[u8], transactions_root: &H256, uncles_hash: &
|
||||
if expected_root != transactions_root {
|
||||
return Err(From::from(BlockError::InvalidTransactionsRoot(Mismatch { expected: expected_root.clone(), found: transactions_root.clone() })))
|
||||
}
|
||||
let expected_uncles = &block.at(2)?.as_raw().sha3();
|
||||
let expected_uncles = &keccak(block.at(2)?.as_raw());
|
||||
if expected_uncles != uncles_hash {
|
||||
return Err(From::from(BlockError::InvalidUnclesHash(Mismatch { expected: expected_uncles.clone(), found: uncles_hash.clone() })))
|
||||
}
|
||||
@ -267,6 +269,8 @@ fn verify_block_integrity(block: &[u8], transactions_root: &H256, uncles_hash: &
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::collections::{BTreeMap, HashMap};
|
||||
use hash::keccak;
|
||||
use triehash::ordered_trie_root;
|
||||
use util::*;
|
||||
use ethkey::{Random, Generator};
|
||||
use header::*;
|
||||
@ -325,7 +329,7 @@ mod tests {
|
||||
|
||||
pub fn insert(&mut self, bytes: Bytes) {
|
||||
let number = BlockView::new(&bytes).header_view().number();
|
||||
let hash = BlockView::new(&bytes).header_view().sha3();
|
||||
let hash = BlockView::new(&bytes).header_view().hash();
|
||||
self.blocks.insert(hash.clone(), bytes);
|
||||
self.numbers.insert(number, hash.clone());
|
||||
}
|
||||
@ -483,7 +487,7 @@ mod tests {
|
||||
let good_uncles = vec![ good_uncle1.clone(), good_uncle2.clone() ];
|
||||
let mut uncles_rlp = RlpStream::new();
|
||||
uncles_rlp.append_list(&good_uncles);
|
||||
let good_uncles_hash = uncles_rlp.as_raw().sha3();
|
||||
let good_uncles_hash = keccak(uncles_rlp.as_raw());
|
||||
let good_transactions_root = ordered_trie_root(good_transactions.iter().map(|t| ::rlp::encode::<UnverifiedTransaction>(t).into_vec()));
|
||||
|
||||
let mut parent = good.clone();
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
//! View onto block rlp.
|
||||
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use header::*;
|
||||
use transaction::*;
|
||||
@ -44,7 +45,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Block header hash.
|
||||
pub fn hash(&self) -> H256 {
|
||||
self.sha3()
|
||||
self.header_view().hash()
|
||||
}
|
||||
|
||||
/// Return reference to underlaying rlp.
|
||||
@ -75,7 +76,7 @@ impl<'a> BlockView<'a> {
|
||||
/// Return List of transactions with additional localization info.
|
||||
pub fn localized_transactions(&self) -> Vec<LocalizedTransaction> {
|
||||
let header = self.header_view();
|
||||
let block_hash = header.sha3();
|
||||
let block_hash = header.hash();
|
||||
let block_number = header.number();
|
||||
self.transactions()
|
||||
.into_iter()
|
||||
@ -101,7 +102,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return transaction hashes.
|
||||
pub fn transaction_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(1).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(1).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Returns transaction at given index without deserializing unnecessary data.
|
||||
@ -112,7 +113,7 @@ impl<'a> BlockView<'a> {
|
||||
/// Returns localized transaction at given index.
|
||||
pub fn localized_transaction_at(&self, index: usize) -> Option<LocalizedTransaction> {
|
||||
let header = self.header_view();
|
||||
let block_hash = header.sha3();
|
||||
let block_hash = header.hash();
|
||||
let block_number = header.number();
|
||||
self.transaction_at(index).map(|t| LocalizedTransaction {
|
||||
signed: t,
|
||||
@ -140,7 +141,7 @@ impl<'a> BlockView<'a> {
|
||||
|
||||
/// Return list of uncle hashes of given block.
|
||||
pub fn uncle_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(2).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(2).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Return nth uncle.
|
||||
@ -154,12 +155,6 @@ impl<'a> BlockView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Hashable for BlockView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.header_view().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
//! View onto block body rlp.
|
||||
|
||||
use hash::keccak;
|
||||
use util::*;
|
||||
use header::*;
|
||||
use transaction::*;
|
||||
@ -78,7 +79,7 @@ impl<'a> BodyView<'a> {
|
||||
|
||||
/// Return transaction hashes.
|
||||
pub fn transaction_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(0).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(0).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Returns transaction at given index without deserializing unnecessary data.
|
||||
@ -114,7 +115,7 @@ impl<'a> BodyView<'a> {
|
||||
|
||||
/// Return list of uncle hashes of given block.
|
||||
pub fn uncle_hashes(&self) -> Vec<H256> {
|
||||
self.rlp.at(1).iter().map(|rlp| rlp.as_raw().sha3()).collect()
|
||||
self.rlp.at(1).iter().map(|rlp| keccak(rlp.as_raw())).collect()
|
||||
}
|
||||
|
||||
/// Return nth uncle.
|
||||
|
@ -16,7 +16,8 @@
|
||||
|
||||
//! View onto block header rlp
|
||||
|
||||
use util::{U256, Bytes, Hashable, H256, Address, H2048};
|
||||
use hash::keccak;
|
||||
use util::{U256, Bytes, H256, Address, H2048};
|
||||
use rlp::Rlp;
|
||||
use header::BlockNumber;
|
||||
|
||||
@ -41,7 +42,9 @@ impl<'a> HeaderView<'a> {
|
||||
}
|
||||
|
||||
/// Returns header hash.
|
||||
pub fn hash(&self) -> H256 { self.sha3() }
|
||||
pub fn hash(&self) -> H256 {
|
||||
keccak(self.rlp.as_raw())
|
||||
}
|
||||
|
||||
/// Returns raw rlp.
|
||||
pub fn rlp(&self) -> &Rlp<'a> { &self.rlp }
|
||||
@ -95,12 +98,6 @@ impl<'a> HeaderView<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> Hashable for HeaderView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.rlp.as_raw().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
@ -15,7 +15,8 @@
|
||||
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
//! View onto transaction rlp
|
||||
use util::{U256, Bytes, Hashable, H256};
|
||||
use util::{U256, Bytes, H256};
|
||||
use hash::keccak;
|
||||
use rlp::Rlp;
|
||||
|
||||
/// View onto transaction rlp.
|
||||
@ -43,6 +44,11 @@ impl<'a> TransactionView<'a> {
|
||||
&self.rlp
|
||||
}
|
||||
|
||||
/// Returns transaction hash.
|
||||
pub fn hash(&self) -> H256 {
|
||||
keccak(self.rlp.as_raw())
|
||||
}
|
||||
|
||||
/// Get the nonce field of the transaction.
|
||||
pub fn nonce(&self) -> U256 { self.rlp.val_at(0) }
|
||||
|
||||
@ -68,12 +74,6 @@ impl<'a> TransactionView<'a> {
|
||||
pub fn s(&self) -> U256 { self.rlp.val_at(8) }
|
||||
}
|
||||
|
||||
impl<'a> Hashable for TransactionView<'a> {
|
||||
fn sha3(&self) -> H256 {
|
||||
self.rlp.as_raw().sha3()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::str::FromStr;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user