From 71ac6b12055f0fdab478f8e5fad3fdce5626e9e0 Mon Sep 17 00:00:00 2001 From: Alexandru Sardan Date: Thu, 30 May 2024 16:01:37 +0000 Subject: [PATCH 1/2] Refactor `casper-db-utils` to make it compatible with casper-node 2.0 Signed-off-by: Alexandru Sardan --- Cargo.lock | 2794 +++++------------ Cargo.toml | 21 +- src/common.rs | 1 - src/common/db.rs | 47 +- src/common/db/approvals_hashes_db.rs | 35 + src/common/db/block_body_db.rs | 10 +- ...eploy_hashes_db.rs => block_body_v2_db.rs} | 14 +- src/common/db/block_header_db.rs | 10 +- ...ansfer_hashes_db.rs => block_header_v2.rs} | 14 +- src/common/db/block_metadata_db.rs | 10 +- src/common/db/block_metadata_v2_db.rs | 27 + src/common/db/deploy_metadata_db.rs | 17 +- src/common/db/deploys_db.rs | 2 +- src/common/db/execution_results_db.rs | 26 + src/common/db/finalized_approvals_db.rs | 5 +- src/common/db/tests.rs | 64 +- .../{proposers_db.rs => transactions_db.rs} | 14 +- src/common/db/transfer_db.rs | 4 +- ...db.rs => versioned_approvals_hashes_db.rs} | 14 +- .../db/versioned_finalized_approvals_db.rs | 28 + src/common/db/versioned_transfers_db.rs | 27 + src/common/lmdb_utils.rs | 90 - src/main.rs | 4 +- src/subcommands/check.rs | 67 +- src/subcommands/execution_results_summary.rs | 15 +- .../execution_results_summary/block_body.rs | 50 - .../execution_results_summary/read_db.rs | 139 +- .../execution_results_summary/summary.rs | 2 +- .../execution_results_summary/tests.rs | 273 +- src/subcommands/extract_slice.rs | 21 +- src/subcommands/extract_slice/db_helpers.rs | 39 - src/subcommands/extract_slice/extract.rs | 6 +- src/subcommands/extract_slice/global_state.rs | 14 +- src/subcommands/extract_slice/storage.rs | 217 +- src/subcommands/extract_slice/tests.rs | 534 +--- src/subcommands/latest_block_summary.rs | 11 +- .../latest_block_summary/block_info.rs | 34 +- .../latest_block_summary/read_db.rs | 106 +- src/subcommands/latest_block_summary/tests.rs | 111 +- src/subcommands/purge_signatures.rs | 20 +- .../purge_signatures/block_signatures.rs | 44 - src/subcommands/purge_signatures/purge.rs | 208 +- .../purge_signatures/signatures.rs | 177 +- src/subcommands/purge_signatures/tests.rs | 1449 ++++----- src/subcommands/remove_block.rs | 24 +- src/subcommands/remove_block/remove.rs | 109 +- src/subcommands/remove_block/tests.rs | 803 ++--- src/subcommands/trie_compact.rs | 20 +- src/subcommands/trie_compact/compact.rs | 63 +- src/subcommands/trie_compact/helpers.rs | 31 +- src/subcommands/trie_compact/tests.rs | 99 +- src/subcommands/trie_compact/utils.rs | 110 +- src/subcommands/unsparse.rs | 21 +- src/test_utils.rs | 146 +- 54 files changed, 3036 insertions(+), 5205 deletions(-) create mode 100644 src/common/db/approvals_hashes_db.rs rename src/common/db/{deploy_hashes_db.rs => block_body_v2_db.rs} (53%) rename src/common/db/{transfer_hashes_db.rs => block_header_v2.rs} (52%) create mode 100644 src/common/db/block_metadata_v2_db.rs create mode 100644 src/common/db/execution_results_db.rs rename src/common/db/{proposers_db.rs => transactions_db.rs} (54%) rename src/common/db/{block_body_merkle_db.rs => versioned_approvals_hashes_db.rs} (52%) create mode 100644 src/common/db/versioned_finalized_approvals_db.rs create mode 100644 src/common/db/versioned_transfers_db.rs delete mode 100644 src/common/lmdb_utils.rs delete mode 100644 src/subcommands/execution_results_summary/block_body.rs delete mode 100644 src/subcommands/extract_slice/db_helpers.rs delete mode 100644 src/subcommands/purge_signatures/block_signatures.rs diff --git a/Cargo.lock b/Cargo.lock index faae83e..068ed0b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,21 +2,11 @@ # It is not intended for manual editing. version = 3 -[[package]] -name = "Inflector" -version = "0.11.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" -dependencies = [ - "lazy_static", - "regex", -] - [[package]] name = "addr2line" -version = "0.19.0" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a76fd60b23679b7d19bd066031410fb7e458ccc5e958eb5c325888ce4baedc97" +checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" dependencies = [ "gimli", ] @@ -29,85 +19,24 @@ checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" [[package]] name = "aho-corasick" -version = "0.7.20" +version = "1.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac" +checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" dependencies = [ "memchr", ] -[[package]] -name = "alloc-no-stdlib" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc7bb162ec39d46ab1ca8c77bf72e890535becd1751bb45f64c597edb4c8c6b3" - -[[package]] -name = "alloc-stdlib" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94fb8275041c72129eb51b7d0322c29b8387a0386127718b096429201a5d6ece" -dependencies = [ - "alloc-no-stdlib", -] - -[[package]] -name = "android_system_properties" -version = "0.1.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" -dependencies = [ - "libc", -] - -[[package]] -name = "ansi_term" -version = "0.12.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d52a9bb7ec0cf484c551830a7ce27bd20d67eac647e1befb56b0be4ee39a55d2" -dependencies = [ - "winapi", -] - [[package]] name = "anyhow" -version = "1.0.70" +version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7de8ce5e0f9f8d88245311066a578d72b7af3e7088f32783804676302df237e4" +checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" [[package]] -name = "async-compression" -version = "0.3.15" +name = "atomic-waker" +version = "1.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "942c7cd7ae39e91bde4820d74132e9862e62c2f386c3aa90ccf55949f5bad63a" -dependencies = [ - "brotli", - "flate2", - "futures-core", - "memchr", - "pin-project-lite", - "tokio", -] - -[[package]] -name = "async-trait" -version = "0.1.68" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9ccdd8f2a161be9bd5c023df56f1b2a0bd1d83872ae53b71a84a12c9bf6e842" -dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", -] - -[[package]] -name = "atomic-shim" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d20fdac7156779a1a30d970e838195558b4810dd06aa69e7c7461bdc518edf9b" -dependencies = [ - "crossbeam", -] +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "atty" @@ -122,19 +51,19 @@ dependencies = [ [[package]] name = "autocfg" -version = "1.1.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d468802bab17cbc0cc575e9b053f41e72aa36bfa6b7f55e3529ffa43161b97fa" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" -version = "0.3.67" +version = "0.3.72" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "233d376d6d185f2a3093e58f283f60f880315b6c60075b01f36b3b85154564ca" +checksum = "17c6a35df3749d2e8bb1b7b21a976d82b15548788d2735b9d82f329268f71a11" dependencies = [ "addr2line", "cc", - "cfg-if 1.0.0", + "cfg-if", "libc", "miniz_oxide", "object", @@ -147,6 +76,12 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d27c3610c36aee21ce8ac510e6224498de4228ad772a171ed65643a24693a5a8" +[[package]] +name = "base16ct" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c7f02d4ea65f2c1853089ffd8d2787bdbc63de2f0d29dedbcf8ccdfa0ccd4cf" + [[package]] name = "base64" version = "0.13.1" @@ -155,9 +90,15 @@ checksum = "9e1b586273c5702936fe7b7d6896644d8be71e6314cfe09d3167c95f712589e8" [[package]] name = "base64" -version = "0.21.0" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64ct" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4a4ddaa51a5bc52a6948f74c06d20aaaddb71924eab79b8c97a8c556e942d6a" +checksum = "8c3c1a368f70d6cf7302d78f8f7093da241fb8e8807c05cc9e51a125895a6d5b" [[package]] name = "bincode" @@ -190,15 +131,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" [[package]] -name = "bitvec" -version = "0.18.5" +name = "bitflags" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98fcd36dda4e17b7d7abc64cb549bf0201f4ab71e00700c798ca7e62ed3761fa" -dependencies = [ - "funty", - "radium", - "wyz", -] +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" [[package]] name = "blake2" @@ -206,20 +142,11 @@ version = "0.9.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0a4e37d16930f5459780f5621038b6382b9bb37c19016f39fb6b5808d831f174" dependencies = [ - "crypto-mac 0.8.0", + "crypto-mac", "digest 0.9.0", "opaque-debug", ] -[[package]] -name = "block-buffer" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4152116fd6e9dadb291ae18fc1ec3575ed6d84c29642d97890f4b4a3417297e4" -dependencies = [ - "generic-array", -] - [[package]] name = "block-buffer" version = "0.10.4" @@ -229,44 +156,23 @@ dependencies = [ "generic-array", ] -[[package]] -name = "brotli" -version = "3.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1a0b1dbcc8ae29329621f8d4f0d835787c1c38bb1401979b49d13b0b305ff68" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", - "brotli-decompressor", -] - -[[package]] -name = "brotli-decompressor" -version = "2.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b6561fd3f895a11e8f72af2cb7d22e08366bebc2b6b57f7744c4bda27034744" -dependencies = [ - "alloc-no-stdlib", - "alloc-stdlib", -] - [[package]] name = "bumpalo" -version = "3.12.0" +version = "3.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d261e256854913907f67ed06efbc3338dfe6179796deefc1ff763fc1aee5535" +checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c" [[package]] name = "byteorder" -version = "1.4.3" +version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" [[package]] name = "bytes" -version = "1.4.0" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89b2fd2a0dcf38d7971e2194b6b6eebab45ae01067456a7fd93d5547a61b70be" +checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cache-padded" @@ -282,7 +188,7 @@ checksum = "e11c675378efb449ed3ce8de78d75d0d80542fc98487c26aba28eb3b82feac72" dependencies = [ "semver", "serde", - "toml 0.7.5", + "toml", "url", ] @@ -294,16 +200,14 @@ dependencies = [ "bincode", "cargo-lock", "casper-execution-engine", - "casper-hashing", - "casper-node", + "casper-storage", "casper-types", - "clap 3.2.25", + "clap", "futures", - "lmdb", - "lmdb-sys", + "lmdb-rkv", "log", "once_cell", - "rand 0.8.5", + "rand", "reqwest", "ringbuf", "serde", @@ -318,271 +222,181 @@ dependencies = [ [[package]] name = "casper-execution-engine" -version = "4.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43f452bdfc52a9cb70c121d03b5ae10e01b685f9bdacc9fd1ed38cff7242df69" +version = "7.0.0" +source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#f803ee53db31edd5f7f3c1fa1e0ec0ea59550158" dependencies = [ "anyhow", "base16", "bincode", - "casper-hashing", + "casper-storage", "casper-types", + "casper-wasm", "casper-wasm-utils", - "chrono", + "casper-wasmi", "datasize", "either", - "hex-buffer-serde 0.2.2", + "hex-buffer-serde", "hex_fmt", "hostname", + "humantime", "itertools", - "libc", "linked-hash-map", - "lmdb", "log", "num", "num-derive", - "num-rational 0.4.1", + "num-rational", "num-traits", "num_cpus", "once_cell", - "parity-wasm", "proptest", - "rand 0.8.5", - "rand_chacha 0.3.1", + "rand", + "rand_chacha", "schemars", "serde", "serde_bytes", "serde_json", + "strum", "thiserror", "tracing", "uint", - "uuid", - "wasmi", ] [[package]] -name = "casper-hashing" -version = "1.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8f51474856233388910920a6392b5ff19c6dfba2d001b17118cac9bf43667397" -dependencies = [ - "base16", - "blake2", - "casper-types", - "datasize", - "hex", - "hex-buffer-serde 0.3.0", - "itertools", - "schemars", - "serde", - "thiserror", -] - -[[package]] -name = "casper-node" -version = "1.4.15-alt" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7f6e3c80f7cada6bb4d405a7c5bf2e4728afa09d60b1b5cf29dab7b1e7a2ac6" +name = "casper-storage" +version = "2.0.0" +source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#f803ee53db31edd5f7f3c1fa1e0ec0ea59550158" dependencies = [ - "ansi_term", - "anyhow", - "async-trait", - "backtrace", - "base16", - "base64 0.13.1", "bincode", - "bytes", - "casper-execution-engine", - "casper-hashing", - "casper-node-macros", "casper-types", - "chrono", "datasize", - "derive_more", - "derp", - "ed25519-dalek", "either", - "enum-iterator", - "fs2", - "futures", - "futures-io", - "getrandom", - "hex-buffer-serde 0.3.0", - "hex_fmt", - "hostname", - "http", - "humantime", - "hyper", "itertools", - "jemalloc-ctl", - "jemallocator", - "k256", - "libc", "linked-hash-map", - "lmdb", - "log", + "lmdb-rkv", "num", "num-derive", - "num-rational 0.4.1", + "num-rational", "num-traits", - "num_cpus", "once_cell", - "openssl", - "parking_lot 0.11.2", - "pem", - "pin-project", - "prometheus", - "quanta", - "rand 0.8.5", - "rand_chacha 0.3.1", - "regex", - "rmp-serde", - "schemars", + "rand", + "rand_chacha", "serde", - "serde-big-array", - "serde_bytes", - "serde_json", - "serde_repr", - "signal-hook", - "signature", - "smallvec", - "static_assertions", - "structopt", - "sys-info", "tempfile", "thiserror", - "tokio", - "tokio-openssl", - "tokio-serde", - "tokio-stream", - "tokio-util 0.6.10", - "toml 0.5.11", - "tower", "tracing", - "tracing-futures", - "tracing-subscriber", - "uint", - "untrusted", "uuid", - "vergen", - "warp", - "warp-json-rpc", - "wheelbuf", -] - -[[package]] -name = "casper-node-macros" -version = "1.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29d034bcd971692440e26ac229595fcf349e528a29fd8df44b42cfd8c66b9ef1" -dependencies = [ - "Inflector", - "indexmap 1.9.3", - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", ] [[package]] name = "casper-types" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e40fa172ff619ae56b2d3c6feb3e941a07fc64c0c73b913621ab0b2808cad80" +version = "5.0.0" +source = "git+https://github.com/casper-network/casper-node.git?branch=feat-2.0#f803ee53db31edd5f7f3c1fa1e0ec0ea59550158" dependencies = [ "base16", "base64 0.13.1", - "bitflags", + "bincode", + "bitflags 1.3.2", "blake2", "datasize", + "derive_more", "derp", "ed25519-dalek", "getrandom", "hex", "hex_fmt", "humantime", + "itertools", "k256", + "libc", "num", "num-derive", "num-integer", - "num-rational 0.4.1", + "num-rational", "num-traits", "once_cell", "pem", "proptest", "proptest-derive", - "rand 0.8.5", + "rand", "rand_pcg", "schemars", "serde", + "serde-map-to-array", "serde_bytes", "serde_json", "strum", "thiserror", + "tracing", "uint", "untrusted", ] +[[package]] +name = "casper-wasm" +version = "0.46.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48f53c4e789fbff66ead0ea44030b1af2fc3c465201973483528e479a9155f98" + [[package]] name = "casper-wasm-utils" -version = "1.0.0" +version = "3.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e9c4208106e8a95a83ab3cb5f4e800114bfc101df9e7cb8c2160c7e298c6397" +checksum = "15d9f1a2269d52961812862f67d209ef29742d06b47634e2982a96e80d0fe2b4" dependencies = [ "byteorder", + "casper-wasm", "log", - "parity-wasm", ] [[package]] -name = "cc" -version = "1.0.79" +name = "casper-wasmi" +version = "0.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d30906286121d95be3d479533b458f87493b30a4b5f79a607db8f5d11aa91f" +checksum = "8357f19a7fd98073d8fe8df60f1bef1e677b7c623c1e6e2e07d2f8e59ceb87fc" dependencies = [ - "jobserver", + "casper-wasm", + "casper-wasmi-core", + "casper-wasmi-validation", ] [[package]] -name = "cfg-if" -version = "0.1.10" +name = "casper-wasmi-core" +version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" +checksum = "60089625560924f184cf91d59b0731373d5114b81224f1201c6a39ccc1d8388c" +dependencies = [ + "downcast-rs", + "libm", + "memory_units", + "num-rational", + "num-traits", +] [[package]] -name = "cfg-if" -version = "1.0.0" +name = "casper-wasmi-validation" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +checksum = "f669d385132ce321a57fdf453588d69c01654e75991bee3d22392a3aaaad80bb" +dependencies = [ + "casper-wasm", +] [[package]] -name = "chrono" -version = "0.4.24" +name = "cc" +version = "1.0.98" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e3c5919066adf22df73762e50cffcde3a758f2a848b113b586d1f86728b673b" +checksum = "41c270e7540d725e65ac7f1b212ac8ce349719624d7bcff99f8e2e488e8cf03f" dependencies = [ - "iana-time-zone", - "js-sys", - "num-integer", - "num-traits", - "time 0.1.45", - "wasm-bindgen", - "winapi", + "jobserver", + "libc", + "once_cell", ] [[package]] -name = "clap" -version = "2.34.0" +name = "cfg-if" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a0610544180c38b88101fecf2dd634b174a62eef6946f84dfc6a7127512b381c" -dependencies = [ - "ansi_term", - "atty", - "bitflags", - "strsim 0.8.0", - "textwrap 0.11.0", - "unicode-width", - "vec_map", -] +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" [[package]] name = "clap" @@ -591,13 +405,13 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "atty", - "bitflags", + "bitflags 1.3.2", "clap_lex", "indexmap 1.9.3", "once_cell", - "strsim 0.10.0", + "strsim", "termcolor", - "textwrap 0.16.0", + "textwrap", ] [[package]] @@ -609,21 +423,11 @@ dependencies = [ "os_str_bytes", ] -[[package]] -name = "codespan-reporting" -version = "0.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3538270d33cc669650c4b093848450d380def10c331d38c768e34cac80576e6e" -dependencies = [ - "termcolor", - "unicode-width", -] - [[package]] name = "const-oid" -version = "0.4.5" +version = "0.9.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f6b64db6932c7e49332728e3a6bd82c6b7e16016607d20923b537c3bc4c0d5f" +checksum = "c2459377285ad874054d797f3ccebf984978aa39129f6eafde5cdc8315b612f8" [[package]] name = "convert_case" @@ -633,9 +437,9 @@ checksum = "6245d59a3e82a7fc217c5828a6692dbc6dfb63a0c8c90495621f7b9d79704a0e" [[package]] name = "core-foundation" -version = "0.9.3" +version = "0.9.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "194a7a9e6de53fa55116934067c844d9d749312f75c6f6d0980e8c252f8c2146" +checksum = "91e195e091a93c46f7102ec7818a2aa394e1e1771c3ab4825963fa03e45afb8f" dependencies = [ "core-foundation-sys", "libc", @@ -643,106 +447,37 @@ dependencies = [ [[package]] name = "core-foundation-sys" -version = "0.8.4" +version = "0.8.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" +checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f" [[package]] name = "cpufeatures" -version = "0.2.6" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "280a9f2d8b3a38871a3c8a46fb80db65e5e5ed97da80c4d08bf27fb63e35e181" +checksum = "53fe5e26ff1b7aef8bca9c6080520cfb8d9333c7568e1829cef191a9723e5504" dependencies = [ "libc", ] [[package]] -name = "crc32fast" -version = "1.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b540bd8bc810d3885c6ea91e2018302f68baba2129ab3e88f32389ee9370880d" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "crossbeam" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e" -dependencies = [ - "cfg-if 0.1.10", - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-epoch", - "crossbeam-queue", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-channel" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b153fe7cbef478c567df0f972e02e6d736db11affe43dfc9c56a9374d1adfb87" -dependencies = [ - "crossbeam-utils", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-deque" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c20ff29ded3204c5106278a81a38f4b482636ed4fa1e6cfbeef193291beb29ed" -dependencies = [ - "crossbeam-epoch", - "crossbeam-utils", - "maybe-uninit", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "058ed274caafc1f60c4997b5fc07bf7dc7cca454af7c6e81edffe5f33f70dace" -dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "crossbeam-utils", - "lazy_static", - "maybe-uninit", - "memoffset", - "scopeguard", -] - -[[package]] -name = "crossbeam-queue" -version = "0.2.3" +name = "crunchy" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "774ba60a54c213d409d5353bda12d49cd68d14e45036a285234c8d6f91f92570" -dependencies = [ - "cfg-if 0.1.10", - "crossbeam-utils", - "maybe-uninit", -] +checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" [[package]] -name = "crossbeam-utils" -version = "0.7.2" +name = "crypto-bigint" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3c7c73a2d1e9fc0886a08b93e98eb643461230d5f1925e4036204d5f2e261a8" +checksum = "0dc92fb57ca44df6db8059111ab3af99a63d5d0f8375d9972e319a379c6bab76" dependencies = [ - "autocfg", - "cfg-if 0.1.10", - "lazy_static", + "generic-array", + "rand_core", + "subtle", + "zeroize", ] -[[package]] -name = "crunchy" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" - [[package]] name = "crypto-common" version = "0.1.6" @@ -763,114 +498,71 @@ dependencies = [ "subtle", ] -[[package]] -name = "crypto-mac" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bff07008ec701e8028e2ceb8f83f0e4274ee62bd2dbdc4fefff2e9a91824081a" -dependencies = [ - "generic-array", - "subtle", -] - -[[package]] -name = "ctor" -version = "0.1.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d2301688392eb071b0bf1a37be05c469d3cc4dbbd95df672fe28ab021e6a096" -dependencies = [ - "quote 1.0.29", - "syn 1.0.109", -] - [[package]] name = "curve25519-dalek" -version = "3.2.1" +version = "4.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90f9d052967f590a76e62eb387bd0bbb1b000182c3cefe5364db6b7211651bc0" +checksum = "0a677b8922c94e01bdbb12126b0bc852f00447528dee1782229af9c720c3f348" dependencies = [ - "byteorder", - "digest 0.9.0", - "rand_core 0.5.1", + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "platforms", + "rustc_version", "subtle", "zeroize", ] [[package]] -name = "cxx" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e88abab2f5abbe4c56e8f1fb431b784d710b709888f35755a160e62e33fe38e8" -dependencies = [ - "cc", - "cxxbridge-flags", - "cxxbridge-macro", - "link-cplusplus", -] - -[[package]] -name = "cxx-build" -version = "1.0.94" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12cee708e8962df2aeb38f594aae5d827c022b6460ac71a7a3e2c3c2aae5a07b" -dependencies = [ - "cc", - "codespan-reporting", - "once_cell", - "proc-macro2 1.0.63", - "quote 1.0.29", - "scratch", - "syn 2.0.23", -] - -[[package]] -name = "cxxbridge-flags" -version = "1.0.97" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8d3816ed957c008ccd4728485511e3d9aaf7db419aa321e3d2c5a2f3411e36c8" - -[[package]] -name = "cxxbridge-macro" -version = "1.0.97" +name = "curve25519-dalek-derive" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a26acccf6f445af85ea056362561a24ef56cdc15fcc685f03aec50b9c702cb6d" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] name = "datasize" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c88ad90721dc8e2ebe1430ac2f59c5bdcd74478baa68da26f30f33b0fe997f11" +checksum = "e65c07d59e45d77a8bda53458c24a828893a99ac6cdd9c84111e09176ab739a2" dependencies = [ "datasize_derive", - "fake_instant", - "futures", - "serde", - "smallvec", ] [[package]] name = "datasize_derive" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b0415ec81945214410892a00d4b5dd4566f6263205184248e018a3fe384a61e" +checksum = "613e4ee15899913285b7612004bbd490abd605be7b11d35afada5902fb6b91d5" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", + "proc-macro2 1.0.84", + "quote 1.0.36", "syn 1.0.109", ] [[package]] name = "der" -version = "0.1.0" +version = "0.7.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51f59c66c30bb7445c8320a5f9233e437e3572368099f25532a59054328899b4" +checksum = "f55bf8e7b65898637379c1b74eb1551107c8294ed26d855ceb9fd1a09cfc9bc0" dependencies = [ "const-oid", + "zeroize", +] + +[[package]] +name = "deranged" +version = "0.3.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4" +dependencies = [ + "powerfmt", ] [[package]] @@ -880,8 +572,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321" dependencies = [ "convert_case", - "proc-macro2 1.0.63", - "quote 1.0.29", + "proc-macro2 1.0.84", + "quote 1.0.36", "rustc_version", "syn 1.0.109", ] @@ -906,223 +598,146 @@ dependencies = [ [[package]] name = "digest" -version = "0.10.6" +version = "0.10.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8168378f4e5023e7218c89c891c0fd8ecdb5e5e4f18cb78f38cf245dd021e76f" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" dependencies = [ - "block-buffer 0.10.4", + "block-buffer", + "const-oid", "crypto-common", + "subtle", ] [[package]] name = "downcast-rs" -version = "1.2.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ea835d29036a4087793836fa931b08837ad5e957da9e23886b29586fb9b6650" +checksum = "75b325c5dbd37f80359721ad39aca5a29fb04c89279657cffdda8736d0c0b9d2" [[package]] name = "dyn-clone" -version = "1.0.11" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68b0cf012f1230e43cd00ebb729c6bb58707ecfa8ad08b52ef3a4ccd2697fc30" +checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" [[package]] name = "ecdsa" -version = "0.10.2" +version = "0.16.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41fbdb4ff710acb4db8ca29f93b897529ea6d6a45626d5183b47e012aa6ae7e4" +checksum = "ee27f32b5c5292967d2d4a9d7f1e0b0aed2c15daded5a60300e4abb9d8020bca" dependencies = [ + "der", + "digest 0.10.7", "elliptic-curve", - "hmac", + "rfc6979", "signature", ] [[package]] name = "ed25519" -version = "1.2.0" +version = "2.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4620d40f6d2601794401d6dd95a5cf69b6c157852539470eeda433a99b3c0efc" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" dependencies = [ - "serde", + "pkcs8", "signature", ] [[package]] name = "ed25519-dalek" -version = "1.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" dependencies = [ "curve25519-dalek", "ed25519", - "rand 0.7.3", "serde", - "serde_bytes", "sha2", + "subtle", "zeroize", ] -[[package]] -name = "educe" -version = "0.4.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb0188e3c3ba8df5753894d54461f0e39bc91741dc5b22e1c46999ec2c71f4e4" -dependencies = [ - "enum-ordinalize", - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", -] - [[package]] name = "either" -version = "1.8.1" +version = "1.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7fcaabb2fef8c910e7f4c7ce9f67a1283a1715879a7c230ca9d6d1ae31f16d91" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" [[package]] name = "elliptic-curve" -version = "0.8.5" +version = "0.13.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f2db227e61a43a34915680bdda462ec0e212095518020a88a1f91acd16092c39" +checksum = "b5e6043086bf7973472e0c7dff2142ea0b680d30e18d9cc40f267efbf222bd47" dependencies = [ - "bitvec", - "digest 0.9.0", + "base16ct", + "crypto-bigint", + "digest 0.10.7", "ff", - "funty", "generic-array", "group", - "pkcs8", - "rand_core 0.5.1", + "rand_core", + "sec1", "subtle", "zeroize", ] [[package]] name = "encoding_rs" -version = "0.8.32" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "071a31f4ee85403370b58aca746f01041ede6f0da2730960ad001edc2b71b394" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "enum-iterator" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c79a6321a1197d7730510c7e3f6cb80432dfefecb32426de8cea0aa19b4bb8d7" -dependencies = [ - "enum-iterator-derive", -] - -[[package]] -name = "enum-iterator-derive" -version = "0.6.0" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e94aa31f7c0dc764f57896dc615ddd76fc13b0d5dca7eb6cc5e018a5a09ec06" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", -] - -[[package]] -name = "enum-ordinalize" -version = "3.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a62bb1df8b45ecb7ffa78dca1c17a438fb193eb083db0b1b494d2a61bcb5096a" -dependencies = [ - "num-bigint 0.4.3", - "num-traits", - "proc-macro2 1.0.63", - "quote 1.0.29", - "rustc_version", - "syn 1.0.109", + "cfg-if", ] [[package]] name = "equivalent" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "88bffebc5d80432c9b140ee17875ff173a8ab62faad5b257da912bd2f6c1c0a1" - -[[package]] -name = "erased-serde" -version = "0.3.25" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f2b0c2380453a92ea8b6c8e5f64ecaafccddde8ceab55ff7a8ac1029f894569" -dependencies = [ - "serde", -] +checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50d6a0976c999d473fe89ad888d5a284e55366d9dc9038b1ba2aa15128c4afa0" -dependencies = [ - "errno-dragonfly", - "libc", - "windows-sys 0.45.0", -] - -[[package]] -name = "errno-dragonfly" -version = "0.1.2" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aa68f1b12764fab894d2755d2518754e71b4fd80ecfb822714a1206c2aab39bf" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ - "cc", "libc", + "windows-sys 0.52.0", ] -[[package]] -name = "fake_instant" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3006df2e7bf21592b4983931164020b02f54eefdc1e35b2f70147858cc1e20ad" - [[package]] name = "fastrand" -version = "1.9.0" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e51093e27b0797c359783294ca4f0a911c270184cb10f85783b118614a1501be" -dependencies = [ - "instant", -] +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "ff" -version = "0.8.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01646e077d4ebda82b73f1bca002ea1e91561a77df2431a9e79729bcc31950ef" +checksum = "ded41244b729663b1e574f1b4fb731469f69f79c17667b5d776b16cda0479449" dependencies = [ - "bitvec", - "rand_core 0.5.1", + "rand_core", "subtle", ] [[package]] -name = "filetime" -version = "0.2.20" +name = "fiat-crypto" +version = "0.2.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a3de6e8d11b22ff9edc6d916f890800597d60f8b2da1caf2955c274638d6412" -dependencies = [ - "cfg-if 1.0.0", - "libc", - "redox_syscall 0.2.16", - "windows-sys 0.45.0", -] +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" [[package]] -name = "flate2" -version = "1.0.25" +name = "filetime" +version = "0.2.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8a2db397cb1c8772f31494cb8917e48cd1e64f0fa7efac59fbd741a0a8ce841" +checksum = "1ee447700ac8aa0b2f2bd7bc4462ad686ba06baa6727ac149a2d6277f0d240fd" dependencies = [ - "crc32fast", - "miniz_oxide", + "cfg-if", + "libc", + "redox_syscall 0.4.1", + "windows-sys 0.52.0", ] [[package]] @@ -1148,40 +763,18 @@ checksum = "00b0228411908ca8685dba7fc2cdd70ec9990a6e753e89b6ac91a84c40fbaf4b" [[package]] name = "form_urlencoded" -version = "1.1.0" +version = "1.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9c384f161156f5260c24a097c56119f9be8c798586aecc13afbcbe7b7e26bf8" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" dependencies = [ "percent-encoding", ] -[[package]] -name = "fs2" -version = "0.4.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9564fc758e15025b46aa6643b1b77d047d1a56a1aea6e01002ac0c7026876213" -dependencies = [ - "libc", - "winapi", -] - -[[package]] -name = "fs_extra" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "42703706b716c37f96a77aea830392ad231f44c9e9a67872fa5548707e11b11c" - -[[package]] -name = "funty" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fed34cd105917e91daa4da6b3728c47b068749d6a62c59811f06ed2ac71d9da7" - [[package]] name = "futures" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23342abe12aba583913b2e62f22225ff9c950774065e4bfb61a19cd9770fec40" +checksum = "645c6916888f6cb6350d2550b80fb63e734897a8498abe35cfb732b6487804b0" dependencies = [ "futures-channel", "futures-core", @@ -1194,9 +787,9 @@ dependencies = [ [[package]] name = "futures-channel" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "955518d47e09b25bbebc7a18df10b81f0c766eaf4c4f1cccef2fca5f2a4fb5f2" +checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" dependencies = [ "futures-core", "futures-sink", @@ -1204,15 +797,15 @@ dependencies = [ [[package]] name = "futures-core" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4bca583b7e26f571124fe5b7561d49cb2868d79116cfa0eefce955557c6fee8c" +checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" [[package]] name = "futures-executor" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccecee823288125bd88b4d7f565c9e58e41858e47ab72e8ea2d64e93624386e0" +checksum = "a576fc72ae164fca6b9db127eaa9a9dda0d61316034f33a0a0d4eda41f02b01d" dependencies = [ "futures-core", "futures-task", @@ -1221,38 +814,38 @@ dependencies = [ [[package]] name = "futures-io" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4fff74096e71ed47f8e023204cfd0aa1289cd54ae5430a9523be060cdb849964" +checksum = "a44623e20b9681a318efdd71c299b6b222ed6f231972bfe2f224ebad6311f0c1" [[package]] name = "futures-macro" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89ca545a94061b6365f2c7355b4b32bd20df3ff95f02da9329b34ccc3bd6ee72" +checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] name = "futures-sink" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f43be4fe21a13b9781a69afa4985b0f6ee0e1afab2c6f454a8cf30e2b2237b6e" +checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" [[package]] name = "futures-task" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76d3d132be6c0e6aa1534069c705a74a5997a356c0dc2f86a47765e5617c5b65" +checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" [[package]] name = "futures-util" -version = "0.3.28" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26b01e40b772d54cf6c6d721c1d1abd0647a0106a12ecaa1c186273392a69533" +checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" dependencies = [ "futures-channel", "futures-core", @@ -1274,52 +867,53 @@ checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" dependencies = [ "typenum", "version_check", + "zeroize", ] [[package]] name = "getrandom" -version = "0.2.8" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", - "wasi 0.11.0+wasi-snapshot-preview1", + "wasi", ] [[package]] name = "gimli" -version = "0.27.2" +version = "0.29.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad0a93d233ebf96623465aad4046a8d3aa4da22d4f4beba5388838c8a434bbb4" +checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" [[package]] name = "group" -version = "0.8.0" +version = "0.13.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cc11f9f5fbf1943b48ae7c2bf6846e7d827a512d1be4f23af708f5ca5d01dde1" +checksum = "f0f9ef7462f7c099f518d754361858f86d8a07af53ba9af0fe635bbccb151a63" dependencies = [ "ff", - "rand_core 0.5.1", + "rand_core", "subtle", ] [[package]] name = "h2" -version = "0.3.20" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97ec8491ebaf99c8eaa73058b045fe58073cd6be7f596ac993ced0b0a0c01049" +checksum = "fa82e28a107a8cc405f0839610bdc9b15f1e25ec7d696aa5cf173edbcb1486ab" dependencies = [ + "atomic-waker", "bytes", "fnv", "futures-core", "futures-sink", - "futures-util", "http", - "indexmap 1.9.3", + "indexmap 2.2.6", "slab", "tokio", - "tokio-util 0.7.7", + "tokio-util", "tracing", ] @@ -1331,43 +925,9 @@ checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" [[package]] name = "hashbrown" -version = "0.14.0" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c6201b9ff9fd90a5a3bac2e56a830d0caa509576f0e503818ee82c181b3437a" - -[[package]] -name = "headers" -version = "0.3.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3e372db8e5c0d213e0cd0b9be18be2aca3d44cf2fe30a9d46a65581cd454584" -dependencies = [ - "base64 0.13.1", - "bitflags", - "bytes", - "headers-core", - "http", - "httpdate", - "mime", - "sha1", -] - -[[package]] -name = "headers-core" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7f66481bfee273957b1f20485a4ff3362987f85b2c236580d81b4eb7a326429" -dependencies = [ - "http", -] - -[[package]] -name = "heck" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d621efb26863f0e9924c6ac577e8275e5e6b77455db64ffa6c65c904e9e132c" -dependencies = [ - "unicode-segmentation", -] +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" [[package]] name = "heck" @@ -1386,27 +946,15 @@ dependencies = [ [[package]] name = "hermit-abi" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee512640fe35acbfb4bb779db6f0d80704c2cacfa2e39b601ef3e3f47d1ae4c7" -dependencies = [ - "libc", -] - -[[package]] -name = "hermit-abi" -version = "0.3.2" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "443144c8cdadd93ebf52ddb4056d257f5b52c04d3c804e657d19eb73fc33668b" +checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" [[package]] name = "hex" version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" -dependencies = [ - "serde", -] [[package]] name = "hex-buffer-serde" @@ -1418,16 +966,6 @@ dependencies = [ "serde", ] -[[package]] -name = "hex-buffer-serde" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f52012c160668b4494727f3588045aa00429849fcae51de70d68fa98228039" -dependencies = [ - "hex", - "serde", -] - [[package]] name = "hex_fmt" version = "0.3.0" @@ -1436,12 +974,11 @@ checksum = "b07f60793ff0a4d9cef0f18e63b5357e06209987153a64648c972c1e5aff336f" [[package]] name = "hmac" -version = "0.10.1" +version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1441c6b1e930e2817404b5046f1f989899143a12bf92de603b69f4e0aee1e15" +checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e" dependencies = [ - "crypto-mac 0.10.1", - "digest 0.9.0", + "digest 0.10.7", ] [[package]] @@ -1457,9 +994,9 @@ dependencies = [ [[package]] name = "http" -version = "0.2.9" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd6effc99afb63425aff9b05836f029929e345a6148a14b7ecd5ab67af944482" +checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" dependencies = [ "bytes", "fnv", @@ -1468,12 +1005,24 @@ dependencies = [ [[package]] name = "http-body" -version = "0.4.5" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f38f16d184e36f2408a55281cd658ecbd3ca05cce6d6510a176eca393e26d1" +checksum = "1cac85db508abc24a2e48553ba12a996e87244a0395ce011e62b37158745d643" dependencies = [ "bytes", "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0475f8b2ac86659c21b64320d5d653f9efe42acd2a4e560073ec61a155a34f1d" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", "pin-project-lite", ] @@ -1483,12 +1032,6 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d897f394bad6a705d5f4104762e116a75639e470d80901eed05a860a95cb1904" -[[package]] -name = "httpdate" -version = "1.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" - [[package]] name = "humantime" version = "2.1.0" @@ -1497,70 +1040,65 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" [[package]] name = "hyper" -version = "0.14.27" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ffb1cfd654a8219eaef89881fdb3bb3b1cdc5fa75ded05d6933b2b382e395468" +checksum = "fe575dd17d0862a9a33781c8c4696a55c320909004a67a00fb286ba8b1bc496d" dependencies = [ "bytes", "futures-channel", - "futures-core", "futures-util", "h2", "http", "http-body", "httparse", - "httpdate", "itoa", "pin-project-lite", - "socket2", + "smallvec", "tokio", - "tower-service", - "tracing", "want", ] [[package]] name = "hyper-tls" -version = "0.5.0" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6183ddfa99b85da61a140bea0efc93fdf56ceaa041b37d553518030827f9905" +checksum = "70206fc6890eaca9fde8a0bf71caa2ddfc9fe045ac9e5c70df101a7dbde866e0" dependencies = [ "bytes", + "http-body-util", "hyper", + "hyper-util", "native-tls", "tokio", "tokio-native-tls", + "tower-service", ] [[package]] -name = "iana-time-zone" -version = "0.1.56" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0722cd7114b7de04316e7ea5456a0bbb20e4adb46fd27a3697adb812cff0f37c" -dependencies = [ - "android_system_properties", - "core-foundation-sys", - "iana-time-zone-haiku", - "js-sys", - "wasm-bindgen", - "windows", -] - -[[package]] -name = "iana-time-zone-haiku" -version = "0.1.1" +name = "hyper-util" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0703ae284fc167426161c2e3f1da3ea71d94b21bedbcc9494e92b28e334e3dca" +checksum = "7b875924a60b96e5d7b9ae7b066540b1dd1cbd90d1828f54c92e02a283351c56" dependencies = [ - "cxx", - "cxx-build", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "hyper", + "pin-project-lite", + "socket2", + "tokio", + "tower", + "tower-service", + "tracing", ] [[package]] name = "idna" -version = "0.3.0" +version = "0.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e14ddfc70884202db2244c223200c204c2bda1bc6e0998d11b5e024d657209e6" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" dependencies = [ "unicode-bidi", "unicode-normalization", @@ -1579,39 +1117,19 @@ dependencies = [ [[package]] name = "indexmap" -version = "2.0.0" +version = "2.2.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5477fe2230a79769d8dc68e0eabf5437907c0457a5614a9e8dddb67f65eb65d" +checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26" dependencies = [ "equivalent", - "hashbrown 0.14.0", -] - -[[package]] -name = "instant" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a5bbe824c507c5da5956355e86a746d82e0e1464f65d862cc5e71da70e94b2c" -dependencies = [ - "cfg-if 1.0.0", -] - -[[package]] -name = "io-lifetimes" -version = "1.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c66c74d2ae7e79a5a8f7ac924adbe38ee42a859c6539ad869eb51f0b52dc220" -dependencies = [ - "hermit-abi 0.3.2", - "libc", - "windows-sys 0.48.0", + "hashbrown 0.14.5", ] [[package]] name = "ipnet" -version = "2.7.2" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12b6ee2129af8d4fb011108c73d99a1b83a85977f23b82460c0ae2e25bb4b57f" +checksum = "8f518f335dce6725a761382244631d86cf0ccb2863413590b31338feb467f9c3" [[package]] name = "itertools" @@ -1624,67 +1142,35 @@ dependencies = [ [[package]] name = "itoa" -version = "1.0.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "453ad9f582a441959e5f0d088b02ce04cfe8d51a8eaf077f12ac6d3e94164ca6" - -[[package]] -name = "jemalloc-ctl" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c502a5ff9dd2924f1ed32ba96e3b65735d837b4bfd978d3161b1702e66aca4b7" -dependencies = [ - "jemalloc-sys", - "libc", - "paste 0.1.18", -] - -[[package]] -name = "jemalloc-sys" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d3b9f3f5c9b31aa0f5ed3260385ac205db665baa41d49bb8338008ae94ede45" -dependencies = [ - "cc", - "fs_extra", - "libc", -] - -[[package]] -name = "jemallocator" -version = "0.3.2" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ae63fcfc45e99ab3d1b29a46782ad679e98436c3169d15a167a1108a724b69" -dependencies = [ - "jemalloc-sys", - "libc", -] +checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.26" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "936cfd212a0155903bcbc060e316fb6cc7cbf2e1907329391ebadc1fe0ce77c2" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] [[package]] name = "js-sys" -version = "0.3.61" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "445dde2150c55e483f3d8416706b97ec8e8237c307e5b7b4b8dd15e6af2a0730" +checksum = "29c15563dc2726973df627357ce0c9ddddbea194836909d655df6a75d2cf296d" dependencies = [ "wasm-bindgen", ] [[package]] name = "k256" -version = "0.7.3" +version = "0.13.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4476a0808212a9e81ce802eb1a0cfc60e73aea296553bacc0fac7e1268bc572a" +checksum = "956ff9b67e26e1a6a866cb758f12c6f8746208489e3e4a4b5580802f2f0a587b" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "ecdsa", "elliptic-curve", "sha2", @@ -1696,32 +1182,17 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "lazycell" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55" - [[package]] name = "libc" -version = "0.2.141" +version = "0.2.155" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3304a64d199bb964be99741b7a14d26972741915b3649639149b2479bb46f4b5" +checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c" [[package]] name = "libm" -version = "0.2.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "348108ab3fba42ec82ff6e9564fc4ca0247bdccdc68dd8af9764bbc79c3c8ffb" - -[[package]] -name = "link-cplusplus" -version = "1.0.8" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecd207c9c713c34f95a097a5b029ac2ce6010530c7b49d7fea24d977dede04f5" -dependencies = [ - "cc", -] +checksum = "4ec2a862134d2a7d32d7983ddcdd1c4923530833c9f2ea1a44fc5fa473989058" [[package]] name = "linked-hash-map" @@ -1731,26 +1202,27 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.3.1" +version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d59d8c75012853d2e872fb56bc8a2e53718e2cafe1a4c823143141c6d90c322f" +checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" [[package]] -name = "lmdb" -version = "0.8.0" +name = "lmdb-rkv" +version = "0.14.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b0908efb5d6496aa977d96f91413da2635a902e5e31dbef0bfb88986c248539" +checksum = "447a296f7aca299cfbb50f4e4f3d49451549af655fb7215d7f8c0c3d64bad42b" dependencies = [ - "bitflags", + "bitflags 1.3.2", + "byteorder", "libc", - "lmdb-sys", + "lmdb-rkv-sys", ] [[package]] -name = "lmdb-sys" -version = "0.8.0" +name = "lmdb-rkv-sys" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5b392838cfe8858e86fac37cf97a0e8c55cc60ba0a18365cadc33092f128ce9" +checksum = "61b9ce6b3be08acefa3003c57b7565377432a89ec24476bbe72e11d101f852fe" dependencies = [ "cc", "libc", @@ -1759,9 +1231,9 @@ dependencies = [ [[package]] name = "lock_api" -version = "0.4.9" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "435011366fe56583b16cf956f9df0095b405b82d76425bc8981c0e22e60ec4df" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1769,65 +1241,31 @@ dependencies = [ [[package]] name = "log" -version = "0.4.17" +version = "0.4.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abb12e687cfb44aa40f41fc3978ef76448f9b6038cad6aef4259d3c095a2382e" +checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c" dependencies = [ - "cfg-if 1.0.0", "serde", "value-bag", ] -[[package]] -name = "mach" -version = "0.3.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b823e83b2affd8f40a9ee8c29dbc56404c1e34cd2710921f2801e2cf29527afa" -dependencies = [ - "libc", -] - [[package]] name = "match_cfg" version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" -[[package]] -name = "matchers" -version = "0.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f099785f7595cc4b4553a174ce30dd7589ef93391ff414dbb67f62392b9e0ce1" -dependencies = [ - "regex-automata", -] - -[[package]] -name = "maybe-uninit" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60302e4db3a61da70c0cb7991976248362f30319e88850c487b9b95bbf059e00" - [[package]] name = "memchr" -version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" - -[[package]] -name = "memoffset" -version = "0.5.6" +version = "2.7.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "043175f069eda7b85febe4a74abbaeff828d9f8b448515d3151a14a3542811aa" -dependencies = [ - "autocfg", -] +checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d" [[package]] name = "memory_units" -version = "0.3.0" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "71d96e3f3c0b6325d8ccd83c33b28acb183edcb6c67938ba104ec546854b0882" +checksum = "8452105ba047068f40ff7093dd1d9da90898e63dd61736462e9cdda6a90ad3c3" [[package]] name = "mime" @@ -1835,58 +1273,32 @@ version = "0.3.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6877bb514081ee2a7ff5ef9de3281f14a4dd4bceac4c09388074a6b5df8a139a" -[[package]] -name = "mime_guess" -version = "2.0.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4192263c238a5f0d0c6bfd21f336a313a4ce1c450542449ca191bb657b4642ef" -dependencies = [ - "mime", - "unicase", -] - [[package]] name = "miniz_oxide" -version = "0.6.2" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b275950c28b37e794e8c55d88aeb5e139d0ce23fdbbeda68f8d7174abdf9e8fa" +checksum = "87dfd01fe195c66b572b37921ad8803d010623c0aca821bea2302239d155cdae" dependencies = [ "adler", ] [[package]] name = "mio" -version = "0.8.6" +version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b9d9a46eff5b4ff64b45a9e316a6d1e0bc719ef429cbec4dc630684212bfdf9" +checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c" dependencies = [ "libc", - "log", - "wasi 0.11.0+wasi-snapshot-preview1", - "windows-sys 0.45.0", -] - -[[package]] -name = "multiparty" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ed1ec6589a6d4a1e0b33b4c0a3f6ee96dfba88ebdb3da51403fd7cf0a24a4b04" -dependencies = [ - "bytes", - "futures-core", - "httparse", - "memchr", - "pin-project-lite", - "try-lock", + "wasi", + "windows-sys 0.48.0", ] [[package]] name = "native-tls" -version = "0.2.11" +version = "0.2.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "07226173c32f2926027b63cce4bcd8076c3552846cbe7925f3aaffeac0a3b92e" +checksum = "a8614eb2c83d59d1c8cc974dd3f920198647674a0a035e1af1fa58707e317466" dependencies = [ - "lazy_static", "libc", "log", "openssl", @@ -1900,48 +1312,42 @@ dependencies = [ [[package]] name = "num" -version = "0.4.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43db66d1170d347f9a065114077f7dccb00c1b9478c89384490a3425279a4606" +checksum = "35bd024e8b2ff75562e5f34e7f4905839deb4b22955ef5e73d2fea1b9813cb23" dependencies = [ - "num-bigint 0.4.3", + "num-bigint", "num-complex", "num-integer", "num-iter", - "num-rational 0.4.1", + "num-rational", "num-traits", ] [[package]] name = "num-bigint" -version = "0.2.6" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "090c7f9998ee0ff65aa5b723e4009f7b217707f1fb5ea551329cc4d6231fb304" +checksum = "c165a9ab64cf766f73521c0dd2cfdff64f488b8f0b3e621face3462d3db536d7" dependencies = [ - "autocfg", "num-integer", "num-traits", ] [[package]] -name = "num-bigint" -version = "0.4.3" +name = "num-complex" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +checksum = "73f88a1307638156682bada9d7604135552957b7818057dcef22705b4d509495" dependencies = [ - "autocfg", - "num-integer", "num-traits", ] [[package]] -name = "num-complex" -version = "0.4.3" +name = "num-conv" +version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02e0d21255c828d6f128a1e41534206671e8c3ea0c62f32291e808dc82cff17d" -dependencies = [ - "num-traits", -] +checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9" [[package]] name = "num-derive" @@ -1949,52 +1355,38 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", + "proc-macro2 1.0.84", + "quote 1.0.36", "syn 1.0.109", ] [[package]] name = "num-integer" -version = "0.1.45" +version = "0.1.46" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +checksum = "7969661fd2958a5cb096e56c8e1ad0444ac2bbcd0061bd28660485a44879858f" dependencies = [ - "autocfg", "num-traits", ] [[package]] name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.2.4" +version = "0.1.45" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c000134b5dbf44adc5cb772486d335293351644b801551abe8f75c84cfa4aef" +checksum = "1429034a0490724d0075ebb2bc9e875d6503c3cf69e235a8941aa757d83ef5bf" dependencies = [ "autocfg", - "num-bigint 0.2.6", "num-integer", "num-traits", ] [[package]] name = "num-rational" -version = "0.4.1" +version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0638a1c9d0a3c0914158145bc76cff373a75a627e6ecbfb71cbe6f453a5a19b0" +checksum = "f83d14da390562dca69fc84082e73e548e1ad308d24accdedd2720017cb37824" dependencies = [ - "autocfg", - "num-bigint 0.4.3", + "num-bigint", "num-integer", "num-traits", "serde", @@ -2002,9 +1394,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.15" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", "libm", @@ -2012,52 +1404,52 @@ dependencies = [ [[package]] name = "num_cpus" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fac9e2da13b5eb447a6ce3d392f23a29d8694bff781bf03a16cd9ac8697593b" +checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43" dependencies = [ - "hermit-abi 0.2.6", + "hermit-abi 0.3.9", "libc", ] [[package]] name = "num_threads" -version = "0.1.6" +version = "0.1.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2819ce041d2ee131036f4fc9d6ae7ae125a3a40e97ba64d04fe799ad9dabbb44" +checksum = "5c7398b9c8b70908f6371f47ed36737907c87c52af34c268fed0bf0ceb92ead9" dependencies = [ "libc", ] [[package]] name = "object" -version = "0.30.3" +version = "0.35.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea86265d3d3dcb6a27fc51bd29a4bf387fae9d2986b823079d4986af253eb439" +checksum = "b8ec7ab813848ba4522158d5517a6093db1ded27575b070f4177b8d12b41db5e" dependencies = [ "memchr", ] [[package]] name = "once_cell" -version = "1.17.1" +version = "1.19.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7e5500299e16ebb147ae15a00a942af264cf3688f47923b8fc2cd5858f23ad3" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" [[package]] name = "opaque-debug" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "624a8340c38c1b80fd549087862da4ba43e08858af025b236e509b6649fc13d5" +checksum = "c08d65885ee38876c4f86fa503fb49d7b507c2b62552df7c70b2fce627e06381" [[package]] name = "openssl" -version = "0.10.49" +version = "0.10.64" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d2f106ab837a24e03672c59b1239669a0596406ff657c3c0835b6b7f0f35a33" +checksum = "95a0481286a310808298130d22dd1fef0fa571e05a8f44ec801801e84b216b1f" dependencies = [ - "bitflags", - "cfg-if 1.0.0", + "bitflags 2.5.0", + "cfg-if", "foreign-types", "libc", "once_cell", @@ -2071,9 +1463,9 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] @@ -2084,9 +1476,9 @@ checksum = "ff011a302c396a5197692431fc1948019154afc178baf7d8e37367442a4601cf" [[package]] name = "openssl-sys" -version = "0.9.84" +version = "0.9.102" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3a20eace9dc2d82904039cb76dcf50fb1a0bba071cfd1629720b5d6f1ddba0fa" +checksum = "c597637d56fbc83893a35eb0dd04b2b8e7a50c91e64e9493e398b5df4fb45fa2" dependencies = [ "cc", "libc", @@ -2096,87 +1488,31 @@ dependencies = [ [[package]] name = "os_str_bytes" -version = "6.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d5d9eb14b174ee9aa2ef96dc2b94637a2d4b6e7cb873c7e171f0c20c6cf3eac" - -[[package]] -name = "parity-wasm" -version = "0.42.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "be5e13c266502aadf83426d87d81a0f5d1ef45b8027f5a471c360abfe4bfae92" - -[[package]] -name = "parking_lot" -version = "0.11.2" +version = "6.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" -dependencies = [ - "instant", - "lock_api", - "parking_lot_core 0.8.6", -] +checksum = "e2355d85b9a3786f481747ced0e0ff2ba35213a1f9bd406ed906554d7af805a1" [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" dependencies = [ "lock_api", - "parking_lot_core 0.9.7", -] - -[[package]] -name = "parking_lot_core" -version = "0.8.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "60a2cfe6f0ad2bfc16aefa463b497d5c7a5ecd44a23efa72aa342d90177356dc" -dependencies = [ - "cfg-if 1.0.0", - "instant", - "libc", - "redox_syscall 0.2.16", - "smallvec", - "winapi", + "parking_lot_core", ] [[package]] name = "parking_lot_core" -version = "0.9.7" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9069cbb9f99e3a5083476ccb29ceb1de18b9118cafa53e90c9551235de2b9521" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "libc", - "redox_syscall 0.2.16", + "redox_syscall 0.5.1", "smallvec", - "windows-sys 0.45.0", -] - -[[package]] -name = "paste" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45ca20c77d80be666aef2b45486da86238fabe33e38306bd3118fe4af33fa880" -dependencies = [ - "paste-impl", - "proc-macro-hack", -] - -[[package]] -name = "paste" -version = "1.0.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f746c4065a8fa3fe23974dd82f15431cc8d40779821001404d10d2e79ca7d79" - -[[package]] -name = "paste-impl" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d95a7db200b97ef370c8e6de0088252f7e0dfff7d047a28528e47456c0fc98b6" -dependencies = [ - "proc-macro-hack", + "windows-targets 0.52.5", ] [[package]] @@ -2192,35 +1528,35 @@ dependencies = [ [[package]] name = "percent-encoding" -version = "2.2.0" +version = "2.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "478c572c3d73181ff3c2539045f6eb99e5491218eae919370993b890cdbdd98e" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" [[package]] name = "pin-project" -version = "1.0.12" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ad29a609b6bcd67fee905812e544992d216af9d755757c05ed2d0e15a74c6ecc" +checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" dependencies = [ "pin-project-internal", ] [[package]] name = "pin-project-internal" -version = "1.0.12" +version = "1.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "069bdb1e05adc7a8990dce9cc75370895fbe4e3d58b9b73bf1aee56359344a55" +checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] name = "pin-project-lite" -version = "0.2.9" +version = "0.2.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0a7ae3ac2f1173085d398531c705756c94a4c56843785df85a60c1a0afac116" +checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" [[package]] name = "pin-utils" @@ -2230,54 +1566,37 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "pkcs8" -version = "0.3.3" +version = "0.10.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4839a901843f3942576e65857f0ebf2e190ef7024d3c62a94099ba3f819ad1d" +checksum = "f950b2377845cebe5cf8b5165cb3cc1a5e0fa5cfa3e1f7f55707d8fd82e0a7b7" dependencies = [ "der", + "spki", ] [[package]] name = "pkg-config" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" - -[[package]] -name = "ppv-lite86" -version = "0.2.17" +version = "0.3.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" +checksum = "d231b230927b5e4ad203db57bbcbee2802f6bce620b1e4a9024a07d94e2907ec" [[package]] -name = "proc-macro-error" -version = "1.0.4" +name = "platforms" +version = "3.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" -dependencies = [ - "proc-macro-error-attr", - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", - "version_check", -] +checksum = "db23d408679286588f4d4644f965003d056e3dd5abcaaa938116871d7ce2fee7" [[package]] -name = "proc-macro-error-attr" -version = "1.0.4" +name = "powerfmt" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" -dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "version_check", -] +checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391" [[package]] -name = "proc-macro-hack" -version = "0.5.20+deprecated" +name = "ppv-lite86" +version = "0.2.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dc375e1527247fe1a97d8b7156678dfe7c1af2fc075c9a4db3690ecd2a148068" +checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" [[package]] name = "proc-macro2" @@ -2290,42 +1609,26 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.63" +version = "1.0.84" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b368fba921b0dce7e60f5e04ec15e565b3303972b42bcfde1d0713b881959eb" +checksum = "ec96c6a92621310b51366f1e28d05ef11489516e93be030060e5fc12024a49d6" dependencies = [ "unicode-ident", ] -[[package]] -name = "prometheus" -version = "0.12.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5986aa8d62380092d2f50f8b1cdba9cb9b6731ffd4b25b51fd126b6c3e05b99c" -dependencies = [ - "cfg-if 1.0.0", - "fnv", - "lazy_static", - "memchr", - "parking_lot 0.11.2", - "protobuf", - "thiserror", -] - [[package]] name = "proptest" -version = "1.1.0" +version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29f1b898011ce9595050a68e60f90bad083ff2987a695a42357134c8381fba70" +checksum = "31b476131c3c86cb68032fdc5cb6d5a1045e3e42d96b69fa599fd77701e1f5bf" dependencies = [ "bit-set", - "bitflags", - "byteorder", + "bit-vec", + "bitflags 2.5.0", "lazy_static", "num-traits", - "quick-error 2.0.1", - "rand 0.8.5", - "rand_chacha 0.3.1", + "rand", + "rand_chacha", "rand_xorshift", "regex-syntax", "rusty-fork", @@ -2339,30 +1642,9 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90b46295382dc76166cb7cf2bb4a97952464e4b7ed5a43e6cd34e1fec3349ddc" dependencies = [ - "proc-macro2 0.4.30", - "quote 0.6.13", - "syn 0.15.44", -] - -[[package]] -name = "protobuf" -version = "2.28.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "106dd99e98437432fed6519dedecfade6a06a73bb7b2a1e019fdd2bee5778d94" - -[[package]] -name = "quanta" -version = "0.7.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e76a3afdefd0ce2c0363bf3146271e947782240ea617885dd64e56c4de9fb3c9" -dependencies = [ - "atomic-shim", - "ctor", - "libc", - "mach", - "once_cell", - "raw-cpuid", - "winapi", + "proc-macro2 0.4.30", + "quote 0.6.13", + "syn 0.15.44", ] [[package]] @@ -2371,12 +1653,6 @@ version = "1.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a1d01941d82fa2ab50be1e79e6714289dd7cde78eba4c074bc5a4374f650dfe0" -[[package]] -name = "quick-error" -version = "2.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a993555f31e5a609f617c12db6250dedcac1b0a85076912c436e6fc9b2c8e6a3" - [[package]] name = "quote" version = "0.6.13" @@ -2388,28 +1664,11 @@ dependencies = [ [[package]] name = "quote" -version = "1.0.29" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "573015e8ab27661678357f27dc26460738fd2b6c86e46f386fde94cb5d913105" -dependencies = [ - "proc-macro2 1.0.63", -] - -[[package]] -name = "radium" -version = "0.3.0" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" - -[[package]] -name = "rand" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc", + "proc-macro2 1.0.84", ] [[package]] @@ -2419,18 +1678,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", - "rand_chacha 0.3.1", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.2.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" -dependencies = [ - "ppv-lite86", - "rand_core 0.5.1", + "rand_chacha", + "rand_core", ] [[package]] @@ -2440,15 +1689,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90bde5296fc891b0cef12a6d03ddccc162ce7b2aff54160af9338f8d40df6d19" - [[package]] name = "rand_core" version = "0.6.4" @@ -2458,22 +1701,13 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" -dependencies = [ - "rand_core 0.5.1", -] - [[package]] name = "rand_pcg" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "59cad018caf63deb318e5a4586d99a24424a364f40f1e5778c29aca23f4fc73e" dependencies = [ - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -2482,69 +1716,63 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d25bf25ec5ae4a3f1b92f929810509a2f53d7dca2f50b794ff57e3face536c8f" dependencies = [ - "rand_core 0.6.4", -] - -[[package]] -name = "raw-cpuid" -version = "9.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1733f6f80c9c24268736a501cd00d41a9849b4faa7a9f9334c096e5d10553206" -dependencies = [ - "bitflags", + "rand_core", ] [[package]] name = "redox_syscall" -version = "0.2.16" +version = "0.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a" +checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" dependencies = [ - "bitflags", + "bitflags 1.3.2", ] [[package]] name = "redox_syscall" -version = "0.3.5" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "567664f262709473930a4bf9e51bf2ebf3348f2e748ccc50dea20646858f8f29" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags", + "bitflags 2.5.0", ] [[package]] name = "regex" -version = "1.7.3" +version = "1.10.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8b1f693b24f6ac912f4893ef08244d70b6067480d2f1a46e950c9691e6749d1d" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" dependencies = [ "aho-corasick", "memchr", + "regex-automata", "regex-syntax", ] [[package]] name = "regex-automata" -version = "0.1.10" +version = "0.4.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" +checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea" dependencies = [ + "aho-corasick", + "memchr", "regex-syntax", ] [[package]] name = "regex-syntax" -version = "0.6.29" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f162c6dd7b008981e4d40210aca20b4bd0f9b60ca9271061b07f78537722f2e1" +checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56" [[package]] name = "reqwest" -version = "0.11.16" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27b71749df584b7f4cac2c426c127a7c785a5106cc98f7a8feb044115f0fa254" +checksum = "566cafdd92868e0939d3fb961bd0dc25fcfaaed179291093b3d43e6b3150ea10" dependencies = [ - "base64 0.21.0", + "base64 0.22.1", "bytes", "encoding_rs", "futures-core", @@ -2552,8 +1780,10 @@ dependencies = [ "h2", "http", "http-body", + "http-body-util", "hyper", "hyper-tls", + "hyper-util", "ipnet", "js-sys", "log", @@ -2562,12 +1792,15 @@ dependencies = [ "once_cell", "percent-encoding", "pin-project-lite", + "rustls-pemfile", "serde", "serde_json", "serde_urlencoded", + "sync_wrapper", + "system-configuration", "tokio", "tokio-native-tls", - "tokio-util 0.7.7", + "tokio-util", "tower-service", "url", "wasm-bindgen", @@ -2578,41 +1811,29 @@ dependencies = [ ] [[package]] -name = "ringbuf" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f65af18d50f789e74aaf23bbb3f65dcd22a3cb6e029b5bced149f6bd57c5c2a2" -dependencies = [ - "cache-padded", -] - -[[package]] -name = "rmp" -version = "0.8.11" +name = "rfc6979" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44519172358fd6d58656c86ab8e7fbc9e1490c3e8f14d35ed78ca0dd07403c9f" +checksum = "f8dd2a808d456c4a54e300a23e9f5a67e122c3024119acbfd73e3bf664491cb2" dependencies = [ - "byteorder", - "num-traits", - "paste 1.0.12", + "hmac", + "subtle", ] [[package]] -name = "rmp-serde" -version = "0.14.4" +name = "ringbuf" +version = "0.2.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ce7d70c926fe472aed493b902010bccc17fa9f7284145cb8772fd22fdb052d8" +checksum = "f65af18d50f789e74aaf23bbb3f65dcd22a3cb6e029b5bced149f6bd57c5c2a2" dependencies = [ - "byteorder", - "rmp", - "serde", + "cache-padded", ] [[package]] name = "rustc-demangle" -version = "0.1.22" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d4a36c42d1873f9a77c53bde094f9664d9891bc604a45b4798fd2c389ed12e5b" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc_version" @@ -2625,32 +1846,38 @@ dependencies = [ [[package]] name = "rustix" -version = "0.37.7" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aae838e49b3d63e9274e1c01833cc8139d3fec468c3b84688c628f44b1ae11d" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ - "bitflags", + "bitflags 2.5.0", "errno", - "io-lifetimes", "libc", "linux-raw-sys", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] name = "rustls-pemfile" -version = "1.0.2" +version = "2.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d194b56d58803a43635bdc398cd17e383d6f71f9182b9a192c127ca42494a59b" +checksum = "29993a25686778eb88d4189742cd713c9bce943bc54251a33509dc63cbacf73d" dependencies = [ - "base64 0.21.0", + "base64 0.22.1", + "rustls-pki-types", ] +[[package]] +name = "rustls-pki-types" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "976295e77ce332211c0d24d92c0e83e50f5c5f046d11082cea19f3df13a3562d" + [[package]] name = "rustversion" -version = "1.0.12" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f3208ce4d8448b3f3e7d168a73f5e0c43a61e32930de3bceeccedb388b6bf06" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "rusty-fork" @@ -2659,31 +1886,31 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cb3dcc6e454c328bb824492db107ab7c0ae8fcffe4ad210136ef014458c1bc4f" dependencies = [ "fnv", - "quick-error 1.2.3", + "quick-error", "tempfile", "wait-timeout", ] [[package]] name = "ryu" -version = "1.0.13" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "schannel" -version = "0.1.21" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "713cfb06c7059f3588fb8044c0fad1d09e3c01d225e25b9220dbfdcf16dbb1b3" +checksum = "fbc91545643bcf3a0bbb6569265615222618bdf33ce4ffbbd13c4bbd4c093534" dependencies = [ - "windows-sys 0.42.0", + "windows-sys 0.52.0", ] [[package]] name = "schemars" -version = "0.8.5" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b82485a532ef0af18878ad4281f73e58161cdba1db7918176e9294f0ca5498a5" +checksum = "09c024468a378b7e36765cd36702b7a90cc3cba11654f6685c8f233408e89e92" dependencies = [ "dyn-clone", "indexmap 1.9.3", @@ -2694,41 +1921,42 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.5" +version = "0.8.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "791c2c848cff1abaeae34fef7e70da5f93171d9eea81ce0fe969a1df627a61a8" +checksum = "b1eee588578aff73f856ab961cd2f79e36bc45d7ded33a7562adba4667aecc0e" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", + "proc-macro2 1.0.84", + "quote 1.0.36", "serde_derive_internals", - "syn 1.0.109", + "syn 2.0.66", ] -[[package]] -name = "scoped-tls" -version = "1.0.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e1cf6437eb19a8f4a6cc0f7dca544973b0b78843adbfeb3683d1a94a0024a294" - [[package]] name = "scopeguard" -version = "1.1.0" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" [[package]] -name = "scratch" -version = "1.0.5" +name = "sec1" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1792db035ce95be60c3f8853017b3999209281c24e2ba5bc8e59bf97a0c590c1" +checksum = "d3e97a565f76233a6003f9f5c54be1d9c5bdfa3eccfb189469f11ec4901c47dc" +dependencies = [ + "base16ct", + "der", + "generic-array", + "subtle", + "zeroize", +] [[package]] name = "security-framework" -version = "2.8.2" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a332be01508d814fed64bf28f798a146d73792121129962fdf335bb3c49a4254" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -2737,9 +1965,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.8.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31c9bb296072e961fcbd8853511dd39c2d8be2deb1e17c6860b1d30732b323b4" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -2747,90 +1975,80 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.17" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bebd363326d05ec3e2f532ab7660680f3b02130d780c299bca73469d521bc0ed" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" dependencies = [ "serde", ] [[package]] name = "serde" -version = "1.0.159" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c04e8343c3daeec41f58990b9d77068df31209f2af111e059e9fe9646693065" +checksum = "7253ab4de971e72fb7be983802300c30b5a7f0c2e56fab8abfc6a214307c0094" dependencies = [ "serde_derive", ] [[package]] -name = "serde-big-array" -version = "0.3.3" +name = "serde-map-to-array" +version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd31f59f6fe2b0c055371bb2f16d7f0aa7d8881676c04a55b1596d1a17cd10a4" +checksum = "c14b52efc56c711e0dbae3f26e0cc233f5dac336c1bf0b07e1b7dc2dca3b2cc7" dependencies = [ + "schemars", "serde", ] [[package]] name = "serde_bytes" -version = "0.11.9" +version = "0.11.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "416bda436f9aab92e02c8e10d49a15ddd339cea90b6e340fe51ed97abb548294" +checksum = "8b8497c313fd43ab992087548117643f6fcd935cbf36f176ffda0aacf9591734" dependencies = [ "serde", ] [[package]] name = "serde_derive" -version = "1.0.159" +version = "1.0.203" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c614d17805b093df4b147b51339e7e44bf05ef59fba1e45d83500bcfb4d8585" +checksum = "500cbc0ebeb6f46627f50f3f5811ccf6bf00643be300b4c3eabc0ef55dc5b5ba" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] name = "serde_derive_internals" -version = "0.25.0" +version = "0.29.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dbab34ca63057a1f15280bdf3c39f2b1eb1b54c17e98360e511637aef7418c6" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] name = "serde_json" -version = "1.0.95" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d721eca97ac802aa7777b701877c8004d950fc142651367300d21c1cc0194744" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ - "indexmap 1.9.3", + "indexmap 2.2.6", "itoa", "ryu", "serde", ] -[[package]] -name = "serde_repr" -version = "0.1.12" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcec881020c684085e55a25f7fd888954d56609ef363479dc5a1305eb0d40cab" -dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", -] - [[package]] name = "serde_spanned" -version = "0.6.3" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96426c9936fd7a0124915f9185ea1d20aa9445cc9821142f0a73bc9207a2e186" +checksum = "79e674e01f999af37c49f70a6ede167a8a60b2503e56c5599532a65baa5969a0" dependencies = [ "serde", ] @@ -2847,118 +2065,87 @@ dependencies = [ "serde", ] -[[package]] -name = "sha1" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f04293dc80c3993519f2d7f6f511707ee7094fe0c6d3406feb330cdb3540eba3" -dependencies = [ - "cfg-if 1.0.0", - "cpufeatures", - "digest 0.10.6", -] - [[package]] name = "sha2" -version = "0.9.9" +version = "0.10.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4d58a1e1bf39749807d89cf2d98ac2dfa0ff1cb3faa38fbb64dd88ac8013d800" +checksum = "793db75ad2bcafc3ffa7c68b215fee268f537982cd901d132f89c6343f3a3dc8" dependencies = [ - "block-buffer 0.9.0", - "cfg-if 1.0.0", + "cfg-if", "cpufeatures", - "digest 0.9.0", - "opaque-debug", -] - -[[package]] -name = "sharded-slab" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "900fba806f70c630b0a382d0d825e17a0f19fcd059a2ade1ff237bcddf446b31" -dependencies = [ - "lazy_static", -] - -[[package]] -name = "signal-hook" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "732768f1176d21d09e076c23a93123d40bba92d50c4058da34d45c8de8e682b9" -dependencies = [ - "libc", - "signal-hook-registry", + "digest 0.10.7", ] [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] [[package]] name = "signature" -version = "1.2.2" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "29f060a7d147e33490ec10da418795238fd7545bba241504d6b31a409f2e6210" +checksum = "77549399552de45a898a580c1b41d445bf730df867cc44e6c0233bbc4b8329de" dependencies = [ - "digest 0.9.0", - "rand_core 0.5.1", + "digest 0.10.7", + "rand_core", ] [[package]] name = "simplelog" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acee08041c5de3d5048c8b3f6f13fafb3026b24ba43c6a695a0c76179b844369" +checksum = "16257adbfaef1ee58b1363bdc0664c9b8e1e30aed86049635fb5f147d065a9c0" dependencies = [ "log", "termcolor", - "time 0.3.20", + "time", ] [[package]] name = "slab" -version = "0.4.8" +version = "0.4.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6528351c9bc8ab22353f9d776db39a20288e8d6c37ef8cfe3317cf875eecfc2d" +checksum = "8f92a496fb766b417c996b9c5e57daf2f7ad3b0bebe1ccfca4856390e3d3bb67" dependencies = [ "autocfg", ] [[package]] name = "smallvec" -version = "1.10.0" +version = "1.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a507befe795404456341dfab10cef66ead4c041f62b8b11bbb92bffe5d0953e0" -dependencies = [ - "serde", -] +checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" [[package]] name = "socket2" -version = "0.4.9" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64a4a911eed85daf18834cfaa86a79b7d266ff93ff5ba14005426219480ed662" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", - "winapi", + "windows-sys 0.52.0", ] [[package]] -name = "static_assertions" -version = "1.1.0" +name = "spki" +version = "0.7.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +checksum = "d91ed6c858b01f942cd56b37a94b3e0a1798290327d1236e4d9cf4eaca44d29d" +dependencies = [ + "base64ct", + "der", +] [[package]] -name = "strsim" -version = "0.8.0" +name = "static_assertions" +version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" [[package]] name = "strsim" @@ -2966,30 +2153,6 @@ version = "0.10.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623" -[[package]] -name = "structopt" -version = "0.3.26" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c6b5c64445ba8094a6ab0c3cd2ad323e07171012d9c98b0b15651daf1787a10" -dependencies = [ - "clap 2.34.0", - "lazy_static", - "structopt-derive", -] - -[[package]] -name = "structopt-derive" -version = "0.4.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcb5ae327f9cc13b68763b5749770cb9e048a99bd9dfdfa58d0cf05d5f64afe0" -dependencies = [ - "heck 0.3.3", - "proc-macro-error", - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", -] - [[package]] name = "strum" version = "0.24.1" @@ -3005,18 +2168,18 @@ version = "0.24.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1e385be0d24f186b4ce2f9982191e7101bb737312ad61c1f2f984f34bcf85d59" dependencies = [ - "heck 0.4.1", - "proc-macro2 1.0.63", - "quote 1.0.29", + "heck", + "proc-macro2 1.0.84", + "quote 1.0.36", "rustversion", "syn 1.0.109", ] [[package]] name = "subtle" -version = "2.4.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601" +checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" [[package]] name = "syn" @@ -3035,37 +2198,54 @@ version = "1.0.109" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", + "proc-macro2 1.0.84", + "quote 1.0.36", "unicode-ident", ] [[package]] name = "syn" -version = "2.0.23" +version = "2.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59fb7d6d8281a51045d62b8eb3a7d1ce347b76f312af50cd3dc0af39c87c1737" +checksum = "c42f3f41a2de00b01c0aaad383c5a45241efc8b2d1eda5661812fda5f3cdcff5" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", + "proc-macro2 1.0.84", + "quote 1.0.36", "unicode-ident", ] [[package]] -name = "sys-info" -version = "0.8.0" +name = "sync_wrapper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" + +[[package]] +name = "system-configuration" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3f3e7ba888a12ddcf0084e36ae4609b055845f38022d1946b67356fbc27d5795" +checksum = "ba3a3adc5c275d719af8cb4272ea1c4a6d668a777f37e115f6d11ddbc1c8e0e7" dependencies = [ - "cc", + "bitflags 1.3.2", + "core-foundation", + "system-configuration-sys", +] + +[[package]] +name = "system-configuration-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a75fb188eb626b924683e3b95e3a48e63551fcfb51949de2f06a9d91dbee93c9" +dependencies = [ + "core-foundation-sys", "libc", ] [[package]] name = "tar" -version = "0.4.38" +version = "0.4.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4b55807c0344e1e6c04d7c965f5289c39a8d94ae23ed5c0b57aabac549f871c6" +checksum = "b16afcea1f22891c49a00c751c7b63b2233284064f11a200fc624137c51e2ddb" dependencies = [ "filetime", "libc", @@ -3074,91 +2254,63 @@ dependencies = [ [[package]] name = "tempfile" -version = "3.5.0" +version = "3.10.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9fbec84f381d5795b08656e4912bec604d162bff9291d6189a78f4c8ab87998" +checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "fastrand", - "redox_syscall 0.3.5", "rustix", - "windows-sys 0.45.0", + "windows-sys 0.52.0", ] [[package]] name = "termcolor" -version = "1.1.3" +version = "1.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" dependencies = [ "winapi-util", ] [[package]] name = "textwrap" -version = "0.11.0" +version = "0.16.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" -dependencies = [ - "unicode-width", -] - -[[package]] -name = "textwrap" -version = "0.16.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "222a222a5bfe1bba4a77b45ec488a741b3cb8872e5e499451fd7d0129c9c7c3d" +checksum = "23d434d3f8967a09480fb04132ebe0a3e088c173e6d0ee7897abbdf4eab0f8b9" [[package]] name = "thiserror" -version = "1.0.40" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac" +checksum = "c546c80d6be4bc6a00c0f01730c08df82eaa7a7a61f11d656526506112cc1709" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.40" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f" -dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", -] - -[[package]] -name = "thread_local" -version = "1.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152" -dependencies = [ - "cfg-if 1.0.0", - "once_cell", -] - -[[package]] -name = "time" -version = "0.1.45" +version = "1.0.61" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" +checksum = "46c3384250002a6d5af4d114f2845d37b57521033f30d5c3f46c4d70e1197533" dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] name = "time" -version = "0.3.20" +version = "0.3.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cd0cbfecb4d19b5ea75bb31ad904eb5b9fa13f21079c3b92017ebdf4999a5890" +checksum = "5dfd88e563464686c916c7e46e623e520ddc6d79fa6641390f2e3fa86e83e885" dependencies = [ + "deranged", "itoa", "libc", + "num-conv", "num_threads", + "powerfmt", "serde", "time-core", "time-macros", @@ -3166,16 +2318,17 @@ dependencies = [ [[package]] name = "time-core" -version = "0.1.0" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2e153e1f1acaef8acc537e68b44906d2db6436e2b35ac2c6b42640fff91f00fd" +checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3" [[package]] name = "time-macros" -version = "0.2.8" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fd80a657e71da814b8e5d60d3374fc6d35045062245d80224748ae522dd76f36" +checksum = "3f252a68540fde3a3877aeea552b832b40ab9a69e318efd078774a01ddee1ccf" dependencies = [ + "num-conv", "time-core", ] @@ -3189,144 +2342,69 @@ dependencies = [ ] [[package]] -name = "tinyvec_macros" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" - -[[package]] -name = "tokio" -version = "1.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d0de47a4eecbe11f498978a9b29d792f0d2692d1dd003650c24c76510e3bc001" -dependencies = [ - "autocfg", - "bytes", - "libc", - "mio", - "num_cpus", - "parking_lot 0.12.1", - "pin-project-lite", - "signal-hook-registry", - "socket2", - "tokio-macros", - "windows-sys 0.45.0", -] - -[[package]] -name = "tokio-macros" -version = "2.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61a573bdc87985e9d6ddeed1b3d864e8a302c847e40d647746df2f1de209d1ce" -dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", -] - -[[package]] -name = "tokio-native-tls" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" -dependencies = [ - "native-tls", - "tokio", -] - -[[package]] -name = "tokio-openssl" -version = "0.6.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c08f9ffb7809f1b20c1b398d92acf4cc719874b3b2b2d9ea2f09b4a80350878a" -dependencies = [ - "futures-util", - "openssl", - "openssl-sys", - "tokio", -] - -[[package]] -name = "tokio-serde" -version = "0.8.0" +name = "tinyvec_macros" +version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "911a61637386b789af998ee23f50aa30d5fd7edcec8d6d3dedae5e5815205466" -dependencies = [ - "bincode", - "bytes", - "educe", - "futures-core", - "futures-sink", - "pin-project", - "serde", -] +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] -name = "tokio-stream" -version = "0.1.12" +name = "tokio" +version = "1.37.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8fb52b74f05dbf495a8fba459fdc331812b96aa086d9eb78101fa0d4569c3313" +checksum = "1adbebffeca75fcfd058afa480fb6c0b81e165a0323f9c9d39c9697e37c46787" dependencies = [ - "futures-core", + "backtrace", + "bytes", + "libc", + "mio", + "num_cpus", + "parking_lot", "pin-project-lite", - "tokio", - "tokio-util 0.7.7", + "signal-hook-registry", + "socket2", + "tokio-macros", + "windows-sys 0.48.0", ] [[package]] -name = "tokio-tungstenite" -version = "0.18.0" +name = "tokio-macros" +version = "2.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "54319c93411147bced34cb5609a80e0a8e44c5999c93903a81cd866630ec0bfd" +checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ - "futures-util", - "log", - "tokio", - "tungstenite", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] -name = "tokio-util" -version = "0.6.10" +name = "tokio-native-tls" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36943ee01a6d67977dd3f84a5a1d2efeb4ada3a1ae771cadfaa535d9d9fc6507" +checksum = "bbae76ab933c85776efabc971569dd6119c580d8f5d448769dec1764bf796ef2" dependencies = [ - "bytes", - "futures-core", - "futures-sink", - "log", - "pin-project-lite", + "native-tls", "tokio", ] [[package]] name = "tokio-util" -version = "0.7.7" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5427d89453009325de0d8f342c9490009f76e999cb7672d77e46267448f7e6b2" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] name = "toml" -version = "0.5.11" +version = "0.7.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" -dependencies = [ - "serde", -] - -[[package]] -name = "toml" -version = "0.7.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebafdf5ad1220cb59e7d17cf4d2c72015297b75b19a10472f99b89225089240" +checksum = "dd79e69d3b627db300ff956027cc6c3798cef26d22526befdfcd12feeb6d2257" dependencies = [ "serde", "serde_spanned", @@ -3336,20 +2414,20 @@ dependencies = [ [[package]] name = "toml_datetime" -version = "0.6.3" +version = "0.6.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +checksum = "4badfd56924ae69bcc9039335b2e017639ce3f9b001c393c1b2d1ef846ce2cbf" dependencies = [ "serde", ] [[package]] name = "toml_edit" -version = "0.19.11" +version = "0.19.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "266f016b7f039eec8a1a80dfe6156b633d208b9fccca5e4db1d6775b0c4e34a7" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" dependencies = [ - "indexmap 2.0.0", + "indexmap 2.2.6", "serde", "serde_spanned", "toml_datetime", @@ -3363,12 +2441,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" dependencies = [ "futures-core", + "futures-util", + "pin-project", "pin-project-lite", "tokio", - "tokio-util 0.7.7", "tower-layer", "tower-service", - "tracing", ] [[package]] @@ -3385,12 +2463,10 @@ checksum = "b6bc1c9ce2b5135ac7f93c72918fc37feb872bdc6a5533a8b85eb4b86bfdae52" [[package]] name = "tracing" -version = "0.1.37" +version = "0.1.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ce8c33a8d48bd45d624a6e523445fd21ec13d3653cd51f681abf67418f54eb8" +checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" dependencies = [ - "cfg-if 1.0.0", - "log", "pin-project-lite", "tracing-attributes", "tracing-core", @@ -3398,108 +2474,35 @@ dependencies = [ [[package]] name = "tracing-attributes" -version = "0.1.23" +version = "0.1.27" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4017f8f45139870ca7e672686113917c71c7a6e02d4924eda67186083c03081a" +checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", ] [[package]] name = "tracing-core" -version = "0.1.30" +version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24eb03ba0eab1fd845050058ce5e616558e8f8d8fca633e6b163fe25c797213a" +checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" dependencies = [ "once_cell", - "valuable", -] - -[[package]] -name = "tracing-futures" -version = "0.2.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" -dependencies = [ - "pin-project", - "tracing", -] - -[[package]] -name = "tracing-log" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78ddad33d2d10b1ed7eb9d1f518a5674713876e97e5bb9b7345a7984fbb4f922" -dependencies = [ - "lazy_static", - "log", - "tracing-core", -] - -[[package]] -name = "tracing-serde" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bc6b213177105856957181934e4920de57730fc69bf42c37ee5bb664d406d9e1" -dependencies = [ - "serde", - "tracing-core", -] - -[[package]] -name = "tracing-subscriber" -version = "0.2.25" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e0d2eaa99c3c2e41547cfa109e910a68ea03823cccad4a0525dcbc9b01e8c71" -dependencies = [ - "ansi_term", - "chrono", - "lazy_static", - "matchers", - "regex", - "serde", - "serde_json", - "sharded-slab", - "smallvec", - "thread_local", - "tracing", - "tracing-core", - "tracing-log", - "tracing-serde", ] [[package]] name = "try-lock" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" - -[[package]] -name = "tungstenite" -version = "0.18.0" +version = "0.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ee6ab729cd4cf0fd55218530c4522ed30b7b6081752839b68fcec8d0960788" -dependencies = [ - "base64 0.13.1", - "byteorder", - "bytes", - "http", - "httparse", - "log", - "rand 0.8.5", - "sha1", - "thiserror", - "url", - "utf-8", -] +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" [[package]] name = "typenum" -version = "1.16.0" +version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" +checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" [[package]] name = "uint" @@ -3519,48 +2522,27 @@ version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "eaea85b334db583fe3274d12b4cd1880032beab409c0d774be044d4480ab9a94" -[[package]] -name = "unicase" -version = "2.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50f37be617794602aabbeee0be4f259dc1778fabe05e2d67ee8f79326d5cb4f6" -dependencies = [ - "version_check", -] - [[package]] name = "unicode-bidi" -version = "0.3.13" +version = "0.3.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92888ba5573ff080736b3648696b70cafad7d250551175acbaa4e0385b3e1460" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" [[package]] name = "unicode-ident" -version = "1.0.8" +version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5464a87b239f13a63a501f2701565754bae92d243d4bb7eb12f6d57d2269bf4" +checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" [[package]] name = "unicode-normalization" -version = "0.1.22" +version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-segmentation" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dd624098567895118886609431a7c3b8f516e41d30e0643f03d94592a147e36" - -[[package]] -name = "unicode-width" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0edd1e5b14653f783770bce4a4dabb4a5108a5370a5f5d8cfe8710c361f6c8b" - [[package]] name = "unicode-xid" version = "0.1.0" @@ -3575,21 +2557,15 @@ checksum = "a156c684c91ea7d62626509bce3cb4e1d9ed5c4d978f7b4352658f96a4c26b4a" [[package]] name = "url" -version = "2.3.1" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0d68c799ae75762b8c3fe375feb6600ef5602c883c5d21eb51c09f22b83c4643" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" dependencies = [ "form_urlencoded", "idna", "percent-encoding", ] -[[package]] -name = "utf-8" -version = "0.7.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" - [[package]] name = "uuid" version = "0.8.2" @@ -3600,21 +2576,11 @@ dependencies = [ "serde", ] -[[package]] -name = "valuable" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" - [[package]] name = "value-bag" -version = "1.0.0-alpha.9" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2209b78d1249f7e6f3293657c9779fe31ced465df091bbd433a1cf88e916ec55" -dependencies = [ - "ctor", - "version_check", -] +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" [[package]] name = "vcpkg" @@ -3622,23 +2588,6 @@ version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" -[[package]] -name = "vec_map" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" - -[[package]] -name = "vergen" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7141e445af09c8919f1d5f8a20dae0b20c3b57a45dee0d5823c6ed5d237f15a" -dependencies = [ - "bitflags", - "chrono", - "rustc_version", -] - [[package]] name = "version_check" version = "0.9.4" @@ -3656,70 +2605,13 @@ dependencies = [ [[package]] name = "want" -version = "0.3.0" +version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ce8a968cb1cd110d136ff8b819a556d6fb6d919363c61534f6860c7eb172ba0" +checksum = "bfa7760aed19e106de2c7c0b581b509f2f25d3dacaf737cb82ac61bc6d760b0e" dependencies = [ - "log", "try-lock", ] -[[package]] -name = "warp" -version = "0.3.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27e1a710288f0f91a98dd8a74f05b76a10768db245ce183edf64dc1afdc3016c" -dependencies = [ - "async-compression", - "bytes", - "futures-channel", - "futures-util", - "headers", - "http", - "hyper", - "log", - "mime", - "mime_guess", - "multiparty", - "percent-encoding", - "pin-project", - "rustls-pemfile", - "scoped-tls", - "serde", - "serde_json", - "serde_urlencoded", - "tokio", - "tokio-stream", - "tokio-tungstenite", - "tokio-util 0.7.7", - "tower-service", - "tracing", -] - -[[package]] -name = "warp-json-rpc" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7267422020cd1544b9eb9d1a5e54128ccfd2e203a12b7f5eeec992d656c72fd8" -dependencies = [ - "anyhow", - "erased-serde", - "futures", - "http", - "hyper", - "lazycell", - "log", - "serde", - "serde_json", - "warp", -] - -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - [[package]] name = "wasi" version = "0.11.0+wasi-snapshot-preview1" @@ -3728,36 +2620,36 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.84" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "31f8dcbc21f30d9b8f2ea926ecb58f6b91192c17e9d33594b3df58b2007ca53b" +checksum = "4be2531df63900aeb2bca0daaaddec08491ee64ceecbee5076636a3b026795a8" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "wasm-bindgen-macro", ] [[package]] name = "wasm-bindgen-backend" -version = "0.2.84" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95ce90fd5bcc06af55a641a86428ee4229e44e07033963a2290a8e241607ccb9" +checksum = "614d787b966d3989fa7bb98a654e369c762374fd3213d212cfc0251257e747da" dependencies = [ "bumpalo", "log", "once_cell", - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-futures" -version = "0.4.34" +version = "0.4.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f219e0d211ba40266969f6dbdd90636da12f75bee4fc9d6c23d1260dadb51454" +checksum = "76bc14366121efc8dbb487ab05bcc9d346b3b5ec0eaa76e46594cabbe51762c0" dependencies = [ - "cfg-if 1.0.0", + "cfg-if", "js-sys", "wasm-bindgen", "web-sys", @@ -3765,38 +2657,38 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.84" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c21f77c0bedc37fd5dc21f897894a5ca01e7bb159884559461862ae90c0b4c5" +checksum = "a1f8823de937b71b9460c0c34e25f3da88250760bec0ebac694b49997550d726" dependencies = [ - "quote 1.0.29", + "quote 1.0.36", "wasm-bindgen-macro-support", ] [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.84" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2aff81306fcac3c7515ad4e177f521b5c9a15f2b08f4e32d823066102f35a5f6" +checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 1.0.109", + "proc-macro2 1.0.84", + "quote 1.0.36", + "syn 2.0.66", "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.84" +version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0046fef7e28c3804e5e38bfa31ea2a0f73905319b677e57ebe37e49358989b5d" +checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" [[package]] name = "wasm-streams" -version = "0.2.3" +version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6bbae3363c08332cadccd13b67db371814cd214c2524020932f0804b8cf7c078" +checksum = "b65dc4c90b63b118468cf747d8bf3566c1913ef60be765b5730ead9e0a3ba129" dependencies = [ "futures-util", "js-sys", @@ -3805,46 +2697,16 @@ dependencies = [ "web-sys", ] -[[package]] -name = "wasmi" -version = "0.9.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca00c5147c319a8ec91ec1a0edbec31e566ce2c9cc93b3f9bb86a9efd0eb795d" -dependencies = [ - "downcast-rs", - "libc", - "memory_units", - "num-rational 0.2.4", - "num-traits", - "parity-wasm", - "wasmi-validation", -] - -[[package]] -name = "wasmi-validation" -version = "0.4.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "165343ecd6c018fc09ebcae280752702c9a2ef3e6f8d02f1cfcbdb53ef6d7937" -dependencies = [ - "parity-wasm", -] - [[package]] name = "web-sys" -version = "0.3.61" +version = "0.3.69" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e33b99f4b23ba3eec1a53ac264e35a755f00e966e0065077d6027c0f575b0b97" +checksum = "77afa9a11836342370f4817622a2f0f418b134426d91a82dfb48f532d2ec13ef" dependencies = [ "js-sys", "wasm-bindgen", ] -[[package]] -name = "wheelbuf" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62945bc99a6a121cb2759c7bfa7b779ddf0e69b68bb35a9b23ab72276cfdcd3c" - [[package]] name = "winapi" version = "0.3.9" @@ -3863,11 +2725,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.5" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -3876,241 +2738,205 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" -[[package]] -name = "windows" -version = "0.48.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f" -dependencies = [ - "windows-targets 0.48.0", -] - -[[package]] -name = "windows-sys" -version = "0.42.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7" -dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", -] - [[package]] name = "windows-sys" -version = "0.45.0" +version = "0.48.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" dependencies = [ - "windows-targets 0.42.2", + "windows-targets 0.48.5", ] [[package]] name = "windows-sys" -version = "0.48.0" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.48.0", + "windows-targets 0.52.5", ] [[package]] name = "windows-targets" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c" dependencies = [ - "windows_aarch64_gnullvm 0.42.2", - "windows_aarch64_msvc 0.42.2", - "windows_i686_gnu 0.42.2", - "windows_i686_msvc 0.42.2", - "windows_x86_64_gnu 0.42.2", - "windows_x86_64_gnullvm 0.42.2", - "windows_x86_64_msvc 0.42.2", + "windows_aarch64_gnullvm 0.48.5", + "windows_aarch64_msvc 0.48.5", + "windows_i686_gnu 0.48.5", + "windows_i686_msvc 0.48.5", + "windows_x86_64_gnu 0.48.5", + "windows_x86_64_gnullvm 0.48.5", + "windows_x86_64_msvc 0.48.5", ] [[package]] name = "windows-targets" -version = "0.48.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b1eb6f0cd7c80c79759c929114ef071b87354ce476d9d94271031c0497adfd5" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.48.0", - "windows_aarch64_msvc 0.48.0", - "windows_i686_gnu 0.48.0", - "windows_i686_msvc 0.48.0", - "windows_x86_64_gnu 0.48.0", - "windows_x86_64_gnullvm 0.48.0", - "windows_x86_64_msvc 0.48.0", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] name = "windows_aarch64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" +checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.48.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "91ae572e1b79dba883e0d315474df7305d12f569b400fcf90581b06062f7e1bc" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" +checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.48.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2ef27e0d7bdfcfc7b868b317c1d32c641a6fe4629c171b8928c7b08d98d7cf3" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" +checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.48.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "622a1962a7db830d6fd0a69683c80a18fda201879f0f447f065a3b7467daa241" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" +checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.48.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4542c6e364ce21bf45d69fdd2a8e455fa38d316158cfd43b3ac1c5b1b19f8e00" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" +checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.48.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca2b8a661f7628cbd23440e50b05d705db3686f894fc9580820623656af974b1" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" +checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.48.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7896dbc1f41e08872e9d5e8f8baa8fdd2677f29468c4e156210174edc7f7b953" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" -version = "0.42.2" +version = "0.48.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" +checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.48.0" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a515f5799fe4961cb532f983ce2b23082366b898e52ffbce459c86f67c8378a" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.4.7" +version = "0.5.40" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ca0ace3845f0d96209f0375e6d367e3eb87eb65d27d445bdc9f1843a26f39448" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" dependencies = [ "memchr", ] [[package]] name = "winreg" -version = "0.10.1" +version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80d0f4e272c85def139476380b12f9ac60926689dd2e01d4923222f40580869d" +checksum = "a277a57398d4bfa075df44f501a17cfdf8542d224f0d36095a2adc7aee4ef0a5" dependencies = [ - "winapi", + "cfg-if", + "windows-sys 0.48.0", ] -[[package]] -name = "wyz" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "85e60b0d1b5f99db2556934e21937020776a5d31520bf169e851ac44e6420214" - [[package]] name = "xattr" -version = "0.2.3" +version = "1.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d1526bbe5aaeb5eb06885f4d987bcdfa5e23187055de9b83fe00156a821fabc" +checksum = "8da84f1a25939b27f6820d92aed108f83ff920fdf11a7b19366c27c4cda81d4f" dependencies = [ "libc", + "linux-raw-sys", + "rustix", ] [[package]] name = "zeroize" -version = "1.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4756f7db3f7b5574938c3eb1c117038b8e07f95ee6718c0efad4ac21508f1efd" -dependencies = [ - "zeroize_derive", -] - -[[package]] -name = "zeroize_derive" -version = "1.4.2" +version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" -dependencies = [ - "proc-macro2 1.0.63", - "quote 1.0.29", - "syn 2.0.23", -] +checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde" [[package]] name = "zstd" -version = "0.12.3+zstd.1.5.2" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "76eea132fb024e0e13fd9c2f5d5d595d8a967aa72382ac2f9d39fcc95afd0806" +checksum = "2d789b1514203a1120ad2429eae43a7bd32b90976a7bb8a05f7ec02fa88cc23a" dependencies = [ "zstd-safe", ] [[package]] name = "zstd-safe" -version = "6.0.5+zstd.1.5.4" +version = "7.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d56d9e60b4b1758206c238a10165fbcae3ca37b01744e394c463463f6529d23b" +checksum = "1cd99b45c6bc03a018c8b8a86025678c87e55526064e38f9df301989dce7ec0a" dependencies = [ - "libc", "zstd-sys", ] [[package]] name = "zstd-sys" -version = "2.0.7+zstd.1.5.4" +version = "2.0.10+zstd.1.5.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94509c3ba2fe55294d752b79842c530ccfab760192521df74a081a78d2b3c7f5" +checksum = "c253a4914af5bafc8fa8c86ee400827e83cf6ec01195ec1f1ed8441bf00d65aa" dependencies = [ "cc", - "libc", "pkg-config", ] diff --git a/Cargo.toml b/Cargo.toml index 66d6160..388d408 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -14,17 +14,15 @@ build = "build.rs" [dependencies] anyhow = "1" bincode = "1" -casper-execution-engine = "4" -casper-hashing = "1.4" -casper-node = "=1.4.15-alt" -casper-types = "2" +casper-execution-engine = "*" +casper-storage = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } +casper-types = "*" clap = { version = "3", features = ["cargo"] } futures = "0.3.21" -lmdb = "0.8.0" -lmdb-sys = "0.8.0" +lmdb-rkv = "0.14" log = "0.4.17" once_cell = "1" -reqwest = { version = "0.11.10", features = ["stream"] } +reqwest = { version = "0.12.4", features = ["stream"] } ringbuf = "0.2.8" serde = { version = "1", features = ["derive"] } serde_json = "1" @@ -32,7 +30,7 @@ simplelog = "0.12.0" tar = "0.4.38" thiserror = "1" tokio = { version = "1", features = ["full"] } -zstd = "0.12" +zstd = "0.13.1" [dev-dependencies] once_cell = "1" @@ -40,4 +38,9 @@ rand = "0.8.5" tempfile = "3" [build-dependencies] -cargo-lock = { version = "9.0", default-features = false } \ No newline at end of file +cargo-lock = { version = "9.0", default-features = false } + +[patch.crates-io] +casper-types = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } +casper-execution-engine = { git = "https://github.com/casper-network/casper-node.git", branch = "feat-2.0" } + diff --git a/src/common.rs b/src/common.rs index 50189a1..f4ed97e 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,3 +1,2 @@ pub mod db; -pub mod lmdb_utils; pub mod progress; diff --git a/src/common/db.rs b/src/common/db.rs index 5dc4512..0d89623 100644 --- a/src/common/db.rs +++ b/src/common/db.rs @@ -1,30 +1,41 @@ +mod approvals_hashes_db; mod block_body_db; -mod block_body_merkle_db; +mod block_body_v2_db; mod block_header_db; +mod block_header_v2; mod block_metadata_db; -mod deploy_hashes_db; +mod block_metadata_v2_db; mod deploy_metadata_db; mod deploys_db; +mod execution_results_db; mod finalized_approvals_db; -mod proposers_db; mod state_store_db; +mod transactions_db; +mod transfer_db; +mod versioned_approvals_hashes_db; +mod versioned_finalized_approvals_db; +mod versioned_transfers_db; + #[cfg(test)] mod tests; -mod transfer_db; -mod transfer_hashes_db; - -pub use block_body_db::BlockBodyDatabase; -pub use block_body_merkle_db::BlockBodyMerkleDatabase; -pub use block_header_db::BlockHeaderDatabase; -pub use block_metadata_db::BlockMetadataDatabase; -pub use deploy_hashes_db::DeployHashesDatabase; -pub use deploy_metadata_db::DeployMetadataDatabase; + +pub use approvals_hashes_db::ApprovalsHashesDatabase; +pub use block_body_db::LegacyBlockBodyDatabase; +pub use block_body_v2_db::VersionedBlockBodyDatabase; +pub use block_header_db::LegacyBlockHeaderDatabase; +pub use block_header_v2::VersionedBlockHeaderDatabase; +pub use block_metadata_db::LegacyBlockMetadataDatabase; +pub use block_metadata_v2_db::VersionedBlockMetadataDatabase; +pub use deploy_metadata_db::LegacyDeployMetadataDatabase; pub use deploys_db::DeployDatabase; +pub use execution_results_db::VersionedExecutionResultsDatabase; pub use finalized_approvals_db::FinalizedApprovalsDatabase; -pub use proposers_db::ProposerDatabase; pub use state_store_db::StateStoreDatabase; +pub use transactions_db::TransactionsDatabase; pub use transfer_db::TransferDatabase; -pub use transfer_hashes_db::TransferHashesDatabase; +pub use versioned_approvals_hashes_db::VersionedApprovalsHashesDatabase; +pub use versioned_finalized_approvals_db::VersionedFinalizedApprovalsDatabase; +pub use versioned_transfers_db::VersionedTransfersDatabase; use std::{ fmt::{Display, Formatter, Result as FormatterResult}, @@ -44,6 +55,11 @@ pub const TRIE_STORE_FILE_NAME: &str = "data.lmdb"; const ENTRY_LOG_INTERVAL: usize = 100_000; const MAX_DB_READERS: u32 = 100; +const GIB: usize = 1024 * 1024 * 1024; +pub(crate) const DEFAULT_MAX_BLOCK_STORE_SIZE: usize = 450 * GIB; +pub(crate) const DEFAULT_MAX_DEPLOY_STORE_SIZE: usize = 300 * GIB; +pub(crate) const DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE: usize = 300 * GIB; + #[derive(Debug, Error)] pub enum DeserializationError { #[error("failed parsing struct with bincode")] @@ -109,7 +125,8 @@ pub trait Database { info!("Skipping {} entries.", start_at); } let mut error_buffer = vec![]; - for (idx, (_raw_key, raw_val)) in cursor.iter().skip(start_at).enumerate() { + for (idx, entry) in cursor.iter().skip(start_at).enumerate() { + let (_raw_key, raw_val) = entry.map_err(Error::Database)?; if let Err(e) = Self::parse_element(raw_val).map_err(|parsing_err| Error::Parsing(idx, parsing_err)) { diff --git a/src/common/db/approvals_hashes_db.rs b/src/common/db/approvals_hashes_db.rs new file mode 100644 index 0000000..db9e8dc --- /dev/null +++ b/src/common/db/approvals_hashes_db.rs @@ -0,0 +1,35 @@ +use std::{ + fmt::{Display, Formatter, Result as FormatterResult}, + result::Result, +}; + +#[derive(Deserialize)] +struct LegacyApprovalsHashes { + _block_hash: BlockHash, + _approvals_hashes: Vec, + _merkle_proof_approvals: TrieMerkleProof, +} + +use casper_types::{global_state::TrieMerkleProof, ApprovalsHash, BlockHash, Key, StoredValue}; +use serde::Deserialize; + +use super::{Database, DeserializationError}; + +pub struct ApprovalsHashesDatabase; + +impl Display for ApprovalsHashesDatabase { + fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { + write!(f, "approvals_hashes") + } +} + +impl Database for ApprovalsHashesDatabase { + fn db_name() -> &'static str { + "approvals_hashes" + } + + fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { + let _: LegacyApprovalsHashes = bincode::deserialize(bytes)?; + Ok(()) + } +} diff --git a/src/common/db/block_body_db.rs b/src/common/db/block_body_db.rs index d883c2c..b108f49 100644 --- a/src/common/db/block_body_db.rs +++ b/src/common/db/block_body_db.rs @@ -3,25 +3,25 @@ use std::{ result::Result, }; -use casper_node::types::BlockBody; +use casper_types::BlockBodyV1; use super::{Database, DeserializationError}; -pub struct BlockBodyDatabase; +pub struct LegacyBlockBodyDatabase; -impl Display for BlockBodyDatabase { +impl Display for LegacyBlockBodyDatabase { fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { write!(f, "block_body") } } -impl Database for BlockBodyDatabase { +impl Database for LegacyBlockBodyDatabase { fn db_name() -> &'static str { "block_body" } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: BlockBody = bincode::deserialize(bytes)?; + let _: BlockBodyV1 = bincode::deserialize(bytes)?; Ok(()) } } diff --git a/src/common/db/deploy_hashes_db.rs b/src/common/db/block_body_v2_db.rs similarity index 53% rename from src/common/db/deploy_hashes_db.rs rename to src/common/db/block_body_v2_db.rs index 2a552ca..56624a3 100644 --- a/src/common/db/deploy_hashes_db.rs +++ b/src/common/db/block_body_v2_db.rs @@ -3,25 +3,25 @@ use std::{ result::Result, }; -use casper_types::{bytesrepr::FromBytes, DeployHash}; +use casper_types::{bytesrepr::FromBytes, BlockBody}; use super::{Database, DeserializationError}; -pub struct DeployHashesDatabase; +pub struct VersionedBlockBodyDatabase; -impl Display for DeployHashesDatabase { +impl Display for VersionedBlockBodyDatabase { fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { - write!(f, "deploy_hashes") + write!(f, "block_body_v2") } } -impl Database for DeployHashesDatabase { +impl Database for VersionedBlockBodyDatabase { fn db_name() -> &'static str { - "deploy_hashes" + "block_body_v2" } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: Vec = FromBytes::from_bytes(bytes)?.0; + let _: BlockBody = FromBytes::from_bytes(bytes)?.0; Ok(()) } } diff --git a/src/common/db/block_header_db.rs b/src/common/db/block_header_db.rs index 487da80..c173ed5 100644 --- a/src/common/db/block_header_db.rs +++ b/src/common/db/block_header_db.rs @@ -3,25 +3,25 @@ use std::{ result::Result, }; -use casper_node::types::BlockHeader; +use casper_types::BlockHeaderV1; use super::{Database, DeserializationError}; -pub struct BlockHeaderDatabase; +pub struct LegacyBlockHeaderDatabase; -impl Display for BlockHeaderDatabase { +impl Display for LegacyBlockHeaderDatabase { fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { write!(f, "block_header") } } -impl Database for BlockHeaderDatabase { +impl Database for LegacyBlockHeaderDatabase { fn db_name() -> &'static str { "block_header" } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: BlockHeader = bincode::deserialize(bytes)?; + let _: BlockHeaderV1 = bincode::deserialize(bytes)?; Ok(()) } } diff --git a/src/common/db/transfer_hashes_db.rs b/src/common/db/block_header_v2.rs similarity index 52% rename from src/common/db/transfer_hashes_db.rs rename to src/common/db/block_header_v2.rs index 6248fee..a7cddcc 100644 --- a/src/common/db/transfer_hashes_db.rs +++ b/src/common/db/block_header_v2.rs @@ -3,25 +3,25 @@ use std::{ result::Result, }; -use casper_types::{bytesrepr::FromBytes, DeployHash}; +use casper_types::{bytesrepr::FromBytes, BlockHeader}; use super::{Database, DeserializationError}; -pub struct TransferHashesDatabase; +pub struct VersionedBlockHeaderDatabase; -impl Display for TransferHashesDatabase { +impl Display for VersionedBlockHeaderDatabase { fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { - write!(f, "transfer_hashes") + write!(f, "block_header_v2") } } -impl Database for TransferHashesDatabase { +impl Database for VersionedBlockHeaderDatabase { fn db_name() -> &'static str { - "transfer_hashes" + "block_header_v2" } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: Vec = FromBytes::from_bytes(bytes)?.0; + let _: BlockHeader = FromBytes::from_bytes(bytes)?.0; Ok(()) } } diff --git a/src/common/db/block_metadata_db.rs b/src/common/db/block_metadata_db.rs index 07eefc3..c0c5f26 100644 --- a/src/common/db/block_metadata_db.rs +++ b/src/common/db/block_metadata_db.rs @@ -3,25 +3,25 @@ use std::{ result::Result, }; -use casper_node::types::BlockSignatures; +use casper_types::BlockSignaturesV1; use super::{Database, DeserializationError}; -pub struct BlockMetadataDatabase; +pub struct LegacyBlockMetadataDatabase; -impl Display for BlockMetadataDatabase { +impl Display for LegacyBlockMetadataDatabase { fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { write!(f, "block_metadata") } } -impl Database for BlockMetadataDatabase { +impl Database for LegacyBlockMetadataDatabase { fn db_name() -> &'static str { "block_metadata" } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: BlockSignatures = bincode::deserialize(bytes)?; + let _: BlockSignaturesV1 = bincode::deserialize(bytes)?; Ok(()) } } diff --git a/src/common/db/block_metadata_v2_db.rs b/src/common/db/block_metadata_v2_db.rs new file mode 100644 index 0000000..44d1409 --- /dev/null +++ b/src/common/db/block_metadata_v2_db.rs @@ -0,0 +1,27 @@ +use std::{ + fmt::{Display, Formatter, Result as FormatterResult}, + result::Result, +}; + +use casper_types::{bytesrepr::FromBytes, BlockSignatures}; + +use super::{Database, DeserializationError}; + +pub struct VersionedBlockMetadataDatabase; + +impl Display for VersionedBlockMetadataDatabase { + fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { + write!(f, "block_metadata_v2") + } +} + +impl Database for VersionedBlockMetadataDatabase { + fn db_name() -> &'static str { + "block_metadata_v2" + } + + fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { + let _: BlockSignatures = FromBytes::from_bytes(bytes)?.0; + Ok(()) + } +} diff --git a/src/common/db/deploy_metadata_db.rs b/src/common/db/deploy_metadata_db.rs index 6e24626..42eab4f 100644 --- a/src/common/db/deploy_metadata_db.rs +++ b/src/common/db/deploy_metadata_db.rs @@ -1,26 +1,33 @@ -use casper_node::types::DeployMetadata; +use casper_types::{execution::ExecutionResultV1, BlockHash}; +use serde::{Deserialize, Serialize}; use std::{ + collections::HashMap, fmt::{Display, Formatter, Result as FormatterResult}, result::Result, }; use super::{Database, DeserializationError}; -pub struct DeployMetadataDatabase; +#[derive(Clone, Default, Serialize, Deserialize, Debug, PartialEq, Eq)] +struct DeployMetadataV1 { + execution_results: HashMap, +} + +pub struct LegacyDeployMetadataDatabase; -impl Display for DeployMetadataDatabase { +impl Display for LegacyDeployMetadataDatabase { fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { write!(f, "deploy_metadata") } } -impl Database for DeployMetadataDatabase { +impl Database for LegacyDeployMetadataDatabase { fn db_name() -> &'static str { "deploy_metadata" } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: DeployMetadata = bincode::deserialize(bytes)?; + let _: DeployMetadataV1 = bincode::deserialize(bytes)?; Ok(()) } } diff --git a/src/common/db/deploys_db.rs b/src/common/db/deploys_db.rs index 09b0e74..4547bc0 100644 --- a/src/common/db/deploys_db.rs +++ b/src/common/db/deploys_db.rs @@ -3,7 +3,7 @@ use std::{ result::Result, }; -use casper_node::types::Deploy; +use casper_types::Deploy; use super::{Database, DeserializationError}; diff --git a/src/common/db/execution_results_db.rs b/src/common/db/execution_results_db.rs new file mode 100644 index 0000000..37b599e --- /dev/null +++ b/src/common/db/execution_results_db.rs @@ -0,0 +1,26 @@ +use casper_types::{bytesrepr::FromBytes, execution::ExecutionResult}; +use std::{ + fmt::{Display, Formatter, Result as FormatterResult}, + result::Result, +}; + +use super::{Database, DeserializationError}; + +pub struct VersionedExecutionResultsDatabase; + +impl Display for VersionedExecutionResultsDatabase { + fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { + write!(f, "execution_results") + } +} + +impl Database for VersionedExecutionResultsDatabase { + fn db_name() -> &'static str { + "execution_results" + } + + fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { + let _: ExecutionResult = FromBytes::from_bytes(bytes)?.0; + Ok(()) + } +} diff --git a/src/common/db/finalized_approvals_db.rs b/src/common/db/finalized_approvals_db.rs index df25719..dd0aa77 100644 --- a/src/common/db/finalized_approvals_db.rs +++ b/src/common/db/finalized_approvals_db.rs @@ -1,9 +1,10 @@ use std::{ + collections::BTreeSet, fmt::{Display, Formatter, Result as FormatterResult}, result::Result, }; -use casper_node::types::FinalizedApprovals; +use casper_types::Approval; use super::{Database, DeserializationError}; @@ -21,7 +22,7 @@ impl Database for FinalizedApprovalsDatabase { } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: FinalizedApprovals = bincode::deserialize(bytes)?; + let _: BTreeSet = bincode::deserialize(bytes)?; Ok(()) } } diff --git a/src/common/db/tests.rs b/src/common/db/tests.rs index 6c28fb2..4d713b7 100644 --- a/src/common/db/tests.rs +++ b/src/common/db/tests.rs @@ -1,9 +1,13 @@ -use lmdb::{Database as LmdbDatabase, Environment, Transaction, WriteFlags}; +use std::fs::OpenOptions; + +use lmdb::{ + Database as LmdbDatabase, DatabaseFlags, Environment, EnvironmentFlags, Transaction, WriteFlags, +}; use rand::{self, prelude::ThreadRng, Rng, RngCore}; use serde::{Deserialize, Serialize}; +use tempfile::NamedTempFile; use super::{Database, DeserializationError}; -use crate::test_utils::LmdbTestFixture; fn gen_bytes(rng: &mut ThreadRng) -> Vec { let mock = MockStruct::random(rng); @@ -139,24 +143,56 @@ fn sanity_check_ser_deser() { assert!(bincode::deserialize::(&gen_faulty_bytes(&mut rng)).is_err()); } +fn test_lmdb_database(db_name: &str) -> (Environment, lmdb::Database) { + let tmp_dir = tempfile::tempdir().unwrap(); + let db_path = NamedTempFile::new_in(tmp_dir.as_ref()) + .unwrap() + .path() + .to_path_buf(); + let _ = OpenOptions::new() + .create_new(true) + .write(true) + .open(&db_path) + .unwrap(); + + let env = Environment::new() + .set_flags( + EnvironmentFlags::WRITE_MAP + | EnvironmentFlags::NO_SUB_DIR + | EnvironmentFlags::NO_TLS + | EnvironmentFlags::NO_READAHEAD, + ) + .set_max_readers(12) + .set_map_size(4096 * 1024) + .set_max_dbs(10) + .open(&db_path) + .expect("can't create environment"); + + let db = env + .create_db(Some(db_name), DatabaseFlags::empty()) + .expect("can't create database"); + + (env, db) +} + #[test] fn good_db_should_pass_check() { - let fixture = LmdbTestFixture::new(vec![MockDb::db_name()], None); - populate_db(&fixture.env, fixture.db(Some(MockDb::db_name())).unwrap()); + let (env, db) = test_lmdb_database(MockDb::db_name()); + populate_db(&env, &db); - assert!(MockDb::check_db(&fixture.env, true, 0).is_ok()); - assert!(MockDb::check_db(&fixture.env, false, 0).is_ok()); - assert!(MockDb::check_db(&fixture.env, true, 4).is_ok()); - assert!(MockDb::check_db(&fixture.env, false, 4).is_ok()); + assert!(MockDb::check_db(&env, true, 0).is_ok()); + assert!(MockDb::check_db(&env, false, 0).is_ok()); + assert!(MockDb::check_db(&env, true, 4).is_ok()); + assert!(MockDb::check_db(&env, false, 4).is_ok()); } #[test] fn bad_db_should_fail_check() { - let fixture = LmdbTestFixture::new(vec![MockDb::db_name()], None); - populate_faulty_db(&fixture.env, fixture.db(Some(MockDb::db_name())).unwrap()); + let (env, db) = test_lmdb_database(MockDb::db_name()); + populate_faulty_db(&env, &db); - assert!(MockDb::check_db(&fixture.env, true, 0).is_err()); - assert!(MockDb::check_db(&fixture.env, false, 0).is_err()); - assert!(MockDb::check_db(&fixture.env, true, 4).is_err()); - assert!(MockDb::check_db(&fixture.env, false, 4).is_err()); + assert!(MockDb::check_db(&env, true, 0).is_err()); + assert!(MockDb::check_db(&env, false, 0).is_err()); + assert!(MockDb::check_db(&env, true, 4).is_err()); + assert!(MockDb::check_db(&env, false, 4).is_err()); } diff --git a/src/common/db/proposers_db.rs b/src/common/db/transactions_db.rs similarity index 54% rename from src/common/db/proposers_db.rs rename to src/common/db/transactions_db.rs index ed52f63..eb2875d 100644 --- a/src/common/db/proposers_db.rs +++ b/src/common/db/transactions_db.rs @@ -3,25 +3,25 @@ use std::{ result::Result, }; -use casper_types::{bytesrepr::FromBytes, PublicKey}; +use casper_types::{bytesrepr::FromBytes, Transaction}; use super::{Database, DeserializationError}; -pub struct ProposerDatabase; +pub struct TransactionsDatabase; -impl Display for ProposerDatabase { +impl Display for TransactionsDatabase { fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { - write!(f, "proposers") + write!(f, "transactions") } } -impl Database for ProposerDatabase { +impl Database for TransactionsDatabase { fn db_name() -> &'static str { - "proposers" + "transactions" } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: PublicKey = FromBytes::from_bytes(bytes)?.0; + let _: Transaction = FromBytes::from_bytes(bytes)?.0; Ok(()) } } diff --git a/src/common/db/transfer_db.rs b/src/common/db/transfer_db.rs index 4e5735b..74647c8 100644 --- a/src/common/db/transfer_db.rs +++ b/src/common/db/transfer_db.rs @@ -3,7 +3,7 @@ use std::{ result::Result, }; -use casper_types::Transfer; +use casper_types::TransferV1; use super::{Database, DeserializationError}; @@ -21,7 +21,7 @@ impl Database for TransferDatabase { } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: Vec = bincode::deserialize(bytes)?; + let _: Vec = bincode::deserialize(bytes)?; Ok(()) } } diff --git a/src/common/db/block_body_merkle_db.rs b/src/common/db/versioned_approvals_hashes_db.rs similarity index 52% rename from src/common/db/block_body_merkle_db.rs rename to src/common/db/versioned_approvals_hashes_db.rs index c4981d2..49305e9 100644 --- a/src/common/db/block_body_merkle_db.rs +++ b/src/common/db/versioned_approvals_hashes_db.rs @@ -3,26 +3,26 @@ use std::{ result::Result, }; -use casper_hashing::Digest; +use casper_storage::block_store::types::ApprovalsHashes; use casper_types::bytesrepr::FromBytes; use super::{Database, DeserializationError}; -pub struct BlockBodyMerkleDatabase; +pub struct VersionedApprovalsHashesDatabase; -impl Display for BlockBodyMerkleDatabase { +impl Display for VersionedApprovalsHashesDatabase { fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { - write!(f, "block_body_merkle") + write!(f, "versioned_approvals_hashes") } } -impl Database for BlockBodyMerkleDatabase { +impl Database for VersionedApprovalsHashesDatabase { fn db_name() -> &'static str { - "block_body_merkle" + "versioned_approvals_hashes" } fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { - let _: (Digest, Digest) = FromBytes::from_bytes(bytes)?.0; + let _: ApprovalsHashes = FromBytes::from_bytes(bytes)?.0; Ok(()) } } diff --git a/src/common/db/versioned_finalized_approvals_db.rs b/src/common/db/versioned_finalized_approvals_db.rs new file mode 100644 index 0000000..5a6770c --- /dev/null +++ b/src/common/db/versioned_finalized_approvals_db.rs @@ -0,0 +1,28 @@ +use std::{ + collections::BTreeSet, + fmt::{Display, Formatter, Result as FormatterResult}, + result::Result, +}; + +use casper_types::{bytesrepr::FromBytes, Approval}; + +use super::{Database, DeserializationError}; + +pub struct VersionedFinalizedApprovalsDatabase; + +impl Display for VersionedFinalizedApprovalsDatabase { + fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { + write!(f, "versioned_finalized_approvals") + } +} + +impl Database for VersionedFinalizedApprovalsDatabase { + fn db_name() -> &'static str { + "versioned_finalized_approvals" + } + + fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { + let _: BTreeSet = FromBytes::from_bytes(bytes)?.0; + Ok(()) + } +} diff --git a/src/common/db/versioned_transfers_db.rs b/src/common/db/versioned_transfers_db.rs new file mode 100644 index 0000000..cedcab8 --- /dev/null +++ b/src/common/db/versioned_transfers_db.rs @@ -0,0 +1,27 @@ +use std::{ + fmt::{Display, Formatter, Result as FormatterResult}, + result::Result, +}; + +use casper_types::{bytesrepr::FromBytes, Transfer}; + +use super::{Database, DeserializationError}; + +pub struct VersionedTransfersDatabase; + +impl Display for VersionedTransfersDatabase { + fn fmt(&self, f: &mut Formatter<'_>) -> FormatterResult { + write!(f, "versioned_transfers") + } +} + +impl Database for VersionedTransfersDatabase { + fn db_name() -> &'static str { + "versioned_transfers" + } + + fn parse_element(bytes: &[u8]) -> Result<(), DeserializationError> { + let _: Vec = FromBytes::from_bytes(bytes)?.0; + Ok(()) + } +} diff --git a/src/common/lmdb_utils.rs b/src/common/lmdb_utils.rs deleted file mode 100644 index 96cfe28..0000000 --- a/src/common/lmdb_utils.rs +++ /dev/null @@ -1,90 +0,0 @@ -use std::result::Result; - -use lmdb::{Database, Error, Transaction}; -use lmdb_sys::{mdb_stat, MDB_stat}; - -/// Retrieves the number of entries in a database. -pub fn entry_count(txn: &'_ T, database: Database) -> Result { - let mut stat = MDB_stat { - ms_psize: 0, - ms_depth: 0, - ms_branch_pages: 0, - ms_leaf_pages: 0, - ms_overflow_pages: 0, - ms_entries: 0, - }; - let result = unsafe { mdb_stat(txn.txn(), database.dbi(), &mut stat as *mut MDB_stat) }; - if result != 0 { - Err(Error::from_err_code(result)) - } else { - Ok(stat.ms_entries) - } -} - -#[cfg(test)] -mod tests { - use lmdb::{Transaction, WriteFlags}; - - use crate::test_utils::LmdbTestFixture; - - use super::entry_count; - - #[test] - fn db_entry_count() { - let fixture = LmdbTestFixture::new(vec![], None); - let env = &fixture.env; - let db = fixture.db(None).unwrap(); - - if let Ok(txn) = env.begin_ro_txn() { - assert_eq!(entry_count(&txn, *db).unwrap(), 0); - txn.commit().unwrap(); - } - - let first_dummy_input = [0u8, 1u8]; - let second_dummy_input = [1u8, 2u8]; - // Insert the first entry into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - txn.put( - *db, - &first_dummy_input, - &first_dummy_input, - WriteFlags::empty(), - ) - .unwrap(); - txn.commit().unwrap(); - }; - - if let Ok(txn) = env.begin_ro_txn() { - assert_eq!(entry_count(&txn, *db).unwrap(), 1); - txn.commit().unwrap(); - } - - // Insert the second entry into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - txn.put( - *db, - &second_dummy_input, - &second_dummy_input, - WriteFlags::empty(), - ) - .unwrap(); - txn.commit().unwrap(); - }; - - if let Ok(txn) = env.begin_ro_txn() { - assert_eq!(entry_count(&txn, *db).unwrap(), 2); - txn.commit().unwrap(); - }; - - // Delete the first entry from the database. - if let Ok(mut txn) = env.begin_rw_txn() { - txn.del(*db, &first_dummy_input, None).unwrap(); - txn.commit().unwrap(); - }; - - if let Ok(txn) = env.begin_ro_txn() { - assert_eq!(entry_count(&txn, *db).unwrap(), 1); - txn.commit().unwrap(); - }; - } -} diff --git a/src/main.rs b/src/main.rs index e317252..955c592 100644 --- a/src/main.rs +++ b/src/main.rs @@ -28,13 +28,13 @@ enum DisplayOrder { Unsparse, } +// TODO: revisit this since we don't depend on the node anymore. const VERSION_STRING: &str = concat!( crate_version!(), "\n", "This version of ", crate_name!(), - " is compatible with casper-node version ", - env!("CASPER_NODE_VERSION") + " is compatible with casper-storage 2.0 ", ); fn cli() -> Command<'static> { diff --git a/src/subcommands/check.rs b/src/subcommands/check.rs index 3346c15..37fe102 100644 --- a/src/subcommands/check.rs +++ b/src/subcommands/check.rs @@ -5,10 +5,13 @@ use lmdb::Error as LmdbError; use thiserror::Error as ThisError; use crate::common::db::{ - db_env, BlockBodyDatabase, BlockBodyMerkleDatabase, BlockHeaderDatabase, BlockMetadataDatabase, - Database, DeployDatabase, DeployHashesDatabase, DeployMetadataDatabase, Error as DbError, - FinalizedApprovalsDatabase, ProposerDatabase, StateStoreDatabase, TransferDatabase, - TransferHashesDatabase, STORAGE_FILE_NAME, + db_env, ApprovalsHashesDatabase, Database, DeployDatabase, Error as DbError, + FinalizedApprovalsDatabase, LegacyBlockBodyDatabase, LegacyBlockHeaderDatabase, + LegacyBlockMetadataDatabase, LegacyDeployMetadataDatabase, StateStoreDatabase, + TransactionsDatabase, TransferDatabase, VersionedApprovalsHashesDatabase, + VersionedBlockBodyDatabase, VersionedBlockHeaderDatabase, VersionedBlockMetadataDatabase, + VersionedExecutionResultsDatabase, VersionedFinalizedApprovalsDatabase, + VersionedTransfersDatabase, STORAGE_FILE_NAME, }; pub const COMMAND_NAME: &str = "check"; @@ -110,37 +113,57 @@ fn check_db>( .map_err(|lmdb_err| Error::Path(path.as_ref().to_path_buf(), lmdb_err))?; if let Some(db_name) = specific { match db_name.trim() { - "block_body" => BlockBodyDatabase::check_db(&env, failfast, start_at)?, - "block_body_merkle" => BlockBodyMerkleDatabase::check_db(&env, failfast, start_at)?, - "block_header" => BlockHeaderDatabase::check_db(&env, failfast, start_at)?, - "block_metadata" => BlockMetadataDatabase::check_db(&env, failfast, start_at)?, - "deploy_hashes" => DeployHashesDatabase::check_db(&env, failfast, start_at)?, - "deploy_metadata" => DeployMetadataDatabase::check_db(&env, failfast, start_at)?, + "block_body" => LegacyBlockBodyDatabase::check_db(&env, failfast, start_at)?, + "block_body_v2" => VersionedBlockBodyDatabase::check_db(&env, failfast, start_at)?, + "block_header" => LegacyBlockHeaderDatabase::check_db(&env, failfast, start_at)?, + "block_header_v2" => VersionedBlockHeaderDatabase::check_db(&env, failfast, start_at)?, + "block_metadata" => LegacyBlockMetadataDatabase::check_db(&env, failfast, start_at)?, + "block_metadata_v2" => { + VersionedBlockMetadataDatabase::check_db(&env, failfast, start_at)? + } + "deploy_metadata" => LegacyDeployMetadataDatabase::check_db(&env, failfast, start_at)?, + "execution_results" => { + VersionedExecutionResultsDatabase::check_db(&env, failfast, start_at)? + } "deploys" => DeployDatabase::check_db(&env, failfast, start_at)?, + "transactions" => TransactionsDatabase::check_db(&env, failfast, start_at)?, "finalized_approvals" => { FinalizedApprovalsDatabase::check_db(&env, failfast, start_at)? } - "proposers" => ProposerDatabase::check_db(&env, failfast, start_at)?, - "state_store" => StateStoreDatabase::check_db(&env, failfast, start_at)?, + "versioned_finalized_approvals" => { + VersionedFinalizedApprovalsDatabase::check_db(&env, failfast, start_at)? + } "transfer" => TransferDatabase::check_db(&env, failfast, start_at)?, - "transfer_hashes" => TransferHashesDatabase::check_db(&env, failfast, start_at)?, + "versioned_transfers" => { + VersionedTransfersDatabase::check_db(&env, failfast, start_at)? + } + "state_store" => StateStoreDatabase::check_db(&env, failfast, start_at)?, + "approvals_hashes" => ApprovalsHashesDatabase::check_db(&env, failfast, start_at)?, + "versioned_approvals_hashes" => { + VersionedApprovalsHashesDatabase::check_db(&env, failfast, start_at)? + } _ => return Err(Error::UnknownDb(db_name.to_string())), } } else { // Sanity check for `start_at`, already validated in arg parser. assert_eq!(start_at, 0); - BlockBodyDatabase::check_db(&env, failfast, start_at)?; - BlockBodyMerkleDatabase::check_db(&env, failfast, start_at)?; - BlockHeaderDatabase::check_db(&env, failfast, start_at)?; - BlockMetadataDatabase::check_db(&env, failfast, start_at)?; - DeployHashesDatabase::check_db(&env, failfast, start_at)?; - DeployMetadataDatabase::check_db(&env, failfast, start_at)?; + LegacyBlockBodyDatabase::check_db(&env, failfast, start_at)?; + VersionedBlockBodyDatabase::check_db(&env, failfast, start_at)?; + LegacyBlockHeaderDatabase::check_db(&env, failfast, start_at)?; + VersionedBlockHeaderDatabase::check_db(&env, failfast, start_at)?; + LegacyBlockMetadataDatabase::check_db(&env, failfast, start_at)?; + VersionedBlockMetadataDatabase::check_db(&env, failfast, start_at)?; + LegacyDeployMetadataDatabase::check_db(&env, failfast, start_at)?; + VersionedExecutionResultsDatabase::check_db(&env, failfast, start_at)?; DeployDatabase::check_db(&env, failfast, start_at)?; + TransactionsDatabase::check_db(&env, failfast, start_at)?; FinalizedApprovalsDatabase::check_db(&env, failfast, start_at)?; - ProposerDatabase::check_db(&env, failfast, start_at)?; - StateStoreDatabase::check_db(&env, failfast, start_at)?; + VersionedFinalizedApprovalsDatabase::check_db(&env, failfast, start_at)?; TransferDatabase::check_db(&env, failfast, start_at)?; - TransferHashesDatabase::check_db(&env, failfast, start_at)?; + VersionedTransfersDatabase::check_db(&env, failfast, start_at)?; + StateStoreDatabase::check_db(&env, failfast, start_at)?; + ApprovalsHashesDatabase::check_db(&env, failfast, start_at)?; + VersionedApprovalsHashesDatabase::check_db(&env, failfast, start_at)?; }; Ok(()) } diff --git a/src/subcommands/execution_results_summary.rs b/src/subcommands/execution_results_summary.rs index 1401fbe..e3afefa 100644 --- a/src/subcommands/execution_results_summary.rs +++ b/src/subcommands/execution_results_summary.rs @@ -1,4 +1,3 @@ -pub(crate) mod block_body; mod read_db; mod summary; #[cfg(test)] @@ -7,9 +6,8 @@ mod tests; use std::{io::Error as IoError, path::Path}; use bincode::Error as BincodeError; -use casper_node::types::BlockHash; +use casper_storage::block_store::BlockStoreError; use clap::{Arg, ArgMatches, Command}; -use lmdb::Error as LmdbError; use serde_json::Error as JsonSerializationError; use thiserror::Error as ThisError; @@ -22,19 +20,16 @@ const OUTPUT: &str = "output"; #[derive(Debug, ThisError)] pub enum Error { /// Database operation error. - #[error("Error operating the database: {0}")] - Database(#[from] LmdbError), - #[error("Error deserializing raw key of block header DB element: {0}")] - InvalidKey(usize), #[error("Error serializing output: {0}")] JsonSerialize(#[from] JsonSerializationError), #[error("Error writing output: {0}")] Output(#[from] IoError), - /// Parsing error on entry at index in the database. - #[error("Error parsing element for block hash {0} in {1} DB: {2}")] - Parsing(BlockHash, String, BincodeError), #[error("Error serializing execution results: {0}")] Serialize(#[from] BincodeError), + #[error("Block store error: {0}")] + BlockStore(#[from] BlockStoreError), + #[error("Empty database.")] + EmptyDatabase, } enum DisplayOrder { diff --git a/src/subcommands/execution_results_summary/block_body.rs b/src/subcommands/execution_results_summary/block_body.rs deleted file mode 100644 index cdb2a35..0000000 --- a/src/subcommands/execution_results_summary/block_body.rs +++ /dev/null @@ -1,50 +0,0 @@ -/// The [`BlockBody`] struct had to be copied over from `casper-node` because -/// it isn't exported outside of the crate. -use std::fmt::{Display, Formatter, Result as FmtResult}; - -use casper_hashing::Digest; -use casper_node::types::DeployHash; -use casper_types::PublicKey; -use once_cell::sync::OnceCell; -use serde::{Deserialize, Serialize}; - -/// The body portion of a block. -#[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Debug)] -pub struct BlockBody { - proposer: PublicKey, - pub deploy_hashes: Vec, - pub transfer_hashes: Vec, - #[serde(skip)] - hash: OnceCell, -} - -impl BlockBody { - #[cfg(test)] - /// Creates a new body from deploy and transfer hashes. - pub(crate) fn new(deploy_hashes: Vec) -> Self { - BlockBody { - proposer: PublicKey::System, - deploy_hashes, - transfer_hashes: vec![], - hash: OnceCell::new(), - } - } - - /// Retrieves the deploy hashes within the block. - pub(crate) fn deploy_hashes(&self) -> &Vec { - &self.deploy_hashes - } -} - -impl Display for BlockBody { - fn fmt(&self, formatter: &mut Formatter) -> FmtResult { - write!( - formatter, - "block body proposed by {}, {} deploys, {} transfers", - self.proposer, - self.deploy_hashes.len(), - self.transfer_hashes.len() - )?; - Ok(()) - } -} diff --git a/src/subcommands/execution_results_summary/read_db.rs b/src/subcommands/execution_results_summary/read_db.rs index 48859a4..1c665fe 100644 --- a/src/subcommands/execution_results_summary/read_db.rs +++ b/src/subcommands/execution_results_summary/read_db.rs @@ -5,120 +5,97 @@ use std::{ result::Result, }; -use lmdb::{Cursor, Environment, Transaction}; +use casper_storage::block_store::{ + lmdb::{IndexedLmdbBlockStore, LmdbBlockStore}, + types::{BlockHeight, Tip}, + BlockStoreProvider, DataReader, +}; use log::{info, warn}; use serde_json::{self, Error as JsonSerializationError}; -use casper_node::types::{BlockHash, BlockHeader, DeployMetadata}; +use casper_types::{ + execution::ExecutionResult, Block, BlockHeader, ProtocolVersion, TransactionHash, +}; use crate::common::{ db::{ - self, BlockBodyDatabase, BlockHeaderDatabase, Database, DeployMetadataDatabase, - STORAGE_FILE_NAME, + DEFAULT_MAX_BLOCK_STORE_SIZE, DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + DEFAULT_MAX_DEPLOY_STORE_SIZE, }, - lmdb_utils, progress::ProgressTracker, }; use super::{ - block_body::BlockBody, summary::{ExecutionResultsStats, ExecutionResultsSummary}, Error, }; -fn get_execution_results_stats( - env: &Environment, +fn get_execution_results_stats>( + db_path: P, log_progress: bool, ) -> Result { - let txn = env.begin_ro_txn()?; - let block_header_db = unsafe { txn.open_db(Some(BlockHeaderDatabase::db_name()))? }; - let block_body_db = unsafe { txn.open_db(Some(BlockBodyDatabase::db_name()))? }; - let deploy_metadata_db = unsafe { txn.open_db(Some(DeployMetadataDatabase::db_name()))? }; + let block_store = LmdbBlockStore::new( + db_path.as_ref(), + DEFAULT_MAX_BLOCK_STORE_SIZE + + DEFAULT_MAX_DEPLOY_STORE_SIZE + + DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + )?; - let maybe_entry_count = lmdb_utils::entry_count(&txn, block_header_db).ok(); - let mut maybe_progress_tracker = None; + let indexed_block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::from_parts(0, 0, 0))?; + let ro_txn = indexed_block_store.checkout_ro()?; - let mut stats = ExecutionResultsStats::default(); - if let Ok(mut cursor) = txn.open_ro_cursor(block_header_db) { - if log_progress { - match maybe_entry_count { - Some(entry_count) => { - match ProgressTracker::new( - entry_count, - Box::new(|completion| { - info!("Database parsing {}% complete...", completion) - }), - ) { - Ok(progress_tracker) => maybe_progress_tracker = Some(progress_tracker), - Err(progress_tracker_error) => warn!( - "Couldn't initialize progress tracker: {}", - progress_tracker_error - ), - } - } - None => warn!("Unable to count db entries, progress will not be logged."), + let mut maybe_progress_tracker = None; + let mut block_heights = vec![]; + let latest_block_header = + DataReader::::read(&ro_txn, Tip)?.ok_or(Error::EmptyDatabase)?; + let maybe_block_heights = 0..=latest_block_header.height(); + + if log_progress { + for height in maybe_block_heights { + if DataReader::::exists(&ro_txn, height)? { + block_heights.push(height); } } - // Go through all the block headers in the database. - for (idx, (block_hash_raw, raw_val)) in cursor.iter().enumerate() { - // Deserialize the block hash. - let block_hash = BlockHash::new( - block_hash_raw - .try_into() - .map_err(|_| Error::InvalidKey(idx))?, - ); - // Deserialize the header. - let header: BlockHeader = bincode::deserialize(raw_val).map_err(|bincode_err| { - Error::Parsing( - block_hash, - BlockHeaderDatabase::db_name().to_string(), - bincode_err, - ) - })?; - // Get the body hash for this block. - let block_body_raw = txn.get(block_body_db, header.body_hash())?; - // Get the body of this block. - let block_body: BlockBody = - bincode::deserialize(block_body_raw).map_err(|bincode_err| { - Error::Parsing( - block_hash, - BlockBodyDatabase::db_name().to_string(), - bincode_err, - ) - })?; + match ProgressTracker::new( + block_heights.len(), + Box::new(|completion| info!("Database parsing {}% complete...", completion)), + ) { + Ok(progress_tracker) => maybe_progress_tracker = Some(progress_tracker), + Err(progress_tracker_error) => warn!( + "Couldn't initialize progress tracker: {}", + progress_tracker_error + ), + } + } else { + block_heights = maybe_block_heights.collect(); + } + let mut stats = ExecutionResultsStats::default(); + for block_height in block_heights { + if let Some(block) = DataReader::::read(&ro_txn, block_height)? { // Set of execution results of this block. let mut execution_results = vec![]; - - // Go through all the deploys in this block and get the execution - // result of each one. - for deploy_hash in block_body.deploy_hashes() { - // Get this deploy's metadata. - let metadata_raw = txn.get(deploy_metadata_db, &deploy_hash)?; - let mut metadata: DeployMetadata = - bincode::deserialize(metadata_raw).map_err(|bincode_err| { - Error::Parsing( - block_hash, - DeployMetadataDatabase::db_name().to_string(), - bincode_err, - ) - })?; - // Extract the execution result of this deploy for the current block. - if let Some(execution_result) = metadata.execution_results.remove(&block_hash) { - // Add it to this block's set of execution results. - execution_results.push(execution_result); + // Go through all the transactions in this block and get the execution result of each one. + for transaction_hash in block.all_transaction_hashes() { + if let Some(exec_result) = + DataReader::::read(&ro_txn, transaction_hash)? + { + execution_results.push(exec_result); } } - // Update the statistics with this block's execution results. stats.feed(execution_results)?; if let Some(progress_tracker) = maybe_progress_tracker.as_mut() { progress_tracker.advance_by(1); } + } else { + continue; } } + Ok(stats) } @@ -134,8 +111,6 @@ pub fn execution_results_summary, P2: AsRef>( output: Option, overwrite: bool, ) -> Result<(), Error> { - let storage_path = db_path.as_ref().join(STORAGE_FILE_NAME); - let env = db::db_env(storage_path)?; let mut log_progress = false; // Validate the output file early so that, in case this fails // we don't unnecessarily read the whole database. @@ -150,7 +125,7 @@ pub fn execution_results_summary, P2: AsRef>( Box::new(io::stdout()) }; - let execution_results_stats = get_execution_results_stats(&env, log_progress)?; + let execution_results_stats = get_execution_results_stats(&db_path, log_progress)?; let execution_results_summary: ExecutionResultsSummary = execution_results_stats.into(); dump_execution_results_summary(&execution_results_summary, out_writer)?; diff --git a/src/subcommands/execution_results_summary/summary.rs b/src/subcommands/execution_results_summary/summary.rs index ef9213a..6c99d35 100644 --- a/src/subcommands/execution_results_summary/summary.rs +++ b/src/subcommands/execution_results_summary/summary.rs @@ -1,6 +1,6 @@ use std::collections::BTreeMap; -use casper_types::{bytesrepr::ToBytes, ExecutionResult}; +use casper_types::{bytesrepr::ToBytes, execution::ExecutionResult}; use serde::{Deserialize, Serialize}; use super::Error; diff --git a/src/subcommands/execution_results_summary/tests.rs b/src/subcommands/execution_results_summary/tests.rs index 6cadefe..92c03ab 100644 --- a/src/subcommands/execution_results_summary/tests.rs +++ b/src/subcommands/execution_results_summary/tests.rs @@ -1,20 +1,22 @@ use std::{ collections::BTreeMap, fs::{self, OpenOptions}, - slice, }; -use casper_node::types::{BlockHash, DeployHash}; +use casper_storage::block_store::{ + types::{BlockExecutionResults, BlockHashHeightAndEra}, + BlockStoreProvider, BlockStoreTransaction, DataWriter, +}; use casper_types::bytesrepr::ToBytes; -use lmdb::{Transaction, WriteFlags}; +use casper_types::{ + execution::ExecutionResult, testing::TestRng, Block, TestBlockBuilder, Transaction, +}; use once_cell::sync::Lazy; use rand::Rng; use tempfile::{self, TempDir}; use crate::{ - common::db::{Database, DeployMetadataDatabase, STORAGE_FILE_NAME}, subcommands::execution_results_summary::{ - block_body::BlockBody, read_db, summary::{ chunk_count_after_partition, summarize_map, CollectionStatistics, @@ -22,7 +24,7 @@ use crate::{ }, Error, }, - test_utils::{self, LmdbTestFixture, MockBlockHeader}, + test_utils::{self, LmdbTestFixture}, }; static OUT_DIR: Lazy = Lazy::new(|| tempfile::tempdir().unwrap()); @@ -146,6 +148,7 @@ fn empty_execution_results_stats() { #[test] fn different_execution_results_stats_feed() { + let mut rng = TestRng::new(); let mut stats = ExecutionResultsStats::default(); let mut bincode_sizes = vec![]; let mut bytesrepr_sizes = vec![]; @@ -153,7 +156,7 @@ fn different_execution_results_stats_feed() { for i in 1..4 { let mut execution_results = vec![]; for _ in 0..(10 * i) { - execution_results.push(test_utils::success_execution_result()); + execution_results.push(test_utils::success_execution_result(&mut rng)); } bincode_sizes.push(bincode::serialized_size(&execution_results).unwrap() as usize); bytesrepr_sizes.push(chunk_count_after_partition( @@ -180,20 +183,22 @@ fn different_execution_results_stats_feed() { #[test] fn identical_execution_results_stats_feed() { + let mut rng = TestRng::new(); let mut stats = ExecutionResultsStats::default(); let mut bincode_sizes = vec![]; let mut bytesrepr_sizes = vec![]; + let mut execution_results = vec![]; + for _ in 0..10 { + execution_results.push(test_utils::success_execution_result(&mut rng)); + } + for _ in 1..4 { - let mut execution_results = vec![]; - for _ in 0..10 { - execution_results.push(test_utils::success_execution_result()); - } bincode_sizes.push(bincode::serialized_size(&execution_results).unwrap() as usize); bytesrepr_sizes.push(chunk_count_after_partition( execution_results.serialized_length(), )); - stats.feed(execution_results).unwrap(); + stats.feed(execution_results.clone()).unwrap(); } assert_eq!(stats.execution_results_size.len(), 1); assert_eq!(stats.chunk_count.len(), 1); @@ -224,75 +229,69 @@ fn identical_execution_results_stats_feed() { #[test] fn execution_results_stats_should_succeed() { - const BLOCK_COUNT: usize = 3; - const DEPLOY_COUNT: usize = 4; + const TRANSACTION_COUNT: usize = 7; - let fixture = LmdbTestFixture::new( - vec!["block_header", "block_body", "deploy_metadata"], - Some(STORAGE_FILE_NAME), - ); + let mut rng = TestRng::new(); + + let mut fixture = LmdbTestFixture::new(); let out_file_path = OUT_DIR.as_ref().join("execution_results_summary.json"); - let deploy_hashes: Vec = (0..DEPLOY_COUNT as u8) - .map(test_utils::mock_deploy_hash) + let transactions: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| Transaction::random(&mut rng)) .collect(); - let block_headers: Vec<(BlockHash, MockBlockHeader)> = (0..BLOCK_COUNT as u8) - .map(test_utils::mock_block_header) + + let mut blocks: Vec = vec![]; + let mut block_transactions_map: Vec> = vec![]; + blocks.push( + TestBlockBuilder::new() + .transactions([0, 1, 2].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), + ); + block_transactions_map.push(vec![0, 1, 2]); + blocks.push( + TestBlockBuilder::new() + .transactions([3, 4].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), + ); + block_transactions_map.push(vec![3, 4]); + blocks.push( + TestBlockBuilder::new() + .transactions([5, 6].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), + ); + block_transactions_map.push(vec![5, 6]); + + let exec_results: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| ExecutionResult::random(&mut rng)) .collect(); - let mut block_bodies = vec![]; - let mut block_body_deploy_map: Vec> = vec![]; - block_bodies.push(BlockBody::new(vec![ - deploy_hashes[0], - deploy_hashes[1], - deploy_hashes[3], - ])); - block_body_deploy_map.push(vec![0, 1, 3]); - block_bodies.push(BlockBody::new(vec![deploy_hashes[1], deploy_hashes[2]])); - block_body_deploy_map.push(vec![1, 2]); - block_bodies.push(BlockBody::new(vec![deploy_hashes[2], deploy_hashes[3]])); - block_body_deploy_map.push(vec![2, 3]); - - let deploy_metadatas = vec![ - test_utils::mock_deploy_metadata(slice::from_ref(&block_headers[0].0)), - test_utils::mock_deploy_metadata(&[block_headers[0].0, block_headers[1].0]), - test_utils::mock_deploy_metadata(&[block_headers[1].0, block_headers[2].0]), - test_utils::mock_deploy_metadata(&[block_headers[0].0, block_headers[2].0]), - ]; - - let env = &fixture.env; - // Insert the 3 blocks into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for i in 0..BLOCK_COUNT { - // Store the header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - &block_headers[i].0, - &bincode::serialize(&block_headers[i].1).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the body. - txn.put( - *fixture.db(Some("block_body")).unwrap(), - &block_headers[i].1.body_hash, - &bincode::serialize(&block_bodies[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - // Insert the 4 deploys into the database. - for i in 0..DEPLOY_COUNT { - txn.put( - *fixture.db(Some("deploy_metadata")).unwrap(), - &deploy_hashes[i], - &bincode::serialize(&deploy_metadatas[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + + for transaction in transactions.iter() { + let _ = rw_txn.write(transaction).unwrap(); + } + + for (block_id, block) in blocks.iter().enumerate() { + let block_hash = rw_txn.write(block).unwrap(); + + let height = block.height(); + let era = block.era_id(); + + let block_info = BlockHashHeightAndEra::new(block_hash, height, era); + + let block_exec_results = BlockExecutionResults { + block_info, + exec_results: block_transactions_map[block_id] + .iter() + .map(|id| (transactions[*id].hash(), exec_results[*id].clone())) + .collect(), + }; + rw_txn.write(&block_exec_results).unwrap(); + } + rw_txn.commit().unwrap(); // Get the execution results summary and ensure it matches with the // expected statistics. @@ -308,17 +307,10 @@ fn execution_results_stats_should_succeed() { // Construct the expected statistics. let mut stats = ExecutionResultsStats::default(); - for (block_idx, (block_hash, _block_header)) in block_headers.iter().enumerate() { - let _block_body = &block_bodies[block_idx]; + for (block_idx, _block) in blocks.iter().enumerate() { let mut execution_results = vec![]; - for metadata_idx in &block_body_deploy_map[block_idx] { - execution_results.push( - deploy_metadatas[*metadata_idx] - .execution_results - .get(block_hash) - .unwrap() - .clone(), - ); + for exec_result_idx in &block_transactions_map[block_idx] { + execution_results.push(exec_results[*exec_result_idx].clone()); } stats.feed(execution_results).unwrap(); } @@ -326,118 +318,9 @@ fn execution_results_stats_should_succeed() { assert_eq!(execution_results_summary, expected_summary); } -#[test] -fn execution_results_summary_invalid_key_should_fail() { - let fixture = LmdbTestFixture::new( - vec!["block_header", "block_body", "deploy_metadata"], - Some(STORAGE_FILE_NAME), - ); - let out_file_path = OUT_DIR.as_ref().join("invalid_key.json"); - - let env = &fixture.env; - if let Ok(mut txn) = env.begin_rw_txn() { - let (_, block_header) = test_utils::mock_block_header(0); - let bogus_hash = [0u8; 1]; - // Insert a block header in the database with a key that can't be - // deserialized. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - &bogus_hash, - &bincode::serialize(&block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - txn.commit().unwrap(); - }; - - match read_db::execution_results_summary( - fixture.tmp_dir.as_ref(), - Some(out_file_path.as_path()), - false, - ) { - Err(Error::InvalidKey(idx)) => assert_eq!(idx, 0), - Err(error) => panic!("Got unexpected error: {error:?}"), - Ok(_) => panic!("Command unexpectedly succeeded"), - } -} - -#[test] -fn execution_results_summary_parsing_should_fail() { - let fixture = LmdbTestFixture::new( - vec!["block_header", "block_body", "deploy_metadata"], - Some(STORAGE_FILE_NAME), - ); - let out_file_path = OUT_DIR.as_ref().join("parsing.json"); - - let deploy_hash = test_utils::mock_deploy_hash(0); - let (block_hash, block_header) = test_utils::mock_block_header(0); - let block_body = BlockBody::new(vec![deploy_hash]); - - let env = &fixture.env; - if let Ok(mut txn) = env.begin_rw_txn() { - // Store the header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - &block_hash, - &bincode::serialize(&block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the body. - txn.put( - *fixture.db(Some("block_body")).unwrap(), - &block_header.body_hash, - &bincode::serialize(&block_body).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store a bogus metadata under the deploy hash key we used before. - txn.put( - *fixture.db(Some("deploy_metadata")).unwrap(), - &deploy_hash, - &"bogus_deploy_metadata".to_bytes().unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - txn.commit().unwrap(); - }; - - match read_db::execution_results_summary( - fixture.tmp_dir.as_ref(), - Some(out_file_path.as_path()), - false, - ) { - Err(Error::Parsing(hash, db_name, _bincode_err)) => { - assert_eq!(hash, block_hash); - assert_eq!(db_name, DeployMetadataDatabase::db_name()); - } - Err(error) => panic!("Got unexpected error: {error:?}"), - Ok(_) => panic!("Command unexpectedly succeeded"), - } -} - -#[test] -fn execution_results_summary_bogus_db_should_fail() { - let fixture = LmdbTestFixture::new(vec!["bogus"], Some(STORAGE_FILE_NAME)); - let out_file_path = OUT_DIR.as_ref().join("bogus_db.json"); - - match read_db::execution_results_summary( - fixture.tmp_dir.as_ref(), - Some(out_file_path.as_path()), - false, - ) { - Err(Error::Database(_)) => { /* expected result */ } - Err(error) => panic!("Got unexpected error: {error:?}"), - Ok(_) => panic!("Command unexpectedly succeeded"), - } -} - #[test] fn execution_results_summary_existing_output_should_fail() { - let fixture = LmdbTestFixture::new( - vec!["block_header", "block_body", "deploy_metadata"], - Some(STORAGE_FILE_NAME), - ); + let fixture = LmdbTestFixture::new(); let out_file_path = OUT_DIR.as_ref().join("existing.json"); let _ = OpenOptions::new() .create_new(true) diff --git a/src/subcommands/extract_slice.rs b/src/subcommands/extract_slice.rs index 4865368..3c47d85 100644 --- a/src/subcommands/extract_slice.rs +++ b/src/subcommands/extract_slice.rs @@ -1,4 +1,3 @@ -mod db_helpers; mod extract; mod global_state; mod storage; @@ -8,10 +7,12 @@ mod tests; use std::{io::Error as IoError, path::Path}; use bincode::Error as BincodeError; -use casper_hashing::Digest; -use casper_node::types::BlockHash; +use casper_storage::block_store::BlockStoreError; +use casper_storage::global_state::error::Error as GlobalStateError; +use casper_types::BlockHash; +use casper_types::Digest; +use casper_types::TransactionHash; use clap::{Arg, ArgMatches, Command}; -use lmdb::Error as LmdbError; use thiserror::Error as ThisError; use self::extract::SliceIdentifier; @@ -30,15 +31,21 @@ pub enum Error { #[error("Error creating the destination execution engine: {0}")] CreateExecutionEngine(anyhow::Error), #[error("Error operating the database: {0}")] - Database(#[from] LmdbError), + GlobalState(#[from] GlobalStateError), #[error("Error loading the source execution engine: {0}")] LoadExecutionEngine(anyhow::Error), #[error("Error writing output: {0}")] Output(#[from] IoError), - #[error("Error parsing element for block hash {0} in {1} DB: {2}")] - Parsing(BlockHash, String, BincodeError), #[error("Error transferring state root: {0}")] StateRootTransfer(anyhow::Error), + #[error("Encountered an error with the block store: {0}")] + BlockStore(#[from] BlockStoreError), + #[error("Missing block with hash: {0}")] + MissingBlock(BlockHash), + #[error("Missing transaction with hash: {0}")] + MissingTransaction(TransactionHash), + #[error("Missing execution result for transaction with hash: {0}")] + MissingExecutionResult(TransactionHash), } enum DisplayOrder { diff --git a/src/subcommands/extract_slice/db_helpers.rs b/src/subcommands/extract_slice/db_helpers.rs deleted file mode 100644 index c57973b..0000000 --- a/src/subcommands/extract_slice/db_helpers.rs +++ /dev/null @@ -1,39 +0,0 @@ -use std::result::Result; - -use lmdb::{Error as LmdbError, RoTransaction, RwTransaction, Transaction, WriteFlags}; - -/// Reads the value under a key in a database using the given LMDB transaction. -pub(crate) fn read_from_db>( - txn: &mut RoTransaction, - db_name: &str, - key: &K, -) -> Result, LmdbError> { - let db = unsafe { txn.open_db(Some(db_name))? }; - let value = txn.get(db, key)?.to_vec(); - Ok(value) -} - -/// Writes a key-value pair in a database using the given LMDB transaction. -pub(crate) fn write_to_db, V: AsRef<[u8]>>( - txn: &mut RwTransaction, - db_name: &str, - key: &K, - value: &V, -) -> Result<(), LmdbError> { - let db = unsafe { txn.open_db(Some(db_name))? }; - txn.put(db, key, value, WriteFlags::empty())?; - Ok(()) -} - -/// Copies the value under a key from the source database to the destination -/// database and returns the raw value bytes. -pub(crate) fn transfer_to_new_db>( - source_txn: &mut RoTransaction, - destination_txn: &mut RwTransaction, - db_name: &str, - key: &K, -) -> Result, LmdbError> { - let value = read_from_db(source_txn, db_name, key)?; - write_to_db(destination_txn, db_name, key, &value)?; - Ok(value) -} diff --git a/src/subcommands/extract_slice/extract.rs b/src/subcommands/extract_slice/extract.rs index 5427b6f..c1cbe50 100644 --- a/src/subcommands/extract_slice/extract.rs +++ b/src/subcommands/extract_slice/extract.rs @@ -1,7 +1,7 @@ use std::path::Path; -use casper_hashing::Digest; -use casper_node::types::BlockHash; +use casper_types::BlockHash; +use casper_types::Digest; use super::{global_state, storage, Error}; @@ -15,7 +15,7 @@ pub fn extract_slice, P2: AsRef>( output: P2, slice_identifier: SliceIdentifier, ) -> Result<(), Error> { - storage::create_output_db(&output)?; + storage::create_output_db_dir(&output)?; let state_root_hash = match slice_identifier { SliceIdentifier::BlockHash(block_hash) => { storage::transfer_block_info(&db_path, &output, block_hash)? diff --git a/src/subcommands/extract_slice/global_state.rs b/src/subcommands/extract_slice/global_state.rs index 5cd5d9e..6d6a9c2 100644 --- a/src/subcommands/extract_slice/global_state.rs +++ b/src/subcommands/extract_slice/global_state.rs @@ -1,10 +1,11 @@ use std::{path::Path, result::Result}; -use casper_hashing::Digest; +use casper_storage::{data_access_layer::FlushRequest, global_state::state::StateProvider}; +use casper_types::Digest; use log::info; use crate::subcommands::trie_compact::{ - copy_state_root, create_execution_engine, load_execution_engine, DEFAULT_MAX_DB_SIZE, + copy_state_root, create_data_access_layer, load_data_access_layer, DEFAULT_MAX_DB_SIZE, }; use super::Error; @@ -21,17 +22,20 @@ pub(crate) fn transfer_global_state, P2: AsRef>( .expect("should be able to parse max db size"); // Load the source trie store. - let (source_state, _env) = load_execution_engine(source, max_db_size, Digest::default(), true) + let source_state = load_data_access_layer(source, max_db_size, Digest::default(), true) .map_err(Error::LoadExecutionEngine)?; // Create the destination trie store. - let (destination_state, _env) = create_execution_engine(destination, max_db_size, true) + let destination_state = create_data_access_layer(destination, max_db_size, true) .map_err(Error::CreateExecutionEngine)?; info!("Starting transfer process for state root hash {state_root_hash}"); // Copy the state root along with missing descendants over to the new trie // store. copy_state_root(state_root_hash, &source_state, &destination_state) .map_err(Error::StateRootTransfer)?; - destination_state.flush_environment()?; + destination_state + .flush(FlushRequest::new()) + .as_error() + .map_err(Error::GlobalState)?; Ok(()) } diff --git a/src/subcommands/extract_slice/storage.rs b/src/subcommands/extract_slice/storage.rs index 6e8e9b3..387d501 100644 --- a/src/subcommands/extract_slice/storage.rs +++ b/src/subcommands/extract_slice/storage.rs @@ -1,39 +1,33 @@ -use std::{fs, io::ErrorKind, path::Path, result::Result}; +use std::{collections::BTreeSet, fs, io::ErrorKind, path::Path, result::Result}; -use casper_hashing::Digest; -use lmdb::{DatabaseFlags, Error as LmdbError, Transaction}; +use casper_storage::block_store::{ + lmdb::LmdbBlockStore, + types::{ + ApprovalsHashes, BlockExecutionResults, BlockHashHeightAndEra, BlockTransfers, + ExecutionResults, TransactionFinalizedApprovals, + }, + BlockStoreProvider, BlockStoreTransaction, DataReader, DataWriter, +}; -use casper_node::types::{BlockHash, BlockHeader, DeployMetadata}; -use log::info; +use casper_types::{ + execution::ExecutionResult, Approval, Block, BlockHash, BlockSignatures, Digest, Transaction, + Transfer, +}; +use log::{info, warn}; -use crate::{ - common::db::{ - self, BlockBodyDatabase, BlockHeaderDatabase, Database, DeployDatabase, - DeployMetadataDatabase, TransferDatabase, STORAGE_FILE_NAME, - }, - subcommands::execution_results_summary::block_body::BlockBody, +use crate::common::db::{ + DEFAULT_MAX_BLOCK_STORE_SIZE, DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + DEFAULT_MAX_DEPLOY_STORE_SIZE, STORAGE_FILE_NAME, }; -use super::{db_helpers, Error}; +use super::Error; -pub(crate) fn create_output_db>(output_path: P) -> Result<(), Error> { +pub(crate) fn create_output_db_dir>(output_path: P) -> Result<(), Error> { if output_path.as_ref().exists() { return Err(Error::Output(ErrorKind::AlreadyExists.into())); } fs::create_dir_all(&output_path)?; - let storage_path = output_path.as_ref().join(STORAGE_FILE_NAME); - let storage_env = db::db_env(storage_path)?; - - storage_env.create_db(Some(BlockHeaderDatabase::db_name()), DatabaseFlags::empty())?; - storage_env.create_db(Some(BlockBodyDatabase::db_name()), DatabaseFlags::empty())?; - storage_env.create_db(Some(DeployDatabase::db_name()), DatabaseFlags::empty())?; - storage_env.create_db(Some(TransferDatabase::db_name()), DatabaseFlags::empty())?; - storage_env.create_db( - Some(DeployMetadataDatabase::db_name()), - DatabaseFlags::empty(), - )?; - Ok(()) } @@ -47,12 +41,7 @@ pub(crate) fn transfer_block_info, P2: AsRef>( block_hash: BlockHash, ) -> Result { let source_path = source.as_ref().join(STORAGE_FILE_NAME); - let source_env = db::db_env(&source_path)?; let destination_path = destination.as_ref().join(STORAGE_FILE_NAME); - let destination_env = db::db_env(&destination_path)?; - - let mut source_txn = source_env.begin_ro_txn()?; - let mut destination_txn = destination_env.begin_rw_txn()?; info!( "Initiating block information transfer from {} to {} for block {block_hash}", @@ -60,84 +49,116 @@ pub(crate) fn transfer_block_info, P2: AsRef>( destination_path.to_string_lossy() ); - // Read the block header associated with the given block hash. - let block_header_bytes = db_helpers::transfer_to_new_db( - &mut source_txn, - &mut destination_txn, - BlockHeaderDatabase::db_name(), - &block_hash, + let source_store = LmdbBlockStore::new( + source.as_ref(), + DEFAULT_MAX_BLOCK_STORE_SIZE + + DEFAULT_MAX_DEPLOY_STORE_SIZE + + DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, )?; - info!("Successfully transferred block header"); - let block_header: BlockHeader = bincode::deserialize(&block_header_bytes)?; - - // Read the block body associated with the previously read block header. - let block_body_bytes = db_helpers::transfer_to_new_db( - &mut source_txn, - &mut destination_txn, - BlockBodyDatabase::db_name(), - block_header.body_hash(), + let source_txn = source_store.checkout_ro()?; + + let mut destination_store = LmdbBlockStore::new( + destination.as_ref(), + DEFAULT_MAX_BLOCK_STORE_SIZE + + DEFAULT_MAX_DEPLOY_STORE_SIZE + + DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, )?; - info!("Successfully transferred block body"); - let block_body: BlockBody = bincode::deserialize(&block_body_bytes)?; + let mut destination_txn = destination_store.checkout_rw()?; + + // Read the block header and body associated with the given block hash. + let block: Block = source_txn + .read(block_hash)? + .ok_or(Error::MissingBlock(block_hash))?; + let block_height = block.height(); + let block_era = block.era_id(); + let state_root_hash = *block.state_root_hash(); + + let hash = destination_txn.write(&block)?; + debug_assert!(hash == block_hash); + info!("Successfully transferred block"); + + let mut exec_results = ExecutionResults::new(); + + // Copy over all the transactions in this block and construct the execution + // results to be stored in the new database. + for transaction_hash in block.all_transaction_hashes() { + let transaction: Transaction = source_txn + .read(transaction_hash)? + .ok_or(Error::MissingTransaction(transaction_hash))?; + let hash = destination_txn.write(&transaction)?; + debug_assert!(hash == transaction_hash); + + let maybe_finalized_approvals: Option> = + source_txn.read(transaction_hash)?; + + if let Some(finalized_approvals) = maybe_finalized_approvals { + let transaction_approvals = TransactionFinalizedApprovals { + transaction_hash, + finalized_approvals, + }; + + let hash = destination_txn.write(&transaction_approvals)?; + debug_assert!(hash == transaction_hash); + } else { + warn!("Missing approvals hashes for transaction {transaction_hash}"); + } + + let exec_result: ExecutionResult = source_txn + .read(transaction_hash)? + .ok_or(Error::MissingExecutionResult(transaction_hash))?; + exec_results.insert(transaction_hash, exec_result); + + info!("Successfully transferred transaction and approvals for {transaction_hash}"); + } + + if exec_results.is_empty() { + info!("No execution results found in the source DB for block {block_hash}"); + } else { + let block_info = BlockHashHeightAndEra::new(block_hash, block_height, block_era); + let block_execution_results = BlockExecutionResults { + block_info, + exec_results, + }; + destination_txn.write(&block_execution_results)?; + info!("Successfully transferred block execution results for block {block_hash}"); + } // Attempt to copy over all entries in the transfer database for the given // block hash. If we have no entry under the block hash, we move on. - match db_helpers::transfer_to_new_db( - &mut source_txn, - &mut destination_txn, - TransferDatabase::db_name(), - &block_hash, - ) { - Ok(_) => info!("Found transfers in the source DB and successfully transferred them"), - Err(LmdbError::NotFound) => info!("No transfers found in the source DB"), - Err(lmdb_error) => return Err(Error::Database(lmdb_error)), + let maybe_transfers: Option> = source_txn.read(block_hash)?; + if let Some(transfers) = maybe_transfers { + let block_transfers = BlockTransfers { + block_hash, + transfers, + }; + let hash = destination_txn.write(&block_transfers)?; + debug_assert!(hash == block_hash); + info!("Found transfers in the source DB for block {block_hash} and successfully transferred them"); + } else { + info!("No transfers found in the source DB for block {block_hash}"); } - // Copy over all the deploys in this block and construct the execution - // results to be stored in the new database. - let deploy_metadata_db = - unsafe { source_txn.open_db(Some(DeployMetadataDatabase::db_name()))? }; - for deploy_hash in block_body.deploy_hashes() { - // Copy the deploy to the new database. - db_helpers::transfer_to_new_db( - &mut source_txn, - &mut destination_txn, - DeployDatabase::db_name(), - deploy_hash, - )?; - info!("Successfully transferred deploy {deploy_hash}"); - - // Get this deploy's metadata. - let metadata_raw = source_txn.get(deploy_metadata_db, &deploy_hash)?; - let mut metadata: DeployMetadata = - bincode::deserialize(metadata_raw).map_err(|bincode_err| { - Error::Parsing( - block_hash, - DeployMetadataDatabase::db_name().to_string(), - bincode_err, - ) - })?; - // Extract the execution result of this deploy for this block. - if let Some(execution_result) = metadata.execution_results.remove(&block_hash) { - // Construct the metadata to be stored using only the relevant - // execution results. - let mut new_metadata = DeployMetadata::default(); - new_metadata - .execution_results - .insert(block_hash, execution_result.clone()); - let serialized_new_metadata = bincode::serialize(&new_metadata)?; - db_helpers::write_to_db( - &mut destination_txn, - DeployMetadataDatabase::db_name(), - deploy_hash, - &serialized_new_metadata, - )?; - info!("Successfully transferred execution results for {deploy_hash}"); - } + let maybe_signatures: Option = source_txn.read(block_hash)?; + if let Some(signatures) = maybe_signatures { + let hash = destination_txn.write(&signatures)?; + debug_assert!(hash == block_hash); + info!("Found block signatures in the source DB for block {block_hash} and successfully transferred them"); + } else { + info!("No block signatures found in the source DB for block {block_hash}"); } + + let maybe_approvals_hashes: Option = source_txn.read(block_hash)?; + if let Some(approvals_hashes) = maybe_approvals_hashes { + let hash = destination_txn.write(&approvals_hashes)?; + debug_assert!(hash == block_hash); + info!("Found block approvals hashes in the source DB for block {block_hash} and successfully transferred them"); + } else { + info!("No block approvals hashes found in the source DB for block {block_hash}"); + } + // Commit the transactions. source_txn.commit()?; destination_txn.commit()?; info!("Storage transfer complete"); - Ok(*block_header.state_root_hash()) + Ok(state_root_hash) } diff --git a/src/subcommands/extract_slice/tests.rs b/src/subcommands/extract_slice/tests.rs index 526b549..fea110a 100644 --- a/src/subcommands/extract_slice/tests.rs +++ b/src/subcommands/extract_slice/tests.rs @@ -1,247 +1,97 @@ -use std::slice; - -use casper_execution_engine::storage::{ - store::StoreExt, - transaction_source::{lmdb::LmdbEnvironment, TransactionSource}, - trie::Trie, - trie_store::lmdb::LmdbTrieStore, +use casper_storage::{ + block_store::{ + types::{BlockExecutionResults, BlockHashHeightAndEra, BlockTransfers}, + BlockStoreProvider, BlockStoreTransaction, DataReader, DataWriter, + }, + global_state::{store::StoreExt, transaction_source::TransactionSource, trie::Trie}, }; -use casper_hashing::Digest; -use casper_node::types::{BlockHash, DeployHash, DeployMetadata}; use casper_types::bytesrepr::{Bytes, ToBytes}; -use lmdb::{DatabaseFlags, Error as LmdbError, Transaction, WriteFlags}; +use casper_types::{ + execution::ExecutionResult, testing::TestRng, Block, BlockHeader, Digest, TestBlockBuilder, + Transaction, Transfer, +}; +use lmdb::Transaction as LmdbTransaction; use crate::{ - common::db::{ - BlockBodyDatabase, BlockHeaderDatabase, Database, DeployDatabase, DeployMetadataDatabase, - TransferDatabase, STORAGE_FILE_NAME, - }, subcommands::{ - execution_results_summary::block_body::BlockBody, - extract_slice::{db_helpers, global_state, storage}, - trie_compact::{ - create_execution_engine, load_execution_engine, tests::create_data, DEFAULT_MAX_DB_SIZE, - }, - }, - test_utils::{ - mock_block_header, mock_deploy_hash, mock_deploy_metadata, LmdbTestFixture, MockBlockHeader, + extract_slice::{global_state, storage}, + trie_compact::{create_data_access_layer, tests::create_data, DEFAULT_MAX_DB_SIZE}, }, + test_utils::LmdbTestFixture, }; #[test] -fn transfer_data_between_dbs() { - const DATA_COUNT: usize = 4; - const MOCK_DB_NAME: &str = "mock_data"; +fn transfer_blocks() { + const TRANSFER_COUNT: usize = 3; - let source_fixture = LmdbTestFixture::new(vec![MOCK_DB_NAME], Some(STORAGE_FILE_NAME)); + const TRANSACTION_COUNT: usize = 7; + let mut rng = TestRng::new(); - let deploy_hashes: Vec = (0..DATA_COUNT as u8).map(mock_deploy_hash).collect(); + let mut source_fixture = LmdbTestFixture::new(); - { - let env = &source_fixture.env; - // Insert the 3 blocks into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for (i, deploy_hash) in deploy_hashes.iter().enumerate().take(DATA_COUNT) { - txn.put( - *source_fixture.db(Some(MOCK_DB_NAME)).unwrap(), - &i.to_le_bytes(), - &bincode::serialize(deploy_hash).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; - } + let transactions: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| Transaction::random(&mut rng)) + .collect(); - let destination_fixture = LmdbTestFixture::new(vec![MOCK_DB_NAME], Some(STORAGE_FILE_NAME)); + let mut blocks: Vec = vec![]; + let mut block_transactions_map: Vec> = vec![]; + blocks.push( + TestBlockBuilder::new() + .transactions([0, 1, 2].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), + ); + block_transactions_map.push(vec![0, 1, 2]); + blocks.push( + TestBlockBuilder::new() + .transactions([3, 4].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), + ); + block_transactions_map.push(vec![3, 4]); + blocks.push( + TestBlockBuilder::new() + .transactions([5, 6].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), + ); + block_transactions_map.push(vec![5, 6]); - { - let mut source_txn = source_fixture.env.begin_ro_txn().unwrap(); - assert_eq!( - db_helpers::read_from_db(&mut source_txn, MOCK_DB_NAME, &0usize.to_le_bytes()).unwrap(), - bincode::serialize(&deploy_hashes[0]).unwrap() - ); - assert_eq!( - db_helpers::read_from_db(&mut source_txn, MOCK_DB_NAME, &DATA_COUNT.to_le_bytes()) - .unwrap_err(), - LmdbError::NotFound - ); - source_txn.commit().unwrap(); - } + let exec_results: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| ExecutionResult::random(&mut rng)) + .collect(); - { - let mut destination_txn = destination_fixture.env.begin_rw_txn().unwrap(); - let serialized_deploy_hash = bincode::serialize(&deploy_hashes[1]).unwrap(); - assert!(db_helpers::write_to_db( - &mut destination_txn, - MOCK_DB_NAME, - &1usize.to_le_bytes(), - &serialized_deploy_hash - ) - .is_ok()); - destination_txn.commit().unwrap(); - } + let mut rw_txn = source_fixture.block_store.checkout_rw().unwrap(); - { - let mut source_txn = source_fixture.env.begin_ro_txn().unwrap(); - let mut destination_txn = destination_fixture.env.begin_rw_txn().unwrap(); - let serialized_deploy_hash = bincode::serialize(&deploy_hashes[2]).unwrap(); - let copied_bytes = db_helpers::transfer_to_new_db( - &mut source_txn, - &mut destination_txn, - MOCK_DB_NAME, - &2usize.to_le_bytes(), - ) - .unwrap(); - assert_eq!(serialized_deploy_hash, copied_bytes); - assert_eq!( - db_helpers::transfer_to_new_db( - &mut source_txn, - &mut destination_txn, - MOCK_DB_NAME, - &DATA_COUNT.to_le_bytes() - ) - .unwrap_err(), - LmdbError::NotFound - ); - source_txn.commit().unwrap(); - destination_txn.commit().unwrap(); + // Insert the transactions in the database. + for transaction in transactions.iter() { + let _ = rw_txn.write(transaction).unwrap(); } - { - let destination_txn = destination_fixture.env.begin_ro_txn().unwrap(); - let destination_db = destination_fixture.db(Some(MOCK_DB_NAME)).unwrap(); - assert_eq!( - destination_txn - .get(*destination_db, &0usize.to_le_bytes()) - .unwrap_err(), - LmdbError::NotFound - ); - assert_eq!( - destination_txn - .get(*destination_db, &1usize.to_le_bytes()) - .unwrap(), - bincode::serialize(&deploy_hashes[1]).unwrap() - ); - assert_eq!( - destination_txn - .get(*destination_db, &2usize.to_le_bytes()) - .unwrap(), - bincode::serialize(&deploy_hashes[2]).unwrap() - ); - assert_eq!( - destination_txn - .get(*destination_db, &DATA_COUNT.to_le_bytes()) - .unwrap_err(), - LmdbError::NotFound - ); - destination_txn.commit().unwrap(); - } -} + // Insert the 3 blocks into the database. + for (block_id, block) in blocks.iter().enumerate() { + let block_hash = rw_txn.write(block).unwrap(); -#[test] -fn transfer_blocks() { - const BLOCK_COUNT: usize = 3; - const DEPLOY_COUNT: usize = 4; - - let source_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - DeployDatabase::db_name(), - TransferDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), - ); + let height = block.height(); + let era = block.era_id(); - let deploy_hashes: Vec = (0..DEPLOY_COUNT as u8).map(mock_deploy_hash).collect(); - let block_headers: Vec<(BlockHash, MockBlockHeader)> = - (0..BLOCK_COUNT as u8).map(mock_block_header).collect(); - let mut block_bodies = vec![]; - let mut block_body_deploy_map: Vec> = vec![]; - block_bodies.push(BlockBody::new(vec![ - deploy_hashes[0], - deploy_hashes[1], - deploy_hashes[3], - ])); - block_body_deploy_map.push(vec![0, 1, 3]); - block_bodies.push(BlockBody::new(vec![deploy_hashes[1], deploy_hashes[2]])); - block_body_deploy_map.push(vec![1, 2]); - block_bodies.push(BlockBody::new(vec![deploy_hashes[2], deploy_hashes[3]])); - block_body_deploy_map.push(vec![2, 3]); - - let deploy_metadatas = vec![ - mock_deploy_metadata(slice::from_ref(&block_headers[0].0)), - mock_deploy_metadata(&[block_headers[0].0, block_headers[1].0]), - mock_deploy_metadata(&[block_headers[1].0, block_headers[2].0]), - mock_deploy_metadata(&[block_headers[0].0, block_headers[2].0]), - ]; - - let env = &source_fixture.env; - // Insert the 3 blocks into the database. - { - let mut txn = env.begin_rw_txn().unwrap(); - for i in 0..BLOCK_COUNT { - // Store the header. - txn.put( - *source_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[i].0, - &bincode::serialize(&block_headers[i].1).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the body. - txn.put( - *source_fixture - .db(Some(BlockBodyDatabase::db_name())) - .unwrap(), - &block_headers[i].1.body_hash, - &bincode::serialize(&block_bodies[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } + let block_info = BlockHashHeightAndEra::new(block_hash, height, era); - // Insert the 4 deploys into the deploys and deploy_metadata databases. - for i in 0..DEPLOY_COUNT { - txn.put( - *source_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[i], - &bincode::serialize(&deploy_metadatas[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Add mock deploy data in the database. - txn.put( - *source_fixture.db(Some(DeployDatabase::db_name())).unwrap(), - &deploy_hashes[i], - &bincode::serialize(&deploy_hashes[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; - - let destination_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - DeployDatabase::db_name(), - TransferDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), - ); + let block_exec_results = BlockExecutionResults { + block_info, + exec_results: block_transactions_map[block_id] + .iter() + .map(|id| (transactions[*id].hash(), exec_results[*id].clone())) + .collect(), + }; + rw_txn.write(&block_exec_results).unwrap(); + } + rw_txn.commit().unwrap(); + + let destination_fixture = LmdbTestFixture::new(); - let block_hash_0 = block_headers[0].0; - let expected_state_root_hash = block_headers[0].1.state_root_hash; + let block_hash_0 = *blocks[0].hash(); + let expected_state_root_hash = *blocks[0].state_root_hash(); let actual_state_root_hash = storage::transfer_block_info( source_fixture.tmp_dir.path(), destination_fixture.tmp_dir.path(), @@ -251,102 +101,49 @@ fn transfer_blocks() { assert_eq!(expected_state_root_hash, actual_state_root_hash); { - let txn = destination_fixture.env.begin_ro_txn().unwrap(); - let actual_block_header: MockBlockHeader = txn - .get( - *destination_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_hash_0, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert_eq!(actual_block_header, block_headers[0].1); - - let actual_block_body: BlockBody = txn - .get( - *destination_fixture - .db(Some(BlockBodyDatabase::db_name())) - .unwrap(), - &actual_block_header.body_hash, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert_eq!(actual_block_body, block_bodies[0]); - - for deploy_hash in actual_block_body.deploy_hashes() { - let actual_mock_deploy: DeployHash = txn - .get( - *destination_fixture - .db(Some(DeployDatabase::db_name())) - .unwrap(), - deploy_hash, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert_eq!(*deploy_hash, actual_mock_deploy); - - let mut actual_deploy_metadata: DeployMetadata = txn - .get( - *destination_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - deploy_hash, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert!(actual_deploy_metadata - .execution_results - .remove(&block_hash_0) - .is_some()); - assert!(actual_deploy_metadata.execution_results.is_empty()); + let txn = destination_fixture.block_store.checkout_ro().unwrap(); + let actual_block_header: Option = txn.read(block_hash_0).unwrap(); + assert_eq!(actual_block_header, Some(blocks[0].clone_header())); + + let actual_block: Option = txn.read(block_hash_0).unwrap(); + assert_eq!(actual_block, Some(blocks[0].clone())); + + for transaction_hash in actual_block.unwrap().all_transaction_hashes() { + // Check if the transactions are stored + let transaction: Option = txn.read(transaction_hash).unwrap(); + assert!(transaction.is_some()); + assert_eq!(transaction_hash, transaction.unwrap().hash()); + + let exec_result: Option = txn.read(transaction_hash).unwrap(); + assert!(exec_result.is_some()); } - assert_eq!( - txn.get( - *destination_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[1].0, - ) - .unwrap_err(), - LmdbError::NotFound - ); - assert_eq!( - txn.get( - *destination_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[2].0, - ) - .unwrap_err(), - LmdbError::NotFound - ); + let block_header: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(block_header.is_none()); + let block_header: Option = txn.read(*blocks[2].hash()).unwrap(); + assert!(block_header.is_none()); txn.commit().unwrap(); } - let block_hash_1 = block_headers[1].0; + let block_hash_1 = *blocks[1].hash(); + let transfers: Vec = (0..TRANSFER_COUNT as u8) + .map(|_| Transfer::random(&mut rng)) + .collect(); // Put some mock data in the transfer DB under block hash 1. { - let mut txn = source_fixture.env.begin_rw_txn().unwrap(); - txn.put( - *source_fixture - .db(Some(TransferDatabase::db_name())) - .unwrap(), - &block_hash_1, - &bincode::serialize(&block_hash_1).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); + let mut txn = source_fixture.block_store.checkout_rw().unwrap(); + + let block_transfers = BlockTransfers { + block_hash: block_hash_1, + transfers: transfers.clone(), + }; + + let _ = txn.write(&block_transfers).unwrap(); txn.commit().unwrap(); } - let expected_state_root_hash = block_headers[1].1.state_root_hash; + let expected_state_root_hash = *blocks[1].state_root_hash(); let actual_state_root_hash = storage::transfer_block_info( source_fixture.tmp_dir.path(), destination_fixture.tmp_dir.path(), @@ -356,83 +153,29 @@ fn transfer_blocks() { assert_eq!(expected_state_root_hash, actual_state_root_hash); { - let txn = destination_fixture.env.begin_ro_txn().unwrap(); - let actual_block_header: MockBlockHeader = txn - .get( - *destination_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_hash_1, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert_eq!(actual_block_header, block_headers[1].1); - - let actual_block_body: BlockBody = txn - .get( - *destination_fixture - .db(Some(BlockBodyDatabase::db_name())) - .unwrap(), - &actual_block_header.body_hash, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert_eq!(actual_block_body, block_bodies[1]); - - let actual_mock_transfer: BlockHash = txn - .get( - *destination_fixture - .db(Some(TransferDatabase::db_name())) - .unwrap(), - &block_hash_1, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert_eq!(block_hash_1, actual_mock_transfer); - - for deploy_hash in actual_block_body.deploy_hashes() { - let actual_mock_deploy: DeployHash = txn - .get( - *destination_fixture - .db(Some(DeployDatabase::db_name())) - .unwrap(), - deploy_hash, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert_eq!(*deploy_hash, actual_mock_deploy); - - let mut actual_deploy_metadata: DeployMetadata = txn - .get( - *destination_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - deploy_hash, - ) - .map(bincode::deserialize) - .unwrap() - .unwrap(); - assert!(actual_deploy_metadata - .execution_results - .remove(&block_hash_1) - .is_some()); - assert!(actual_deploy_metadata.execution_results.is_empty()); + let txn = destination_fixture.block_store.checkout_ro().unwrap(); + let actual_block_header: Option = txn.read(block_hash_1).unwrap(); + assert_eq!(actual_block_header, Some(blocks[1].clone_header())); + + let actual_block: Option = txn.read(block_hash_1).unwrap(); + assert_eq!(actual_block, Some(blocks[1].clone())); + + let actual_transfers: Option> = txn.read(block_hash_1).unwrap(); + assert_eq!(Some(transfers), actual_transfers); + + for transaction_hash in actual_block.unwrap().all_transaction_hashes() { + // Check if the transactions are stored + let transaction: Option = txn.read(transaction_hash).unwrap(); + assert!(transaction.is_some()); + assert_eq!(transaction_hash, transaction.unwrap().hash()); + + let exec_result: Option = txn.read(transaction_hash).unwrap(); + assert!(exec_result.is_some()); } - assert_eq!( - txn.get( - *destination_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[2].0, - ) - .unwrap_err(), - LmdbError::NotFound - ); + let block_header: Option = txn.read(*blocks[2].hash()).unwrap(); + assert!(block_header.is_none()); + txn.commit().unwrap(); } } @@ -444,24 +187,27 @@ fn transfer_global_state_information() { let max_db_size = DEFAULT_MAX_DB_SIZE .parse() .expect("should be able to parse max db size"); - let source_env = LmdbEnvironment::new(source_tmp_dir.path(), max_db_size, 512, true).unwrap(); - let source_store = LmdbTrieStore::new(&source_env, None, DatabaseFlags::empty()).unwrap(); + // Construct mock data. let data = create_data(); + let source = create_data_access_layer(source_tmp_dir.path(), max_db_size, true).unwrap(); + + let source_store = source.state().trie_store(); { // Put the generated data into the source trie. - let mut txn = source_env.create_read_write_txn().unwrap(); + let mut txn = source + .state() + .environment() + .create_read_write_txn() + .unwrap(); let items = data.iter().map(Into::into); source_store.put_many(&mut txn, items).unwrap(); txn.commit().unwrap(); } - let (_source_state, _env) = - load_execution_engine(source_tmp_dir.path(), max_db_size, Digest::default(), true).unwrap(); - - let (_destination_state, dst_env) = - create_execution_engine(destination_tmp_dir.path(), max_db_size, true).unwrap(); + let destination = + create_data_access_layer(destination_tmp_dir.path(), max_db_size, true).unwrap(); // Copy from `node2`, the root of the created trie. All data under node 2, // which has leaf 2 and 3 under it, should be copied. @@ -472,9 +218,13 @@ fn transfer_global_state_information() { ) .unwrap(); - let destination_store = LmdbTrieStore::new(&dst_env, None, DatabaseFlags::empty()).unwrap(); + let destination_store = destination.state().trie_store(); // LmdbTrieStore::new(&dst_env, None, DatabaseFlags::empty()).unwrap(); { - let txn = dst_env.create_read_write_txn().unwrap(); + let txn = destination + .state() + .environment() + .create_read_write_txn() + .unwrap(); let keys = vec![data[1].0, data[2].0, data[4].0]; let entries: Vec>> = destination_store.get_many(&txn, keys.iter()).unwrap(); diff --git a/src/subcommands/latest_block_summary.rs b/src/subcommands/latest_block_summary.rs index dc87942..f5f8a04 100644 --- a/src/subcommands/latest_block_summary.rs +++ b/src/subcommands/latest_block_summary.rs @@ -3,9 +3,9 @@ mod read_db; #[cfg(test)] mod tests; -use std::{array::TryFromSliceError, io::Error as IoError, path::Path}; +use std::{io::Error as IoError, path::Path}; -use bincode::Error as BincodeError; +use casper_storage::block_store::BlockStoreError; use clap::{Arg, ArgMatches, Command}; use lmdb::Error as LmdbError; use serde_json::Error as SerializationError; @@ -21,9 +21,6 @@ const OUTPUT: &str = "output"; pub enum Error { #[error("No blocks found in the block header database")] EmptyDatabase, - /// Parsing error on entry at index in the database. - #[error("Error parsing element {0}: {1}")] - Parsing(usize, BincodeError), /// Database operation error. #[error("Error operating the database: {0}")] Database(#[from] LmdbError), @@ -31,8 +28,8 @@ pub enum Error { Serialize(#[from] SerializationError), #[error("Error writing output: {0}")] Output(#[from] IoError), - #[error("Invalid block hash {err:?} {val}")] - InvalidBlockHash { err: TryFromSliceError, val: String }, + #[error("Block store error: {0}")] + BlockStore(#[from] BlockStoreError), } enum DisplayOrder { diff --git a/src/subcommands/latest_block_summary/block_info.rs b/src/subcommands/latest_block_summary/block_info.rs index 2b8bd3f..5ede9bd 100644 --- a/src/subcommands/latest_block_summary/block_info.rs +++ b/src/subcommands/latest_block_summary/block_info.rs @@ -7,13 +7,10 @@ use std::{ use serde::{Deserialize, Serialize}; -use casper_hashing::Digest; -use casper_node::types::{BlockHash, BlockHeader}; +use casper_types::Digest; +use casper_types::{BlockHash, BlockHeader}; use casper_types::{EraId, ProtocolVersion, Timestamp}; -#[cfg(test)] -use crate::test_utils::MockBlockHeader; - #[derive(Clone, Eq, PartialEq, Serialize, Deserialize, Debug)] pub struct BlockInfo { network_name: Option, @@ -27,13 +24,9 @@ pub struct BlockInfo { } impl BlockInfo { - pub fn new( - network_name: Option, - block_hash: BlockHash, - block_header: BlockHeader, - ) -> Self { + pub fn new(network_name: Option, block_header: BlockHeader) -> Self { Self { - block_hash, + block_hash: block_header.block_hash(), network_name, body_hash: *block_header.body_hash(), era_id: block_header.era_id(), @@ -43,25 +36,6 @@ impl BlockInfo { timestamp: block_header.timestamp(), } } - - #[cfg(test)] - pub fn into_mock(self) -> (MockBlockHeader, Option) { - ( - MockBlockHeader { - body_hash: self.body_hash, - era_id: self.era_id, - height: self.height, - protocol_version: self.protocol_version, - state_root_hash: self.state_root_hash, - timestamp: self.timestamp, - parent_hash: Default::default(), - random_bit: Default::default(), - accumulated_seed: Default::default(), - era_end: None, - }, - self.network_name, - ) - } } pub fn parse_network_name>(path: P) -> Result { diff --git a/src/subcommands/latest_block_summary/read_db.rs b/src/subcommands/latest_block_summary/read_db.rs index 64938be..e4fa03a 100644 --- a/src/subcommands/latest_block_summary/read_db.rs +++ b/src/subcommands/latest_block_summary/read_db.rs @@ -5,17 +5,20 @@ use std::{ result::Result, }; -use casper_hashing::Digest; -use lmdb::{Cursor, Environment, Transaction}; -use log::{info, warn}; +use casper_storage::block_store::{ + lmdb::{IndexedLmdbBlockStore, LmdbBlockStore}, + types::Tip, + BlockStoreProvider, DataReader, +}; +use casper_types::ProtocolVersion; +use log::warn; use serde_json::{self, Error as SerializationError}; -use casper_node::types::{BlockHash, BlockHeader}; +use casper_types::BlockHeader; -use crate::common::{ - db::{self, BlockHeaderDatabase, Database, STORAGE_FILE_NAME}, - lmdb_utils, - progress::ProgressTracker, +use crate::common::db::{ + DEFAULT_MAX_BLOCK_STORE_SIZE, DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + DEFAULT_MAX_DEPLOY_STORE_SIZE, }; use super::{ @@ -23,74 +26,19 @@ use super::{ Error, }; -fn get_highest_block( - env: &Environment, - log_progress: bool, -) -> Result<(BlockHash, BlockHeader), Error> { - let txn = env.begin_ro_txn()?; - let db = unsafe { txn.open_db(Some(BlockHeaderDatabase::db_name()))? }; - - let mut max_height = 0u64; - let mut max_height_key = None; - - let maybe_entry_count = lmdb_utils::entry_count(&txn, db).ok(); - let mut maybe_progress_tracker = None; - - if let Ok(mut cursor) = txn.open_ro_cursor(db) { - if log_progress { - match maybe_entry_count { - Some(entry_count) => { - match ProgressTracker::new( - entry_count, - Box::new(|completion| { - info!("Database parsing {}% complete...", completion) - }), - ) { - Ok(progress_tracker) => maybe_progress_tracker = Some(progress_tracker), - Err(progress_tracker_error) => warn!( - "Couldn't initialize progress tracker: {}", - progress_tracker_error - ), - } - } - None => warn!("Unable to count db entries, progress will not be logged."), - } - } - - for (idx, (raw_key, raw_val)) in cursor.iter().enumerate() { - let header: BlockHeader = bincode::deserialize(raw_val) - .map_err(|bincode_err| Error::Parsing(idx, bincode_err))?; - if header.height() >= max_height { - max_height = header.height(); - let _ = max_height_key.replace(raw_key); - } - - if let Some(progress_tracker) = maybe_progress_tracker.as_mut() { - progress_tracker.advance_by(1); - } - } - } - - let max_height_key = max_height_key.ok_or(Error::EmptyDatabase)?; - let raw_bytes = txn.get(db, &max_height_key)?; - let highest_block_header: BlockHeader = - bincode::deserialize(raw_bytes).map_err(|bincode_err| { - Error::Parsing( - max_height - .try_into() - .expect("block height doesn't fit in usize"), - bincode_err, - ) - })?; +fn get_highest_block>(db_path: P) -> Result { + let block_store = LmdbBlockStore::new( + db_path.as_ref(), + DEFAULT_MAX_BLOCK_STORE_SIZE + + DEFAULT_MAX_DEPLOY_STORE_SIZE + + DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + )?; - let block_hash = Digest::try_from(max_height_key) - .map_err(|err| Error::InvalidBlockHash { - err, - val: String::from_utf8_lossy(max_height_key).to_string(), - })? - .into(); + let indexed_block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::from_parts(0, 0, 0))?; + let ro_txn = indexed_block_store.checkout_ro()?; - Ok((block_hash, highest_block_header)) + DataReader::::read(&ro_txn, Tip)?.ok_or(Error::EmptyDatabase) } pub(crate) fn dump_block_info( @@ -105,9 +53,6 @@ pub fn latest_block_summary, P2: AsRef>( output: Option, overwrite: bool, ) -> Result<(), Error> { - let storage_path = db_path.as_ref().join(STORAGE_FILE_NAME); - let env = db::db_env(storage_path)?; - let mut log_progress = false; // Validate the output file early so that, in case this fails // we don't unnecessarily read the whole database. let out_writer: Box = if let Some(out_path) = output { @@ -115,12 +60,11 @@ pub fn latest_block_summary, P2: AsRef>( .create_new(!overwrite) .write(true) .open(out_path)?; - log_progress = true; Box::new(file) } else { Box::new(io::stdout()) }; - let network_name = match parse_network_name(db_path) { + let network_name = match parse_network_name(&db_path) { Ok(name) => Some(name), Err(io_err) => { warn!("Couldn't derive network name from path: {}", io_err); @@ -128,8 +72,8 @@ pub fn latest_block_summary, P2: AsRef>( } }; - let (block_hash, highest_block) = get_highest_block(&env, log_progress)?; - let block_info = BlockInfo::new(network_name, block_hash, highest_block); + let highest_block_header = get_highest_block(db_path)?; + let block_info = BlockInfo::new(network_name, highest_block_header); dump_block_info(&block_info, out_writer)?; Ok(()) diff --git a/src/subcommands/latest_block_summary/tests.rs b/src/subcommands/latest_block_summary/tests.rs index a23b515..8ef466a 100644 --- a/src/subcommands/latest_block_summary/tests.rs +++ b/src/subcommands/latest_block_summary/tests.rs @@ -1,19 +1,14 @@ use std::fs::{self, OpenOptions}; -use lmdb::{Transaction, WriteFlags}; +use casper_storage::block_store::{BlockStoreProvider, BlockStoreTransaction, DataWriter}; +use casper_types::{testing::TestRng, Block, BlockHash, BlockHeader, TestBlockBuilder}; use once_cell::sync::Lazy; use tempfile::{self, NamedTempFile, TempDir}; -use casper_node::{ - rpcs::docs::DocExample, - types::{BlockHeader, JsonBlockHeader}, -}; - use super::block_info::BlockInfo; use crate::{ - common::db::STORAGE_FILE_NAME, subcommands::latest_block_summary::{block_info, read_db}, - test_utils::{LmdbTestFixture, MockBlockHeader}, + test_utils::LmdbTestFixture, }; static OUT_DIR: Lazy = Lazy::new(|| tempfile::tempdir().unwrap()); @@ -45,9 +40,10 @@ fn parse_network_name_input() { #[test] fn dump_with_net_name() { - let json_header = JsonBlockHeader::doc_example().clone(); - let header: BlockHeader = json_header.into(); - let block_info = BlockInfo::new(Some("casper".to_string()), header.hash(), header); + let mut rng = TestRng::new(); + + let header: BlockHeader = TestBlockBuilder::new().build(&mut rng).take_header().into(); + let block_info = BlockInfo::new(Some("casper".to_string()), header); let reference_json = serde_json::to_string_pretty(&block_info).unwrap(); let out_file_path = OUT_DIR.as_ref().join("casper_network.json"); @@ -64,9 +60,10 @@ fn dump_with_net_name() { #[test] fn dump_without_net_name() { - let json_header = JsonBlockHeader::doc_example().clone(); - let header: BlockHeader = json_header.into(); - let block_info = BlockInfo::new(None, header.hash(), header); + let mut rng = TestRng::new(); + + let header: BlockHeader = TestBlockBuilder::new().build(&mut rng).take_header().into(); + let block_info = BlockInfo::new(None, header); let reference_json = serde_json::to_string_pretty(&block_info).unwrap(); let out_file_path = OUT_DIR.as_ref().join("no_net_name.json"); @@ -83,37 +80,26 @@ fn dump_without_net_name() { #[test] fn latest_block_should_succeed() { - let fixture = LmdbTestFixture::new(vec!["block_header"], Some(STORAGE_FILE_NAME)); + let mut rng = TestRng::new(); + + let mut fixture = LmdbTestFixture::new(); let out_file_path = OUT_DIR.as_ref().join("latest_block_metadata.json"); // Create 2 block headers, height 0 and 1. - let first_block = MockBlockHeader::default(); - let first_block_key = [0u8; 32]; + let first_block: Block = TestBlockBuilder::new().height(0).build(&mut rng).into(); - let mut second_block = MockBlockHeader::default(); - let second_block_key = [1u8; 32]; - second_block.height = 1; + let second_block: Block = TestBlockBuilder::new().height(1).build(&mut rng).into(); - let env = &fixture.env; - let db = fixture.db(Some("block_header")).unwrap(); // Insert the 2 blocks into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - txn.put( - *db, - &first_block_key, - &bincode::serialize(&first_block).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - txn.put( - *db, - &second_block_key, - &bincode::serialize(&second_block).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - txn.commit().unwrap(); - }; + + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + + let first_block_header = first_block.take_header(); + let _ = rw_txn.write(&first_block_header).unwrap(); + + let second_block_header = second_block.take_header(); + let second_block_hash = rw_txn.write(&second_block_header).unwrap(); + rw_txn.commit().unwrap(); // Get the latest block information and ensure it matches with the second block. read_db::latest_block_summary( @@ -123,15 +109,26 @@ fn latest_block_should_succeed() { ) .unwrap(); let json_str = fs::read_to_string(&out_file_path).unwrap(); - let block_info: BlockInfo = serde_json::from_str(&json_str).unwrap(); - let (mock_block_header_deserialized, _network_name) = block_info.into_mock(); - assert_eq!(mock_block_header_deserialized, second_block); + let latest_block_info: BlockInfo = serde_json::from_str(&json_str).unwrap(); + let second_block_info = BlockInfo::new( + Some( + fixture + .tmp_dir + .path() + .file_name() + .unwrap() + .to_owned() + .into_string() + .unwrap(), + ), + second_block_header, + ); + assert_eq!(latest_block_info, second_block_info); // Delete the second block from the database. - if let Ok(mut txn) = env.begin_rw_txn() { - txn.del(*db, &second_block_key, None).unwrap(); - txn.commit().unwrap(); - }; + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + DataWriter::::delete(&mut rw_txn, second_block_hash).unwrap(); + rw_txn.commit().unwrap(); // Now latest block summary should return information about the first block. // Given that the output exists, another run on the same destination path should fail. @@ -149,14 +146,26 @@ fn latest_block_should_succeed() { ) .unwrap(); let json_str = fs::read_to_string(&out_file_path).unwrap(); - let block_info: BlockInfo = serde_json::from_str(&json_str).unwrap(); - let (mock_block_header_deserialized, _network_name) = block_info.into_mock(); - assert_eq!(mock_block_header_deserialized, first_block); + let latest_block_info: BlockInfo = serde_json::from_str(&json_str).unwrap(); + let first_block_info = BlockInfo::new( + Some( + fixture + .tmp_dir + .path() + .file_name() + .unwrap() + .to_owned() + .into_string() + .unwrap(), + ), + first_block_header, + ); + assert_eq!(latest_block_info, first_block_info); } #[test] fn latest_block_empty_db_should_fail() { - let fixture = LmdbTestFixture::new(vec!["block_header_faulty"], Some(STORAGE_FILE_NAME)); + let fixture = LmdbTestFixture::new(); let out_file_path = OUT_DIR.as_ref().join("empty.json"); assert!(read_db::latest_block_summary( fixture.tmp_dir.as_ref(), @@ -168,7 +177,7 @@ fn latest_block_empty_db_should_fail() { #[test] fn latest_block_existing_output_should_fail() { - let fixture = LmdbTestFixture::new(vec!["block_header_faulty"], Some(STORAGE_FILE_NAME)); + let fixture = LmdbTestFixture::new(); let out_file_path = OUT_DIR.as_ref().join("existing.json"); let _ = OpenOptions::new() .create_new(true) diff --git a/src/subcommands/purge_signatures.rs b/src/subcommands/purge_signatures.rs index a7b8c99..5fbc1e5 100644 --- a/src/subcommands/purge_signatures.rs +++ b/src/subcommands/purge_signatures.rs @@ -1,4 +1,3 @@ -pub(crate) mod block_signatures; mod purge; mod signatures; #[cfg(test)] @@ -6,8 +5,8 @@ mod tests; use std::{collections::BTreeSet, path::Path}; -use bincode::Error as BincodeError; -use casper_node::types::BlockHash; +use casper_storage::block_store::BlockStoreError; +use casper_types::BlockHash; use casper_types::EraId; use clap::{Arg, ArgMatches, Command}; use lmdb::Error as LmdbError; @@ -28,19 +27,16 @@ pub enum Error { /// Database operation error. #[error("Error operating the database: {0}")] Database(#[from] LmdbError), + /// Block store error. + #[error("Error encountered with block store: {0}")] + BlockStore(#[from] BlockStoreError), #[error("Found duplicate block header with height {0}")] DuplicateBlock(u64), - /// Parsing error on entry in the block header database. - #[error("Error parsing block header with hash {0}: {1}")] - HeaderParsing(BlockHash, BincodeError), #[error("Missing switch block with weights for era {0}")] MissingEraWeights(EraId), - /// Serialization error for an entry in the signatures database. - #[error("Error serializing block signatures for block hash {0}: {1}")] - Serialize(BlockHash, BincodeError), - /// Parsing error on entry at index in the signatures database. - #[error("Error parsing block signatures for block hash {0}: {1}")] - SignaturesParsing(BlockHash, BincodeError), + /// Missing block header from database. + #[error("Missing block header from database at hash: {0}")] + MissingBlockHeader(BlockHash), } enum DisplayOrder { diff --git a/src/subcommands/purge_signatures/block_signatures.rs b/src/subcommands/purge_signatures/block_signatures.rs deleted file mode 100644 index 4d87cb2..0000000 --- a/src/subcommands/purge_signatures/block_signatures.rs +++ /dev/null @@ -1,44 +0,0 @@ -use std::{ - collections::BTreeMap, - fmt::{self, Display, Formatter}, -}; - -use casper_node::types::BlockHash; -use casper_types::{EraId, PublicKey, Signature}; -use serde::{Deserialize, Serialize}; - -/// A storage representation of finality signatures with the associated block -/// hash. This structure had to be copied over from the node codebase because -/// it is not publicly accessible through the API. -#[derive(Clone, Debug, Default, PartialOrd, Ord, Hash, Serialize, Deserialize, Eq, PartialEq)] -pub(crate) struct BlockSignatures { - /// The block hash for a given block. - pub(crate) block_hash: BlockHash, - /// The era id for the given set of finality signatures. - pub(crate) era_id: EraId, - /// The signatures associated with the block hash. - pub(crate) proofs: BTreeMap, -} - -#[cfg(test)] -impl BlockSignatures { - pub(crate) fn new(block_hash: BlockHash, era_id: EraId) -> Self { - Self { - block_hash, - era_id, - proofs: Default::default(), - } - } -} - -impl Display for BlockSignatures { - fn fmt(&self, formatter: &mut Formatter) -> fmt::Result { - write!( - formatter, - "block signatures for hash: {} in era_id: {} with {} proofs", - self.block_hash, - self.era_id, - self.proofs.len() - ) - } -} diff --git a/src/subcommands/purge_signatures/purge.rs b/src/subcommands/purge_signatures/purge.rs index a1bd3df..ee1febe 100644 --- a/src/subcommands/purge_signatures/purge.rs +++ b/src/subcommands/purge_signatures/purge.rs @@ -3,19 +3,24 @@ use std::{ path::Path, }; -use casper_hashing::Digest; -use casper_node::types::{BlockHash, BlockHeader}; +use casper_storage::block_store::{ + lmdb::{IndexedLmdbBlockStore, LmdbBlockStore}, + types::{BlockHeight, Tip}, + BlockStoreProvider, BlockStoreTransaction, DataReader, DataWriter, +}; +use casper_types::{BlockHash, BlockHeader, BlockSignatures}; use casper_types::{EraId, ProtocolVersion, PublicKey, U512}; -use lmdb::{Cursor, Database, Environment, Error as LmdbError, Transaction, WriteFlags}; -use log::{error, info, warn}; +use log::{info, warn}; use crate::common::{ - db::{self, BlockHeaderDatabase, BlockMetadataDatabase, Database as _, STORAGE_FILE_NAME}, - lmdb_utils, + db::{ + DEFAULT_MAX_BLOCK_STORE_SIZE, DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + DEFAULT_MAX_DEPLOY_STORE_SIZE, + }, progress::ProgressTracker, }; -use super::{block_signatures::BlockSignatures, signatures::strip_signatures, Error}; +use super::{signatures::strip_signatures, Error}; /// Structure to hold lookup information for a set of block headers. #[derive(Default)] @@ -43,10 +48,9 @@ impl EraWeights { /// /// Return value is `true` when the switch block used to populate the /// weights is a switch block right before an upgrade or `false` otherwise. - pub(crate) fn refresh_weights_for_era( + pub(crate) fn refresh_weights_for_era( &mut self, - txn: &T, - db: Database, + txn: &impl DataReader, indices: &Indices, era_id: EraId, ) -> Result { @@ -60,9 +64,12 @@ impl EraWeights { .get(&era_id) .ok_or_else(|| Error::MissingEraWeights(era_id))?; // Deserialize it. - let switch_block_header: BlockHeader = - bincode::deserialize(txn.get(db, &switch_block_hash)?) - .map_err(|bincode_err| Error::HeaderParsing(*switch_block_hash, bincode_err))?; + let maybe_switch_block_header: Option = txn.read(*switch_block_hash)?; + let switch_block_header = if let Some(header) = maybe_switch_block_header { + header + } else { + return Err(Error::MissingBlockHeader(*switch_block_hash)); + }; // Check if this switch block is the last in the era before an upgrade. self.era_after_upgrade = indices .switch_blocks_before_upgrade @@ -91,79 +98,72 @@ impl EraWeights { /// Creates a collection of indices to store lookup information for a given /// list of block heights. pub(crate) fn initialize_indices( - env: &Environment, + ro_txn: &(impl DataReader + DataReader), needed_heights: &BTreeSet, ) -> Result { let mut indices = Indices::default(); - let txn = env.begin_ro_txn()?; - let header_db = unsafe { txn.open_db(Some(BlockHeaderDatabase::db_name()))? }; - let mut maybe_progress_tracker = match lmdb_utils::entry_count(&txn, header_db).ok() { - Some(entry_count) => Some( - ProgressTracker::new( - entry_count, - Box::new(|completion| info!("Header database parsing {}% complete...", completion)), - ) - .map_err(|_| Error::EmptyDatabase)?, - ), - None => { - info!("Skipping progress tracking for header database parsing"); - None + let mut block_heights = vec![]; + let latest_block_header = + DataReader::::read(ro_txn, Tip)?.ok_or(Error::EmptyDatabase)?; + let maybe_block_heights = 0..=latest_block_header.height(); + for height in maybe_block_heights { + if DataReader::::exists(ro_txn, height)? { + block_heights.push(height); } - }; + } + + let mut progress_tracker = ProgressTracker::new( + block_heights.len(), + Box::new(|completion| info!("Header database parsing {}% complete...", completion)), + ) + .map_err(|_| Error::EmptyDatabase)?; { let mut last_blocks_before_upgrade: BTreeMap = BTreeMap::default(); - // Iterate through all block headers. - let mut cursor = txn.open_ro_cursor(header_db)?; - for (raw_key, raw_value) in cursor.iter() { - if let Some(progress_tracker) = maybe_progress_tracker.as_mut() { - progress_tracker.advance_by(1); - } - // Deserialize the block hash. - let block_hash: BlockHash = match Digest::try_from(raw_key) { - Ok(digest) => digest.into(), - Err(digest_parsing_err) => { - error!("Skipping block header because of invalid hash {raw_key:?}: {digest_parsing_err}"); - continue; - } - }; - // Deserialize the header. - let block_header: BlockHeader = bincode::deserialize(raw_value) - .map_err(|bincode_err| Error::HeaderParsing(block_hash, bincode_err))?; - let block_height = block_header.height(); - // We store all switch block hashes keyed by the era for which they - // hold the weights. - if block_header.is_switch_block() { - let _ = indices - .switch_blocks - .insert(block_header.era_id().successor(), block_hash); - // Store the highest switch block height for each protocol - // version we encounter. - match last_blocks_before_upgrade.entry(block_header.protocol_version()) { - Entry::Vacant(vacant_entry) => { - vacant_entry.insert(block_height); - } - Entry::Occupied(mut occupied_entry) => { - if *occupied_entry.get() < block_height { - occupied_entry.insert(block_height); + + for block_height in block_heights { + if let Some(block_header) = + DataReader::::read(ro_txn, block_height)? + { + let block_height = block_header.height(); + let block_hash = block_header.block_hash(); + // We store all switch block hashes keyed by the era for which they + // hold the weights. + if block_header.is_switch_block() { + let _ = indices + .switch_blocks + .insert(block_header.era_id().successor(), block_hash); + // Store the highest switch block height for each protocol + // version we encounter. + match last_blocks_before_upgrade.entry(block_header.protocol_version()) { + Entry::Vacant(vacant_entry) => { + vacant_entry.insert(block_height); + } + Entry::Occupied(mut occupied_entry) => { + if *occupied_entry.get() < block_height { + occupied_entry.insert(block_height); + } } } } + // If this block is on our list, store its hash and header in the + // indices. We store the header to avoid looking it up again in the + // future since we know we will need it and we expect + // `needed_heights` to be a relatively small list. + if needed_heights.contains(&block_height) + && indices + .heights + .insert(block_height, (block_hash, block_header)) + .is_some() + { + return Err(Error::DuplicateBlock(block_height)); + }; } - // If this block is on our list, store its hash and header in the - // indices. We store the header to avoid looking it up again in the - // future since we know we will need it and we expect - // `needed_heights` to be a relatively small list. - if needed_heights.contains(&block_height) - && indices - .heights - .insert(block_height, (block_hash, block_header)) - .is_some() - { - return Err(Error::DuplicateBlock(block_height)); - }; + + progress_tracker.advance_by(1); } + // Remove the entry for the highest known protocol version as it hasn't // had an upgrade yet. let _ = last_blocks_before_upgrade.pop_last(); @@ -172,7 +172,6 @@ pub(crate) fn initialize_indices( .switch_blocks_before_upgrade .extend(last_blocks_before_upgrade.into_values()); } - txn.commit()?; Ok(indices) } @@ -188,18 +187,15 @@ pub(crate) fn initialize_indices( /// If this is not possible for that block given its signature set and the era /// weights, it is skipped and a message is logged. pub(crate) fn purge_signatures_for_blocks( - env: &Environment, + rw_txn: &mut (impl DataReader + + DataReader + + DataWriter), indices: &Indices, heights_to_visit: BTreeSet, full_purge: bool, ) -> Result<(), Error> { - let mut txn = env.begin_rw_txn()?; - let header_db = unsafe { txn.open_db(Some(BlockHeaderDatabase::db_name()))? }; - let signatures_db = unsafe { txn.open_db(Some(BlockMetadataDatabase::db_name()))? }; - let mut era_weights = EraWeights::default(); - - let mut progress_tracker = ProgressTracker::new( + let mut progress_tracker: ProgressTracker = ProgressTracker::new( heights_to_visit.len(), Box::new(if full_purge { |completion| { @@ -242,13 +238,11 @@ pub(crate) fn purge_signatures_for_blocks( let era_id = block_header.era_id(); // Make sure we have the correct era weights for this block before // trying to strip any signatures. - let era_after_upgrade = - era_weights.refresh_weights_for_era(&txn, header_db, indices, era_id)?; + let era_after_upgrade = era_weights.refresh_weights_for_era(rw_txn, indices, era_id)?; - let mut block_signatures: BlockSignatures = match txn.get(signatures_db, &block_hash) { - Ok(raw_signatures) => bincode::deserialize(raw_signatures) - .map_err(|bincode_err| Error::SignaturesParsing(*block_hash, bincode_err))?, - Err(LmdbError::NotFound) => { + let mut block_signatures: BlockSignatures = match rw_txn.read(*block_hash)? { + Some(signatures) => signatures, + None => { // Skip blocks which have no signature entry in the database. warn!( "No signature entry in the database for block \ @@ -257,12 +251,11 @@ pub(crate) fn purge_signatures_for_blocks( progress_tracker.advance_by(1); continue; } - Err(lmdb_err) => return Err(Error::Database(lmdb_err)), }; if full_purge { // Delete the record completely from the database. - txn.del(signatures_db, &block_hash, None)?; + rw_txn.delete(*block_hash)?; } else if strip_signatures(&mut block_signatures, &era_weights.weights) { if era_after_upgrade { warn!( @@ -270,22 +263,14 @@ pub(crate) fn purge_signatures_for_blocks( for block {block_hash} at height {block_height}" ); } - // Serialize the remaining signatures and overwrite the database - // entry. - let serialized_signatures = bincode::serialize(&block_signatures) - .map_err(|bincode_err| Error::Serialize(*block_hash, bincode_err))?; - txn.put( - signatures_db, - &block_hash, - &serialized_signatures, - WriteFlags::default(), - )?; + + // Overwrite the database with the remaining signatures entry. + rw_txn.write(&block_signatures)?; } else { warn!("Couldn't strip signatures for block {block_hash} at height {block_height}"); } progress_tracker.advance_by(1); } - txn.commit()?; Ok(()) } @@ -294,18 +279,31 @@ pub fn purge_signatures>( weak_finality_block_list: BTreeSet, no_finality_block_list: BTreeSet, ) -> Result<(), Error> { - let storage_path = db_path.as_ref().join(STORAGE_FILE_NAME); - let env = db::db_env(storage_path)?; let heights_to_visit = weak_finality_block_list .union(&no_finality_block_list) .copied() .collect(); - let indices = initialize_indices(&env, &heights_to_visit)?; + + let block_store = LmdbBlockStore::new( + db_path.as_ref(), + DEFAULT_MAX_BLOCK_STORE_SIZE + + DEFAULT_MAX_DEPLOY_STORE_SIZE + + DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + )?; + let mut indexed_block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::from_parts(0, 0, 0))?; + + let ro_txn = indexed_block_store.checkout_ro()?; + let indices = initialize_indices(&ro_txn, &heights_to_visit)?; + ro_txn.commit()?; + + let mut rw_txn = indexed_block_store.checkout_rw()?; if !weak_finality_block_list.is_empty() { - purge_signatures_for_blocks(&env, &indices, weak_finality_block_list, false)?; + purge_signatures_for_blocks(&mut rw_txn, &indices, weak_finality_block_list, false)?; } if !no_finality_block_list.is_empty() { - purge_signatures_for_blocks(&env, &indices, no_finality_block_list, true)?; + purge_signatures_for_blocks(&mut rw_txn, &indices, no_finality_block_list, true)?; } + rw_txn.commit()?; Ok(()) } diff --git a/src/subcommands/purge_signatures/signatures.rs b/src/subcommands/purge_signatures/signatures.rs index 0a308ca..0bb92a9 100644 --- a/src/subcommands/purge_signatures/signatures.rs +++ b/src/subcommands/purge_signatures/signatures.rs @@ -1,8 +1,6 @@ use std::collections::{BTreeMap, BTreeSet}; -use casper_types::{PublicKey, U512}; - -use super::block_signatures::BlockSignatures; +use casper_types::{BlockSignatures, PublicKey, U512}; // Returns whether the cumulative `weight` exceeds the weak finality threshold // for a `total` weight. @@ -44,7 +42,7 @@ pub(super) fn strip_signatures( .iter() .flat_map(|(weight, keys)| keys.iter().map(move |key| (weight, *key))) { - if signatures.proofs.contains_key(key) { + if signatures.proofs().contains_key(key) { accumulated_weight += *weight; accumulated_sigs.insert(key); @@ -75,9 +73,18 @@ pub(super) fn strip_signatures( return false; } // Keep only the accumulated signatures. - signatures - .proofs - .retain(|key, _| accumulated_sigs.contains(key)); + let signatures_to_remove: Vec = signatures + .proofs() + .keys() + .filter(|key| !accumulated_sigs.contains(*key)) + .cloned() + .collect(); + + for key in signatures_to_remove { + if signatures.remove_signature(&key).is_none() { + return false; + } + } true } @@ -85,12 +92,14 @@ pub(super) fn strip_signatures( mod tests { use std::collections::BTreeMap; - use casper_types::{PublicKey, Signature, U512}; + use casper_types::{ + testing::TestRng, BlockHash, BlockSignatures, BlockSignaturesV2, ChainNameDigest, + PublicKey, Signature, U512, + }; use crate::{ - subcommands::purge_signatures::{ - block_signatures::BlockSignatures, - signatures::{is_strict_finality, is_weak_finality, strip_signatures}, + subcommands::purge_signatures::signatures::{ + is_strict_finality, is_weak_finality, strip_signatures, }, test_utils::KEYS, }; @@ -123,20 +132,20 @@ mod tests { #[test] fn strip_signatures_progressive() { - let mut block_signatures = BlockSignatures::default(); + let mut rng = TestRng::new(); + + let mut block_signatures: BlockSignatures = BlockSignaturesV2::new( + BlockHash::random(&mut rng), + 100, + 10.into(), + ChainNameDigest::from_chain_name("test"), + ) + .into(); // Create signatures for keys [1..4]. - block_signatures - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[1].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[2].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[3].clone(), Signature::System); + block_signatures.insert_signature(KEYS[0].clone(), Signature::System); + block_signatures.insert_signature(KEYS[1].clone(), Signature::System); + block_signatures.insert_signature(KEYS[2].clone(), Signature::System); + block_signatures.insert_signature(KEYS[3].clone(), Signature::System); let mut weights: BTreeMap = BTreeMap::default(); // Add weights for keys [1..4]. @@ -148,22 +157,27 @@ mod tests { assert!(strip_signatures(&mut block_signatures, &weights)); // Signatures from keys [1..3] have a cumulative weight of 600/1000, // so signature from key 4 should have been purged. - assert!(block_signatures.proofs.contains_key(&KEYS[0])); - assert!(block_signatures.proofs.contains_key(&KEYS[1])); - assert!(block_signatures.proofs.contains_key(&KEYS[2])); - assert!(!block_signatures.proofs.contains_key(&KEYS[3])); + assert!(block_signatures.proofs().contains_key(&KEYS[0])); + assert!(block_signatures.proofs().contains_key(&KEYS[1])); + assert!(block_signatures.proofs().contains_key(&KEYS[2])); + assert!(!block_signatures.proofs().contains_key(&KEYS[3])); } #[test] fn strip_signatures_equal_weights() { - let mut block_signatures = BlockSignatures::default(); + let mut rng = TestRng::new(); + + let mut block_signatures: BlockSignatures = BlockSignaturesV2::new( + BlockHash::random(&mut rng), + 100, + 10.into(), + ChainNameDigest::from_chain_name("test"), + ) + .into(); + // Create signatures for keys [1..2]. - block_signatures - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[1].clone(), Signature::System); + block_signatures.insert_signature(KEYS[0].clone(), Signature::System); + block_signatures.insert_signature(KEYS[1].clone(), Signature::System); let mut weights: BTreeMap = BTreeMap::default(); // Add weights for keys [1..2]. @@ -173,25 +187,26 @@ mod tests { assert!(strip_signatures(&mut block_signatures, &weights)); // Any of the signatures has half the weight, so only one should have // been kept. - assert_eq!(block_signatures.proofs.len(), 1); + assert_eq!(block_signatures.proofs().len(), 1); } #[test] fn strip_signatures_one_small_three_large() { - let mut block_signatures = BlockSignatures::default(); + let mut rng = TestRng::new(); + + let mut block_signatures: BlockSignatures = BlockSignaturesV2::new( + BlockHash::random(&mut rng), + 100, + 10.into(), + ChainNameDigest::from_chain_name("test"), + ) + .into(); + // Create signatures for keys [1..4]. - block_signatures - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[1].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[2].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[3].clone(), Signature::System); + block_signatures.insert_signature(KEYS[0].clone(), Signature::System); + block_signatures.insert_signature(KEYS[1].clone(), Signature::System); + block_signatures.insert_signature(KEYS[2].clone(), Signature::System); + block_signatures.insert_signature(KEYS[3].clone(), Signature::System); let mut weights: BTreeMap = BTreeMap::default(); // Add weights for keys [1..4]. @@ -204,23 +219,25 @@ mod tests { // Any of the signatures [2..4] has a third of the weight, so one of // them plus the first signature with a weight of 1 make weak but not // strict finality. - assert!(block_signatures.proofs.contains_key(&KEYS[0])); - assert_eq!(block_signatures.proofs.len(), 2); + assert!(block_signatures.proofs().contains_key(&KEYS[0])); + assert_eq!(block_signatures.proofs().len(), 2); } #[test] fn strip_signatures_split_weights() { - let mut block_signatures = BlockSignatures::default(); + let mut rng = TestRng::new(); + let mut block_signatures: BlockSignatures = BlockSignaturesV2::new( + BlockHash::random(&mut rng), + 100, + 10.into(), + ChainNameDigest::from_chain_name("test"), + ) + .into(); + // Create signatures for keys [1..3]. - block_signatures - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[1].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[2].clone(), Signature::System); + block_signatures.insert_signature(KEYS[0].clone(), Signature::System); + block_signatures.insert_signature(KEYS[1].clone(), Signature::System); + block_signatures.insert_signature(KEYS[2].clone(), Signature::System); let mut weights: BTreeMap = BTreeMap::default(); // Add weights for keys [1..3]. @@ -231,22 +248,24 @@ mod tests { assert!(strip_signatures(&mut block_signatures, &weights)); // Any 2 signatures have a cumulative weight of 666/999, or 2/3 of the // weight, so 1 of the 3 signatures should have been purged. - assert_eq!(block_signatures.proofs.len(), 2); + assert_eq!(block_signatures.proofs().len(), 2); } #[test] fn strip_signatures_one_key_has_strict_finality() { - let mut block_signatures = BlockSignatures::default(); + let mut rng = TestRng::new(); + let mut block_signatures: BlockSignatures = BlockSignaturesV2::new( + BlockHash::random(&mut rng), + 100, + 10.into(), + ChainNameDigest::from_chain_name("test"), + ) + .into(); + // Create signatures for keys [1..3]. - block_signatures - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[1].clone(), Signature::System); - block_signatures - .proofs - .insert(KEYS[2].clone(), Signature::System); + block_signatures.insert_signature(KEYS[0].clone(), Signature::System); + block_signatures.insert_signature(KEYS[1].clone(), Signature::System); + block_signatures.insert_signature(KEYS[2].clone(), Signature::System); let mut weights: BTreeMap = BTreeMap::default(); // Add weights for keys [1..3]. @@ -260,11 +279,17 @@ mod tests { #[test] fn strip_signatures_single_key() { - let mut block_signatures = BlockSignatures::default(); + let mut rng = TestRng::new(); + let mut block_signatures: BlockSignatures = BlockSignaturesV2::new( + BlockHash::random(&mut rng), + 100, + 10.into(), + ChainNameDigest::from_chain_name("test"), + ) + .into(); + // Create a signature for key 1. - block_signatures - .proofs - .insert(KEYS[0].clone(), Signature::System); + block_signatures.insert_signature(KEYS[0].clone(), Signature::System); let mut weights: BTreeMap = BTreeMap::default(); // Add a weight for key 1. diff --git a/src/subcommands/purge_signatures/tests.rs b/src/subcommands/purge_signatures/tests.rs index dea5e05..069880e 100644 --- a/src/subcommands/purge_signatures/tests.rs +++ b/src/subcommands/purge_signatures/tests.rs @@ -1,909 +1,826 @@ -use std::collections::BTreeSet; +use std::collections::{BTreeMap, BTreeSet}; -use casper_node::types::BlockHash; -use casper_types::{ProtocolVersion, Signature, U512}; -use lmdb::{Error as LmdbError, Transaction, WriteFlags}; +use casper_storage::block_store::{ + lmdb::IndexedLmdbBlockStore, BlockStoreProvider, BlockStoreTransaction, DataReader, DataWriter, +}; +use casper_types::{ + testing::TestRng, Block, BlockHash, BlockHeaderV2, BlockSignatures, BlockSignaturesV2, BlockV2, + ChainNameDigest, Digest, EraEndV2, ProtocolVersion, PublicKey, Signature, TestBlockBuilder, + U512, +}; +use once_cell::sync::OnceCell; use crate::{ subcommands::purge_signatures::{ - block_signatures::BlockSignatures, purge::{initialize_indices, purge_signatures_for_blocks, EraWeights}, Error, }, - test_utils::{self, LmdbTestFixture, MockBlockHeader, MockSwitchBlockHeader, KEYS}, + test_utils::{LmdbTestFixture, KEYS}, }; -// Gets and deserializes a `BlockSignatures` structure from the block +// Gets a `BlockSignatures` structure from the block // signatures database. -fn get_sigs_from_db( - txn: &T, - fixture: &LmdbTestFixture, +fn get_sigs_from_db( + txn: &impl DataReader, block_hash: &BlockHash, ) -> BlockSignatures { - let serialized_sigs = txn - .get(*fixture.db(Some("block_metadata")).unwrap(), block_hash) - .unwrap(); - let block_sigs: BlockSignatures = bincode::deserialize(serialized_sigs).unwrap(); - assert_eq!(block_sigs.block_hash, *block_hash); + let block_sigs: BlockSignatures = txn.read(*block_hash).unwrap().unwrap(); + assert_eq!(*block_sigs.block_hash(), *block_hash); block_sigs } #[test] fn indices_initialization() { - const BLOCK_COUNT: usize = 4; - const SWITCH_BLOCK_COUNT: usize = 2; - - let fixture = LmdbTestFixture::new(vec!["block_header"], None); + let mut rng = TestRng::new(); + let mut fixture = LmdbTestFixture::new(); + + // Create mock blocks and set an era and height for each one. + let mut blocks: Vec = vec![]; + blocks.push( + TestBlockBuilder::new() + .height(100) + .era(10) + .switch_block(false) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(200) + .era(10) + .switch_block(false) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(300) + .era(20) + .switch_block(false) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(400) + .era(20) + .switch_block(false) + .build(&mut rng) + .into(), + ); - // Create mock block headers. - let mut block_headers: Vec<(BlockHash, MockBlockHeader)> = (0..BLOCK_COUNT as u8) - .map(test_utils::mock_block_header) - .collect(); - // Set an era and height for each one. - block_headers[0].1.era_id = 10.into(); - block_headers[0].1.height = 100; - block_headers[1].1.era_id = 10.into(); - block_headers[1].1.height = 200; - block_headers[2].1.era_id = 20.into(); - block_headers[2].1.height = 300; - block_headers[3].1.era_id = 20.into(); - block_headers[3].1.height = 400; - // Create mock switch blocks for each era. - let mut switch_block_headers: Vec<(BlockHash, MockSwitchBlockHeader)> = (0..BLOCK_COUNT as u8) - .map(test_utils::mock_switch_block_header) - .collect(); - // Set an appropriate era and height for each one. - switch_block_headers[0].1.era_id = block_headers[0].1.era_id - 1; - switch_block_headers[0].1.height = 80; - switch_block_headers[1].1.era_id = block_headers[2].1.era_id - 1; - switch_block_headers[1].1.height = 280; + // Create mock switch blocks for each era and set an appropriate era and height for each one. + let mut switch_blocks: Vec = vec![]; + switch_blocks.push( + TestBlockBuilder::new() + .height(80) + .era(blocks[0].era_id() - 1) + .switch_block(true) + .build(&mut rng) + .into(), + ); + switch_blocks.push( + TestBlockBuilder::new() + .height(280) + .era(blocks[2].era_id() - 1) + .switch_block(true) + .build(&mut rng) + .into(), + ); - let env = &fixture.env; // Insert the blocks into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for (block_hash, block_header) in block_headers.iter().take(BLOCK_COUNT) { - // Store the block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(&block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - for (block_hash, block_header) in switch_block_headers.iter().take(SWITCH_BLOCK_COUNT) { - // Store the switch block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + for block in blocks.iter() { + let _ = rw_txn.write(block).unwrap(); + } + for switch_block in switch_blocks.iter() { + let _ = rw_txn.write(switch_block).unwrap(); + } + rw_txn.commit().unwrap(); + + let (block_store, _store_dir) = fixture.destructure(); + let block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::default()).unwrap(); + + let ro_txn = block_store.checkout_ro().unwrap(); + let indices = initialize_indices(&ro_txn, &BTreeSet::from([100, 200, 300])).unwrap(); + ro_txn.commit().unwrap(); - let indices = initialize_indices(env, &BTreeSet::from([100, 200, 300])).unwrap(); // Make sure we have the relevant blocks in the indices. assert_eq!( - indices.heights.get(&block_headers[0].1.height).unwrap().0, - block_headers[0].0 + indices.heights.get(&blocks[0].height()).unwrap().0, + *blocks[0].hash() ); assert_eq!( - indices.heights.get(&block_headers[1].1.height).unwrap().0, - block_headers[1].0 + indices.heights.get(&blocks[1].height()).unwrap().0, + *blocks[1].hash() ); assert_eq!( - indices.heights.get(&block_headers[2].1.height).unwrap().0, - block_headers[2].0 + indices.heights.get(&blocks[2].height()).unwrap().0, + *blocks[2].hash() ); // And that the irrelevant ones are not included. - assert!(!indices.heights.contains_key(&block_headers[3].1.height)); + assert!(!indices.heights.contains_key(&blocks[3].height())); // Make sure we got all the switch blocks. assert_eq!( - *indices - .switch_blocks - .get(&block_headers[0].1.era_id) - .unwrap(), - switch_block_headers[0].0 + *indices.switch_blocks.get(&blocks[0].era_id()).unwrap(), + *switch_blocks[0].hash() ); assert_eq!( - *indices - .switch_blocks - .get(&block_headers[2].1.era_id) - .unwrap(), - switch_block_headers[1].0 - ); - - // Test for a header with a height which we already have in the db. - let (duplicate_hash, mut duplicate_header) = test_utils::mock_block_header(4); - duplicate_header.height = block_headers[0].1.height; - if let Ok(mut txn) = env.begin_rw_txn() { - // Store the header with duplicated height. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - &duplicate_hash, - &bincode::serialize(&duplicate_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - txn.commit().unwrap(); - }; - - match initialize_indices(env, &BTreeSet::from([100, 200, 300])) { - Err(Error::DuplicateBlock(height)) => assert_eq!(height, block_headers[0].1.height), - _ => panic!("Unexpected error"), - } + *indices.switch_blocks.get(&blocks[2].era_id()).unwrap(), + *switch_blocks[1].hash() + ); } #[test] fn indices_initialization_with_upgrade() { - const BLOCK_COUNT: usize = 4; - const SWITCH_BLOCK_COUNT: usize = 4; - - let fixture = LmdbTestFixture::new(vec!["block_header"], None); - // Create mock block headers. - let mut block_headers: Vec<(BlockHash, MockBlockHeader)> = (0..BLOCK_COUNT as u8) - .map(test_utils::mock_block_header) - .collect(); - // Set an era and height for each one. - block_headers[0].1.era_id = 10.into(); - block_headers[0].1.height = 80; - - block_headers[1].1.era_id = 11.into(); - block_headers[1].1.height = 200; - block_headers[2].1.protocol_version = ProtocolVersion::from_parts(1, 1, 0); - - block_headers[2].1.era_id = 12.into(); - block_headers[2].1.height = 290; - block_headers[2].1.protocol_version = ProtocolVersion::from_parts(2, 0, 0); - - block_headers[3].1.era_id = 13.into(); - block_headers[3].1.height = 350; - block_headers[3].1.protocol_version = ProtocolVersion::from_parts(2, 0, 0); - - // Create mock switch blocks. - let mut switch_block_headers: Vec<(BlockHash, MockSwitchBlockHeader)> = (0..SWITCH_BLOCK_COUNT - as u8) - .map(test_utils::mock_switch_block_header) - .collect(); - // Set an appropriate era and height for each one. - switch_block_headers[0].1.era_id = block_headers[0].1.era_id - 1; - switch_block_headers[0].1.height = 60; - - switch_block_headers[1].1.era_id = block_headers[1].1.era_id - 1; - switch_block_headers[1].1.height = 180; - - switch_block_headers[2].1.era_id = block_headers[2].1.era_id - 1; - switch_block_headers[2].1.height = 250; - switch_block_headers[2].1.protocol_version = ProtocolVersion::from_parts(1, 1, 0); + let mut rng = TestRng::new(); + let mut fixture = LmdbTestFixture::new(); + // Create mock blocks and set an era and height for each one. + let mut blocks: Vec = vec![]; + blocks.push( + TestBlockBuilder::new() + .height(80) + .era(10) + .switch_block(false) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(200) + .era(11) + .switch_block(false) + .protocol_version(ProtocolVersion::from_parts(1, 1, 0)) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(290) + .era(12) + .switch_block(false) + .protocol_version(ProtocolVersion::from_parts(2, 0, 0)) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(350) + .era(13) + .switch_block(false) + .protocol_version(ProtocolVersion::from_parts(2, 0, 0)) + .build(&mut rng) + .into(), + ); - switch_block_headers[3].1.height = 300; - switch_block_headers[3].1.protocol_version = ProtocolVersion::from_parts(2, 0, 0); + // Create mock switch blocks for each era and set an appropriate era and height for each one. + let mut switch_blocks: Vec = vec![]; + switch_blocks.push( + TestBlockBuilder::new() + .height(60) + .era(blocks[0].era_id() - 1) + .switch_block(true) + .build(&mut rng) + .into(), + ); + switch_blocks.push( + TestBlockBuilder::new() + .height(180) + .era(blocks[1].era_id() - 1) + .switch_block(true) + .build(&mut rng) + .into(), + ); + switch_blocks.push( + TestBlockBuilder::new() + .height(250) + .era(blocks[2].era_id() - 1) + .switch_block(true) + .protocol_version(ProtocolVersion::from_parts(1, 1, 0)) + .build(&mut rng) + .into(), + ); + switch_blocks.push( + TestBlockBuilder::new() + .height(300) + .era(blocks[3].era_id() - 1) + .switch_block(true) + .protocol_version(ProtocolVersion::from_parts(2, 0, 0)) + .build(&mut rng) + .into(), + ); - let env = &fixture.env; // Insert the blocks into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for (block_hash, block_header) in block_headers.iter().take(BLOCK_COUNT) { - // Store the block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(&block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - for (block_hash, block_header) in switch_block_headers.iter().take(SWITCH_BLOCK_COUNT) { - // Store the switch block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + for block in blocks.iter() { + let _ = rw_txn.write(block).unwrap(); + } + for switch_block in switch_blocks.iter() { + let _ = rw_txn.write(switch_block).unwrap(); + } + rw_txn.commit().unwrap(); - let indices = initialize_indices(env, &BTreeSet::from([100, 200, 300])).unwrap(); + let (block_store, _store_dir) = fixture.destructure(); + let block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::default()).unwrap(); + + let ro_txn = block_store.checkout_ro().unwrap(); + let indices = initialize_indices(&ro_txn, &BTreeSet::from([100, 200, 300])).unwrap(); assert!(!indices .switch_blocks_before_upgrade - .contains(&switch_block_headers[0].1.height)); + .contains(&switch_blocks[0].height())); assert!(indices .switch_blocks_before_upgrade - .contains(&switch_block_headers[1].1.height)); + .contains(&switch_blocks[1].height())); assert!(indices .switch_blocks_before_upgrade - .contains(&switch_block_headers[2].1.height)); + .contains(&switch_blocks[2].height())); assert!(!indices .switch_blocks_before_upgrade - .contains(&switch_block_headers[3].1.height)); + .contains(&switch_blocks[3].height())); +} + +fn new_switch_block_with_weights( + rng: &mut TestRng, + era_id: u64, + height: u64, + weights: &[(PublicKey, U512)], + protocol_version: Option, +) -> Block { + let switch_block = TestBlockBuilder::new() + .height(height) + .era(era_id) + .switch_block(true) + .build(rng); + + let next_era_weights: BTreeMap = weights.iter().cloned().collect(); + let era_end = EraEndV2::new(vec![], vec![], next_era_weights, BTreeMap::new(), 1); + + let switch_block_header = switch_block.header().clone(); + let switch_block_header = BlockHeaderV2::new( + *switch_block_header.parent_hash(), + *switch_block_header.state_root_hash(), + *switch_block_header.body_hash(), + switch_block_header.random_bit(), + *switch_block_header.accumulated_seed(), + Some(era_end), + switch_block_header.timestamp(), + switch_block_header.era_id(), + switch_block_header.height(), + protocol_version.unwrap_or(switch_block_header.protocol_version()), + switch_block_header.proposer().clone(), + switch_block_header.current_gas_price(), + switch_block_header.last_switch_block_hash(), + OnceCell::new(), + ); + + Block::from(BlockV2::new_from_header_and_body( + switch_block_header, + switch_block.take_body(), + )) } #[test] fn era_weights() { - const SWITCH_BLOCK_COUNT: usize = 2; + let mut rng = TestRng::new(); + let mut fixture = LmdbTestFixture::new(); + + // Create mock switch blocks for each era and set an appropriate era and height for each one. + let mut switch_blocks: Vec = vec![]; + + switch_blocks.push(new_switch_block_with_weights( + &mut rng, + 10, + 80, + &[(KEYS[0].clone(), 100.into())], + None, + )); + switch_blocks.push(new_switch_block_with_weights( + &mut rng, + 20, + 280, + &[(KEYS[1].clone(), 100.into())], + None, + )); - let fixture = LmdbTestFixture::new(vec!["block_header"], None); - // Create mock switch block headers. - let mut switch_block_headers: Vec<(BlockHash, MockSwitchBlockHeader)> = (0..SWITCH_BLOCK_COUNT - as u8) - .map(test_utils::mock_switch_block_header) - .collect(); - // Set an era and height for each one. - switch_block_headers[0].1.era_id = 10.into(); - switch_block_headers[0].1.height = 80; - // Insert some weight for the next era weights. - switch_block_headers[0] - .1 - .era_end - .as_mut() - .unwrap() - .next_era_validator_weights - .insert(KEYS[0].clone(), 100.into()); - // Set an era and height for each one. - switch_block_headers[1].1.era_id = 20.into(); - switch_block_headers[1].1.height = 280; - // Insert some weight for the next era weights. - switch_block_headers[1] - .1 - .era_end - .as_mut() - .unwrap() - .next_era_validator_weights - .insert(KEYS[1].clone(), 100.into()); - - let env = &fixture.env; // Insert the blocks into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for (block_hash, block_header) in switch_block_headers.iter().take(SWITCH_BLOCK_COUNT) { - // Store the switch block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; - let indices = initialize_indices(env, &BTreeSet::from([80])).unwrap(); + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + for switch_block in switch_blocks.iter() { + let _ = rw_txn.write(switch_block).unwrap(); + } + rw_txn.commit().unwrap(); + + let (block_store, _store_dir) = fixture.destructure(); + let block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::default()).unwrap(); + let ro_txn = block_store.checkout_ro().unwrap(); + let indices = initialize_indices(&ro_txn, &BTreeSet::from([80])).unwrap(); let mut era_weights = EraWeights::default(); - if let Ok(txn) = env.begin_ro_txn() { - let db = env.open_db(Some("block_header")).unwrap(); - // Try to update the weights for the first switch block. - assert!(!era_weights - .refresh_weights_for_era( - &txn, - db, - &indices, - switch_block_headers[0].1.era_id.successor() - ) - .unwrap()); - assert_eq!( - era_weights.era_id(), - switch_block_headers[0].1.era_id.successor() - ); - assert_eq!( - *era_weights.weights_mut().get(&KEYS[0]).unwrap(), - U512::from(100) - ); - assert!(!era_weights.weights_mut().contains_key(&KEYS[1])); - - // Try to update the weights for the second switch block. - assert!(!era_weights - .refresh_weights_for_era( - &txn, - db, - &indices, - switch_block_headers[1].1.era_id.successor() - ) - .unwrap()); - assert_eq!( - era_weights.era_id(), - switch_block_headers[1].1.era_id.successor() - ); - assert_eq!( - *era_weights.weights_mut().get(&KEYS[1]).unwrap(), - U512::from(100) - ); - assert!(!era_weights.weights_mut().contains_key(&KEYS[0])); - - // Try to update the weights for the second switch block again. - assert!(!era_weights - .refresh_weights_for_era( - &txn, - db, - &indices, - switch_block_headers[1].1.era_id.successor() - ) - .unwrap()); - assert_eq!( - era_weights.era_id(), - switch_block_headers[1].1.era_id.successor() - ); - assert_eq!( - *era_weights.weights_mut().get(&KEYS[1]).unwrap(), - U512::from(100) - ); - assert!(!era_weights.weights_mut().contains_key(&KEYS[0])); - - // Try to update the weights for a nonexistent switch block. - let expected_missing_era_id = switch_block_headers[1].1.era_id.successor().successor(); - match era_weights.refresh_weights_for_era(&txn, db, &indices, expected_missing_era_id) { - Err(Error::MissingEraWeights(actual_missing_era_id)) => { - assert_eq!(expected_missing_era_id, actual_missing_era_id) - } - _ => panic!("Unexpected failure"), - } - txn.commit().unwrap(); - }; - if let Ok(mut txn) = env.begin_rw_txn() { - // Delete the weights for the first switch block in the db. - switch_block_headers[0].1.era_end = None; - txn.put( - *fixture.db(Some("block_header")).unwrap(), - &switch_block_headers[0].0, - &bincode::serialize(&switch_block_headers[0].1).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - txn.commit().unwrap(); - }; - if let Ok(txn) = env.begin_ro_txn() { - let db = env.open_db(Some("block_header")).unwrap(); - let expected_missing_era_id = switch_block_headers[0].1.era_id.successor(); - // Make sure we get an error when the block has no weights. - match era_weights.refresh_weights_for_era(&txn, db, &indices, expected_missing_era_id) { - Err(Error::MissingEraWeights(actual_missing_era_id)) => { - assert_eq!(expected_missing_era_id, actual_missing_era_id) - } - _ => panic!("Unexpected failure"), + // Try to update the weights for the first switch block. + assert!(!era_weights + .refresh_weights_for_era(&ro_txn, &indices, switch_blocks[0].era_id().successor()) + .unwrap()); + assert_eq!(era_weights.era_id(), switch_blocks[0].era_id().successor()); + assert_eq!( + *era_weights.weights_mut().get(&KEYS[0]).unwrap(), + U512::from(100) + ); + assert!(!era_weights.weights_mut().contains_key(&KEYS[1])); + + // Try to update the weights for the second switch block. + assert!(!era_weights + .refresh_weights_for_era(&ro_txn, &indices, switch_blocks[1].era_id().successor()) + .unwrap()); + assert_eq!(era_weights.era_id(), switch_blocks[1].era_id().successor()); + assert_eq!( + *era_weights.weights_mut().get(&KEYS[1]).unwrap(), + U512::from(100) + ); + assert!(!era_weights.weights_mut().contains_key(&KEYS[0])); + + // Try to update the weights for the second switch block again. + assert!(!era_weights + .refresh_weights_for_era(&ro_txn, &indices, switch_blocks[1].era_id().successor()) + .unwrap()); + assert_eq!(era_weights.era_id(), switch_blocks[1].era_id().successor()); + assert_eq!( + *era_weights.weights_mut().get(&KEYS[1]).unwrap(), + U512::from(100) + ); + assert!(!era_weights.weights_mut().contains_key(&KEYS[0])); + + // Try to update the weights for a nonexistent switch block. + let expected_missing_era_id = switch_blocks[1].era_id().successor().successor(); + match era_weights.refresh_weights_for_era(&ro_txn, &indices, expected_missing_era_id) { + Err(Error::MissingEraWeights(actual_missing_era_id)) => { + assert_eq!(expected_missing_era_id, actual_missing_era_id) } - txn.commit().unwrap(); - }; + _ => panic!("Unexpected failure"), + } + ro_txn.commit().unwrap(); } #[test] fn era_weights_with_upgrade() { - const SWITCH_BLOCK_COUNT: usize = 2; + let mut rng = TestRng::new(); + let mut fixture = LmdbTestFixture::new(); + + // Create mock switch blocks for each era and set an appropriate era and height for each one. + let mut switch_blocks: Vec = vec![]; + + // Set an era, height and next era weights for the first one. + switch_blocks.push(new_switch_block_with_weights( + &mut rng, + 10, + 80, + &[(KEYS[0].clone(), 100.into())], + None, + )); + + // Set an era, height and next era weights for the second one. + // Upgrade the version of the second switch block. + switch_blocks.push(new_switch_block_with_weights( + &mut rng, + 11, + 280, + &[(KEYS[1].clone(), 100.into())], + Some(ProtocolVersion::from_parts(1, 1, 0)), + )); - let fixture = LmdbTestFixture::new(vec!["block_header"], None); - // Create mock switch block headers. - let mut switch_block_headers: Vec<(BlockHash, MockSwitchBlockHeader)> = (0..SWITCH_BLOCK_COUNT - as u8) - .map(test_utils::mock_switch_block_header) - .collect(); - // Set an era and height for the first one. - switch_block_headers[0].1.era_id = 10.into(); - switch_block_headers[0].1.height = 80; - // Insert some weight for the next era weights. - switch_block_headers[0] - .1 - .era_end - .as_mut() - .unwrap() - .next_era_validator_weights - .insert(KEYS[0].clone(), 100.into()); - // Set an era and height for the second one. - switch_block_headers[1].1.era_id = 11.into(); - switch_block_headers[1].1.height = 280; - // Insert some weight for the next era weights. - switch_block_headers[1] - .1 - .era_end - .as_mut() - .unwrap() - .next_era_validator_weights - .insert(KEYS[1].clone(), 100.into()); - // Upgrade the version of the second and third switch blocks. - switch_block_headers[1].1.protocol_version = ProtocolVersion::from_parts(1, 1, 0); - - let env = &fixture.env; // Insert the blocks into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for (block_hash, block_header) in switch_block_headers.iter().take(SWITCH_BLOCK_COUNT) { - // Store the switch block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; - let indices = initialize_indices(env, &BTreeSet::from([80, 280])).unwrap(); + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + for switch_block in switch_blocks.iter() { + let _ = rw_txn.write(switch_block).unwrap(); + } + rw_txn.commit().unwrap(); + + let (block_store, _store_dir) = fixture.destructure(); + let block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::default()).unwrap(); + let txn = block_store.checkout_ro().unwrap(); + let indices = initialize_indices(&txn, &BTreeSet::from([80, 280])).unwrap(); let mut era_weights = EraWeights::default(); - if let Ok(txn) = env.begin_ro_txn() { - let db = env.open_db(Some("block_header")).unwrap(); - - assert!(era_weights - .refresh_weights_for_era( - &txn, - db, - &indices, - switch_block_headers[0].1.era_id.successor() - ) - .unwrap()); - - assert!(!era_weights - .refresh_weights_for_era( - &txn, - db, - &indices, - switch_block_headers[1].1.era_id.successor() - ) - .unwrap()); - - assert!(era_weights - .refresh_weights_for_era( - &txn, - db, - &indices, - switch_block_headers[0].1.era_id.successor() - ) - .unwrap()); - - assert!(!era_weights - .refresh_weights_for_era( - &txn, - db, - &indices, - switch_block_headers[1].1.era_id.successor() - ) - .unwrap()); - txn.commit().unwrap(); - }; + assert!(era_weights + .refresh_weights_for_era(&txn, &indices, switch_blocks[0].era_id().successor()) + .unwrap()); + + assert!(!era_weights + .refresh_weights_for_era(&txn, &indices, switch_blocks[1].era_id().successor()) + .unwrap()); + + assert!(era_weights + .refresh_weights_for_era(&txn, &indices, switch_blocks[0].era_id().successor()) + .unwrap()); + + assert!(!era_weights + .refresh_weights_for_era(&txn, &indices, switch_blocks[1].era_id().successor()) + .unwrap()); + + txn.commit().unwrap(); } #[test] fn purge_signatures_should_work() { - const BLOCK_COUNT: usize = 4; - const SWITCH_BLOCK_COUNT: usize = 2; + let mut rng = TestRng::new(); + let mut fixture = LmdbTestFixture::new(); + + // Create mock blocks and set an era and height for each one. + let mut blocks: Vec = vec![]; + blocks.push( + TestBlockBuilder::new() + .height(100) + .era(10) + .switch_block(false) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(200) + .era(10) + .switch_block(false) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(300) + .era(20) + .switch_block(false) + .build(&mut rng) + .into(), + ); + blocks.push( + TestBlockBuilder::new() + .height(400) + .era(20) + .switch_block(false) + .build(&mut rng) + .into(), + ); - let fixture = LmdbTestFixture::new(vec!["block_header", "block_metadata"], None); - // Create mock block headers. - let mut block_headers: Vec<(BlockHash, MockBlockHeader)> = (0..BLOCK_COUNT as u8) - .map(test_utils::mock_block_header) - .collect(); - // Set an era and height for each one. - block_headers[0].1.era_id = 10.into(); - block_headers[0].1.height = 100; - block_headers[1].1.era_id = 10.into(); - block_headers[1].1.height = 200; - block_headers[2].1.era_id = 20.into(); - block_headers[2].1.height = 300; - block_headers[3].1.era_id = 20.into(); - block_headers[3].1.height = 400; // Create mock block signatures. - let mut block_signatures: Vec = block_headers + let mut block_signatures: Vec = blocks .iter() - .map(|(block_hash, header)| BlockSignatures::new(*block_hash, header.era_id)) - .collect(); - // Create mock switch block headers. - let mut switch_block_headers: Vec<(BlockHash, MockSwitchBlockHeader)> = (0..SWITCH_BLOCK_COUNT - as u8) - .map(test_utils::mock_switch_block_header) + .map(|block| { + BlockSignaturesV2::new( + *block.hash(), + block.height(), + block.era_id(), + ChainNameDigest::from_digest(Digest::random(&mut rng).into()), + ) + }) .collect(); - // Set an appropriate era and height for switch block 1. - switch_block_headers[0].1.era_id = block_headers[0].1.era_id - 1; - switch_block_headers[0].1.height = 80; + + // Create mock switch blocks for each era and set an appropriate era and height for each one. // Add weights for this switch block (500, 500). - switch_block_headers[0] - .1 - .insert_key_weight(KEYS[0].clone(), 500.into()); - switch_block_headers[0] - .1 - .insert_key_weight(KEYS[1].clone(), 500.into()); + let mut switch_blocks: Vec = vec![]; + switch_blocks.push(new_switch_block_with_weights( + &mut rng, + (blocks[0].era_id() - 1).value(), + 80, + &[(KEYS[0].clone(), 500.into()), (KEYS[1].clone(), 500.into())], + None, + )); + + // Add weights for this switch block (300, 300, 400). + switch_blocks.push(new_switch_block_with_weights( + &mut rng, + (blocks[2].era_id() - 1).value(), + 280, + &[ + (KEYS[0].clone(), 300.into()), + (KEYS[1].clone(), 300.into()), + (KEYS[2].clone(), 400.into()), + ], + None, + )); // Add keys and signatures for block 1. - block_signatures[0] - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures[0] - .proofs - .insert(KEYS[1].clone(), Signature::System); + block_signatures[0].insert_signature(KEYS[0].clone(), Signature::System); + block_signatures[0].insert_signature(KEYS[1].clone(), Signature::System); // Add keys and signatures for block 2. - block_signatures[1] - .proofs - .insert(KEYS[0].clone(), Signature::System); - - // Set an appropriate era and height for switch block 2. - switch_block_headers[1].1.era_id = block_headers[2].1.era_id - 1; - switch_block_headers[1].1.height = 280; - // Add weights for this switch block (300, 300, 400). - switch_block_headers[1] - .1 - .insert_key_weight(KEYS[0].clone(), 300.into()); - switch_block_headers[1] - .1 - .insert_key_weight(KEYS[1].clone(), 300.into()); - switch_block_headers[1] - .1 - .insert_key_weight(KEYS[2].clone(), 400.into()); + block_signatures[1].insert_signature(KEYS[0].clone(), Signature::System); // Add keys and signatures for block 3. - block_signatures[2] - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures[2] - .proofs - .insert(KEYS[1].clone(), Signature::System); - block_signatures[2] - .proofs - .insert(KEYS[2].clone(), Signature::System); + block_signatures[2].insert_signature(KEYS[0].clone(), Signature::System); + block_signatures[2].insert_signature(KEYS[1].clone(), Signature::System); + block_signatures[2].insert_signature(KEYS[2].clone(), Signature::System); // Add keys and signatures for block 4. - block_signatures[3] - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures[3] - .proofs - .insert(KEYS[2].clone(), Signature::System); - - let env = &fixture.env; + block_signatures[3].insert_signature(KEYS[0].clone(), Signature::System); + block_signatures[3].insert_signature(KEYS[2].clone(), Signature::System); + // Insert the blocks and signatures into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for i in 0..BLOCK_COUNT { - // Store the block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - &block_headers[i].0, - &bincode::serialize(&block_headers[i].1).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the signatures. - txn.put( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[i].0, - &bincode::serialize(&block_signatures[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - for (block_hash, block_header) in switch_block_headers.iter().take(SWITCH_BLOCK_COUNT) { - // Store the switch block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + for switch_block in switch_blocks.iter() { + let _ = rw_txn.write(switch_block).unwrap(); + } + for (id, block) in blocks.iter().enumerate() { + let _ = rw_txn.write(block).unwrap(); + let sigs: BlockSignatures = block_signatures[id].clone().into(); + let _ = rw_txn.write(&sigs).unwrap(); + } + rw_txn.commit().unwrap(); - let indices = initialize_indices(env, &BTreeSet::from([100, 200, 300, 400])).unwrap(); + let (block_store, _store_dir) = fixture.destructure(); + let mut block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::default()).unwrap(); + let txn = block_store.checkout_ro().unwrap(); + let indices = initialize_indices(&txn, &BTreeSet::from([100, 200, 300, 400])).unwrap(); + txn.commit().unwrap(); // Purge signatures for blocks 1, 2 and 3 to weak finality. + let mut txn = block_store.checkout_rw().unwrap(); + assert!(purge_signatures_for_blocks( + &mut txn, + &indices, + BTreeSet::from([100, 200, 300]), + false + ) + .is_ok()); + txn.commit().unwrap(); + + let txn = block_store.checkout_ro().unwrap(); + let block_1_sigs = get_sigs_from_db(&txn, blocks[0].hash()); + // For block 1, any of the 2 signatures will be fine (500/1000), but + // not both. assert!( - purge_signatures_for_blocks(env, &indices, BTreeSet::from([100, 200, 300]), false).is_ok() - ); - if let Ok(txn) = env.begin_ro_txn() { - let block_1_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[0].0); - // For block 1, any of the 2 signatures will be fine (500/1000), but - // not both. - assert!( - (block_1_sigs.proofs.contains_key(&KEYS[0]) - && !block_1_sigs.proofs.contains_key(&KEYS[1])) - || (!block_1_sigs.proofs.contains_key(&KEYS[0]) - && block_1_sigs.proofs.contains_key(&KEYS[1])) - ); - - // Block 2 only had the first signature, which already meets the - // requirements (500/1000). - let block_2_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[1].0); - assert!(block_2_sigs.proofs.contains_key(&KEYS[0])); - assert!(!block_2_sigs.proofs.contains_key(&KEYS[1])); - - // Block 3 had all the keys (300, 300, 400), so it should have kept - // the first 2. - let block_3_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[2].0); - assert!(block_3_sigs.proofs.contains_key(&KEYS[0])); - assert!(block_3_sigs.proofs.contains_key(&KEYS[1])); - assert!(!block_3_sigs.proofs.contains_key(&KEYS[2])); - - // Block 4 had signatures for keys 1 (300) and 3 (400), but it was not - // included in the purge list, so it should have kept both. - let block_4_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[3].0); - assert!(block_4_sigs.proofs.contains_key(&KEYS[0])); - assert!(!block_4_sigs.proofs.contains_key(&KEYS[1])); - assert!(block_4_sigs.proofs.contains_key(&KEYS[2])); - txn.commit().unwrap(); - }; + (block_1_sigs.proofs().contains_key(&KEYS[0]) + && !block_1_sigs.proofs().contains_key(&KEYS[1])) + || (!block_1_sigs.proofs().contains_key(&KEYS[0]) + && block_1_sigs.proofs().contains_key(&KEYS[1])) + ); - // Purge signatures for blocks 1 and 4 to no finality. - assert!(purge_signatures_for_blocks(env, &indices, BTreeSet::from([100, 400]), true).is_ok()); - if let Ok(txn) = env.begin_ro_txn() { - // We should have no record for the signatures of block 1. - match txn.get( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[0].0, - ) { - Err(LmdbError::NotFound) => {} - other => panic!("Unexpected search result: {other:?}"), - } + // Block 2 only had the first signature, which already meets the + // requirements (500/1000). + let block_2_sigs = get_sigs_from_db(&txn, blocks[1].hash()); + assert!(block_2_sigs.proofs().contains_key(&KEYS[0])); + assert!(!block_2_sigs.proofs().contains_key(&KEYS[1])); + + // Block 3 had all the keys (300, 300, 400), so it should have kept + // the first 2. + let block_3_sigs = get_sigs_from_db(&txn, blocks[2].hash()); + assert!(block_3_sigs.proofs().contains_key(&KEYS[0])); + assert!(block_3_sigs.proofs().contains_key(&KEYS[1])); + assert!(!block_3_sigs.proofs().contains_key(&KEYS[2])); + + // Block 4 had signatures for keys 1 (300) and 3 (400), but it was not + // included in the purge list, so it should have kept both. + let block_4_sigs = get_sigs_from_db(&txn, blocks[3].hash()); + assert!(block_4_sigs.proofs().contains_key(&KEYS[0])); + assert!(!block_4_sigs.proofs().contains_key(&KEYS[1])); + assert!(block_4_sigs.proofs().contains_key(&KEYS[2])); + txn.commit().unwrap(); - // Block 2 should be the same as before. - let block_2_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[1].0); - assert!(block_2_sigs.proofs.contains_key(&KEYS[0])); - assert!(!block_2_sigs.proofs.contains_key(&KEYS[1])); - - // Block 3 should be the same as before. - let block_3_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[2].0); - assert!(block_3_sigs.proofs.contains_key(&KEYS[0])); - assert!(block_3_sigs.proofs.contains_key(&KEYS[1])); - assert!(!block_3_sigs.proofs.contains_key(&KEYS[2])); - - // We should have no record for the signatures of block 4. - match txn.get( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[3].0, - ) { - Err(LmdbError::NotFound) => {} - other => panic!("Unexpected search result: {other:?}"), - } - txn.commit().unwrap(); - }; + // Purge signatures for blocks 1 and 4 to no finality. + let mut txn = block_store.checkout_rw().unwrap(); + assert!( + purge_signatures_for_blocks(&mut txn, &indices, BTreeSet::from([100, 400]), true).is_ok() + ); + txn.commit().unwrap(); + + let txn = block_store.checkout_ro().unwrap(); + // We should have no record for the signatures of block 1. + let maybe_block_sigs: Option = txn.read(*blocks[0].hash()).unwrap(); + assert!(maybe_block_sigs.is_none()); + + // Block 2 should be the same as before. + let block_2_sigs = get_sigs_from_db(&txn, blocks[1].hash()); + assert!(block_2_sigs.proofs().contains_key(&KEYS[0])); + assert!(!block_2_sigs.proofs().contains_key(&KEYS[1])); + + // Block 3 should be the same as before. + let block_3_sigs = get_sigs_from_db(&txn, blocks[2].hash()); + assert!(block_3_sigs.proofs().contains_key(&KEYS[0])); + assert!(block_3_sigs.proofs().contains_key(&KEYS[1])); + assert!(!block_3_sigs.proofs().contains_key(&KEYS[2])); + + // We should have no record for the signatures of block 4. + let maybe_block_sigs: Option = txn.read(*blocks[3].hash()).unwrap(); + assert!(maybe_block_sigs.is_none()); + txn.commit().unwrap(); } #[test] fn purge_signatures_bad_input() { - const BLOCK_COUNT: usize = 2; - const SWITCH_BLOCK_COUNT: usize = 2; + let mut rng = TestRng::new(); + let mut fixture = LmdbTestFixture::new(); - let fixture = LmdbTestFixture::new(vec!["block_header", "block_metadata"], None); - // Create mock block headers. - let mut block_headers: Vec<(BlockHash, MockBlockHeader)> = (0..BLOCK_COUNT as u8) - .map(test_utils::mock_block_header) - .collect(); + // Create mock blocks and set an era and height for each one. + let mut blocks: Vec = vec![]; // Set an era and height for block 1. - block_headers[0].1.era_id = 10.into(); - block_headers[0].1.height = 100; + blocks.push( + TestBlockBuilder::new() + .height(100) + .era(10) + .switch_block(false) + .build(&mut rng) + .into(), + ); // Set an era and height for block 2. - block_headers[1].1.era_id = 20.into(); - block_headers[1].1.height = 200; + blocks.push( + TestBlockBuilder::new() + .height(200) + .era(20) + .switch_block(false) + .build(&mut rng) + .into(), + ); + // Create mock block signatures. - let mut block_signatures: Vec = block_headers + let mut block_signatures: Vec = blocks .iter() - .map(|(block_hash, header)| BlockSignatures::new(*block_hash, header.era_id)) - .collect(); - // Create mock switch block headers. - let mut switch_block_headers: Vec<(BlockHash, MockSwitchBlockHeader)> = (0..SWITCH_BLOCK_COUNT - as u8) - .map(test_utils::mock_switch_block_header) + .map(|block| { + BlockSignaturesV2::new( + *block.hash(), + block.height(), + block.era_id(), + ChainNameDigest::from_digest(Digest::random(&mut rng).into()), + ) + }) .collect(); - // Set an appropriate era and height for switch block 1. - switch_block_headers[0].1.era_id = block_headers[0].1.era_id - 1; - switch_block_headers[0].1.height = 80; + + // Create mock switch blocks for each era and set an appropriate era and height for each one. + let mut switch_blocks: Vec = vec![]; // Add weights for this switch block (700, 300). - switch_block_headers[0] - .1 - .insert_key_weight(KEYS[0].clone(), 700.into()); - switch_block_headers[0] - .1 - .insert_key_weight(KEYS[1].clone(), 300.into()); + switch_blocks.push(new_switch_block_with_weights( + &mut rng, + (blocks[0].era_id() - 1).value(), + 80, + &[(KEYS[0].clone(), 700.into()), (KEYS[1].clone(), 300.into())], + None, + )); + // Add weights for this switch block (400, 600). + switch_blocks.push(new_switch_block_with_weights( + &mut rng, + (blocks[1].era_id() - 1).value(), + 180, + &[(KEYS[0].clone(), 400.into()), (KEYS[1].clone(), 600.into())], + None, + )); // Add keys and signatures for block 1. - block_signatures[0] - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures[0] - .proofs - .insert(KEYS[1].clone(), Signature::System); - - // Set an appropriate era and height for switch block 2. - switch_block_headers[1].1.era_id = block_headers[1].1.era_id - 1; - switch_block_headers[1].1.height = 180; - // Add weights for this switch block (400, 600). - switch_block_headers[1] - .1 - .insert_key_weight(KEYS[0].clone(), 400.into()); - switch_block_headers[1] - .1 - .insert_key_weight(KEYS[1].clone(), 600.into()); + block_signatures[0].insert_signature(KEYS[0].clone(), Signature::System); + block_signatures[0].insert_signature(KEYS[1].clone(), Signature::System); // Add keys and signatures for block 2. - block_signatures[1] - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures[1] - .proofs - .insert(KEYS[1].clone(), Signature::System); - - let env = &fixture.env; + block_signatures[1].insert_signature(KEYS[0].clone(), Signature::System); + block_signatures[1].insert_signature(KEYS[1].clone(), Signature::System); + // Insert the blocks and signatures into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for i in 0..BLOCK_COUNT { - // Store the block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - &block_headers[i].0, - &bincode::serialize(&block_headers[i].1).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the signatures. - txn.put( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[i].0, - &bincode::serialize(&block_signatures[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - for (block_hash, block_header) in switch_block_headers.iter().take(SWITCH_BLOCK_COUNT) { - // Store the switch block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + for switch_block in switch_blocks.iter() { + let _ = rw_txn.write(switch_block).unwrap(); + } + for (id, block) in blocks.iter().enumerate() { + let _ = rw_txn.write(block).unwrap(); + let sigs: BlockSignatures = block_signatures[id].clone().into(); + let _ = rw_txn.write(&sigs).unwrap(); + } + rw_txn.commit().unwrap(); + + let (block_store, _store_dir) = fixture.destructure(); + let mut block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::default()).unwrap(); + let txn = block_store.checkout_ro().unwrap(); + let indices = initialize_indices(&txn, &BTreeSet::from([100])).unwrap(); + txn.commit().unwrap(); - let indices = initialize_indices(env, &BTreeSet::from([100])).unwrap(); // Purge signatures for blocks 1 and 2 to weak finality. - assert!(purge_signatures_for_blocks(env, &indices, BTreeSet::from([100, 200]), false).is_ok()); - if let Ok(txn) = env.begin_ro_txn() { - let block_1_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[0].0); + let mut txn = block_store.checkout_rw().unwrap(); + assert!( + purge_signatures_for_blocks(&mut txn, &indices, BTreeSet::from([100, 200]), false).is_ok() + ); + txn.commit().unwrap(); + + if let Ok(txn) = block_store.checkout_ro() { + let block_1_sigs = get_sigs_from_db(&txn, blocks[0].hash()); // Block 1 has a super-majority signature (700), so the purge would // have failed and the signatures are untouched. - assert!(block_1_sigs.proofs.contains_key(&KEYS[0])); - assert!(block_1_sigs.proofs.contains_key(&KEYS[1])); + assert!(block_1_sigs.proofs().contains_key(&KEYS[0])); + assert!(block_1_sigs.proofs().contains_key(&KEYS[1])); - let block_2_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[1].0); + let block_2_sigs = get_sigs_from_db(&txn, blocks[1].hash()); // Block 2 wasn't in the purge list, so it should be untouched. - assert!(block_2_sigs.proofs.contains_key(&KEYS[0])); - assert!(block_2_sigs.proofs.contains_key(&KEYS[1])); - txn.commit().unwrap(); - }; - - // Overwrite the signatures for block 2 with bogus data. - if let Ok(mut txn) = env.begin_rw_txn() { - // Store the signatures. - txn.put( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[1].0, - &bincode::serialize(&[0u8, 1u8, 2u8]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); + assert!(block_2_sigs.proofs().contains_key(&KEYS[0])); + assert!(block_2_sigs.proofs().contains_key(&KEYS[1])); txn.commit().unwrap(); }; - - let indices = initialize_indices(env, &BTreeSet::from([100, 200])).unwrap(); - // Purge should fail with a deserialization error. - match purge_signatures_for_blocks(env, &indices, BTreeSet::from([100, 200]), false) { - Err(Error::SignaturesParsing(block_hash, _)) if block_hash == block_headers[1].0 => {} - other => panic!("Unexpected result: {other:?}"), - }; } #[test] fn purge_signatures_missing_from_db() { - const BLOCK_COUNT: usize = 2; + let mut rng = TestRng::new(); + let mut fixture = LmdbTestFixture::new(); + + // Create mock blocks and set an era and height for each one. + let mut blocks: Vec = vec![]; + // Set an era and height for block 1. + blocks.push( + TestBlockBuilder::new() + .height(100) + .era(10) + .switch_block(false) + .build(&mut rng) + .into(), + ); + // Set an era and height for block 2. + blocks.push( + TestBlockBuilder::new() + .height(200) + .era(10) + .switch_block(false) + .build(&mut rng) + .into(), + ); - let fixture = LmdbTestFixture::new(vec!["block_header", "block_metadata"], None); - // Create mock block headers. - let mut block_headers: Vec<(BlockHash, MockBlockHeader)> = (0..BLOCK_COUNT as u8) - .map(test_utils::mock_block_header) - .collect(); - // Set an era and height for each one. - block_headers[0].1.era_id = 10.into(); - block_headers[0].1.height = 100; - block_headers[1].1.era_id = 10.into(); - block_headers[1].1.height = 200; // Create mock block signatures. - let mut block_signatures: Vec = block_headers + let mut block_signatures: Vec = blocks .iter() - .map(|(block_hash, header)| BlockSignatures::new(*block_hash, header.era_id)) + .map(|block| { + BlockSignaturesV2::new( + *block.hash(), + block.height(), + block.era_id(), + ChainNameDigest::from_digest(Digest::random(&mut rng).into()), + ) + }) .collect(); - // Create mock switch block headers. - let (switch_block_hash, mut switch_block_header) = test_utils::mock_switch_block_header(0); - // Set an appropriate era and height for switch block 1. - switch_block_header.era_id = block_headers[0].1.era_id - 1; - switch_block_header.height = 80; + // Add weights for this switch block (400, 600). - switch_block_header.insert_key_weight(KEYS[0].clone(), 400.into()); - switch_block_header.insert_key_weight(KEYS[1].clone(), 600.into()); + let switch_block = new_switch_block_with_weights( + &mut rng, + (blocks[0].era_id() - 1).value(), + 80, + &[(KEYS[0].clone(), 400.into()), (KEYS[1].clone(), 600.into())], + None, + ); // Add keys and signatures for block 1 but skip block 2. - block_signatures[0] - .proofs - .insert(KEYS[0].clone(), Signature::System); - block_signatures[0] - .proofs - .insert(KEYS[1].clone(), Signature::System); - - let env = &fixture.env; + block_signatures[0].insert_signature(KEYS[0].clone(), Signature::System); + block_signatures[0].insert_signature(KEYS[1].clone(), Signature::System); + // Insert the blocks and signatures into the database. - if let Ok(mut txn) = env.begin_rw_txn() { - for (block_hash, block_header) in block_headers.iter().take(BLOCK_COUNT) { - // Store the block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - block_hash, - &bincode::serialize(block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - // Store the signatures for block 1. - txn.put( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[0].0, - &bincode::serialize(&block_signatures[0]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the switch block header. - txn.put( - *fixture.db(Some("block_header")).unwrap(), - &switch_block_hash, - &bincode::serialize(&switch_block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - txn.commit().unwrap(); - }; + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + let _ = rw_txn.write(&switch_block).unwrap(); + + for block in blocks.iter() { + let _ = rw_txn.write(block).unwrap(); + } - let indices = initialize_indices(env, &BTreeSet::from([100, 200])).unwrap(); + // Only store signatures for block 1. + let sigs: BlockSignatures = block_signatures[0].clone().into(); + let _ = rw_txn.write(&sigs).unwrap(); + rw_txn.commit().unwrap(); + + let (block_store, _store_dir) = fixture.destructure(); + let mut block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::default()).unwrap(); + let txn = block_store.checkout_ro().unwrap(); + let indices = initialize_indices(&txn, &BTreeSet::from([100, 200])).unwrap(); + txn.commit().unwrap(); // Purge signatures for blocks 1 and 2 to weak finality. The operation // should succeed even if the signatures for block 2 are missing. - assert!(purge_signatures_for_blocks(env, &indices, BTreeSet::from([100, 200]), false).is_ok()); - if let Ok(txn) = env.begin_ro_txn() { - let block_1_sigs = get_sigs_from_db(&txn, &fixture, &block_headers[0].0); + let mut txn = block_store.checkout_rw().unwrap(); + assert!( + purge_signatures_for_blocks(&mut txn, &indices, BTreeSet::from([100, 200]), false).is_ok() + ); + txn.commit().unwrap(); + + if let Ok(txn) = block_store.checkout_ro() { + let block_1_sigs = get_sigs_from_db(&txn, blocks[0].hash()); // Block 1 had both keys (400, 600), so it should have kept // the first one. - assert!(block_1_sigs.proofs.contains_key(&KEYS[0])); - assert!(!block_1_sigs.proofs.contains_key(&KEYS[1])); + assert!(block_1_sigs.proofs().contains_key(&KEYS[0])); + assert!(!block_1_sigs.proofs().contains_key(&KEYS[1])); // We should have no record for the signatures of block 2. - match txn.get( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[1].0, - ) { - Err(LmdbError::NotFound) => {} - other => panic!("Unexpected search result: {other:?}"), - } + let maybe_block_sigs: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(maybe_block_sigs.is_none()); + txn.commit().unwrap(); }; // Purge signatures for blocks 1 and 2 to no finality. The operation // should succeed even if the signatures for block 2 are missing. - assert!(purge_signatures_for_blocks(env, &indices, BTreeSet::from([100, 200]), true).is_ok()); - if let Ok(txn) = env.begin_ro_txn() { + let mut txn = block_store.checkout_rw().unwrap(); + assert!( + purge_signatures_for_blocks(&mut txn, &indices, BTreeSet::from([100, 200]), true).is_ok() + ); + txn.commit().unwrap(); + + if let Ok(txn) = block_store.checkout_ro() { // We should have no record for the signatures of block 1. - match txn.get( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[0].0, - ) { - Err(LmdbError::NotFound) => {} - other => panic!("Unexpected search result: {other:?}"), - } + let maybe_block_sigs: Option = txn.read(*blocks[0].hash()).unwrap(); + assert!(maybe_block_sigs.is_none()); // We should have no record for the signatures of block 2. - match txn.get( - *fixture.db(Some("block_metadata")).unwrap(), - &block_headers[1].0, - ) { - Err(LmdbError::NotFound) => {} - other => panic!("Unexpected search result: {other:?}"), - } + let maybe_block_sigs: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(maybe_block_sigs.is_none()); txn.commit().unwrap(); }; } diff --git a/src/subcommands/remove_block.rs b/src/subcommands/remove_block.rs index 548c516..5d60f87 100644 --- a/src/subcommands/remove_block.rs +++ b/src/subcommands/remove_block.rs @@ -4,9 +4,9 @@ mod tests; use std::path::Path; -use bincode::Error as BincodeError; -use casper_hashing::Digest; -use casper_node::types::{BlockHash, DeployHash}; +use casper_storage::block_store::BlockStoreError; +use casper_types::BlockHash; +use casper_types::Digest; use clap::{Arg, ArgMatches, Command}; use lmdb::Error as LmdbError; use thiserror::Error as ThisError; @@ -18,27 +18,15 @@ const DB_PATH: &str = "db-path"; /// Errors encountered when operating on the storage database. #[derive(Debug, ThisError)] pub enum Error { - /// Parsing error on entry in the block body database. - #[error("Error parsing block body for block with hash {0}: {1}")] - BodyParsing(BlockHash, BincodeError), /// Database operation error. #[error("Error operating the database: {0}")] Database(#[from] LmdbError), - /// Parsing error on entry in the deploy metadata database. - #[error("Error parsing execution results for block with hash {0} at deploy {1}: {2}")] - ExecutionResultsParsing(BlockHash, DeployHash, BincodeError), - /// Parsing error on entry in the block header database. - #[error("Error parsing block header with hash {0}: {1}")] - HeaderParsing(BlockHash, BincodeError), - /// Missing entry in the deploy metadata database. - #[error("Deploy with hash {0} not present in the database")] - MissingDeploy(DeployHash), /// Missing entry in the block header database. #[error("Block header for block hash {0} not present in the database")] MissingHeader(BlockHash), - /// Serialization error on entry in the deploy metadata database. - #[error("Error serializing execution results for deploy {0}: {1}")] - Serialization(DeployHash, BincodeError), + /// Block store error. + #[error("Encountered a block store error: {0}")] + BlockStore(#[from] BlockStoreError), } enum DisplayOrder { diff --git a/src/subcommands/remove_block/remove.rs b/src/subcommands/remove_block/remove.rs index a17834d..5c711f4 100644 --- a/src/subcommands/remove_block/remove.rs +++ b/src/subcommands/remove_block/remove.rs @@ -1,89 +1,48 @@ use std::path::Path; -use casper_node::types::{BlockHash, BlockHeader, DeployMetadata}; -use lmdb::{Error as LmdbError, Transaction, WriteFlags}; -use log::warn; - -use crate::{ - common::db::{ - self, BlockBodyDatabase, BlockHeaderDatabase, Database, DeployMetadataDatabase, - STORAGE_FILE_NAME, - }, - subcommands::execution_results_summary::block_body::BlockBody, +use crate::common::db::{ + DEFAULT_MAX_BLOCK_STORE_SIZE, DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + DEFAULT_MAX_DEPLOY_STORE_SIZE, }; use super::Error; +use casper_storage::block_store::{ + lmdb::LmdbBlockStore, + types::{ApprovalsHashes, BlockExecutionResults, BlockHashHeightAndEra, BlockTransfers}, + BlockStoreProvider, BlockStoreTransaction, DataReader, DataWriter, +}; +use casper_types::{Block, BlockHash, BlockHeader, BlockSignatures, Transaction, TransactionHash}; pub(crate) fn remove_block>(db_path: P, block_hash: BlockHash) -> Result<(), Error> { - let storage_path = db_path.as_ref().join(STORAGE_FILE_NAME); - let env = db::db_env(storage_path)?; - - let mut txn = env.begin_rw_txn()?; - let header_db = unsafe { txn.open_db(Some(BlockHeaderDatabase::db_name()))? }; - let body_db = unsafe { txn.open_db(Some(BlockBodyDatabase::db_name()))? }; - let deploy_metadata_db = unsafe { txn.open_db(Some(DeployMetadataDatabase::db_name()))? }; - - let header: BlockHeader = match txn.get(header_db, &block_hash) { - Ok(raw_header) => bincode::deserialize(raw_header) - .map_err(|bincode_err| Error::HeaderParsing(block_hash, bincode_err))?, - Err(LmdbError::NotFound) => { - return Err(Error::MissingHeader(block_hash)); - } - Err(lmdb_err) => { - return Err(lmdb_err.into()); - } + let mut block_store = LmdbBlockStore::new( + db_path.as_ref(), + DEFAULT_MAX_BLOCK_STORE_SIZE + + DEFAULT_MAX_DEPLOY_STORE_SIZE + + DEFAULT_MAX_DEPLOY_METADATA_STORE_SIZE, + )?; + + let mut rw_txn = block_store.checkout_rw()?; + + let maybe_block_header: Option = rw_txn.read(block_hash)?; + let block_info = if let Some(header) = maybe_block_header { + BlockHashHeightAndEra::new(block_hash, header.height(), header.era_id()) + } else { + return Err(Error::MissingHeader(block_hash)); }; - let maybe_body: Option = match txn.get(body_db, header.body_hash()) { - Ok(raw_body) => Some( - bincode::deserialize(raw_body) - .map_err(|bincode_err| Error::BodyParsing(block_hash, bincode_err))?, - ), - Err(LmdbError::NotFound) => { - warn!( - "No block body found for block header with hash {}", - block_hash - ); - None + let maybe_block: Option = rw_txn.read(block_hash)?; + if let Some(block) = maybe_block { + for transaction_hash in block.all_transaction_hashes() { + DataWriter::::delete(&mut rw_txn, transaction_hash)?; } - Err(lmdb_err) => { - return Err(lmdb_err.into()); - } - }; - - if let Some(body) = maybe_body { - // Go through all the deploys in this block and get the execution - // result of each one. - for deploy_hash in body.deploy_hashes() { - // Get this deploy's metadata. - let mut metadata: DeployMetadata = match txn.get(deploy_metadata_db, deploy_hash) { - Ok(raw_metadata) => bincode::deserialize(raw_metadata).map_err(|bincode_err| { - Error::ExecutionResultsParsing(block_hash, *deploy_hash, bincode_err) - })?, - Err(LmdbError::NotFound) => return Err(Error::MissingDeploy(*deploy_hash)), - Err(lmdb_error) => return Err(lmdb_error.into()), - }; - // Extract the execution result of this deploy for the current block. - if let Some(_execution_result) = metadata.execution_results.remove(&block_hash) { - if metadata.execution_results.is_empty() { - txn.del(deploy_metadata_db, deploy_hash, None)?; - } else { - let encoded_metadata = bincode::serialize(&metadata) - .map_err(|bincode_err| Error::Serialization(*deploy_hash, bincode_err))?; - txn.put( - deploy_metadata_db, - deploy_hash, - &encoded_metadata, - WriteFlags::default(), - )?; - } - } - } - - txn.del(body_db, header.body_hash(), None)?; } - txn.del(header_db, &block_hash, None)?; - txn.commit()?; + DataWriter::::delete(&mut rw_txn, block_info)?; + DataWriter::::delete(&mut rw_txn, block_hash)?; + DataWriter::::delete(&mut rw_txn, block_hash)?; + DataWriter::::delete(&mut rw_txn, block_hash)?; + DataWriter::::delete(&mut rw_txn, block_hash)?; + + rw_txn.commit()?; Ok(()) } diff --git a/src/subcommands/remove_block/tests.rs b/src/subcommands/remove_block/tests.rs index 1225991..5ff53a5 100644 --- a/src/subcommands/remove_block/tests.rs +++ b/src/subcommands/remove_block/tests.rs @@ -1,631 +1,292 @@ -use std::slice; - -use casper_node::types::{BlockHash, DeployHash, DeployMetadata}; -use lmdb::{Error as LmdbError, Transaction, WriteFlags}; +use casper_storage::block_store::{ + types::{BlockExecutionResults, BlockHashHeightAndEra}, + BlockStoreProvider, BlockStoreTransaction, DataReader, DataWriter, +}; +use casper_types::{ + execution::ExecutionResult, testing::TestRng, Block, BlockHeader, TestBlockBuilder, Transaction, +}; use crate::{ - common::db::{ - BlockBodyDatabase, BlockHeaderDatabase, Database, DeployMetadataDatabase, STORAGE_FILE_NAME, - }, - subcommands::{ - execution_results_summary::block_body::BlockBody, - remove_block::{remove::remove_block, Error}, - }, - test_utils::{ - mock_block_header, mock_deploy_hash, mock_deploy_metadata, LmdbTestFixture, MockBlockHeader, - }, + subcommands::remove_block::{remove::remove_block, Error}, + test_utils::LmdbTestFixture, }; #[test] fn remove_block_should_work() { - const BLOCK_COUNT: usize = 2; - const DEPLOY_COUNT: usize = 3; - - let test_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), + const TRANSACTION_COUNT: usize = 4; + + let mut rng = TestRng::new(); + let mut test_fixture = LmdbTestFixture::new(); + + let transactions: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| Transaction::random(&mut rng)) + .collect(); + let mut blocks: Vec = vec![]; + let mut block_transactions_map: Vec> = vec![]; + blocks.push( + TestBlockBuilder::new() + .transactions([0, 1].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), ); + block_transactions_map.push(vec![0, 1]); + blocks.push( + TestBlockBuilder::new() + .transactions([2, 3].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), + ); + block_transactions_map.push(vec![2, 3]); - let deploy_hashes: Vec = (0..DEPLOY_COUNT as u8).map(mock_deploy_hash).collect(); - let block_headers: Vec<(BlockHash, MockBlockHeader)> = - (0..BLOCK_COUNT as u8).map(mock_block_header).collect(); - let mut block_bodies = vec![]; - let mut block_body_deploy_map: Vec> = vec![]; - block_bodies.push(BlockBody::new(vec![deploy_hashes[0], deploy_hashes[1]])); - block_body_deploy_map.push(vec![0, 1]); - block_bodies.push(BlockBody::new(vec![deploy_hashes[1], deploy_hashes[2]])); - block_body_deploy_map.push(vec![1, 2]); - - let deploy_metadatas = vec![ - mock_deploy_metadata(slice::from_ref(&block_headers[0].0)), - mock_deploy_metadata(&[block_headers[0].0, block_headers[1].0]), - mock_deploy_metadata(slice::from_ref(&block_headers[1].0)), - ]; - - // Insert the 2 blocks into the database. - { - let mut txn = test_fixture.env.begin_rw_txn().unwrap(); - for i in 0..BLOCK_COUNT { - // Store the header. - txn.put( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[i].0, - &bincode::serialize(&block_headers[i].1).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the body. - txn.put( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_headers[i].1.body_hash, - &bincode::serialize(&block_bodies[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - - // Insert the 3 deploys into the deploys and deploy_metadata databases. - for i in 0..DEPLOY_COUNT { - txn.put( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[i], - &bincode::serialize(&deploy_metadatas[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; + let exec_results: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| ExecutionResult::random(&mut rng)) + .collect(); + + let mut rw_txn = test_fixture.block_store.checkout_rw().unwrap(); + + for transaction in transactions.iter() { + let _ = rw_txn.write(transaction).unwrap(); + } - assert!(remove_block(test_fixture.tmp_dir.path(), block_headers[0].0).is_ok()); + for (block_id, block) in blocks.iter().enumerate() { + let block_hash = rw_txn.write(block).unwrap(); + + let height = block.height(); + let era = block.era_id(); + + let block_info = BlockHashHeightAndEra::new(block_hash, height, era); + + let block_exec_results = BlockExecutionResults { + block_info, + exec_results: block_transactions_map[block_id] + .iter() + .map(|id| (transactions[*id].hash(), exec_results[*id].clone())) + .collect(), + }; + rw_txn.write(&block_exec_results).unwrap(); + } + rw_txn.commit().unwrap(); + + assert!(remove_block(test_fixture.tmp_dir.path(), *blocks[0].hash()).is_ok()); { - let txn = test_fixture.env.begin_ro_txn().unwrap(); - assert_eq!( - txn.get( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[0].0, - ) - .unwrap_err(), - LmdbError::NotFound - ); - assert!(txn - .get( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[1].0, - ) - .is_ok()); - - assert_eq!( - txn.get( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_headers[0].1.body_hash, - ) - .unwrap_err(), - LmdbError::NotFound - ); - assert!(txn - .get( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_headers[1].1.body_hash, - ) - .is_ok()); - - assert_eq!( - txn.get( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[0] - ) - .unwrap_err(), - LmdbError::NotFound - ); - - let deploy_metadata: DeployMetadata = bincode::deserialize( - txn.get( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[1], - ) - .unwrap(), - ) - .unwrap(); - assert!(!deploy_metadata - .execution_results - .contains_key(&block_headers[0].0)); - assert!(deploy_metadata - .execution_results - .contains_key(&block_headers[1].0)); - - let deploy_metadata: DeployMetadata = bincode::deserialize( - txn.get( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[2], - ) - .unwrap(), - ) - .unwrap(); - assert!(!deploy_metadata - .execution_results - .contains_key(&block_headers[0].0)); - assert!(deploy_metadata - .execution_results - .contains_key(&block_headers[1].0)); + let txn = test_fixture.block_store.checkout_ro().unwrap(); + let removed_block_header: Option = txn.read(*blocks[0].hash()).unwrap(); + assert!(removed_block_header.is_none()); + let removed_block: Option = txn.read(*blocks[0].hash()).unwrap(); + assert!(removed_block.is_none()); + + let block_header: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(block_header.is_some()); + let block: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(block.is_some()); + + // Transactions included in the removed blocks should be removed. + let transaction: Option = txn.read(transactions[0].hash()).unwrap(); + assert!(transaction.is_none()); + let transaction: Option = txn.read(transactions[1].hash()).unwrap(); + assert!(transaction.is_none()); + + // Exec results for transactions included in the removed block should be removed. + let exec_result: Option = txn.read(transactions[0].hash()).unwrap(); + assert!(exec_result.is_none()); + let exec_result: Option = txn.read(transactions[1].hash()).unwrap(); + assert!(exec_result.is_none()); txn.commit().unwrap(); } } #[test] fn remove_block_no_deploys() { - const BLOCK_COUNT: usize = 2; - const DEPLOY_COUNT: usize = 3; - - let test_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), + const TRANSACTION_COUNT: usize = 3; + + let mut rng = TestRng::new(); + let mut test_fixture = LmdbTestFixture::new(); + + let transactions: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| Transaction::random(&mut rng)) + .collect(); + let mut blocks: Vec = vec![]; + let mut block_transactions_map: Vec> = vec![]; + + blocks.push(TestBlockBuilder::new().build(&mut rng).into()); + block_transactions_map.push(vec![]); + blocks.push( + TestBlockBuilder::new() + .transactions([1, 2].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), ); + block_transactions_map.push(vec![1, 2]); - let deploy_hashes: Vec = (0..DEPLOY_COUNT as u8).map(mock_deploy_hash).collect(); - let block_headers: Vec<(BlockHash, MockBlockHeader)> = - (0..BLOCK_COUNT as u8).map(mock_block_header).collect(); - let mut block_bodies = vec![]; - let mut block_body_deploy_map: Vec> = vec![]; - block_bodies.push(BlockBody::new(vec![])); - block_body_deploy_map.push(vec![]); - block_bodies.push(BlockBody::new(vec![deploy_hashes[1], deploy_hashes[2]])); - block_body_deploy_map.push(vec![1, 2]); - - let deploy_metadatas = vec![ - mock_deploy_metadata(&[]), - mock_deploy_metadata(slice::from_ref(&block_headers[1].0)), - mock_deploy_metadata(slice::from_ref(&block_headers[1].0)), - ]; - - // Insert the 2 blocks into the database. - { - let mut txn = test_fixture.env.begin_rw_txn().unwrap(); - for i in 0..BLOCK_COUNT { - // Store the header. - txn.put( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[i].0, - &bincode::serialize(&block_headers[i].1).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the body. - txn.put( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_headers[i].1.body_hash, - &bincode::serialize(&block_bodies[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - - // Insert the last 2 deploys into the deploys and deploy_metadata - // databases. - for i in 1..DEPLOY_COUNT { - txn.put( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[i], - &bincode::serialize(&deploy_metadatas[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; + let exec_results: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| ExecutionResult::random(&mut rng)) + .collect(); - assert!(remove_block(test_fixture.tmp_dir.path(), block_headers[0].0).is_ok()); + let mut rw_txn = test_fixture.block_store.checkout_rw().unwrap(); - { - let txn = test_fixture.env.begin_ro_txn().unwrap(); - assert_eq!( - txn.get( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[0].0, - ) - .unwrap_err(), - LmdbError::NotFound - ); - assert!(txn - .get( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[1].0, - ) - .is_ok()); - - assert_eq!( - txn.get( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_headers[0].1.body_hash, - ) - .unwrap_err(), - LmdbError::NotFound - ); - assert!(txn - .get( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_headers[1].1.body_hash, - ) - .is_ok()); - - assert_eq!( - txn.get( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[0] - ) - .unwrap_err(), - LmdbError::NotFound - ); - - let deploy_metadata: DeployMetadata = bincode::deserialize( - txn.get( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[1], - ) - .unwrap(), - ) - .unwrap(); - assert!(!deploy_metadata - .execution_results - .contains_key(&block_headers[0].0)); - assert!(deploy_metadata - .execution_results - .contains_key(&block_headers[1].0)); - - let deploy_metadata: DeployMetadata = bincode::deserialize( - txn.get( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[2], - ) - .unwrap(), - ) - .unwrap(); - assert!(!deploy_metadata - .execution_results - .contains_key(&block_headers[0].0)); - assert!(deploy_metadata - .execution_results - .contains_key(&block_headers[1].0)); - txn.commit().unwrap(); + for i in 1..TRANSACTION_COUNT { + let _ = rw_txn.write(&transactions[i]).unwrap(); } -} -#[test] -fn remove_block_missing_header() { - let test_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), - ); + for (block_id, block) in blocks.iter().enumerate() { + let block_hash = rw_txn.write(block).unwrap(); - let (block_hash, _block_header) = mock_block_header(0); - assert!( - matches!(remove_block(test_fixture.tmp_dir.path(), block_hash).unwrap_err(), Error::MissingHeader(actual_block_hash) if block_hash == actual_block_hash) - ); -} + let height = block.height(); + let era = block.era_id(); -#[test] -fn remove_block_missing_body() { - const BLOCK_COUNT: usize = 2; - const DEPLOY_COUNT: usize = 3; - - let test_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), - ); + let block_info = BlockHashHeightAndEra::new(block_hash, height, era); - let deploy_hashes: Vec = (0..DEPLOY_COUNT as u8).map(mock_deploy_hash).collect(); - let block_headers: Vec<(BlockHash, MockBlockHeader)> = - (0..BLOCK_COUNT as u8).map(mock_block_header).collect(); - let mut block_bodies = vec![]; - let mut block_body_deploy_map: Vec> = vec![]; - block_bodies.push(BlockBody::new(vec![deploy_hashes[0], deploy_hashes[1]])); - block_body_deploy_map.push(vec![0, 1]); - block_bodies.push(BlockBody::new(vec![deploy_hashes[1], deploy_hashes[2]])); - block_body_deploy_map.push(vec![1, 2]); - - let deploy_metadatas = vec![ - mock_deploy_metadata(slice::from_ref(&block_headers[0].0)), - mock_deploy_metadata(&[block_headers[0].0, block_headers[1].0]), - mock_deploy_metadata(slice::from_ref(&block_headers[1].0)), - ]; - - // Insert the 2 block headers into the database. - { - let mut txn = test_fixture.env.begin_rw_txn().unwrap(); - for (block_hash, block_header) in block_headers.iter().take(BLOCK_COUNT) { - // Store the header. - txn.put( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - block_hash, - &bincode::serialize(block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - - // Insert the 3 deploys into the deploys and deploy_metadata databases. - for i in 0..DEPLOY_COUNT { - txn.put( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hashes[i], - &bincode::serialize(&deploy_metadatas[i]).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - } - txn.commit().unwrap(); - }; + let block_exec_results = BlockExecutionResults { + block_info, + exec_results: block_transactions_map[block_id] + .iter() + .map(|id| (transactions[*id].hash(), exec_results[*id].clone())) + .collect(), + }; + rw_txn.write(&block_exec_results).unwrap(); + } + rw_txn.commit().unwrap(); - assert!(remove_block(test_fixture.tmp_dir.path(), block_headers[0].0).is_ok()); + assert!(remove_block(test_fixture.tmp_dir.path(), *blocks[0].hash()).is_ok()); { - let txn = test_fixture.env.begin_ro_txn().unwrap(); - assert_eq!( - txn.get( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[0].0, - ) - .unwrap_err(), - LmdbError::NotFound - ); - assert!(txn - .get( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_headers[1].0, - ) - .is_ok()); - - assert_eq!( - txn.get( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_headers[0].1.body_hash, - ) - .unwrap_err(), - LmdbError::NotFound - ); - assert_eq!( - txn.get( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_headers[1].1.body_hash, - ) - .unwrap_err(), - LmdbError::NotFound - ); + let txn = test_fixture.block_store.checkout_ro().unwrap(); + let removed_block_header: Option = txn.read(*blocks[0].hash()).unwrap(); + assert!(removed_block_header.is_none()); + let removed_block: Option = txn.read(*blocks[0].hash()).unwrap(); + assert!(removed_block.is_none()); + + let block_header: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(block_header.is_some()); + let block: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(block.is_some()); + + let transaction: Option = txn.read(transactions[0].hash()).unwrap(); + assert!(transaction.is_none()); + + let transaction: Option = txn.read(transactions[1].hash()).unwrap(); + assert!(transaction.is_some()); + let transaction: Option = txn.read(transactions[2].hash()).unwrap(); + assert!(transaction.is_some()); + + let exec_result: Option = txn.read(transactions[0].hash()).unwrap(); + assert!(exec_result.is_none()); + let exec_result: Option = txn.read(transactions[1].hash()).unwrap(); + assert!(exec_result.is_some()); + let exec_result: Option = txn.read(transactions[2].hash()).unwrap(); + assert!(exec_result.is_some()); + txn.commit().unwrap(); } } #[test] -fn remove_block_missing_deploys() { - let test_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), - ); - - let (block_hash, block_header) = mock_block_header(0); - let deploy_hash = mock_deploy_hash(0); - let block_body = BlockBody::new(vec![deploy_hash]); - - // Insert the block into the database. - { - let mut txn = test_fixture.env.begin_rw_txn().unwrap(); - - // Store the header. - txn.put( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_hash, - &bincode::serialize(&block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the body. - txn.put( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_header.body_hash, - &bincode::serialize(&block_body).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - - txn.commit().unwrap(); - }; +fn remove_block_missing_header() { + let test_fixture = LmdbTestFixture::new(); + let mut rng = TestRng::new(); + let block_hash = *Block::from(TestBlockBuilder::new().build(&mut rng)).hash(); assert!( - matches!(remove_block(test_fixture.tmp_dir.path(), block_hash).unwrap_err(), Error::MissingDeploy(actual_deploy_hash) if deploy_hash == actual_deploy_hash) + matches!(remove_block(test_fixture.tmp_dir.path(), block_hash).unwrap_err(), Error::MissingHeader(actual_block_hash) if block_hash == actual_block_hash) ); } #[test] -fn remove_block_invalid_header() { - let test_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), +fn remove_block_missing_body() { + const TRANSACTION_COUNT: usize = 4; + + let mut rng = TestRng::new(); + let mut test_fixture = LmdbTestFixture::new(); + + let transactions: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| Transaction::random(&mut rng)) + .collect(); + let mut blocks: Vec = vec![]; + let mut block_transactions_map: Vec> = vec![]; + blocks.push( + TestBlockBuilder::new() + .transactions([0, 1].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), + ); + block_transactions_map.push(vec![0, 1]); + blocks.push( + TestBlockBuilder::new() + .transactions([2, 3].iter().map(|i| &transactions[*i])) + .build(&mut rng) + .into(), ); + block_transactions_map.push(vec![2, 3]); - let (block_hash, _block_header) = mock_block_header(0); + let exec_results: Vec = (0..TRANSACTION_COUNT as u8) + .map(|_| ExecutionResult::random(&mut rng)) + .collect(); - // Insert the an invalid block header into the database. - { - let mut txn = test_fixture.env.begin_rw_txn().unwrap(); - - // Store the header. - txn.put( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_hash, - &[0u8, 1u8, 2u8], - WriteFlags::empty(), - ) - .unwrap(); + let mut rw_txn = test_fixture.block_store.checkout_rw().unwrap(); + for transaction in transactions.iter() { + let _ = rw_txn.write(transaction).unwrap(); + } - txn.commit().unwrap(); - }; + // Insert the 2 block headers and transactions into the database. + for (block_id, block) in blocks.iter().enumerate() { + let block_hash = rw_txn.write(&block.clone_header()).unwrap(); - assert!( - matches!(remove_block(test_fixture.tmp_dir.path(), block_hash).unwrap_err(), Error::HeaderParsing(actual_block_hash, _) if block_hash == actual_block_hash) - ); -} + let height = block.height(); + let era = block.era_id(); -#[test] -fn remove_block_invalid_body() { - let test_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), - ); + let block_info = BlockHashHeightAndEra::new(block_hash, height, era); - let (block_hash, block_header) = mock_block_header(0); + let block_exec_results = BlockExecutionResults { + block_info, + exec_results: block_transactions_map[block_id] + .iter() + .map(|id| (transactions[*id].hash(), exec_results[*id].clone())) + .collect(), + }; + rw_txn.write(&block_exec_results).unwrap(); + } + rw_txn.commit().unwrap(); - // Insert the block header along with an invalid body into the database. - { - let mut txn = test_fixture.env.begin_rw_txn().unwrap(); - - // Store the header. - txn.put( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_hash, - &bincode::serialize(&block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the body. - txn.put( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_header.body_hash, - &[0u8, 1u8, 2u8], - WriteFlags::empty(), - ) - .unwrap(); + assert!(remove_block(test_fixture.tmp_dir.path(), *blocks[0].hash()).is_ok()); + { + let txn = test_fixture.block_store.checkout_ro().unwrap(); + let removed_block_header: Option = txn.read(*blocks[0].hash()).unwrap(); + assert!(removed_block_header.is_none()); + let removed_block: Option = txn.read(*blocks[0].hash()).unwrap(); + assert!(removed_block.is_none()); + + let block_header: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(block_header.is_some()); + let block: Option = txn.read(*blocks[1].hash()).unwrap(); + assert!(block.is_none()); txn.commit().unwrap(); - }; - - assert!( - matches!(remove_block(test_fixture.tmp_dir.path(), block_hash).unwrap_err(), Error::BodyParsing(actual_block_hash, _) if block_hash == actual_block_hash) - ); + } } #[test] -fn remove_block_invalid_deploy_metadata() { - let test_fixture = LmdbTestFixture::new( - vec![ - BlockHeaderDatabase::db_name(), - BlockBodyDatabase::db_name(), - DeployMetadataDatabase::db_name(), - ], - Some(STORAGE_FILE_NAME), - ); +fn remove_block_missing_deploys() { + let mut test_fixture = LmdbTestFixture::new(); + let mut rng = TestRng::new(); - let (block_hash, block_header) = mock_block_header(0); - let deploy_hash = mock_deploy_hash(0); - let block_body = BlockBody::new(vec![deploy_hash]); + let transaction = Transaction::random(&mut rng); + let block: Block = TestBlockBuilder::new() + .transactions(std::iter::once(&transaction)) + .build(&mut rng) + .into(); // Insert the block into the database. { - let mut txn = test_fixture.env.begin_rw_txn().unwrap(); - - // Store the header. - txn.put( - *test_fixture - .db(Some(BlockHeaderDatabase::db_name())) - .unwrap(), - &block_hash, - &bincode::serialize(&block_header).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the body. - txn.put( - *test_fixture.db(Some(BlockBodyDatabase::db_name())).unwrap(), - &block_header.body_hash, - &bincode::serialize(&block_body).unwrap(), - WriteFlags::empty(), - ) - .unwrap(); - // Store the deploy metadata. - txn.put( - *test_fixture - .db(Some(DeployMetadataDatabase::db_name())) - .unwrap(), - &deploy_hash, - &[0u8, 1u8, 2u8], - WriteFlags::empty(), - ) - .unwrap(); - - txn.commit().unwrap(); + let mut rw_txn = test_fixture.block_store.checkout_rw().unwrap(); + // Store the block. + let _ = rw_txn.write(&block).unwrap(); + rw_txn.commit().unwrap(); }; - assert!( - matches!(remove_block(test_fixture.tmp_dir.path(), block_hash).unwrap_err(), Error::ExecutionResultsParsing(actual_block_hash, actual_deploy_hash, _) if block_hash == actual_block_hash && deploy_hash == actual_deploy_hash) - ); + assert!(remove_block(test_fixture.tmp_dir.path(), *block.hash()).is_ok()); + + let txn = test_fixture.block_store.checkout_ro().unwrap(); + let maybe_transaction: Option = txn.read(transaction.hash()).unwrap(); + assert!(maybe_transaction.is_none()); } diff --git a/src/subcommands/trie_compact.rs b/src/subcommands/trie_compact.rs index 18b8b65..a690485 100644 --- a/src/subcommands/trie_compact.rs +++ b/src/subcommands/trie_compact.rs @@ -1,7 +1,9 @@ mod compact; mod helpers; + #[cfg(test)] pub(crate) mod tests; + // All code in the `utils` mod was copied from `casper-node` because it isn't available in the // public interface. mod utils; @@ -10,15 +12,15 @@ use std::{io::Error as IoError, path::PathBuf}; use anyhow::Error as AnyError; use clap::{Arg, ArgMatches, Command}; -use lmdb::Error as LmdbError; use thiserror::Error as ThisError; -use casper_hashing::Digest; -use casper_node::storage::Error as StorageError; +use casper_storage::block_store::BlockStoreError; +use casper_storage::global_state::error::Error as GlobalStateError; +use casper_types::Digest; use compact::DestinationOptions; pub use helpers::copy_state_root; -pub use utils::{create_execution_engine, load_execution_engine}; +pub use utils::{create_data_access_layer, load_data_access_layer}; pub const COMMAND_NAME: &str = "compact-trie"; const APPEND: &str = "append"; @@ -44,9 +46,9 @@ pub enum Error { /// Path cannot be created/resolved. #[error("Path {0} cannot be created/resolved: {1}")] InvalidPath(PathBuf, IoError), - /// Error while operating on LMDB. - #[error("Error while operating on LMDB: {0}")] - LmdbOperation(LmdbError), + /// Error while operating on the global state. + #[error("Error while operating on the global state: {0}")] + GlobalState(GlobalStateError), /// A block of specific height is missing from the storage. #[error("Storage database is missing block {0}")] MissingBlock(u64), @@ -55,10 +57,10 @@ pub enum Error { OpenSourceTrie(AnyError), /// Error opening the block/deploys LMDB store. #[error("Error opening the block/deploy storage: {0}")] - OpenStorage(AnyError), + OpenStorage(BlockStoreError), /// Error while getting a block of specific height from storage. #[error("Storage error while trying to retrieve block {0}: {1}")] - Storage(u64, StorageError), + Storage(u64, BlockStoreError), } enum DisplayOrder { diff --git a/src/subcommands/trie_compact/compact.rs b/src/subcommands/trie_compact/compact.rs index f9248ea..8e808ff 100644 --- a/src/subcommands/trie_compact/compact.rs +++ b/src/subcommands/trie_compact/compact.rs @@ -4,14 +4,23 @@ use std::{ path::Path, }; +use casper_storage::{ + block_store::{ + lmdb::{IndexedLmdbBlockStore, LmdbBlockStore}, + types::{BlockHeight, Tip}, + BlockStoreProvider, DataReader, + }, + data_access_layer::FlushRequest, + global_state::state::StateProvider, +}; use log::info; -use casper_hashing::Digest; +use casper_types::{Block, Digest, ProtocolVersion}; use crate::common::db::TRIE_STORE_FILE_NAME; use super::{ - utils::{create_execution_engine, create_storage, load_execution_engine}, + utils::{create_data_access_layer, load_data_access_layer}, Error, }; @@ -141,27 +150,31 @@ pub fn trie_compact, P2: AsRef, P3: AsRef>( ) -> Result<(), Error> { validate_trie_paths(&source_trie_path, &destination_trie_path, dest_opt)?; - let (source_state, _env) = - load_execution_engine(source_trie_path, max_db_size, Digest::default(), true) + let source_state = + load_data_access_layer(source_trie_path, max_db_size, Digest::default(), true) .map_err(Error::OpenSourceTrie)?; - let (destination_state, _env) = - create_execution_engine(destination_trie_path, max_db_size, true) - .map_err(Error::CreateDestTrie)?; - - // Create a separate lmdb for block/deploy storage at chain_download_path. - let storage = create_storage(&storage_path).map_err(Error::OpenStorage)?; - - let mut block = match storage - .read_highest_block() - .map_err(|err| Error::Storage(0, err))? - { - Some(block) => block, - None => { - info!("No blocks found in storage, exiting."); - return Ok(()); - } - }; + let destination_state = create_data_access_layer(destination_trie_path, max_db_size, true) + .map_err(Error::CreateDestTrie)?; + + // Create a separate lmdb for block store at chain_download_path. + let block_store = + LmdbBlockStore::new(storage_path.as_ref(), max_db_size).map_err(Error::OpenStorage)?; + let indexed_block_store = + IndexedLmdbBlockStore::new(block_store, None, ProtocolVersion::from_parts(0, 0, 0)) + .map_err(Error::OpenStorage)?; + let ro_txn = indexed_block_store + .checkout_ro() + .map_err(Error::OpenStorage)?; + + let mut block = + match DataReader::::read(&ro_txn, Tip).map_err(|err| Error::Storage(0, err))? { + Some(block) => block, + None => { + info!("No blocks found in storage, exiting."); + return Ok(()); + } + }; let mut visited_roots = HashSet::new(); let mut block_height; @@ -173,15 +186,15 @@ pub fn trie_compact, P2: AsRef, P3: AsRef>( super::helpers::copy_state_root(state_root, &source_state, &destination_state) .map_err(|err| Error::CopyStateRoot(state_root, err))?; destination_state - .flush_environment() - .map_err(Error::LmdbOperation)?; + .flush(FlushRequest::new()) + .as_error() + .map_err(Error::GlobalState)?; visited_roots.insert(state_root); } if block_height == 0 { break; } - block = storage - .read_block_by_height(block_height - 1) + block = DataReader::::read(&ro_txn, block_height - 1) .map_err(|storage_err| Error::Storage(block_height - 1, storage_err))? .ok_or(Error::MissingBlock(block_height - 1))?; } diff --git a/src/subcommands/trie_compact/helpers.rs b/src/subcommands/trie_compact/helpers.rs index 9ad3cd1..7aa761f 100644 --- a/src/subcommands/trie_compact/helpers.rs +++ b/src/subcommands/trie_compact/helpers.rs @@ -1,22 +1,18 @@ use std::time::{Duration, Instant}; +use casper_storage::data_access_layer::DataAccessLayer; +use casper_storage::global_state::state::lmdb::LmdbGlobalState; +use casper_storage::global_state::transaction_source::{Readable, TransactionSource, Writable}; +use casper_storage::global_state::trie::Trie; +use casper_storage::global_state::trie_store::lmdb::LmdbTrieStore; use lmdb::{RwTransaction, Transaction}; use log::{info, warn}; -use casper_execution_engine::{ - core::engine_state::EngineState, - storage::{ - global_state::lmdb::LmdbGlobalState, - transaction_source::{Readable, TransactionSource, Writable}, - trie::{Pointer, Trie}, - trie_store::lmdb::LmdbTrieStore, - }, -}; -use casper_hashing::Digest; use casper_types::{ bytesrepr::{self, Bytes, ToBytes}, Key, StoredValue, }; +use casper_types::{Digest, Pointer}; fn memoized_find_missing_descendants( value_bytes: Bytes, @@ -73,8 +69,8 @@ fn find_missing_trie_keys( pub fn copy_state_root( state_root: Digest, - source: &EngineState, - destination: &EngineState, + source: &DataAccessLayer, + destination: &DataAccessLayer, ) -> Result<(), anyhow::Error> { let mut missing_trie_keys = vec![state_root]; let start_time = Instant::now(); @@ -95,17 +91,14 @@ pub fn copy_state_root( heartbeat_interval = Instant::now(); } - let source_store = source.get_state().trie_store(); - let destination_store = destination.get_state().trie_store(); + let source_store = source.state().trie_store(); + let destination_store = destination.state().trie_store(); let trie_key_bytes = next_trie_key .to_bytes() .map_err(|err| anyhow::anyhow!("couldn't serialize trie key: {:?}", err))?; - let read_txn = source.get_state().environment().create_read_txn()?; - let mut write_txn = destination - .get_state() - .environment() - .create_read_write_txn()?; + let read_txn = source.state().environment().create_read_txn()?; + let mut write_txn = destination.state().environment().create_read_write_txn()?; match read_txn.read(source_store.get_db(), &trie_key_bytes)? { Some(value_bytes) => { diff --git a/src/subcommands/trie_compact/tests.rs b/src/subcommands/trie_compact/tests.rs index c05eb7d..d624763 100644 --- a/src/subcommands/trie_compact/tests.rs +++ b/src/subcommands/trie_compact/tests.rs @@ -1,18 +1,15 @@ use std::fs::{self, File}; -use lmdb::DatabaseFlags; +use casper_storage::block_store::lmdb::LmdbBlockStore; +use casper_storage::global_state::store::StoreExt; +use casper_storage::global_state::transaction_source::TransactionSource; +use casper_storage::global_state::trie::{PointerBlock, Trie}; +use lmdb::Transaction; use once_cell::sync::Lazy; use tempfile::{tempdir, TempDir}; -use casper_execution_engine::storage::{ - store::StoreExt, - transaction_source::{lmdb::LmdbEnvironment, Transaction, TransactionSource}, - trie::{Pointer, PointerBlock, Trie}, - trie_store::lmdb::LmdbTrieStore, -}; -use casper_hashing::Digest; -use casper_node::storage::Storage; use casper_types::bytesrepr::{Bytes, ToBytes}; +use casper_types::{Digest, Pointer}; static DEFAULT_MAX_DB_SIZE: Lazy = Lazy::new(|| super::DEFAULT_MAX_DB_SIZE.parse().unwrap()); @@ -20,7 +17,7 @@ use crate::common::db::TRIE_STORE_FILE_NAME; use super::{ compact::{self, DestinationOptions}, - utils::{create_execution_engine, create_storage, load_execution_engine}, + utils::create_data_access_layer, Error, }; @@ -95,13 +92,19 @@ pub(crate) fn create_data() -> Vec> { fn create_test_trie_store() -> (TempDir, Vec>) { let tmp_dir = tempdir().unwrap(); - let env = LmdbEnvironment::new(tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, 512, true).unwrap(); - let store = LmdbTrieStore::new(&env, None, DatabaseFlags::empty()).unwrap(); + + let source = create_data_access_layer(tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, true).unwrap(); + let store = source.state().trie_store(); + let data = create_data(); { // Put the generated data into the source trie. - let mut txn = env.create_read_write_txn().unwrap(); + let mut txn = source + .state() + .environment() + .create_read_write_txn() + .unwrap(); let items = data.iter().map(Into::into); store.put_many(&mut txn, items).unwrap(); txn.commit().unwrap(); @@ -110,9 +113,9 @@ fn create_test_trie_store() -> (TempDir, Vec>) { (tmp_dir, data) } -fn create_empty_test_storage() -> (TempDir, Storage) { +fn create_empty_test_storage() -> (TempDir, LmdbBlockStore) { let tmp_dir = tempdir().unwrap(); - let storage = create_storage(tmp_dir.as_ref()).unwrap(); + let storage = LmdbBlockStore::new(tmp_dir.as_ref(), *DEFAULT_MAX_DB_SIZE).unwrap(); (tmp_dir, storage) } @@ -120,37 +123,36 @@ fn create_empty_test_storage() -> (TempDir, Storage) { fn copy_state_root_roundtrip() { let src_tmp_dir = tempdir().unwrap(); let dst_tmp_dir = tempdir().unwrap(); - let src_env = - LmdbEnvironment::new(src_tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, 512, true).unwrap(); - let src_store = LmdbTrieStore::new(&src_env, None, DatabaseFlags::empty()).unwrap(); // Construct mock data. let data = create_data(); + let source = create_data_access_layer(src_tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, true).unwrap(); + let src_store = source.state().trie_store(); { // Put the generated data into the source trie. - let mut txn = src_env.create_read_write_txn().unwrap(); + let mut txn = source + .state() + .environment() + .create_read_write_txn() + .unwrap(); let items = data.iter().map(Into::into); src_store.put_many(&mut txn, items).unwrap(); txn.commit().unwrap(); } - let (source_state, _env) = load_execution_engine( - src_tmp_dir.path(), - *DEFAULT_MAX_DB_SIZE, - Digest::default(), - true, - ) - .unwrap(); - - let (destination_state, dst_env) = - create_execution_engine(dst_tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, true).unwrap(); + let destination = + create_data_access_layer(dst_tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, true).unwrap(); // Copy from `node1`, the root of the created trie. All data should be copied. - super::helpers::copy_state_root(data[3].0, &source_state, &destination_state).unwrap(); + super::helpers::copy_state_root(data[3].0, &source, &destination).unwrap(); - let dst_store = LmdbTrieStore::new(&dst_env, None, DatabaseFlags::empty()).unwrap(); + let dst_store = destination.state().trie_store(); { - let txn = dst_env.create_read_write_txn().unwrap(); + let txn = destination + .state() + .environment() + .create_read_write_txn() + .unwrap(); let keys: Vec<_> = data.iter().map(|test_data| test_data.0).collect(); let entries: Vec>> = dst_store.get_many(&txn, keys.iter()).unwrap(); @@ -180,37 +182,36 @@ fn copy_state_root_roundtrip() { fn check_no_extra_tries() { let src_tmp_dir = tempdir().unwrap(); let dst_tmp_dir = tempdir().unwrap(); - let src_env = - LmdbEnvironment::new(src_tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, 512, true).unwrap(); - let src_store = LmdbTrieStore::new(&src_env, None, DatabaseFlags::empty()).unwrap(); // Construct mock data. let data = create_data(); + let source = create_data_access_layer(src_tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, true).unwrap(); + let src_store = source.state().trie_store(); { // Put the generated data into the source trie. - let mut txn = src_env.create_read_write_txn().unwrap(); + let mut txn = source + .state() + .environment() + .create_read_write_txn() + .unwrap(); let items = data.iter().map(Into::into); src_store.put_many(&mut txn, items).unwrap(); txn.commit().unwrap(); } - let (source_state, _env) = load_execution_engine( - src_tmp_dir.path(), - *DEFAULT_MAX_DB_SIZE, - Digest::default(), - true, - ) - .unwrap(); - - let (destination_state, dst_env) = - create_execution_engine(dst_tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, true).unwrap(); + let destination = + create_data_access_layer(dst_tmp_dir.path(), *DEFAULT_MAX_DB_SIZE, true).unwrap(); // Check with `node2`, which only has `leaf1` and `leaf2` as children in the constructed trie. - super::helpers::copy_state_root(data[4].0, &source_state, &destination_state).unwrap(); + super::helpers::copy_state_root(data[4].0, &source, &destination).unwrap(); - let dst_store = LmdbTrieStore::new(&dst_env, None, DatabaseFlags::empty()).unwrap(); + let dst_store = destination.state().trie_store(); { - let txn = dst_env.create_read_write_txn().unwrap(); + let txn = destination + .state() + .environment() + .create_read_write_txn() + .unwrap(); let data_keys: Vec<_> = data.iter().map(|test_data| test_data.0).collect(); // `TestData` objects `[leaf2, leaf3, node2]` which should be included in the search result. let mut included_data = vec![data[1].clone(), data[2].clone(), data[4].clone()]; diff --git a/src/subcommands/trie_compact/utils.rs b/src/subcommands/trie_compact/utils.rs index 9699405..552c7ac 100644 --- a/src/subcommands/trie_compact/utils.rs +++ b/src/subcommands/trie_compact/utils.rs @@ -1,21 +1,15 @@ -use std::{ - env, fs, - path::{Path, PathBuf}, - sync::Arc, -}; - -use log::info; +use std::{fs, path::Path, sync::Arc}; -use casper_execution_engine::{ - core::engine_state::{EngineConfig, EngineState}, - storage::{ - global_state::lmdb::LmdbGlobalState, transaction_source::lmdb::LmdbEnvironment, +use casper_storage::{ + data_access_layer::{BlockStore, DataAccessLayer}, + global_state::{ + state::lmdb::LmdbGlobalState, transaction_source::lmdb::LmdbEnvironment, trie_store::lmdb::LmdbTrieStore, }, }; -use casper_hashing::Digest; -use casper_node::{storage::Storage, StorageConfig, WithDir}; -use casper_types::ProtocolVersion; +use log::info; + +use casper_types::Digest; use lmdb::DatabaseFlags; use crate::common::db::TRIE_STORE_FILE_NAME; @@ -24,33 +18,38 @@ use crate::common::db::TRIE_STORE_FILE_NAME; /// /// The default value is chosen to be the same as the node itself. const DEFAULT_MAX_READERS: u32 = 512; +const DEFAULT_MAX_QUERY_DEPTH: u64 = 5; -/// Loads an existing execution engine. -pub fn load_execution_engine( - ee_lmdb_path: impl AsRef, +/// Loads an existing data access layer. +pub fn load_data_access_layer( + storage_path: impl AsRef, default_max_db_size: usize, state_root_hash: Digest, manual_sync_enabled: bool, -) -> Result<(Arc>, Arc), anyhow::Error> { - let lmdb_data_file = ee_lmdb_path.as_ref().join(TRIE_STORE_FILE_NAME); - if !ee_lmdb_path.as_ref().join(TRIE_STORE_FILE_NAME).exists() { +) -> Result, anyhow::Error> { + let lmdb_data_file = storage_path.as_ref().join(TRIE_STORE_FILE_NAME); + if !storage_path.as_ref().join(TRIE_STORE_FILE_NAME).exists() { return Err(anyhow::anyhow!( "lmdb data file not found at: {}", lmdb_data_file.display() )); } let lmdb_environment = - create_lmdb_environment(&ee_lmdb_path, default_max_db_size, manual_sync_enabled)?; + create_lmdb_environment(&storage_path, default_max_db_size, manual_sync_enabled)?; let lmdb_trie_store = Arc::new(LmdbTrieStore::open(&lmdb_environment, None)?); let global_state = LmdbGlobalState::new( Arc::clone(&lmdb_environment), lmdb_trie_store, state_root_hash, + DEFAULT_MAX_QUERY_DEPTH, ); - Ok(( - Arc::new(EngineState::new(global_state, EngineConfig::default())), - lmdb_environment, - )) + let block_store = BlockStore::new(); + + Ok(DataAccessLayer { + state: global_state, + block_store, + max_query_depth: DEFAULT_MAX_QUERY_DEPTH, + }) } /// Create an lmdb environment at a given path. @@ -68,22 +67,22 @@ fn create_lmdb_environment( Ok(lmdb_environment) } -/// Creates a new execution engine. -pub fn create_execution_engine( - ee_lmdb_path: impl AsRef, +/// Creates a new data access layer. +pub fn create_data_access_layer( + storage_path: impl AsRef, default_max_db_size: usize, manual_sync_enabled: bool, -) -> Result<(Arc>, Arc), anyhow::Error> { - if !ee_lmdb_path.as_ref().exists() { +) -> Result, anyhow::Error> { + if !storage_path.as_ref().exists() { info!( "creating new lmdb data dir {}", - ee_lmdb_path.as_ref().display() + storage_path.as_ref().display() ); - fs::create_dir_all(&ee_lmdb_path)?; + fs::create_dir_all(&storage_path)?; } - fs::create_dir_all(&ee_lmdb_path)?; + fs::create_dir_all(&storage_path)?; let lmdb_environment = - create_lmdb_environment(&ee_lmdb_path, default_max_db_size, manual_sync_enabled)?; + create_lmdb_environment(&storage_path, default_max_db_size, manual_sync_enabled)?; lmdb_environment.env().sync(true)?; let lmdb_trie_store = Arc::new(LmdbTrieStore::new( @@ -91,38 +90,17 @@ pub fn create_execution_engine( None, DatabaseFlags::empty(), )?); - let global_state = LmdbGlobalState::empty(Arc::clone(&lmdb_environment), lmdb_trie_store)?; - - Ok(( - Arc::new(EngineState::new(global_state, EngineConfig::default())), - lmdb_environment, - )) -} + let global_state = LmdbGlobalState::empty( + Arc::clone(&lmdb_environment), + lmdb_trie_store, + DEFAULT_MAX_QUERY_DEPTH, + )?; -pub fn create_storage(chain_download_path: impl AsRef) -> Result { - let chain_download_path = normalize_path(chain_download_path)?; - let mut storage_config = StorageConfig::default(); - storage_config.path = chain_download_path.clone(); - Ok(Storage::new( - &WithDir::new(chain_download_path, storage_config), - None, - ProtocolVersion::from_parts(0, 0, 0), - false, - // Works around needing to add "network name" to the path, instead a caller can - // reference the exact directory. - #[cfg(not(test))] - ".", - #[cfg(test)] - "casper", - )?) -} + let block_store: BlockStore = BlockStore::new(); -pub fn normalize_path>(path: P) -> Result { - let path = path.as_ref(); - let path = if path.is_absolute() { - path.into() - } else { - env::current_dir()?.join(path) - }; - Ok(fs::canonicalize(path)?) + Ok(DataAccessLayer { + state: global_state, + block_store, + max_query_depth: DEFAULT_MAX_QUERY_DEPTH, + }) } diff --git a/src/subcommands/unsparse.rs b/src/subcommands/unsparse.rs index 0e5bd71..5ab1169 100644 --- a/src/subcommands/unsparse.rs +++ b/src/subcommands/unsparse.rs @@ -83,26 +83,35 @@ fn unsparse(path: &Path) -> Result<(), Error> { #[cfg(test)] mod tests { + use casper_storage::block_store::{BlockStoreProvider, BlockStoreTransaction, DataWriter}; + use casper_types::{testing::TestRng, Block, TestBlockBuilder}; + use super::*; - use crate::test_utils::LmdbTestFixture; + use crate::{common::db::STORAGE_FILE_NAME, test_utils::LmdbTestFixture}; #[test] fn should_reduce_lmdb_file_size() { - let fixture = LmdbTestFixture::new(vec!["a"], None); - let db_path = fixture.file_path.as_path(); + let mut rng = TestRng::new(); + let mut fixture = LmdbTestFixture::new(); + let block: Block = TestBlockBuilder::new().build(&mut rng).into(); + let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); + let _ = rw_txn.write(&block).unwrap(); + rw_txn.commit().unwrap(); + + let db_path = fixture.tmp_dir.path().join(STORAGE_FILE_NAME); let db_size = || { - fs::metadata(db_path) + fs::metadata(db_path.as_path()) .unwrap_or_else(|error| { panic!("should get metadata for {}: {}", db_path.display(), error) }) .len() }; let size_before = db_size(); - unsparse(db_path).expect("unsparse should succeed"); + unsparse(db_path.as_path()).expect("unsparse should succeed"); let size_after = db_size(); assert!(size_after < size_before, "unsparse should reduce file size"); - assert!(unsparse(db_path).is_err(), "repeat unsparse should fail"); + assert!(unsparse(&db_path).is_err(), "repeat unsparse should fail"); assert_eq!(db_size(), size_after, "file size should be unchanged"); } } diff --git a/src/test_utils.rs b/src/test_utils.rs index cce07dc..a9dbc25 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -1,22 +1,16 @@ #![cfg(test)] -use std::{ - collections::{BTreeMap, HashMap}, - fs::OpenOptions, - path::PathBuf, -}; +use std::collections::BTreeMap; -use lmdb::{Database as LmdbDatabase, DatabaseFlags, Environment, EnvironmentFlags}; +use casper_storage::block_store::lmdb::LmdbBlockStore; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; -use tempfile::{NamedTempFile, TempDir}; +use tempfile::TempDir; -use casper_hashing::Digest; -use casper_node::types::{BlockHash, DeployHash, DeployMetadata}; use casper_types::{ - EraId, ExecutionEffect, ExecutionResult, ProtocolVersion, PublicKey, SecretKey, Timestamp, - U256, U512, + execution::ExecutionResult, EraId, ProtocolVersion, PublicKey, SecretKey, Timestamp, U256, U512, }; +use casper_types::{execution::ExecutionResultV2, testing::TestRng, BlockHash, Digest}; pub(crate) static KEYS: Lazy> = Lazy::new(|| { (0..10) @@ -32,75 +26,28 @@ pub(crate) static KEYS: Lazy> = Lazy::new(|| { }); pub struct LmdbTestFixture { - pub env: Environment, - pub dbs: HashMap<&'static str, LmdbDatabase>, pub tmp_dir: TempDir, - pub file_path: PathBuf, + pub block_store: LmdbBlockStore, } impl LmdbTestFixture { - pub fn new(names: Vec<&'static str>, file_name: Option<&str>) -> Self { + pub fn new() -> Self { let tmp_dir = tempfile::tempdir().unwrap(); - let file_path = if let Some(name) = file_name { - let path = tmp_dir.as_ref().join(name); - let _ = OpenOptions::new() - .create_new(true) - .write(true) - .open(&path) - .unwrap(); - path - } else { - let path = NamedTempFile::new_in(tmp_dir.as_ref()) - .unwrap() - .path() - .to_path_buf(); - let _ = OpenOptions::new() - .create_new(true) - .write(true) - .open(&path) - .unwrap(); - path - }; - let env = Environment::new() - .set_flags( - EnvironmentFlags::WRITE_MAP - | EnvironmentFlags::NO_SUB_DIR - | EnvironmentFlags::NO_TLS - | EnvironmentFlags::NO_READAHEAD, - ) - .set_max_readers(12) - .set_map_size(4096 * 1024) - .set_max_dbs(10) - .open(&file_path) - .expect("can't create environment"); - let mut dbs = HashMap::new(); - if names.is_empty() { - let db = env - .create_db(None, DatabaseFlags::empty()) - .expect("can't create database"); - dbs.insert("default", db); - } else { - for name in names { - let db = env - .create_db(Some(name), DatabaseFlags::empty()) - .expect("can't create database"); - dbs.insert(name, db); - } - } - LmdbTestFixture { - env, - dbs, - tmp_dir, - file_path, - } + Self::from_temp_dir(tmp_dir) + } + + pub fn destructure(self) -> (LmdbBlockStore, TempDir) { + (self.block_store, self.tmp_dir) } - pub fn db(&self, maybe_name: Option<&str>) -> Option<&LmdbDatabase> { - if let Some(name) = maybe_name { - self.dbs.get(name) - } else { - self.dbs.get("default") + pub fn from_temp_dir(tmp_dir: TempDir) -> Self { + let block_store = + LmdbBlockStore::new(tmp_dir.path(), 4096 * 1024).expect("can't create the block store"); + + LmdbTestFixture { + block_store, + tmp_dir, } } } @@ -139,47 +86,11 @@ impl Default for MockBlockHeader { } } -pub(crate) fn mock_deploy_hash(idx: u8) -> DeployHash { - DeployHash::new([idx; 32].into()) -} +pub(crate) fn success_execution_result(rng: &mut TestRng) -> ExecutionResult { + let mut exec_result = ExecutionResultV2::random(rng); + exec_result.error_message = None; -pub(crate) fn mock_block_header(idx: u8) -> (BlockHash, MockBlockHeader) { - let mut block_header = MockBlockHeader::default(); - let block_hash_digest: Digest = [idx; Digest::LENGTH].into(); - let block_hash: BlockHash = block_hash_digest.into(); - block_header.body_hash = [idx; Digest::LENGTH].into(); - (block_hash, block_header) -} - -pub(crate) fn mock_switch_block_header(idx: u8) -> (BlockHash, MockSwitchBlockHeader) { - let mut block_header = MockSwitchBlockHeader::default(); - let block_hash_digest: Digest = { - let mut bytes = [idx; Digest::LENGTH]; - bytes[Digest::LENGTH - 1] = 255; - bytes - } - .into(); - let block_hash: BlockHash = block_hash_digest.into(); - block_header.body_hash = [idx; Digest::LENGTH].into(); - (block_hash, block_header) -} - -pub(crate) fn mock_deploy_metadata(block_hashes: &[BlockHash]) -> DeployMetadata { - let mut deploy_metadata = DeployMetadata::default(); - for block_hash in block_hashes { - deploy_metadata - .execution_results - .insert(*block_hash, success_execution_result()); - } - deploy_metadata -} - -pub(crate) fn success_execution_result() -> ExecutionResult { - ExecutionResult::Success { - effect: ExecutionEffect::default(), - transfers: vec![], - cost: 100.into(), - } + exec_result.into() } #[derive(Clone, Debug, Default, PartialOrd, Ord, PartialEq, Eq, Hash, Serialize, Deserialize)] @@ -209,17 +120,6 @@ pub struct MockSwitchBlockHeader { pub protocol_version: ProtocolVersion, } -impl MockSwitchBlockHeader { - pub fn insert_key_weight(&mut self, key: PublicKey, weight: U512) { - let _ = self - .era_end - .as_mut() - .unwrap() - .next_era_validator_weights - .insert(key, weight); - } -} - impl Default for MockSwitchBlockHeader { fn default() -> Self { Self { From d83bd3818ee7db18316aa7b74d26a7550c181a60 Mon Sep 17 00:00:00 2001 From: Alexandru Sardan Date: Thu, 30 May 2024 16:32:07 +0000 Subject: [PATCH 2/2] tests: fix lint errors Signed-off-by: Alexandru Sardan --- src/subcommands/extract_slice/tests.rs | 2 +- src/subcommands/purge_signatures/tests.rs | 209 ++++++++-------------- src/subcommands/remove_block/tests.rs | 4 +- 3 files changed, 80 insertions(+), 135 deletions(-) diff --git a/src/subcommands/extract_slice/tests.rs b/src/subcommands/extract_slice/tests.rs index fea110a..79607d0 100644 --- a/src/subcommands/extract_slice/tests.rs +++ b/src/subcommands/extract_slice/tests.rs @@ -225,7 +225,7 @@ fn transfer_global_state_information() { .environment() .create_read_write_txn() .unwrap(); - let keys = vec![data[1].0, data[2].0, data[4].0]; + let keys = [data[1].0, data[2].0, data[4].0]; let entries: Vec>> = destination_store.get_many(&txn, keys.iter()).unwrap(); for entry in entries { diff --git a/src/subcommands/purge_signatures/tests.rs b/src/subcommands/purge_signatures/tests.rs index 069880e..371502b 100644 --- a/src/subcommands/purge_signatures/tests.rs +++ b/src/subcommands/purge_signatures/tests.rs @@ -35,58 +35,48 @@ fn indices_initialization() { let mut fixture = LmdbTestFixture::new(); // Create mock blocks and set an era and height for each one. - let mut blocks: Vec = vec![]; - blocks.push( + let blocks: Vec = vec![ TestBlockBuilder::new() .height(100) .era(10) .switch_block(false) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(200) .era(10) .switch_block(false) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(300) .era(20) .switch_block(false) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(400) .era(20) .switch_block(false) .build(&mut rng) .into(), - ); + ]; // Create mock switch blocks for each era and set an appropriate era and height for each one. - let mut switch_blocks: Vec = vec![]; - switch_blocks.push( + let switch_blocks: Vec = vec![ TestBlockBuilder::new() .height(80) .era(blocks[0].era_id() - 1) .switch_block(true) .build(&mut rng) .into(), - ); - switch_blocks.push( TestBlockBuilder::new() .height(280) .era(blocks[2].era_id() - 1) .switch_block(true) .build(&mut rng) .into(), - ); + ]; // Insert the blocks into the database. let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); @@ -137,16 +127,13 @@ fn indices_initialization_with_upgrade() { let mut rng = TestRng::new(); let mut fixture = LmdbTestFixture::new(); // Create mock blocks and set an era and height for each one. - let mut blocks: Vec = vec![]; - blocks.push( + let blocks: Vec = vec![ TestBlockBuilder::new() .height(80) .era(10) .switch_block(false) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(200) .era(11) @@ -154,8 +141,6 @@ fn indices_initialization_with_upgrade() { .protocol_version(ProtocolVersion::from_parts(1, 1, 0)) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(290) .era(12) @@ -163,8 +148,6 @@ fn indices_initialization_with_upgrade() { .protocol_version(ProtocolVersion::from_parts(2, 0, 0)) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(350) .era(13) @@ -172,27 +155,22 @@ fn indices_initialization_with_upgrade() { .protocol_version(ProtocolVersion::from_parts(2, 0, 0)) .build(&mut rng) .into(), - ); + ]; // Create mock switch blocks for each era and set an appropriate era and height for each one. - let mut switch_blocks: Vec = vec![]; - switch_blocks.push( + let switch_blocks: Vec = vec![ TestBlockBuilder::new() .height(60) .era(blocks[0].era_id() - 1) .switch_block(true) .build(&mut rng) .into(), - ); - switch_blocks.push( TestBlockBuilder::new() .height(180) .era(blocks[1].era_id() - 1) .switch_block(true) .build(&mut rng) .into(), - ); - switch_blocks.push( TestBlockBuilder::new() .height(250) .era(blocks[2].era_id() - 1) @@ -200,8 +178,6 @@ fn indices_initialization_with_upgrade() { .protocol_version(ProtocolVersion::from_parts(1, 1, 0)) .build(&mut rng) .into(), - ); - switch_blocks.push( TestBlockBuilder::new() .height(300) .era(blocks[3].era_id() - 1) @@ -209,7 +185,7 @@ fn indices_initialization_with_upgrade() { .protocol_version(ProtocolVersion::from_parts(2, 0, 0)) .build(&mut rng) .into(), - ); + ]; // Insert the blocks into the database. let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); @@ -287,22 +263,10 @@ fn era_weights() { let mut fixture = LmdbTestFixture::new(); // Create mock switch blocks for each era and set an appropriate era and height for each one. - let mut switch_blocks: Vec = vec![]; - - switch_blocks.push(new_switch_block_with_weights( - &mut rng, - 10, - 80, - &[(KEYS[0].clone(), 100.into())], - None, - )); - switch_blocks.push(new_switch_block_with_weights( - &mut rng, - 20, - 280, - &[(KEYS[1].clone(), 100.into())], - None, - )); + let switch_blocks: Vec = vec![ + new_switch_block_with_weights(&mut rng, 10, 80, &[(KEYS[0].clone(), 100.into())], None), + new_switch_block_with_weights(&mut rng, 20, 280, &[(KEYS[1].clone(), 100.into())], None), + ]; // Insert the blocks into the database. let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); @@ -368,26 +332,19 @@ fn era_weights_with_upgrade() { let mut fixture = LmdbTestFixture::new(); // Create mock switch blocks for each era and set an appropriate era and height for each one. - let mut switch_blocks: Vec = vec![]; - - // Set an era, height and next era weights for the first one. - switch_blocks.push(new_switch_block_with_weights( - &mut rng, - 10, - 80, - &[(KEYS[0].clone(), 100.into())], - None, - )); - - // Set an era, height and next era weights for the second one. - // Upgrade the version of the second switch block. - switch_blocks.push(new_switch_block_with_weights( - &mut rng, - 11, - 280, - &[(KEYS[1].clone(), 100.into())], - Some(ProtocolVersion::from_parts(1, 1, 0)), - )); + let switch_blocks: Vec = vec![ + // Set an era, height and next era weights for the first one. + new_switch_block_with_weights(&mut rng, 10, 80, &[(KEYS[0].clone(), 100.into())], None), + // Set an era, height and next era weights for the second one. + // Upgrade the version of the second switch block. + new_switch_block_with_weights( + &mut rng, + 11, + 280, + &[(KEYS[1].clone(), 100.into())], + Some(ProtocolVersion::from_parts(1, 1, 0)), + ), + ]; // Insert the blocks into the database. let mut rw_txn = fixture.block_store.checkout_rw().unwrap(); @@ -428,39 +385,32 @@ fn purge_signatures_should_work() { let mut fixture = LmdbTestFixture::new(); // Create mock blocks and set an era and height for each one. - let mut blocks: Vec = vec![]; - blocks.push( + let blocks: Vec = vec![ TestBlockBuilder::new() .height(100) .era(10) .switch_block(false) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(200) .era(10) .switch_block(false) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(300) .era(20) .switch_block(false) .build(&mut rng) .into(), - ); - blocks.push( TestBlockBuilder::new() .height(400) .era(20) .switch_block(false) .build(&mut rng) .into(), - ); + ]; // Create mock block signatures. let mut block_signatures: Vec = blocks @@ -470,34 +420,34 @@ fn purge_signatures_should_work() { *block.hash(), block.height(), block.era_id(), - ChainNameDigest::from_digest(Digest::random(&mut rng).into()), + ChainNameDigest::from_digest(Digest::random(&mut rng)), ) }) .collect(); // Create mock switch blocks for each era and set an appropriate era and height for each one. // Add weights for this switch block (500, 500). - let mut switch_blocks: Vec = vec![]; - switch_blocks.push(new_switch_block_with_weights( - &mut rng, - (blocks[0].era_id() - 1).value(), - 80, - &[(KEYS[0].clone(), 500.into()), (KEYS[1].clone(), 500.into())], - None, - )); - - // Add weights for this switch block (300, 300, 400). - switch_blocks.push(new_switch_block_with_weights( - &mut rng, - (blocks[2].era_id() - 1).value(), - 280, - &[ - (KEYS[0].clone(), 300.into()), - (KEYS[1].clone(), 300.into()), - (KEYS[2].clone(), 400.into()), - ], - None, - )); + let switch_blocks: Vec = vec![ + new_switch_block_with_weights( + &mut rng, + (blocks[0].era_id() - 1).value(), + 80, + &[(KEYS[0].clone(), 500.into()), (KEYS[1].clone(), 500.into())], + None, + ), + // Add weights for this switch block (300, 300, 400). + new_switch_block_with_weights( + &mut rng, + (blocks[2].era_id() - 1).value(), + 280, + &[ + (KEYS[0].clone(), 300.into()), + (KEYS[1].clone(), 300.into()), + (KEYS[2].clone(), 400.into()), + ], + None, + ), + ]; // Add keys and signatures for block 1. block_signatures[0].insert_signature(KEYS[0].clone(), Signature::System); @@ -610,25 +560,22 @@ fn purge_signatures_bad_input() { let mut fixture = LmdbTestFixture::new(); // Create mock blocks and set an era and height for each one. - let mut blocks: Vec = vec![]; - // Set an era and height for block 1. - blocks.push( + let blocks: Vec = vec![ + // Set an era and height for block 1. TestBlockBuilder::new() .height(100) .era(10) .switch_block(false) .build(&mut rng) .into(), - ); - // Set an era and height for block 2. - blocks.push( + // Set an era and height for block 2. TestBlockBuilder::new() .height(200) .era(20) .switch_block(false) .build(&mut rng) .into(), - ); + ]; // Create mock block signatures. let mut block_signatures: Vec = blocks @@ -638,29 +585,30 @@ fn purge_signatures_bad_input() { *block.hash(), block.height(), block.era_id(), - ChainNameDigest::from_digest(Digest::random(&mut rng).into()), + ChainNameDigest::from_digest(Digest::random(&mut rng)), ) }) .collect(); // Create mock switch blocks for each era and set an appropriate era and height for each one. - let mut switch_blocks: Vec = vec![]; - // Add weights for this switch block (700, 300). - switch_blocks.push(new_switch_block_with_weights( - &mut rng, - (blocks[0].era_id() - 1).value(), - 80, - &[(KEYS[0].clone(), 700.into()), (KEYS[1].clone(), 300.into())], - None, - )); - // Add weights for this switch block (400, 600). - switch_blocks.push(new_switch_block_with_weights( - &mut rng, - (blocks[1].era_id() - 1).value(), - 180, - &[(KEYS[0].clone(), 400.into()), (KEYS[1].clone(), 600.into())], - None, - )); + let switch_blocks: Vec = vec![ + // Add weights for this switch block (700, 300). + new_switch_block_with_weights( + &mut rng, + (blocks[0].era_id() - 1).value(), + 80, + &[(KEYS[0].clone(), 700.into()), (KEYS[1].clone(), 300.into())], + None, + ), + // Add weights for this switch block (400, 600). + new_switch_block_with_weights( + &mut rng, + (blocks[1].era_id() - 1).value(), + 180, + &[(KEYS[0].clone(), 400.into()), (KEYS[1].clone(), 600.into())], + None, + ), + ]; // Add keys and signatures for block 1. block_signatures[0].insert_signature(KEYS[0].clone(), Signature::System); @@ -717,25 +665,22 @@ fn purge_signatures_missing_from_db() { let mut fixture = LmdbTestFixture::new(); // Create mock blocks and set an era and height for each one. - let mut blocks: Vec = vec![]; - // Set an era and height for block 1. - blocks.push( + let blocks: Vec = vec![ + // Set an era and height for block 1. TestBlockBuilder::new() .height(100) .era(10) .switch_block(false) .build(&mut rng) .into(), - ); - // Set an era and height for block 2. - blocks.push( + // Set an era and height for block 2. TestBlockBuilder::new() .height(200) .era(10) .switch_block(false) .build(&mut rng) .into(), - ); + ]; // Create mock block signatures. let mut block_signatures: Vec = blocks @@ -745,7 +690,7 @@ fn purge_signatures_missing_from_db() { *block.hash(), block.height(), block.era_id(), - ChainNameDigest::from_digest(Digest::random(&mut rng).into()), + ChainNameDigest::from_digest(Digest::random(&mut rng)), ) }) .collect(); diff --git a/src/subcommands/remove_block/tests.rs b/src/subcommands/remove_block/tests.rs index 5ff53a5..a242fc7 100644 --- a/src/subcommands/remove_block/tests.rs +++ b/src/subcommands/remove_block/tests.rs @@ -125,8 +125,8 @@ fn remove_block_no_deploys() { let mut rw_txn = test_fixture.block_store.checkout_rw().unwrap(); - for i in 1..TRANSACTION_COUNT { - let _ = rw_txn.write(&transactions[i]).unwrap(); + for transaction in transactions.iter().take(TRANSACTION_COUNT).skip(1) { + let _ = rw_txn.write(transaction).unwrap(); } for (block_id, block) in blocks.iter().enumerate() {