diff --git a/Cargo.lock b/Cargo.lock index 97ddde1f88b922c56f0c60357fec29830b77d6a4..de991b0325611281e9ed9d0c4990a8ee086f8aea 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -18,7 +18,7 @@ name = "ansi_term" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -40,17 +40,17 @@ version = "0.2.13" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] name = "autocfg" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "backtrace" -version = "0.3.34" +version = "0.3.35" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)", @@ -64,7 +64,7 @@ name = "backtrace-sys" version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -106,12 +106,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "blake2b_simd" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", - "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -138,7 +138,7 @@ name = "bstr" version = "0.2.7" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)", "regex-automata 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -170,7 +170,7 @@ dependencies = [ [[package]] name = "cc" -version = "1.0.40" +version = "1.0.41" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -183,7 +183,7 @@ name = "chacha20-poly1305-aead" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", + "constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -207,7 +207,7 @@ dependencies = [ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "textwrap 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -216,7 +216,7 @@ name = "clear_on_drop" version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -229,7 +229,7 @@ dependencies = [ [[package]] name = "constant_time_eq" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -257,7 +257,7 @@ dependencies = [ "arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", "scopeguard 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -276,7 +276,7 @@ version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -313,8 +313,8 @@ name = "ctor" version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -337,7 +337,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "redox_users 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -517,6 +517,7 @@ dependencies = [ name = "durs-blockchain-dal" version = "0.3.0-dev" dependencies = [ + "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dubp-block-doc 0.1.0", "dubp-common-doc 0.1.0", "dubp-currency-params 0.2.0", @@ -525,21 +526,36 @@ dependencies = [ "dubp-user-docs-tests-tools 0.1.0", "dup-crypto 0.7.0", "dup-crypto-tests-tools 0.1.0", + "durs-common-dal 0.1.0-a", "durs-common-tests-tools 0.1.0", "durs-common-tools 0.2.0", "durs-conf 0.3.0-dev", "durs-module 0.3.0-dev", "durs-wot 0.8.0-a0.9", "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", - "id_tree 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "rustbreak 2.0.0-rc3 (registry+https://github.com/rust-lang/crates.io-index)", + "rkv 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "unwrap 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "durs-common-dal" +version = "0.1.0-a" +dependencies = [ + "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "durs-common-tools 0.2.0", + "fnv 1.0.6 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", + "rkv 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)", + "rustbreak 2.0.0-rc3 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "unwrap 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "durs-common-tests-tools" version = "0.1.0" @@ -666,7 +682,7 @@ dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "pest 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "pest_derive 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "pretty_assertions 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -748,7 +764,7 @@ dependencies = [ "durs-ws2p-protocol 0.3.0-dev", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", @@ -816,7 +832,7 @@ dependencies = [ "durs-wot 0.8.0-a0.9", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", - "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", "serde_json 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", "structopt 0.2.18 (registry+https://github.com/rust-lang/crates.io-index)", @@ -832,7 +848,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "encode_unicode" -version = "0.3.5" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -840,7 +856,7 @@ name = "failure" version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -913,7 +929,7 @@ name = "generic-array" version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)", + "typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -953,7 +969,7 @@ name = "human-panic" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)", + "backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", "os_type 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)", "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", @@ -964,14 +980,6 @@ dependencies = [ "uuid 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)", ] -[[package]] -name = "id_tree" -version = "1.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -dependencies = [ - "snowflake 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", -] - [[package]] name = "idna" version = "0.2.0" @@ -1033,7 +1041,7 @@ dependencies = [ [[package]] name = "lazy_static" -version = "1.3.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1051,12 +1059,33 @@ name = "libz-sys" version = "1.0.25" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "lmdb-rkv" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "lmdb-rkv-sys 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "lmdb-rkv-sys" +version = "0.8.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "log" version = "0.4.8" @@ -1067,7 +1096,7 @@ dependencies = [ [[package]] name = "maplit" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -1096,7 +1125,7 @@ name = "miniz-sys" version = "0.1.12" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1154,7 +1183,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1176,7 +1205,7 @@ name = "num-integer" version = "0.1.41" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1185,7 +1214,7 @@ name = "num-traits" version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1214,7 +1243,7 @@ dependencies = [ "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", "cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)", "foreign-types 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "openssl-sys 0.9.49 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1224,13 +1253,21 @@ name = "openssl-sys" version = "0.9.49" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "pkg-config 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)", "vcpkg 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "ordered-float" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "num-traits 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "os_type" version = "2.2.0" @@ -1244,7 +1281,7 @@ name = "output_vt100" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1307,7 +1344,7 @@ name = "pest_meta" version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "pest 2.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "sha-1 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1361,10 +1398,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)", "csv 1.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1409,7 +1446,7 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.1" +version = "1.0.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1424,7 +1461,7 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1432,7 +1469,7 @@ name = "rand" version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1442,7 +1479,7 @@ dependencies = [ "rand_os 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)", "rand_pcg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "rand_xorshift 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1450,7 +1487,7 @@ name = "rand_chacha" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1490,7 +1527,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1503,7 +1540,7 @@ dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "rdrand 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1511,7 +1548,7 @@ name = "rand_pcg" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", "rand_core 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1541,7 +1578,7 @@ dependencies = [ "crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-queue 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.10.1 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1606,7 +1643,7 @@ name = "remove_dir_all" version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1614,13 +1651,32 @@ name = "ring" version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "web-sys 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "rkv" +version = "0.9.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)", + "bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", + "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lmdb-rkv 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)", + "ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "serde 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "serde_derive 1.0.99 (registry+https://github.com/rust-lang/crates.io-index)", + "url 2.1.0 (registry+https://github.com/rust-lang/crates.io-index)", + "uuid 0.7.4 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1644,7 +1700,7 @@ name = "rules-engine" version = "0.1.0" dependencies = [ "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", - "maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "rayon 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1654,7 +1710,7 @@ version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)", - "blake2b_simd 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)", + "blake2b_simd 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)", "crossbeam-utils 0.6.6 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1746,8 +1802,8 @@ version = "1.0.99" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1813,11 +1869,6 @@ name = "smallvec" version = "0.6.10" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "snowflake" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "sourcefile" version = "0.1.4" @@ -1880,11 +1931,11 @@ dependencies = [ [[package]] name = "syn" -version = "1.0.2" +version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -1915,7 +1966,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1942,7 +1993,7 @@ name = "textwrap" version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1950,7 +2001,7 @@ name = "thread_local" version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1968,7 +2019,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)", "redox_syscall 0.1.56 (registry+https://github.com/rust-lang/crates.io-index)", - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -1981,7 +2032,7 @@ dependencies = [ [[package]] name = "typenum" -version = "1.10.0" +version = "1.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2012,7 +2063,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "unicode-width" -version = "0.1.5" +version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] @@ -2093,11 +2144,11 @@ version = "0.2.50" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "bumpalo 2.6.0 (registry+https://github.com/rust-lang/crates.io-index)", - "lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)", + "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-shared 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2106,7 +2157,7 @@ name = "wasm-bindgen-macro" version = "0.2.50" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-macro-support 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2116,8 +2167,8 @@ version = "0.2.50" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-backend 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-shared 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2136,8 +2187,8 @@ dependencies = [ "heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)", "proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", - "syn 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", + "syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)", "wasm-bindgen-backend 0.2.50 (registry+https://github.com/rust-lang/crates.io-index)", "weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)", ] @@ -2169,7 +2220,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "winapi" -version = "0.3.7" +version = "0.3.8" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ "winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -2196,7 +2247,7 @@ name = "wincolor" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" dependencies = [ - "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -2235,15 +2286,15 @@ dependencies = [ "checksum arrayref 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "0d382e583f07208808f6b1249e60848879ba3543f57c32277bf52d69c2f0f0ee" "checksum arrayvec 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b8d73f9beda665eaa98ab9e4f7442bd4e7de6652587de55b2525e52e29c1b0ba" "checksum atty 0.2.13 (registry+https://github.com/rust-lang/crates.io-index)" = "1803c647a3ec87095e7ae7acfca019e98de5ec9a7d01343f611cf3152ed71a90" -"checksum autocfg 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "22130e92352b948e7e82a49cdb0aa94f2211761117f29e052dd397c1ac33542b" -"checksum backtrace 0.3.34 (registry+https://github.com/rust-lang/crates.io-index)" = "b5164d292487f037ece34ec0de2fcede2faa162f085dd96d2385ab81b12765ba" +"checksum autocfg 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "b671c8fb71b457dd4ae18c4ba1e59aa81793daacc361d82fcd410cef0d491875" +"checksum backtrace 0.3.35 (registry+https://github.com/rust-lang/crates.io-index)" = "1371048253fa3bac6704bfd6bbfc922ee9bdcee8881330d40f308b81cc5adc55" "checksum backtrace-sys 0.1.31 (registry+https://github.com/rust-lang/crates.io-index)" = "82a830b4ef2d1124a711c71d263c5abdc710ef8e907bd508c88be475cebc422b" "checksum base58 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5024ee8015f02155eee35c711107ddd9a9bf3cb689cf2a9089c97e79b6e1ae83" "checksum base64 0.10.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0b25d992356d2eb0ed82172f5248873db5560c4721f564b13cb5193bda5e668e" "checksum base64 0.9.3 (registry+https://github.com/rust-lang/crates.io-index)" = "489d6c0ed21b11d038c31b6ceccca973e65d73ba3bd8ecb9a2babf5546164643" "checksum bincode 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "9f2fb9e29e72fd6bc12071533d5dc7664cb01480c59406f656d7ac25c7bd8ff7" "checksum bitflags 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3d155346769a6855b86399e9bc3814ab343cd3d62c7e985113d46a0ec3c281fd" -"checksum blake2b_simd 0.5.6 (registry+https://github.com/rust-lang/crates.io-index)" = "461f4b879a8eb70c1debf7d0788a9a5ff15f1ea9d25925fea264ef4258bed6b2" +"checksum blake2b_simd 0.5.7 (registry+https://github.com/rust-lang/crates.io-index)" = "bf775a81bb2d464e20ff170ac20316c7b08a43d11dbc72f0f82e8e8d3d6d0499" "checksum block-buffer 0.7.3 (registry+https://github.com/rust-lang/crates.io-index)" = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" "checksum block-padding 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "6d4dc3af3ee2e12f3e5d224e5e1e3d73668abbeb69e566d361f7d5563a4fdf09" "checksum bstr 0.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94cdf78eb7e94c566c1f5dbe2abf8fc70a548fc902942a48c4b3a98b48ca9ade" @@ -2251,14 +2302,14 @@ dependencies = [ "checksum byte-tools 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" "checksum byteorder 1.2.7 (registry+https://github.com/rust-lang/crates.io-index)" = "94f88df23a25417badc922ab0f5716cc1330e87f71ddd9203b3a3ccd9cedf75d" "checksum bytes 0.4.12 (registry+https://github.com/rust-lang/crates.io-index)" = "206fdffcfa2df7cbe15601ef46c813fce0965eb3286db6b56c583b814b51c81c" -"checksum cc 1.0.40 (registry+https://github.com/rust-lang/crates.io-index)" = "b548a4ee81fccb95919d4e22cfea83c7693ebfd78f0495493178db20b3139da7" +"checksum cc 1.0.41 (registry+https://github.com/rust-lang/crates.io-index)" = "8dae9c4b8fedcae85592ba623c4fd08cfdab3e3b72d6df780c6ead964a69bfff" "checksum cfg-if 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "b486ce3ccf7ffd79fdeb678eac06a9e6c09fc88d33836340becb8fffe87c5e33" "checksum chacha20-poly1305-aead 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77d2058ba29594f69c75e8a9018e0485e3914ca5084e3613cd64529042f5423b" "checksum chrono 0.4.7 (registry+https://github.com/rust-lang/crates.io-index)" = "77d81f58b7301084de3b958691458a53c3f7e0b1d702f77e550b6a88e3a88abe" "checksum clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5067f5bb2d80ef5d68b4c87db81601f0b75bca627bc2ef76b141d7b846a3c6d9" "checksum clear_on_drop 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "97276801e127ffb46b66ce23f35cc96bd454fa311294bced4bbace7baa8b1d17" "checksum cloudabi 0.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -"checksum constant_time_eq 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "8ff012e225ce166d4422e0e78419d901719760f62ae2b7969ca6b564d1b54a9e" +"checksum constant_time_eq 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "995a44c877f9212528ccc74b21a232f66ad69001e40ede5bcee2ac9ef2657120" "checksum crc32fast 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ba125de2af0df55319f41944744ad91c71113bf74a4646efff39afe1f6842db1" "checksum crossbeam-deque 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b18cd2e169ad86297e6bc0ad9aa679aee9daa4f19e8163860faf7c164e4f5a71" "checksum crossbeam-epoch 0.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "fedcd6772e37f3da2a9af9bf12ebe046c0dfe657992377b4df982a2b54cd37a9" @@ -2272,7 +2323,7 @@ dependencies = [ "checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" "checksum dirs 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "3fd78930633bd1c6e35c4b42b1df7b0cbc6bc191146e512bb3bedf243fcc3901" "checksum either 1.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "5527cfe0d098f36e3f8839852688e63c8fff1c90b2b405aef730615f9a7bcf7b" -"checksum encode_unicode 0.3.5 (registry+https://github.com/rust-lang/crates.io-index)" = "90b2c9496c001e8cb61827acdefad780795c42264c137744cae6f7d9e3450abd" +"checksum encode_unicode 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" "checksum failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "795bd83d3abeb9220f257e597aa0080a508b27533824adf336529648f6abf7e2" "checksum failure_derive 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "ea1063915fd7ef4309e222a5a07cf9c319fb9c7836b1f89b85458672dbb127e1" "checksum fake-simd 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" @@ -2290,19 +2341,20 @@ dependencies = [ "checksum hmac 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" "checksum human-panic 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "21638c5955a6daf3ecc42cae702335fc37a72a4abcc6959ce457b31a7d43bbdd" -"checksum id_tree 1.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1bb51d6d2c77a59bfe64a6e909a00140e680fc9a32c6f383e64ed462b3cab957" "checksum idna 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "02e2673c30ee86b5b96a9cb52ad15718aa1f966f5ab9ad54a8b95d5ca33120a9" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum itertools 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "0d47946d458e94a1b7bcabbf6521ea7c037062c81f534615abcad76e84d4970d" "checksum itoa 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)" = "501266b7edd0174f8530248f87f99c88fbe60ca4ef3dd486835b8d8d53136f7f" "checksum js-sys 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "1efc4f2a556c58e79c5500912e221dd826bec64ff4aabd8ce71ccef6da02d7d4" "checksum kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7507624b29483431c0ba2d82aece8ca6cdba9382bff4ddd0f7490560c056098d" -"checksum lazy_static 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bc5729f27f159ddd61f4df6228e827e86643d4d3e7c32183cb30a1c08f604a14" +"checksum lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum libc 0.2.62 (registry+https://github.com/rust-lang/crates.io-index)" = "34fcd2c08d2f832f376f4173a231990fa5aef4e99fb569867318a227ef4c06ba" "checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" +"checksum lmdb-rkv 0.11.4 (registry+https://github.com/rust-lang/crates.io-index)" = "e25b4069789bf7ac069d6fd58229f18aec20c6f7cc9173cb731d11c10dbb6b6e" +"checksum lmdb-rkv-sys 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c60e2728ce41a4d4fa4ccf3d07c105bebf198721117e6328a3cf1cb7e4242c70" "checksum log 0.4.8 (registry+https://github.com/rust-lang/crates.io-index)" = "14b6052be84e6b71ab17edffc2eeabf5c2c3ae1fdb464aae35ac50c67a44e1f7" -"checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" +"checksum maplit 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "3e2e65a1a2e43cfcb47a895c4c8b10d1f4a61097f9f254f183aee60cad9c651d" "checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" "checksum memoffset 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "ce6075db033bbbb7ee5a0bbd3a3186bbae616f57fb001c485c7ff77955f8177f" @@ -2321,6 +2373,7 @@ dependencies = [ "checksum opaque-debug 0.2.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" "checksum openssl 0.10.24 (registry+https://github.com/rust-lang/crates.io-index)" = "8152bb5a9b5b721538462336e3bef9a539f892715e5037fda0f984577311af15" "checksum openssl-sys 0.9.49 (registry+https://github.com/rust-lang/crates.io-index)" = "f4fad9e54bd23bd4cbbe48fdc08a1b8091707ac869ef8508edea2fec77dcc884" +"checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" "checksum os_type 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7edc011af0ae98b7f88cf7e4a83b70a54a75d2b8cb013d6efd02e5956207e9eb" "checksum output_vt100 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" "checksum pbkdf2 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "006c038a43a45995a9670da19e67600114740e8511d4333bf97a56e66a7542d9" @@ -2339,7 +2392,7 @@ dependencies = [ "checksum proc-macro2 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4c5c2380ae88876faae57698be9e9775e3544decad214599c3a6266cca6ac802" "checksum quote 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "1eca14c727ad12702eb4b6bfb5a232287dcf8385cb8ca83a3eeaf6519c44c408" "checksum quote 0.6.13 (registry+https://github.com/rust-lang/crates.io-index)" = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1" -"checksum quote 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "49d77c41ca8767f2f41394c11a4eebccab83da25e7cc035387a3125f02be90a3" +"checksum quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "053a8c8bcc71fcce321828dc897a98ab9760bef03a4fc36693c231e5b3216cfe" "checksum rand 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)" = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" "checksum rand 0.6.5 (registry+https://github.com/rust-lang/crates.io-index)" = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" "checksum rand_chacha 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" @@ -2362,6 +2415,7 @@ dependencies = [ "checksum regex-syntax 0.6.11 (registry+https://github.com/rust-lang/crates.io-index)" = "b143cceb2ca5e56d5671988ef8b15615733e7ee16cd348e064333b251b89343f" "checksum remove_dir_all 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "4a83fa3702a688b9359eccba92d153ac33fd2e8462f9e0e3fdf155239ea7792e" "checksum ring 0.16.9 (registry+https://github.com/rust-lang/crates.io-index)" = "6747f8da1f2b1fabbee1aaa4eb8a11abf9adef0bf58a41cee45db5d59cecdfac" +"checksum rkv 0.9.7 (registry+https://github.com/rust-lang/crates.io-index)" = "4f9d6a4dd60be13a62ae1d19df68c0c85d77bbee3749b62bf35c49f207d3d750" "checksum rpassword 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b273c91bd242ca03ad6d71c143b6f17a48790e61f21a6c78568fa2b6774a24a4" "checksum rprompt 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1601f32bc5858aae3cbfa1c645c96c4d820cc5c16be0194f089560c00b6eb625" "checksum rust-argon2 0.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "4ca4eaef519b494d1f2848fc602d18816fed808a981aedf4f1f00ceb7c9d32cf" @@ -2384,7 +2438,6 @@ dependencies = [ "checksum simplelog 0.5.3 (registry+https://github.com/rust-lang/crates.io-index)" = "2e95345f185d5adeb8ec93459d2dc99654e294cc6ccf5b75414d8ea262de9a13" "checksum slab 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "c111b5bd5695e56cffe5129854aa230b39c93a305372fdbb2668ca2394eea9f8" "checksum smallvec 0.6.10 (registry+https://github.com/rust-lang/crates.io-index)" = "ab606a9c5e214920bb66c458cd7be8ef094f813f20fe77a54cc7dbfff220d4b7" -"checksum snowflake 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "27207bb65232eda1f588cf46db2fee75c0808d557f6b3cf19a75f5d6d7c94df1" "checksum sourcefile 0.1.4 (registry+https://github.com/rust-lang/crates.io-index)" = "4bf77cb82ba8453b42b6ae1d692e4cdc92f9a47beaf89a847c8be83f4e328ad3" "checksum spin 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d" "checksum strsim 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" @@ -2393,7 +2446,7 @@ dependencies = [ "checksum subtle 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" "checksum syn 0.12.15 (registry+https://github.com/rust-lang/crates.io-index)" = "c97c05b8ebc34ddd6b967994d5c6e9852fa92f8b82b3858c39451f97346dcce5" "checksum syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)" = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5" -"checksum syn 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "2ae5cd13590144ea968ba5d5520da7a4c08415861014399b5b349f74591c375f" +"checksum syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)" = "66850e97125af79138385e9b88339cbcd037e3f28ceab8c5ad98e64f0f1f80bf" "checksum synstructure 0.10.2 (registry+https://github.com/rust-lang/crates.io-index)" = "02353edf96d6e4dc81aea2d8490a7e9db177bf8acb0e951c24940bf866cb313f" "checksum tempdir 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" "checksum term 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "edd106a334b7657c10b7c540a0106114feadeb4dc314513e97df481d5d966f42" @@ -2404,12 +2457,12 @@ dependencies = [ "checksum threadpool 1.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "e2f0c90a5f3459330ac8bc0d2f879c693bb7a2f59689c1083fc4ef83834da865" "checksum time 0.1.42 (registry+https://github.com/rust-lang/crates.io-index)" = "db8dcfca086c1143c9270ac42a2bbd8a7ee477b78ac8e45b19abfb0cbede4b6f" "checksum toml 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)" = "758664fc71a3a69038656bee8b6be6477d2a6c315a6b81f7081f591bffa4111f" -"checksum typenum 1.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "612d636f949607bdf9b123b4a6f6d966dedf3ff669f7f045890d3a4a73948169" +"checksum typenum 1.11.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6d2783fe2d6b8c1101136184eb41be8b1ad379e4657050b8aaff0c79ee7575f9" "checksum ucd-trie 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8f00ed7be0c1ff1e24f46c3d2af4859f7e863672ba3a6e92e7cff702bf9f06c2" "checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" "checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" "checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" -"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" +"checksum unicode-width 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)" = "7007dbd421b92cc6e28410fe7362e2e0a2503394908f417b68ec8d1c364c4e20" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unicode-xid 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "826e7639553986605ec5979c7dd957c7895e93eabed50ab2ffa7f6128a75097c" "checksum untrusted 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)" = "60369ef7a31de49bcb3f6ca728d4ba7300d9a1658f94c727d4cab8c8d9f4aece" @@ -2429,7 +2482,7 @@ dependencies = [ "checksum web-sys 0.3.27 (registry+https://github.com/rust-lang/crates.io-index)" = "6435c477200ad486089a7a72c2bd6c9bdf9740bd7fff868806076218076d8c51" "checksum weedle 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3bb43f70885151e629e2a19ce9e50bd730fd436cfd4b666894c9ce4de9141164" "checksum winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)" = "167dc9d6949a9b857f3451275e911c3f44255842c1f7a76f33c55103a909087a" -"checksum winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)" = "f10e386af2b13e47c89e7236a7a14a086791a2b88ebad6df9bf42040195cf770" +"checksum winapi 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)" = "8093091eeb260906a183e6ae1abdba2ef5ef2257a21801128899c3fc699229c6" "checksum winapi-build 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "2d315eee3b34aca4797b2da6b13ed88266e6d612562a0c46390af8299fc699bc" "checksum winapi-i686-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" "checksum winapi-x86_64-pc-windows-gnu 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" diff --git a/Cargo.toml b/Cargo.toml index 8bce67f4fd91801cfe2f2d92cc4e940647ae79c0..bc8bd99bc875c6f7075a950bb05aed66fabc923b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,6 +25,7 @@ members = [ "lib/tests-tools/user-docs-tests-tools", "lib/tests-tools/common-tests-tools", "lib/tools/common-tools", + "lib/tools/dbs-tools", "lib/tools/json-pest-parser", "lib/tools/pkstl", "lib/tools/rules-engine", diff --git a/lib/modules/blockchain/blockchain-dal/Cargo.toml b/lib/modules/blockchain/blockchain-dal/Cargo.toml index 13672ce3b531e32b001edf9a902f64e482964061..c432e225b43aa2d819bf63ac552cd8fde795169a 100644 --- a/lib/modules/blockchain/blockchain-dal/Cargo.toml +++ b/lib/modules/blockchain/blockchain-dal/Cargo.toml @@ -10,6 +10,7 @@ edition = "2018" path = "src/lib.rs" [dependencies] +bincode = "1.0.*" dubp-block-doc = { path = "../../../dubp/block-doc"} #, version = "0.1.0" } dubp-common-doc = { path = "../../../dubp/common-doc"} #, version = "0.1.0" } dubp-indexes = { path = "../../../dubp/indexes"} #, version = "0.1.0" } @@ -19,11 +20,11 @@ dubp-user-docs= { path = "../../../dubp/user-docs" } durs-conf = { path = "../../../core/conf" } durs-module = { path = "../../../core/module" } durs-common-tools = { path = "../../../tools/common-tools" } +durs-dbs-tools = { path = "../../../tools/dbs-tools" } durs-wot = { path = "../../../dubp/wot" } fnv = "1.0.6" -id_tree = "1.3.0" log = "0.4.*" -rustbreak = {version = "2.0.0-rc3", features = ["bin_enc"]} +maplit = "1.0.1" serde = "1.0.*" serde_derive = "1.0.*" serde_json = "1.0.*" @@ -33,5 +34,6 @@ unwrap = "1.2.1" dup-crypto-tests-tools = { path = "../../../tests-tools/crypto-tests-tools" } dubp-user-docs-tests-tools = { path = "../../../tests-tools/user-docs-tests-tools" } durs-common-tests-tools = { path = "../../../tests-tools/common-tests-tools" } +tempfile = "3.1.0" [features] diff --git a/lib/modules/blockchain/blockchain-dal/src/constants.rs b/lib/modules/blockchain/blockchain-dal/src/constants.rs index e44d0fd5fd2d43e335f27918a62015e2a18aac27..49557d05f161a13be41311c3ded4d6de2a696619 100644 --- a/lib/modules/blockchain/blockchain-dal/src/constants.rs +++ b/lib/modules/blockchain/blockchain-dal/src/constants.rs @@ -18,3 +18,6 @@ pub static DEFAULT_PAGE_SIZE: &usize = &50; /// Currency parameters DB name pub const CURRENCY_PARAMS_DB_NAME: &str = "params.db"; + +/// Local blockchain collection name +pub static LOCAL_BC: &str = "bc"; diff --git a/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs index 121cae23f202a7de44b5c3b317e03f2f177ff583..2838c59feaf2630e9ce11fbc9acfa545ecd2d53e 100644 --- a/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/entities/fork_tree.rs @@ -112,6 +112,7 @@ impl TreeNode { #[derive(Debug, Clone, Serialize, Deserialize)] /// Tree store all forks branchs pub struct ForkTree { + current_blockstamp: Option<Blockstamp>, main_branch: HashMap<BlockNumber, TreeNodeId>, max_depth: usize, nodes: Vec<Option<TreeNode>>, @@ -132,6 +133,7 @@ impl ForkTree { #[inline] pub fn new(max_depth: usize) -> Self { ForkTree { + current_blockstamp: None, main_branch: HashMap::with_capacity(max_depth + 1), max_depth, nodes: Vec::with_capacity(max_depth * 2), @@ -140,6 +142,11 @@ impl ForkTree { sheets: HashSet::new(), } } + /// Get tree size + #[inline] + pub fn get_current_blockstamp(&self) -> Option<Blockstamp> { + self.current_blockstamp + } /// Set max depth #[inline] pub fn set_max_depth(&mut self, max_depth: usize) { @@ -357,6 +364,9 @@ impl ForkTree { self.pruning(); } } + + // Update current blockstamp + self.current_blockstamp = Some(new_current_blockstamp); } /// Find node with specific blockstamp pub fn find_node_with_blockstamp(&self, blockstamp: &Blockstamp) -> Option<TreeNodeId> { @@ -409,6 +419,7 @@ impl ForkTree { self.removed_blockstamps.clear(); if main_branch { self.main_branch.insert(data.id, new_node_id); + self.current_blockstamp = Some(data); if self.main_branch.len() > self.max_depth { self.pruning(); } diff --git a/lib/modules/blockchain/blockchain-dal/src/lib.rs b/lib/modules/blockchain/blockchain-dal/src/lib.rs index 9335720fe7ad359cd5a9d9c50309727cf69ea183..ef27366cb3133a10ce9eafb6ede9da69a84186f3 100644 --- a/lib/modules/blockchain/blockchain-dal/src/lib.rs +++ b/lib/modules/blockchain/blockchain-dal/src/lib.rs @@ -18,7 +18,6 @@ #![allow(clippy::large_enum_variant)] #![deny( missing_docs, - missing_debug_implementations, missing_copy_implementations, trivial_casts, trivial_numeric_casts, @@ -45,39 +44,47 @@ pub mod filters; /// Contains all read databases functions pub mod readers; +//pub mod storage; + /// Tools pub mod tools; /// Contains all write databases functions pub mod writers; +pub use durs_dbs_tools::kv_db::{ + KvFileDbHandler, KvFileDbRead as DbReadable, KvFileDbRoHandler, KvFileDbSchema, + KvFileDbStoreType, KvFileDbValue, +}; +pub use durs_dbs_tools::{ + open_free_struct_db, open_free_struct_file_db, open_free_struct_memory_db, +}; +pub use durs_dbs_tools::{BinFreeStructDb, DALError}; + +use crate::constants::LOCAL_BC; +use crate::entities::block::DALBlock; +use crate::entities::identity::DALIdentity; +use crate::entities::sources::{SourceAmount, UTXOContentV10}; +use crate::writers::transaction::DALTxV10; use dubp_common_doc::{BlockNumber, Blockstamp, PreviousBlockstamp}; +use dubp_indexes::sindex::UniqueIdUTXOv10; use dubp_user_docs::documents::transaction::*; use dup_crypto::hashs::Hash; use dup_crypto::keys::*; use durs_common_tools::fatal_error; use durs_wot::data::{rusty::RustyWebOfTrust, WotId}; use fnv::FnvHashMap; -use rustbreak::backend::{FileBackend, MemoryBackend}; -use rustbreak::error::{RustbreakError, RustbreakErrorKind}; -use rustbreak::{deser::Bincode, Database, FileDatabase, MemoryDatabase}; -use serde::de::DeserializeOwned; +use maplit::hashmap; use serde::Serialize; use std::collections::{HashMap, HashSet}; -use std::default::Default; -use std::fmt::Debug; -use std::fs; -use std::panic::UnwindSafe; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; -use crate::entities::block::DALBlock; -use crate::entities::identity::DALIdentity; -use crate::entities::sources::{SourceAmount, UTXOContentV10}; -use crate::writers::transaction::DALTxV10; -use dubp_indexes::sindex::UniqueIdUTXOv10; +/// Database handler +pub type Db = KvFileDbHandler; + +/// Read-only database handler +pub type DbReader = KvFileDbRoHandler; -/// All blocks of local blockchain indexed by block number -pub type LocalBlockchainV10Datas = FnvHashMap<BlockNumber, DALBlock>; /// Forks tree meta datas (block number and hash only) pub type ForksTreeV10Datas = entities::fork_tree::ForkTree; /// Forks blocks referenced in tree indexed by their blockstamp @@ -101,109 +108,42 @@ pub type UDsV10Datas = HashMap<PubKey, HashSet<BlockNumber>>; /// V10 Balances accounts pub type BalancesV10Datas = HashMap<UTXOConditionsGroup, (SourceAmount, HashSet<UniqueIdUTXOv10>)>; -#[derive(Debug)] -/// Database -pub enum BinDB<D: Serialize + DeserializeOwned + Debug + Default + Clone + Send> { - /// File database - File(Database<D, FileBackend, Bincode>), - /// Memory database - Mem(Database<D, MemoryBackend, Bincode>), -} - -impl<D: Serialize + DeserializeOwned + Debug + Default + Clone + Send> BinDB<D> { - /// Flush the data structure to the backend - pub fn save(&self) -> Result<(), RustbreakError> { - match *self { - BinDB::File(ref file_db) => file_db.save(), - BinDB::Mem(ref mem_db) => mem_db.save(), - } - } - /// Read lock the database and get write access to the Data container - /// This gives you a read-only lock on the database. You can have as many readers in parallel as you wish. - pub fn read<T, R>(&self, task: T) -> Result<R, RustbreakError> - where - T: FnOnce(&D) -> R, - { - match *self { - BinDB::File(ref file_db) => file_db.read(task), - BinDB::Mem(ref mem_db) => mem_db.read(task), - } - } - /// Write lock the database and get write access to the Data container - /// This gives you an exclusive lock on the memory object. Trying to open the database in writing will block if it is currently being written to. - pub fn write<T>(&self, task: T) -> Result<(), RustbreakError> - where - T: FnOnce(&mut D), - { - match *self { - BinDB::File(ref file_db) => file_db.write(task), - BinDB::Mem(ref mem_db) => mem_db.write(task), - } - } - /// Write lock the database and get write access to the Data container in a safe way (clone of the internal data is made). - pub fn write_safe<T>(&self, task: T) -> Result<(), RustbreakError> - where - T: FnOnce(&mut D) + UnwindSafe, - { - match *self { - BinDB::File(ref file_db) => file_db.write_safe(task), - BinDB::Mem(ref mem_db) => mem_db.write_safe(task), - } - } - /// Load the Data from the backend - pub fn load(&self) -> Result<(), RustbreakError> { - match *self { - BinDB::File(ref file_db) => file_db.load(), - BinDB::Mem(ref mem_db) => mem_db.load(), - } - } -} - -#[derive(Debug)] -/// Set of databases storing block information -pub struct BlocksV10DBs { - /// Local blockchain database - pub blockchain_db: BinDB<LocalBlockchainV10Datas>, -} - -impl BlocksV10DBs { - /// Open blocks databases from their respective files - pub fn open(db_path: Option<&PathBuf>) -> BlocksV10DBs { - BlocksV10DBs { - blockchain_db: open_db::<LocalBlockchainV10Datas>(db_path, "blockchain.db") - .expect("Fail to open LocalBlockchainV10DB"), - } - } - /// Save blocks databases in their respective files - pub fn save_dbs(&self) { - info!("BLOCKCHAIN-DAL: Save LocalBlockchainV10DB."); - self.blockchain_db - .save() - .expect("Fatal error : fail to save LocalBlockchainV10DB !"); - } +/// Open database +pub fn open_db(path: &Path) -> Result<Db, DALError> { + Db::open_db( + path, + &KvFileDbSchema { + stores: hashmap![ + LOCAL_BC.to_owned() => KvFileDbStoreType::SingleIntKey, + ], + }, + ) } #[derive(Debug)] /// Set of databases storing forks informations pub struct ForksDBs { /// Fork tree (store only blockstamp) - pub fork_tree_db: BinDB<ForksTreeV10Datas>, + pub fork_tree_db: BinFreeStructDb<ForksTreeV10Datas>, /// Blocks in fork tree - pub fork_blocks_db: BinDB<ForksBlocksV10Datas>, + pub fork_blocks_db: BinFreeStructDb<ForksBlocksV10Datas>, /// Orphan blocks - pub orphan_blocks_db: BinDB<OrphanBlocksV10Datas>, + pub orphan_blocks_db: BinFreeStructDb<OrphanBlocksV10Datas>, } impl ForksDBs { /// Open fork databases from their respective files pub fn open(db_path: Option<&PathBuf>) -> ForksDBs { ForksDBs { - fork_tree_db: open_db::<ForksTreeV10Datas>(db_path, "fork_tree.db") + fork_tree_db: open_free_struct_db::<ForksTreeV10Datas>(db_path, "fork_tree.db") .expect("Fail to open ForksTreeV10Datas"), - fork_blocks_db: open_db::<ForksBlocksV10Datas>(db_path, "fork_blocks.db") + fork_blocks_db: open_free_struct_db::<ForksBlocksV10Datas>(db_path, "fork_blocks.db") .expect("Fail to open ForkForksBlocksV10DatassV10DB"), - orphan_blocks_db: open_db::<OrphanBlocksV10Datas>(db_path, "orphan_blocks.db") - .expect("Fail to open OrphanBlocksV10Datas"), + orphan_blocks_db: open_free_struct_db::<OrphanBlocksV10Datas>( + db_path, + "orphan_blocks.db", + ) + .expect("Fail to open OrphanBlocksV10Datas"), } } /// Save fork databases in their respective files @@ -225,24 +165,26 @@ impl ForksDBs { /// Set of databases storing web of trust information pub struct WotsV10DBs { /// Store wot graph - pub wot_db: BinDB<WotDB>, + pub wot_db: BinFreeStructDb<WotDB>, /// Store idrntities - pub identities_db: BinDB<IdentitiesV10Datas>, + pub identities_db: BinFreeStructDb<IdentitiesV10Datas>, /// Store memberships created_block_id (Use only to detect expirations) - pub ms_db: BinDB<MsExpirV10Datas>, + pub ms_db: BinFreeStructDb<MsExpirV10Datas>, /// Store certifications created_block_id (Use only to detect expirations) - pub certs_db: BinDB<CertsExpirV10Datas>, + pub certs_db: BinFreeStructDb<CertsExpirV10Datas>, } impl WotsV10DBs { /// Open wot databases from their respective files pub fn open(db_path: Option<&PathBuf>) -> WotsV10DBs { WotsV10DBs { - wot_db: open_db::<RustyWebOfTrust>(db_path, "wot.db").expect("Fail to open WotDB"), - identities_db: open_db::<IdentitiesV10Datas>(db_path, "identities.db") + wot_db: open_free_struct_db::<RustyWebOfTrust>(db_path, "wot.db") + .expect("Fail to open WotDB"), + identities_db: open_free_struct_db::<IdentitiesV10Datas>(db_path, "identities.db") .expect("Fail to open IdentitiesV10DB"), - ms_db: open_db::<MsExpirV10Datas>(db_path, "ms.db").expect("Fail to open MsExpirV10DB"), - certs_db: open_db::<CertsExpirV10Datas>(db_path, "certs.db") + ms_db: open_free_struct_db::<MsExpirV10Datas>(db_path, "ms.db") + .expect("Fail to open MsExpirV10DB"), + certs_db: open_free_struct_db::<CertsExpirV10Datas>(db_path, "certs.db") .expect("Fail to open CertsExpirV10DB"), } } @@ -272,25 +214,26 @@ impl WotsV10DBs { /// Set of databases storing currency information pub struct CurrencyV10DBs { /// Store all UD sources - pub du_db: BinDB<UDsV10Datas>, + pub du_db: BinFreeStructDb<UDsV10Datas>, /// Store all Transactions - pub tx_db: BinDB<TxV10Datas>, + pub tx_db: BinFreeStructDb<TxV10Datas>, /// Store all UTXOs - pub utxos_db: BinDB<UTXOsV10Datas>, + pub utxos_db: BinFreeStructDb<UTXOsV10Datas>, /// Store balances of all address (and theirs UTXOs indexs) - pub balances_db: BinDB<BalancesV10Datas>, + pub balances_db: BinFreeStructDb<BalancesV10Datas>, } impl CurrencyV10DBs { /// Open currency databases from their respective files pub fn open(db_path: Option<&PathBuf>) -> CurrencyV10DBs { CurrencyV10DBs { - du_db: open_db::<UDsV10Datas>(db_path, "du.db").expect("Fail to open UDsV10DB"), - tx_db: open_db::<TxV10Datas>(db_path, "tx.db") + du_db: open_free_struct_db::<UDsV10Datas>(db_path, "du.db") + .expect("Fail to open UDsV10DB"), + tx_db: open_free_struct_db::<TxV10Datas>(db_path, "tx.db") .unwrap_or_else(|_| fatal_error!("Fail to open TxV10DB")), - utxos_db: open_db::<UTXOsV10Datas>(db_path, "sources.db") + utxos_db: open_free_struct_db::<UTXOsV10Datas>(db_path, "sources.db") .expect("Fail to open UTXOsV10DB"), - balances_db: open_db::<BalancesV10Datas>(db_path, "balances.db") + balances_db: open_free_struct_db::<BalancesV10Datas>(db_path, "balances.db") .expect("Fail to open BalancesV10DB"), } } @@ -316,36 +259,6 @@ impl CurrencyV10DBs { } } -#[derive(Debug, Deserialize, Copy, Clone, PartialEq, Eq, Hash, Serialize)] -/// Data Access Layer Error -pub enum DALError { - /// Error in write operation - WriteError, - /// Error in read operation - ReadError, - /// A database is corrupted, you have to reset the data completely - DBCorrupted, - /// Error with the file system - FileSystemError, - /// Capturing a panic signal during a write operation - WritePanic, - /// Unknown error - UnknowError, -} - -impl From<RustbreakError> for DALError { - fn from(rust_break_error: RustbreakError) -> DALError { - match rust_break_error.kind() { - RustbreakErrorKind::Serialization => DALError::WriteError, - RustbreakErrorKind::Deserialization => DALError::ReadError, - RustbreakErrorKind::Poison => DALError::DBCorrupted, - RustbreakErrorKind::Backend => DALError::FileSystemError, - RustbreakErrorKind::WritePanic => DALError::WritePanic, - _ => DALError::UnknowError, - } - } -} - /*#[derive(Debug, Clone)] pub struct WotStats { pub block_number: u32, @@ -360,51 +273,16 @@ pub struct WotStats { pub centralities: Vec<u64>, }*/ -/// Open Rustbreak database -pub fn open_db<D: Serialize + DeserializeOwned + Debug + Default + Clone + Send>( - dbs_folder_path: Option<&PathBuf>, - db_file_name: &str, -) -> Result<BinDB<D>, DALError> { - if let Some(dbs_folder_path) = dbs_folder_path { - Ok(BinDB::File(open_file_db::<D>( - dbs_folder_path, - db_file_name, - )?)) - } else { - Ok(BinDB::Mem(open_memory_db::<D>()?)) - } -} +#[cfg(test)] +pub mod tests { -/// Open Rustbreak memory database -pub fn open_memory_db<D: Serialize + DeserializeOwned + Debug + Default + Clone + Send>( -) -> Result<MemoryDatabase<D, Bincode>, DALError> { - let backend = MemoryBackend::new(); - let db = MemoryDatabase::<D, Bincode>::from_parts(D::default(), backend, Bincode); - Ok(db) -} + use super::*; + use tempfile::tempdir; -/// Open Rustbreak file database -pub fn open_file_db<D: Serialize + DeserializeOwned + Debug + Default + Clone + Send>( - dbs_folder_path: &PathBuf, - db_file_name: &str, -) -> Result<FileDatabase<D, Bincode>, DALError> { - let mut db_path = dbs_folder_path.clone(); - db_path.push(db_file_name); - let file_path = db_path.as_path(); - if file_path.exists() - && fs::metadata(file_path) - .expect("fail to get file size") - .len() - > 0 - { - let backend = FileBackend::open(db_path.as_path())?; - let db = FileDatabase::<D, Bincode>::from_parts(D::default(), backend, Bincode); - db.load()?; - Ok(db) - } else { - Ok(FileDatabase::<D, Bincode>::from_path( - db_path.as_path(), - D::default(), - )?) + #[inline] + /// Open database in an arbitrary temporary directory given by OS + /// and automatically cleaned when `Db` is dropped + pub fn open_tmp_db() -> Result<Db, DALError> { + open_db(tempdir().map_err(DALError::FileSystemError)?.path()) } } diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/balance.rs b/lib/modules/blockchain/blockchain-dal/src/readers/balance.rs index 2709ac8e7708743ecc5b8dd72932773e015f8281..df07d5d0dc3c9e2a8ffc8df96cee8cdea37d4b4b 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/balance.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/balance.rs @@ -18,7 +18,7 @@ use crate::*; /// Get address balance pub fn get_address_balance( - balances_db: &BinDB<BalancesV10Datas>, + balances_db: &BinFreeStructDb<BalancesV10Datas>, address: &UTXOConditionsGroup, ) -> Result<Option<SourceAmount>, DALError> { Ok(balances_db.read(|db| { diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/block.rs b/lib/modules/blockchain/blockchain-dal/src/readers/block.rs index 034b15e7736dc2cbe46d81156dc6dc9b067c62e6..f795061bf6223626f31a9e6152ae1509cb744703 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/block.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/block.rs @@ -13,6 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use crate::constants::*; use crate::*; use dubp_block_doc::block::{BlockDocument, BlockDocumentTrait}; use dubp_common_doc::traits::Document; @@ -21,36 +22,22 @@ use dup_crypto::keys::*; use std::collections::HashMap; use unwrap::unwrap; -/// get current blockstamp -pub fn get_current_blockstamp(blocks_db: &BlocksV10DBs) -> Result<Option<Blockstamp>, DALError> { - Ok(blocks_db.blockchain_db.read(|db| { - let blockchain_len = db.len() as u32; - if blockchain_len == 0 { - None - } else if let Some(dal_block) = db.get(&BlockNumber(blockchain_len - 1)) { - Some(dal_block.blockstamp()) - } else { - None - } - })?) -} - /// Get block hash -pub fn get_block_hash( - db: &BinDB<LocalBlockchainV10Datas>, +pub fn get_block_hash<DB: DbReadable>( + db: &DB, block_number: BlockNumber, ) -> Result<Option<BlockHash>, DALError> { - Ok(db.read(|db| { - if let Some(dal_block) = db.get(&block_number) { - dal_block.block.hash() + Ok( + if let Some(block) = get_block_in_local_blockchain(db, block_number)? { + block.hash() } else { None - } - })?) + }, + ) } /// Return true if the node already knows this block -pub fn already_have_block( - blockchain_db: &BinDB<LocalBlockchainV10Datas>, +pub fn already_have_block<DB: DbReadable>( + db: &DB, forks_dbs: &ForksDBs, blockstamp: Blockstamp, previous_hash: Option<Hash>, @@ -84,91 +71,114 @@ pub fn already_have_block( } } } else { - return Ok(blockchain_db.read(|db| { - if let Some(dal_block) = db.get(&blockstamp.id) { - if dal_block.block.hash().unwrap_or_default() == blockstamp.hash { - return true; - } - } - false - })?); + return Ok(get_block_in_local_blockchain(db, blockstamp.id)?.is_some()); } Ok(false) } /// Get block -pub fn get_block( - blockchain_db: &BinDB<LocalBlockchainV10Datas>, - forks_blocks_db: Option<&BinDB<ForksBlocksV10Datas>>, +pub fn get_block<DB: DbReadable>( + db: &DB, + forks_blocks_db: Option<&BinFreeStructDb<ForksBlocksV10Datas>>, blockstamp: &Blockstamp, ) -> Result<Option<DALBlock>, DALError> { - let dal_block = blockchain_db.read(|db| db.get(&blockstamp.id).cloned())?; - if dal_block.is_none() && forks_blocks_db.is_some() { + let opt_dal_block = get_dal_block_in_local_blockchain(db, blockstamp.id)?; + if opt_dal_block.is_none() && forks_blocks_db.is_some() { Ok(forks_blocks_db .expect("safe unwrap") .read(|db| db.get(&blockstamp).cloned())?) } else { - Ok(dal_block) + Ok(opt_dal_block) } } /// Get block in local blockchain #[inline] -pub fn get_block_in_local_blockchain( - db: &BinDB<LocalBlockchainV10Datas>, - block_id: BlockNumber, +pub fn get_block_in_local_blockchain<DB: DbReadable>( + db: &DB, + block_number: BlockNumber, ) -> Result<Option<BlockDocument>, DALError> { - Ok(db.read(|db| { - if let Some(dal_block) = db.get(&block_id) { - Some(dal_block.block.clone()) + Ok(get_dal_block_in_local_blockchain(db, block_number)?.map(|dal_block| dal_block.block)) +} + +/// Get block in local blockchain +pub fn get_dal_block_in_local_blockchain<DB: DbReadable>( + db: &DB, + block_number: BlockNumber, +) -> Result<Option<DALBlock>, DALError> { + db.read(|r| { + if let Some(v) = db.get_int_store(LOCAL_BC).get(r, block_number.0)? { + Ok(Some(DB::from_db_value(v)?)) } else { - None + Ok(None) } - })?) + }) + //local_bc_db.read(|r| local_bc_db.get(&r, block_number.0)) } /// Get several blocks in local blockchain -#[inline] -pub fn get_blocks_in_local_blockchain( - db: &BinDB<LocalBlockchainV10Datas>, +pub fn get_blocks_in_local_blockchain<DB: DbReadable>( + db: &DB, first_block_number: BlockNumber, - count: u32, + mut count: u32, ) -> Result<Vec<BlockDocument>, DALError> { - Ok(db.read(|db| { + db.read(|r| { + let bc_store = db.get_int_store(LOCAL_BC); let mut blocks = Vec::with_capacity(count as usize); let mut current_block_number = first_block_number; - while let Some(dal_block) = db.get(¤t_block_number) { - blocks.push(dal_block.block.clone()); - current_block_number = BlockNumber(current_block_number.0 + 1); + + while let Some(v) = bc_store.get(r, current_block_number.0)? { + blocks.push(DB::from_db_value::<DALBlock>(v)?.block); + count -= 1; + if count > 0 { + current_block_number = BlockNumber(current_block_number.0 + 1); + } else { + return Ok(blocks); + } + } + Ok(blocks) + }) + /*bc_db.read(|r| { + let mut blocks = Vec::with_capacity(count as usize); + let mut current_block_number = first_block_number; + while let Some(dal_block) = bc_db.get(&r, current_block_number.0)? { + blocks.push(dal_block.block); + count -= 1; + if count > 0 { + current_block_number = BlockNumber(current_block_number.0 + 1); + } else { + return Ok(blocks); + } } - blocks - })?) + Ok(blocks) + })*/ } /// Get current frame of calculating members -pub fn get_current_frame( +pub fn get_current_frame<DB: DbReadable>( current_block: &DALBlock, - db: &BinDB<LocalBlockchainV10Datas>, + db: &DB, ) -> Result<HashMap<PubKey, usize>, DALError> { let frame_begin = current_block.block.number().0 - current_block.block.current_frame_size() as u32; - Ok(db.read(|db| { - let mut current_frame: HashMap<PubKey, usize> = HashMap::new(); - for block_number in frame_begin..current_block.block.number().0 { - let issuer = db - .get(&BlockNumber(block_number)) - .unwrap_or_else(|| fatal_error!("Fail to get block #{} !", block_number)) - .block - .issuers()[0]; - let issuer_count_blocks = if let Some(issuer_count_blocks) = current_frame.get(&issuer) - { - issuer_count_blocks + 1 - } else { - 1 - }; - current_frame.insert(issuer, issuer_count_blocks); - } - current_frame - })?) + + let blocks = get_blocks_in_local_blockchain( + db, + BlockNumber(frame_begin), + current_block.block.current_frame_size() as u32, + )?; + + let mut current_frame: HashMap<PubKey, usize> = HashMap::new(); + for block in blocks { + let issuer = block.issuers()[0]; + let issuer_count_blocks = if let Some(issuer_count_blocks) = current_frame.get(&issuer) { + issuer_count_blocks + 1 + } else { + 1 + }; + current_frame.insert(issuer, issuer_count_blocks); + } + + Ok(current_frame) } diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs b/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs index 2c65e770d63deee7646cc72254ffa084a7dcc4bd..ec57457899aca37548ee2e3777d45e4cc9ac49f0 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/certs.rs @@ -13,14 +13,14 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use crate::{BinDB, CertsExpirV10Datas, DALError}; +use crate::{BinFreeStructDb, CertsExpirV10Datas, DALError}; use dubp_common_doc::BlockNumber; use durs_wot::WotId; use std::collections::HashMap; /// Find certifications that emitted in indicated blocks expiring pub fn find_expire_certs( - certs_db: &BinDB<CertsExpirV10Datas>, + certs_db: &BinFreeStructDb<CertsExpirV10Datas>, blocks_expiring: Vec<BlockNumber>, ) -> Result<HashMap<(WotId, WotId), BlockNumber>, DALError> { Ok(certs_db.read(|db| { diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/readers/fork_tree.rs index a61a9a2a25bdd6d5e95c66681135f524b3a50d69..37c448f6cc272819d30d08fe8b6334b0cb2e9793 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/fork_tree.rs @@ -16,6 +16,13 @@ use crate::*; use dubp_common_doc::Blockstamp; +/// get current blockstamp +pub fn get_current_blockstamp(forks_dbs: &ForksDBs) -> Result<Option<Blockstamp>, DALError> { + Ok(forks_dbs + .fork_tree_db + .read(|fork_tree| fork_tree.get_current_blockstamp())?) +} + /// Get stackables blocks pub fn get_stackables_blocks( forks_dbs: &ForksDBs, diff --git a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs index b6eb745a6e195ba2d590e7251857cb7d711bc93f..bd25cfa9e3bae493d580d88c5a66b665365fdaac 100644 --- a/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/readers/identity.rs @@ -15,7 +15,7 @@ use crate::entities::identity::DALIdentity; use crate::filters::identities::IdentitiesFilter; -use crate::{BinDB, DALError, IdentitiesV10Datas}; +use crate::{BinFreeStructDb, DALError, IdentitiesV10Datas}; use dubp_common_doc::traits::Document; use dubp_common_doc::BlockNumber; use dup_crypto::keys::*; @@ -24,7 +24,7 @@ use std::collections::HashMap; /// Get identities in databases pub fn get_identities( - db: &BinDB<IdentitiesV10Datas>, + db: &BinFreeStructDb<IdentitiesV10Datas>, filters: IdentitiesFilter, current_block_id: BlockNumber, ) -> Result<Vec<DALIdentity>, DALError> { @@ -62,7 +62,7 @@ pub fn get_identities( /// Get identity in databases pub fn get_identity( - db: &BinDB<IdentitiesV10Datas>, + db: &BinFreeStructDb<IdentitiesV10Datas>, pubkey: &PubKey, ) -> Result<Option<DALIdentity>, DALError> { Ok(db.read(|db| { @@ -76,7 +76,7 @@ pub fn get_identity( /// Get uid from pubkey pub fn get_uid( - identities_db: &BinDB<IdentitiesV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, pubkey: PubKey, ) -> Result<Option<String>, DALError> { Ok(identities_db.read(|db| { @@ -90,7 +90,7 @@ pub fn get_uid( /// Get pubkey from uid pub fn get_pubkey_from_uid( - identities_db: &BinDB<IdentitiesV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, uid: &str, ) -> Result<Option<PubKey>, DALError> { Ok(identities_db.read(|db| { @@ -105,7 +105,7 @@ pub fn get_pubkey_from_uid( /// Get wot_id index pub fn get_wot_index( - identities_db: &BinDB<IdentitiesV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, ) -> Result<HashMap<PubKey, WotId>, DALError> { Ok(identities_db.read(|db| { db.iter() @@ -155,8 +155,9 @@ mod test { ]; // Write mock identities in DB - let identities_db = - BinDB::Mem(open_memory_db::<IdentitiesV10Datas>().expect("Fail to create memory DB !")); + let identities_db = BinFreeStructDb::Mem( + open_free_struct_memory_db::<IdentitiesV10Datas>().expect("Fail to create memory DB !"), + ); for idty in &mock_identities { identities_db.write(|db| { db.insert(idty.idty_doc.issuers()[0], idty.clone()); diff --git a/lib/modules/blockchain/blockchain-dal/src/storage.rs b/lib/modules/blockchain/blockchain-dal/src/storage.rs new file mode 100644 index 0000000000000000000000000000000000000000..041a2d0ebf07a0d583d0e9629041775a4d297b51 --- /dev/null +++ b/lib/modules/blockchain/blockchain-dal/src/storage.rs @@ -0,0 +1,66 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +use crate::DALError; + +/// Storage type +pub enum StorageType { + Single, + SingleInteger, + Multi, + MultiInteger, +} + +pub enum DB { + File(Arc<RwLock<Rkv>>), + Mem(), +} + +impl DB { + /// Open database + pub fn open(db_path: Option<&PathBuf>) -> DB { + let bc_backend = if let Some(db_path) = db_path { + let mut manager = Manager::singleton() + .write() + .expect("fail to get rkb manager !"); + let db = manager + .get_or_create(db_path.as_path(), Rkv::new) + .expect("Fail to open LMDB blockchain database !"); + DB::File(db) + } else { + DB::Mem() + }; + } + /// Open integer storage (astorage is like a table or collection) + pub fn open_integer_storage(&self, storage_name: &str) -> Result<IntegerStore<u32>, DalError> { + let rkv = self.clone().read().expect("Fail to read lock Rkv"); + rkv.open_integer(storage_name, StoreOptions::create())?; + } +} + +/*pub trait MapStorage<K, V> { + + open(Option<&PathBuf>) -> Result<Self, DALError>; + + get(&self, key: &K) -> Result<Option<V>, DALError>; + put(&self, key: K, value: V) -> Result<(), DALError>; + delete(&self, key: &K) -> Result<(), DALError>; + + get_values(&self, keys: Vec<&K>) -> Result<Vec<(&K, Option<V>)>, DALError>; + put_values(&self, datas: Vec<(K, V)>) -> Result<Vec<()>, DALError>; + delete_values(&self, keys: Vec<&K>) -> Result<(), DALError>; + + fn save(&self) -> Result<(), DALError>; +}*/ diff --git a/lib/modules/blockchain/blockchain-dal/src/storage/local_blockchain.rs b/lib/modules/blockchain/blockchain-dal/src/storage/local_blockchain.rs new file mode 100644 index 0000000000000000000000000000000000000000..a5cf34f2ff2361f84328ba61fce24de576e5378b --- /dev/null +++ b/lib/modules/blockchain/blockchain-dal/src/storage/local_blockchain.rs @@ -0,0 +1,42 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Local blockchain storage + +use crate::entities::block::DALBlock; +use super::MapStorage; +use dubp_common_doc::BlockNumber; +use fnv::FnvHashMap; +use rkv::{IntegerStore, Manager, Rkv, StoreOptions, Value}; + +impl MapStorage<BlockNumber, DALBlock> { + + open(Option<&PathBuf>) -> Result<Self, DALError>; + + get(&self, key: &K) -> Result<Option<V>, DALError>; + put(&self, key: K, value: V) -> Result<(), DALError>; + delete(&self, key: &K) -> Result<(), DALError>; + + get_values(&self, keys: Vec<&K>) -> Result<Vec<(&K, Option<V>)>, DALError>; + put_values(&self, datas: Vec<(K, V)>) -> Result<Vec<()>, DALError>; + delete_values(&self, keys: Vec<&K>) -> Result<(), DALError>; + + fn save(&self) -> Result<(), DALError> { + if let Some(file_backend) = self.open_file_backend() { + file_backend.sync(true)?; + } + Ok(()) + } +} \ No newline at end of file diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/block.rs b/lib/modules/blockchain/blockchain-dal/src/writers/block.rs index 3e8f991d19cd36e6aae504d00317611b553cdc09..21316eef45edce18813f1d43e96494d9be4ee067 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/block.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/block.rs @@ -13,45 +13,62 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. +use crate::constants::*; use crate::entities::block::DALBlock; +use crate::DALError; use crate::*; -use crate::{BinDB, DALError, LocalBlockchainV10Datas}; use dubp_block_doc::block::BlockDocumentTrait; use dubp_common_doc::traits::Document; use unwrap::unwrap; /// Insert new head Block in databases pub fn insert_new_head_block( - blockchain_db: &BinDB<LocalBlockchainV10Datas>, - forks_dbs: &ForksDBs, + db: &Db, + forks_dbs: Option<&ForksDBs>, dal_block: DALBlock, ) -> Result<(), DALError> { // Insert head block in blockchain - blockchain_db.write(|db| { - db.insert(dal_block.block.number(), dal_block.clone()); + let bin_block = durs_dbs_tools::to_bytes(&dal_block)?; + db.write(|mut w| { + db.get_int_store(LOCAL_BC).put( + w.as_mut(), + *dal_block.block.number(), + &Db::db_value(&bin_block)?, + )?; + Ok(w) })?; - // Insert head block in fork tree - let removed_blockstamps = crate::writers::fork_tree::insert_new_head_block( - &forks_dbs.fork_tree_db, - dal_block.blockstamp(), - )?; - - // Insert head block in ForksBlocks - forks_dbs.fork_blocks_db.write(|db| { - db.insert(dal_block.blockstamp(), dal_block); - })?; + if let Some(forks_dbs) = forks_dbs { + // Insert head block in fork tree + let removed_blockstamps = crate::writers::fork_tree::insert_new_head_block( + &forks_dbs.fork_tree_db, + dal_block.blockstamp(), + )?; - // Remove too old blocks - forks_dbs.fork_blocks_db.write(|db| { - for blockstamp in removed_blockstamps { - db.remove(&blockstamp); - } - })?; + // Insert head block in ForksBlocks + forks_dbs.fork_blocks_db.write(|db| { + db.insert(dal_block.blockstamp(), dal_block); + })?; + // Remove too old blocks + forks_dbs.fork_blocks_db.write(|db| { + for blockstamp in removed_blockstamps { + db.remove(&blockstamp); + } + })?; + } Ok(()) } +/// Remove a block in local blockchain storage +pub fn remove_block(db: &Db, block_number: BlockNumber) -> Result<(), DALError> { + db.write(|mut w| { + db.get_int_store(LOCAL_BC) + .delete(w.as_mut(), block_number.0)?; + Ok(w) + }) +} + /// Insert new fork Block in databases pub fn insert_new_fork_block(forks_dbs: &ForksDBs, dal_block: DALBlock) -> Result<bool, DALError> { if crate::writers::fork_tree::insert_new_fork_block( diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs b/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs index 730c994294d1fe399f4bfe9c97b94efac4542b22..a6faeb472a0f812c5c9aa82fcb5d49ec46043dad 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/certification.rs @@ -13,7 +13,7 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. -use crate::{BinDB, CertsExpirV10Datas, DALError, IdentitiesV10Datas}; +use crate::{BinFreeStructDb, CertsExpirV10Datas, DALError, IdentitiesV10Datas}; use dubp_common_doc::BlockNumber; use dubp_currency_params::CurrencyParameters; use dubp_user_docs::documents::certification::CompactCertificationDocumentV10; @@ -23,8 +23,8 @@ use durs_wot::WotId; /// Apply "certification" event in databases pub fn write_certification( currency_params: &CurrencyParameters, - identities_db: &BinDB<IdentitiesV10Datas>, - certs_db: &BinDB<CertsExpirV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, + certs_db: &BinFreeStructDb<CertsExpirV10Datas>, source_pubkey: PubKey, source: WotId, target: WotId, @@ -56,8 +56,8 @@ pub fn write_certification( /// Revert writtent certification pub fn revert_write_cert( - identities_db: &BinDB<IdentitiesV10Datas>, - certs_db: &BinDB<CertsExpirV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, + certs_db: &BinFreeStructDb<CertsExpirV10Datas>, compact_doc: CompactCertificationDocumentV10, source: WotId, target: WotId, @@ -83,7 +83,7 @@ pub fn revert_write_cert( /// Revert "certification expiry" event in databases pub fn revert_expire_cert( - certs_db: &BinDB<CertsExpirV10Datas>, + certs_db: &BinFreeStructDb<CertsExpirV10Datas>, source: WotId, target: WotId, created_block_id: BlockNumber, @@ -99,7 +99,7 @@ pub fn revert_expire_cert( /// Apply "certification expiry" event in databases pub fn expire_certs( - certs_db: &BinDB<CertsExpirV10Datas>, + certs_db: &BinFreeStructDb<CertsExpirV10Datas>, created_block_id: BlockNumber, ) -> Result<(), DALError> { // Remove CertsExpirV10Datas entries diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs b/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs index 601e13f193a7de7c29a7d0b31e2fe69df4fc8abb..25af8596ed74846898b981c945efd08db60f27ff 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/dividend.rs @@ -22,8 +22,8 @@ use std::collections::{HashMap, HashSet}; /// Apply UD creation in databases pub fn create_du( - du_db: &BinDB<UDsV10Datas>, - balances_db: &BinDB<BalancesV10Datas>, + du_db: &BinFreeStructDb<UDsV10Datas>, + balances_db: &BinFreeStructDb<BalancesV10Datas>, du_amount: &SourceAmount, du_block_id: BlockNumber, members: &[PubKey], diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs b/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs index 0b2e913e47ac392c977d29e7e52b54fd403aff3c..1bff1dc617bfd1268f36893dc34636009e55a50f 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/fork_tree.rs @@ -20,7 +20,7 @@ use dubp_common_doc::BlockHash; /// Insert new head Block in fork tree, /// return vector of removed blockstamps pub fn insert_new_head_block( - fork_tree_db: &BinDB<ForksTreeV10Datas>, + fork_tree_db: &BinFreeStructDb<ForksTreeV10Datas>, blockstamp: Blockstamp, ) -> Result<Vec<Blockstamp>, DALError> { fork_tree_db.write(|fork_tree| { @@ -39,7 +39,7 @@ pub fn insert_new_head_block( /// Insert new fork block in fork tree only if parent exist in fork tree (orphan block not inserted) /// Returns true if block has a parent and has therefore been inserted, return false if block is orphaned pub fn insert_new_fork_block( - fork_tree_db: &BinDB<ForksTreeV10Datas>, + fork_tree_db: &BinFreeStructDb<ForksTreeV10Datas>, blockstamp: Blockstamp, previous_hash: Hash, ) -> Result<bool, DALError> { @@ -97,12 +97,12 @@ mod test { // Create mock datas let blockstamps = dubp_user_docs_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 2); - let fork_tree_db = open_db::<ForksTreeV10Datas>(None, "")?; + let fork_tree_db = open_free_struct_db::<ForksTreeV10Datas>(None, "")?; // Insert genesis block assert_eq!( - Ok(vec![]), - insert_new_head_block(&fork_tree_db, blockstamps[0]) + Vec::<Blockstamp>::with_capacity(0), + insert_new_head_block(&fork_tree_db, blockstamps[0])? ); // Check tree state @@ -115,8 +115,8 @@ mod test { // Insert FORK_WINDOW_SIZE blocks for i in 1..*DEFAULT_FORK_WINDOW_SIZE { assert_eq!( - Ok(vec![]), - insert_new_head_block(&fork_tree_db, blockstamps[i]) + Vec::<Blockstamp>::with_capacity(0), + insert_new_head_block(&fork_tree_db, blockstamps[i])? ); } @@ -135,12 +135,12 @@ mod test { // Insert blocks after FORK_WINDOW_SIZE (firsts blocks must be removed) assert_eq!( - Ok(vec![blockstamps[0]]), - insert_new_head_block(&fork_tree_db, blockstamps[*DEFAULT_FORK_WINDOW_SIZE]) + vec![blockstamps[0]], + insert_new_head_block(&fork_tree_db, blockstamps[*DEFAULT_FORK_WINDOW_SIZE])? ); assert_eq!( - Ok(vec![blockstamps[1]]), - insert_new_head_block(&fork_tree_db, blockstamps[*DEFAULT_FORK_WINDOW_SIZE + 1]) + vec![blockstamps[1]], + insert_new_head_block(&fork_tree_db, blockstamps[*DEFAULT_FORK_WINDOW_SIZE + 1])? ); Ok(()) @@ -151,13 +151,13 @@ mod test { // Create mock datas let blockstamps = dubp_user_docs_tests_tools::mocks::generate_blockstamps(*DEFAULT_FORK_WINDOW_SIZE + 3); - let fork_tree_db = open_db::<ForksTreeV10Datas>(None, "")?; + let fork_tree_db = open_free_struct_db::<ForksTreeV10Datas>(None, "")?; // Insert 4 main blocks for i in 0..4 { assert_eq!( - Ok(vec![]), - insert_new_head_block(&fork_tree_db, blockstamps[i]) + Vec::<Blockstamp>::with_capacity(0), + insert_new_head_block(&fork_tree_db, blockstamps[i])? ); } @@ -174,8 +174,8 @@ mod test { hash: BlockHash(dup_crypto_tests_tools::mocks::hash('A')), }; assert_eq!( - Ok(true), - insert_new_fork_block(&fork_tree_db, fork_blockstamp, blockstamps[2].hash.0) + true, + insert_new_fork_block(&fork_tree_db, fork_blockstamp, blockstamps[2].hash.0)? ); // Check tree state @@ -194,8 +194,8 @@ mod test { hash: BlockHash(dup_crypto_tests_tools::mocks::hash('B')), }; assert_eq!( - Ok(true), - insert_new_fork_block(&fork_tree_db, fork_blockstamp_2, fork_blockstamp.hash.0) + true, + insert_new_fork_block(&fork_tree_db, fork_blockstamp_2, fork_blockstamp.hash.0)? ); // Check tree state @@ -211,8 +211,8 @@ mod test { // Insert FORK_WINDOW_SIZE blocks for i in 4..*DEFAULT_FORK_WINDOW_SIZE { assert_eq!( - Ok(vec![]), - insert_new_head_block(&fork_tree_db, blockstamps[i]) + Vec::<Blockstamp>::with_capacity(0), + insert_new_head_block(&fork_tree_db, blockstamps[i])? ); } @@ -235,15 +235,15 @@ mod test { // Insert 2 new main blocks (too old blocks must be removed) for i in 0..2 { assert_eq!( - Ok(vec![blockstamps[i]]), - insert_new_head_block(&fork_tree_db, blockstamps[*DEFAULT_FORK_WINDOW_SIZE + i]) + vec![blockstamps[i]], + insert_new_head_block(&fork_tree_db, blockstamps[*DEFAULT_FORK_WINDOW_SIZE + i])? ); } // Insert one new main block (fork branch must be removed) assert_eq!( - Ok(vec![blockstamps[2], fork_blockstamp_2, fork_blockstamp]), - insert_new_head_block(&fork_tree_db, blockstamps[*DEFAULT_FORK_WINDOW_SIZE + 2]) + vec![blockstamps[2], fork_blockstamp_2, fork_blockstamp], + insert_new_head_block(&fork_tree_db, blockstamps[*DEFAULT_FORK_WINDOW_SIZE + 2])? ); // Check tree state diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs b/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs index 2e8cb65de8b557c7a396040a01a01fd84596e349..5e73017231bd6fd5748769d1759b7bbc326acdea 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/identity.rs @@ -14,7 +14,7 @@ // along with this program. If not, see <https://www.gnu.org/licenses/>. use crate::entities::identity::{DALIdentity, DALIdentityState}; -use crate::{BinDB, DALError, IdentitiesV10Datas, MsExpirV10Datas}; +use crate::{BinFreeStructDb, DALError, IdentitiesV10Datas, MsExpirV10Datas}; use dubp_common_doc::traits::Document; use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_currency_params::CurrencyParameters; @@ -25,8 +25,8 @@ use durs_wot::WotId; /// Remove identity from databases pub fn revert_create_identity( - identities_db: &BinDB<IdentitiesV10Datas>, - ms_db: &BinDB<MsExpirV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, + ms_db: &BinFreeStructDb<MsExpirV10Datas>, pubkey: &PubKey, ) -> Result<(), DALError> { let dal_idty = identities_db.read(|db| { @@ -53,8 +53,8 @@ pub fn revert_create_identity( /// Write identity in databases pub fn create_identity( currency_params: &CurrencyParameters, - identities_db: &BinDB<IdentitiesV10Datas>, - ms_db: &BinDB<MsExpirV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, + ms_db: &BinFreeStructDb<MsExpirV10Datas>, idty_doc: &IdentityDocumentV10, ms_created_block_id: BlockNumber, wot_id: WotId, @@ -90,7 +90,7 @@ pub fn create_identity( /// Apply "exclude identity" event pub fn exclude_identity( - identities_db: &BinDB<IdentitiesV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, pubkey: &PubKey, exclusion_blockstamp: &Blockstamp, revert: bool, @@ -127,7 +127,7 @@ pub fn exclude_identity( /// Apply "revoke identity" event pub fn revoke_identity( - identities_db: &BinDB<IdentitiesV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, pubkey: &PubKey, renewal_blockstamp: &Blockstamp, explicit: bool, @@ -178,8 +178,8 @@ pub fn revoke_identity( /// Apply "renewal identity" event in databases pub fn renewal_identity( currency_params: &CurrencyParameters, - identities_db: &BinDB<IdentitiesV10Datas>, - ms_db: &BinDB<MsExpirV10Datas>, + identities_db: &BinFreeStructDb<IdentitiesV10Datas>, + ms_db: &BinFreeStructDb<MsExpirV10Datas>, pubkey: &PubKey, idty_wot_id: WotId, renewal_timestamp: u64, @@ -241,7 +241,10 @@ pub fn renewal_identity( } /// Remove identity from databases -pub fn remove_identity(db: &BinDB<IdentitiesV10Datas>, pubkey: PubKey) -> Result<(), DALError> { +pub fn remove_identity( + db: &BinFreeStructDb<IdentitiesV10Datas>, + pubkey: PubKey, +) -> Result<(), DALError> { db.write(|db| { db.remove(&pubkey); })?; diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs index b79c7980c82674984a8fb3e4b4408df4cc6ca12a..00e51d6d35615028b7761ea64ca281aa49775dbc 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/requests.rs @@ -57,7 +57,7 @@ impl BlocksDBsWriteQuery { /// BlocksDBsWriteQuery pub fn apply( self, - blockchain_db: &BinDB<LocalBlockchainV10Datas>, + db: &Db, forks_db: &ForksDBs, fork_window_size: usize, sync_target: Option<Blockstamp>, @@ -70,20 +70,14 @@ impl BlocksDBsWriteQuery { || dal_block.blockstamp().id.0 + fork_window_size as u32 >= sync_target.expect("safe unwrap").id.0 { - super::block::insert_new_head_block(blockchain_db, forks_db, dal_block)?; + super::block::insert_new_head_block(db, Some(forks_db), dal_block)?; } else { - // Insert block in blockchain - blockchain_db.write(|db| { - db.insert(dal_block.block.number(), dal_block); - })?; + super::block::insert_new_head_block(db, None, dal_block)?; } } BlocksDBsWriteQuery::RevertBlock(dal_block) => { trace!("BlocksDBsWriteQuery::WriteBlock..."); - // Remove block in blockchain - blockchain_db.write(|db| { - db.remove(&dal_block.block.number()); - })?; + super::block::remove_block(db, dal_block.block.number())?; trace!("BlocksDBsWriteQuery::WriteBlock...finish"); } } diff --git a/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs b/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs index a9229cd85b8b952b9516b0927fec98cb7697e943..8714a46df2d23c85c1dd8e7ed7fbb8ac089dc08a 100644 --- a/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs +++ b/lib/modules/blockchain/blockchain-dal/src/writers/transaction.rs @@ -20,7 +20,7 @@ use crate::entities::sources::{SourceAmount, UTXOV10}; use crate::*; use dubp_indexes::sindex::{SourceUniqueIdV10, UniqueIdUTXOv10}; -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] /// Transaction error pub enum TxError { /// UnkonwError diff --git a/lib/modules/blockchain/blockchain/Cargo.toml b/lib/modules/blockchain/blockchain/Cargo.toml index 9c464a1f2b70be2a4f3aa31a464cbfd852340d67..364115a9ad2f4300fb026301d209cc65e689828d 100644 --- a/lib/modules/blockchain/blockchain/Cargo.toml +++ b/lib/modules/blockchain/blockchain/Cargo.toml @@ -39,4 +39,5 @@ unwrap = "1.2.1" [dev-dependencies] dup-crypto-tests-tools = { path = "../../../tests-tools/crypto-tests-tools" } -dubp-user-docs-tests-tools = { path = "../../../tests-tools/user-docs-tests-tools" } \ No newline at end of file +dubp-user-docs-tests-tools = { path = "../../../tests-tools/user-docs-tests-tools" } +tempfile = "3.1.0" diff --git a/lib/modules/blockchain/blockchain/src/dbex.rs b/lib/modules/blockchain/blockchain/src/dbex.rs index fe31cd626e3de6f9314a5a28bc3c6ac7956ecab8..7f4131a7acb745a57ce9df2abd24ec664bee9411 100644 --- a/lib/modules/blockchain/blockchain/src/dbex.rs +++ b/lib/modules/blockchain/blockchain/src/dbex.rs @@ -93,8 +93,8 @@ pub fn dbex_bc(profile_path: PathBuf, _csv: bool, _query: DbExBcQuery) -> Result // Open databases let load_dbs_begin = SystemTime::now(); - let blocks_db = BlocksV10DBs::open(Some(&db_path)); - //let forks_dbs = ForksDBs::open(Some(&db_path)); + let db = open_db(&db_path.as_path())?; + let forks_dbs = ForksDBs::open(Some(&db_path)); let wot_databases = WotsV10DBs::open(Some(&db_path)); let load_dbs_duration = SystemTime::now() @@ -107,18 +107,14 @@ pub fn dbex_bc(profile_path: PathBuf, _csv: bool, _query: DbExBcQuery) -> Result ); if let Some(current_blockstamp) = - durs_blockchain_dal::readers::block::get_current_blockstamp(&blocks_db)? + durs_blockchain_dal::readers::fork_tree::get_current_blockstamp(&forks_dbs)? { println!("Current block: #{}.", current_blockstamp); - if let Some(current_block) = durs_blockchain_dal::readers::block::get_block( - &blocks_db.blockchain_db, - None, - ¤t_blockstamp, - )? { - let map_pubkey = durs_blockchain_dal::readers::block::get_current_frame( - ¤t_block, - &blocks_db.blockchain_db, - )?; + if let Some(current_block) = + durs_blockchain_dal::readers::block::get_block(&db, None, ¤t_blockstamp)? + { + let map_pubkey = + durs_blockchain_dal::readers::block::get_current_frame(¤t_block, &db)?; let mut vec = map_pubkey.iter().collect::<Vec<(&PubKey, &usize)>>(); vec.sort_by(|a, b| b.1.cmp(&a.1)); @@ -303,8 +299,9 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { .expect("Fail to read IdentitiesDB !"); // Open wot db - let wot_db = BinDB::File( - open_file_db::<RustyWebOfTrust>(&db_path, "wot.db").expect("Fail to open WotDB !"), + let wot_db = BinFreeStructDb::File( + open_free_struct_file_db::<RustyWebOfTrust>(&db_path, "wot.db") + .expect("Fail to open WotDB !"), ); // Print wot blockstamp @@ -374,19 +371,19 @@ pub fn dbex_wot(profile_path: PathBuf, csv: bool, query: &DbExWotQuery) { } DbExWotQuery::ExpireMembers(ref reverse) => { // Open blockchain database - let blockchain_db = open_file_db::<LocalBlockchainV10Datas>(&db_path, "blockchain.db") - .expect("Fail to open blockchain db"); + let db = open_db(&db_path.as_path()).expect("Fail to open DB."); // Get blocks_times - let (current_bc_time, blocks_times): (u64, HashMap<BlockNumber, u64>) = blockchain_db - .read(|db| { - ( - db[&BlockNumber(db.len() as u32 - 1)].block.common_time(), - db.iter() - .map(|(block_id, dal_block)| (*block_id, dal_block.block.common_time())) - .collect(), - ) - }) - .expect("Fail to read blockchain db"); + let all_blocks = durs_blockchain_dal::readers::block::get_blocks_in_local_blockchain( + &db, + BlockNumber(0), + 10_000_000, + ) + .expect("Fail to get all blocks"); + let current_bc_time = all_blocks.last().expect("empty blockchain").common_time(); + let blocks_times: HashMap<BlockNumber, u64> = all_blocks + .iter() + .map(|block| (block.number(), block.common_time())) + .collect(); // Get expire_dates let min_created_ms_time = current_bc_time - currency_params.ms_validity; let mut expire_dates: Vec<(WotId, u64)> = wot_databases diff --git a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs index b7047a04f24f0b05e0649570d8a6ce461501841f..571c7708ec7aa41f72f1a93298166a965942d3d1 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/apply/mod.rs @@ -23,7 +23,7 @@ use dup_crypto::keys::*; use durs_blockchain_dal::entities::block::DALBlock; use durs_blockchain_dal::entities::sources::SourceAmount; use durs_blockchain_dal::writers::requests::*; -use durs_blockchain_dal::BinDB; +use durs_blockchain_dal::BinFreeStructDb; use durs_common_tools::fatal_error; use durs_wot::data::NewLinkResult; use durs_wot::{WebOfTrust, WotId}; @@ -49,7 +49,7 @@ pub enum ApplyValidBlockError { pub fn apply_valid_block<W: WebOfTrust>( block: BlockDocument, wot_index: &mut HashMap<PubKey, WotId>, - wot_db: &BinDB<W>, + wot_db: &BinFreeStructDb<W>, expire_certs: &HashMap<(WotId, WotId), BlockNumber>, ) -> Result<ValidBlockApplyReqs, ApplyValidBlockError> { match block { @@ -62,7 +62,7 @@ pub fn apply_valid_block<W: WebOfTrust>( pub fn apply_valid_block_v10<W: WebOfTrust>( mut block: BlockDocumentV10, wot_index: &mut HashMap<PubKey, WotId>, - wot_db: &BinDB<W>, + wot_db: &BinFreeStructDb<W>, expire_certs: &HashMap<(WotId, WotId), BlockNumber>, ) -> Result<ValidBlockApplyReqs, ApplyValidBlockError> { debug!( diff --git a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs index 9d13dd06e322710a08c52e64a35b250694b89f70..2ffefd8be2065781e6fa5e68497e4ea6815030af 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/check/mod.rs @@ -32,20 +32,22 @@ pub enum InvalidBlockError { VersionDecrease, } -pub fn verify_block_validity<W: WebOfTrust>( +pub fn verify_block_validity<DB, W>( block: &BlockDocument, - blockchain_db: &BinDB<LocalBlockchainV10Datas>, - _certs_db: &BinDB<CertsExpirV10Datas>, + db: &DB, + _certs_db: &BinFreeStructDb<CertsExpirV10Datas>, _wot_index: &HashMap<PubKey, WotId>, - _wot_db: &BinDB<W>, -) -> Result<(), BlockError> { + _wot_db: &BinFreeStructDb<W>, +) -> Result<(), BlockError> +where + DB: DbReadable, + W: WebOfTrust, +{ // Rules that do not concern genesis block if block.number().0 > 0 { // Get previous block - let previous_block_opt = readers::block::get_block_in_local_blockchain( - blockchain_db, - BlockNumber(block.number().0 - 1), - )?; + let previous_block_opt = + readers::block::get_block_in_local_blockchain(db, BlockNumber(block.number().0 - 1))?; // Previous block must exist if previous_block_opt.is_none() { diff --git a/lib/modules/blockchain/blockchain/src/dubp/mod.rs b/lib/modules/blockchain/blockchain/src/dubp/mod.rs index 5023e3f9425160a017438cf93e892e68b44220b3..8a86e0351b4e3ce8217b99563e36b35b2ea65b25 100644 --- a/lib/modules/blockchain/blockchain/src/dubp/mod.rs +++ b/lib/modules/blockchain/blockchain/src/dubp/mod.rs @@ -35,7 +35,7 @@ pub enum CheckAndApplyBlockReturn { OrphanBlock, } -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] pub enum BlockError { AlreadyHaveBlock, BlockOrOutForkWindow, @@ -69,7 +69,7 @@ pub fn check_and_apply_block( ) -> Result<CheckAndApplyBlockReturn, BlockError> { // Get BlockDocument && check if already have block let already_have_block = readers::block::already_have_block( - &bc.blocks_databases.blockchain_db, + &bc.db, &bc.forks_dbs, block_doc.blockstamp(), block_doc.previous_hash(), @@ -98,7 +98,7 @@ pub fn check_and_apply_block( // Verify block validity (check all protocol rule, very long !) verify_block_validity( &block_doc, - &bc.blocks_databases.blockchain_db, + &bc.db, &bc.wot_databases.certs_db, &bc.wot_index, &bc.wot_databases.wot_db, diff --git a/lib/modules/blockchain/blockchain/src/dunp/receiver.rs b/lib/modules/blockchain/blockchain/src/dunp/receiver.rs index 3fb479a61e0cf72f71b5a52ce602c3c8a99534c3..782820eb14b2cdd40195f329db336fd332f3fa07 100644 --- a/lib/modules/blockchain/blockchain/src/dunp/receiver.rs +++ b/lib/modules/blockchain/blockchain/src/dunp/receiver.rs @@ -53,7 +53,7 @@ pub fn receive_blocks(bc: &mut BlockchainModule, blocks: Vec<BlockDocument>) { // Apply db requests bc_db_query .apply( - &bc.blocks_databases.blockchain_db, + &bc.db, &bc.forks_dbs, unwrap!(bc.currency_params).fork_window_size, None, @@ -126,7 +126,9 @@ pub fn receive_blocks(bc: &mut BlockchainModule, blocks: Vec<BlockDocument>) { } // Save databases if save_blocks_dbs { - bc.blocks_databases.save_dbs(); + bc.db + .save() + .unwrap_or_else(|_| fatal_error!("DB corrupted, please reset data.")); bc.forks_dbs.save_dbs(); } if save_wots_dbs { diff --git a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs index 789b05eac21e58bb5f21282ec9de0b43e8dd5d72..2cc94befa0a316c18b08d350460b393e457a07c3 100644 --- a/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs +++ b/lib/modules/blockchain/blockchain/src/fork/fork_algo.rs @@ -106,11 +106,13 @@ mod tests { #[test] fn test_fork_resolution_algo() -> Result<(), DALError> { + // Open empty DB in tmp dir + let db = crate::tests::open_tmp_db()?; + // Get FORK_WINDOW_SIZE value let fork_window_size = *dubp_currency_params::constants::DEFAULT_FORK_WINDOW_SIZE; // Open empty databases in memory mode - let bc_dbs = BlocksV10DBs::open(None); let forks_dbs = ForksDBs::open(None); // Begin with no invalid blocks @@ -126,14 +128,25 @@ mod tests { // Insert mock blocks in forks_dbs for block in &main_branch { durs_blockchain_dal::writers::block::insert_new_head_block( - &bc_dbs.blockchain_db, - &forks_dbs, + &db, + Some(&forks_dbs), DALBlock { block: block.clone(), expire_certs: None, }, )?; } + + // Local blockchain must contain at least `fork_window_size +2` blocks + assert!( + durs_blockchain_dal::readers::block::get_block_in_local_blockchain( + &db, + BlockNumber((fork_window_size + 1) as u32) + )? + .is_some() + ); + + // Fork tree must contain at least `fork_window_size +2` blocks assert_eq!( fork_window_size, forks_dbs.fork_tree_db.read(|fork_tree| fork_tree.size())? diff --git a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs index 16a457d860eb90fe53123865b4895644525556b6..d6586090a22b13bdc6f9ddc9ba7b6ddcfe927beb 100644 --- a/lib/modules/blockchain/blockchain/src/fork/revert_block.rs +++ b/lib/modules/blockchain/blockchain/src/fork/revert_block.rs @@ -25,7 +25,7 @@ use durs_blockchain_dal::entities::block::DALBlock; use durs_blockchain_dal::entities::sources::SourceAmount; use durs_blockchain_dal::writers::requests::*; use durs_blockchain_dal::writers::transaction::DALTxV10; -use durs_blockchain_dal::{BinDB, DALError, TxV10Datas}; +use durs_blockchain_dal::{BinFreeStructDb, DALError, TxV10Datas}; use durs_common_tools::fatal_error; use durs_wot::data::{NewLinkResult, RemLinkResult}; use durs_wot::{WebOfTrust, WotId}; @@ -41,7 +41,7 @@ pub struct ValidBlockRevertReqs { pub currency_queries: Vec<CurrencyDBsWriteQuery>, } -#[derive(Debug, Copy, Clone)] +#[derive(Debug)] /// RevertValidBlockError pub enum RevertValidBlockError { ExcludeUnknowNodeId(), @@ -58,8 +58,8 @@ impl From<DALError> for RevertValidBlockError { pub fn revert_block<W: WebOfTrust>( dal_block: DALBlock, wot_index: &mut HashMap<PubKey, WotId>, - wot_db: &BinDB<W>, - txs_db: &BinDB<TxV10Datas>, + wot_db: &BinFreeStructDb<W>, + txs_db: &BinFreeStructDb<TxV10Datas>, ) -> Result<ValidBlockRevertReqs, RevertValidBlockError> { match dal_block.block { BlockDocument::V10(block_v10) => revert_block_v10( @@ -76,8 +76,8 @@ pub fn revert_block_v10<W: WebOfTrust>( mut block: BlockDocumentV10, expire_certs: HashMap<(WotId, WotId), BlockNumber>, wot_index: &mut HashMap<PubKey, WotId>, - wot_db: &BinDB<W>, - txs_db: &BinDB<TxV10Datas>, + wot_db: &BinFreeStructDb<W>, + txs_db: &BinFreeStructDb<TxV10Datas>, ) -> Result<ValidBlockRevertReqs, RevertValidBlockError> { // Get transactions let dal_txs: Vec<DALTxV10> = block diff --git a/lib/modules/blockchain/blockchain/src/fork/rollback.rs b/lib/modules/blockchain/blockchain/src/fork/rollback.rs index a4bbf7633c0413ca27e61440f1be7a3fb3bd992a..bac5a71c7b0c74828e0c9f1e4a2fae6fdd782fbc 100644 --- a/lib/modules/blockchain/blockchain/src/fork/rollback.rs +++ b/lib/modules/blockchain/blockchain/src/fork/rollback.rs @@ -59,7 +59,7 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) // Apply db requests block_query .apply( - &bc.blocks_databases.blockchain_db, + &bc.db, &bc.forks_dbs, unwrap!(bc.currency_params).fork_window_size, None, @@ -99,7 +99,7 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) // Apply db requests bc_db_query .apply( - &bc.blocks_databases.blockchain_db, + &bc.db, &bc.forks_dbs, unwrap!(bc.currency_params).fork_window_size, None, @@ -139,7 +139,9 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) } // save dbs - bc.blocks_databases.save_dbs(); + bc.db + .save() + .unwrap_or_else(|_| fatal_error!("DB corrupted, please reset data.")); bc.forks_dbs.save_dbs(); bc.wot_databases.save_dbs(); bc.currency_databases.save_dbs(true, true); @@ -161,7 +163,6 @@ pub fn apply_rollback(bc: &mut BlockchainModule, new_bc_branch: Vec<Blockstamp>) } else { // reload dbs let dbs_path = durs_conf::get_blockchain_db_path(bc.profile_path.clone()); - bc.blocks_databases = BlocksV10DBs::open(Some(&dbs_path)); bc.forks_dbs = ForksDBs::open(Some(&dbs_path)); bc.wot_databases = WotsV10DBs::open(Some(&dbs_path)); bc.currency_databases = CurrencyV10DBs::open(Some(&dbs_path)); diff --git a/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs b/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs index 8f0e348b73958efcbf33f909c77053292868ae34..905b847497e9797c537cd22c48a16457e1908b40 100644 --- a/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs +++ b/lib/modules/blockchain/blockchain/src/fork/stackable_blocks.rs @@ -47,7 +47,7 @@ pub fn apply_stackable_blocks(bc: &mut BlockchainModule) { // Apply db requests bc_db_query .apply( - &bc.blocks_databases.blockchain_db, + &bc.db, &bc.forks_dbs, unwrap!(bc.currency_params).fork_window_size, None, @@ -76,7 +76,9 @@ pub fn apply_stackable_blocks(bc: &mut BlockchainModule) { } } // Save databases - bc.blocks_databases.save_dbs(); + bc.db + .save() + .unwrap_or_else(|_| fatal_error!("DB corrupted, please reset data.")); bc.forks_dbs.save_dbs(); bc.wot_databases.save_dbs(); bc.currency_databases.save_dbs(true, true); diff --git a/lib/modules/blockchain/blockchain/src/lib.rs b/lib/modules/blockchain/blockchain/src/lib.rs index 3b08651bf9340da0ae74f2c5fd5a4d59606c73c6..28485b335ebc1a5e8a51db64e5a0ef339af072d1 100644 --- a/lib/modules/blockchain/blockchain/src/lib.rs +++ b/lib/modules/blockchain/blockchain/src/lib.rs @@ -18,7 +18,6 @@ #![allow(clippy::large_enum_variant)] #![deny( missing_docs, - missing_debug_implementations, missing_copy_implementations, trivial_casts, trivial_numeric_casts, @@ -89,7 +88,6 @@ pub static MAX_BLOCKS_REQUEST: &u32 = &500; pub static DISTANCE_CALCULATOR: &RustyDistanceCalculator = &RustyDistanceCalculator {}; /// Blockchain Module -#[derive(Debug)] pub struct BlockchainModule { /// Router sender pub router_sender: mpsc::Sender<RouterThreadMessage<DursMsg>>, @@ -97,8 +95,8 @@ pub struct BlockchainModule { pub profile_path: PathBuf, /// Currency pub currency: Option<CurrencyName>, - /// Blocks Databases - pub blocks_databases: BlocksV10DBs, + /// Database + pub db: Db, /// Forks Databases pub forks_dbs: ForksDBs, /// Wot index @@ -190,14 +188,14 @@ impl BlockchainModule { let dbs_path = durs_conf::get_blockchain_db_path(profile_path.clone()); // Open databases - let blocks_databases = BlocksV10DBs::open(Some(&dbs_path)); + let db = open_db(&dbs_path.as_path()).unwrap_or_else(|_| fatal_error!("Fail to open DB.")); let forks_dbs = ForksDBs::open(Some(&dbs_path)); let wot_databases = WotsV10DBs::open(Some(&dbs_path)); let currency_databases = CurrencyV10DBs::open(Some(&dbs_path)); // Get current blockstamp let current_blockstamp = - durs_blockchain_dal::readers::block::get_current_blockstamp(&blocks_databases) + durs_blockchain_dal::readers::fork_tree::get_current_blockstamp(&forks_dbs) .expect("Fatal error : fail to read Blockchain DB !") .unwrap_or_default(); @@ -226,7 +224,7 @@ impl BlockchainModule { currency_params, current_blockstamp, consensus: Blockstamp::default(), - blocks_databases, + db, forks_dbs, wot_index, wot_databases, @@ -342,3 +340,17 @@ impl BlockchainModule { } } } + +#[cfg(test)] +pub mod tests { + + use super::*; + use tempfile::tempdir; + + #[inline] + /// Open database in an arbitrary temporary directory given by OS + /// and automatically cleaned when `Db` is dropped + pub fn open_tmp_db() -> Result<Db, DALError> { + open_db(tempdir().map_err(DALError::FileSystemError)?.path()) + } +} diff --git a/lib/modules/blockchain/blockchain/src/requests/received.rs b/lib/modules/blockchain/blockchain/src/requests/received.rs index 00fd40c0a4ffeb625026f96848297fad3b54dc01..03414696dca78cfb8bd708368cfc702df4108259 100644 --- a/lib/modules/blockchain/blockchain/src/requests/received.rs +++ b/lib/modules/blockchain/blockchain/src/requests/received.rs @@ -37,11 +37,9 @@ pub fn receive_req( BlockchainRequest::CurrentBlock => { debug!("BlockchainModule : receive BlockchainRequest::CurrentBlock()"); - if let Ok(block_opt) = readers::block::get_block( - &bc.blocks_databases.blockchain_db, - None, - &bc.current_blockstamp, - ) { + if let Ok(block_opt) = + readers::block::get_block(&bc.db, None, &bc.current_blockstamp) + { if let Some(dal_block) = block_opt { debug!( "BlockchainModule : send_req_response(CurrentBlock({}))", @@ -71,10 +69,9 @@ pub fn receive_req( block_number ); - if let Ok(block_opt) = readers::block::get_block_in_local_blockchain( - &bc.blocks_databases.blockchain_db, - block_number, - ) { + if let Ok(block_opt) = + readers::block::get_block_in_local_blockchain(&bc.db, block_number) + { if let Some(block) = block_opt { debug!( "BlockchainModule : send_req_response(BlockByNumber(#{}))", @@ -108,7 +105,7 @@ pub fn receive_req( ); if let Ok(blocks) = readers::block::get_blocks_in_local_blockchain( - &bc.blocks_databases.blockchain_db, + &bc.db, first_block_number, count, ) { diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs b/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs index bdf091a89c313369038503fa406274e64905b38f..985c724d2bcbd48b67e01bac39bdbd14c4e09dbe 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/blocks_worker.rs @@ -21,7 +21,7 @@ pub fn execute( pool: &ThreadPool, sender_sync_thread: mpsc::Sender<MessForSyncThread>, recv: mpsc::Receiver<SyncJobsMess>, - blocks_dbs: BlocksV10DBs, + db: Db, forks_db: ForksDBs, target_blockstamp: Blockstamp, mut apply_pb: ProgressBar<std::io::Stdout>, @@ -46,13 +46,8 @@ pub fn execute( all_wait_duration += SystemTime::now().duration_since(wait_begin).unwrap(); // Apply db request - req.apply( - &blocks_dbs.blockchain_db, - &forks_db, - fork_window_size, - Some(target_blockstamp), - ) - .expect("Fatal error : Fail to apply DBWriteRequest !"); + req.apply(&db, &forks_db, fork_window_size, Some(target_blockstamp)) + .expect("Fatal error : Fail to apply DBWriteRequest !"); chunk_index += 1; if chunk_index == 250 { @@ -81,7 +76,8 @@ pub fn execute( println!(); println!("Write indexs in files..."); info!("Save blockchain and forks databases in files..."); - blocks_dbs.save_dbs(); + db.save() + .unwrap_or_else(|_| fatal_error!("DB corrupted, please reset data.")); forks_db.save_dbs(); // Send finish signal diff --git a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs index d21117caa1fda5738ebd4e191c21225a73b1b298..976212ca53d0b24aea1f4ad59bf2cf34e383d5ee 100644 --- a/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/apply/mod.rs @@ -27,7 +27,7 @@ use dubp_common_doc::{BlockNumber, Blockstamp}; use dubp_currency_params::{CurrencyName, CurrencyParameters}; use dup_crypto::keys::PubKey; use durs_blockchain_dal::writers::requests::WotsDBsWriteQuery; -use durs_blockchain_dal::{BinDB, CertsExpirV10Datas, WotsV10DBs}; +use durs_blockchain_dal::{BinFreeStructDb, CertsExpirV10Datas, WotsV10DBs}; use durs_common_tools::fatal_error; use durs_network_documents::url::Url; use durs_wot::data::rusty::RustyWebOfTrust; @@ -59,7 +59,7 @@ pub struct BlockApplicator { // databases pub wot_index: HashMap<PubKey, WotId>, pub wot_databases: WotsV10DBs, - pub certs_db: BinDB<CertsExpirV10Datas>, + pub certs_db: BinFreeStructDb<CertsExpirV10Datas>, // time measurement pub wait_begin: SystemTime, pub all_wait_duration: Duration, diff --git a/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs b/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs index 90520132d77d95e4246e47cf6f00356295c11466..6fa6caabff79d60402f29e8c179ed0395dcd329d 100644 --- a/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs +++ b/lib/modules/blockchain/blockchain/src/sync/download/json_reader_worker.rs @@ -96,9 +96,9 @@ pub fn json_reader_worker( // Get current local blockstamp debug!("Get local current blockstamp..."); let db_path = durs_conf::get_blockchain_db_path(profile_path); - let blocks_databases = BlocksV10DBs::open(Some(&db_path)); + let forks_dbs = ForksDBs::open(Some(&db_path)); let current_blockstamp: Blockstamp = - durs_blockchain_dal::readers::block::get_current_blockstamp(&blocks_databases) + durs_blockchain_dal::readers::fork_tree::get_current_blockstamp(&forks_dbs) .expect("ForksV10DB : RustBreakError !") .unwrap_or_default(); info!("Local current blockstamp = {}", current_blockstamp); diff --git a/lib/modules/blockchain/blockchain/src/sync/mod.rs b/lib/modules/blockchain/blockchain/src/sync/mod.rs index a5ddfa8f298e922990b50cec4ea822ef91717c68..b8a2c591ebac0c4175cec36e39265eecfb70e8bb 100644 --- a/lib/modules/blockchain/blockchain/src/sync/mod.rs +++ b/lib/modules/blockchain/blockchain/src/sync/mod.rs @@ -24,7 +24,7 @@ use dubp_common_doc::{BlockHash, BlockNumber}; use dubp_currency_params::{CurrencyName, CurrencyParameters}; use dup_crypto::keys::*; use durs_blockchain_dal::writers::requests::*; -use durs_blockchain_dal::{open_memory_db, CertsExpirV10Datas}; +use durs_blockchain_dal::{open_free_struct_memory_db, CertsExpirV10Datas}; use durs_common_tools::fatal_error; use durs_wot::WotId; use failure::Fail; @@ -69,6 +69,11 @@ pub enum SyncJobsMess { #[derive(Clone, Debug, Fail)] /// Local sync error pub enum LocalSyncError { + /// Fail to open database + #[fail( + display = "Unable to open the database, it may be a problem of access rights to the folder" + )] + FailToOpenDB, #[fail( display = "The folder you specified contains the blockchain of currency {}, \ and your node already contains the blockchain of another currency {}. If you \ @@ -175,7 +180,7 @@ pub fn local_sync<DC: DursConfTrait>( durs_conf::write_conf_file(conf_path.as_path(), &conf).expect("Fail to write new conf !"); // Open blocks databases - let blocks_dbs = BlocksV10DBs::open(Some(&db_path)); + let db = open_db(&db_path.as_path()).map_err(|_| LocalSyncError::FailToOpenDB)?; // Open forks databases let forks_dbs = ForksDBs::open(Some(&db_path)); @@ -186,7 +191,7 @@ pub fn local_sync<DC: DursConfTrait>( // Get local current blockstamp debug!("Get local current blockstamp..."); let current_blockstamp: Blockstamp = - durs_blockchain_dal::readers::block::get_current_blockstamp(&blocks_dbs) + durs_blockchain_dal::readers::fork_tree::get_current_blockstamp(&forks_dbs) .expect("DALError : fail to get current blockstamp !") .unwrap_or_default(); debug!("Success to get local current blockstamp."); @@ -235,7 +240,7 @@ pub fn local_sync<DC: DursConfTrait>( &pool, sender_sync_thread.clone(), recv_blocks_thread, - blocks_dbs, + db, forks_dbs, target_blockstamp, apply_pb, @@ -261,8 +266,9 @@ pub fn local_sync<DC: DursConfTrait>( // Open databases let dbs_path = durs_conf::get_blockchain_db_path(profile_path.clone()); - let certs_db = - BinDB::Mem(open_memory_db::<CertsExpirV10Datas>().expect("Fail to create memory certs_db")); + let certs_db = BinFreeStructDb::Mem( + open_free_struct_memory_db::<CertsExpirV10Datas>().expect("Fail to create memory certs_db"), + ); // initialise le BlockApplicator let mut block_applicator = BlockApplicator { diff --git a/lib/tools/dbs-tools/Cargo.toml b/lib/tools/dbs-tools/Cargo.toml new file mode 100644 index 0000000000000000000000000000000000000000..57de80404f1d64984e2f9680d0c0fadb93b18095 --- /dev/null +++ b/lib/tools/dbs-tools/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "durs-dbs-tools" +version = "0.1.0-a" +authors = ["librelois <elois@ifee.fr>"] +description = "DBs tools for Dunitrust project." +license = "AGPL-3.0" +edition = "2018" + +[lib] +path = "src/lib.rs" + +[dependencies] +bincode = "1.0.*" +durs-common-tools = { path = "../common-tools" } +fnv = "1.0.6" +log = "0.4.*" +rkv = "0.9.7" +rustbreak = {version = "2.0.0-rc3", features = ["bin_enc"]} +serde = { version = "1.0.*", features = ["derive"] } +serde_json = "1.0.*" +unwrap = "1.2.1" + +[dev-dependencies] + + +[features] diff --git a/lib/tools/dbs-tools/src/errors.rs b/lib/tools/dbs-tools/src/errors.rs new file mode 100644 index 0000000000000000000000000000000000000000..245ce61edf8eef2a12dd20519f82bda4f74af7a7 --- /dev/null +++ b/lib/tools/dbs-tools/src/errors.rs @@ -0,0 +1,76 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Common Datas Access Layer for Dunitrust project +//! Errors manadgment + +use rustbreak::error::{RustbreakError, RustbreakErrorKind}; + +#[derive(Debug)] +/// Data Access Layer Error +pub enum DALError { + /// Abort write transaction + WriteAbort { + /// Reason of transaction abort + reason: String, + }, + /// Error in write operation + WriteError, + /// Error in read operation + ReadError, + /// A database is corrupted, you have to reset the data completely + DBCorrupted, + /// Error with the file system + FileSystemError(std::io::Error), + /// Serialization/Deserialization error + SerdeError(String), + /// Rkv store error + StoreError(rkv::error::StoreError), + /// Capturing a panic signal during a write operation + WritePanic, + /// Unknown error + UnknowError, +} + +impl From<bincode::Error> for DALError { + fn from(e: bincode::Error) -> DALError { + DALError::SerdeError(format!("{}", e)) + } +} + +impl From<rkv::error::StoreError> for DALError { + fn from(e: rkv::error::StoreError) -> DALError { + DALError::StoreError(e) + } +} + +impl<T> From<std::sync::PoisonError<T>> for DALError { + fn from(_: std::sync::PoisonError<T>) -> DALError { + DALError::DBCorrupted + } +} + +impl From<RustbreakError> for DALError { + fn from(rust_break_error: RustbreakError) -> DALError { + match rust_break_error.kind() { + RustbreakErrorKind::Serialization => DALError::WriteError, + RustbreakErrorKind::Deserialization => DALError::ReadError, + RustbreakErrorKind::Poison => DALError::DBCorrupted, + RustbreakErrorKind::Backend => DALError::DBCorrupted, + RustbreakErrorKind::WritePanic => DALError::WritePanic, + _ => DALError::UnknowError, + } + } +} diff --git a/lib/tools/dbs-tools/src/free_struct_db.rs b/lib/tools/dbs-tools/src/free_struct_db.rs new file mode 100644 index 0000000000000000000000000000000000000000..b42fd09c1a0634507e21a0b1f595ef909c48db8e --- /dev/null +++ b/lib/tools/dbs-tools/src/free_struct_db.rs @@ -0,0 +1,123 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Define free structure database + +use crate::errors::DALError; +use rustbreak::backend::{FileBackend, MemoryBackend}; +use rustbreak::error::RustbreakError; +use rustbreak::{deser::Bincode, Database, FileDatabase, MemoryDatabase}; +use serde::de::DeserializeOwned; +use serde::Serialize; +use std::default::Default; +use std::fmt::Debug; +use std::fs; +use std::panic::UnwindSafe; +use std::path::PathBuf; + +/// Open free structured rustbreak memory database +pub fn open_free_struct_memory_db< + D: Serialize + DeserializeOwned + Debug + Default + Clone + Send, +>() -> Result<MemoryDatabase<D, Bincode>, DALError> { + let backend = MemoryBackend::new(); + let db = MemoryDatabase::<D, Bincode>::from_parts(D::default(), backend, Bincode); + Ok(db) +} + +/// Open free structured rustbreak file database +pub fn open_free_struct_file_db< + D: Serialize + DeserializeOwned + Debug + Default + Clone + Send, +>( + dbs_folder_path: &PathBuf, + db_file_name: &str, +) -> Result<FileDatabase<D, Bincode>, DALError> { + let mut db_path = dbs_folder_path.clone(); + db_path.push(db_file_name); + let file_path = db_path.as_path(); + if file_path.exists() + && fs::metadata(file_path) + .expect("fail to get file size") + .len() + > 0 + { + let backend = FileBackend::open(db_path.as_path())?; + let db = FileDatabase::<D, Bincode>::from_parts(D::default(), backend, Bincode); + db.load()?; + Ok(db) + } else { + Ok(FileDatabase::<D, Bincode>::from_path( + db_path.as_path(), + D::default(), + )?) + } +} + +#[derive(Debug)] +/// Database +pub enum BinFreeStructDb<D: Serialize + DeserializeOwned + Debug + Default + Clone + Send> { + /// File database + File(Database<D, FileBackend, Bincode>), + /// Memory database + Mem(Database<D, MemoryBackend, Bincode>), +} + +impl<D: Serialize + DeserializeOwned + Debug + Default + Clone + Send> BinFreeStructDb<D> { + /// Flush the data structure to the backend + pub fn save(&self) -> Result<(), RustbreakError> { + match *self { + BinFreeStructDb::File(ref file_db) => file_db.save(), + BinFreeStructDb::Mem(ref mem_db) => mem_db.save(), + } + } + /// Read lock the database and get write access to the Data container + /// This gives you a read-only lock on the database. You can have as many readers in parallel as you wish. + pub fn read<T, R>(&self, task: T) -> Result<R, RustbreakError> + where + T: FnOnce(&D) -> R, + { + match *self { + BinFreeStructDb::File(ref file_db) => file_db.read(task), + BinFreeStructDb::Mem(ref mem_db) => mem_db.read(task), + } + } + /// Write lock the database and get write access to the Data container + /// This gives you an exclusive lock on the memory object. Trying to open the database in writing will block if it is currently being written to. + pub fn write<T>(&self, task: T) -> Result<(), RustbreakError> + where + T: FnOnce(&mut D), + { + match *self { + BinFreeStructDb::File(ref file_db) => file_db.write(task), + BinFreeStructDb::Mem(ref mem_db) => mem_db.write(task), + } + } + /// Write lock the database and get write access to the Data container in a safe way (clone of the internal data is made). + pub fn write_safe<T>(&self, task: T) -> Result<(), RustbreakError> + where + T: FnOnce(&mut D) + UnwindSafe, + { + match *self { + BinFreeStructDb::File(ref file_db) => file_db.write_safe(task), + BinFreeStructDb::Mem(ref mem_db) => mem_db.write_safe(task), + } + } + /// Load the Data from the backend + pub fn load(&self) -> Result<(), RustbreakError> { + match *self { + BinFreeStructDb::File(ref file_db) => file_db.load(), + BinFreeStructDb::Mem(ref mem_db) => mem_db.load(), + } + } +} diff --git a/lib/tools/dbs-tools/src/kv_db.rs b/lib/tools/dbs-tools/src/kv_db.rs new file mode 100644 index 0000000000000000000000000000000000000000..4ccf499b82ad7bd060614be809cb84ba26255a1c --- /dev/null +++ b/lib/tools/dbs-tools/src/kv_db.rs @@ -0,0 +1,27 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Define Key-Value database + +mod file; + +pub use file::{ + KvFileDbHandler, KvFileDbRead, KvFileDbReader, KvFileDbRoHandler, KvFileDbSchema, + KvFileDbStoreType, KvFileDbWriter, +}; +pub use rkv::{ + IntegerStore, MultiIntegerStore, MultiStore, OwnedValue as KvFileDbOwnedValue, SingleStore, + Value as KvFileDbValue, +}; diff --git a/lib/tools/dbs-tools/src/kv_db/file.rs b/lib/tools/dbs-tools/src/kv_db/file.rs new file mode 100644 index 0000000000000000000000000000000000000000..2585c112ff363144aa31e93b3461d43547433ff3 --- /dev/null +++ b/lib/tools/dbs-tools/src/kv_db/file.rs @@ -0,0 +1,274 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! Define Key-Value file database + +use crate::errors::DALError; +use durs_common_tools::fatal_error; +use log::error; +use rkv::{DatabaseFlags, EnvironmentFlags, Manager, OwnedValue, Rkv, StoreOptions, Value}; +use serde::de::DeserializeOwned; +use serde::Serialize; +use std::collections::HashMap; +use std::fmt::Debug; +use std::path::{Path, PathBuf}; +use std::sync::{Arc, RwLock}; + +/// Key-value database reader +pub type KvFileDbReader<'a> = &'a rkv::Reader<'a>; + +/// Key-value database writer +pub struct KvFileDbWriter<'a> { + buffer: Vec<u8>, + writer: rkv::Writer<'a>, +} + +impl<'a> AsMut<rkv::Writer<'a>> for KvFileDbWriter<'a> { + fn as_mut(&mut self) -> &mut rkv::Writer<'a> { + &mut self.writer + } +} + +/// Key-value file Database handler +pub struct KvFileDbHandler { + arc: Arc<RwLock<Rkv>>, + path: PathBuf, + schema: KvFileDbSchema, + stores: HashMap<String, KvFileDbStore>, +} + +/// Key-value file Database read-only handler +pub struct KvFileDbRoHandler(KvFileDbHandler); + +/// Key-value file Database read operations +pub trait KvFileDbRead: Sized { + /// Convert DB value to a rust type + fn from_db_value<T: DeserializeOwned>(v: Value) -> Result<T, DALError>; + + /// get a single store + fn get_store(&self, store_name: &str) -> &super::SingleStore; + + /// Get an integer store + fn get_int_store(&self, store_name: &str) -> &super::IntegerStore<u32>; + + /// Read datas in transaction database + fn read<F, R>(&self, f: F) -> Result<R, DALError> + where + F: FnOnce(KvFileDbReader) -> Result<R, DALError>; + + /// Try to clone database handler + fn try_clone(&self) -> Result<Self, DALError>; +} + +impl KvFileDbRead for KvFileDbRoHandler { + #[inline] + fn from_db_value<T: DeserializeOwned>(v: Value) -> Result<T, DALError> { + KvFileDbHandler::from_db_value(v) + } + #[inline] + fn get_store(&self, store_name: &str) -> &super::SingleStore { + self.0.get_store(store_name) + } + #[inline] + fn get_int_store(&self, store_name: &str) -> &super::IntegerStore<u32> { + self.0.get_int_store(store_name) + } + #[inline] + fn read<F, R>(&self, f: F) -> Result<R, DALError> + where + F: FnOnce(KvFileDbReader) -> Result<R, DALError>, + { + self.0.read(f) + } + #[inline] + fn try_clone(&self) -> Result<Self, DALError> { + Ok(KvFileDbRoHandler(self.0.try_clone()?)) + } +} + +/// Describe Key-Value database schema +#[derive(Debug, Clone)] +pub struct KvFileDbSchema { + /// Database collections + pub stores: HashMap<String, KvFileDbStoreType>, +} + +/// Key-value store type (store is like "table" in SGBD) +#[derive(Debug, Clone, Copy)] +pub enum KvFileDbStoreType { + /// Single valued map + Single, + /// Single valued map with integer key + SingleIntKey, + /// Multi valued map + Multi, + /// Multi valued map with integer key + MultiIntKey, +} + +/// Key-value file DB store (store is like "table" in SGBD) +pub enum KvFileDbStore { + /// Single valued map + Single(super::SingleStore), + /// Single valued map with integer key + SingleIntKey(super::IntegerStore<u32>), + /// Multi valued map + Multi(super::MultiStore), + /// Multi valued map with integer key + MultiIntKey(super::MultiIntegerStore<u32>), +} + +impl KvFileDbRead for KvFileDbHandler { + #[inline] + fn from_db_value<T: DeserializeOwned>(v: Value) -> Result<T, DALError> { + if let Value::Blob(bytes) = v { + Ok(bincode::deserialize::<T>(bytes)?) + } else { + Err(DALError::DBCorrupted) + } + } + fn get_int_store(&self, store_name: &str) -> &super::IntegerStore<u32> { + if let Some(store_enum) = self.stores.get(store_name) { + if let KvFileDbStore::SingleIntKey(store) = store_enum { + store + } else { + fatal_error!("Dev error: store '{}' is not an integer store.", store_name); + } + } else { + fatal_error!("Dev error: store '{}' don't exist in DB.", store_name); + } + } + fn get_store(&self, store_name: &str) -> &super::SingleStore { + if let Some(store_enum) = self.stores.get(store_name) { + if let KvFileDbStore::Single(store) = store_enum { + store + } else { + fatal_error!("Dev error: store '{}' is not a single store.", store_name); + } + } else { + fatal_error!("Dev error: store '{}' don't exist in DB.", store_name); + } + } + fn read<F, R>(&self, f: F) -> Result<R, DALError> + where + F: FnOnce(KvFileDbReader) -> Result<R, DALError>, + { + Ok(f(&self.arc_clone().read()?.read()?)?) + } + fn try_clone(&self) -> Result<KvFileDbHandler, DALError> { + KvFileDbHandler::open_db_inner(&self.path, &self.schema, false) + } +} + +impl KvFileDbHandler { + fn arc(&self) -> &Arc<RwLock<Rkv>> { + &self.arc + } + fn arc_clone(&self) -> Arc<RwLock<Rkv>> { + self.arc().clone() + } + /// Convert bytes to DB value + pub fn db_value(bytes: &[u8]) -> Result<Value, DALError> { + Ok(Value::Blob(bytes)) + } + /// Get read_only handler + pub fn get_ro_handler(&self) -> Result<KvFileDbRoHandler, DALError> { + Ok(KvFileDbRoHandler(self.try_clone()?)) + } + /// Open Key-value file Database + #[inline] + pub fn open_db(path: &Path, schema: &KvFileDbSchema) -> Result<KvFileDbHandler, DALError> { + KvFileDbHandler::open_db_inner(path, schema, true) + } + fn open_db_inner( + path: &Path, + schema: &KvFileDbSchema, + first_open: bool, + ) -> Result<KvFileDbHandler, DALError> { + let mut manager = Manager::singleton().write()?; + let mut env = Rkv::environment_builder(); + env.set_flags(EnvironmentFlags::NO_SYNC) + .set_max_dbs(64) + .set_map_size(std::u32::MAX as usize); + let arc = manager.get_or_create(path, |path| Rkv::from_env(path, env))?; + + let mut stores = HashMap::new(); + for (store_name, store_type) in &schema.stores { + let store = match store_type { + KvFileDbStoreType::Single => { + KvFileDbStore::Single(arc.clone().read()?.open_single( + store_name.as_str(), + StoreOptions { + create: first_open, + flags: DatabaseFlags::empty(), + }, + )?) + } + KvFileDbStoreType::SingleIntKey => { + KvFileDbStore::SingleIntKey(arc.clone().read()?.open_integer( + store_name.as_str(), + StoreOptions { + create: first_open, + flags: DatabaseFlags::INTEGER_KEY, + }, + )?) + } + KvFileDbStoreType::Multi => KvFileDbStore::Multi(arc.clone().read()?.open_multi( + store_name.as_str(), + StoreOptions { + create: first_open, + flags: DatabaseFlags::empty(), + }, + )?), + KvFileDbStoreType::MultiIntKey => { + KvFileDbStore::MultiIntKey(arc.clone().read()?.open_multi_integer( + store_name.as_str(), + StoreOptions { + create: first_open, + flags: DatabaseFlags::INTEGER_KEY, + }, + )?) + } + }; + stores.insert(store_name.to_owned(), store); + } + + Ok(KvFileDbHandler { + arc, + path: path.to_owned(), + schema: schema.clone(), + stores, + }) + } + /// Persist DB datas on disk + pub fn save(&self) -> Result<(), DALError> { + Ok(self.arc_clone().read()?.sync(true)?) + } + /// Write datas in database + /// /!\ The written data are visible to readers but not persisted on the disk until a save() is performed. + pub fn write<F>(&self, f: F) -> Result<(), DALError> + where + F: FnOnce(KvFileDbWriter) -> Result<KvFileDbWriter, DALError>, + { + f(KvFileDbWriter { + buffer: Vec::with_capacity(0), + writer: self.arc().read()?.write()?, + })? + .writer + .commit()?; + + Ok(()) + } +} diff --git a/lib/tools/dbs-tools/src/lib.rs b/lib/tools/dbs-tools/src/lib.rs new file mode 100644 index 0000000000000000000000000000000000000000..219f96b73ad97ee26ac8ea56dc2e6d8a4f7f4f5c --- /dev/null +++ b/lib/tools/dbs-tools/src/lib.rs @@ -0,0 +1,62 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as +// published by the Free Software Foundation, either version 3 of the +// License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU Affero General Public License for more details. +// +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +//! DBs tools for Dunitrust project. + +#![allow(dead_code, unused_imports, clippy::large_enum_variant)] +#![deny( + missing_docs, + missing_copy_implementations, + trivial_casts, + trivial_numeric_casts, + unsafe_code, + unstable_features, + unused_import_braces, + unused_qualifications +)] + +mod errors; +mod free_struct_db; +pub mod kv_db; + +pub use errors::DALError; +pub use free_struct_db::{open_free_struct_file_db, open_free_struct_memory_db, BinFreeStructDb}; + +use serde::de::DeserializeOwned; +use serde::Serialize; +use std::default::Default; +use std::fmt::Debug; +use std::path::PathBuf; + +/// Convert rust type to bytes +#[inline] +pub fn to_bytes<T: Serialize>(t: &T) -> Result<Vec<u8>, DALError> { + Ok(bincode::serialize(t)?) +} + +/// Open free structured database +pub fn open_free_struct_db<D: Serialize + DeserializeOwned + Debug + Default + Clone + Send>( + dbs_folder_path: Option<&PathBuf>, + db_file_name: &str, +) -> Result<BinFreeStructDb<D>, DALError> { + if let Some(dbs_folder_path) = dbs_folder_path { + Ok(BinFreeStructDb::File(open_free_struct_file_db::<D>( + dbs_folder_path, + db_file_name, + )?)) + } else { + Ok(BinFreeStructDb::Mem(open_free_struct_memory_db::<D>()?)) + } +}