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:
parent
4e0ec4e66b
commit
6bb106a784
95
Cargo.lock
generated
95
Cargo.lock
generated
@ -718,7 +718,7 @@ dependencies = [
|
|||||||
"ethkey 0.3.0",
|
"ethkey 0.3.0",
|
||||||
"evm 0.1.0",
|
"evm 0.1.0",
|
||||||
"fetch 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)",
|
"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)",
|
"itertools 0.5.10 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"journaldb 0.2.0",
|
"journaldb 0.2.0",
|
||||||
@ -733,7 +733,7 @@ dependencies = [
|
|||||||
"lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
"lru-cache 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"macros 0.1.0",
|
"macros 0.1.0",
|
||||||
"memory-cache 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 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)",
|
"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)",
|
"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-runtime 0.1.0",
|
||||||
"parity-snappy 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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",
|
"patricia-trie-ethereum 0.1.0",
|
||||||
"rand 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"rayon 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -755,6 +754,7 @@ dependencies = [
|
|||||||
"stats 0.1.0",
|
"stats 0.1.0",
|
||||||
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"trie-standardmap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"triehash-ethereum 0.2.0",
|
"triehash-ethereum 0.2.0",
|
||||||
"unexpected 0.1.0",
|
"unexpected 0.1.0",
|
||||||
@ -870,19 +870,19 @@ dependencies = [
|
|||||||
"failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"failsafe 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"fastmap 0.1.0",
|
"fastmap 0.1.0",
|
||||||
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"keccak-hasher 0.1.1",
|
"keccak-hasher 0.1.1",
|
||||||
"kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"log 0.4.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"memory-cache 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)",
|
||||||
"parity-bytes 0.1.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)",
|
"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",
|
"patricia-trie-ethereum 0.1.0",
|
||||||
"rand 0.4.3 (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)",
|
"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)",
|
"smallvec 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"stats 0.1.0",
|
"stats 0.1.0",
|
||||||
"tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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",
|
"triehash-ethereum 0.2.0",
|
||||||
"vm 0.1.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-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)",
|
"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)",
|
"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",
|
"patricia-trie-ethereum 0.1.0",
|
||||||
"rand 0.3.22 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"url 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -1130,7 +1131,7 @@ dependencies = [
|
|||||||
"ethkey 0.3.0",
|
"ethkey 0.3.0",
|
||||||
"ethstore 0.2.1",
|
"ethstore 0.2.1",
|
||||||
"fastmap 0.1.0",
|
"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)",
|
"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-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"keccak-hasher 0.1.1",
|
"keccak-hasher 0.1.1",
|
||||||
@ -1540,8 +1541,8 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hashdb"
|
name = "hash-db"
|
||||||
version = "0.3.0"
|
version = "0.11.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@ -1809,14 +1810,14 @@ dependencies = [
|
|||||||
"env_logger 0.5.13 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"fastmap 0.1.0",
|
"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)",
|
"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-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"keccak-hasher 0.1.1",
|
"keccak-hasher 0.1.1",
|
||||||
"kvdb 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
@ -1937,7 +1938,7 @@ name = "keccak-hasher"
|
|||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ethereum-types 0.4.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)",
|
||||||
"plain_hasher 0.2.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)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
name = "memory_units"
|
name = "memory_units"
|
||||||
version = "0.3.0"
|
version = "0.3.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
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]]
|
[[package]]
|
||||||
name = "memzero"
|
name = "memzero"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
@ -2678,7 +2677,6 @@ dependencies = [
|
|||||||
"parity-updater 1.12.0",
|
"parity-updater 1.12.0",
|
||||||
"parity-version 2.4.0",
|
"parity-version 2.4.0",
|
||||||
"parking_lot 0.7.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)",
|
|
||||||
"pretty_assertions 0.1.2 (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)",
|
"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)",
|
"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)",
|
"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)",
|
"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)",
|
"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",
|
"vm 0.1.0",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -2902,31 +2901,20 @@ dependencies = [
|
|||||||
"winapi 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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]]
|
[[package]]
|
||||||
name = "patricia-trie-ethereum"
|
name = "patricia-trie-ethereum"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"keccak-hasher 0.1.1",
|
"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)",
|
"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)",
|
"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]]
|
[[package]]
|
||||||
@ -4079,6 +4067,17 @@ dependencies = [
|
|||||||
"protobuf 1.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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]]
|
[[package]]
|
||||||
name = "trie-standardmap"
|
name = "trie-standardmap"
|
||||||
version = "0.1.1"
|
version = "0.1.1"
|
||||||
@ -4092,10 +4091,10 @@ dependencies = [
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "triehash"
|
name = "triehash"
|
||||||
version = "0.3.0"
|
version = "0.4.0"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
dependencies = [
|
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)",
|
"rlp 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
]
|
]
|
||||||
|
|
||||||
@ -4105,7 +4104,7 @@ version = "0.2.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
"ethereum-types 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
"keccak-hasher 0.1.1",
|
"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]]
|
[[package]]
|
||||||
@ -4281,9 +4280,9 @@ dependencies = [
|
|||||||
"keccak-hash 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"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)",
|
"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",
|
"patricia-trie-ethereum 0.1.0",
|
||||||
"rlp 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]]
|
[[package]]
|
||||||
@ -4553,7 +4552,7 @@ dependencies = [
|
|||||||
"checksum h2 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "a27e7ed946e8335bdf9a191bc1b9b14a03ba822d013d2f58437f4fabcbd7fc2c"
|
"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 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 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 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 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"
|
"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 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 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 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 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 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 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"
|
"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 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.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 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 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 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"
|
"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 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 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 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 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.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 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"
|
"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169"
|
||||||
|
@ -30,7 +30,7 @@ ethereum-types = "0.4"
|
|||||||
ethjson = { path = "../json" }
|
ethjson = { path = "../json" }
|
||||||
ethkey = { path = "../accounts/ethkey" }
|
ethkey = { path = "../accounts/ethkey" }
|
||||||
evm = { path = "evm" }
|
evm = { path = "evm" }
|
||||||
hashdb = "0.3.0"
|
hash-db = "0.11.0"
|
||||||
heapsize = "0.4"
|
heapsize = "0.4"
|
||||||
itertools = "0.5"
|
itertools = "0.5"
|
||||||
journaldb = { path = "../util/journaldb" }
|
journaldb = { path = "../util/journaldb" }
|
||||||
@ -45,7 +45,7 @@ log = "0.4"
|
|||||||
lru-cache = "0.1"
|
lru-cache = "0.1"
|
||||||
macros = { path = "../util/macros" }
|
macros = { path = "../util/macros" }
|
||||||
memory-cache = { path = "../util/memory-cache" }
|
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 = { version = "0.1", default-features = false, features = ["bigint"] }
|
||||||
num_cpus = "1.2"
|
num_cpus = "1.2"
|
||||||
parity-bytes = "0.1"
|
parity-bytes = "0.1"
|
||||||
@ -53,7 +53,7 @@ parity-crypto = "0.3.0"
|
|||||||
parity-machine = { path = "../machine" }
|
parity-machine = { path = "../machine" }
|
||||||
parity-snappy = "0.1"
|
parity-snappy = "0.1"
|
||||||
parking_lot = "0.7"
|
parking_lot = "0.7"
|
||||||
patricia-trie = "0.3.0"
|
trie-db = "0.11.0"
|
||||||
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
|
patricia-trie-ethereum = { path = "../util/patricia-trie-ethereum" }
|
||||||
rand = "0.4"
|
rand = "0.4"
|
||||||
rayon = "1.0"
|
rayon = "1.0"
|
||||||
|
@ -14,12 +14,12 @@ ethcore = { path = ".."}
|
|||||||
ethcore-db = { path = "../db" }
|
ethcore-db = { path = "../db" }
|
||||||
ethcore-blockchain = { path = "../blockchain" }
|
ethcore-blockchain = { path = "../blockchain" }
|
||||||
ethereum-types = "0.4"
|
ethereum-types = "0.4"
|
||||||
memorydb = "0.3.0"
|
memory-db = "0.11.0"
|
||||||
patricia-trie = "0.3.0"
|
trie-db = "0.11.0"
|
||||||
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
|
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
|
||||||
ethcore-network = { path = "../../util/network" }
|
ethcore-network = { path = "../../util/network" }
|
||||||
ethcore-io = { path = "../../util/io" }
|
ethcore-io = { path = "../../util/io" }
|
||||||
hashdb = "0.3.0"
|
hash-db = "0.11.0"
|
||||||
heapsize = "0.4"
|
heapsize = "0.4"
|
||||||
vm = { path = "../vm" }
|
vm = { path = "../vm" }
|
||||||
fastmap = { path = "../../util/fastmap" }
|
fastmap = { path = "../../util/fastmap" }
|
||||||
@ -41,6 +41,7 @@ triehash-ethereum = { version = "0.2", path = "../../util/triehash-ethereum" }
|
|||||||
kvdb = "0.1"
|
kvdb = "0.1"
|
||||||
memory-cache = { path = "../../util/memory-cache" }
|
memory-cache = { path = "../../util/memory-cache" }
|
||||||
error-chain = { version = "0.12", default-features = false }
|
error-chain = { version = "0.12", default-features = false }
|
||||||
|
journaldb = { path = "../../util/journaldb" }
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
ethcore = { path = "..", features = ["test-helpers"] }
|
ethcore = { path = "..", features = ["test-helpers"] }
|
||||||
|
@ -25,10 +25,11 @@
|
|||||||
|
|
||||||
use common_types::ids::BlockId;
|
use common_types::ids::BlockId;
|
||||||
use ethereum_types::{H256, U256};
|
use ethereum_types::{H256, U256};
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use memorydb::MemoryDB;
|
use memory_db::MemoryDB;
|
||||||
|
use journaldb::new_memory_db;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use trie::{TrieMut, Trie, Recorder};
|
use trie::{TrieMut, Trie, Recorder};
|
||||||
use ethtrie::{self, TrieDB, TrieDBMut};
|
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) }
|
if block_to_cht_number(num) != Some(self.number) { return Ok(None) }
|
||||||
|
|
||||||
let mut recorder = Recorder::with_depth(from_level);
|
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)?;
|
t.get_with(&key!(num), &mut recorder)?;
|
||||||
|
|
||||||
Ok(Some(recorder.drain().into_iter().map(|x| x.data).collect()))
|
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>>>
|
pub fn build<F>(cht_num: u64, mut fetcher: F) -> Option<CHT<MemoryDB<KeccakHasher, DBValue>>>
|
||||||
where F: FnMut(BlockId) -> Option<BlockInfo>
|
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.
|
// start from the last block by number and work backwards.
|
||||||
let last_num = start_number(cht_num + 1) - 1;
|
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.
|
/// verify the given trie branch and extract the canonical hash and total difficulty.
|
||||||
// TODO: better support for partially-checked queries.
|
// TODO: better support for partially-checked queries.
|
||||||
pub fn check_proof(proof: &[Bytes], num: u64, root: H256) -> Option<(H256, U256)> {
|
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[..]); }
|
for node in proof { db.insert(&node[..]); }
|
||||||
let res = match TrieDB::new(&db, &root) {
|
let res = match TrieDB::new(&db, &root) {
|
||||||
|
@ -62,14 +62,14 @@ extern crate ethcore_network as network;
|
|||||||
extern crate parity_bytes as bytes;
|
extern crate parity_bytes as bytes;
|
||||||
extern crate ethereum_types;
|
extern crate ethereum_types;
|
||||||
extern crate ethcore;
|
extern crate ethcore;
|
||||||
extern crate hashdb;
|
extern crate hash_db;
|
||||||
extern crate heapsize;
|
extern crate heapsize;
|
||||||
extern crate failsafe;
|
extern crate failsafe;
|
||||||
extern crate futures;
|
extern crate futures;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate keccak_hasher;
|
extern crate keccak_hasher;
|
||||||
extern crate memorydb;
|
extern crate memory_db;
|
||||||
extern crate patricia_trie as trie;
|
extern crate trie_db as trie;
|
||||||
extern crate patricia_trie_ethereum as ethtrie;
|
extern crate patricia_trie_ethereum as ethtrie;
|
||||||
extern crate fastmap;
|
extern crate fastmap;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
@ -92,3 +92,4 @@ extern crate error_chain;
|
|||||||
extern crate kvdb_memorydb;
|
extern crate kvdb_memorydb;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
extern crate tempdir;
|
extern crate tempdir;
|
||||||
|
extern crate journaldb;
|
||||||
|
@ -30,9 +30,8 @@ use ethcore::state::{self, ProvedExecution};
|
|||||||
use ethereum_types::{H256, U256, Address};
|
use ethereum_types::{H256, U256, Address};
|
||||||
use ethtrie::{TrieError, TrieDB};
|
use ethtrie::{TrieError, TrieDB};
|
||||||
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak};
|
use hash::{KECCAK_NULL_RLP, KECCAK_EMPTY, KECCAK_EMPTY_LIST_RLP, keccak};
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use memorydb::MemoryDB;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use request::{self as net_request, IncompleteRequest, CompleteRequest, Output, OutputKind, Field};
|
use request::{self as net_request, IncompleteRequest, CompleteRequest, Output, OutputKind, Field};
|
||||||
use rlp::{RlpStream, Rlp};
|
use rlp::{RlpStream, Rlp};
|
||||||
@ -981,7 +980,7 @@ impl Account {
|
|||||||
let header = self.header.as_ref()?;
|
let header = self.header.as_ref()?;
|
||||||
let state_root = header.state_root();
|
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[..]); }
|
for node in proof { db.insert(&node[..]); }
|
||||||
|
|
||||||
match TrieDB::new(&db, &state_root).and_then(|t| t.get(&keccak(&self.address)))? {
|
match TrieDB::new(&db, &state_root).and_then(|t| t.get(&keccak(&self.address)))? {
|
||||||
@ -1101,7 +1100,6 @@ mod tests {
|
|||||||
use super::*;
|
use super::*;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
use ethereum_types::{H256, Address};
|
use ethereum_types::{H256, Address};
|
||||||
use memorydb::MemoryDB;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use trie::{Trie, TrieMut};
|
use trie::{Trie, TrieMut};
|
||||||
use ethtrie::{SecTrieDB, SecTrieDBMut};
|
use ethtrie::{SecTrieDB, SecTrieDBMut};
|
||||||
@ -1281,7 +1279,7 @@ mod tests {
|
|||||||
use rlp::RlpStream;
|
use rlp::RlpStream;
|
||||||
|
|
||||||
let mut root = H256::default();
|
let mut root = H256::default();
|
||||||
let mut db = MemoryDB::new();
|
let mut db = journaldb::new_memory_db();
|
||||||
let mut header = Header::new();
|
let mut header = Header::new();
|
||||||
header.set_number(123_456);
|
header.set_number(123_456);
|
||||||
header.set_extra_data(b"test_header".to_vec());
|
header.set_extra_data(b"test_header".to_vec());
|
||||||
|
@ -26,7 +26,7 @@ log = "0.4"
|
|||||||
parity-bytes = "0.1"
|
parity-bytes = "0.1"
|
||||||
parity-crypto = "0.3.0"
|
parity-crypto = "0.3.0"
|
||||||
parking_lot = "0.7"
|
parking_lot = "0.7"
|
||||||
patricia-trie = "0.3.0"
|
trie-db = "0.11.0"
|
||||||
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
|
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
|
||||||
rand = "0.3"
|
rand = "0.3"
|
||||||
rlp = { version = "0.3.0", features = ["ethereum"] }
|
rlp = { version = "0.3.0", features = ["ethereum"] }
|
||||||
|
@ -42,7 +42,7 @@ extern crate keccak_hash as hash;
|
|||||||
extern crate parity_bytes as bytes;
|
extern crate parity_bytes as bytes;
|
||||||
extern crate parity_crypto as crypto;
|
extern crate parity_crypto as crypto;
|
||||||
extern crate parking_lot;
|
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 patricia_trie_ethereum as ethtrie;
|
||||||
extern crate rlp;
|
extern crate rlp;
|
||||||
extern crate rustc_hex;
|
extern crate rustc_hex;
|
||||||
|
@ -17,11 +17,10 @@
|
|||||||
//! DB backend wrapper for Account trie
|
//! DB backend wrapper for Account trie
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use hash::{KECCAK_NULL_RLP, keccak};
|
use hash::{KECCAK_NULL_RLP, keccak};
|
||||||
use hashdb::{HashDB, AsHashDB};
|
use hash_db::{HashDB, AsHashDB};
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use rlp::NULL_RLP;
|
use rlp::NULL_RLP;
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use ethereum_types::Address;
|
use ethereum_types::Address;
|
||||||
@ -99,15 +98,11 @@ impl<'db> AccountDB<'db> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> AsHashDB<KeccakHasher, DBValue> for AccountDB<'db> {
|
impl<'db> AsHashDB<KeccakHasher, DBValue> for AccountDB<'db> {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> HashDB<KeccakHasher, DBValue> for AccountDB<'db> {
|
impl<'db> HashDB<KeccakHasher, DBValue> for AccountDB<'db> {
|
||||||
fn keys(&self) -> HashMap<H256, i32> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
if key == &KECCAK_NULL_RLP {
|
if key == &KECCAK_NULL_RLP {
|
||||||
return Some(DBValue::from_slice(&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>{
|
impl<'db> HashDB<KeccakHasher, DBValue> for AccountDBMut<'db>{
|
||||||
fn keys(&self) -> HashMap<H256, i32> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
if key == &KECCAK_NULL_RLP {
|
if key == &KECCAK_NULL_RLP {
|
||||||
return Some(DBValue::from_slice(&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> {
|
impl<'db> AsHashDB<KeccakHasher, DBValue> for AccountDBMut<'db> {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Wrapping<'db>(&'db HashDB<KeccakHasher, DBValue>);
|
struct Wrapping<'db>(&'db HashDB<KeccakHasher, DBValue>);
|
||||||
|
|
||||||
impl<'db> AsHashDB<KeccakHasher, DBValue> for Wrapping<'db> {
|
impl<'db> AsHashDB<KeccakHasher, DBValue> for Wrapping<'db> {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> HashDB<KeccakHasher, DBValue> for Wrapping<'db> {
|
impl<'db> HashDB<KeccakHasher, DBValue> for Wrapping<'db> {
|
||||||
fn keys(&self) -> HashMap<H256, i32> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
if key == &KECCAK_NULL_RLP {
|
if key == &KECCAK_NULL_RLP {
|
||||||
return Some(DBValue::from_slice(&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>);
|
struct WrappingMut<'db>(&'db mut HashDB<KeccakHasher, DBValue>);
|
||||||
impl<'db> AsHashDB<KeccakHasher, DBValue> for WrappingMut<'db> {
|
impl<'db> AsHashDB<KeccakHasher, DBValue> for WrappingMut<'db> {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'db> HashDB<KeccakHasher, DBValue> for WrappingMut<'db>{
|
impl<'db> HashDB<KeccakHasher, DBValue> for WrappingMut<'db>{
|
||||||
fn keys(&self) -> HashMap<H256, i32> {
|
|
||||||
unimplemented!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
if key == &KECCAK_NULL_RLP {
|
if key == &KECCAK_NULL_RLP {
|
||||||
return Some(DBValue::from_slice(&NULL_RLP));
|
return Some(DBValue::from_slice(&NULL_RLP));
|
||||||
|
@ -624,7 +624,7 @@ impl Importer {
|
|||||||
|
|
||||||
let call = move |addr, data| {
|
let call = move |addr, data| {
|
||||||
let mut state_db = state_db.boxed_clone();
|
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 =
|
let transaction =
|
||||||
client.contract_call_tx(BlockId::Hash(*header.parent_hash()), addr, data);
|
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;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -1781,7 +1781,8 @@ impl BlockChainClient for Client {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (root, db) = state.drop();
|
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,
|
Ok(trie) => trie,
|
||||||
_ => {
|
_ => {
|
||||||
trace!(target: "fatdb", "list_accounts: Couldn't open the DB");
|
trace!(target: "fatdb", "list_accounts: Couldn't open the DB");
|
||||||
@ -1827,8 +1828,9 @@ impl BlockChainClient for Client {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let (_, db) = state.drop();
|
let (_, db) = state.drop();
|
||||||
let account_db = self.factories.accountdb.readonly(db.as_hashdb(), keccak(account));
|
let account_db = &self.factories.accountdb.readonly(db.as_hash_db(), keccak(account));
|
||||||
let trie = match self.factories.trie.readonly(account_db.as_hashdb(), &root) {
|
let account_db = &account_db.as_hash_db();
|
||||||
|
let trie = match self.factories.trie.readonly(account_db, &root) {
|
||||||
Ok(trie) => trie,
|
Ok(trie) => trie,
|
||||||
_ => {
|
_ => {
|
||||||
trace!(target: "fatdb", "list_storage: Couldn't open the DB");
|
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();
|
let mut jdb = self.state_db.read().journal_db().boxed_clone();
|
||||||
|
|
||||||
state::prove_transaction_virtual(
|
state::prove_transaction_virtual(
|
||||||
jdb.as_hashdb_mut(),
|
jdb.as_hash_db_mut(),
|
||||||
header.state_root().clone(),
|
header.state_root().clone(),
|
||||||
&transaction,
|
&transaction,
|
||||||
self.engine.machine(),
|
self.engine.machine(),
|
||||||
|
@ -18,9 +18,6 @@ use ethjson;
|
|||||||
use trie::{TrieFactory, TrieSpec};
|
use trie::{TrieFactory, TrieSpec};
|
||||||
use ethtrie::RlpCodec;
|
use ethtrie::RlpCodec;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use memorydb::MemoryDB;
|
|
||||||
use keccak_hasher::KeccakHasher;
|
|
||||||
use kvdb::DBValue;
|
|
||||||
|
|
||||||
use super::HookType;
|
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() {
|
for (name, test) in tests.into_iter() {
|
||||||
start_stop_hook(&name, HookType::OnStart);
|
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 root = H256::default();
|
||||||
let mut t = factory.create(&mut memdb, &mut root);
|
let mut t = factory.create(&mut memdb, &mut root);
|
||||||
|
|
||||||
|
@ -73,7 +73,7 @@ extern crate ethcore_miner;
|
|||||||
extern crate ethereum_types;
|
extern crate ethereum_types;
|
||||||
extern crate ethjson;
|
extern crate ethjson;
|
||||||
extern crate ethkey;
|
extern crate ethkey;
|
||||||
extern crate hashdb;
|
extern crate hash_db;
|
||||||
extern crate heapsize;
|
extern crate heapsize;
|
||||||
extern crate itertools;
|
extern crate itertools;
|
||||||
extern crate journaldb;
|
extern crate journaldb;
|
||||||
@ -84,7 +84,7 @@ extern crate kvdb_memorydb;
|
|||||||
extern crate len_caching_lock;
|
extern crate len_caching_lock;
|
||||||
extern crate lru_cache;
|
extern crate lru_cache;
|
||||||
extern crate memory_cache;
|
extern crate memory_cache;
|
||||||
extern crate memorydb;
|
extern crate memory_db;
|
||||||
extern crate num;
|
extern crate num;
|
||||||
extern crate num_cpus;
|
extern crate num_cpus;
|
||||||
extern crate parity_bytes as bytes;
|
extern crate parity_bytes as bytes;
|
||||||
@ -92,7 +92,7 @@ extern crate parity_crypto;
|
|||||||
extern crate parity_machine;
|
extern crate parity_machine;
|
||||||
extern crate parity_snappy as snappy;
|
extern crate parity_snappy as snappy;
|
||||||
extern crate parking_lot;
|
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 patricia_trie_ethereum as ethtrie;
|
||||||
extern crate rand;
|
extern crate rand;
|
||||||
extern crate rayon;
|
extern crate rayon;
|
||||||
|
@ -21,7 +21,7 @@ use std::collections::BTreeMap;
|
|||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use hash::{keccak};
|
use hash::{keccak};
|
||||||
use ethereum_types::{H256, U256};
|
use ethereum_types::{H256, U256};
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use triehash::sec_trie_root;
|
use triehash::sec_trie_root;
|
||||||
|
@ -22,7 +22,7 @@ use bytes::Bytes;
|
|||||||
use ethereum_types::{H256, U256};
|
use ethereum_types::{H256, U256};
|
||||||
use ethtrie::{TrieDB, TrieDBMut};
|
use ethtrie::{TrieDB, TrieDBMut};
|
||||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP};
|
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP};
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use rlp::{RlpStream, Rlp};
|
use rlp::{RlpStream, Rlp};
|
||||||
use snapshot::Error;
|
use snapshot::Error;
|
||||||
use std::collections::HashSet;
|
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`
|
// account address hash, account properties and the storage. Each item contains at most `max_storage_items`
|
||||||
// storage records split according to snapshot format definition.
|
// 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> {
|
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 chunks = Vec::new();
|
||||||
let mut db_iter = db.iter()?;
|
let mut db_iter = db.iter()?;
|
||||||
let mut target_chunk_size = first_chunk_size;
|
let mut target_chunk_size = first_chunk_size;
|
||||||
@ -213,7 +214,7 @@ mod tests {
|
|||||||
|
|
||||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||||
use ethereum_types::{H256, Address};
|
use ethereum_types::{H256, Address};
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use rlp::Rlp;
|
use rlp::Rlp;
|
||||||
|
|
||||||
@ -236,9 +237,9 @@ mod tests {
|
|||||||
let thin_rlp = ::rlp::encode(&account);
|
let thin_rlp = ::rlp::encode(&account);
|
||||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), 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();
|
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]
|
#[test]
|
||||||
@ -247,7 +248,7 @@ mod tests {
|
|||||||
let addr = Address::random();
|
let addr = Address::random();
|
||||||
|
|
||||||
let account = {
|
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;
|
let mut root = KECCAK_NULL_RLP;
|
||||||
fill_storage(acct_db, &mut root, &mut H256::zero());
|
fill_storage(acct_db, &mut root, &mut H256::zero());
|
||||||
BasicAccount {
|
BasicAccount {
|
||||||
@ -261,9 +262,9 @@ mod tests {
|
|||||||
let thin_rlp = ::rlp::encode(&account);
|
let thin_rlp = ::rlp::encode(&account);
|
||||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), 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();
|
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]
|
#[test]
|
||||||
@ -272,7 +273,7 @@ mod tests {
|
|||||||
let addr = Address::random();
|
let addr = Address::random();
|
||||||
|
|
||||||
let account = {
|
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;
|
let mut root = KECCAK_NULL_RLP;
|
||||||
fill_storage(acct_db, &mut root, &mut H256::zero());
|
fill_storage(acct_db, &mut root, &mut H256::zero());
|
||||||
BasicAccount {
|
BasicAccount {
|
||||||
@ -286,12 +287,12 @@ mod tests {
|
|||||||
let thin_rlp = ::rlp::encode(&account);
|
let thin_rlp = ::rlp::encode(&account);
|
||||||
assert_eq!(::rlp::decode::<BasicAccount>(&thin_rlp).unwrap(), 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 root = KECCAK_NULL_RLP;
|
||||||
let mut restored_account = None;
|
let mut restored_account = None;
|
||||||
for rlp in fat_rlps {
|
for rlp in fat_rlps {
|
||||||
let fat_rlp = Rlp::new(&rlp).at(1).unwrap();
|
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();
|
root = restored_account.as_ref().unwrap().storage_root.clone();
|
||||||
}
|
}
|
||||||
assert_eq!(restored_account, Some(account));
|
assert_eq!(restored_account, Some(account));
|
||||||
@ -305,12 +306,12 @@ mod tests {
|
|||||||
let addr2 = Address::random();
|
let addr2 = Address::random();
|
||||||
|
|
||||||
let code_hash = {
|
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")
|
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"));
|
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 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_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_hashdb(), &addr2), &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);
|
assert_eq!(used_code.len(), 1);
|
||||||
|
|
||||||
let fat_rlp1 = Rlp::new(&fat_rlp1[0]).at(1).unwrap();
|
let fat_rlp1 = Rlp::new(&fat_rlp1[0]).at(1).unwrap();
|
||||||
let fat_rlp2 = Rlp::new(&fat_rlp2[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!(maybe_code.is_none());
|
||||||
assert_eq!(acc, account2);
|
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!(maybe_code, Some(b"this is definitely code".to_vec()));
|
||||||
assert_eq!(acc, account1);
|
assert_eq!(acc, account1);
|
||||||
}
|
}
|
||||||
@ -349,6 +350,6 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn encoding_empty_acc() {
|
fn encoding_empty_acc() {
|
||||||
let mut db = get_temp_state_db();
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -32,7 +32,7 @@ use types::header::Header;
|
|||||||
use types::ids::BlockId;
|
use types::ids::BlockId;
|
||||||
|
|
||||||
use ethereum_types::{H256, U256};
|
use ethereum_types::{H256, U256};
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use snappy;
|
use snappy;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@ -322,7 +322,7 @@ impl<'a> StateChunker<'a> {
|
|||||||
/// Returns a list of hashes of chunks created, or any error it may
|
/// Returns a list of hashes of chunks created, or any error it may
|
||||||
/// have encountered.
|
/// 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> {
|
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 {
|
let mut chunker = StateChunker {
|
||||||
hashes: Vec::new(),
|
hashes: Vec::new(),
|
||||||
@ -414,7 +414,7 @@ impl StateRebuilder {
|
|||||||
pairs.resize(rlp.item_count()?, (H256::new(), Vec::new()));
|
pairs.resize(rlp.item_count()?, (H256::new(), Vec::new()));
|
||||||
|
|
||||||
let status = rebuild_accounts(
|
let status = rebuild_accounts(
|
||||||
self.db.as_hashdb_mut(),
|
self.db.as_hash_db_mut(),
|
||||||
rlp,
|
rlp,
|
||||||
&mut pairs,
|
&mut pairs,
|
||||||
&self.known_code,
|
&self.known_code,
|
||||||
@ -429,7 +429,7 @@ impl StateRebuilder {
|
|||||||
// patch up all missing code. must be done after collecting all new missing code entries.
|
// 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 (code_hash, code, first_with) in status.new_code {
|
||||||
for addr_hash in self.missing_code.remove(&code_hash).unwrap_or_else(Vec::new) {
|
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));
|
db.emplace(code_hash, DBValue::from_slice(&code));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,9 +441,9 @@ impl StateRebuilder {
|
|||||||
// batch trie writes
|
// batch trie writes
|
||||||
{
|
{
|
||||||
let mut account_trie = if self.state_root != KECCAK_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)?
|
TrieDBMut::from_existing(self.db.as_hash_db_mut(), &mut self.state_root)?
|
||||||
} else {
|
} 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 {
|
for (hash, thin_rlp) in pairs {
|
||||||
|
@ -35,7 +35,7 @@ use rand::Rng;
|
|||||||
|
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use journaldb;
|
use journaldb;
|
||||||
use trie::{TrieMut, Trie};
|
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>) {
|
pub fn tick<R: Rng>(&mut self, rng: &mut R, db: &mut HashDB<KeccakHasher, DBValue>) {
|
||||||
// modify existing accounts.
|
// modify existing accounts.
|
||||||
let mut accounts_to_modify: Vec<_> = {
|
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
|
let temp = trie.iter().unwrap() // binding required due to complicated lifetime stuff
|
||||||
.filter(|_| rng.gen::<f32>() < ACCOUNT_CHURN)
|
.filter(|_| rng.gen::<f32>() < ACCOUNT_CHURN)
|
||||||
.map(Result::unwrap)
|
.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.
|
/// Take a snapshot from the given client into a temporary file.
|
||||||
/// Return a snapshot reader for it.
|
/// Return a snapshot reader for it.
|
||||||
pub fn snap(client: &Client) -> (Box<SnapshotReader>, TempDir) {
|
pub fn snap(client: &Client) -> (Box<SnapshotReader>, TempDir) {
|
||||||
|
@ -184,7 +184,7 @@ fn keep_ancient_blocks() {
|
|||||||
let start_header = bc.block_header_data(&best_hash).unwrap();
|
let start_header = bc.block_header_data(&best_hash).unwrap();
|
||||||
let state_root = start_header.state_root();
|
let state_root = start_header.state_root();
|
||||||
let state_hashes = chunk_state(
|
let state_hashes = chunk_state(
|
||||||
state_db.as_hashdb(),
|
state_db.as_hash_db(),
|
||||||
&state_root,
|
&state_root,
|
||||||
&writer,
|
&writer,
|
||||||
&Progress::default(),
|
&Progress::default(),
|
||||||
|
@ -24,7 +24,7 @@ use types::basic_account::BasicAccount;
|
|||||||
use snapshot::account;
|
use snapshot::account;
|
||||||
use snapshot::{chunk_state, Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS};
|
use snapshot::{chunk_state, Error as SnapshotError, Progress, StateRebuilder, SNAPSHOT_SUBPARTS};
|
||||||
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter};
|
use snapshot::io::{PackedReader, PackedWriter, SnapshotReader, SnapshotWriter};
|
||||||
use super::helpers::{compare_dbs, StateProducer};
|
use super::helpers::StateProducer;
|
||||||
|
|
||||||
use error::{Error, ErrorKind};
|
use error::{Error, ErrorKind};
|
||||||
|
|
||||||
@ -32,15 +32,15 @@ use rand::{XorShiftRng, SeedableRng};
|
|||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use journaldb::{self, Algorithm};
|
use journaldb::{self, Algorithm};
|
||||||
use kvdb_rocksdb::{Database, DatabaseConfig};
|
use kvdb_rocksdb::{Database, DatabaseConfig};
|
||||||
use memorydb::MemoryDB;
|
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use tempdir::TempDir;
|
use tempdir::TempDir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn snap_and_restore() {
|
fn snap_and_restore() {
|
||||||
|
use hash_db::HashDB;
|
||||||
let mut producer = StateProducer::new();
|
let mut producer = StateProducer::new();
|
||||||
let mut rng = XorShiftRng::from_seed([1, 2, 3, 4]);
|
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);
|
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
||||||
|
|
||||||
for _ in 0..150 {
|
for _ in 0..150 {
|
||||||
@ -91,8 +91,11 @@ fn snap_and_restore() {
|
|||||||
|
|
||||||
let new_db = journaldb::new(db, Algorithm::OverlayRecent, ::db::COL_STATE);
|
let new_db = journaldb::new(db, Algorithm::OverlayRecent, ::db::COL_STATE);
|
||||||
assert_eq!(new_db.earliest_era(), Some(1000));
|
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]
|
#[test]
|
||||||
@ -100,7 +103,7 @@ fn get_code_from_prev_chunk() {
|
|||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use rlp::RlpStream;
|
use rlp::RlpStream;
|
||||||
use ethereum_types::{H256, U256};
|
use ethereum_types::{H256, U256};
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
|
|
||||||
use account_db::{AccountDBMut, AccountDB};
|
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 acc: BasicAccount = ::rlp::decode(&thin_rlp).expect("error decoding basic account");
|
||||||
|
|
||||||
let mut make_chunk = |acc, hash| {
|
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[..]);
|
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();
|
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() {
|
fn checks_flag() {
|
||||||
let mut producer = StateProducer::new();
|
let mut producer = StateProducer::new();
|
||||||
let mut rng = XorShiftRng::from_seed([5, 6, 7, 8]);
|
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);
|
let db_cfg = DatabaseConfig::with_columns(::db::NUM_COLUMNS);
|
||||||
|
|
||||||
for _ in 0..10 {
|
for _ in 0..10 {
|
||||||
|
@ -25,7 +25,6 @@ use bytes::Bytes;
|
|||||||
use ethereum_types::{H256, Bloom, U256, Address};
|
use ethereum_types::{H256, Bloom, U256, Address};
|
||||||
use ethjson;
|
use ethjson;
|
||||||
use hash::{KECCAK_NULL_RLP, keccak};
|
use hash::{KECCAK_NULL_RLP, keccak};
|
||||||
use memorydb::MemoryDB;
|
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use rlp::{Rlp, RlpStream};
|
use rlp::{Rlp, RlpStream};
|
||||||
use rustc_hex::{FromHex, ToHex};
|
use rustc_hex::{FromHex, ToHex};
|
||||||
@ -556,7 +555,7 @@ fn load_from(spec_params: SpecParams, s: ethjson::spec::Spec) -> Result<Spec, Er
|
|||||||
None => {
|
None => {
|
||||||
let _ = s.run_constructors(
|
let _ = s.run_constructors(
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
BasicBackend(MemoryDB::new()),
|
BasicBackend(journaldb::new_memory_db()),
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -624,7 +623,7 @@ impl Spec {
|
|||||||
|
|
||||||
// basic accounts in 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() {
|
for (address, account) in self.genesis_state.get().iter() {
|
||||||
t.insert(&**address, &account.rlp())?;
|
t.insert(&**address, &account.rlp())?;
|
||||||
@ -635,7 +634,7 @@ impl Spec {
|
|||||||
db.note_non_null_account(address);
|
db.note_non_null_account(address);
|
||||||
account.insert_additional(
|
account.insert_additional(
|
||||||
&mut *factories.accountdb.create(
|
&mut *factories.accountdb.create(
|
||||||
db.as_hashdb_mut(),
|
db.as_hash_db_mut(),
|
||||||
keccak(address),
|
keccak(address),
|
||||||
),
|
),
|
||||||
&factories.trie,
|
&factories.trie,
|
||||||
@ -792,7 +791,7 @@ impl Spec {
|
|||||||
self.genesis_state = s;
|
self.genesis_state = s;
|
||||||
let _ = self.run_constructors(
|
let _ = self.run_constructors(
|
||||||
&Default::default(),
|
&Default::default(),
|
||||||
BasicBackend(MemoryDB::new()),
|
BasicBackend(journaldb::new_memory_db()),
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@ -813,7 +812,7 @@ impl Spec {
|
|||||||
|
|
||||||
/// Ensure that the given state DB has the trie nodes in for the genesis state.
|
/// 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> {
|
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);
|
return Ok(db);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -860,7 +859,7 @@ impl Spec {
|
|||||||
None,
|
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))?;
|
.map_err(|e| format!("Unable to initialize genesis state: {}", e))?;
|
||||||
|
|
||||||
let call = |a, d| {
|
let call = |a, d| {
|
||||||
@ -886,7 +885,7 @@ impl Spec {
|
|||||||
}.fake_sign(from);
|
}.fake_sign(from);
|
||||||
|
|
||||||
let res = ::state::prove_transaction_virtual(
|
let res = ::state::prove_transaction_virtual(
|
||||||
db.as_hashdb_mut(),
|
db.as_hash_db_mut(),
|
||||||
*genesis.state_root(),
|
*genesis.state_root(),
|
||||||
&tx,
|
&tx,
|
||||||
self.engine.machine(),
|
self.engine.machine(),
|
||||||
|
@ -22,7 +22,7 @@ use std::collections::{HashMap, BTreeMap};
|
|||||||
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
use hash::{KECCAK_EMPTY, KECCAK_NULL_RLP, keccak};
|
||||||
use ethereum_types::{H256, U256, Address};
|
use ethereum_types::{H256, U256, Address};
|
||||||
use error::Error;
|
use error::Error;
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use bytes::{Bytes, ToPretty};
|
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> {
|
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 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 item: U256 = db.get_with(key, panicky_decoder)?.unwrap_or_else(U256::zero);
|
||||||
let value: H256 = item.into();
|
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)> {
|
pub fn prove_storage(&self, db: &HashDB<KeccakHasher, DBValue>, storage_key: H256) -> TrieResult<(Vec<Bytes>, H256)> {
|
||||||
let mut recorder = Recorder::new();
|
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 item: U256 = {
|
||||||
let panicky_decoder = |bytes:&[u8]| ::rlp::decode(bytes).expect("decoding db value failed");
|
let panicky_decoder = |bytes:&[u8]| ::rlp::decode(bytes).expect("decoding db value failed");
|
||||||
let query = (&mut recorder, panicky_decoder);
|
let query = (&mut recorder, panicky_decoder);
|
||||||
@ -617,7 +617,7 @@ impl fmt::Debug for Account {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use rlp_compress::{compress, decompress, snapshot_swapper};
|
use rlp_compress::{compress, decompress, snapshot_swapper};
|
||||||
use ethereum_types::{H256, Address};
|
use ethereum_types::{H256, Address};
|
||||||
use memorydb::MemoryDB;
|
use journaldb::new_memory_db;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use super::*;
|
use super::*;
|
||||||
use account_db::*;
|
use account_db::*;
|
||||||
@ -633,7 +633,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn storage_at() {
|
fn storage_at() {
|
||||||
let mut db = MemoryDB::new();
|
let mut db = new_memory_db();
|
||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
let rlp = {
|
let rlp = {
|
||||||
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
|
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
|
||||||
@ -652,7 +652,7 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn note_code() {
|
fn note_code() {
|
||||||
let mut db = MemoryDB::new();
|
let mut db = new_memory_db();
|
||||||
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
|
|
||||||
let rlp = {
|
let rlp = {
|
||||||
@ -672,7 +672,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn commit_storage() {
|
fn commit_storage() {
|
||||||
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
|
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());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.set_storage(0.into(), 0x1234.into());
|
a.set_storage(0.into(), 0x1234.into());
|
||||||
assert_eq!(a.storage_root(), None);
|
assert_eq!(a.storage_root(), None);
|
||||||
@ -683,7 +683,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn commit_remove_commit_storage() {
|
fn commit_remove_commit_storage() {
|
||||||
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
|
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());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.set_storage(0.into(), 0x1234.into());
|
a.set_storage(0.into(), 0x1234.into());
|
||||||
a.commit_storage(&Default::default(), &mut db).unwrap();
|
a.commit_storage(&Default::default(), &mut db).unwrap();
|
||||||
@ -697,7 +697,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn commit_code() {
|
fn commit_code() {
|
||||||
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
|
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());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
||||||
assert_eq!(a.code_filth, Filth::Dirty);
|
assert_eq!(a.code_filth, Filth::Dirty);
|
||||||
@ -709,7 +709,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn reset_code() {
|
fn reset_code() {
|
||||||
let mut a = Account::new_contract(69.into(), 0.into(), KECCAK_NULL_RLP);
|
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());
|
let mut db = AccountDBMut::new(&mut db, &Address::new());
|
||||||
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
a.init_code(vec![0x55, 0x44, 0xffu8]);
|
||||||
assert_eq!(a.code_filth, Filth::Dirty);
|
assert_eq!(a.code_filth, Filth::Dirty);
|
||||||
|
@ -27,18 +27,19 @@ use std::sync::Arc;
|
|||||||
use state::Account;
|
use state::Account;
|
||||||
use parking_lot::Mutex;
|
use parking_lot::Mutex;
|
||||||
use ethereum_types::{Address, H256};
|
use ethereum_types::{Address, H256};
|
||||||
use memorydb::MemoryDB;
|
use memory_db::MemoryDB;
|
||||||
use hashdb::{AsHashDB, HashDB};
|
use hash_db::{AsHashDB, HashDB};
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
|
use journaldb::AsKeyedHashDB;
|
||||||
|
|
||||||
/// State backend. See module docs for more details.
|
/// State backend. See module docs for more details.
|
||||||
pub trait Backend: Send {
|
pub trait Backend: Send {
|
||||||
/// Treat the backend as a read-only hashdb.
|
/// 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.
|
/// 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.
|
/// Add an account entry to the cache.
|
||||||
fn add_to_account_cache(&mut self, addr: Address, data: Option<Account>, modified: bool);
|
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 {
|
impl ProofCheck {
|
||||||
/// Create a new `ProofCheck` backend from the given state items.
|
/// Create a new `ProofCheck` backend from the given state items.
|
||||||
pub fn new(proof: &[DBValue]) -> Self {
|
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); }
|
for item in proof { db.insert(item); }
|
||||||
ProofCheck(db)
|
ProofCheck(db)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HashDB<KeccakHasher, DBValue> for ProofCheck {
|
impl journaldb::KeyedHashDB for ProofCheck {
|
||||||
fn keys(&self) -> HashMap<H256, i32> { self.0.keys() }
|
fn keys(&self) -> HashMap<H256, i32> { self.0.keys() }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HashDB<KeccakHasher, DBValue> for ProofCheck {
|
||||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
self.0.get(key)
|
self.0.get(key)
|
||||||
}
|
}
|
||||||
@ -110,13 +114,13 @@ impl HashDB<KeccakHasher, DBValue> for ProofCheck {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AsHashDB<KeccakHasher, DBValue> for ProofCheck {
|
impl AsHashDB<KeccakHasher, DBValue> for ProofCheck {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Backend for ProofCheck {
|
impl Backend for ProofCheck {
|
||||||
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, _addr: Address, _data: Option<Account>, _modified: bool) {}
|
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 cache_code(&self, _hash: H256, _code: Arc<Vec<u8>>) {}
|
||||||
fn get_cached_account(&self, _addr: &Address) -> Option<Option<Account>> { None }
|
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`.
|
/// The proof-of-execution can be extracted with `extract_proof`.
|
||||||
///
|
///
|
||||||
/// This doesn't cache anything or rely on the canonical state caches.
|
/// 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.
|
base: H, // state we're proving values from.
|
||||||
changed: MemoryDB<KeccakHasher, DBValue>, // changed state via insertions.
|
changed: MemoryDB<KeccakHasher, DBValue>, // changed state via insertions.
|
||||||
proof: Mutex<HashSet<DBValue>>,
|
proof: Mutex<HashSet<DBValue>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<AH: AsHashDB<KeccakHasher, DBValue> + Send + Sync> AsHashDB<KeccakHasher, DBValue> for Proving<AH> {
|
impl<AH: AsKeyedHashDB + Send + Sync> AsKeyedHashDB for Proving<AH> {
|
||||||
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> { self }
|
fn as_keyed_hash_db(&self) -> &journaldb::KeyedHashDB { self }
|
||||||
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> { 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> {
|
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.extend(self.changed.keys());
|
||||||
keys
|
keys
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> HashDB<KeccakHasher, DBValue> for Proving<H> {
|
||||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
match self.base.as_hashdb().get(key) {
|
match self.base.as_hash_db().get(key) {
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
self.proof.lock().insert(val.clone());
|
self.proof.lock().insert(val.clone());
|
||||||
Some(val)
|
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> {
|
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) { }
|
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 {
|
pub fn new(base: H) -> Self {
|
||||||
Proving {
|
Proving {
|
||||||
base: base,
|
base: base,
|
||||||
changed: MemoryDB::<KeccakHasher, DBValue>::new(),
|
changed: journaldb::new_memory_db(),
|
||||||
proof: Mutex::new(HashSet::new()),
|
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);
|
pub struct Basic<H>(pub H);
|
||||||
|
|
||||||
impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> Backend for Basic<H> {
|
impl<H: AsHashDB<KeccakHasher, DBValue> + Send + Sync> Backend for Basic<H> {
|
||||||
fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> {
|
fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> {
|
||||||
self.0.as_hashdb()
|
self.0.as_hash_db()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
|
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
|
||||||
self.0.as_hashdb_mut()
|
self.0.as_hash_db_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_to_account_cache(&mut self, _: Address, _: Option<Account>, _: bool) { }
|
fn add_to_account_cache(&mut self, _: Address, _: Option<Account>, _: bool) { }
|
||||||
|
@ -43,7 +43,7 @@ use state_db::StateDB;
|
|||||||
use factory::VmFactory;
|
use factory::VmFactory;
|
||||||
|
|
||||||
use ethereum_types::{H256, U256, Address};
|
use ethereum_types::{H256, U256, Address};
|
||||||
use hashdb::{HashDB, AsHashDB};
|
use hash_db::{HashDB, AsHashDB};
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
@ -366,7 +366,7 @@ impl<B: Backend> State<B> {
|
|||||||
let mut root = H256::new();
|
let mut root = H256::new();
|
||||||
{
|
{
|
||||||
// init trie and reset root to null
|
// 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 {
|
State {
|
||||||
@ -381,7 +381,7 @@ impl<B: Backend> State<B> {
|
|||||||
|
|
||||||
/// Creates new state with existing state root
|
/// Creates new state with existing state root
|
||||||
pub fn from_existing(db: B, root: H256, account_start_nonce: U256, factories: Factories) -> TrieResult<State<B>> {
|
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)));
|
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 {
|
let trie_res = self.db.get_cached(address, |acc| match acc {
|
||||||
None => Ok(H256::new()),
|
None => Ok(H256::new()),
|
||||||
Some(a) => {
|
Some(a) => {
|
||||||
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), a.address_hash(address));
|
let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), a.address_hash(address));
|
||||||
f_at(a, account_db.as_hashdb(), key)
|
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.
|
// otherwise cache the account localy and cache storage key there.
|
||||||
if let Some(ref mut acc) = local_account {
|
if let Some(ref mut acc) = local_account {
|
||||||
if let Some(ref account) = acc.account {
|
if let Some(ref account) = acc.account {
|
||||||
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(address));
|
let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), account.address_hash(address));
|
||||||
return f_at(account, account_db.as_hashdb(), key)
|
return f_at(account, account_db.as_hash_db(), key)
|
||||||
} else {
|
} else {
|
||||||
return Ok(H256::new())
|
return Ok(H256::new())
|
||||||
}
|
}
|
||||||
@ -689,12 +689,13 @@ impl<B: Backend> State<B> {
|
|||||||
if self.db.is_known_null(address) { return Ok(H256::zero()) }
|
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
|
// 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 from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed");
|
||||||
let maybe_acc = db.get_with(address, from_rlp)?;
|
let maybe_acc = db.get_with(address, from_rlp)?;
|
||||||
let r = maybe_acc.as_ref().map_or(Ok(H256::new()), |a| {
|
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));
|
let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), a.address_hash(address));
|
||||||
f_at(a, account_db.as_hashdb(), key)
|
f_at(a, account_db.as_hash_db(), key)
|
||||||
});
|
});
|
||||||
self.insert_cache(address, AccountEntry::new_clean(maybe_acc));
|
self.insert_cache(address, AccountEntry::new_clean(maybe_acc));
|
||||||
r
|
r
|
||||||
@ -887,9 +888,9 @@ impl<B: Backend> State<B> {
|
|||||||
if let Some(ref mut account) = a.account {
|
if let Some(ref mut account) = a.account {
|
||||||
let addr_hash = account.address_hash(address);
|
let addr_hash = account.address_hash(address);
|
||||||
{
|
{
|
||||||
let mut account_db = self.factories.accountdb.create(self.db.as_hashdb_mut(), addr_hash);
|
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_hashdb_mut())?;
|
account.commit_storage(&self.factories.trie, account_db.as_hash_db_mut())?;
|
||||||
account.commit_code(account_db.as_hashdb_mut());
|
account.commit_code(account_db.as_hash_db_mut());
|
||||||
}
|
}
|
||||||
if !account.is_empty() {
|
if !account.is_empty() {
|
||||||
self.db.note_non_null_account(address);
|
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()) {
|
for (address, ref mut a) in accounts.iter_mut().filter(|&(_, ref a)| a.is_dirty()) {
|
||||||
a.state = AccountState::Committed;
|
a.state = AccountState::Committed;
|
||||||
match a.account {
|
match a.account {
|
||||||
@ -981,7 +982,8 @@ impl<B: Backend> State<B> {
|
|||||||
|
|
||||||
let mut result = BTreeMap::new();
|
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
|
// put trie in cache
|
||||||
for item in trie.iter()? {
|
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> {
|
fn account_to_pod_account(&self, account: &Account, address: &Address) -> Result<PodAccount, Error> {
|
||||||
let mut pod_storage = BTreeMap::new();
|
let mut pod_storage = BTreeMap::new();
|
||||||
let addr_hash = account.address_hash(address);
|
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 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()? {
|
for o_kv in trie.iter()? {
|
||||||
if let Ok((key, val)) = o_kv {
|
if let Ok((key, val)) = o_kv {
|
||||||
pod_storage.insert(key[..].into(), U256::from(&val[..]).into());
|
pod_storage.insert(key[..].into(), U256::from(&val[..]).into());
|
||||||
@ -1134,8 +1137,8 @@ impl<B: Backend> State<B> {
|
|||||||
// check local cache first
|
// check local cache first
|
||||||
if let Some(ref mut maybe_acc) = self.cache.borrow_mut().get_mut(a) {
|
if let Some(ref mut maybe_acc) = self.cache.borrow_mut().get_mut(a) {
|
||||||
if let Some(ref mut account) = maybe_acc.account {
|
if let Some(ref mut account) = maybe_acc.account {
|
||||||
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
|
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_hashdb()) {
|
if Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) {
|
||||||
return Ok(f(Some(account)));
|
return Ok(f(Some(account)));
|
||||||
} else {
|
} else {
|
||||||
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))));
|
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))));
|
||||||
@ -1146,8 +1149,8 @@ impl<B: Backend> State<B> {
|
|||||||
// check global cache
|
// check global cache
|
||||||
let result = self.db.get_cached(a, |mut acc| {
|
let result = self.db.get_cached(a, |mut acc| {
|
||||||
if let Some(ref mut account) = acc {
|
if let Some(ref mut account) = acc {
|
||||||
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
|
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_hashdb()) {
|
if !Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) {
|
||||||
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))));
|
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)); }
|
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
|
// 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 from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed");
|
||||||
let mut maybe_acc = db.get_with(a, from_rlp)?;
|
let mut maybe_acc = db.get_with(a, from_rlp)?;
|
||||||
if let Some(ref mut account) = maybe_acc.as_mut() {
|
if let Some(ref mut account) = maybe_acc.as_mut() {
|
||||||
let accountdb = self.factories.accountdb.readonly(self.db.as_hashdb(), account.address_hash(a));
|
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_hashdb()) {
|
if !Self::update_account_cache(require, account, &self.db, accountdb.as_hash_db()) {
|
||||||
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))));
|
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)),
|
Some(acc) => self.insert_cache(a, AccountEntry::new_clean_cached(acc)),
|
||||||
None => {
|
None => {
|
||||||
let maybe_acc = if !self.db.is_known_null(a) {
|
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") };
|
let from_rlp = |b:&[u8]| { Account::from_rlp(b).expect("decoding db value failed") };
|
||||||
AccountEntry::new_clean(db.get_with(a, from_rlp)?)
|
AccountEntry::new_clean(db.get_with(a, from_rlp)?)
|
||||||
} else {
|
} else {
|
||||||
@ -1220,9 +1225,9 @@ impl<B: Backend> State<B> {
|
|||||||
|
|
||||||
if require_code {
|
if require_code {
|
||||||
let addr_hash = account.address_hash(a);
|
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))))
|
return Err(Box::new(TrieError::IncompleteDatabase(H256::from(a))))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1245,7 +1250,8 @@ impl<B: Backend> State<B> {
|
|||||||
/// `account_key` == keccak(address)
|
/// `account_key` == keccak(address)
|
||||||
pub fn prove_account(&self, account_key: H256) -> TrieResult<(Vec<Bytes>, BasicAccount)> {
|
pub fn prove_account(&self, account_key: H256) -> TrieResult<(Vec<Bytes>, BasicAccount)> {
|
||||||
let mut recorder = Recorder::new();
|
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 maybe_account: Option<BasicAccount> = {
|
||||||
let panicky_decoder = |bytes: &[u8]| {
|
let panicky_decoder = |bytes: &[u8]| {
|
||||||
::rlp::decode(bytes).expect(&format!("prove_account, could not query trie for account key={}", &account_key))
|
::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)> {
|
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
|
// TODO: probably could look into cache somehow but it's keyed by
|
||||||
// address, not keccak(address).
|
// 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 from_rlp = |b: &[u8]| Account::from_rlp(b).expect("decoding db value failed");
|
||||||
let acc = match trie.get_with(&account_key, from_rlp)? {
|
let acc = match trie.get_with(&account_key, from_rlp)? {
|
||||||
Some(acc) => acc,
|
Some(acc) => acc,
|
||||||
None => return Ok((Vec::new(), H256::new())),
|
None => return Ok((Vec::new(), H256::new())),
|
||||||
};
|
};
|
||||||
|
|
||||||
let account_db = self.factories.accountdb.readonly(self.db.as_hashdb(), account_key);
|
let account_db = self.factories.accountdb.readonly(self.db.as_hash_db(), account_key);
|
||||||
acc.prove_storage(account_db.as_hashdb(), storage_key)
|
acc.prove_storage(account_db.as_hash_db(), storage_key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ use byteorder::{LittleEndian, ByteOrder};
|
|||||||
use db::COL_ACCOUNT_BLOOM;
|
use db::COL_ACCOUNT_BLOOM;
|
||||||
use ethereum_types::{H256, Address};
|
use ethereum_types::{H256, Address};
|
||||||
use hash::keccak;
|
use hash::keccak;
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use journaldb::JournalDB;
|
use journaldb::JournalDB;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
||||||
@ -313,13 +313,13 @@ impl StateDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Conversion method to interpret self as `HashDB` reference
|
/// Conversion method to interpret self as `HashDB` reference
|
||||||
pub fn as_hashdb(&self) -> &HashDB<KeccakHasher, DBValue> {
|
pub fn as_hash_db(&self) -> &HashDB<KeccakHasher, DBValue> {
|
||||||
self.db.as_hashdb()
|
self.db.as_hash_db()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Conversion method to interpret self as mutable `HashDB` reference
|
/// Conversion method to interpret self as mutable `HashDB` reference
|
||||||
pub fn as_hashdb_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
|
pub fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
|
||||||
self.db.as_hashdb_mut()
|
self.db.as_hash_db_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Clone the database.
|
/// Clone the database.
|
||||||
@ -407,10 +407,10 @@ impl StateDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl state::Backend for 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> {
|
fn as_hash_db_mut(&mut self) -> &mut HashDB<KeccakHasher, DBValue> {
|
||||||
self.db.as_hashdb_mut()
|
self.db.as_hash_db_mut()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_to_account_cache(&mut self, addr: Address, data: Option<Account>, modified: bool) {
|
fn add_to_account_cache(&mut self, addr: Address, data: Option<Account>, modified: bool) {
|
||||||
|
@ -19,7 +19,7 @@ ethereum-types = "0.4"
|
|||||||
ethkey = { path = "../../accounts/ethkey" }
|
ethkey = { path = "../../accounts/ethkey" }
|
||||||
ethstore = { path = "../../accounts/ethstore" }
|
ethstore = { path = "../../accounts/ethstore" }
|
||||||
fastmap = { path = "../../util/fastmap" }
|
fastmap = { path = "../../util/fastmap" }
|
||||||
hashdb = "0.3.0"
|
hash-db = "0.11.0"
|
||||||
heapsize = "0.4"
|
heapsize = "0.4"
|
||||||
keccak-hash = "0.1"
|
keccak-hash = "0.1"
|
||||||
keccak-hasher = { path = "../../util/keccak-hasher" }
|
keccak-hasher = { path = "../../util/keccak-hasher" }
|
||||||
|
@ -7,7 +7,7 @@ authors = ["Parity Technologies <admin@parity.io>"]
|
|||||||
byteorder = "1.0"
|
byteorder = "1.0"
|
||||||
parity-bytes = "0.1"
|
parity-bytes = "0.1"
|
||||||
ethereum-types = "0.4"
|
ethereum-types = "0.4"
|
||||||
patricia-trie = "0.3.0"
|
trie-db = "0.11.0"
|
||||||
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
|
patricia-trie-ethereum = { path = "../../util/patricia-trie-ethereum" }
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
ethjson = { path = "../../json" }
|
ethjson = { path = "../../json" }
|
||||||
|
@ -22,7 +22,7 @@ extern crate ethjson;
|
|||||||
extern crate rlp;
|
extern crate rlp;
|
||||||
extern crate keccak_hash as hash;
|
extern crate keccak_hash as hash;
|
||||||
extern crate patricia_trie_ethereum as ethtrie;
|
extern crate patricia_trie_ethereum as ethtrie;
|
||||||
extern crate patricia_trie as trie;
|
extern crate trie_db as trie;
|
||||||
|
|
||||||
mod action_params;
|
mod action_params;
|
||||||
mod call_type;
|
mod call_type;
|
||||||
|
@ -59,7 +59,7 @@ keccak-hash = "0.1.2"
|
|||||||
parity-runtime = { path = "../util/runtime" }
|
parity-runtime = { path = "../util/runtime" }
|
||||||
parity-updater = { path = "../updater" }
|
parity-updater = { path = "../updater" }
|
||||||
parity-version = { path = "../util/version" }
|
parity-version = { path = "../util/version" }
|
||||||
patricia-trie = "0.3.0"
|
trie-db = "0.11.0"
|
||||||
rlp = { version = "0.3.0", features = ["ethereum"] }
|
rlp = { version = "0.3.0", features = ["ethereum"] }
|
||||||
stats = { path = "../util/stats" }
|
stats = { path = "../util/stats" }
|
||||||
vm = { path = "../ethcore/vm" }
|
vm = { path = "../ethcore/vm" }
|
||||||
|
@ -63,7 +63,7 @@ extern crate keccak_hash as hash;
|
|||||||
extern crate parity_runtime;
|
extern crate parity_runtime;
|
||||||
extern crate parity_updater as updater;
|
extern crate parity_updater as updater;
|
||||||
extern crate parity_version as version;
|
extern crate parity_version as version;
|
||||||
extern crate patricia_trie as trie;
|
extern crate trie_db as trie;
|
||||||
extern crate eip_712;
|
extern crate eip_712;
|
||||||
extern crate rlp;
|
extern crate rlp;
|
||||||
extern crate stats;
|
extern crate stats;
|
||||||
|
@ -8,12 +8,12 @@ license = "GPL3"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
parity-bytes = "0.1"
|
parity-bytes = "0.1"
|
||||||
ethereum-types = "0.4"
|
ethereum-types = "0.4"
|
||||||
hashdb = "0.3.0"
|
hash-db = "0.11.0"
|
||||||
heapsize = "0.4"
|
heapsize = "0.4"
|
||||||
keccak-hasher = { path = "../keccak-hasher" }
|
keccak-hasher = { path = "../keccak-hasher" }
|
||||||
kvdb = "0.1"
|
kvdb = "0.1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
memorydb = "0.3.0"
|
memory-db = "0.11.0"
|
||||||
parking_lot = "0.7"
|
parking_lot = "0.7"
|
||||||
fastmap = { path = "../../util/fastmap" }
|
fastmap = { path = "../../util/fastmap" }
|
||||||
rlp = { version = "0.3.0", features = ["ethereum"] }
|
rlp = { version = "0.3.0", features = ["ethereum"] }
|
||||||
|
@ -23,12 +23,12 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use hashdb::*;
|
use hash_db::{HashDB};
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
||||||
use rlp::{encode, decode};
|
use rlp::{encode, decode};
|
||||||
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, error_key_already_exists, error_negatively_reference_hash};
|
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;
|
use traits::JournalDB;
|
||||||
|
|
||||||
/// Implementation of the `HashDB` trait for a disk-backed database with a memory overlay
|
/// 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.")
|
.expect("Low-level database error.")
|
||||||
.map(|val| decode::<u64>(&val).expect("decoding db value failed"));
|
.map(|val| decode::<u64>(&val).expect("decoding db value failed"));
|
||||||
ArchiveDB {
|
ArchiveDB {
|
||||||
overlay: MemoryDB::new(),
|
overlay: ::new_memory_db(),
|
||||||
backing,
|
backing,
|
||||||
latest_era,
|
latest_era,
|
||||||
column,
|
column,
|
||||||
@ -62,31 +62,14 @@ impl ArchiveDB {
|
|||||||
fn payload(&self, key: &H256) -> Option<DBValue> {
|
fn payload(&self, key: &H256) -> Option<DBValue> {
|
||||||
self.backing.get(self.column, key).expect("Low-level database error. Some issue with your hard disk?")
|
self.backing.get(self.column, key).expect("Low-level database error. Some issue with your hard disk?")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HashDB<KeccakHasher, DBValue> for ArchiveDB {
|
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> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
if let Some((d, rc)) = self.overlay.raw(key) {
|
if let Some((d, rc)) = self.overlay.raw(key) {
|
||||||
if rc > 0 {
|
if rc > 0 {
|
||||||
return Some(d);
|
return Some(d.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.payload(key)
|
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 {
|
impl JournalDB for ArchiveDB {
|
||||||
|
|
||||||
fn boxed_clone(&self) -> Box<JournalDB> {
|
fn boxed_clone(&self) -> Box<JournalDB> {
|
||||||
Box::new(ArchiveDB {
|
Box::new(ArchiveDB {
|
||||||
overlay: self.overlay.clone(),
|
overlay: self.overlay.clone(),
|
||||||
@ -202,7 +206,7 @@ impl JournalDB for ArchiveDB {
|
|||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use keccak::keccak;
|
use keccak::keccak;
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use super::*;
|
use super::*;
|
||||||
use {kvdb_memorydb, JournalDB};
|
use {kvdb_memorydb, JournalDB};
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Impls of the `AsHashDB` upcast trait for all different variants of DB
|
//! 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 keccak_hasher::KeccakHasher;
|
||||||
use archivedb::ArchiveDB;
|
use archivedb::ArchiveDB;
|
||||||
use earlymergedb::EarlyMergeDB;
|
use earlymergedb::EarlyMergeDB;
|
||||||
@ -23,28 +23,49 @@ use overlayrecentdb::OverlayRecentDB;
|
|||||||
use refcounteddb::RefCountedDB;
|
use refcounteddb::RefCountedDB;
|
||||||
use overlaydb::OverlayDB;
|
use overlaydb::OverlayDB;
|
||||||
use kvdb::DBValue;
|
use kvdb::DBValue;
|
||||||
|
use crate::{KeyedHashDB, AsKeyedHashDB};
|
||||||
|
|
||||||
impl AsHashDB<KeccakHasher, DBValue> for ArchiveDB {
|
impl AsHashDB<KeccakHasher, DBValue> for ArchiveDB {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsHashDB<KeccakHasher, DBValue> for EarlyMergeDB {
|
impl AsHashDB<KeccakHasher, DBValue> for EarlyMergeDB {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsHashDB<KeccakHasher, DBValue> for OverlayRecentDB {
|
impl AsHashDB<KeccakHasher, DBValue> for OverlayRecentDB {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsHashDB<KeccakHasher, DBValue> for RefCountedDB {
|
impl AsHashDB<KeccakHasher, DBValue> for RefCountedDB {
|
||||||
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 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl AsHashDB<KeccakHasher, DBValue> for OverlayDB {
|
impl AsHashDB<KeccakHasher, DBValue> for OverlayDB {
|
||||||
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 }
|
||||||
|
}
|
||||||
|
|
||||||
|
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 }
|
||||||
}
|
}
|
||||||
|
@ -23,11 +23,11 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use hashdb::*;
|
use hash_db::{HashDB};
|
||||||
use heapsize::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
||||||
use memorydb::*;
|
use memory_db::*;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use rlp::{encode, decode};
|
use rlp::{encode, decode};
|
||||||
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY, error_negatively_reference_hash, error_key_already_exists};
|
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 (latest_era, refs) = EarlyMergeDB::read_refs(&*backing, col);
|
||||||
let refs = Some(Arc::new(RwLock::new(refs)));
|
let refs = Some(Arc::new(RwLock::new(refs)));
|
||||||
EarlyMergeDB {
|
EarlyMergeDB {
|
||||||
overlay: MemoryDB::new(),
|
overlay: ::new_memory_db(),
|
||||||
backing: backing,
|
backing: backing,
|
||||||
refs: refs,
|
refs: refs,
|
||||||
latest_era: latest_era,
|
latest_era: latest_era,
|
||||||
@ -285,31 +285,14 @@ impl EarlyMergeDB {
|
|||||||
}
|
}
|
||||||
(latest_era, refs)
|
(latest_era, refs)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HashDB<KeccakHasher, DBValue> for EarlyMergeDB {
|
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> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
if let Some((d, rc)) = self.overlay.raw(key) {
|
if let Some((d, rc)) = self.overlay.raw(key) {
|
||||||
if rc > 0 {
|
if rc > 0 {
|
||||||
return Some(d)
|
return Some(d.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
self.payload(key)
|
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 {
|
impl JournalDB for EarlyMergeDB {
|
||||||
fn boxed_clone(&self) -> Box<JournalDB> {
|
fn boxed_clone(&self) -> Box<JournalDB> {
|
||||||
Box::new(EarlyMergeDB {
|
Box::new(EarlyMergeDB {
|
||||||
@ -523,7 +526,7 @@ impl JournalDB for EarlyMergeDB {
|
|||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use keccak::keccak;
|
use keccak::keccak;
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use super::*;
|
use super::*;
|
||||||
use super::super::traits::JournalDB;
|
use super::super::traits::JournalDB;
|
||||||
use kvdb_memorydb;
|
use kvdb_memorydb;
|
||||||
|
@ -22,10 +22,10 @@ extern crate log;
|
|||||||
|
|
||||||
extern crate ethereum_types;
|
extern crate ethereum_types;
|
||||||
extern crate parity_bytes as bytes;
|
extern crate parity_bytes as bytes;
|
||||||
extern crate hashdb;
|
extern crate hash_db;
|
||||||
extern crate keccak_hasher;
|
extern crate keccak_hasher;
|
||||||
extern crate kvdb;
|
extern crate kvdb;
|
||||||
extern crate memorydb;
|
extern crate memory_db;
|
||||||
extern crate parking_lot;
|
extern crate parking_lot;
|
||||||
extern crate fastmap;
|
extern crate fastmap;
|
||||||
extern crate rlp;
|
extern crate rlp;
|
||||||
@ -54,6 +54,11 @@ pub mod overlaydb;
|
|||||||
/// Export the `JournalDB` trait.
|
/// Export the `JournalDB` trait.
|
||||||
pub use self::traits::JournalDB;
|
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.
|
/// Journal database operating strategy.
|
||||||
#[derive(Debug, PartialEq, Clone, Copy)]
|
#[derive(Debug, PartialEq, Clone, Copy)]
|
||||||
pub enum Algorithm {
|
pub enum Algorithm {
|
||||||
@ -158,6 +163,10 @@ fn error_negatively_reference_hash(hash: ðereum_types::H256) -> io::Error {
|
|||||||
io::Error::new(io::ErrorKind::Other, format!("Entry {} removed from database more times than it was added.", hash))
|
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)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::Algorithm;
|
use super::Algorithm;
|
||||||
|
@ -23,9 +23,9 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable, encode, decode};
|
use rlp::{Rlp, RlpStream, Encodable, DecoderError, Decodable, encode, decode};
|
||||||
use hashdb::*;
|
use hash_db::{HashDB};
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use memorydb::*;
|
use memory_db::*;
|
||||||
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
||||||
use super::{error_negatively_reference_hash};
|
use super::{error_negatively_reference_hash};
|
||||||
|
|
||||||
@ -80,7 +80,7 @@ impl Decodable for Payload {
|
|||||||
impl OverlayDB {
|
impl OverlayDB {
|
||||||
/// Create a new instance of OverlayDB given a `backing` database.
|
/// Create a new instance of OverlayDB given a `backing` database.
|
||||||
pub fn new(backing: Arc<KeyValueDB>, col: Option<u32>) -> OverlayDB {
|
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.
|
/// Create a new instance of OverlayDB with an anonymous temporary database.
|
||||||
@ -153,9 +153,10 @@ impl OverlayDB {
|
|||||||
true
|
true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl HashDB<KeccakHasher, DBValue> for OverlayDB {
|
impl crate::KeyedHashDB for OverlayDB {
|
||||||
fn keys(&self) -> HashMap<H256, i32> {
|
fn keys(&self) -> HashMap<H256, i32> {
|
||||||
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
|
let mut ret: HashMap<H256, i32> = self.backing.iter(self.column)
|
||||||
.map(|(key, _)| {
|
.map(|(key, _)| {
|
||||||
@ -178,13 +179,16 @@ impl HashDB<KeccakHasher, DBValue> for OverlayDB {
|
|||||||
ret
|
ret
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
impl HashDB<KeccakHasher, DBValue> for OverlayDB {
|
||||||
fn get(&self, key: &H256) -> Option<DBValue> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
// return ok if positive; if negative, check backing - might be enough references there to make
|
// return ok if positive; if negative, check backing - might be enough references there to make
|
||||||
// it positive again.
|
// it positive again.
|
||||||
let k = self.overlay.raw(key);
|
let k = self.overlay.raw(key);
|
||||||
let memrc = {
|
let memrc = {
|
||||||
if let Some((d, rc)) = k {
|
if let Some((d, rc)) = k {
|
||||||
if rc > 0 { return Some(d); }
|
if rc > 0 { return Some(d.clone()); }
|
||||||
rc
|
rc
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
@ -23,11 +23,11 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use hashdb::*;
|
use hash_db::{HashDB};
|
||||||
use heapsize::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
||||||
use memorydb::*;
|
use memory_db::*;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use fastmap::H256FastMap;
|
use fastmap::H256FastMap;
|
||||||
use rlp::{Rlp, RlpStream, encode, decode, DecoderError, Decodable, Encodable};
|
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 {
|
pub fn new(backing: Arc<KeyValueDB>, col: Option<u32>) -> OverlayRecentDB {
|
||||||
let journal_overlay = Arc::new(RwLock::new(OverlayRecentDB::read_overlay(&*backing, col)));
|
let journal_overlay = Arc::new(RwLock::new(OverlayRecentDB::read_overlay(&*backing, col)));
|
||||||
OverlayRecentDB {
|
OverlayRecentDB {
|
||||||
transaction_overlay: MemoryDB::new(),
|
transaction_overlay: ::new_memory_db(),
|
||||||
backing: backing,
|
backing: backing,
|
||||||
journal_overlay: journal_overlay,
|
journal_overlay: journal_overlay,
|
||||||
column: col,
|
column: col,
|
||||||
@ -181,7 +181,7 @@ impl OverlayRecentDB {
|
|||||||
|
|
||||||
fn read_overlay(db: &KeyValueDB, col: Option<u32>) -> JournalOverlay {
|
fn read_overlay(db: &KeyValueDB, col: Option<u32>) -> JournalOverlay {
|
||||||
let mut journal = HashMap::new();
|
let mut journal = HashMap::new();
|
||||||
let mut overlay = MemoryDB::new();
|
let mut overlay = ::new_memory_db();
|
||||||
let mut count = 0;
|
let mut count = 0;
|
||||||
let mut latest_era = None;
|
let mut latest_era = None;
|
||||||
let mut earliest_era = None;
|
let mut earliest_era = None;
|
||||||
@ -233,6 +233,7 @@ impl OverlayRecentDB {
|
|||||||
cumulative_size: cumulative_size,
|
cumulative_size: cumulative_size,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
@ -242,7 +243,28 @@ fn to_short_key(key: &H256) -> H256 {
|
|||||||
k
|
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 {
|
impl JournalDB for OverlayRecentDB {
|
||||||
|
|
||||||
fn boxed_clone(&self) -> Box<JournalDB> {
|
fn boxed_clone(&self) -> Box<JournalDB> {
|
||||||
Box::new(self.clone())
|
Box::new(self.clone())
|
||||||
}
|
}
|
||||||
@ -365,7 +387,7 @@ impl JournalDB for OverlayRecentDB {
|
|||||||
for h in &journal.insertions {
|
for h in &journal.insertions {
|
||||||
if let Some((d, rc)) = journal_overlay.backing_overlay.raw(&to_short_key(h)) {
|
if let Some((d, rc)) = journal_overlay.backing_overlay.raw(&to_short_key(h)) {
|
||||||
if rc > 0 {
|
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 {
|
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> {
|
fn get(&self, key: &H256) -> Option<DBValue> {
|
||||||
if let Some((d, rc)) = self.transaction_overlay.raw(key) {
|
if let Some((d, rc)) = self.transaction_overlay.raw(key) {
|
||||||
if rc > 0 {
|
if rc > 0 {
|
||||||
return Some(d)
|
return Some(d.clone())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let v = {
|
let v = {
|
||||||
@ -493,7 +497,7 @@ mod tests {
|
|||||||
|
|
||||||
use keccak::keccak;
|
use keccak::keccak;
|
||||||
use super::*;
|
use super::*;
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use {kvdb_memorydb, JournalDB};
|
use {kvdb_memorydb, JournalDB};
|
||||||
|
|
||||||
fn new_db() -> OverlayRecentDB {
|
fn new_db() -> OverlayRecentDB {
|
||||||
|
@ -22,11 +22,11 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use hashdb::*;
|
use hash_db::{HashDB};
|
||||||
use heapsize::HeapSizeOf;
|
use heapsize::HeapSizeOf;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
use kvdb::{KeyValueDB, DBTransaction, DBValue};
|
||||||
use memorydb::MemoryDB;
|
use memory_db::MemoryDB;
|
||||||
use overlaydb::OverlayDB;
|
use overlaydb::OverlayDB;
|
||||||
use rlp::{encode, decode};
|
use rlp::{encode, decode};
|
||||||
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY};
|
use super::{DB_PREFIX_LEN, LATEST_ERA_KEY};
|
||||||
@ -81,7 +81,6 @@ impl RefCountedDB {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl HashDB<KeccakHasher, DBValue> for 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 get(&self, key: &H256) -> Option<DBValue> { self.forward.get(key) }
|
||||||
fn contains(&self, key: &H256) -> bool { self.forward.contains(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 }
|
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()); }
|
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 {
|
impl JournalDB for RefCountedDB {
|
||||||
fn boxed_clone(&self) -> Box<JournalDB> {
|
fn boxed_clone(&self) -> Box<JournalDB> {
|
||||||
Box::new(RefCountedDB {
|
Box::new(RefCountedDB {
|
||||||
@ -216,7 +219,7 @@ impl JournalDB for RefCountedDB {
|
|||||||
mod tests {
|
mod tests {
|
||||||
|
|
||||||
use keccak::keccak;
|
use keccak::keccak;
|
||||||
use hashdb::HashDB;
|
use hash_db::HashDB;
|
||||||
use super::*;
|
use super::*;
|
||||||
use {JournalDB, kvdb_memorydb};
|
use {JournalDB, kvdb_memorydb};
|
||||||
|
|
||||||
|
@ -21,13 +21,28 @@ use std::sync::Arc;
|
|||||||
|
|
||||||
use bytes::Bytes;
|
use bytes::Bytes;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use hashdb::HashDB;
|
use hash_db::{HashDB, AsHashDB};
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use kvdb::{self, DBTransaction, DBValue};
|
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
|
/// A `HashDB` which can manage a short-term journal potentially containing many forks of mutually
|
||||||
/// exclusive actions.
|
/// exclusive actions.
|
||||||
pub trait JournalDB: HashDB<KeccakHasher, DBValue> {
|
pub trait JournalDB: KeyedHashDB {
|
||||||
|
|
||||||
/// Return a copy of ourself, in a box.
|
/// Return a copy of ourself, in a box.
|
||||||
fn boxed_clone(&self) -> Box<JournalDB>;
|
fn boxed_clone(&self) -> Box<JournalDB>;
|
||||||
|
|
||||||
@ -78,7 +93,7 @@ pub trait JournalDB: HashDB<KeccakHasher, DBValue> {
|
|||||||
fn flush(&self) {}
|
fn flush(&self) {}
|
||||||
|
|
||||||
/// Consolidate all the insertions and deletions in the given memory overlay.
|
/// 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
|
/// Commit all changes in a single batch
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
|
@ -8,5 +8,5 @@ license = "GPL-3.0"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
ethereum-types = "0.4"
|
ethereum-types = "0.4"
|
||||||
tiny-keccak = "1.4.2"
|
tiny-keccak = "1.4.2"
|
||||||
hashdb = "0.3.0"
|
hash-db = "0.11.0"
|
||||||
plain_hasher = "0.2"
|
plain_hasher = "0.2"
|
||||||
|
@ -15,12 +15,12 @@
|
|||||||
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
// along with Parity Ethereum. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
//! Hasher implementation for the Keccak-256 hash
|
//! Hasher implementation for the Keccak-256 hash
|
||||||
extern crate hashdb;
|
extern crate hash_db;
|
||||||
extern crate ethereum_types;
|
extern crate ethereum_types;
|
||||||
extern crate tiny_keccak;
|
extern crate tiny_keccak;
|
||||||
extern crate plain_hasher;
|
extern crate plain_hasher;
|
||||||
|
|
||||||
use hashdb::Hasher;
|
use hash_db::Hasher;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use tiny_keccak::Keccak;
|
use tiny_keccak::Keccak;
|
||||||
use plain_hasher::PlainHasher;
|
use plain_hasher::PlainHasher;
|
||||||
|
@ -6,14 +6,15 @@ description = "Merkle-Patricia Trie (Ethereum Style)"
|
|||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
patricia-trie = "0.3.0"
|
trie-db = "0.11.0"
|
||||||
keccak-hasher = { version = "0.1.1", path = "../keccak-hasher" }
|
keccak-hasher = { version = "0.1.1", path = "../keccak-hasher" }
|
||||||
hashdb = "0.3.0"
|
hash-db = "0.11.0"
|
||||||
rlp = "0.3.0"
|
rlp = "0.3.0"
|
||||||
parity-bytes = "0.1"
|
parity-bytes = "0.1"
|
||||||
ethereum-types = "0.4"
|
ethereum-types = "0.4"
|
||||||
elastic-array = "0.10"
|
elastic-array = "0.10"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
memorydb = "0.3.0"
|
memory-db = "0.11.0"
|
||||||
keccak-hash = "0.1.2"
|
keccak-hash = "0.1.2"
|
||||||
|
journaldb = { path = "../journaldb" }
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
//! Façade crate for `patricia_trie` for Ethereum specific impls
|
//! 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 elastic_array;
|
||||||
extern crate parity_bytes;
|
extern crate parity_bytes;
|
||||||
extern crate ethereum_types;
|
extern crate ethereum_types;
|
||||||
extern crate hashdb;
|
extern crate hash_db;
|
||||||
extern crate keccak_hasher;
|
extern crate keccak_hasher;
|
||||||
extern crate rlp;
|
extern crate rlp;
|
||||||
|
|
||||||
@ -42,18 +42,19 @@ pub type RlpCodec = RlpNodeCodec<KeccakHasher>;
|
|||||||
///
|
///
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// extern crate patricia_trie as trie;
|
/// extern crate trie_db as trie;
|
||||||
/// extern crate patricia_trie_ethereum as ethtrie;
|
/// extern crate patricia_trie_ethereum as ethtrie;
|
||||||
/// extern crate hashdb;
|
/// extern crate hash_db;
|
||||||
/// extern crate keccak_hasher;
|
/// extern crate keccak_hasher;
|
||||||
/// extern crate memorydb;
|
/// extern crate memory_db;
|
||||||
/// extern crate ethereum_types;
|
/// extern crate ethereum_types;
|
||||||
/// extern crate elastic_array;
|
/// extern crate elastic_array;
|
||||||
|
/// extern crate journaldb;
|
||||||
///
|
///
|
||||||
/// use trie::*;
|
/// use trie::*;
|
||||||
/// use hashdb::*;
|
/// use hash_db::*;
|
||||||
/// use keccak_hasher::KeccakHasher;
|
/// use keccak_hasher::KeccakHasher;
|
||||||
/// use memorydb::*;
|
/// use memory_db::*;
|
||||||
/// use ethereum_types::H256;
|
/// use ethereum_types::H256;
|
||||||
/// use ethtrie::{TrieDB, TrieDBMut};
|
/// use ethtrie::{TrieDB, TrieDBMut};
|
||||||
/// use elastic_array::ElasticArray128;
|
/// use elastic_array::ElasticArray128;
|
||||||
@ -61,7 +62,7 @@ pub type RlpCodec = RlpNodeCodec<KeccakHasher>;
|
|||||||
/// type DBValue = ElasticArray128<u8>;
|
/// type DBValue = ElasticArray128<u8>;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let mut memdb = MemoryDB::<KeccakHasher, DBValue>::new();
|
/// let mut memdb = journaldb::new_memory_db();
|
||||||
/// let mut root = H256::new();
|
/// let mut root = H256::new();
|
||||||
/// TrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap();
|
/// TrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap();
|
||||||
/// let t = TrieDB::new(&memdb, &root).unwrap();
|
/// let t = TrieDB::new(&memdb, &root).unwrap();
|
||||||
@ -85,26 +86,27 @@ pub type FatDB<'db> = trie::FatDB<'db, KeccakHasher, RlpCodec>;
|
|||||||
|
|
||||||
/// # Example
|
/// # Example
|
||||||
/// ```
|
/// ```
|
||||||
/// extern crate patricia_trie as trie;
|
/// extern crate trie_db as trie;
|
||||||
/// extern crate patricia_trie_ethereum as ethtrie;
|
/// extern crate patricia_trie_ethereum as ethtrie;
|
||||||
/// extern crate hashdb;
|
/// extern crate hash_db;
|
||||||
/// extern crate keccak_hash;
|
/// extern crate keccak_hash;
|
||||||
/// extern crate keccak_hasher;
|
/// extern crate keccak_hasher;
|
||||||
/// extern crate memorydb;
|
/// extern crate memory_db;
|
||||||
/// extern crate ethereum_types;
|
/// extern crate ethereum_types;
|
||||||
/// extern crate elastic_array;
|
/// extern crate elastic_array;
|
||||||
|
/// extern crate journaldb;
|
||||||
///
|
///
|
||||||
/// use keccak_hash::KECCAK_NULL_RLP;
|
/// use keccak_hash::KECCAK_NULL_RLP;
|
||||||
/// use ethtrie::{TrieDBMut, trie::TrieMut};
|
/// use ethtrie::{TrieDBMut, trie::TrieMut};
|
||||||
/// use keccak_hasher::KeccakHasher;
|
/// use keccak_hasher::KeccakHasher;
|
||||||
/// use memorydb::*;
|
/// use memory_db::*;
|
||||||
/// use ethereum_types::H256;
|
/// use ethereum_types::H256;
|
||||||
/// use elastic_array::ElasticArray128;
|
/// use elastic_array::ElasticArray128;
|
||||||
///
|
///
|
||||||
/// type DBValue = ElasticArray128<u8>;
|
/// type DBValue = ElasticArray128<u8>;
|
||||||
///
|
///
|
||||||
/// fn main() {
|
/// fn main() {
|
||||||
/// let mut memdb = MemoryDB::<KeccakHasher, DBValue>::new();
|
/// let mut memdb = journaldb::new_memory_db();
|
||||||
/// let mut root = H256::new();
|
/// let mut root = H256::new();
|
||||||
/// let mut t = TrieDBMut::new(&mut memdb, &mut root);
|
/// let mut t = TrieDBMut::new(&mut memdb, &mut root);
|
||||||
/// assert!(t.is_empty());
|
/// assert!(t.is_empty());
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
|
|
||||||
use elastic_array::ElasticArray128;
|
use elastic_array::ElasticArray128;
|
||||||
use ethereum_types::H256;
|
use ethereum_types::H256;
|
||||||
use hashdb::Hasher;
|
use hash_db::Hasher;
|
||||||
use keccak_hasher::KeccakHasher;
|
use keccak_hasher::KeccakHasher;
|
||||||
use rlp::{DecoderError, RlpStream, Rlp, Prototype};
|
use rlp::{DecoderError, RlpStream, Rlp, Prototype};
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
@ -28,13 +28,17 @@ use trie::{NibbleSlice, NodeCodec, node::Node, ChildReference};
|
|||||||
#[derive(Default, Clone)]
|
#[derive(Default, Clone)]
|
||||||
pub struct RlpNodeCodec<H: Hasher> {mark: PhantomData<H>}
|
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:
|
// NOTE: what we'd really like here is:
|
||||||
// `impl<H: Hasher> NodeCodec<H> for RlpNodeCodec<H> where H::Out: Decodable`
|
// `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
|
// 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?
|
// do `const HASHED_NULL_NODE: H::Out = H::Out( … … )`. Perhaps one day soon?
|
||||||
impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
|
impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
|
||||||
type Error = DecoderError;
|
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> {
|
fn decode(data: &[u8]) -> ::std::result::Result<Node, Self::Error> {
|
||||||
let r = Rlp::new(data);
|
let r = Rlp::new(data);
|
||||||
match r.prototype()? {
|
match r.prototype()? {
|
||||||
@ -49,9 +53,14 @@ impl NodeCodec<KeccakHasher> for RlpNodeCodec<KeccakHasher> {
|
|||||||
},
|
},
|
||||||
// branch - first 16 are nodes, 17th is a value (or empty).
|
// branch - first 16 are nodes, 17th is a value (or empty).
|
||||||
Prototype::List(17) => {
|
Prototype::List(17) => {
|
||||||
let mut nodes = [&[] as &[u8]; 16];
|
let mut nodes = [None as Option<&[u8]>; 16];
|
||||||
for i in 0..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()?) }))
|
Ok(Node::Branch(nodes, if r.at(16)?.is_empty() { None } else { Some(r.at(16)?.data()?) }))
|
||||||
},
|
},
|
||||||
|
@ -6,6 +6,6 @@ description = "Trie-root helpers, ethereum style"
|
|||||||
license = "GPL-3.0"
|
license = "GPL-3.0"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
triehash = { version = "0.3.0", features = ["ethereum"] }
|
triehash = { version = "0.4.0", features = ["ethereum"] }
|
||||||
ethereum-types = "0.4"
|
ethereum-types = "0.4"
|
||||||
keccak-hasher = { path = "../keccak-hasher" }
|
keccak-hasher = { path = "../keccak-hasher" }
|
||||||
|
Loading…
Reference in New Issue
Block a user