Update to latest mem-db, hash-db and trie-db. (#10314)

* Switch to 'trie' crates, there is an unpublished deps to staging
parity-common triehash still.

* Use crates.io dependency.

* indentation

* Update util/journaldb/src/traits.rs

indentation

Co-Authored-By: cheme <emericchevalier.pro@gmail.com>

* Update ethcore/src/snapshot/tests/state.rs

Co-Authored-By: cheme <emericchevalier.pro@gmail.com>
This commit is contained in:
cheme 2019-02-20 19:09:34 +01:00 committed by Andronik Ordian
parent 4e0ec4e66b
commit 6bb106a784
43 changed files with 473 additions and 404 deletions

95
Cargo.lock generated
View File

@ -718,7 +718,7 @@ dependencies = [
"ethkey 0.3.0",
"evm 0.1.0",
"fetch 0.1.0",
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)",
"itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"journaldb 0.2.0",
@ -733,7 +733,7 @@ dependencies = [
"lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"macros 0.1.0",
"memory-cache 0.1.0",
"memorydb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -742,7 +742,6 @@ dependencies = [
"parity-runtime 0.1.0",
"parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie-ethereum 0.1.0",
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
@ -755,6 +754,7 @@ dependencies = [
"stats 0.1.0",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"trace-time 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-standardmap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"triehash-ethereum 0.2.0",
"unexpected 0.1.0",
@ -870,19 +870,19 @@ dependencies = [
"failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fastmap 0.1.0",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)",
"itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
"journaldb 0.2.0",
"keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hasher 0.1.1",
"kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-cache 0.1.0",
"memorydb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie-ethereum 0.1.0",
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -892,6 +892,7 @@ dependencies = [
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
"stats 0.1.0",
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"triehash-ethereum 0.2.0",
"vm 0.1.0",
]
@ -1025,7 +1026,6 @@ dependencies = [
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-crypto 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie-ethereum 0.1.0",
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1036,6 +1036,7 @@ dependencies = [
"serde_json 1.0.32 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"transaction-pool 1.13.3 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -1130,7 +1131,7 @@ dependencies = [
"ethkey 0.3.0",
"ethstore 0.2.1",
"fastmap 0.1.0",
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)",
"keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hasher 0.1.1",
@ -1540,8 +1541,8 @@ dependencies = [
]
[[package]]
name = "hashdb"
version = "0.3.0"
name = "hash-db"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@ -1809,14 +1810,14 @@ dependencies = [
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fastmap 0.1.0",
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)",
"keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hasher 0.1.1",
"kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb-memorydb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"memorydb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -1937,7 +1938,7 @@ name = "keccak-hasher"
version = "0.1.1"
dependencies = [
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -2142,22 +2143,20 @@ dependencies = [
"lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memory-db"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)",
]
[[package]]
name = "memory_units"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memorydb"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)",
"plain_hasher 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "memzero"
version = "0.1.0"
@ -2678,7 +2677,6 @@ dependencies = [
"parity-updater 1.12.0",
"parity-version 2.4.0",
"parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie 0.3.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.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
@ -2693,6 +2691,7 @@ dependencies = [
"tokio-timer 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"transaction-pool 1.13.3 (registry+https://github.com/rust-lang/crates.io-index)",
"transient-hashmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"vm 0.1.0",
]
@ -2902,31 +2901,20 @@ dependencies = [
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "patricia-trie"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.3.9 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "patricia-trie-ethereum"
version = "0.1.0"
dependencies = [
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"journaldb 0.2.0",
"keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hasher 0.1.1",
"memorydb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -4079,6 +4067,17 @@ dependencies = [
"protobuf 1.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "trie-db"
version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "trie-standardmap"
version = "0.1.1"
@ -4092,10 +4091,10 @@ dependencies = [
[[package]]
name = "triehash"
version = "0.3.0"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@ -4105,7 +4104,7 @@ version = "0.2.0"
dependencies = [
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hasher 0.1.1",
"triehash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"triehash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -4281,9 +4280,9 @@ dependencies = [
"keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"patricia-trie-ethereum 0.1.0",
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@ -4553,7 +4552,7 @@ dependencies = [
"checksum h2 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "a27e7ed946e8335bdf9a191bc1b9b14a03ba822d013d2f58437f4fabcbd7fc2c"
"checksum hamming 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "65043da274378d68241eb9a8f8f8aa54e349136f7b8e12f63e3ef44043cc30e1"
"checksum handlebars 0.32.4 (registry+https://github.com/rust-lang/crates.io-index)" = "d89ec99d1594f285d4590fc32bac5f75cdab383f1123d504d27862c644a807dd"
"checksum hashdb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d91261ee336dd046ac7df28306cb297b7a7228bd1ae25e9a57f4ed5e0ab628c7"
"checksum hash-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1b03501f6e1a2a97f1618879aba3156f14ca2847faa530c4e28859638bd11483"
"checksum heapsize 0.4.2 (git+https://github.com/cheme/heapsize.git?branch=ec-macfix)" = "<none>"
"checksum heck 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ea04fa3ead4e05e51a7c806fc07271fdbde4e246a6c6d1efd52e72230b771b82"
"checksum hex 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "d6a22814455d41612f41161581c2883c0c6a1c41852729b17d5ed88f01e153aa"
@ -4613,8 +4612,8 @@ dependencies = [
"checksum memchr 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "4b3629fe9fdbff6daa6c33b90f7c08355c1aca05a3d01fa8063b822fcf185f3b"
"checksum memmap 0.6.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e2ffa2c986de11a9df78620c01eeaaf27d94d3ff02bf81bfcca953102dd0c6ff"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum memory-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94da53143d45f6bad3753f532e56ad57a6a26c0ca6881794583310c7cb4c885f"
"checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882"
"checksum memorydb 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e143fbad9f90d2158bca3c4b09015276a6de6f085a77088943901cb26828780f"
"checksum mime 0.3.12 (registry+https://github.com/rust-lang/crates.io-index)" = "0a907b83e7b9e987032439a387e187119cddafc92d5c2aaeb1d92580a793f630"
"checksum mime_guess 2.0.0-alpha.6 (registry+https://github.com/rust-lang/crates.io-index)" = "30de2e4613efcba1ec63d8133f344076952090c122992a903359be5a4f99c3ed"
"checksum mio 0.6.16 (registry+https://github.com/rust-lang/crates.io-index)" = "71646331f2619b1026cc302f87a2b8b648d5c6dd6937846a16cc8ce0f347f432"
@ -4657,7 +4656,6 @@ dependencies = [
"checksum parking_lot 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "9723236a9525c757d9725b993511e3fc941e33f27751942232f0058298297edf"
"checksum parking_lot_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ad7f7e6ebdc79edff6fdcb87a55b620174f7a989e3eb31b65231f4af57f00b8c"
"checksum parking_lot_core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "94c8c7923936b28d546dfd14d4472eaf34c99b14e1c973a32b3e6d4eb04298c9"
"checksum patricia-trie 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "10438ba40c2f6e9ceca55277d8e7f6a5dafd58cabd802e6d97e16f02aab83a03"
"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831"
"checksum pest 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)" = "0fce5d8b5cc33983fc74f78ad552b5522ab41442c4ca91606e4236eb4b5ceefc"
"checksum pest_derive 1.0.8 (registry+https://github.com/rust-lang/crates.io-index)" = "ca3294f437119209b084c797604295f40227cffa35c57220b1e99a6ff3bf8ee4"
@ -4783,8 +4781,9 @@ dependencies = [
"checksum transaction-pool 1.13.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e5866e5126b14358f1d7af4bf51a0be677a363799b90e655edcec8254edef1d2"
"checksum transient-hashmap 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "aeb4b191d033a35edfce392a38cdcf9790b6cebcb30fa690c312c29da4dc433e"
"checksum trezor-sys 1.0.0 (git+https://github.com/paritytech/trezor-sys)" = "<none>"
"checksum trie-db 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c7319e28ca295f27359d944a682f7f65b419158bf1590c92cadc0000258d788"
"checksum trie-standardmap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0e26f52976a57a0859616d6fcec87092ac35d08eabbd78dc3dabee93b480ea5f"
"checksum triehash 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cd9cb3a626dd9a19a1b5f84087143b19409db793d902c5ddee4b6212020713f1"
"checksum triehash 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "0d26efb4ddf87870fc08dc9a6580dc3061be350d7b9d0eb30aef1c8b4227aa46"
"checksum try-lock 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ee2aa4715743892880f70885373966c83d73ef1b0838a664ef0c76fffd35e7c2"
"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"

View File

@ -30,7 +30,7 @@ ethereum-types = "0.4"
ethjson = { path = "../json" }
ethkey = { path = "../accounts/ethkey" }
evm = { path = "evm" }
hashdb = "0.3.0"
hash-db = "0.11.0"
heapsize = "0.4"
itertools = "0.5"
journaldb = { path = "../util/journaldb" }
@ -45,7 +45,7 @@ log = "0.4"
lru-cache = "0.1"
macros = { path = "../util/macros" }
memory-cache = { path = "../util/memory-cache" }
memorydb = "0.3.0"
memory-db = "0.11.0"
num = { version = "0.1", default-features = false, features = ["bigint"] }
num_cpus = "1.2"
parity-bytes = "0.1"
@ -53,7 +53,7 @@ parity-crypto = "0.3.0"
parity-machine = { path = "../machine" }
parity-snappy = "0.1"
parking_lot = "0.7"
patricia-trie = "0.3.0"
trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
rand = "0.4"
rayon = "1.0"

View File

@ -14,12 +14,12 @@ ethcore = { path = ".."}
ethcore-db = { path = "../db" }
ethcore-blockchain = { path = "../blockchain" }
ethereum-types = "0.4"
memorydb = "0.3.0"
patricia-trie = "0.3.0"
memory-db = "0.11.0"
trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
ethcore-network = { path = "../../util/network" }
ethcore-io = { path = "../../util/io" }
hashdb = "0.3.0"
hash-db = "0.11.0"
heapsize = "0.4"
vm = { path = "../vm" }
fastmap = { path = "../../util/fastmap" }
@ -41,6 +41,7 @@ triehash-ethereum = { version = "0.2", path = "../../util/triehash-ethereum" }
kvdb = "0.1"
memory-cache = { path = "../../util/memory-cache" }
error-chain = { version = "0.12", default-features = false }
journaldb = { path = "../../util/journaldb" }
[dev-dependencies]
ethcore = { path = "..", features = ["test-helpers"] }

View File

@ -25,10 +25,11 @@
use common_types::ids::BlockId;
use ethereum_types::{H256, U256};
use hashdb::HashDB;
use hash_db::HashDB;
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;
use memorydb::MemoryDB;
use memory_db::MemoryDB;
use journaldb::new_memory_db;
use bytes::Bytes;
use trie::{TrieMut, Trie, Recorder};
use ethtrie::{self, TrieDB, TrieDBMut};
@ -73,7 +74,8 @@ impl<DB: HashDB<KeccakHasher, DBValue>> CHT<DB> {
if block_to_cht_number(num) != Some(self.number) { return Ok(None) }
let mut recorder = Recorder::with_depth(from_level);
let t = TrieDB::new(&self.db, &self.root)?;
let db: &HashDB<_,_> = &self.db;
let t = TrieDB::new(&db, &self.root)?;
t.get_with(&key!(num), &mut recorder)?;
Ok(Some(recorder.drain().into_iter().map(|x| x.data).collect()))
@ -96,7 +98,7 @@ pub struct BlockInfo {
pub fn build<F>(cht_num: u64, mut fetcher: F) -> Option<CHT<MemoryDB<KeccakHasher, DBValue>>>
where F: FnMut(BlockId) -> Option<BlockInfo>
{
let mut db = MemoryDB::<KeccakHasher, DBValue>::new();
let mut db = new_memory_db();
// start from the last block by number and work backwards.
let last_num = start_number(cht_num + 1) - 1;
@ -150,7 +152,7 @@ pub fn compute_root<I>(cht_num: u64, iterable: I) -> Option<H256>
/// verify the given trie branch and extract the canonical hash and total difficulty.
// TODO: better support for partially-checked queries.
pub fn check_proof(proof: &[Bytes], num: u64, root: H256) -> Option<(H256, U256)> {
let mut db = MemoryDB::<KeccakHasher, DBValue>::new();
let mut db = new_memory_db();
for node in proof { db.insert(&node[..]); }
let res = match TrieDB::new(&db, &root) {

View File

@ -62,14 +62,14 @@ extern crate ethcore_network as network;
extern crate parity_bytes as bytes;
extern crate ethereum_types;
extern crate ethcore;
extern crate hashdb;
extern crate hash_db;
extern crate heapsize;
extern crate failsafe;
extern crate futures;
extern crate itertools;
extern crate keccak_hasher;
extern crate memorydb;
extern crate patricia_trie as trie;
extern crate memory_db;
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate fastmap;
extern crate rand;
@ -92,3 +92,4 @@ extern crate error_chain;
extern crate kvdb_memorydb;
#[cfg(test)]
extern crate tempdir;
extern crate journaldb;

View File

@ -30,9 +30,8 @@ use ethcore::state::{self, ProvedExecution};
use ethereum_types::{H256, U256, Address};
use ethtrie::{TrieError, TrieDB};
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak};
use hashdb::HashDB;
use hash_db::HashDB;
use kvdb::DBValue;
use memorydb::MemoryDB;
use parking_lot::Mutex;
use request::{self as net_request, IncompleteRequest, CompleteRequest, Output, OutputKind, Field};
use rlp::{RlpStream, Rlp};
@ -981,7 +980,7 @@ impl Account {
let header = self.header.as_ref()?;
let state_root = header.state_root();
let mut db = MemoryDB::new();
let mut db = journaldb::new_memory_db();
for node in proof { db.insert(&node[..]); }
match TrieDB::new(&db, &state_root).and_then(|t| t.get(&keccak(&self.address)))? {
@ -1101,7 +1100,6 @@ mod tests {
use super::*;
use std::time::Duration;
use ethereum_types::{H256, Address};
use memorydb::MemoryDB;
use parking_lot::Mutex;
use trie::{Trie, TrieMut};
use ethtrie::{SecTrieDB, SecTrieDBMut};
@ -1281,7 +1279,7 @@ mod tests {
use rlp::RlpStream;
let mut root = H256::default();
let mut db = MemoryDB::new();
let mut db = journaldb::new_memory_db();
let mut header = Header::new();
header.set_number(123_456);
header.set_extra_data(b"test_header".to_vec());

View File

@ -26,7 +26,7 @@ log = "0.4"
parity-bytes = "0.1"
parity-crypto = "0.3.0"
parking_lot = "0.7"
patricia-trie = "0.3.0"
trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
rand = "0.3"
rlp = { version = "0.3.0", features = ["ethereum"] }

View File

@ -42,7 +42,7 @@ extern crate keccak_hash as hash;
extern crate parity_bytes as bytes;
extern crate parity_crypto as crypto;
extern crate parking_lot;
extern crate patricia_trie as trie;
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate rlp;
extern crate rustc_hex;

View File

@ -17,11 +17,10 @@
//! DB backend wrapper for Account trie
use ethereum_types::H256;
use hash::{KECCAK_NULL_RLP, keccak};
use hashdb::{HashDB, AsHashDB};
use hash_db::{HashDB, AsHashDB};
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;
use rlp::NULL_RLP;
use std::collections::HashMap;
#[cfg(test)]
use ethereum_types::Address;
@ -99,15 +98,11 @@ impl<'db> AccountDB<'db> {
}
impl<'db> AsHashDB<KeccakHasher, DBValue> for AccountDB<'db> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl<'db> HashDB<KeccakHasher, DBValue> for AccountDB<'db> {
fn keys(&self) -> HashMap<H256, i32> {
unimplemented!()
}
fn get(&self, key: &H256) -> Option<DBValue> {
if key == &KECCAK_NULL_RLP {
return Some(DBValue::from_slice(&NULL_RLP));
@ -163,10 +158,6 @@ impl<'db> AccountDBMut<'db> {
}
impl<'db> HashDB<KeccakHasher, DBValue> for AccountDBMut<'db>{
fn keys(&self) -> HashMap<H256, i32> {
unimplemented!()
}
fn get(&self, key: &H256) -> Option<DBValue> {
if key == &KECCAK_NULL_RLP {
return Some(DBValue::from_slice(&NULL_RLP));
@ -209,22 +200,18 @@ impl<'db> HashDB<KeccakHasher, DBValue> for AccountDBMut<'db>{
}
impl<'db> AsHashDB<KeccakHasher, DBValue> for AccountDBMut<'db> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
struct Wrapping<'db>(&'db HashDB<KeccakHasher, DBValue>);
impl<'db> AsHashDB<KeccakHasher, DBValue> for Wrapping<'db> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl<'db> HashDB<KeccakHasher, DBValue> for Wrapping<'db> {
fn keys(&self) -> HashMap<H256, i32> {
unimplemented!()
}
fn get(&self, key: &H256) -> Option<DBValue> {
if key == &KECCAK_NULL_RLP {
return Some(DBValue::from_slice(&NULL_RLP));
@ -254,15 +241,11 @@ impl<'db> HashDB<KeccakHasher, DBValue> for Wrapping<'db> {
struct WrappingMut<'db>(&'db mut HashDB<KeccakHasher, DBValue>);
impl<'db> AsHashDB<KeccakHasher, DBValue> for WrappingMut<'db> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl<'db> HashDB<KeccakHasher, DBValue> for WrappingMut<'db>{
fn keys(&self) -> HashMap<H256, i32> {
unimplemented!()
}
fn get(&self, key: &H256) -> Option<DBValue> {
if key == &KECCAK_NULL_RLP {
return Some(DBValue::from_slice(&NULL_RLP));

View File

@ -624,7 +624,7 @@ impl Importer {
let call = move |addr, data| {
let mut state_db = state_db.boxed_clone();
let backend = ::state::backend::Proving::new(state_db.as_hashdb_mut());
let backend = ::state::backend::Proving::new(state_db.as_hash_db_mut());
let transaction =
client.contract_call_tx(BlockId::Hash(*header.parent_hash()), addr, data);
@ -1176,7 +1176,7 @@ impl Client {
};
let processing_threads = self.config.snapshot.processing_threads;
snapshot::take_snapshot(&*self.engine, &self.chain.read(), start_hash, db.as_hashdb(), writer, p, processing_threads)?;
snapshot::take_snapshot(&*self.engine, &self.chain.read(), start_hash, db.as_hash_db(), writer, p, processing_threads)?;
Ok(())
}
@ -1781,7 +1781,8 @@ impl BlockChainClient for Client {
};
let (root, db) = state.drop();
let trie = match self.factories.trie.readonly(db.as_hashdb(), &root) {
let db = &db.as_hash_db();
let trie = match self.factories.trie.readonly(db, &root) {
Ok(trie) => trie,
_ => {
trace!(target: "fatdb", "list_accounts: Couldn't open the DB");
@ -1827,8 +1828,9 @@ impl BlockChainClient for Client {
};
let (_, db) = state.drop();
let account_db = self.factories.accountdb.readonly(db.as_hashdb(), keccak(account));
let trie = match self.factories.trie.readonly(account_db.as_hashdb(), &root) {
let account_db = &self.factories.accountdb.readonly(db.as_hash_db(), keccak(account));
let account_db = &account_db.as_hash_db();
let trie = match self.factories.trie.readonly(account_db, &root) {
Ok(trie) => trie,
_ => {
trace!(target: "fatdb", "list_storage: Couldn't open the DB");
@ -2499,7 +2501,7 @@ impl ProvingBlockChainClient for Client {
let mut jdb = self.state_db.read().journal_db().boxed_clone();
state::prove_transaction_virtual(
jdb.as_hashdb_mut(),
jdb.as_hash_db_mut(),
header.state_root().clone(),
&transaction,
self.engine.machine(),

View File

@ -18,9 +18,6 @@ use ethjson;
use trie::{TrieFactory, TrieSpec};
use ethtrie::RlpCodec;
use ethereum_types::H256;
use memorydb::MemoryDB;
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;
use super::HookType;
@ -37,7 +34,7 @@ fn test_trie<H: FnMut(&str, HookType)>(json: &[u8], trie: TrieSpec, start_stop_h
for (name, test) in tests.into_iter() {
start_stop_hook(&name, HookType::OnStart);
let mut memdb = MemoryDB::<KeccakHasher, DBValue>::new();
let mut memdb = journaldb::new_memory_db();
let mut root = H256::default();
let mut t = factory.create(&mut memdb, &mut root);

View File

@ -73,7 +73,7 @@ extern crate ethcore_miner;
extern crate ethereum_types;
extern crate ethjson;
extern crate ethkey;
extern crate hashdb;
extern crate hash_db;
extern crate heapsize;
extern crate itertools;
extern crate journaldb;
@ -84,7 +84,7 @@ extern crate kvdb_memorydb;
extern crate len_caching_lock;
extern crate lru_cache;
extern crate memory_cache;
extern crate memorydb;
extern crate memory_db;
extern crate num;
extern crate num_cpus;
extern crate parity_bytes as bytes;
@ -92,7 +92,7 @@ extern crate parity_crypto;
extern crate parity_machine;
extern crate parity_snappy as snappy;
extern crate parking_lot;
extern crate patricia_trie as trie;
extern crate trie_db as trie;
extern crate patricia_trie_ethereum as ethtrie;
extern crate rand;
extern crate rayon;

View File

@ -21,7 +21,7 @@ use std::collections::BTreeMap;
use itertools::Itertools;
use hash::{keccak};
use ethereum_types::{H256, U256};
use hashdb::HashDB;
use hash_db::HashDB;
use kvdb::DBValue;
use keccak_hasher::KeccakHasher;
use triehash::sec_trie_root;

View File

@ -22,7 +22,7 @@ use bytes::Bytes;
use ethereum_types::{H256, U256};
use ethtrie::{TrieDB, TrieDBMut};
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP};
use hashdb::HashDB;
use hash_db::HashDB;
use rlp::{RlpStream, Rlp};
use snapshot::Error;
use std::collections::HashSet;
@ -66,7 +66,8 @@ impl CodeState {
// account address hash, account properties and the storage. Each item contains at most `max_storage_items`
// storage records split according to snapshot format definition.
pub fn to_fat_rlps(account_hash: &H256, acc: &BasicAccount, acct_db: &AccountDB, used_code: &mut HashSet<H256>, first_chunk_size: usize, max_chunk_size: usize) -> Result<Vec<Bytes>, Error> {
let db = TrieDB::new(acct_db, &acc.storage_root)?;
let db = &(acct_db as &HashDB<_,_>);
let db = TrieDB::new(db, &acc.storage_root)?;
let mut chunks = Vec::new();
let mut db_iter = db.iter()?;
let mut target_chunk_size = first_chunk_size;
@ -213,7 +214,7 @@ mod tests {
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
use ethereum_types::{H256, Address};
use hashdb::HashDB;
use hash_db::HashDB;
use kvdb::DBValue;
use rlp::Rlp;
@ -236,9 +237,9 @@ mod tests {
let thin_rlp = ::rlp::encode(&account);
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), account);
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_rlps = to_fat_rlps(&keccak(&addr), &account, &AccountDB::new(db.as_hash_db(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
let fat_rlp = Rlp::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);
assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hash_db_mut(), &addr), fat_rlp, H256::zero()).unwrap().0, account);
}
#[test]
@ -247,7 +248,7 @@ mod tests {
let addr = Address::random();
let account = {
let acct_db = AccountDBMut::new(db.as_hashdb_mut(), &addr);
let acct_db = AccountDBMut::new(db.as_hash_db_mut(), &addr);
let mut root = KECCAK_NULL_RLP;
fill_storage(acct_db, &mut root, &mut H256::zero());
BasicAccount {
@ -261,9 +262,9 @@ mod tests {
let thin_rlp = ::rlp::encode(&account);
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), account);
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 = to_fat_rlps(&keccak(&addr), &account, &AccountDB::new(db.as_hash_db(), &addr), &mut Default::default(), usize::max_value(), usize::max_value()).unwrap();
let fat_rlp = Rlp::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);
assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hash_db_mut(), &addr), fat_rlp, H256::zero()).unwrap().0, account);
}
#[test]
@ -272,7 +273,7 @@ mod tests {
let addr = Address::random();
let account = {
let acct_db = AccountDBMut::new(db.as_hashdb_mut(), &addr);
let acct_db = AccountDBMut::new(db.as_hash_db_mut(), &addr);
let mut root = KECCAK_NULL_RLP;
fill_storage(acct_db, &mut root, &mut H256::zero());
BasicAccount {
@ -286,12 +287,12 @@ mod tests {
let thin_rlp = ::rlp::encode(&account);
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), account);
let fat_rlps = to_fat_rlps(&keccak(addr), &account, &AccountDB::new(db.as_hashdb(), &addr), &mut Default::default(), 500, 1000).unwrap();
let fat_rlps = to_fat_rlps(&keccak(addr), &account, &AccountDB::new(db.as_hash_db(), &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 = Rlp::new(&rlp).at(1).unwrap();
restored_account = Some(from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr), fat_rlp, root).unwrap().0);
restored_account = Some(from_fat_rlp(&mut AccountDBMut::new(db.as_hash_db_mut(), &addr), fat_rlp, root).unwrap().0);
root = restored_account.as_ref().unwrap().storage_root.clone();
}
assert_eq!(restored_account, Some(account));
@ -305,12 +306,12 @@ mod tests {
let addr2 = Address::random();
let code_hash = {
let mut acct_db = AccountDBMut::new(db.as_hashdb_mut(), &addr1);
let mut acct_db = AccountDBMut::new(db.as_hash_db_mut(), &addr1);
acct_db.insert(b"this is definitely code")
};
{
let mut acct_db = AccountDBMut::new(db.as_hashdb_mut(), &addr2);
let mut acct_db = AccountDBMut::new(db.as_hash_db_mut(), &addr2);
acct_db.emplace(code_hash.clone(), DBValue::from_slice(b"this is definitely code"));
}
@ -330,18 +331,18 @@ mod tests {
let mut used_code = HashSet::new();
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();
let fat_rlp1 = to_fat_rlps(&keccak(&addr1), &account1, &AccountDB::new(db.as_hash_db(), &addr1), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
let fat_rlp2 = to_fat_rlps(&keccak(&addr2), &account2, &AccountDB::new(db.as_hash_db(), &addr2), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
assert_eq!(used_code.len(), 1);
let fat_rlp1 = Rlp::new(&fat_rlp1[0]).at(1).unwrap();
let fat_rlp2 = Rlp::new(&fat_rlp2[0]).at(1).unwrap();
let (acc, maybe_code) = from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr2), fat_rlp2, H256::zero()).unwrap();
let (acc, maybe_code) = from_fat_rlp(&mut AccountDBMut::new(db.as_hash_db_mut(), &addr2), fat_rlp2, H256::zero()).unwrap();
assert!(maybe_code.is_none());
assert_eq!(acc, account2);
let (acc, maybe_code) = from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &addr1), fat_rlp1, H256::zero()).unwrap();
let (acc, maybe_code) = from_fat_rlp(&mut AccountDBMut::new(db.as_hash_db_mut(), &addr1), fat_rlp1, H256::zero()).unwrap();
assert_eq!(maybe_code, Some(b"this is definitely code".to_vec()));
assert_eq!(acc, account1);
}
@ -349,6 +350,6 @@ mod tests {
#[test]
fn encoding_empty_acc() {
let mut db = get_temp_state_db();
assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hashdb_mut(), &Address::default()), Rlp::new(&::rlp::NULL_RLP), H256::zero()).unwrap(), (ACC_EMPTY, None));
assert_eq!(from_fat_rlp(&mut AccountDBMut::new(db.as_hash_db_mut(), &Address::default()), Rlp::new(&::rlp::NULL_RLP), H256::zero()).unwrap(), (ACC_EMPTY, None));
}
}

View File

@ -32,7 +32,7 @@ use types::header::Header;
use types::ids::BlockId;
use ethereum_types::{H256, U256};
use hashdb::HashDB;
use hash_db::HashDB;
use keccak_hasher::KeccakHasher;
use snappy;
use bytes::Bytes;
@ -322,7 +322,7 @@ impl<'a> StateChunker<'a> {
/// Returns a list of hashes of chunks created, or any error it may
/// have encountered.
pub fn chunk_state<'a>(db: &HashDB<KeccakHasher, DBValue>, root: &H256, writer: &Mutex<SnapshotWriter + 'a>, progress: &'a Progress, part: Option<usize>) -> Result<Vec<H256>, Error> {
let account_trie = TrieDB::new(db, &root)?;
let account_trie = TrieDB::new(&db, &root)?;
let mut chunker = StateChunker {
hashes: Vec::new(),
@ -414,7 +414,7 @@ impl StateRebuilder {
pairs.resize(rlp.item_count()?, (H256::new(), Vec::new()));
let status = rebuild_accounts(
self.db.as_hashdb_mut(),
self.db.as_hash_db_mut(),
rlp,
&mut pairs,
&self.known_code,
@ -429,7 +429,7 @@ impl StateRebuilder {
// patch up all missing code. must be done after collecting all new missing code entries.
for (code_hash, code, first_with) in status.new_code {
for addr_hash in self.missing_code.remove(&code_hash).unwrap_or_else(Vec::new) {
let mut db = AccountDBMut::from_hash(self.db.as_hashdb_mut(), addr_hash);
let mut db = AccountDBMut::from_hash(self.db.as_hash_db_mut(), addr_hash);
db.emplace(code_hash, DBValue::from_slice(&code));
}
@ -441,9 +441,9 @@ impl StateRebuilder {
// batch trie writes
{
let mut account_trie = if self.state_root != KECCAK_NULL_RLP {
TrieDBMut::from_existing(self.db.as_hashdb_mut(), &mut self.state_root)?
TrieDBMut::from_existing(self.db.as_hash_db_mut(), &mut self.state_root)?
} else {
TrieDBMut::new(self.db.as_hashdb_mut(), &mut self.state_root)
TrieDBMut::new(self.db.as_hash_db_mut(), &mut self.state_root)
};
for (hash, thin_rlp) in pairs {

View File

@ -35,7 +35,7 @@ use rand::Rng;
use kvdb::DBValue;
use ethereum_types::H256;
use hashdb::HashDB;
use hash_db::HashDB;
use keccak_hasher::KeccakHasher;
use journaldb;
use trie::{TrieMut, Trie};
@ -65,7 +65,7 @@ impl StateProducer {
pub fn tick<R: Rng>(&mut self, rng: &mut R, db: &mut HashDB<KeccakHasher, DBValue>) {
// modify existing accounts.
let mut accounts_to_modify: Vec<_> = {
let trie = TrieDB::new(&*db, &self.state_root).unwrap();
let trie = TrieDB::new(&db, &self.state_root).unwrap();
let temp = trie.iter().unwrap() // binding required due to complicated lifetime stuff
.filter(|_| rng.gen::<f32>() < ACCOUNT_CHURN)
.map(Result::unwrap)
@ -130,15 +130,6 @@ pub fn fill_storage(mut db: AccountDBMut, root: &mut H256, seed: &mut H256) {
}
}
/// Compare two state dbs.
pub fn compare_dbs(one: &HashDB<KeccakHasher, DBValue>, two: &HashDB<KeccakHasher, DBValue>) {
let keys = one.keys();
for key in keys.keys() {
assert_eq!(one.get(&key).unwrap(), two.get(&key).unwrap());
}
}
/// Take a snapshot from the given client into a temporary file.
/// Return a snapshot reader for it.
pub fn snap(client: &Client) -> (Box<SnapshotReader>, TempDir) {

View File

@ -184,7 +184,7 @@ fn keep_ancient_blocks() {
let start_header = bc.block_header_data(&best_hash).unwrap();
let state_root = start_header.state_root();
let state_hashes = chunk_state(
state_db.as_hashdb(),
state_db.as_hash_db(),
&state_root,
&writer,
&Progress::default(),

View File

@ -24,7 +24,7 @@ use types::basic_account::BasicAccount;
use snapshot::account;
use snapshot::{chunk_state, Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS};
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter};
use super::helpers::{compare_dbs, StateProducer};
use super::helpers::StateProducer;
use error::{Error, ErrorKind};
@ -32,15 +32,15 @@ use rand::{XorShiftRng, SeedableRng};
use ethereum_types::H256;
use journaldb::{self, Algorithm};
use kvdb_rocksdb::{Database, DatabaseConfig};
use memorydb::MemoryDB;
use parking_lot::Mutex;
use tempdir::TempDir;
#[test]
fn snap_and_restore() {
use hash_db::HashDB;
let mut producer = StateProducer::new();
let mut rng = XorShiftRng::from_seed([1, 2, 3, 4]);
let mut old_db = MemoryDB::new();
let mut old_db = journaldb::new_memory_db();
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
for _ in 0..150 {
@ -91,8 +91,11 @@ fn snap_and_restore() {
let new_db = journaldb::new(db, Algorithm::OverlayRecent, ::db::COL_STATE);
assert_eq!(new_db.earliest_era(), Some(1000));
let keys = old_db.keys();
compare_dbs(&old_db, new_db.as_hashdb());
for key in keys.keys() {
assert_eq!(old_db.get(&key).unwrap(), new_db.as_hash_db().get(&key).unwrap());
}
}
#[test]
@ -100,7 +103,7 @@ fn get_code_from_prev_chunk() {
use std::collections::HashSet;
use rlp::RlpStream;
use ethereum_types::{H256, U256};
use hashdb::HashDB;
use hash_db::HashDB;
use account_db::{AccountDBMut, AccountDB};
@ -121,7 +124,7 @@ fn get_code_from_prev_chunk() {
let acc: BasicAccount = ::rlp::decode(&thin_rlp).expect("error decoding basic account");
let mut make_chunk = |acc, hash| {
let mut db = MemoryDB::new();
let mut db = journaldb::new_memory_db();
AccountDBMut::from_hash(&mut db, hash).insert(&code[..]);
let fat_rlp = account::to_fat_rlps(&hash, &acc, &AccountDB::from_hash(&db, hash), &mut used_code, usize::max_value(), usize::max_value()).unwrap();
@ -155,7 +158,7 @@ fn get_code_from_prev_chunk() {
fn checks_flag() {
let mut producer = StateProducer::new();
let mut rng = XorShiftRng::from_seed([5, 6, 7, 8]);
let mut old_db = MemoryDB::new();
let mut old_db = journaldb::new_memory_db();
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
for _ in 0..10 {

View File

@ -25,7 +25,6 @@ use bytes::Bytes;
use ethereum_types::{H256, Bloom, U256, Address};
use ethjson;
use hash::{KECCAK_NULL_RLP, keccak};
use memorydb::MemoryDB;
use parking_lot::RwLock;
use rlp::{Rlp, RlpStream};
use rustc_hex::{FromHex, ToHex};
@ -556,7 +555,7 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
None => {
let _ = s.run_constructors(
&Default::default(),
BasicBackend(MemoryDB::new()),
BasicBackend(journaldb::new_memory_db()),
)?;
}
}
@ -624,7 +623,7 @@ impl Spec {
// basic accounts in spec.
{
let mut t = factories.trie.create(db.as_hashdb_mut(), &mut root);
let mut t = factories.trie.create(db.as_hash_db_mut(), &mut root);
for (address, account) in self.genesis_state.get().iter() {
t.insert(&**address, &account.rlp())?;
@ -635,7 +634,7 @@ impl Spec {
db.note_non_null_account(address);
account.insert_additional(
&mut *factories.accountdb.create(
db.as_hashdb_mut(),
db.as_hash_db_mut(),
keccak(address),
),
&factories.trie,
@ -792,7 +791,7 @@ impl Spec {
self.genesis_state = s;
let _ = self.run_constructors(
&Default::default(),
BasicBackend(MemoryDB::new()),
BasicBackend(journaldb::new_memory_db()),
)?;
Ok(())
@ -813,7 +812,7 @@ impl Spec {
/// Ensure that the given state DB has the trie nodes in for the genesis state.
pub fn ensure_db_good<T: Backend>(&self, db: T, factories: &Factories) -> Result<T, Error> {
if db.as_hashdb().contains(&self.state_root()) {
if db.as_hash_db().contains(&self.state_root()) {
return Ok(db);
}
@ -860,7 +859,7 @@ impl Spec {
None,
);
self.ensure_db_good(BasicBackend(db.as_hashdb_mut()), &factories)
self.ensure_db_good(BasicBackend(db.as_hash_db_mut()), &factories)
.map_err(|e| format!("Unable to initialize genesis state: {}", e))?;
let call = |a, d| {
@ -886,7 +885,7 @@ impl Spec {
}.fake_sign(from);
let res = ::state::prove_transaction_virtual(
db.as_hashdb_mut(),
db.as_hash_db_mut(),
*genesis.state_root(),
&tx,
self.engine.machine(),

View File

@ -22,7 +22,7 @@ use std::collections::{HashMap, BTreeMap};
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
use ethereum_types::{H256, U256, Address};
use error::Error;
use hashdb::HashDB;
use hash_db::HashDB;
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;
use bytes::{Bytes, ToPretty};
@ -253,7 +253,7 @@ impl Account {
}
fn get_and_cache_storage(storage_root: &H256, storage_cache: &mut LruCache<H256, H256>, db: &HashDB<KeccakHasher, DBValue>, key: &H256) -> TrieResult<H256> {
let db = SecTrieDB::new(db, storage_root)?;
let db = SecTrieDB::new(&db, storage_root)?;
let panicky_decoder = |bytes:&[u8]| ::rlp::decode(&bytes).expect("decoding db value failed");
let item: U256 = db.get_with(key, panicky_decoder)?.unwrap_or_else(U256::zero);
let value: H256 = item.into();
@ -591,7 +591,7 @@ impl Account {
pub fn prove_storage(&self, db: &HashDB<KeccakHasher, DBValue>, storage_key: H256) -> TrieResult<(Vec<Bytes>, H256)> {
let mut recorder = Recorder::new();
let trie = TrieDB::new(db, &self.storage_root)?;
let trie = TrieDB::new(&db, &self.storage_root)?;
let item: U256 = {
let panicky_decoder = |bytes:&[u8]| ::rlp::decode(bytes).expect("decoding db value failed");
let query = (&mut recorder, panicky_decoder);
@ -617,7 +617,7 @@ impl fmt::Debug for Account {
mod tests {
use rlp_compress::{compress, decompress, snapshot_swapper};
use ethereum_types::{H256, Address};
use memorydb::MemoryDB;
use journaldb::new_memory_db;
use bytes::Bytes;
use super::*;
use account_db::*;
@ -633,7 +633,7 @@ mod tests {
#[test]
fn storage_at() {
let mut db = MemoryDB::new();
let mut db = new_memory_db();
let mut db = AccountDBMut::new(&mut db, &Address::new());
let rlp = {
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
@ -652,7 +652,7 @@ mod tests {
#[test]
fn note_code() {
let mut db = MemoryDB::new();
let mut db = new_memory_db();
let mut db = AccountDBMut::new(&mut db, &Address::new());
let rlp = {
@ -672,7 +672,7 @@ mod tests {
#[test]
fn commit_storage() {
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
let mut db = MemoryDB::new();
let mut db = new_memory_db();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.set_storage(0.into(), 0x1234.into());
assert_eq!(a.storage_root(), None);
@ -683,7 +683,7 @@ mod tests {
#[test]
fn commit_remove_commit_storage() {
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
let mut db = MemoryDB::new();
let mut db = new_memory_db();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.set_storage(0.into(), 0x1234.into());
a.commit_storage(&Default::default(), &mut db).unwrap();
@ -697,7 +697,7 @@ mod tests {
#[test]
fn commit_code() {
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
let mut db = MemoryDB::new();
let mut db = new_memory_db();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.init_code(vec![0x55, 0x44, 0xffu8]);
assert_eq!(a.code_filth, Filth::Dirty);
@ -709,7 +709,7 @@ mod tests {
#[test]
fn reset_code() {
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
let mut db = MemoryDB::new();
let mut db = new_memory_db();
let mut db = AccountDBMut::new(&mut db, &Address::new());
a.init_code(vec![0x55, 0x44, 0xffu8]);
assert_eq!(a.code_filth, Filth::Dirty);

View File

@ -27,18 +27,19 @@ use std::sync::Arc;
use state::Account;
use parking_lot::Mutex;
use ethereum_types::{Address, H256};
use memorydb::MemoryDB;
use hashdb::{AsHashDB, HashDB};
use memory_db::MemoryDB;
use hash_db::{AsHashDB, HashDB};
use kvdb::DBValue;
use keccak_hasher::KeccakHasher;
use journaldb::AsKeyedHashDB;
/// State backend. See module docs for more details.
pub trait Backend: Send {
/// Treat the backend as a read-only hashdb.
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue>;
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue>;
/// Treat the backend as a writeable hashdb.
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue>;
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue>;
/// Add an account entry to the cache.
fn add_to_account_cache(&mut self, addr: Address, data: Option<Account>, modified: bool);
@ -82,14 +83,17 @@ pub struct ProofCheck(MemoryDB<KeccakHasher, DBValue>);
impl ProofCheck {
/// Create a new `ProofCheck` backend from the given state items.
pub fn new(proof: &[DBValue]) -> Self {
let mut db = MemoryDB::<KeccakHasher, DBValue>::new();
let mut db = journaldb::new_memory_db();
for item in proof { db.insert(item); }
ProofCheck(db)
}
}
impl HashDB<KeccakHasher, DBValue> for ProofCheck {
impl journaldb::KeyedHashDB for ProofCheck {
fn keys(&self) -> HashMap<H256, i32> { self.0.keys() }
}
impl HashDB<KeccakHasher, DBValue> for ProofCheck {
fn get(&self, key: &H256) -> Option<DBValue> {
self.0.get(key)
}
@ -110,13 +114,13 @@ impl HashDB<KeccakHasher, DBValue> for ProofCheck {
}
impl AsHashDB<KeccakHasher, DBValue> for ProofCheck {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl Backend for ProofCheck {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn add_to_account_cache(&mut self, _addr: Address, _data: Option<Account>, _modified: bool) {}
fn cache_code(&self, _hash: H256, _code: Arc<Vec<u8>>) {}
fn get_cached_account(&self, _addr: &Address) -> Option<Option<Account>> { None }
@ -135,26 +139,32 @@ impl Backend for ProofCheck {
/// The proof-of-execution can be extracted with `extract_proof`.
///
/// This doesn't cache anything or rely on the canonical state caches.
pub struct Proving<H: AsHashDB<KeccakHasher, DBValue>> {
pub struct Proving<H> {
base: H, // state we're proving values from.
changed: MemoryDB<KeccakHasher, DBValue>, // changed state via insertions.
proof: Mutex<HashSet<DBValue>>,
}
impl<AH: AsHashDB<KeccakHasher, DBValue> + Send + Sync> AsHashDB<KeccakHasher, DBValue> for Proving<AH> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
impl<AH: AsKeyedHashDB + Send + Sync> AsKeyedHashDB for Proving<AH> {
fn as_keyed_hash_db(&self) -> &journaldb::KeyedHashDB { self }
}
impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> HashDB<KeccakHasher, DBValue> for Proving<H> {
impl<AH: AsHashDB<KeccakHasher, DBValue> + Send + Sync> AsHashDB<KeccakHasher, DBValue> for Proving<AH> {
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl<H: AsKeyedHashDB + Send + Sync> journaldb::KeyedHashDB for Proving<H> {
fn keys(&self) -> HashMap<H256, i32> {
let mut keys = self.base.as_hashdb().keys();
let mut keys = self.base.as_keyed_hash_db().keys();
keys.extend(self.changed.keys());
keys
}
}
impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> HashDB<KeccakHasher, DBValue> for Proving<H> {
fn get(&self, key: &H256) -> Option<DBValue> {
match self.base.as_hashdb().get(key) {
match self.base.as_hash_db().get(key) {
Some(val) => {
self.proof.lock().insert(val.clone());
Some(val)
@ -184,9 +194,9 @@ impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> HashDB<KeccakHasher, DBVa
}
impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> Backend for Proving<H> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn add_to_account_cache(&mut self, _: Address, _: Option<Account>, _: bool) { }
@ -211,7 +221,7 @@ impl<H: AsHashDB<KeccakHasher, DBValue>> Proving<H> {
pub fn new(base: H) -> Self {
Proving {
base: base,
changed: MemoryDB::<KeccakHasher, DBValue>::new(),
changed: journaldb::new_memory_db(),
proof: Mutex::new(HashSet::new()),
}
}
@ -238,12 +248,12 @@ impl<H: AsHashDB<KeccakHasher, DBValue> + Clone> Clone for Proving<H> {
pub struct Basic<H>(pub H);
impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> Backend for Basic<H> {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> {
self.0.as_hashdb()
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> {
self.0.as_hash_db()
}
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
self.0.as_hashdb_mut()
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
self.0.as_hash_db_mut()
}
fn add_to_account_cache(&mut self, _: Address, _: Option<Account>, _: bool) { }

View File

@ -43,7 +43,7 @@ use state_db::StateDB;
use factory::VmFactory;
use ethereum_types::{H256, U256, Address};
use hashdb::{HashDB, AsHashDB};
use hash_db::{HashDB, AsHashDB};
use keccak_hasher::KeccakHasher;
use kvdb::DBValue;
use bytes::Bytes;
@ -366,7 +366,7 @@ impl<B: Backend> State<B> {
let mut root = H256::new();
{
// init trie and reset root to null
let _ = factories.trie.create(db.as_hashdb_mut(), &mut root);
let _ = factories.trie.create(db.as_hash_db_mut(), &mut root);
}
State {
@ -381,7 +381,7 @@ impl<B: Backend> State<B> {
/// Creates new state with existing state root
pub fn from_existing(db: B, root: H256, account_start_nonce: U256, factories: Factories) -> TrieResult<State<B>> {
if !db.as_hashdb().contains(&root) {
if !db.as_hash_db().contains(&root) {
return Err(Box::new(TrieError::InvalidStateRoot(root)));
}
@ -665,8 +665,8 @@ impl<B: Backend> State<B> {
let trie_res = self.db.get_cached(address, |acc| match acc {
None => Ok(H256::new()),
Some(a) => {
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), a.address_hash(address));
f_at(a, account_db.as_hashdb(), key)
let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), a.address_hash(address));
f_at(a, account_db.as_hash_db(), key)
}
});
@ -677,8 +677,8 @@ impl<B: Backend> State<B> {
// otherwise cache the account localy and cache storage key there.
if let Some(ref mut acc) = local_account {
if let Some(ref account) = acc.account {
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(address));
return f_at(account, account_db.as_hashdb(), key)
let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), account.address_hash(address));
return f_at(account, account_db.as_hash_db(), key)
} else {
return Ok(H256::new())
}
@ -689,12 +689,13 @@ impl<B: Backend> State<B> {
if self.db.is_known_null(address) { return Ok(H256::zero()) }
// account is not found in the global cache, get from the DB and insert into local
let db = self.factories.trie.readonly(self.db.as_hashdb(), &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
let db = &self.db.as_hash_db();
let db = self.factories.trie.readonly(db, &self.root).expect(SEC_TRIE_DB_UNWRAP_STR);
let from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed");
let maybe_acc = db.get_with(address, from_rlp)?;
let r = maybe_acc.as_ref().map_or(Ok(H256::new()), |a| {
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), a.address_hash(address));
f_at(a, account_db.as_hashdb(), key)
let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), a.address_hash(address));
f_at(a, account_db.as_hash_db(), key)
});
self.insert_cache(address, AccountEntry::new_clean(maybe_acc));
r
@ -887,9 +888,9 @@ impl<B: Backend> State<B> {
if let Some(ref mut account) = a.account {
let addr_hash = account.address_hash(address);
{
let mut account_db = self.factories.accountdb.create(self.db.as_hashdb_mut(), addr_hash);
account.commit_storage(&self.factories.trie, account_db.as_hashdb_mut())?;
account.commit_code(account_db.as_hashdb_mut());
let mut account_db = self.factories.accountdb.create(self.db.as_hash_db_mut(), addr_hash);
account.commit_storage(&self.factories.trie, account_db.as_hash_db_mut())?;
account.commit_code(account_db.as_hash_db_mut());
}
if !account.is_empty() {
self.db.note_non_null_account(address);
@ -898,7 +899,7 @@ impl<B: Backend> State<B> {
}
{
let mut trie = self.factories.trie.from_existing(self.db.as_hashdb_mut(), &mut self.root)?;
let mut trie = self.factories.trie.from_existing(self.db.as_hash_db_mut(), &mut self.root)?;
for (address, ref mut a) in accounts.iter_mut().filter(|&(_, ref a)| a.is_dirty()) {
a.state = AccountState::Committed;
match a.account {
@ -981,7 +982,8 @@ impl<B: Backend> State<B> {
let mut result = BTreeMap::new();
let trie = self.factories.trie.readonly(self.db.as_hashdb(), &self.root)?;
let db = &self.db.as_hash_db();
let trie = self.factories.trie.readonly(db, &self.root)?;
// put trie in cache
for item in trie.iter()? {
@ -1011,10 +1013,11 @@ impl<B: Backend> State<B> {
fn account_to_pod_account(&self, account: &Account, address: &Address) -> Result<PodAccount, Error> {
let mut pod_storage = BTreeMap::new();
let addr_hash = account.address_hash(address);
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), addr_hash);
let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), addr_hash);
let root = account.base_storage_root();
let trie = self.factories.trie.readonly(accountdb.as_hashdb(), &root)?;
let accountdb = &accountdb.as_hash_db();
let trie = self.factories.trie.readonly(accountdb, &root)?;
for o_kv in trie.iter()? {
if let Ok((key, val)) = o_kv {
pod_storage.insert(key[..].into(), U256::from(&val[..]).into());
@ -1134,8 +1137,8 @@ impl<B: Backend> State<B> {
// check local cache first
if let Some(ref mut maybe_acc) = self.cache.borrow_mut().get_mut(a) {
if let Some(ref mut account) = maybe_acc.account {
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
if Self::update_account_cache(require, account, &self.db, accountdb.as_hashdb()) {
let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), account.address_hash(a));
if Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) {
return Ok(f(Some(account)));
} else {
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))));
@ -1146,8 +1149,8 @@ impl<B: Backend> State<B> {
// check global cache
let result = self.db.get_cached(a, |mut acc| {
if let Some(ref mut account) = acc {
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
if !Self::update_account_cache(require, account, &self.db, accountdb.as_hashdb()) {
let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), account.address_hash(a));
if !Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) {
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))));
}
}
@ -1160,12 +1163,13 @@ impl<B: Backend> State<B> {
if check_null && self.db.is_known_null(a) { return Ok(f(None)); }
// not found in the global cache, get from the DB and insert into local
let db = self.factories.trie.readonly(self.db.as_hashdb(), &self.root)?;
let db = &self.db.as_hash_db();
let db = self.factories.trie.readonly(db, &self.root)?;
let from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed");
let mut maybe_acc = db.get_with(a, from_rlp)?;
if let Some(ref mut account) = maybe_acc.as_mut() {
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
if !Self::update_account_cache(require, account, &self.db, accountdb.as_hashdb()) {
let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), account.address_hash(a));
if !Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) {
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))));
}
}
@ -1192,7 +1196,8 @@ impl<B: Backend> State<B> {
Some(acc) => self.insert_cache(a, AccountEntry::new_clean_cached(acc)),
None => {
let maybe_acc = if !self.db.is_known_null(a) {
let db = self.factories.trie.readonly(self.db.as_hashdb(), &self.root)?;
let db = &self.db.as_hash_db();
let db = self.factories.trie.readonly(db, &self.root)?;
let from_rlp = |b:&[u8]| { Account::from_rlp(b).expect("decoding db value failed") };
AccountEntry::new_clean(db.get_with(a, from_rlp)?)
} else {
@ -1220,9 +1225,9 @@ impl<B: Backend> State<B> {
if require_code {
let addr_hash = account.address_hash(a);
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), addr_hash);
let accountdb = self.factories.accountdb.readonly(self.db.as_hash_db(), addr_hash);
if !Self::update_account_cache(RequireCache::Code, &mut account, &self.db, accountdb.as_hashdb()) {
if !Self::update_account_cache(RequireCache::Code, &mut account, &self.db, accountdb.as_hash_db()) {
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))))
}
}
@ -1245,7 +1250,8 @@ impl<B: Backend> State<B> {
/// `account_key` == keccak(address)
pub fn prove_account(&self, account_key: H256) -> TrieResult<(Vec<Bytes>, BasicAccount)> {
let mut recorder = Recorder::new();
let trie = TrieDB::new(self.db.as_hashdb(), &self.root)?;
let db = &self.db.as_hash_db();
let trie = TrieDB::new(db, &self.root)?;
let maybe_account: Option<BasicAccount> = {
let panicky_decoder = |bytes: &[u8]| {
::rlp::decode(bytes).expect(&format!("prove_account, could not query trie for account key={}", &account_key))
@ -1271,15 +1277,16 @@ impl<B: Backend> State<B> {
pub fn prove_storage(&self, account_key: H256, storage_key: H256) -> TrieResult<(Vec<Bytes>, H256)> {
// TODO: probably could look into cache somehow but it's keyed by
// address, not keccak(address).
let trie = TrieDB::new(self.db.as_hashdb(), &self.root)?;
let db = &self.db.as_hash_db();
let trie = TrieDB::new(db, &self.root)?;
let from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed");
let acc = match trie.get_with(&account_key, from_rlp)? {
Some(acc) => acc,
None => return Ok((Vec::new(), H256::new())),
};
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), account_key);
acc.prove_storage(account_db.as_hashdb(), storage_key)
let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), account_key);
acc.prove_storage(account_db.as_hash_db(), storage_key)
}
}

View File

@ -25,7 +25,7 @@ use byteorder::{LittleEndian, ByteOrder};
use db::COL_ACCOUNT_BLOOM;
use ethereum_types::{H256, Address};
use hash::keccak;
use hashdb::HashDB;
use hash_db::HashDB;
use journaldb::JournalDB;
use keccak_hasher::KeccakHasher;
use kvdb::{KeyValueDB, DBTransaction, DBValue};
@ -313,13 +313,13 @@ impl StateDB {
}
/// Conversion method to interpret self as `HashDB` reference
pub fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> {
self.db.as_hashdb()
pub fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> {
self.db.as_hash_db()
}
/// Conversion method to interpret self as mutable `HashDB` reference
pub fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
self.db.as_hashdb_mut()
pub fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
self.db.as_hash_db_mut()
}
/// Clone the database.
@ -407,10 +407,10 @@ impl StateDB {
}
impl state::Backend for StateDB {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self.db.as_hashdb() }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self.db.as_hash_db() }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
self.db.as_hashdb_mut()
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
self.db.as_hash_db_mut()
}
fn add_to_account_cache(&mut self, addr: Address, data: Option<Account>, modified: bool) {

View File

@ -19,7 +19,7 @@ ethereum-types = "0.4"
ethkey = { path = "../../accounts/ethkey" }
ethstore = { path = "../../accounts/ethstore" }
fastmap = { path = "../../util/fastmap" }
hashdb = "0.3.0"
hash-db = "0.11.0"
heapsize = "0.4"
keccak-hash = "0.1"
keccak-hasher = { path = "../../util/keccak-hasher" }

View File

@ -7,7 +7,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
byteorder = "1.0"
parity-bytes = "0.1"
ethereum-types = "0.4"
patricia-trie = "0.3.0"
trie-db = "0.11.0"
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
log = "0.4"
ethjson = { path = "../../json" }

View File

@ -22,7 +22,7 @@ extern crate ethjson;
extern crate rlp;
extern crate keccak_hash as hash;
extern crate patricia_trie_ethereum as ethtrie;
extern crate patricia_trie as trie;
extern crate trie_db as trie;
mod action_params;
mod call_type;

View File

@ -59,7 +59,7 @@ keccak-hash = "0.1.2"
parity-runtime = { path = "../util/runtime" }
parity-updater = { path = "../updater" }
parity-version = { path = "../util/version" }
patricia-trie = "0.3.0"
trie-db = "0.11.0"
rlp = { version = "0.3.0", features = ["ethereum"] }
stats = { path = "../util/stats" }
vm = { path = "../ethcore/vm" }

View File

@ -63,7 +63,7 @@ extern crate keccak_hash as hash;
extern crate parity_runtime;
extern crate parity_updater as updater;
extern crate parity_version as version;
extern crate patricia_trie as trie;
extern crate trie_db as trie;
extern crate eip_712;
extern crate rlp;
extern crate stats;

View File

@ -8,12 +8,12 @@ license = "GPL3"
[dependencies]
parity-bytes = "0.1"
ethereum-types = "0.4"
hashdb = "0.3.0"
hash-db = "0.11.0"
heapsize = "0.4"
keccak-hasher = { path = "../keccak-hasher" }
kvdb = "0.1"
log = "0.4"
memorydb = "0.3.0"
memory-db = "0.11.0"
parking_lot = "0.7"
fastmap = { path = "../../util/fastmap" }
rlp = { version = "0.3.0", features = ["ethereum"] }

View File

@ -23,12 +23,12 @@ use std::sync::Arc;
use bytes::Bytes;
use ethereum_types::H256;
use hashdb::*;
use hash_db::{HashDB};
use keccak_hasher::KeccakHasher;
use kvdb::{KeyValueDB, DBTransaction, DBValue};
use rlp::{encode, decode};
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, error_key_already_exists, error_negatively_reference_hash};
use super::memorydb::*;
use super::memory_db::*;
use traits::JournalDB;
/// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay
@ -52,7 +52,7 @@ impl ArchiveDB {
.expect("Low-level database error.")
.map(|val| decode::<u64>(&val).expect("decoding db value failed"));
ArchiveDB {
overlay: MemoryDB::new(),
overlay: ::new_memory_db(),
backing,
latest_era,
column,
@ -62,31 +62,14 @@ impl ArchiveDB {
fn payload(&self, key: &H256) -> Option<DBValue> {
self.backing.get(self.column, key).expect("Low-level database error. Some issue with your hard disk?")
}
}
impl HashDB<KeccakHasher, DBValue> for ArchiveDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
.map(|(key, _)| (H256::from_slice(&*key), 1))
.collect();
for (key, refs) in self.overlay.keys() {
match ret.entry(key) {
Entry::Occupied(mut entry) => {
*entry.get_mut() += refs;
},
Entry::Vacant(entry) => {
entry.insert(refs);
}
}
}
ret
}
fn get(&self, key: &H256) -> Option<DBValue> {
if let Some((d, rc)) = self.overlay.raw(key) {
if rc > 0 {
return Some(d);
return Some(d.clone());
}
}
self.payload(key)
@ -109,7 +92,28 @@ impl HashDB<KeccakHasher, DBValue> for ArchiveDB {
}
}
impl ::traits::KeyedHashDB for ArchiveDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
.map(|(key, _)| (H256::from_slice(&*key), 1))
.collect();
for (key, refs) in self.overlay.keys() {
match ret.entry(key) {
Entry::Occupied(mut entry) => {
*entry.get_mut() += refs;
},
Entry::Vacant(entry) => {
entry.insert(refs);
}
}
}
ret
}
}
impl JournalDB for ArchiveDB {
fn boxed_clone(&self) -> Box<JournalDB> {
Box::new(ArchiveDB {
overlay: self.overlay.clone(),
@ -202,7 +206,7 @@ impl JournalDB for ArchiveDB {
mod tests {
use keccak::keccak;
use hashdb::HashDB;
use hash_db::HashDB;
use super::*;
use {kvdb_memorydb, JournalDB};

View File

@ -15,7 +15,7 @@
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Impls of the `AsHashDB` upcast trait for all different variants of DB
use hashdb::{HashDB, AsHashDB};
use hash_db::{HashDB, AsHashDB};
use keccak_hasher::KeccakHasher;
use archivedb::ArchiveDB;
use earlymergedb::EarlyMergeDB;
@ -23,28 +23,49 @@ use overlayrecentdb::OverlayRecentDB;
use refcounteddb::RefCountedDB;
use overlaydb::OverlayDB;
use kvdb::DBValue;
use crate::{KeyedHashDB, AsKeyedHashDB};
impl AsHashDB<KeccakHasher, DBValue> for ArchiveDB {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl AsHashDB<KeccakHasher, DBValue> for EarlyMergeDB {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl AsHashDB<KeccakHasher, DBValue> for OverlayRecentDB {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl AsHashDB<KeccakHasher, DBValue> for RefCountedDB {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl AsHashDB<KeccakHasher, DBValue> for OverlayDB {
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> { self }
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { self }
}
impl AsKeyedHashDB for ArchiveDB {
fn as_keyed_hash_db(&self) -> &KeyedHashDB { self }
}
impl AsKeyedHashDB for EarlyMergeDB {
fn as_keyed_hash_db(&self) -> &KeyedHashDB { self }
}
impl AsKeyedHashDB for OverlayRecentDB {
fn as_keyed_hash_db(&self) -> &KeyedHashDB { self }
}
impl AsKeyedHashDB for RefCountedDB {
fn as_keyed_hash_db(&self) -> &KeyedHashDB { self }
}
impl AsKeyedHashDB for OverlayDB {
fn as_keyed_hash_db(&self) -> &KeyedHashDB { self }
}

View File

@ -23,11 +23,11 @@ use std::sync::Arc;
use bytes::Bytes;
use ethereum_types::H256;
use hashdb::*;
use hash_db::{HashDB};
use heapsize::HeapSizeOf;
use keccak_hasher::KeccakHasher;
use kvdb::{KeyValueDB, DBTransaction, DBValue};
use memorydb::*;
use memory_db::*;
use parking_lot::RwLock;
use rlp::{encode, decode};
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, error_negatively_reference_hash, error_key_already_exists};
@ -120,7 +120,7 @@ impl EarlyMergeDB {
let (latest_era, refs) = EarlyMergeDB::read_refs(&*backing, col);
let refs = Some(Arc::new(RwLock::new(refs)));
EarlyMergeDB {
overlay: MemoryDB::new(),
overlay: ::new_memory_db(),
backing: backing,
refs: refs,
latest_era: latest_era,
@ -285,31 +285,14 @@ impl EarlyMergeDB {
}
(latest_era, refs)
}
}
impl HashDB<KeccakHasher, DBValue> for EarlyMergeDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
.map(|(key, _)| (H256::from_slice(&*key), 1))
.collect();
for (key, refs) in self.overlay.keys() {
match ret.entry(key) {
Entry::Occupied(mut entry) => {
*entry.get_mut() += refs;
},
Entry::Vacant(entry) => {
entry.insert(refs);
}
}
}
ret
}
fn get(&self, key: &H256) -> Option<DBValue> {
if let Some((d, rc)) = self.overlay.raw(key) {
if rc > 0 {
return Some(d)
return Some(d.clone())
}
}
self.payload(key)
@ -330,6 +313,26 @@ impl HashDB<KeccakHasher, DBValue> for EarlyMergeDB {
}
}
impl ::traits::KeyedHashDB for EarlyMergeDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
.map(|(key, _)| (H256::from_slice(&*key), 1))
.collect();
for (key, refs) in self.overlay.keys() {
match ret.entry(key) {
Entry::Occupied(mut entry) => {
*entry.get_mut() += refs;
},
Entry::Vacant(entry) => {
entry.insert(refs);
}
}
}
ret
}
}
impl JournalDB for EarlyMergeDB {
fn boxed_clone(&self) -> Box<JournalDB> {
Box::new(EarlyMergeDB {
@ -523,7 +526,7 @@ impl JournalDB for EarlyMergeDB {
mod tests {
use keccak::keccak;
use hashdb::HashDB;
use hash_db::HashDB;
use super::*;
use super::super::traits::JournalDB;
use kvdb_memorydb;

View File

@ -22,10 +22,10 @@ extern crate log;
extern crate ethereum_types;
extern crate parity_bytes as bytes;
extern crate hashdb;
extern crate hash_db;
extern crate keccak_hasher;
extern crate kvdb;
extern crate memorydb;
extern crate memory_db;
extern crate parking_lot;
extern crate fastmap;
extern crate rlp;
@ -54,6 +54,11 @@ pub mod overlaydb;
/// Export the `JournalDB` trait.
pub use self::traits::JournalDB;
/// Export keyed hash trait
pub use self::traits::KeyedHashDB;
/// Export as keyed hash trait
pub use self::traits::AsKeyedHashDB;
/// Journal database operating strategy.
#[derive(Debug, PartialEq, Clone, Copy)]
pub enum Algorithm {
@ -158,6 +163,10 @@ fn error_negatively_reference_hash(hash: &ethereum_types::H256) -> io::Error {
io::Error::new(io::ErrorKind::Other, format!("Entry {} removed from database more times than it was added.", hash))
}
pub fn new_memory_db() -> memory_db::MemoryDB<keccak_hasher::KeccakHasher, kvdb::DBValue> {
memory_db::MemoryDB::from_null_node(&rlp::NULL_RLP, rlp::NULL_RLP.as_ref().into())
}
#[cfg(test)]
mod tests {
use super::Algorithm;

View File

@ -23,9 +23,9 @@ use std::sync::Arc;
use ethereum_types::H256;
use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable, encode, decode};
use hashdb::*;
use hash_db::{HashDB};
use keccak_hasher::KeccakHasher;
use memorydb::*;
use memory_db::*;
use kvdb::{KeyValueDB, DBTransaction, DBValue};
use super::{error_negatively_reference_hash};
@ -80,7 +80,7 @@ impl Decodable for Payload {
impl OverlayDB {
/// Create a new instance of OverlayDB given a `backing` database.
pub fn new(backing: Arc<KeyValueDB>, col: Option<u32>) -> OverlayDB {
OverlayDB{ overlay: MemoryDB::new(), backing: backing, column: col }
OverlayDB{ overlay: ::new_memory_db(), backing: backing, column: col }
}
/// Create a new instance of OverlayDB with an anonymous temporary database.
@ -153,9 +153,10 @@ impl OverlayDB {
true
}
}
}
impl HashDB<KeccakHasher, DBValue> for OverlayDB {
impl crate::KeyedHashDB for OverlayDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
.map(|(key, _)| {
@ -178,13 +179,16 @@ impl HashDB<KeccakHasher, DBValue> for OverlayDB {
ret
}
}
impl HashDB<KeccakHasher, DBValue> for OverlayDB {
fn get(&self, key: &H256) -> Option<DBValue> {
// return ok if positive; if negative, check backing - might be enough references there to make
// it positive again.
let k = self.overlay.raw(key);
let memrc = {
if let Some((d, rc)) = k {
if rc > 0 { return Some(d); }
if rc > 0 { return Some(d.clone()); }
rc
} else {
0

View File

@ -23,11 +23,11 @@ use std::sync::Arc;
use bytes::Bytes;
use ethereum_types::H256;
use hashdb::*;
use hash_db::{HashDB};
use heapsize::HeapSizeOf;
use keccak_hasher::KeccakHasher;
use kvdb::{KeyValueDB, DBTransaction, DBValue};
use memorydb::*;
use memory_db::*;
use parking_lot::RwLock;
use fastmap::H256FastMap;
use rlp::{Rlp, RlpStream, encode, decode, DecoderError, Decodable, Encodable};
@ -157,7 +157,7 @@ impl OverlayRecentDB {
pub fn new(backing: Arc<KeyValueDB>, col: Option<u32>) -> OverlayRecentDB {
let journal_overlay = Arc::new(RwLock::new(OverlayRecentDB::read_overlay(&*backing, col)));
OverlayRecentDB {
transaction_overlay: MemoryDB::new(),
transaction_overlay: ::new_memory_db(),
backing: backing,
journal_overlay: journal_overlay,
column: col,
@ -181,7 +181,7 @@ impl OverlayRecentDB {
fn read_overlay(db: &KeyValueDB, col: Option<u32>) -> JournalOverlay {
let mut journal = HashMap::new();
let mut overlay = MemoryDB::new();
let mut overlay = ::new_memory_db();
let mut count = 0;
let mut latest_era = None;
let mut earliest_era = None;
@ -233,6 +233,7 @@ impl OverlayRecentDB {
cumulative_size: cumulative_size,
}
}
}
#[inline]
@ -242,7 +243,28 @@ fn to_short_key(key: &H256) -> H256 {
k
}
impl ::traits::KeyedHashDB for OverlayRecentDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
.map(|(key, _)| (H256::from_slice(&*key), 1))
.collect();
for (key, refs) in self.transaction_overlay.keys() {
match ret.entry(key) {
Entry::Occupied(mut entry) => {
*entry.get_mut() += refs;
},
Entry::Vacant(entry) => {
entry.insert(refs);
}
}
}
ret
}
}
impl JournalDB for OverlayRecentDB {
fn boxed_clone(&self) -> Box<JournalDB> {
Box::new(self.clone())
}
@ -365,7 +387,7 @@ impl JournalDB for OverlayRecentDB {
for h in &journal.insertions {
if let Some((d, rc)) = journal_overlay.backing_overlay.raw(&to_short_key(h)) {
if rc > 0 {
canon_insertions.push((h.clone(), d)); //TODO: optimize this to avoid data copy
canon_insertions.push((h.clone(), d.clone())); //TODO: optimize this to avoid data copy
}
}
}
@ -440,28 +462,10 @@ impl JournalDB for OverlayRecentDB {
}
impl HashDB<KeccakHasher, DBValue> for OverlayRecentDB {
fn keys(&self) -> HashMap<H256, i32> {
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
.map(|(key, _)| (H256::from_slice(&*key), 1))
.collect();
for (key, refs) in self.transaction_overlay.keys() {
match ret.entry(key) {
Entry::Occupied(mut entry) => {
*entry.get_mut() += refs;
},
Entry::Vacant(entry) => {
entry.insert(refs);
}
}
}
ret
}
fn get(&self, key: &H256) -> Option<DBValue> {
if let Some((d, rc)) = self.transaction_overlay.raw(key) {
if rc > 0 {
return Some(d)
return Some(d.clone())
}
}
let v = {
@ -493,7 +497,7 @@ mod tests {
use keccak::keccak;
use super::*;
use hashdb::HashDB;
use hash_db::HashDB;
use {kvdb_memorydb, JournalDB};
fn new_db() -> OverlayRecentDB {

View File

@ -22,11 +22,11 @@ use std::sync::Arc;
use bytes::Bytes;
use ethereum_types::H256;
use hashdb::*;
use hash_db::{HashDB};
use heapsize::HeapSizeOf;
use keccak_hasher::KeccakHasher;
use kvdb::{KeyValueDB, DBTransaction, DBValue};
use memorydb::MemoryDB;
use memory_db::MemoryDB;
use overlaydb::OverlayDB;
use rlp::{encode, decode};
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY};
@ -81,7 +81,6 @@ impl RefCountedDB {
}
impl HashDB<KeccakHasher, DBValue> for RefCountedDB {
fn keys(&self) -> HashMap<H256, i32> { self.forward.keys() }
fn get(&self, key: &H256) -> Option<DBValue> { self.forward.get(key) }
fn contains(&self, key: &H256) -> bool { self.forward.contains(key) }
fn insert(&mut self, value: &[u8]) -> H256 { let r = self.forward.insert(value); self.inserts.push(r.clone()); r }
@ -89,6 +88,10 @@ impl HashDB<KeccakHasher, DBValue> for RefCountedDB {
fn remove(&mut self, key: &H256) { self.removes.push(key.clone()); }
}
impl ::traits::KeyedHashDB for RefCountedDB {
fn keys(&self) -> HashMap<H256, i32> { self.forward.keys() }
}
impl JournalDB for RefCountedDB {
fn boxed_clone(&self) -> Box<JournalDB> {
Box::new(RefCountedDB {
@ -216,7 +219,7 @@ impl JournalDB for RefCountedDB {
mod tests {
use keccak::keccak;
use hashdb::HashDB;
use hash_db::HashDB;
use super::*;
use {JournalDB, kvdb_memorydb};

View File

@ -21,13 +21,28 @@ use std::sync::Arc;
use bytes::Bytes;
use ethereum_types::H256;
use hashdb::HashDB;
use hash_db::{HashDB, AsHashDB};
use keccak_hasher::KeccakHasher;
use kvdb::{self, DBTransaction, DBValue};
use std::collections::HashMap;
/// expose keys of a hashDB for debugging or tests (slow).
pub trait KeyedHashDB: HashDB<KeccakHasher, DBValue> {
/// Primarily use for tests, highly inefficient.
fn keys(&self) -> HashMap<H256, i32>;
}
/// Upcast to `KeyedHashDB`
pub trait AsKeyedHashDB: AsHashDB<KeccakHasher, DBValue> {
/// Perform upcast to KeyedHashDB.
fn as_keyed_hash_db(&self) -> &KeyedHashDB;
}
/// A `HashDB` which can manage a short-term journal potentially containing many forks of mutually
/// exclusive actions.
pub trait JournalDB: HashDB<KeccakHasher, DBValue> {
pub trait JournalDB: KeyedHashDB {
/// Return a copy of ourself, in a box.
fn boxed_clone(&self) -> Box<JournalDB>;
@ -78,7 +93,7 @@ pub trait JournalDB: HashDB<KeccakHasher, DBValue> {
fn flush(&self) {}
/// Consolidate all the insertions and deletions in the given memory overlay.
fn consolidate(&mut self, overlay: ::memorydb::MemoryDB<KeccakHasher, DBValue>);
fn consolidate(&mut self, overlay: ::memory_db::MemoryDB<KeccakHasher, DBValue>);
/// Commit all changes in a single batch
#[cfg(test)]

View File

@ -8,5 +8,5 @@ license = "GPL-3.0"
[dependencies]
ethereum-types = "0.4"
tiny-keccak = "1.4.2"
hashdb = "0.3.0"
hash-db = "0.11.0"
plain_hasher = "0.2"

View File

@ -15,12 +15,12 @@
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
//! Hasher implementation for the Keccak-256 hash
extern crate hashdb;
extern crate hash_db;
extern crate ethereum_types;
extern crate tiny_keccak;
extern crate plain_hasher;
use hashdb::Hasher;
use hash_db::Hasher;
use ethereum_types::H256;
use tiny_keccak::Keccak;
use plain_hasher::PlainHasher;

View File

@ -6,14 +6,15 @@ description = "Merkle-Patricia Trie (Ethereum Style)"
license = "GPL-3.0"
[dependencies]
patricia-trie = "0.3.0"
trie-db = "0.11.0"
keccak-hasher = { version = "0.1.1", path = "../keccak-hasher" }
hashdb = "0.3.0"
hash-db = "0.11.0"
rlp = "0.3.0"
parity-bytes = "0.1"
ethereum-types = "0.4"
elastic-array = "0.10"
[dev-dependencies]
memorydb = "0.3.0"
memory-db = "0.11.0"
keccak-hash = "0.1.2"
journaldb = { path = "../journaldb" }

View File

@ -16,11 +16,11 @@
//! Façade crate for `patricia_trie` for Ethereum specific impls
pub extern crate patricia_trie as trie; // `pub` because we need to import this crate for the tests in `patricia_trie` and there were issues: https://gist.github.com/dvdplm/869251ee557a1b4bd53adc7c971979aa
pub extern crate trie_db as trie; // `pub` because we need to import this crate for the tests in `patricia_trie` and there were issues: https://gist.github.com/dvdplm/869251ee557a1b4bd53adc7c971979aa
extern crate elastic_array;
extern crate parity_bytes;
extern crate ethereum_types;
extern crate hashdb;
extern crate hash_db;
extern crate keccak_hasher;
extern crate rlp;
@ -42,18 +42,19 @@ pub type RlpCodec = RlpNodeCodec<KeccakHasher>;
///
/// # Example
/// ```
/// extern crate patricia_trie as trie;
/// extern crate trie_db as trie;
/// extern crate patricia_trie_ethereum as ethtrie;
/// extern crate hashdb;
/// extern crate hash_db;
/// extern crate keccak_hasher;
/// extern crate memorydb;
/// extern crate memory_db;
/// extern crate ethereum_types;
/// extern crate elastic_array;
/// extern crate journaldb;
///
/// use trie::*;
/// use hashdb::*;
/// use hash_db::*;
/// use keccak_hasher::KeccakHasher;
/// use memorydb::*;
/// use memory_db::*;
/// use ethereum_types::H256;
/// use ethtrie::{TrieDB, TrieDBMut};
/// use elastic_array::ElasticArray128;
@ -61,7 +62,7 @@ pub type RlpCodec = RlpNodeCodec<KeccakHasher>;
/// type DBValue = ElasticArray128<u8>;
///
/// fn main() {
/// let mut memdb = MemoryDB::<KeccakHasher, DBValue>::new();
/// let mut memdb = journaldb::new_memory_db();
/// let mut root = H256::new();
/// TrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap();
/// let t = TrieDB::new(&memdb, &root).unwrap();
@ -85,26 +86,27 @@ pub type FatDB<'db> = trie::FatDB<'db, KeccakHasher, RlpCodec>;
/// # Example
/// ```
/// extern crate patricia_trie as trie;
/// extern crate trie_db as trie;
/// extern crate patricia_trie_ethereum as ethtrie;
/// extern crate hashdb;
/// extern crate hash_db;
/// extern crate keccak_hash;
/// extern crate keccak_hasher;
/// extern crate memorydb;
/// extern crate memory_db;
/// extern crate ethereum_types;
/// extern crate elastic_array;
/// extern crate journaldb;
///
/// use keccak_hash::KECCAK_NULL_RLP;
/// use ethtrie::{TrieDBMut, trie::TrieMut};
/// use keccak_hasher::KeccakHasher;
/// use memorydb::*;
/// use memory_db::*;
/// use ethereum_types::H256;
/// use elastic_array::ElasticArray128;
///
/// type DBValue = ElasticArray128<u8>;
///
/// fn main() {
/// let mut memdb = MemoryDB::<KeccakHasher, DBValue>::new();
/// let mut memdb = journaldb::new_memory_db();
/// let mut root = H256::new();
/// let mut t = TrieDBMut::new(&mut memdb, &mut root);
/// assert!(t.is_empty());

View File

@ -18,7 +18,7 @@
use elastic_array::ElasticArray128;
use ethereum_types::H256;
use hashdb::Hasher;
use hash_db::Hasher;
use keccak_hasher::KeccakHasher;
use rlp::{DecoderError, RlpStream, Rlp, Prototype};
use std::marker::PhantomData;
@ -28,13 +28,17 @@ use trie::{NibbleSlice, NodeCodec, node::Node, ChildReference};
#[derive(Default, Clone)]
pub struct RlpNodeCodec<H: Hasher> {mark: PhantomData<H>}
const HASHED_NULL_NODE_BYTES : [u8;32] = [0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21];
const HASHED_NULL_NODE : H256 = H256( HASHED_NULL_NODE_BYTES );
// NOTE: what we'd really like here is:
// `impl<H: Hasher> NodeCodec<H> for RlpNodeCodec<H> where H::Out: Decodable`
// but due to the current limitations of Rust const evaluation we can't
// do `const HASHED_NULL_NODE: H::Out = H::Out( … … )`. Perhaps one day soon?
impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
type Error = DecoderError;
const HASHED_NULL_NODE : H256 = H256( [0x56, 0xe8, 0x1f, 0x17, 0x1b, 0xcc, 0x55, 0xa6, 0xff, 0x83, 0x45, 0xe6, 0x92, 0xc0, 0xf8, 0x6e, 0x5b, 0x48, 0xe0, 0x1b, 0x99, 0x6c, 0xad, 0xc0, 0x01, 0x62, 0x2f, 0xb5, 0xe3, 0x63, 0xb4, 0x21] );
fn hashed_null_node() -> <KeccakHasher as Hasher>::Out {
HASHED_NULL_NODE
}
fn decode(data: &[u8]) -> ::std::result::Result<Node, Self::Error> {
let r = Rlp::new(data);
match r.prototype()? {
@ -49,9 +53,14 @@ impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
},
// branch - first 16 are nodes, 17th is a value (or empty).
Prototype::List(17) => {
let mut nodes = [&[] as &[u8]; 16];
let mut nodes = [None as Option<&[u8]>; 16];
for i in 0..16 {
nodes[i] = r.at(i)?.as_raw();
let v = r.at(i)?;
if v.is_empty() {
nodes[i] = None;
} else {
nodes[i] = Some(v.as_raw());
}
}
Ok(Node::Branch(nodes, if r.at(16)?.is_empty() { None } else { Some(r.at(16)?.data()?) }))
},

View File

@ -6,6 +6,6 @@ description = "Trie-root helpers, ethereum style"
license = "GPL-3.0"
[dependencies]
triehash = { version = "0.3.0", features = ["ethereum"] }
triehash = { version = "0.4.0", features = ["ethereum"] }
ethereum-types = "0.4"
keccak-hasher = { path = "../keccak-hasher" }