no_std support for substrate trie (#2146)

* no_std trie compile in test_runtime (require to set nightly feature due
to the way hashbrown currently works).

* No nightly with hashmap_core.

* using crate elastic-array

* switch to publish trie crates

* fix default array decl

* bump impl_version for ci

* set all semver when possible wasm, and remove redundant code.

* Actually test use_trie function

* impl version +1

* Bump impl version
This commit is contained in:
cheme
2019-04-02 12:49:04 +02:00
committed by Bastian Köcher
parent 728f0393c7
commit 669e79181e
16 changed files with 150 additions and 65 deletions
+47 -35
View File
@@ -677,7 +677,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "elastic-array"
version = "0.10.0"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -903,7 +903,7 @@ dependencies = [
[[package]]
name = "hash-db"
version = "0.12.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
@@ -923,6 +923,11 @@ dependencies = [
"scopeguard 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "hashmap_core"
version = "0.1.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "heapsize"
version = "0.4.2"
@@ -1207,7 +1212,7 @@ name = "keccak-hasher"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-keccak 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1226,7 +1231,7 @@ name = "kvdb"
version = "0.1.0"
source = "git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d#b0317f649ab2c665b7987b8475878fc4d2e1f81d"
dependencies = [
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-bytes 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
]
@@ -1244,7 +1249,7 @@ name = "kvdb-rocksdb"
version = "0.1.4"
source = "git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d#b0317f649ab2c665b7987b8475878fc4d2e1f81d"
dependencies = [
"elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)",
"elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"fs-swap 0.2.4 (registry+https://github.com/rust-lang/crates.io-index)",
"interleaved-ordered 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
@@ -1723,10 +1728,11 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
[[package]]
name = "memory-db"
version = "0.12.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -1922,7 +1928,7 @@ dependencies = [
"substrate-primitives 1.0.0",
"substrate-state-machine 1.0.0",
"substrate-trie 1.0.0",
"trie-root 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"wabt 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -2004,7 +2010,7 @@ dependencies = [
"substrate-service 1.0.0",
"substrate-transaction-pool 1.0.0",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"vergen 3.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -3006,7 +3012,7 @@ name = "sr-io"
version = "1.0.0"
dependencies = [
"environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"libsecp256k1 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc_version 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -3671,7 +3677,7 @@ dependencies = [
"error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)",
"futures 0.1.25 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
@@ -3699,7 +3705,7 @@ name = "substrate-client-db"
version = "1.0.0"
dependencies = [
"env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"kvdb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
"kvdb-memorydb 0.1.0 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
"kvdb-rocksdb 0.1.4 (git+https://github.com/paritytech/parity-common?rev=b0317f649ab2c665b7987b8475878fc4d2e1f81d)",
@@ -4050,7 +4056,7 @@ dependencies = [
"base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
"blake2-rfc 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)",
"byteorder 1.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4197,7 +4203,7 @@ dependencies = [
name = "substrate-state-machine"
version = "1.0.0"
dependencies = [
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4206,8 +4212,8 @@ dependencies = [
"substrate-panic-handler 1.0.0",
"substrate-primitives 1.0.0",
"substrate-trie 1.0.0",
"trie-db 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4251,6 +4257,7 @@ dependencies = [
"cfg-if 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.87 (registry+https://github.com/rust-lang/crates.io-index)",
@@ -4269,6 +4276,8 @@ dependencies = [
"substrate-offchain-primitives 0.1.0",
"substrate-primitives 1.0.0",
"substrate-test-client 1.0.0",
"substrate-trie 1.0.0",
"trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4311,15 +4320,16 @@ name = "substrate-trie"
version = "1.0.0"
dependencies = [
"criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hex-literal 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"sr-std 1.0.0",
"substrate-primitives 1.0.0",
"trie-bench 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-standardmap 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -4691,32 +4701,33 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-codec 3.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"trie-standardmap 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "trie-db"
version = "0.12.1"
version = "0.12.2"
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.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)",
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "trie-root"
version = "0.12.0"
version = "0.12.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
@@ -4725,7 +4736,7 @@ version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"criterion 0.2.10 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)",
"keccak-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
@@ -5164,7 +5175,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum dns-parser 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c4d33be9473d06f75f58220f71f7a9317aca647dc061dbd3c361b0bef505fbea"
"checksum ed25519-dalek 1.0.0-pre.1 (registry+https://github.com/rust-lang/crates.io-index)" = "81956bcf7ef761fb4e1d88de3fa181358a0d26cbcb9755b587a08f9119824b86"
"checksum either 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3be565ca5c557d7f59e7cfcf1844f9e3033650c929c6566f511e8005f205c1d0"
"checksum elastic-array 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "88d4851b005ef16de812ea9acdb7bece2f0a40dd86c07b85631d7dafa54537bb"
"checksum elastic-array 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "073be79b6538296faf81c631872676600616073817dd9a440c477ad09b408983"
"checksum env_logger 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "afb070faf94c85d17d50ca44f6ad076bce18ae92f0037d350947240a36e9d42e"
"checksum environmental 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5c7464757b80de8930c91c9afe77ddce501826bf9d134a87db2c67d9dc177e2c"
"checksum error-chain 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07e791d3be96241c77c43846b665ef1384606da2cd2a48730abe606a12906e02"
@@ -5190,9 +5201,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum glob 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "8be18de09a56b60ed0edf84bc9df007e30040691af7acd1c41874faac5895bfb"
"checksum globset 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4743617a7464bbda3c8aec8558ff2f9429047e025771037df561d383337ff865"
"checksum h2 0.1.16 (registry+https://github.com/rust-lang/crates.io-index)" = "ddb2b25a33e231484694267af28fec74ac63b5ccf51ee2065a5e313b834d836e"
"checksum hash-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "07463834729d0ce8d475e7dd6d302e407093ad9a9c02d77eb07fb74b5373829d"
"checksum hash-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ba7fb417e5c470acdd61068c79767d0e65962e70836cf6c9dfd2409f06345ce0"
"checksum hash256-std-hasher 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1224388a21c88a80ae7087a2a245ca6d80acc97a9186b75789fb3eeefd0609af"
"checksum hashbrown 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "3bae29b6653b3412c2e71e9d486db9f9df5d701941d86683005efb9f2d28e3da"
"checksum hashmap_core 0.1.10 (registry+https://github.com/rust-lang/crates.io-index)" = "8e04cb7a5051270ef3fa79f8c7604d581ecfa73d520e74f554e45541c4b5881a"
"checksum heapsize 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1679e6ea370dee694f91f1dc469bf94cf8f52051d147aec3e1f9497c6fc22461"
"checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205"
"checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77"
@@ -5263,7 +5275,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
"checksum memchr 2.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "e1dd4eaac298c32ce07eb6ed9242eda7d82955b9170b7d6db59b2e02cc63fcb8"
"checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3"
"checksum memory-db 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3dd87d4d64f7b86d8804bbb419f8ecb187cb8f40a50e91c72848075c604ba88d"
"checksum memory-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7623b01a4f1b7acb7cf8e3f678f05e15e6ae26cb0b738dfeb5cc186fd6b82ef4"
"checksum memory_units 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882"
"checksum merlin 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a9e97b439f6d38cbe2a4a4aa93f6770c5305f62761b78b1851406c09c87ee2a"
"checksum mime 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "ba626b8a6de5da682e1caa06bdb42a335aee5a84db8e5046a3e8ab17ba0a3ae0"
@@ -5435,8 +5447,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
"checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f"
"checksum traitobject 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "efd1f82c56340fdf16f2a953d7bda4f8fdffba13d93b00844c25572110b26079"
"checksum trie-bench 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "eafa32a8662c06f5bf135984bc1a12821fd38770b5c2f2f9e8750327fcbe3955"
"checksum trie-db 0.12.1 (registry+https://github.com/rust-lang/crates.io-index)" = "843af112ba3a8c919cd961edf3cac9272353f5e277ad8678c7023fa70e5c0e2d"
"checksum trie-root 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e45632ecaf2b8b4a40b5208383cd659b4e66f58ccd40086467a4614b45781430"
"checksum trie-db 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1ba73747fd3a64ab531274c04cb588dfa9d30d972d62990831e63fbce2cfec59"
"checksum trie-root 0.12.2 (registry+https://github.com/rust-lang/crates.io-index)" = "cfa2e20c4f1418ac2e71ddc418e35e1b56e34022e2146209ffdbf1b2de8b1bd9"
"checksum trie-standardmap 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006314f54f2ea7944a878e66fd93ad7978095bc355f30a2f26ec40f664d86c86"
"checksum try-lock 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382"
"checksum twofish 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712d261e83e727c8e2dbb75dacac67c36e35db36a958ee504f2164fc052434e1"
-1
View File
@@ -100,4 +100,3 @@ is-it-maintained-open-issues = { repository = "paritytech/substrate" }
[profile.release]
# Substrate runtime requires unwinding.
panic = "unwind"
+6 -6
View File
@@ -18,7 +18,7 @@ state-machine = { package = "substrate-state-machine", path = "../state-machine"
keyring = { package = "substrate-keyring", path = "../keyring", optional = true }
trie = { package = "substrate-trie", path = "../trie", optional = true }
substrate-telemetry = { path = "../telemetry", optional = true }
hash-db = { version = "0.12", optional = true }
hash-db = { version = "0.12.2", default-features = false }
kvdb = { git = "https://github.com/paritytech/parity-common", optional = true, rev="b0317f649ab2c665b7987b8475878fc4d2e1f81d" }
parity-codec = { version = "3.3", default-features = false, features = ["derive"] }
primitives = { package = "substrate-primitives", path = "../primitives", default-features = false }
@@ -35,10 +35,14 @@ kvdb-memorydb = { git = "https://github.com/paritytech/parity-common", rev="b031
[features]
default = ["std"]
std = [
"rstd/std",
"parity-codec/std",
"consensus",
"primitives/std",
"inherents/std",
"runtime-primitives/std",
"runtime-version/std",
"hash-db/std",
"consensus",
"parking_lot",
"error-chain",
"fnv",
@@ -47,13 +51,9 @@ std = [
"futures",
"heapsize",
"executor",
"runtime-primitives/std",
"runtime-version/std",
"rstd/std",
"state-machine",
"keyring",
"trie",
"substrate-telemetry",
"hash-db",
"kvdb"
]
@@ -106,3 +106,11 @@ fn calling_with_native_else_wasm_and_fail_on_native_should_work() {
let block_id = BlockId::Number(client.info().unwrap().chain.best_number);
assert_eq!(runtime_api.fail_on_native(&block_id).unwrap(), 1);
}
#[test]
fn use_trie_function() {
let client = test_client::new_with_execution_strategy(ExecutionStrategy::AlwaysWasm);
let runtime_api = client.runtime_api();
let block_id = BlockId::Number(client.info().unwrap().chain.best_number);
assert_eq!(runtime_api.use_trie(&block_id).unwrap(), 2);
}
+1 -2
View File
@@ -25,11 +25,10 @@ std = [
"primitives/std",
"parity-codec/std",
"rstd/std",
"hash-db/std",
"trie",
"environmental",
"substrate-state-machine",
"trie",
"libsecp256k1",
"tiny-keccak"
]
+1
View File
@@ -30,6 +30,7 @@ pub use std::ptr;
pub use std::rc;
pub use std::slice;
pub use std::vec;
pub use std::default;
pub use std::result;
pub mod collections {
+1
View File
@@ -61,6 +61,7 @@ pub use core::num;
pub use core::ops;
pub use core::ptr;
pub use core::slice;
pub use core::default;
pub use core::result;
// We are trying to avoid certain things here, such as `core::string`
// (if you need `String` you most probably doing something wrong, since
+7
View File
@@ -20,6 +20,9 @@ runtime_io = { package = "sr-io", path = "../sr-io", default-features = false }
runtime_primitives = { package = "sr-primitives", path = "../sr-primitives", default-features = false }
runtime_version = { package = "sr-version", path = "../sr-version", default-features = false }
runtime_support = { package = "srml-support", path = "../../srml/support", default-features = false }
substrate-trie = { path = "../trie", default-features = false }
trie-db = { version = "0.12", default-features = false }
memory-db = { version = "0.12", default-features = false }
offchain-primitives = { package = "substrate-offchain-primitives", path = "../offchain/primitives", default-features = false}
executive = { package = "srml-executive", path = "../../srml/executive", default-features = false }
cfg-if = "0.1.6"
@@ -47,6 +50,10 @@ std = [
"runtime_primitives/std",
"runtime_version/std",
"consensus_aura/std",
"primitives/std",
"substrate-trie/std",
"trie-db/std",
"memory-db/std",
"offchain-primitives/std",
"executive/std",
]
+51 -1
View File
@@ -25,6 +25,10 @@ pub mod system;
use rstd::{prelude::*, marker::PhantomData};
use parity_codec::{Encode, Decode, Input};
use primitives::Blake2Hasher;
use trie_db::{TrieMut, Trie};
use substrate_trie::{TrieDB, TrieDBMut, PrefixedMemoryDB};
use substrate_client::{
runtime_api as client_api, block_builder::api as block_builder_api, decl_runtime_apis,
impl_runtime_apis,
@@ -232,6 +236,8 @@ cfg_if! {
fn function_signature_changed() -> u64;
fn fail_on_native() -> u64;
fn fail_on_wasm() -> u64;
/// trie no_std testing
fn use_trie() -> u64;
fn benchmark_indirect_call() -> u64;
fn benchmark_direct_call() -> u64;
}
@@ -254,6 +260,8 @@ cfg_if! {
fn function_signature_changed() -> Vec<u64>;
fn fail_on_native() -> u64;
fn fail_on_wasm() -> u64;
/// trie no_std testing
fn use_trie() -> u64;
fn benchmark_indirect_call() -> u64;
fn benchmark_direct_call() -> u64;
}
@@ -281,6 +289,37 @@ fn benchmark_add_one(i: u64) -> u64 {
#[cfg(not(feature = "std"))]
static BENCHMARK_ADD_ONE: runtime_io::ExchangeableFunction<fn(u64) -> u64> = runtime_io::ExchangeableFunction::new(benchmark_add_one);
fn code_using_trie() -> u64 {
let pairs = [
(b"0103000000000000000464".to_vec(), b"0400000000".to_vec()),
(b"0103000000000000000469".to_vec(), b"0401000000".to_vec()),
].to_vec();
let mut mdb = PrefixedMemoryDB::default();
let mut root = rstd::default::Default::default();
let _ = {
let v = &pairs;
let mut t = TrieDBMut::<Blake2Hasher>::new(&mut mdb, &mut root);
for i in 0..v.len() {
let key: &[u8]= &v[i].0;
let val: &[u8] = &v[i].1;
t.insert(key, val).expect("static input");
}
t
};
let trie = TrieDB::<Blake2Hasher>::new(&mdb, &root).expect("on memory with static content");
let iter = trie.iter().expect("static input");
let mut iter_pairs = Vec::new();
for pair in iter {
let (key, value) = pair.expect("on memory with static content");
iter_pairs.push((key, value.to_vec()));
}
iter_pairs.len() as u64
}
cfg_if! {
if #[cfg(feature = "std")] {
impl_runtime_apis! {
@@ -367,6 +406,11 @@ cfg_if! {
fn fail_on_wasm() -> u64 {
1
}
fn use_trie() -> u64 {
code_using_trie()
}
fn benchmark_indirect_call() -> u64 {
let function = benchmark_add_one;
(0..1000).fold(0, |p, i| p + function(i))
@@ -483,6 +527,10 @@ cfg_if! {
panic!("Failing because we are on wasm")
}
fn use_trie() -> u64 {
code_using_trie()
}
fn benchmark_indirect_call() -> u64 {
(0..10000).fold(0, |p, i| p + BENCHMARK_ADD_ONE.get()(i))
}
@@ -492,6 +540,8 @@ cfg_if! {
}
}
impl consensus_aura::AuraApi<Block> for Runtime {
fn slot_duration() -> u64 { 1 }
}
@@ -510,4 +560,4 @@ cfg_if! {
}
}
}
}
}
+10 -7
View File
@@ -12,11 +12,12 @@ name = "bench"
harness = false
[dependencies]
codec = { package = "parity-codec", version = "3.2" }
hash-db = { version = "0.12", default-features = false }
trie-db = { version = "0.12", optional = true }
trie-root = { version = "0.12", default-features = false }
memory-db = { version = "0.12", optional = true }
codec = { package = "parity-codec", version = "3.2", default-features = false }
rstd = { package = "sr-std", path = "../sr-std", default-features = false }
hash-db = { version = "0.12.2", default-features = false }
trie-db = { version = "0.12.2", default-features = false }
trie-root = { version = "0.12.2", default-features = false }
memory-db = { version = "0.12.2", default-features = false }
[dev-dependencies]
substrate-primitives = { path = "../primitives" }
@@ -29,8 +30,10 @@ hex-literal = "0.1.0"
[features]
default = ["std"]
std = [
"rstd/std",
"codec/std",
"hash-db/std",
"memory-db",
"trie-db",
"memory-db/std",
"trie-db/std",
"trie-root/std"
]
+4
View File
@@ -6,7 +6,9 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#[cfg(feature="std")]
use std::fmt;
#[cfg(feature="std")]
use std::error::Error as StdError;
#[derive(Debug, PartialEq, Eq, Clone)]
@@ -16,12 +18,14 @@ pub enum Error {
BadFormat,
}
#[cfg(feature="std")]
impl StdError for Error {
fn description(&self) -> &str {
"codec error"
}
}
#[cfg(feature="std")]
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fmt::Debug::fmt(&self, f)
+5 -2
View File
@@ -16,13 +16,16 @@
//! Utility functions to interact with Substrate's Base-16 Modified Merkle Patricia tree ("trie").
// FIXME: no_std - https://github.com/paritytech/substrate/issues/1574
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg_attr(not(feature = "std"), feature(alloc))]
mod error;
mod node_header;
mod node_codec;
mod trie_stream;
use rstd::boxed::Box;
use rstd::vec::Vec;
use hash_db::Hasher;
/// Our `NodeCodec`-specific error.
pub use error::Error;
@@ -290,7 +293,7 @@ fn take<'a>(input: &mut &'a[u8], count: usize) -> Option<&'a[u8]> {
fn partial_to_key(partial: &[u8], offset: u8, big: u8) -> Vec<u8> {
let nibble_count = (partial.len() - 1) * 2 + if partial[0] & 16 == 16 { 1 } else { 0 };
let (first_byte_small, big_threshold) = (offset, (big - offset) as usize);
let mut output = vec![first_byte_small + nibble_count.min(big_threshold) as u8];
let mut output = [first_byte_small + nibble_count.min(big_threshold) as u8].to_vec();
if nibble_count >= big_threshold { output.push((nibble_count - big_threshold) as u8) }
if nibble_count % 2 == 1 {
output.push(partial[0] & 0x0f);
+5 -8
View File
@@ -16,7 +16,8 @@
//! `NodeCodec` implementation for Substrate's trie format.
use std::marker::PhantomData;
use rstd::marker::PhantomData;
use rstd::vec::Vec;
use codec::{Encode, Decode, Compact};
use hash_db::Hasher;
use trie_db::{self, DBValue, NibbleSlice, node::Node, ChildReference};
@@ -28,10 +29,6 @@ use super::{EMPTY_TRIE, LEAF_NODE_OFFSET, LEAF_NODE_BIG, EXTENSION_NODE_OFFSET,
#[derive(Default, Clone)]
pub struct NodeCodec<H: Hasher>(PhantomData<H>);
// NOTE: what we'd really like here is:
// `impl<H: Hasher> NodeCodec<H> for RlpNodeCodec<H> where H::Out: Decodable`
// but due to the current limitations of Rust const evaluation we can't
// do `const HASHED_NULL_NODE: H::Out = H::Out( … … )`. Perhaps one day soon?
impl<H: Hasher> trie_db::NodeCodec<H> for NodeCodec<H> {
type Error = Error;
@@ -39,7 +36,7 @@ impl<H: Hasher> trie_db::NodeCodec<H> for NodeCodec<H> {
H::hash(&[0u8][..])
}
fn decode(data: &[u8]) -> ::std::result::Result<Node, Self::Error> {
fn decode(data: &[u8]) -> ::rstd::result::Result<Node, Self::Error> {
use Error::BadFormat;
let input = &mut &*data;
match NodeHeader::decode(input).ok_or(BadFormat)? {
@@ -92,7 +89,7 @@ impl<H: Hasher> trie_db::NodeCodec<H> for NodeCodec<H> {
data == &[EMPTY_TRIE][..]
}
fn empty_node() -> Vec<u8> {
vec![EMPTY_TRIE]
[EMPTY_TRIE].to_vec()
}
// FIXME: refactor this so that `partial` isn't already encoded with HPE. Should just be an `impl Iterator<Item=u8>`.
@@ -117,7 +114,7 @@ impl<H: Hasher> trie_db::NodeCodec<H> for NodeCodec<H> {
fn branch_node<I>(children: I, maybe_value: Option<DBValue>) -> Vec<u8>
where I: IntoIterator<Item=Option<ChildReference<H::Out>>> + Iterator<Item=Option<ChildReference<H::Out>>>
{
let mut output = vec![0, 0, 0];
let mut output = [0, 0, 0].to_vec();
let have_value = if let Some(value) = maybe_value {
(&*value).encode_to(&mut output);
true
+2 -1
View File
@@ -16,10 +16,11 @@
//! `TrieStream` implementation for Substrate's trie format.
use std::iter::once;
use rstd::iter::once;
use hash_db::Hasher;
use trie_root;
use codec::Encode;
use rstd::vec::Vec;
use super::{EMPTY_TRIE, LEAF_NODE_OFFSET, LEAF_NODE_BIG, EXTENSION_NODE_OFFSET,
EXTENSION_NODE_BIG, branch_node};
+1 -1
View File
@@ -19,7 +19,7 @@ exit-future = "0.1"
parking_lot = "0.7.1"
hex-literal = "0.1"
parity-codec = "3.3"
trie-root = "0.12.0"
trie-root = "0.12.2"
sr-io = { path = "../core/sr-io" }
substrate-cli = { path = "../core/cli" }
primitives = { package = "substrate-primitives", path = "../core/primitives" }
+1 -1
View File
@@ -60,7 +60,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
impl_name: create_runtime_str!("substrate-node"),
authoring_version: 10,
spec_version: 56,
impl_version: 57,
impl_version: 58,
apis: RUNTIME_API_VERSIONS,
};