diff --git a/.cargo/config.toml b/.cargo/config.toml
new file mode 100644
index 000000000..3fbd9f4d5
--- /dev/null
+++ b/.cargo/config.toml
@@ -0,0 +1,14 @@
+# Release profile: all targets get native CPU
+[profile.release.target.'cfg()']
+rustflags = ["-C", "target-cpu=native"]
+
+# Release profile: x86_64 gets native CPU + extra features (overrides the above)
+[profile.release.target.'cfg(target_arch = "x86_64")']
+rustflags = [
+ "-C", "target-cpu=native",
+ "-C", "target-feature=+bmi1,+bmi2,+avx2"
+]
+
+# Dist profile: x86_64 gets only extra features (no native CPU)
+[profile.dist.target.'cfg(target_arch = "x86_64")']
+rustflags = ["-C", "target-feature=+bmi1,+bmi2,+avx2"]
diff --git a/Cargo.lock b/Cargo.lock
index d39e5d009..51de1dc30 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -18,14 +18,16 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa"
[[package]]
-name = "aes"
-version = "0.8.4"
+name = "ahash"
+version = "0.8.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "b169f7a6d4742236a0a00c541b845991d0ac43e546831af1249753ab4c3aa3a0"
+checksum = "5a15f179cd60c4584b8a8c596927aadc462e27f2ca70c04e0071964a73ba7a75"
dependencies = [
"cfg-if",
- "cipher",
- "cpufeatures",
+ "getrandom 0.3.3",
+ "once_cell",
+ "version_check",
+ "zerocopy",
]
[[package]]
@@ -319,6 +321,12 @@ version = "0.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d965446196e3b7decd44aa7ee49e31d630118f90ef12f97900f262eb915c951d"
+[[package]]
+name = "better_io"
+version = "0.1.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "92fde17f91e7ba10b2a07f8dff29530b77144894bc6ae850fbc66e1276af0d28"
+
[[package]]
name = "bincode"
version = "2.0.1"
@@ -476,8 +484,7 @@ dependencies = [
"brk_bundler",
"brk_cli",
"brk_computer",
- "brk_core",
- "brk_exit",
+ "brk_error",
"brk_fetcher",
"brk_indexer",
"brk_interface",
@@ -486,6 +493,7 @@ dependencies = [
"brk_parser",
"brk_server",
"brk_store",
+ "brk_structs",
"brk_vecs",
]
@@ -506,8 +514,6 @@ version = "0.0.83"
dependencies = [
"bitcoincore-rpc",
"brk_computer",
- "brk_core",
- "brk_exit",
"brk_fetcher",
"brk_indexer",
"brk_logger",
@@ -529,14 +535,13 @@ version = "0.0.83"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
- "brk_core",
- "brk_exit",
+ "brk_error",
"brk_fetcher",
"brk_indexer",
"brk_logger",
"brk_parser",
+ "brk_structs",
"brk_vecs",
- "color-eyre",
"derive_deref",
"log",
"rayon",
@@ -546,42 +551,24 @@ dependencies = [
]
[[package]]
-name = "brk_core"
+name = "brk_error"
version = "0.0.83"
dependencies = [
- "bitcoin",
"bitcoincore-rpc",
- "byteview",
- "derive_deref",
+ "brk_vecs",
"fjall",
"jiff",
- "log",
- "rapidhash",
- "rlimit",
- "serde",
- "serde_bytes",
- "serde_json",
+ "minreq",
"zerocopy",
- "zerocopy-derive",
-]
-
-[[package]]
-name = "brk_exit"
-version = "0.0.83"
-dependencies = [
- "brk_logger",
- "ctrlc",
- "log",
- "parking_lot",
]
[[package]]
name = "brk_fetcher"
version = "0.0.83"
dependencies = [
- "brk_core",
+ "brk_error",
"brk_logger",
- "color-eyre",
+ "brk_structs",
"log",
"minreq",
"serde_json",
@@ -593,13 +580,12 @@ version = "0.0.83"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
- "brk_core",
- "brk_exit",
+ "brk_error",
"brk_logger",
"brk_parser",
"brk_store",
+ "brk_structs",
"brk_vecs",
- "color-eyre",
"fjall",
"log",
"rayon",
@@ -610,10 +596,10 @@ name = "brk_interface"
version = "0.0.83"
dependencies = [
"brk_computer",
- "brk_core",
+ "brk_error",
"brk_indexer",
+ "brk_structs",
"brk_vecs",
- "color-eyre",
"derive_deref",
"schemars 1.0.4",
"serde",
@@ -626,10 +612,10 @@ dependencies = [
name = "brk_logger"
version = "0.0.83"
dependencies = [
- "color-eyre",
"env_logger",
"jiff",
"log",
+ "owo-colors",
]
[[package]]
@@ -648,7 +634,7 @@ version = "0.0.83"
dependencies = [
"bitcoin",
"bitcoincore-rpc",
- "brk_core",
+ "brk_structs",
"crossbeam",
"derive_deref",
"rayon",
@@ -1019,8 +1005,7 @@ dependencies = [
"bitcoincore-rpc",
"brk_bundler",
"brk_computer",
- "brk_core",
- "brk_exit",
+ "brk_error",
"brk_fetcher",
"brk_indexer",
"brk_interface",
@@ -1030,10 +1015,11 @@ dependencies = [
"brk_vecs",
"clap",
"clap_derive",
- "color-eyre",
"jiff",
"log",
"minreq",
+ "owo-colors",
+ "quick_cache",
"serde",
"serde_json",
"tokio",
@@ -1046,7 +1032,8 @@ dependencies = [
name = "brk_store"
version = "0.0.83"
dependencies = [
- "brk_core",
+ "brk_error",
+ "brk_structs",
"byteview",
"fjall",
"log",
@@ -1064,24 +1051,50 @@ dependencies = [
"serde",
]
+[[package]]
+name = "brk_structs"
+version = "0.0.83"
+dependencies = [
+ "bitcoin",
+ "bitcoincore-rpc",
+ "brk_error",
+ "brk_vecs",
+ "byteview",
+ "derive_deref",
+ "fjall",
+ "jiff",
+ "rapidhash",
+ "serde",
+ "serde_bytes",
+ "serde_json",
+ "zerocopy",
+ "zerocopy-derive",
+]
+
[[package]]
name = "brk_vecs"
version = "0.0.83"
dependencies = [
- "brk_core",
- "brk_exit",
- "clap",
- "clap_derive",
+ "brk_vecs_macros",
+ "ctrlc",
"libc",
"log",
"memmap2",
"parking_lot",
+ "pco",
"rayon",
"serde",
"serde_json",
"zerocopy",
"zerocopy-derive",
- "zstd",
+]
+
+[[package]]
+name = "brk_vecs_macros"
+version = "0.0.83"
+dependencies = [
+ "quote",
+ "syn 2.0.104",
]
[[package]]
@@ -1138,15 +1151,6 @@ version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6236364b88b9b6d0bc181ba374cf1ab55ba3ef97a1cb6f8cddad48a273767fb5"
-[[package]]
-name = "bzip2"
-version = "0.6.0"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "bea8dcd42434048e4f7a304411d9273a411f647446c1234a65ce0554923f4cff"
-dependencies = [
- "libbz2-rs-sys",
-]
-
[[package]]
name = "castaway"
version = "0.2.4"
@@ -1158,9 +1162,9 @@ dependencies = [
[[package]]
name = "cc"
-version = "1.2.30"
+version = "1.2.31"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "deec109607ca693028562ed836a5f1c4b8bd77755c4e132fc5ce11b0b6211ae7"
+checksum = "c3a42d84bb6b69d3a8b3eaacf0d88f179e1929695e1ad012b6cf64d9caaa5fd2"
dependencies = [
"jobserver",
"libc",
@@ -1205,30 +1209,20 @@ dependencies = [
"windows-link",
]
-[[package]]
-name = "cipher"
-version = "0.4.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "773f3b9af64447d2ce9850330c473515014aa235e6a783b02db81ff39e4a3dad"
-dependencies = [
- "crypto-common",
- "inout",
-]
-
[[package]]
name = "clap"
-version = "4.5.41"
+version = "4.5.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "be92d32e80243a54711e5d7ce823c35c41c9d929dc4ab58e1276f625841aadf9"
+checksum = "ed87a9d530bb41a67537289bafcac159cb3ee28460e0a4571123d2a778a6a882"
dependencies = [
"clap_builder",
]
[[package]]
name = "clap_builder"
-version = "4.5.41"
+version = "4.5.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "707eab41e9622f9139419d573eca0900137718000c517d47da73045f54331c3d"
+checksum = "64f4f3f3c77c94aff3c7e9aac9a2ca1974a5adf392a8bb751e827d6d127ab966"
dependencies = [
"anstream",
"anstyle",
@@ -1434,6 +1428,12 @@ version = "0.8.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
+[[package]]
+name = "crunchy"
+version = "0.2.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5"
+
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -1547,12 +1547,6 @@ dependencies = [
"parking_lot_core",
]
-[[package]]
-name = "deflate64"
-version = "0.1.9"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "da692b8d1080ea3045efaab14434d40468c3d8657e42abddfffca87b428f4c1b"
-
[[package]]
name = "deranged"
version = "0.4.0"
@@ -1614,7 +1608,6 @@ checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
dependencies = [
"block-buffer",
"crypto-common",
- "subtle",
]
[[package]]
@@ -1623,6 +1616,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0d05e1c0dbad51b52c38bda7adceef61b9efc2baf04acfe8726a8c4630a6f57"
+[[package]]
+name = "dtype_dispatch"
+version = "0.1.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "d3a5ccdfd6c5e7e2fea9c5cf256f2a08216047fab19c621c3da64e9ae4a1462d"
+
[[package]]
name = "dunce"
version = "1.0.5"
@@ -1944,6 +1943,16 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "17e2ac29387b1aa07a1e448f7bb4f35b500787971e965b02842b900afa5c8f6f"
+[[package]]
+name = "half"
+version = "2.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "459196ed295495a68f7d7fe1d84f6c4b7ff0e21fe3017b2f283c6fac3ad803c9"
+dependencies = [
+ "cfg-if",
+ "crunchy",
+]
+
[[package]]
name = "hashbrown"
version = "0.12.3"
@@ -1994,15 +2003,6 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd"
-[[package]]
-name = "hmac"
-version = "0.12.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "6c49c37c09c17a53d937dfbb742eb3a961d65a994e6bcdcf37e7399d0cc8ab5e"
-dependencies = [
- "digest",
-]
-
[[package]]
name = "http"
version = "1.3.1"
@@ -2171,15 +2171,6 @@ dependencies = [
"libc",
]
-[[package]]
-name = "inout"
-version = "0.1.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "879f10e63c20629ecabbb64a8010319738c66a5cd0c29b02d63d272b03751d01"
-dependencies = [
- "generic-array",
-]
-
[[package]]
name = "interval-heap"
version = "0.0.5"
@@ -2329,43 +2320,17 @@ version = "1.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
-[[package]]
-name = "libbz2-rs-sys"
-version = "0.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "775bf80d5878ab7c2b1080b5351a48b2f737d9f6f8b383574eebcc22be0dfccb"
-
[[package]]
name = "libc"
version = "0.2.174"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1171693293099992e19cddea4e8b849964e9846f4acee11b3948bcc337be8776"
-[[package]]
-name = "liblzma"
-version = "0.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "0791ab7e08ccc8e0ce893f6906eb2703ed8739d8e89b57c0714e71bad09024c8"
-dependencies = [
- "liblzma-sys",
-]
-
-[[package]]
-name = "liblzma-sys"
-version = "0.4.4"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "01b9596486f6d60c3bbe644c0e1be1aa6ccc472ad630fe8927b456973d7cb736"
-dependencies = [
- "cc",
- "libc",
- "pkg-config",
-]
-
[[package]]
name = "libredox"
-version = "0.1.8"
+version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "360e552c93fa0e8152ab463bc4c4837fce76a225df11dfaeea66c313de5e61f7"
+checksum = "391290121bad3d37fbddad76d8f5d1c1c314cfc646d143d7e07a3086ddff0ce3"
dependencies = [
"bitflags 2.9.1",
"libc",
@@ -2673,9 +2638,9 @@ dependencies = [
[[package]]
name = "oxc-browserslist"
-version = "2.0.11"
+version = "2.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "509ae58826553dbd720886b6a77e7bb2a953d28a52728a74cc1fe296d66fa9a2"
+checksum = "e05d19022f54d3e0b8b1679c80f02d140e95e4308385eb247ba3168c299c81bb"
dependencies = [
"bincode",
"nom",
@@ -2688,9 +2653,9 @@ dependencies = [
[[package]]
name = "oxc-miette"
-version = "2.3.2"
+version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e8f905f1293ce969f8b6f08f2f4e8a0fbfd26dec42a30ea98b436d2faf01f50f"
+checksum = "31cfb121c9d3e0f9082856927f5cff9594279c91b544f4436e4bc971563caa60"
dependencies = [
"cfg-if",
"owo-colors",
@@ -2702,9 +2667,9 @@ dependencies = [
[[package]]
name = "oxc-miette-derive"
-version = "2.3.2"
+version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7cd092b10278cef8cc76dad34116988c2f0ca34bf9082de5513bacd95f4553d0"
+checksum = "a6eabb57f935b454fbe0552ea0abaaf9eb0019b5fa05a7bbe7efd5bd8c765085"
dependencies = [
"proc-macro2",
"quote",
@@ -3198,13 +3163,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "df94ce210e5bc13cb6651479fa48d14f601d9858cfe0467f43ae157023b938d3"
[[package]]
-name = "pbkdf2"
-version = "0.12.2"
+name = "pco"
+version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f8ed6a7761f76e3b9f92dfb0a60a6a6477c61024b775147ff0973a02653abaf2"
+checksum = "ab068b64f2c6f074cbdcafc80ebd83a27da92a3848deba2fabc21eba6691fc65"
dependencies = [
- "digest",
- "hmac",
+ "better_io",
+ "dtype_dispatch",
+ "half",
+ "rand_xoshiro",
]
[[package]]
@@ -3347,12 +3314,6 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
-[[package]]
-name = "ppmd-rust"
-version = "1.2.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "c834641d8ad1b348c9ee86dec3b9840d805acd5f24daa5f90c788951a52ff59b"
-
[[package]]
name = "ppv-lite86"
version = "0.2.21"
@@ -3399,8 +3360,10 @@ version = "0.6.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8565e62e02af316570d4b492f17af1481d6c07cea60f4e7edd71700da5052ba9"
dependencies = [
+ "ahash",
"equivalent",
"hashbrown 0.15.4",
+ "parking_lot",
]
[[package]]
@@ -3487,6 +3450,15 @@ dependencies = [
"getrandom 0.3.3",
]
+[[package]]
+name = "rand_xoshiro"
+version = "0.6.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "6f97cdb2a36ed4183de61b2f824cc45c9f1037f28afe0a322e9fff4c108b5aaa"
+dependencies = [
+ "rand_core 0.6.4",
+]
+
[[package]]
name = "rapidhash"
version = "2.0.2"
@@ -3610,15 +3582,6 @@ dependencies = [
"windows-sys 0.52.0",
]
-[[package]]
-name = "rlimit"
-version = "0.10.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "7043b63bd0cd1aaa628e476b80e6d4023a3b50eb32789f2728908107bd0c793a"
-dependencies = [
- "libc",
-]
-
[[package]]
name = "rolldown-ariadne"
version = "0.5.2"
@@ -3852,9 +3815,9 @@ dependencies = [
[[package]]
name = "serde_json"
-version = "1.0.141"
+version = "1.0.142"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "30b9eff21ebe718216c6ec64e1d9ac57087aad11efc64e32002bce4a0d4c03d3"
+checksum = "030fedb782600dcbd6f02d479bf0d817ac3bb40d644745b769d6a96bc3afc5a7"
dependencies = [
"indexmap 2.10.0",
"itoa",
@@ -4035,12 +3998,6 @@ version = "0.11.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f"
-[[package]]
-name = "subtle"
-version = "2.6.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292"
-
[[package]]
name = "sugar_path"
version = "1.2.0"
@@ -4223,9 +4180,9 @@ dependencies = [
[[package]]
name = "tokio"
-version = "1.47.0"
+version = "1.47.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "43864ed400b6043a4757a25c7a64a8efde741aed79a056a2fb348a406701bb35"
+checksum = "89e49afdadebb872d3145a5638b59eb0691ea23e46ca484037cfab3b76b95038"
dependencies = [
"backtrace",
"bytes",
@@ -4276,9 +4233,9 @@ dependencies = [
[[package]]
name = "toml"
-version = "0.9.3"
+version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e06723639aaded957e5a80be250c1f82f274b9d23ebb4d94163668470623461c"
+checksum = "41ae868b5a0f67631c14589f7e250c1ea2c574ee5ba21c6c8dd4b1485705a5a1"
dependencies = [
"indexmap 2.10.0",
"serde",
@@ -5011,51 +4968,18 @@ dependencies = [
"syn 2.0.104",
]
-[[package]]
-name = "zeroize"
-version = "1.8.1"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ced3678a2879b30306d323f4542626697a464a97c0a07c9aebf7ebca65cd4dde"
-dependencies = [
- "zeroize_derive",
-]
-
-[[package]]
-name = "zeroize_derive"
-version = "1.4.2"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69"
-dependencies = [
- "proc-macro2",
- "quote",
- "syn 2.0.104",
-]
-
[[package]]
name = "zip"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9aed4ac33e8eb078c89e6cbb1d5c4c7703ec6d299fc3e7c3695af8f8b423468b"
dependencies = [
- "aes",
"arbitrary",
- "bzip2",
- "constant_time_eq",
"crc32fast",
- "deflate64",
"flate2",
- "getrandom 0.3.3",
- "hmac",
"indexmap 2.10.0",
- "liblzma",
"memchr",
- "pbkdf2",
- "ppmd-rust",
- "sha1",
- "time",
- "zeroize",
"zopfli",
- "zstd",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index f2a0d330a..ea0196499 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -28,8 +28,8 @@ bitcoincore-rpc = "0.19.0"
brk_bundler = { version = "0.0.83", path = "crates/brk_bundler" }
brk_cli = { version = "0.0.83", path = "crates/brk_cli" }
brk_computer = { version = "0.0.83", path = "crates/brk_computer" }
-brk_core = { version = "0.0.83", path = "crates/brk_core" }
-brk_exit = { version = "0.0.83", path = "crates/brk_exit" }
+brk_structs = { version = "0.0.83", path = "crates/brk_structs" }
+brk_error = { version = "0.0.83", path = "crates/brk_error" }
brk_fetcher = { version = "0.0.83", path = "crates/brk_fetcher" }
brk_indexer = { version = "0.0.83", path = "crates/brk_indexer" }
brk_interface = { version = "0.0.83", path = "crates/brk_interface" }
@@ -39,23 +39,24 @@ brk_parser = { version = "0.0.83", path = "crates/brk_parser" }
brk_server = { version = "0.0.83", path = "crates/brk_server" }
brk_store = { version = "0.0.83", path = "crates/brk_store" }
brk_vecs = { version = "0.0.83", path = "crates/brk_vecs" }
+brk_vecs_macros = { version = "0.0.83", path = "crates/brk_vecs_macros" }
byteview = "=0.6.1"
-clap = { version = "4.5.41", features = ["string"] }
+clap = { version = "4.5.42", features = ["string"] }
clap_derive = "4.5.41"
-color-eyre = "0.6.5"
derive_deref = "1.1.1"
fjall = "2.11.2"
jiff = "0.2.15"
-log = { version = "0.4.27" }
+log = "0.4.27"
minreq = { version = "2.14.0", features = ["https", "serde_json"] }
+owo-colors = "4.2.2"
parking_lot = "0.12.4"
rayon = "1.10.0"
-serde = { version = "1.0.219" }
+serde = "1.0.219"
serde_bytes = "0.11.17"
serde_derive = "1.0.219"
-serde_json = { version = "1.0.141", features = ["float_roundtrip"] }
-tokio = { version = "1.47.0", features = ["rt-multi-thread"] }
-zerocopy = { version = "0.8.26" }
+serde_json = { version = "1.0.142", features = ["float_roundtrip"] }
+tokio = { version = "1.47.1", features = ["rt-multi-thread"] }
+zerocopy = "0.8.26"
zerocopy-derive = "0.8.26"
[workspace.metadata.release]
diff --git a/README.md b/README.md
index d7a82eac5..47cc318c9 100644
--- a/README.md
+++ b/README.md
@@ -23,12 +23,6 @@
-
-
-
-
-
-
The Bitcoin Research Kit is a high-performance toolchain designed to parse, index, compute, serve and visualize data from a Bitcoin node, enabling users to gain deeper insights into the Bitcoin network.
@@ -63,8 +57,7 @@ In contrast, existing alternatives tend to be either [very costly](https://studi
- [`brk`](https://crates.io/crates/brk): Wrapper around all other `brk-*` crates
- [`brk_cli`](https://crates.io/crates/brk_cli): A command line interface to run a Bitcoin Research Kit instance
- [`brk_computer`](https://crates.io/crates/brk_computer): A Bitcoin dataset computer, built on top of brk_indexer
-- [`brk_core`](https://crates.io/crates/brk_core): The Core (Structs and Errors) of the Bitcoin Research Kit
-- [`brk_exit`](https://crates.io/crates/brk_exit): An exit blocker built on top of ctrlc
+- [`brk_structs`](https://crates.io/crates/brk_structs): The Core (Structs and Errors) of the Bitcoin Research Kit
- [`brk_fetcher`](https://crates.io/crates/brk_fetcher): A Bitcoin price fetcher
- [`brk_indexer`](https://crates.io/crates/brk_indexer): A Bitcoin Core indexer built on top of brk_parser
- [`brk_logger`](https://crates.io/crates/brk_logger): A clean logger used in the Bitcoin Research Kit
diff --git a/crates/brk/Cargo.toml b/crates/brk/Cargo.toml
index 3c1f56510..b37651c85 100644
--- a/crates/brk/Cargo.toml
+++ b/crates/brk/Cargo.toml
@@ -11,47 +11,47 @@ version.workspace = true
[features]
full = [
"bundler",
- "core",
"computer",
- "exit",
+ "error",
"fetcher",
"indexer",
+ "interface",
"logger",
"mcp",
"parser",
- "interface",
"server",
"store",
+ "structs",
"vecs",
]
bundler = ["brk_bundler"]
-core = ["brk_core"]
computer = ["brk_computer"]
-exit = ["brk_exit"]
+error = ["brk_error"]
fetcher = ["brk_fetcher"]
indexer = ["brk_indexer"]
+interface = ["brk_interface"]
logger = ["brk_logger"]
mcp = ["brk_mcp"]
parser = ["brk_parser"]
-interface = ["brk_interface"]
server = ["brk_server"]
store = ["brk_store"]
+structs = ["brk_structs"]
vecs = ["brk_vecs"]
[dependencies]
brk_bundler = { workspace = true, optional = true }
brk_cli = { workspace = true }
-brk_core = { workspace = true, optional = true }
brk_computer = { workspace = true, optional = true }
-brk_exit = { workspace = true, optional = true }
+brk_error = { workspace = true, optional = true }
brk_fetcher = { workspace = true, optional = true }
brk_indexer = { workspace = true, optional = true }
+brk_interface = { workspace = true, optional = true }
brk_logger = { workspace = true, optional = true }
brk_mcp = { workspace = true, optional = true }
brk_parser = { workspace = true, optional = true }
-brk_interface = { workspace = true, optional = true }
brk_server = { workspace = true, optional = true }
brk_store = { workspace = true, optional = true }
+brk_structs = { workspace = true, optional = true }
brk_vecs = { workspace = true, optional = true }
[package.metadata.docs.rs]
diff --git a/crates/brk/src/lib.rs b/crates/brk/src/lib.rs
index 1b7f87a0a..b117391f8 100644
--- a/crates/brk/src/lib.rs
+++ b/crates/brk/src/lib.rs
@@ -7,17 +7,17 @@ pub use brk_bundler as bundler;
#[doc(inline)]
pub use brk_cli as cli;
-#[cfg(feature = "core")]
+#[cfg(feature = "structs")]
#[doc(inline)]
-pub use brk_core as core;
+pub use brk_structs as structs;
#[cfg(feature = "computer")]
#[doc(inline)]
pub use brk_computer as computer;
-#[cfg(feature = "exit")]
+#[cfg(feature = "error")]
#[doc(inline)]
-pub use brk_exit as exit;
+pub use brk_error as error;
#[cfg(feature = "fetcher")]
#[doc(inline)]
diff --git a/crates/brk_cli/Cargo.toml b/crates/brk_cli/Cargo.toml
index 3f7a68ec1..da73ca3bb 100644
--- a/crates/brk_cli/Cargo.toml
+++ b/crates/brk_cli/Cargo.toml
@@ -10,8 +10,6 @@ repository.workspace = true
[dependencies]
bitcoincore-rpc = { workspace = true }
brk_computer = { workspace = true }
-brk_core = { workspace = true }
-brk_exit = { workspace = true }
brk_fetcher = { workspace = true }
brk_indexer = { workspace = true }
brk_logger = { workspace = true }
@@ -20,11 +18,11 @@ brk_server = { workspace = true }
brk_vecs = { workspace = true }
clap = { workspace = true }
clap_derive = { workspace = true }
-color-eyre = { workspace = true }
+color-eyre = "0.6.5"
log = { workspace = true }
serde = { workspace = true }
tokio = { workspace = true }
-toml = "0.9.3"
+toml = "0.9.4"
[[bin]]
name = "brk"
diff --git a/crates/brk_cli/README.md b/crates/brk_cli/README.md
index 22752a617..023057bb4 100644
--- a/crates/brk_cli/README.md
+++ b/crates/brk_cli/README.md
@@ -23,12 +23,6 @@
-
-
-
-
-
-
A command line interface to run a Bitcoin Research Kit instance.
diff --git a/crates/brk_cli/src/config.rs b/crates/brk_cli/src/config.rs
index a89d3ac53..e74571963 100644
--- a/crates/brk_cli/src/config.rs
+++ b/crates/brk_cli/src/config.rs
@@ -4,14 +4,16 @@ use std::{
};
use bitcoincore_rpc::{self, Auth, Client};
-use brk_core::{default_bitcoin_path, default_brk_path, default_on_error, dot_brk_path};
use brk_fetcher::Fetcher;
use brk_server::Website;
-use brk_vecs::{Computation, Format};
use clap::Parser;
use clap_derive::Parser;
use color_eyre::eyre::eyre;
-use serde::{Deserialize, Serialize};
+use serde::{Deserialize, Deserializer, Serialize};
+
+use crate::{default_bitcoin_path, default_brk_path, dot_brk_path};
+
+const DOWNLOADS: &str = "downloads";
#[derive(Parser, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Deserialize, Serialize)]
#[command(version, about)]
@@ -31,16 +33,6 @@ pub struct Config {
#[arg(long, value_name = "PATH")]
brkdir: Option,
- /// Computation of computed datasets, `lazy` computes data whenever requested without saving it, `eager` computes the data once and saves it to disk, default: `lazy`, saved
- #[serde(default, deserialize_with = "default_on_error")]
- #[arg(short, long)]
- computation: Option,
-
- /// Format of computed datasets, `compressed` to save disk space (experimental), `raw` to prioritize speed, default: `raw`, saved
- #[serde(default, deserialize_with = "default_on_error")]
- #[arg(short, long)]
- format: Option,
-
/// Activate fetching prices from exchanges APIs and the computation of all related datasets, default: true, saved
#[serde(default, deserialize_with = "default_on_error")]
#[arg(short = 'F', long, value_name = "BOOL")]
@@ -122,18 +114,10 @@ impl Config {
config_saved.brkdir = Some(brkdir);
}
- if let Some(computation) = config_args.computation.take() {
- config_saved.computation = Some(computation);
- }
-
if let Some(fetch) = config_args.fetch.take() {
config_saved.fetch = Some(fetch);
}
- if let Some(format) = config_args.format.take() {
- config_saved.format = Some(format);
- }
-
if let Some(website) = config_args.website.take() {
config_saved.website = Some(website);
}
@@ -291,6 +275,10 @@ impl Config {
self.brkdir().join("hars")
}
+ pub fn downloads_dir(&self) -> PathBuf {
+ dot_brk_path().join(DOWNLOADS)
+ }
+
fn path_cookiefile(&self) -> PathBuf {
self.rpccookiefile.as_ref().map_or_else(
|| self.bitcoindir().join(".cookie"),
@@ -329,14 +317,6 @@ impl Config {
.then(|| Fetcher::import(Some(self.harsdir().as_path())).unwrap())
}
- pub fn computation(&self) -> Computation {
- self.computation.unwrap_or_default()
- }
-
- pub fn format(&self) -> Format {
- self.format.unwrap_or_default()
- }
-
pub fn check_collisions(&self) -> bool {
self.check_collisions.is_some_and(|b| b)
}
@@ -349,3 +329,14 @@ impl Config {
self.watch.is_some_and(|b| b)
}
}
+
+fn default_on_error<'de, D, T>(deserializer: D) -> Result
+where
+ D: Deserializer<'de>,
+ T: Deserialize<'de> + Default,
+{
+ match T::deserialize(deserializer) {
+ Ok(v) => Ok(v),
+ Err(_) => Ok(T::default()),
+ }
+}
diff --git a/crates/brk_cli/src/lib.rs b/crates/brk_cli/src/lib.rs
index 2e143465d..b96bc45af 100644
--- a/crates/brk_cli/src/lib.rs
+++ b/crates/brk_cli/src/lib.rs
@@ -2,11 +2,11 @@
use std::{fs, thread};
-use brk_core::{dot_brk_log_path, dot_brk_path};
-
mod config;
+mod paths;
mod run;
+pub use paths::*;
use run::*;
pub fn main() -> color_eyre::Result<()> {
diff --git a/crates/brk_core/src/utils/paths.rs b/crates/brk_cli/src/paths.rs
similarity index 100%
rename from crates/brk_core/src/utils/paths.rs
rename to crates/brk_cli/src/paths.rs
diff --git a/crates/brk_cli/src/run.rs b/crates/brk_cli/src/run.rs
index 41328e299..aa5a0c22b 100644
--- a/crates/brk_cli/src/run.rs
+++ b/crates/brk_cli/src/run.rs
@@ -2,9 +2,9 @@ use std::{thread::sleep, time::Duration};
use bitcoincore_rpc::{self, RpcApi};
use brk_computer::Computer;
-use brk_exit::Exit;
use brk_indexer::Indexer;
use brk_server::Server;
+use brk_vecs::Exit;
use log::info;
use crate::config::Config;
@@ -13,10 +13,11 @@ pub fn run() -> color_eyre::Result<()> {
let config = Config::import()?;
let rpc = config.rpc()?;
- let exit = Exit::new();
- let parser = brk_parser::Parser::new(config.blocksdir(), config.brkdir(), rpc);
- let format = config.format();
+ let exit = Exit::new();
+ exit.set_ctrlc_handler();
+
+ let parser = brk_parser::Parser::new(config.blocksdir(), config.brkdir(), rpc);
let mut indexer = Indexer::forced_import(&config.brkdir())?;
@@ -36,13 +37,7 @@ pub fn run() -> color_eyre::Result<()> {
Ok(())
};
- let mut computer = Computer::forced_import(
- &config.brkdir(),
- &indexer,
- config.computation(),
- config.fetcher(),
- format,
- )?;
+ let mut computer = Computer::forced_import(&config.brkdir(), &indexer, config.fetcher())?;
tokio::runtime::Builder::new_multi_thread()
.enable_all()
@@ -51,7 +46,12 @@ pub fn run() -> color_eyre::Result<()> {
let served_indexer = indexer.clone();
let served_computer = computer.clone();
- let server = Server::new(served_indexer, served_computer, config.website())?;
+ let server = Server::new(
+ served_indexer,
+ served_computer,
+ config.website(),
+ &config.downloads_dir(),
+ )?;
let watch = config.watch();
let mcp = config.mcp();
@@ -72,7 +72,7 @@ pub fn run() -> color_eyre::Result<()> {
let starting_indexes =
indexer.index(&parser, rpc, &exit, config.check_collisions())?;
- computer.compute(&mut indexer, starting_indexes, &exit)?;
+ computer.compute(&indexer, starting_indexes, &exit)?;
if let Some(delay) = config.delay() {
sleep(Duration::from_secs(delay))
diff --git a/crates/brk_computer/Cargo.toml b/crates/brk_computer/Cargo.toml
index 0eabffa43..355060750 100644
--- a/crates/brk_computer/Cargo.toml
+++ b/crates/brk_computer/Cargo.toml
@@ -10,14 +10,13 @@ repository.workspace = true
[dependencies]
bitcoin = { workspace = true }
bitcoincore-rpc = { workspace = true }
-brk_core = { workspace = true }
-brk_exit = { workspace = true }
+brk_structs = { workspace = true }
+brk_error = { workspace = true }
brk_fetcher = { workspace = true }
brk_indexer = { workspace = true }
brk_logger = { workspace = true }
brk_parser = { workspace = true }
brk_vecs = { workspace = true }
-color-eyre = { workspace = true }
derive_deref = { workspace = true }
log = { workspace = true }
rayon = { workspace = true }
diff --git a/crates/brk_computer/README.md b/crates/brk_computer/README.md
index 55d7ad3ee..bba172db6 100644
--- a/crates/brk_computer/README.md
+++ b/crates/brk_computer/README.md
@@ -23,12 +23,6 @@
-
-
-
-
-
-
A dataset computer, built on top of `brk_indexer` and `brk_fetcher`. It computes any dataset you can think of and if it doesn't feel free to create an issue.
diff --git a/crates/brk_computer/examples/main.rs b/crates/brk_computer/examples/main.rs
index f0140d70a..3dc8b3d32 100644
--- a/crates/brk_computer/examples/main.rs
+++ b/crates/brk_computer/examples/main.rs
@@ -1,18 +1,16 @@
use std::{path::Path, thread};
use brk_computer::Computer;
-use brk_exit::Exit;
+use brk_error::Result;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
use brk_parser::Parser;
-use brk_vecs::{Computation, Format};
-
-pub fn main() -> color_eyre::Result<()> {
- color_eyre::install()?;
+use brk_vecs::Exit;
+pub fn main() -> Result<()> {
brk_logger::init(Some(Path::new(".log")));
- // let bitcoin_dir = brk_core::default_bitcoin_path();
+ // let bitcoin_dir = brk_structs::default_bitcoin_path();
let bitcoin_dir = Path::new("/Volumes/WD_BLACK/bitcoin");
let rpc = Box::leak(Box::new(bitcoincore_rpc::Client::new(
@@ -20,38 +18,27 @@ pub fn main() -> color_eyre::Result<()> {
bitcoincore_rpc::Auth::CookieFile(bitcoin_dir.join(".cookie")),
)?));
let exit = Exit::new();
+ exit.set_ctrlc_handler();
// Can't increase main thread's stack programatically, thus we need to use another thread
thread::Builder::new()
.stack_size(256 * 1024 * 1024)
- .spawn(move || -> color_eyre::Result<()> {
- let parser = Parser::new(
- bitcoin_dir.join("blocks"),
- brk_core::default_brk_path(),
- rpc,
- );
+ .spawn(move || -> Result<()> {
+ let parser = Parser::new(bitcoin_dir.join("blocks"), Path::new("").to_path_buf(), rpc);
let _outputs_dir = Path::new("/Volumes/WD_BLACK/brk").join("outputs");
let outputs_dir = _outputs_dir.as_path();
// let outputs_dir = Path::new("../../_outputs");
- let format = Format::Raw;
-
let mut indexer = Indexer::forced_import(outputs_dir)?;
let fetcher = Fetcher::import(None)?;
- let mut computer = Computer::forced_import(
- outputs_dir,
- &indexer,
- Computation::Lazy,
- Some(fetcher),
- format,
- )?;
+ let mut computer = Computer::forced_import(outputs_dir, &indexer, Some(fetcher))?;
let starting_indexes = indexer.index(&parser, rpc, &exit, true)?;
- computer.compute(&mut indexer, starting_indexes, &exit)?;
+ computer.compute(&indexer, starting_indexes, &exit)?;
Ok(())
})?
diff --git a/crates/brk_computer/src/all.rs b/crates/brk_computer/src/all.rs
index d6e003cd7..1a08b7745 100644
--- a/crates/brk_computer/src/all.rs
+++ b/crates/brk_computer/src/all.rs
@@ -1,13 +1,13 @@
use std::{path::Path, sync::Arc};
-use brk_core::Version;
-use brk_exit::Exit;
+use brk_error::Result;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
-use brk_vecs::{AnyCollectableVec, Computation, File, Format};
+use brk_structs::Version;
+use brk_vecs::{AnyCollectableVec, Computation, Exit, File, Format};
use log::info;
-use crate::{blocks, cointime, constants, fetched, indexes, market, mining, transactions};
+use crate::{blocks, cointime, constants, fetched, indexes, market, mining, price, transactions};
use super::stateful;
@@ -20,6 +20,7 @@ pub struct Vecs {
pub blocks: blocks::Vecs,
pub mining: mining::Vecs,
pub market: market::Vecs,
+ pub price: Option,
pub transactions: transactions::Vecs,
pub stateful: stateful::Vecs,
pub fetched: Option,
@@ -32,12 +33,12 @@ impl Vecs {
file: &Arc,
version: Version,
indexer: &Indexer,
- fetch: bool,
+ fetcher: Option,
computation: Computation,
format: Format,
fetched_file: &Arc,
states_path: &Path,
- ) -> color_eyre::Result {
+ ) -> Result {
let indexes = indexes::Vecs::forced_import(
file,
version + VERSION + Version::ZERO,
@@ -46,10 +47,19 @@ impl Vecs {
format,
)?;
- let fetched = fetch.then(|| {
+ let fetched = fetcher.map(|fetcher| {
fetched::Vecs::forced_import(
file,
fetched_file,
+ fetcher,
+ version + VERSION + Version::ZERO,
+ )
+ .unwrap()
+ });
+
+ let price = fetched.is_some().then(|| {
+ price::Vecs::forced_import(
+ file,
version + VERSION + Version::ZERO,
computation,
format,
@@ -93,7 +103,7 @@ impl Vecs {
computation,
format,
&indexes,
- fetched.as_ref(),
+ price.as_ref(),
states_path,
)?,
transactions: transactions::Vecs::forced_import(
@@ -103,7 +113,7 @@ impl Vecs {
&indexes,
computation,
format,
- fetched.as_ref(),
+ price.as_ref(),
)?,
cointime: cointime::Vecs::forced_import(
file,
@@ -111,10 +121,11 @@ impl Vecs {
computation,
format,
&indexes,
- fetched.as_ref(),
+ price.as_ref(),
)?,
indexes,
fetched,
+ price,
})
}
@@ -122,9 +133,8 @@ impl Vecs {
&mut self,
indexer: &Indexer,
starting_indexes: brk_indexer::Indexes,
- fetcher: Option<&mut Fetcher>,
exit: &Exit,
- ) -> color_eyre::Result<()> {
+ ) -> Result<()> {
info!("Computing indexes...");
let mut starting_indexes = self.indexes.compute(indexer, starting_indexes, exit)?;
@@ -142,11 +152,13 @@ impl Vecs {
if let Some(fetched) = self.fetched.as_mut() {
info!("Computing fetched...");
- fetched.compute(
+ fetched.compute(indexer, &self.indexes, &starting_indexes, exit)?;
+
+ self.price.as_mut().unwrap().compute(
indexer,
&self.indexes,
&starting_indexes,
- fetcher.unwrap(),
+ fetched,
exit,
)?;
}
@@ -156,16 +168,16 @@ impl Vecs {
indexer,
&self.indexes,
&starting_indexes,
- self.fetched.as_ref(),
+ self.price.as_ref(),
exit,
)?;
- if let Some(fetched) = self.fetched.as_ref() {
+ if let Some(price) = self.price.as_ref() {
info!("Computing market...");
self.market.compute(
indexer,
&self.indexes,
- fetched,
+ price,
&mut self.transactions,
&starting_indexes,
exit,
@@ -177,7 +189,7 @@ impl Vecs {
indexer,
&self.indexes,
&self.transactions,
- self.fetched.as_ref(),
+ self.price.as_ref(),
&self.market,
&mut starting_indexes,
exit,
@@ -187,7 +199,7 @@ impl Vecs {
indexer,
&self.indexes,
&starting_indexes,
- self.fetched.as_ref(),
+ self.price.as_ref(),
&self.transactions,
&self.stateful,
exit,
@@ -207,6 +219,7 @@ impl Vecs {
self.stateful.vecs(),
self.cointime.vecs(),
self.fetched.as_ref().map_or(vec![], |v| v.vecs()),
+ self.price.as_ref().map_or(vec![], |v| v.vecs()),
]
.into_iter()
.flatten()
diff --git a/crates/brk_computer/src/blocks.rs b/crates/brk_computer/src/blocks.rs
index f2c8b1074..ad8cc49fd 100644
--- a/crates/brk_computer/src/blocks.rs
+++ b/crates/brk_computer/src/blocks.rs
@@ -1,12 +1,12 @@
-use std::sync::Arc;
+use std::{path::Path, sync::Arc};
-use brk_core::{
- CheckedSub, DifficultyEpoch, HalvingEpoch, Height, StoredU32, StoredU64, StoredUsize,
- Timestamp, Version, Weight,
-};
-use brk_exit::Exit;
+use brk_error::Result;
use brk_indexer::Indexer;
-use brk_vecs::{AnyCollectableVec, AnyIterableVec, Computation, EagerVec, File, Format};
+use brk_structs::{
+ CheckedSub, DifficultyEpoch, HalvingEpoch, Height, StoredU32, StoredU64, Timestamp, Version,
+ Weight,
+};
+use brk_vecs::{AnyCollectableVec, Computation, EagerVec, Exit, File, Format, VecIterator};
use crate::grouped::Source;
@@ -20,6 +20,8 @@ const VERSION: Version = Version::ZERO;
#[derive(Clone)]
pub struct Vecs {
+ file: Arc,
+
pub height_to_interval: EagerVec,
pub height_to_vbytes: EagerVec,
pub difficultyepoch_to_timestamp: EagerVec,
@@ -27,28 +29,30 @@ pub struct Vecs {
pub timeindexes_to_timestamp: ComputedVecsFromDateIndex,
pub indexes_to_block_count: ComputedVecsFromHeight,
pub indexes_to_block_interval: ComputedVecsFromHeight,
- pub indexes_to_block_size: ComputedVecsFromHeight,
+ pub indexes_to_block_size: ComputedVecsFromHeight,
pub indexes_to_block_vbytes: ComputedVecsFromHeight,
pub indexes_to_block_weight: ComputedVecsFromHeight,
}
impl Vecs {
pub fn forced_import(
- file: &Arc,
+ parent: &Path,
version: Version,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
- ) -> color_eyre::Result {
+ ) -> Result {
+ let file = Arc::new(File::open(&parent.join("blocks"))?);
+
Ok(Self {
height_to_interval: EagerVec::forced_import(
- file,
+ &file,
"interval",
version + VERSION + Version::ZERO,
format,
)?,
timeindexes_to_timestamp: ComputedVecsFromDateIndex::forced_import(
- file,
+ &file,
"timestamp",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -58,7 +62,7 @@ impl Vecs {
VecBuilderOptions::default().add_first(),
)?,
indexes_to_block_interval: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"block_interval",
Source::None,
version + VERSION + Version::ZERO,
@@ -71,7 +75,7 @@ impl Vecs {
.add_average(),
)?,
indexes_to_block_count: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"block_count",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -81,7 +85,7 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_block_weight: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"block_weight",
Source::None,
version + VERSION + Version::ZERO,
@@ -91,7 +95,7 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_block_size: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"block_size",
Source::None,
version + VERSION + Version::ZERO,
@@ -101,13 +105,13 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
height_to_vbytes: EagerVec::forced_import(
- file,
+ &file,
"vbytes",
version + VERSION + Version::ZERO,
format,
)?,
indexes_to_block_vbytes: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"block_vbytes",
Source::None,
version + VERSION + Version::ZERO,
@@ -117,17 +121,19 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
difficultyepoch_to_timestamp: EagerVec::forced_import(
- file,
+ &file,
"timestamp",
version + VERSION + Version::ZERO,
format,
)?,
halvingepoch_to_timestamp: EagerVec::forced_import(
- file,
+ &file,
"timestamp",
version + VERSION + Version::ZERO,
format,
)?,
+
+ file,
})
}
@@ -137,7 +143,7 @@ impl Vecs {
indexes: &indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
- ) -> color_eyre::Result<()> {
+ ) -> Result<()> {
self.timeindexes_to_timestamp.compute_all(
indexer,
indexes,
@@ -149,7 +155,8 @@ impl Vecs {
&indexes.dateindex_to_date,
|(di, d, ..)| (di, Timestamp::from(d)),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -164,7 +171,8 @@ impl Vecs {
&indexer.vecs.height_to_weight,
|h| (h, StoredU32::from(1_u32)),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -240,6 +248,8 @@ impl Vecs {
exit,
)?;
+ self.file.flush()?;
+ self.file.punch_holes()?;
Ok(())
}
diff --git a/crates/brk_computer/src/cointime.rs b/crates/brk_computer/src/cointime.rs
index bf8326322..f244b6266 100644
--- a/crates/brk_computer/src/cointime.rs
+++ b/crates/brk_computer/src/cointime.rs
@@ -1,23 +1,25 @@
-use std::sync::Arc;
+use std::{path::Path, sync::Arc};
-use brk_core::{Bitcoin, CheckedSub, Dollars, StoredF64, Version};
-use brk_exit::Exit;
+use brk_error::Result;
use brk_indexer::Indexer;
-use brk_vecs::{AnyCollectableVec, Computation, File, Format, VecIterator};
+use brk_structs::{Bitcoin, CheckedSub, Dollars, StoredF64, Version};
+use brk_vecs::{AnyCollectableVec, Computation, Exit, File, Format, VecIterator};
use super::{
- Indexes, fetched,
+ Indexes,
grouped::{
ComputedRatioVecsFromDateIndex, ComputedValueVecsFromHeight, ComputedVecsFromHeight,
Source, VecBuilderOptions,
},
- indexes, stateful, transactions,
+ indexes, price, stateful, transactions,
};
const VERSION: Version = Version::ZERO;
#[derive(Clone)]
pub struct Vecs {
+ file: Arc,
+
pub indexes_to_coinblocks_created: ComputedVecsFromHeight,
pub indexes_to_coinblocks_stored: ComputedVecsFromHeight,
pub indexes_to_liveliness: ComputedVecsFromHeight,
@@ -46,18 +48,20 @@ pub struct Vecs {
impl Vecs {
pub fn forced_import(
- file: &Arc,
+ parent: &Path,
version: Version,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
- fetched: Option<&fetched::Vecs>,
- ) -> color_eyre::Result {
- let compute_dollars = fetched.is_some();
+ price: Option<&price::Vecs>,
+ ) -> Result {
+ let file = Arc::new(File::open(&parent.join("cointime"))?);
+
+ let compute_dollars = price.is_some();
Ok(Self {
indexes_to_coinblocks_created: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"coinblocks_created",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -67,7 +71,7 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_coinblocks_stored: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"coinblocks_stored",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -77,7 +81,7 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_liveliness: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"liveliness",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -87,7 +91,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_vaultedness: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"vaultedness",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -97,7 +101,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_activity_to_vaultedness_ratio: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"activity_to_vaultedness_ratio",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -107,7 +111,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_supply: ComputedValueVecsFromHeight::forced_import(
- file,
+ &file,
"vaulted_supply",
Source::Compute,
version + VERSION + Version::ONE,
@@ -118,7 +122,7 @@ impl Vecs {
indexes,
)?,
indexes_to_active_supply: ComputedValueVecsFromHeight::forced_import(
- file,
+ &file,
"active_supply",
Source::Compute,
version + VERSION + Version::ONE,
@@ -129,7 +133,7 @@ impl Vecs {
indexes,
)?,
indexes_to_thermo_cap: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"thermo_cap",
Source::Compute,
version + VERSION + Version::ONE,
@@ -139,7 +143,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_investor_cap: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"investor_cap",
Source::Compute,
version + VERSION + Version::ONE,
@@ -149,7 +153,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_cap: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"vaulted_cap",
Source::Compute,
version + VERSION + Version::ONE,
@@ -159,7 +163,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_active_cap: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"active_cap",
Source::Compute,
version + VERSION + Version::ONE,
@@ -169,7 +173,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_price: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"vaulted_price",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -179,7 +183,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_vaulted_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
- file,
+ &file,
"vaulted_price",
Source::None,
version + VERSION + Version::ZERO,
@@ -189,7 +193,7 @@ impl Vecs {
true,
)?,
indexes_to_active_price: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"active_price",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -199,7 +203,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_active_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
- file,
+ &file,
"active_price",
Source::None,
version + VERSION + Version::ZERO,
@@ -209,7 +213,7 @@ impl Vecs {
true,
)?,
indexes_to_true_market_mean: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"true_market_mean",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -219,7 +223,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_true_market_mean_ratio: ComputedRatioVecsFromDateIndex::forced_import(
- file,
+ &file,
"true_market_mean",
Source::None,
version + VERSION + Version::ZERO,
@@ -229,7 +233,7 @@ impl Vecs {
true,
)?,
indexes_to_cointime_value_destroyed: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"cointime_value_destroyed",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -239,7 +243,7 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_cointime_value_created: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"cointime_value_created",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -249,7 +253,7 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_cointime_value_stored: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"cointime_value_stored",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -259,7 +263,7 @@ impl Vecs {
VecBuilderOptions::default().add_sum().add_cumulative(),
)?,
indexes_to_cointime_price: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"cointime_price",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -269,7 +273,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_cointime_cap: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"cointime_cap",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -279,7 +283,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
indexes_to_cointime_price_ratio: ComputedRatioVecsFromDateIndex::forced_import(
- file,
+ &file,
"cointime_price",
Source::None,
version + VERSION + Version::ZERO,
@@ -288,6 +292,8 @@ impl Vecs {
indexes,
true,
)?,
+
+ file,
})
}
@@ -297,11 +303,11 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
starting_indexes: &Indexes,
- fetched: Option<&fetched::Vecs>,
+ price: Option<&price::Vecs>,
transactions: &transactions::Vecs,
stateful: &stateful::Vecs,
exit: &Exit,
- ) -> color_eyre::Result<()> {
+ ) -> Result<()> {
let circulating_supply = &stateful.utxo_cohorts.all.1.height_to_supply;
self.indexes_to_coinblocks_created.compute_all(
@@ -315,7 +321,8 @@ impl Vecs {
circulating_supply,
|(i, v, ..)| (i, StoredF64::from(Bitcoin::from(v))),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -341,7 +348,8 @@ impl Vecs {
(i, created.checked_sub(destroyed).unwrap())
},
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -360,7 +368,8 @@ impl Vecs {
.height_extra
.unwrap_cumulative(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
let liveliness = &self.indexes_to_liveliness;
@@ -376,7 +385,8 @@ impl Vecs {
liveliness.height.as_ref().unwrap(),
|(i, v, ..)| (i, StoredF64::from(1.0).checked_sub(v).unwrap()),
exit,
- )
+ )?;
+ Ok(())
},
)?;
let vaultedness = &self.indexes_to_vaultedness;
@@ -392,14 +402,15 @@ impl Vecs {
liveliness.height.as_ref().unwrap(),
vaultedness.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
self.indexes_to_vaulted_supply.compute_all(
indexer,
indexes,
- fetched,
+ price,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
@@ -408,14 +419,15 @@ impl Vecs {
circulating_supply,
vaultedness.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
self.indexes_to_active_supply.compute_all(
indexer,
indexes,
- fetched,
+ price,
starting_indexes,
exit,
|vec, _, _, starting_indexes, exit| {
@@ -424,11 +436,12 @@ impl Vecs {
circulating_supply,
liveliness.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
- if let Some(fetched) = fetched {
+ if let Some(price) = price {
let realized_cap = stateful
.utxo_cohorts
.all
@@ -465,7 +478,8 @@ impl Vecs {
.unwrap_cumulative(),
|(i, v, ..)| (i, v),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -480,7 +494,8 @@ impl Vecs {
realized_cap,
self.indexes_to_thermo_cap.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -495,7 +510,8 @@ impl Vecs {
realized_cap,
self.indexes_to_vaultedness.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -510,7 +526,8 @@ impl Vecs {
realized_cap,
self.indexes_to_liveliness.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -525,14 +542,15 @@ impl Vecs {
realized_price,
self.indexes_to_vaultedness.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
self.indexes_to_vaulted_price_ratio.compute_rest(
indexer,
indexes,
- fetched,
+ price,
starting_indexes,
exit,
Some(self.indexes_to_vaulted_price.dateindex.unwrap_last()),
@@ -549,14 +567,15 @@ impl Vecs {
realized_price,
self.indexes_to_liveliness.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
self.indexes_to_active_price_ratio.compute_rest(
indexer,
indexes,
- fetched,
+ price,
starting_indexes,
exit,
Some(self.indexes_to_active_price.dateindex.unwrap_last()),
@@ -577,14 +596,15 @@ impl Vecs {
.as_ref()
.unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
self.indexes_to_true_market_mean_ratio.compute_rest(
indexer,
indexes,
- fetched,
+ price,
starting_indexes,
exit,
Some(self.indexes_to_true_market_mean.dateindex.unwrap_last()),
@@ -600,10 +620,11 @@ impl Vecs {
// The price taken won't be correct for time based indexes
vec.compute_multiply(
starting_indexes.height,
- &fetched.chainindexes_to_close.height,
+ &price.chainindexes_to_close.height,
indexes_to_coinblocks_destroyed.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -615,10 +636,11 @@ impl Vecs {
|vec, _, _, starting_indexes, exit| {
vec.compute_multiply(
starting_indexes.height,
- &fetched.chainindexes_to_close.height,
+ &price.chainindexes_to_close.height,
self.indexes_to_coinblocks_created.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -630,10 +652,11 @@ impl Vecs {
|vec, _, _, starting_indexes, exit| {
vec.compute_multiply(
starting_indexes.height,
- &fetched.chainindexes_to_close.height,
+ &price.chainindexes_to_close.height,
self.indexes_to_coinblocks_stored.height.as_ref().unwrap(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -652,7 +675,8 @@ impl Vecs {
.height_extra
.unwrap_cumulative(),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -667,20 +691,23 @@ impl Vecs {
self.indexes_to_cointime_price.height.as_ref().unwrap(),
circulating_supply,
exit,
- )
+ )?;
+ Ok(())
},
)?;
self.indexes_to_cointime_price_ratio.compute_rest(
indexer,
indexes,
- fetched,
+ price,
starting_indexes,
exit,
Some(self.indexes_to_cointime_price.dateindex.unwrap_last()),
)?;
}
+ self.file.flush()?;
+ self.file.punch_holes()?;
Ok(())
}
diff --git a/crates/brk_computer/src/constants.rs b/crates/brk_computer/src/constants.rs
index 769e4da8f..5dc15b46f 100644
--- a/crates/brk_computer/src/constants.rs
+++ b/crates/brk_computer/src/constants.rs
@@ -1,9 +1,9 @@
-use std::sync::Arc;
+use std::{path::Path, sync::Arc};
-use brk_core::{StoredU8, Version};
-use brk_exit::Exit;
+use brk_error::Result;
use brk_indexer::Indexer;
-use brk_vecs::{AnyCollectableVec, AnyVec, Computation, File, Format};
+use brk_structs::{StoredU16, Version};
+use brk_vecs::{AnyCollectableVec, AnyVec, Computation, Exit, File, Format};
use crate::grouped::Source;
@@ -17,23 +17,27 @@ const VERSION: Version = Version::ZERO;
#[derive(Clone)]
pub struct Vecs {
- pub constant_0: ComputedVecsFromHeight,
- pub constant_1: ComputedVecsFromHeight,
- pub constant_50: ComputedVecsFromHeight,
- pub constant_100: ComputedVecsFromHeight,
+ file: Arc,
+
+ pub constant_0: ComputedVecsFromHeight,
+ pub constant_1: ComputedVecsFromHeight,
+ pub constant_50: ComputedVecsFromHeight,
+ pub constant_100: ComputedVecsFromHeight,
}
impl Vecs {
pub fn forced_import(
- file: &Arc,
+ parent: &Path,
version: Version,
computation: Computation,
format: Format,
indexes: &indexes::Vecs,
- ) -> color_eyre::Result {
+ ) -> Result {
+ let file = Arc::new(File::open(&parent.join("constants"))?);
+
Ok(Self {
constant_0: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"constant_0",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -43,7 +47,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
constant_1: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"constant_1",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -53,7 +57,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
constant_50: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"constant_50",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -63,7 +67,7 @@ impl Vecs {
VecBuilderOptions::default().add_last(),
)?,
constant_100: ComputedVecsFromHeight::forced_import(
- file,
+ &file,
"constant_100",
Source::Compute,
version + VERSION + Version::ZERO,
@@ -72,6 +76,8 @@ impl Vecs {
indexes,
VecBuilderOptions::default().add_last(),
)?,
+
+ file,
})
}
@@ -81,7 +87,7 @@ impl Vecs {
indexes: &indexes::Vecs,
starting_indexes: &Indexes,
exit: &Exit,
- ) -> color_eyre::Result<()> {
+ ) -> Result<()> {
self.constant_0.compute_all(
indexer,
indexes,
@@ -92,9 +98,10 @@ impl Vecs {
starting_indexes.height,
indexes.height_to_date.len(),
indexes.height_to_date.version(),
- |i| (i, StoredU8::new(0)),
+ |i| (i, StoredU16::new(0)),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -108,9 +115,10 @@ impl Vecs {
starting_indexes.height,
indexes.height_to_date.len(),
indexes.height_to_date.version(),
- |i| (i, StoredU8::new(1)),
+ |i| (i, StoredU16::new(1)),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -124,9 +132,10 @@ impl Vecs {
starting_indexes.height,
indexes.height_to_date.len(),
indexes.height_to_date.version(),
- |i| (i, StoredU8::new(50)),
+ |i| (i, StoredU16::new(50)),
exit,
- )
+ )?;
+ Ok(())
},
)?;
@@ -140,12 +149,15 @@ impl Vecs {
starting_indexes.height,
indexes.height_to_date.len(),
indexes.height_to_date.version(),
- |i| (i, StoredU8::new(100)),
+ |i| (i, StoredU16::new(100)),
exit,
- )
+ )?;
+ Ok(())
},
)?;
+ self.file.flush()?;
+ self.file.punch_holes()?;
Ok(())
}
diff --git a/crates/brk_computer/src/fetched.rs b/crates/brk_computer/src/fetched.rs
index 068349c97..e1ac3a471 100644
--- a/crates/brk_computer/src/fetched.rs
+++ b/crates/brk_computer/src/fetched.rs
@@ -1,395 +1,44 @@
-use std::sync::Arc;
+use std::{path::Path, sync::Arc};
-use brk_core::{
- Cents, Close, DateIndex, DecadeIndex, DifficultyEpoch, Dollars, Height, High, Low, MonthIndex,
- OHLCCents, OHLCDollars, OHLCSats, Open, QuarterIndex, Sats, SemesterIndex, Version, WeekIndex,
- YearIndex,
-};
-use brk_exit::Exit;
+use brk_error::Result;
use brk_fetcher::Fetcher;
use brk_indexer::Indexer;
+use brk_structs::{DateIndex, Height, OHLCCents, Version};
use brk_vecs::{
- AnyCollectableVec, AnyIterableVec, AnyVec, Computation, EagerVec, File, Format, StoredIndex,
- VecIterator,
+ AnyCollectableVec, AnyIterableVec, AnyStoredVec, AnyVec, Exit, File, GenericStoredVec, RawVec,
+ StoredIndex, VecIterator,
};
-use crate::grouped::Source;
-
-use super::{
- Indexes,
- grouped::{ComputedVecsFromDateIndex, ComputedVecsFromHeightStrict, VecBuilderOptions},
- indexes,
-};
+use super::{Indexes, indexes};
#[derive(Clone)]
pub struct Vecs {
- pub dateindex_to_close_in_cents: EagerVec>,
- pub dateindex_to_high_in_cents: EagerVec>,
- pub dateindex_to_low_in_cents: EagerVec>,
- pub dateindex_to_ohlc: EagerVec,
- pub dateindex_to_ohlc_in_sats: EagerVec,
- pub dateindex_to_ohlc_in_cents: EagerVec,
- pub dateindex_to_open_in_cents: EagerVec>,
- pub height_to_close_in_cents: EagerVec>,
- pub height_to_high_in_cents: EagerVec>,
- pub height_to_low_in_cents: EagerVec>,
- pub height_to_ohlc: EagerVec,
- pub height_to_ohlc_in_sats: EagerVec,
- pub height_to_ohlc_in_cents: EagerVec,
- pub height_to_open_in_cents: EagerVec>,
- pub timeindexes_to_close: ComputedVecsFromDateIndex>,
- pub timeindexes_to_high: ComputedVecsFromDateIndex>,
- pub timeindexes_to_low: ComputedVecsFromDateIndex>,
- pub timeindexes_to_open: ComputedVecsFromDateIndex>,
- pub timeindexes_to_open_in_sats: ComputedVecsFromDateIndex>,
- pub timeindexes_to_high_in_sats: ComputedVecsFromDateIndex>,
- pub timeindexes_to_low_in_sats: ComputedVecsFromDateIndex>,
- pub timeindexes_to_close_in_sats: ComputedVecsFromDateIndex>,
- pub chainindexes_to_close: ComputedVecsFromHeightStrict>,
- pub chainindexes_to_high: ComputedVecsFromHeightStrict>,
- pub chainindexes_to_low: ComputedVecsFromHeightStrict>,
- pub chainindexes_to_open: ComputedVecsFromHeightStrict>,
- pub chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict>,
- pub chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict>,
- pub chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict>,
- pub chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict>,
- pub weekindex_to_ohlc: EagerVec,
- pub weekindex_to_ohlc_in_sats: EagerVec,
- pub difficultyepoch_to_ohlc: EagerVec,
- pub difficultyepoch_to_ohlc_in_sats: EagerVec,
- pub monthindex_to_ohlc: EagerVec,
- pub monthindex_to_ohlc_in_sats: EagerVec,
- pub quarterindex_to_ohlc: EagerVec,
- pub quarterindex_to_ohlc_in_sats: EagerVec,
- pub semesterindex_to_ohlc: EagerVec,
- pub semesterindex_to_ohlc_in_sats: EagerVec,
- pub yearindex_to_ohlc: EagerVec,
- pub yearindex_to_ohlc_in_sats: EagerVec,
- // pub halvingepoch_to_ohlc: StorableVec,
- // pub halvingepoch_to_ohlc_in_sats: StorableVec,
- pub decadeindex_to_ohlc: EagerVec,
- pub decadeindex_to_ohlc_in_sats: EagerVec,
+ file: Arc,
+ fetcher: Fetcher,
+
+ pub dateindex_to_ohlc_in_cents: RawVec,
+ pub height_to_ohlc_in_cents: RawVec,
}
-const VERSION: Version = Version::ZERO;
-const VERSION_IN_SATS: Version = Version::ZERO;
-
impl Vecs {
- pub fn forced_import(
- file: &Arc,
- fetched_file: &Arc,
- version: Version,
- computation: Computation,
- format: Format,
- indexes: &indexes::Vecs,
- ) -> color_eyre::Result {
+ pub fn forced_import(parent: &Path, fetcher: Fetcher, version: Version) -> Result {
+ let file = Arc::new(File::open(&parent.join("fetched"))?);
+
Ok(Self {
- dateindex_to_ohlc_in_cents: EagerVec::forced_import(
- fetched_file,
+ fetcher,
+
+ dateindex_to_ohlc_in_cents: RawVec::forced_import(
+ &file,
"ohlc_in_cents",
version + Version::ZERO,
- format,
)?,
- dateindex_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- dateindex_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- )?,
- dateindex_to_close_in_cents: EagerVec::forced_import(
- file,
- "close_in_cents",
- version + VERSION + Version::ZERO,
- format,
- )?,
- dateindex_to_high_in_cents: EagerVec::forced_import(
- file,
- "high_in_cents",
- version + VERSION + Version::ZERO,
- format,
- )?,
- dateindex_to_low_in_cents: EagerVec::forced_import(
- file,
- "low_in_cents",
- version + VERSION + Version::ZERO,
- format,
- )?,
- dateindex_to_open_in_cents: EagerVec::forced_import(
- file,
- "open_in_cents",
- version + VERSION + Version::ZERO,
- format,
- )?,
- height_to_ohlc_in_cents: EagerVec::forced_import(
- fetched_file,
+ height_to_ohlc_in_cents: RawVec::forced_import(
+ &file,
"ohlc_in_cents",
version + Version::ZERO,
- format,
- )?,
- height_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- height_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- )?,
- height_to_close_in_cents: EagerVec::forced_import(
- file,
- "close_in_cents",
- version + VERSION + Version::ZERO,
- format,
- )?,
- height_to_high_in_cents: EagerVec::forced_import(
- file,
- "high_in_cents",
- version + VERSION + Version::ZERO,
- format,
- )?,
- height_to_low_in_cents: EagerVec::forced_import(
- file,
- "low_in_cents",
- version + VERSION + Version::ZERO,
- format,
- )?,
- height_to_open_in_cents: EagerVec::forced_import(
- file,
- "open_in_cents",
- version + VERSION + Version::ZERO,
- format,
- )?,
- timeindexes_to_open: ComputedVecsFromDateIndex::forced_import(
- file,
- "open",
- Source::Compute,
- version + VERSION + Version::ZERO,
- format,
- computation,
- indexes,
- VecBuilderOptions::default().add_first(),
- )?,
- timeindexes_to_high: ComputedVecsFromDateIndex::forced_import(
- file,
- "high",
- Source::Compute,
- version + VERSION + Version::ZERO,
- format,
- computation,
- indexes,
- VecBuilderOptions::default().add_max(),
- )?,
- timeindexes_to_low: ComputedVecsFromDateIndex::forced_import(
- file,
- "low",
- Source::Compute,
- version + VERSION + Version::ZERO,
- format,
- computation,
- indexes,
- VecBuilderOptions::default().add_min(),
- )?,
- timeindexes_to_close: ComputedVecsFromDateIndex::forced_import(
- file,
- "close",
- Source::Compute,
- version + VERSION + Version::ZERO,
- format,
- computation,
- indexes,
- VecBuilderOptions::default().add_last(),
- )?,
- timeindexes_to_open_in_sats: ComputedVecsFromDateIndex::forced_import(
- file,
- "open_in_sats",
- Source::Compute,
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- computation,
- indexes,
- VecBuilderOptions::default().add_first(),
- )?,
- timeindexes_to_high_in_sats: ComputedVecsFromDateIndex::forced_import(
- file,
- "high_in_sats",
- Source::Compute,
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- computation,
- indexes,
- VecBuilderOptions::default().add_max(),
- )?,
- timeindexes_to_low_in_sats: ComputedVecsFromDateIndex::forced_import(
- file,
- "low_in_sats",
- Source::Compute,
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- computation,
- indexes,
- VecBuilderOptions::default().add_min(),
- )?,
- timeindexes_to_close_in_sats: ComputedVecsFromDateIndex::forced_import(
- file,
- "close_in_sats",
- Source::Compute,
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- computation,
- indexes,
- VecBuilderOptions::default().add_last(),
- )?,
- chainindexes_to_open: ComputedVecsFromHeightStrict::forced_import(
- file,
- "open",
- version + VERSION + Version::ZERO,
- format,
- VecBuilderOptions::default().add_first(),
- )?,
- chainindexes_to_high: ComputedVecsFromHeightStrict::forced_import(
- file,
- "high",
- version + VERSION + Version::ZERO,
- format,
- VecBuilderOptions::default().add_max(),
- )?,
- chainindexes_to_low: ComputedVecsFromHeightStrict::forced_import(
- file,
- "low",
- version + VERSION + Version::ZERO,
- format,
- VecBuilderOptions::default().add_min(),
- )?,
- chainindexes_to_close: ComputedVecsFromHeightStrict::forced_import(
- file,
- "close",
- version + VERSION + Version::ZERO,
- format,
- VecBuilderOptions::default().add_last(),
- )?,
- chainindexes_to_open_in_sats: ComputedVecsFromHeightStrict::forced_import(
- file,
- "open_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- VecBuilderOptions::default().add_first(),
- )?,
- chainindexes_to_high_in_sats: ComputedVecsFromHeightStrict::forced_import(
- file,
- "high_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- VecBuilderOptions::default().add_max(),
- )?,
- chainindexes_to_low_in_sats: ComputedVecsFromHeightStrict::forced_import(
- file,
- "low_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- VecBuilderOptions::default().add_min(),
- )?,
- chainindexes_to_close_in_sats: ComputedVecsFromHeightStrict::forced_import(
- file,
- "close_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- VecBuilderOptions::default().add_last(),
- )?,
- weekindex_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- weekindex_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- )?,
- difficultyepoch_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- difficultyepoch_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- )?,
- monthindex_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- monthindex_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- )?,
- quarterindex_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- quarterindex_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- )?,
- semesterindex_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- semesterindex_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- )?,
- yearindex_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- yearindex_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
- )?,
- // halvingepoch_to_ohlc: StorableVec::forced_import(file,
- // "halvingepoch_to_ohlc"), version + VERSION + Version::ZERO, format)?,
- decadeindex_to_ohlc: EagerVec::forced_import(
- file,
- "ohlc",
- version + VERSION + Version::ZERO,
- format,
- )?,
- decadeindex_to_ohlc_in_sats: EagerVec::forced_import(
- file,
- "ohlc_in_sats",
- version + VERSION + VERSION_IN_SATS + Version::ZERO,
- format,
)?,
+
+ file,
})
}
@@ -398,78 +47,49 @@ impl Vecs {
indexer: &Indexer,
indexes: &indexes::Vecs,
starting_indexes: &Indexes,
- fetcher: &mut Fetcher,
exit: &Exit,
- ) -> color_eyre::Result<()> {
- let mut height_to_timestamp_iter = indexer.vecs.height_to_timestamp.iter();
- self.height_to_ohlc_in_cents.compute_transform(
- starting_indexes.height,
- &indexer.vecs.height_to_timestamp,
- |(h, t, ..)| {
- let ohlc = fetcher
- .get_height(
- h,
- t,
- h.decremented()
- .map(|prev_h| height_to_timestamp_iter.unwrap_get_inner(prev_h)),
- )
- .unwrap();
- (h, ohlc)
- },
- exit,
- )?;
-
- self.height_to_open_in_cents.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, ohlc.open),
- exit,
- )?;
-
- self.height_to_high_in_cents.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, ohlc.high),
- exit,
- )?;
-
- self.height_to_low_in_cents.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, ohlc.low),
- exit,
- )?;
-
- self.height_to_close_in_cents.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, ohlc.close),
- exit,
- )?;
-
- self.height_to_ohlc.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, OHLCDollars::from(ohlc)),
- exit,
- )?;
+ ) -> Result<()> {
+ let height_to_timestamp = &indexer.vecs.height_to_timestamp;
+ height_to_timestamp
+ .iter_at(starting_indexes.height)
+ .try_for_each(|(i, v)| -> Result<()> {
+ let v = v.into_owned();
+ self.height_to_ohlc_in_cents.forced_push_at(
+ i,
+ self.fetcher
+ .get_height(
+ i,
+ v,
+ i.decremented().map(|prev_i| {
+ height_to_timestamp.into_iter().unwrap_get_inner(prev_i)
+ }),
+ )
+ .unwrap(),
+ exit,
+ )?;
+ Ok(())
+ })?;
+ self.height_to_ohlc_in_cents.safe_flush(exit)?;
let mut prev = None;
- self.dateindex_to_ohlc_in_cents.compute_transform(
- starting_indexes.dateindex,
- &indexes.dateindex_to_date,
- |(di, d, this)| {
+ indexes
+ .dateindex_to_date
+ .iter_at(starting_indexes.dateindex)
+ .try_for_each(|(i, v)| -> Result<()> {
+ let d = v.into_owned();
if prev.is_none() {
- let i = di.unwrap_to_usize();
+ let i = i.unwrap_to_usize();
prev.replace(if i > 0 {
- this.into_iter().unwrap_get_inner_(i - 1)
+ self.dateindex_to_ohlc_in_cents
+ .into_iter()
+ .unwrap_get_inner_(i - 1)
} else {
OHLCCents::default()
});
}
- let ohlc = if di.unwrap_to_usize() + 100 >= this.len()
- && let Ok(mut ohlc) = fetcher.get_date(d)
+ let ohlc = if i.unwrap_to_usize() + 100 >= self.dateindex_to_ohlc_in_cents.len()
+ && let Ok(mut ohlc) = self.fetcher.get_date(d)
{
let prev_open = *prev.as_ref().unwrap().close;
*ohlc.open = prev_open;
@@ -482,788 +102,22 @@ impl Vecs {
prev.replace(ohlc.clone());
- (di, ohlc)
- },
- exit,
- )?;
+ self.dateindex_to_ohlc_in_cents
+ .forced_push_at(i, ohlc, exit)?;
- self.dateindex_to_open_in_cents.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, ohlc.open),
- exit,
- )?;
-
- self.dateindex_to_high_in_cents.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, ohlc.high),
- exit,
- )?;
-
- self.dateindex_to_low_in_cents.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, ohlc.low),
- exit,
- )?;
-
- self.dateindex_to_close_in_cents.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, ohlc.close),
- exit,
- )?;
-
- self.dateindex_to_ohlc.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc_in_cents,
- |(di, ohlc, ..)| (di, OHLCDollars::from(ohlc)),
- exit,
- )?;
-
- self.timeindexes_to_close.compute_all(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc,
- |(di, ohlc, ..)| (di, ohlc.close),
- exit,
- )
- },
- )?;
-
- self.timeindexes_to_high.compute_all(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc,
- |(di, ohlc, ..)| (di, ohlc.high),
- exit,
- )
- },
- )?;
-
- self.timeindexes_to_low.compute_all(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc,
- |(di, ohlc, ..)| (di, ohlc.low),
- exit,
- )
- },
- )?;
-
- self.timeindexes_to_open.compute_all(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.dateindex,
- &self.dateindex_to_ohlc,
- |(di, ohlc, ..)| (di, ohlc.open),
- exit,
- )
- },
- )?;
-
- self.chainindexes_to_close.compute(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc,
- |(di, ohlc, ..)| (di, ohlc.close),
- exit,
- )
- },
- )?;
-
- self.chainindexes_to_high.compute(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc,
- |(di, ohlc, ..)| (di, ohlc.high),
- exit,
- )
- },
- )?;
-
- self.chainindexes_to_low.compute(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc,
- |(di, ohlc, ..)| (di, ohlc.low),
- exit,
- )
- },
- )?;
-
- self.chainindexes_to_open.compute(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.height,
- &self.height_to_ohlc,
- |(di, ohlc, ..)| (di, ohlc.open),
- exit,
- )
- },
- )?;
-
- let mut weekindex_first_iter = self.timeindexes_to_open.weekindex.unwrap_first().iter();
- let mut weekindex_max_iter = self.timeindexes_to_high.weekindex.unwrap_max().iter();
- let mut weekindex_min_iter = self.timeindexes_to_low.weekindex.unwrap_min().iter();
- self.weekindex_to_ohlc.compute_transform(
- starting_indexes.weekindex,
- self.timeindexes_to_close.weekindex.unwrap_last(),
- |(i, close, ..)| {
- let open = weekindex_first_iter.unwrap_get_inner(i);
- let high = weekindex_max_iter.unwrap_get_inner(i);
- let low = weekindex_min_iter.unwrap_get_inner(i);
- (
- i,
- OHLCDollars {
- open,
- high,
- low,
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut difficultyepoch_first_iter = self
- .chainindexes_to_open
- .difficultyepoch
- .unwrap_first()
- .iter();
- let mut difficultyepoch_max_iter = self
- .chainindexes_to_high
- .difficultyepoch
- .unwrap_max()
- .iter();
- let mut difficultyepoch_min_iter =
- self.chainindexes_to_low.difficultyepoch.unwrap_min().iter();
- self.difficultyepoch_to_ohlc.compute_transform(
- starting_indexes.difficultyepoch,
- self.chainindexes_to_close.difficultyepoch.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCDollars {
- open: difficultyepoch_first_iter.unwrap_get_inner(i),
- high: difficultyepoch_max_iter.unwrap_get_inner(i),
- low: difficultyepoch_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut monthindex_first_iter = self.timeindexes_to_open.monthindex.unwrap_first().iter();
- let mut monthindex_max_iter = self.timeindexes_to_high.monthindex.unwrap_max().iter();
- let mut monthindex_min_iter = self.timeindexes_to_low.monthindex.unwrap_min().iter();
- self.monthindex_to_ohlc.compute_transform(
- starting_indexes.monthindex,
- self.timeindexes_to_close.monthindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCDollars {
- open: monthindex_first_iter.unwrap_get_inner(i),
- high: monthindex_max_iter.unwrap_get_inner(i),
- low: monthindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut quarterindex_first_iter =
- self.timeindexes_to_open.quarterindex.unwrap_first().iter();
- let mut quarterindex_max_iter = self.timeindexes_to_high.quarterindex.unwrap_max().iter();
- let mut quarterindex_min_iter = self.timeindexes_to_low.quarterindex.unwrap_min().iter();
- self.quarterindex_to_ohlc.compute_transform(
- starting_indexes.quarterindex,
- self.timeindexes_to_close.quarterindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCDollars {
- open: quarterindex_first_iter.unwrap_get_inner(i),
- high: quarterindex_max_iter.unwrap_get_inner(i),
- low: quarterindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut semesterindex_first_iter =
- self.timeindexes_to_open.semesterindex.unwrap_first().iter();
- let mut semesterindex_max_iter = self.timeindexes_to_high.semesterindex.unwrap_max().iter();
- let mut semesterindex_min_iter = self.timeindexes_to_low.semesterindex.unwrap_min().iter();
- self.semesterindex_to_ohlc.compute_transform(
- starting_indexes.semesterindex,
- self.timeindexes_to_close.semesterindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCDollars {
- open: semesterindex_first_iter.unwrap_get_inner(i),
- high: semesterindex_max_iter.unwrap_get_inner(i),
- low: semesterindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut yearindex_first_iter = self.timeindexes_to_open.yearindex.unwrap_first().iter();
- let mut yearindex_max_iter = self.timeindexes_to_high.yearindex.unwrap_max().iter();
- let mut yearindex_min_iter = self.timeindexes_to_low.yearindex.unwrap_min().iter();
- self.yearindex_to_ohlc.compute_transform(
- starting_indexes.yearindex,
- self.timeindexes_to_close.yearindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCDollars {
- open: yearindex_first_iter.unwrap_get_inner(i),
- high: yearindex_max_iter.unwrap_get_inner(i),
- low: yearindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- // self.halvingepoch_to_ohlc
- // .compute_transform(starting_indexes.halvingepoch, other, t, exit)?;
-
- let mut decadeindex_first_iter = self.timeindexes_to_open.decadeindex.unwrap_first().iter();
- let mut decadeindex_max_iter = self.timeindexes_to_high.decadeindex.unwrap_max().iter();
- let mut decadeindex_min_iter = self.timeindexes_to_low.decadeindex.unwrap_min().iter();
- self.decadeindex_to_ohlc.compute_transform(
- starting_indexes.decadeindex,
- self.timeindexes_to_close.decadeindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCDollars {
- open: decadeindex_first_iter.unwrap_get_inner(i),
- high: decadeindex_max_iter.unwrap_get_inner(i),
- low: decadeindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- self.chainindexes_to_open_in_sats.compute(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.height,
- &self.chainindexes_to_open.height,
- |(i, open, ..)| (i, Open::new(Sats::ONE_BTC / *open)),
- exit,
- )
- },
- )?;
-
- self.chainindexes_to_high_in_sats.compute(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.height,
- &self.chainindexes_to_low.height,
- |(i, low, ..)| (i, High::new(Sats::ONE_BTC / *low)),
- exit,
- )
- },
- )?;
-
- self.chainindexes_to_low_in_sats.compute(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.height,
- &self.chainindexes_to_high.height,
- |(i, high, ..)| (i, Low::new(Sats::ONE_BTC / *high)),
- exit,
- )
- },
- )?;
-
- self.chainindexes_to_close_in_sats.compute(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.height,
- &self.chainindexes_to_close.height,
- |(i, close, ..)| (i, Close::new(Sats::ONE_BTC / *close)),
- exit,
- )
- },
- )?;
-
- self.timeindexes_to_open_in_sats.compute_all(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.dateindex,
- self.timeindexes_to_open.dateindex.as_ref().unwrap(),
- |(i, open, ..)| (i, Open::new(Sats::ONE_BTC / *open)),
- exit,
- )
- },
- )?;
-
- self.timeindexes_to_high_in_sats.compute_all(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.dateindex,
- self.timeindexes_to_low.dateindex.as_ref().unwrap(),
- |(i, low, ..)| (i, High::new(Sats::ONE_BTC / *low)),
- exit,
- )
- },
- )?;
-
- self.timeindexes_to_low_in_sats.compute_all(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.dateindex,
- self.timeindexes_to_high.dateindex.as_ref().unwrap(),
- |(i, high, ..)| (i, Low::new(Sats::ONE_BTC / *high)),
- exit,
- )
- },
- )?;
-
- self.timeindexes_to_close_in_sats.compute_all(
- indexer,
- indexes,
- starting_indexes,
- exit,
- |v, _, _, starting_indexes, exit| {
- v.compute_transform(
- starting_indexes.dateindex,
- self.timeindexes_to_close.dateindex.as_ref().unwrap(),
- |(i, close, ..)| (i, Close::new(Sats::ONE_BTC / *close)),
- exit,
- )
- },
- )?;
-
- let mut height_first_iter = self.chainindexes_to_open_in_sats.height.iter();
- let mut height_max_iter = self.chainindexes_to_high_in_sats.height.iter();
- let mut height_min_iter = self.chainindexes_to_low_in_sats.height.iter();
- self.height_to_ohlc_in_sats.compute_transform(
- starting_indexes.height,
- &self.chainindexes_to_close_in_sats.height,
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: height_first_iter.unwrap_get_inner(i),
- high: height_max_iter.unwrap_get_inner(i),
- low: height_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut dateindex_first_iter = self
- .timeindexes_to_open_in_sats
- .dateindex
- .as_ref()
- .unwrap()
- .iter();
- let mut dateindex_max_iter = self
- .timeindexes_to_high_in_sats
- .dateindex
- .as_ref()
- .unwrap()
- .iter();
- let mut dateindex_min_iter = self
- .timeindexes_to_low_in_sats
- .dateindex
- .as_ref()
- .unwrap()
- .iter();
- self.dateindex_to_ohlc_in_sats.compute_transform(
- starting_indexes.dateindex,
- self.timeindexes_to_close_in_sats
- .dateindex
- .as_ref()
- .unwrap(),
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: dateindex_first_iter.unwrap_get_inner(i),
- high: dateindex_max_iter.unwrap_get_inner(i),
- low: dateindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut weekindex_first_iter = self
- .timeindexes_to_open_in_sats
- .weekindex
- .unwrap_first()
- .iter();
- let mut weekindex_max_iter = self
- .timeindexes_to_high_in_sats
- .weekindex
- .unwrap_max()
- .iter();
- let mut weekindex_min_iter = self
- .timeindexes_to_low_in_sats
- .weekindex
- .unwrap_min()
- .iter();
- self.weekindex_to_ohlc_in_sats.compute_transform(
- starting_indexes.weekindex,
- self.timeindexes_to_close_in_sats.weekindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: weekindex_first_iter.unwrap_get_inner(i),
- high: weekindex_max_iter.unwrap_get_inner(i),
- low: weekindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut difficultyepoch_first_iter = self
- .chainindexes_to_open_in_sats
- .difficultyepoch
- .unwrap_first()
- .iter();
- let mut difficultyepoch_max_iter = self
- .chainindexes_to_high_in_sats
- .difficultyepoch
- .unwrap_max()
- .iter();
- let mut difficultyepoch_min_iter = self
- .chainindexes_to_low_in_sats
- .difficultyepoch
- .unwrap_min()
- .iter();
- self.difficultyepoch_to_ohlc_in_sats.compute_transform(
- starting_indexes.difficultyepoch,
- self.chainindexes_to_close_in_sats
- .difficultyepoch
- .unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: difficultyepoch_first_iter.unwrap_get_inner(i),
- high: difficultyepoch_max_iter.unwrap_get_inner(i),
- low: difficultyepoch_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut monthindex_first_iter = self
- .timeindexes_to_open_in_sats
- .monthindex
- .unwrap_first()
- .iter();
- let mut monthindex_max_iter = self
- .timeindexes_to_high_in_sats
- .monthindex
- .unwrap_max()
- .iter();
- let mut monthindex_min_iter = self
- .timeindexes_to_low_in_sats
- .monthindex
- .unwrap_min()
- .iter();
- self.monthindex_to_ohlc_in_sats.compute_transform(
- starting_indexes.monthindex,
- self.timeindexes_to_close_in_sats.monthindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: monthindex_first_iter.unwrap_get_inner(i),
- high: monthindex_max_iter.unwrap_get_inner(i),
- low: monthindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut quarterindex_first_iter = self
- .timeindexes_to_open_in_sats
- .quarterindex
- .unwrap_first()
- .iter();
- let mut quarterindex_max_iter = self
- .timeindexes_to_high_in_sats
- .quarterindex
- .unwrap_max()
- .iter();
- let mut quarterindex_min_iter = self
- .timeindexes_to_low_in_sats
- .quarterindex
- .unwrap_min()
- .iter();
- self.quarterindex_to_ohlc_in_sats.compute_transform(
- starting_indexes.quarterindex,
- self.timeindexes_to_close_in_sats.quarterindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: quarterindex_first_iter.unwrap_get_inner(i),
- high: quarterindex_max_iter.unwrap_get_inner(i),
- low: quarterindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut semesterindex_first_iter = self
- .timeindexes_to_open_in_sats
- .semesterindex
- .unwrap_first()
- .iter();
- let mut semesterindex_max_iter = self
- .timeindexes_to_high_in_sats
- .semesterindex
- .unwrap_max()
- .iter();
- let mut semesterindex_min_iter = self
- .timeindexes_to_low_in_sats
- .semesterindex
- .unwrap_min()
- .iter();
- self.semesterindex_to_ohlc_in_sats.compute_transform(
- starting_indexes.semesterindex,
- self.timeindexes_to_close_in_sats
- .semesterindex
- .unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: semesterindex_first_iter.unwrap_get_inner(i),
- high: semesterindex_max_iter.unwrap_get_inner(i),
- low: semesterindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- let mut yearindex_first_iter = self
- .timeindexes_to_open_in_sats
- .yearindex
- .unwrap_first()
- .iter();
- let mut yearindex_max_iter = self
- .timeindexes_to_high_in_sats
- .yearindex
- .unwrap_max()
- .iter();
- let mut yearindex_min_iter = self
- .timeindexes_to_low_in_sats
- .yearindex
- .unwrap_min()
- .iter();
- self.yearindex_to_ohlc_in_sats.compute_transform(
- starting_indexes.yearindex,
- self.timeindexes_to_close_in_sats.yearindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: yearindex_first_iter.unwrap_get_inner(i),
- high: yearindex_max_iter.unwrap_get_inner(i),
- low: yearindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
-
- // self.halvingepoch_to_ohlc
- // _in_sats.compute_transform(starting_indexes.halvingepoch, other, t, exit)?;
-
- let mut decadeindex_first_iter = self
- .timeindexes_to_open_in_sats
- .decadeindex
- .unwrap_first()
- .iter();
- let mut decadeindex_max_iter = self
- .timeindexes_to_high_in_sats
- .decadeindex
- .unwrap_max()
- .iter();
- let mut decadeindex_min_iter = self
- .timeindexes_to_low_in_sats
- .decadeindex
- .unwrap_min()
- .iter();
- self.decadeindex_to_ohlc_in_sats.compute_transform(
- starting_indexes.decadeindex,
- self.timeindexes_to_close_in_sats.decadeindex.unwrap_last(),
- |(i, close, ..)| {
- (
- i,
- OHLCSats {
- open: decadeindex_first_iter.unwrap_get_inner(i),
- high: decadeindex_max_iter.unwrap_get_inner(i),
- low: decadeindex_min_iter.unwrap_get_inner(i),
- close,
- },
- )
- },
- exit,
- )?;
+ Ok(())
+ })?;
+ self.dateindex_to_ohlc_in_cents.safe_flush(exit)?;
+ self.file.flush()?;
+ self.file.punch_holes()?;
Ok(())
}
pub fn vecs(&self) -> Vec<&dyn AnyCollectableVec> {
vec![
- vec![
- &self.dateindex_to_close_in_cents as &dyn AnyCollectableVec,
- &self.dateindex_to_high_in_cents,
- &self.dateindex_to_low_in_cents,
- &self.dateindex_to_ohlc,
- &self.dateindex_to_ohlc_in_cents,
- &self.dateindex_to_open_in_cents,
- &self.height_to_close_in_cents,
- &self.height_to_high_in_cents,
- &self.height_to_low_in_cents,
- &self.height_to_ohlc,
- &self.height_to_ohlc_in_cents,
- &self.height_to_open_in_cents,
- &self.weekindex_to_ohlc,
- &self.difficultyepoch_to_ohlc,
- &self.monthindex_to_ohlc,
- &self.quarterindex_to_ohlc,
- &self.semesterindex_to_ohlc,
- &self.yearindex_to_ohlc,
- // &self.halvingepoch_to_ohlc,
- &self.decadeindex_to_ohlc,
- &self.height_to_ohlc_in_sats,
- &self.dateindex_to_ohlc_in_sats,
- &self.weekindex_to_ohlc_in_sats,
- &self.difficultyepoch_to_ohlc_in_sats,
- &self.monthindex_to_ohlc_in_sats,
- &self.quarterindex_to_ohlc_in_sats,
- &self.semesterindex_to_ohlc_in_sats,
- &self.yearindex_to_ohlc_in_sats,
- // &self.halvingepoch_to_ohlc_in_sats,
- &self.decadeindex_to_ohlc_in_sats,
- ],
- self.timeindexes_to_close.vecs(),
- self.timeindexes_to_high.vecs(),
- self.timeindexes_to_low.vecs(),
- self.timeindexes_to_open.vecs(),
- self.chainindexes_to_close.vecs(),
- self.chainindexes_to_high.vecs(),
- self.chainindexes_to_low.vecs(),
- self.chainindexes_to_open.vecs(),
- self.timeindexes_to_close_in_sats.vecs(),
- self.timeindexes_to_high_in_sats.vecs(),
- self.timeindexes_to_low_in_sats.vecs(),
- self.timeindexes_to_open_in_sats.vecs(),
- self.chainindexes_to_close_in_sats.vecs(),
- self.chainindexes_to_high_in_sats.vecs(),
- self.chainindexes_to_low_in_sats.vecs(),
- self.chainindexes_to_open_in_sats.vecs(),
+ &self.dateindex_to_ohlc_in_cents as &dyn AnyCollectableVec,
+ &self.height_to_ohlc_in_cents,
]
- .into_iter()
- .flatten()
- .collect::>()
}
}
diff --git a/crates/brk_computer/src/grouped/builder_computed.rs b/crates/brk_computer/src/grouped/builder_computed.rs
index 627fa177a..6b492f9d1 100644
--- a/crates/brk_computer/src/grouped/builder_computed.rs
+++ b/crates/brk_computer/src/grouped/builder_computed.rs
@@ -1,10 +1,11 @@
use std::sync::Arc;
-use brk_core::{FromCoarserIndex, Result, Version};
-use brk_exit::Exit;
+use brk_error::Result;
+
+use brk_structs::Version;
use brk_vecs::{
- AnyCollectableVec, AnyIterableVec, BoxedAnyIterableVec, CloneableAnyIterableVec, Computation,
- ComputedVec, ComputedVecFrom2, File, Format, StoredIndex,
+ AnyBoxedIterableVec, AnyCloneableIterableVec, AnyCollectableVec, AnyIterableVec, Computation,
+ ComputedVec, ComputedVecFrom2, Exit, File, Format, FromCoarserIndex, StoredIndex,
};
use crate::grouped::{EagerVecBuilder, VecBuilderOptions};
@@ -44,11 +45,11 @@ where
version: Version,
format: Format,
computation: Computation,
- source: Option>,
+ source: Option>,
source_extra: &EagerVecBuilder,
- len_source: BoxedAnyIterableVec,
+ len_source: AnyBoxedIterableVec,
options: ComputedVecBuilderOptions,
- ) -> color_eyre::Result {
+ ) -> Result {
let only_one_active = options.is_only_one_active();
let suffix = |s: &str| format!("{name}_{s}");
diff --git a/crates/brk_computer/src/grouped/builder_eager.rs b/crates/brk_computer/src/grouped/builder_eager.rs
index 57001e54c..3ff073125 100644
--- a/crates/brk_computer/src/grouped/builder_eager.rs
+++ b/crates/brk_computer/src/grouped/builder_eager.rs
@@ -1,11 +1,11 @@
use std::sync::Arc;
-use brk_core::{CheckedSub, Result, StoredUsize, Version};
-use brk_exit::Exit;
+use brk_error::{Error, Result};
+use brk_structs::{CheckedSub, StoredU64, Version};
use brk_vecs::{
- AnyCollectableVec, AnyIterableVec, AnyVec, EagerVec, File, Format, StoredIndex, StoredType,
+ AnyCollectableVec, AnyIterableVec, AnyStoredVec, AnyVec, EagerVec, Exit, File, Format,
+ GenericStoredVec, StoredIndex, StoredRaw,
};
-use color_eyre::eyre::ContextCompat;
use crate::utils::get_percentile;
@@ -44,7 +44,7 @@ where
version: Version,
format: Format,
options: VecBuilderOptions,
- ) -> color_eyre::Result {
+ ) -> Result {
let only_one_active = options.is_only_one_active();
let suffix = |s: &str| format!("{name}_{s}");
@@ -213,8 +213,9 @@ where
cumulative_vec.iter().unwrap_get_inner(index)
});
source.iter_at(index).try_for_each(|(i, v)| -> Result<()> {
- cumulative = cumulative.clone() + v.into_owned();
- cumulative_vec.forced_push_at(i, cumulative.clone(), exit)
+ cumulative += v.into_owned();
+ cumulative_vec.forced_push_at(i, cumulative, exit)?;
+ Ok(())
})?;
self.safe_flush(exit)?;
@@ -227,11 +228,11 @@ where
max_from: I,
source: &impl AnyIterableVec,
first_indexes: &impl AnyIterableVec,
- count_indexes: &impl AnyIterableVec,
+ count_indexes: &impl AnyIterableVec,
exit: &Exit,
) -> Result<()>
where
- I2: StoredIndex + StoredType + CheckedSub,
+ I2: StoredIndex + StoredRaw + CheckedSub,
{
self.validate_computed_version_or_reset_file(
source.version() + first_indexes.version() + count_indexes.version(),
@@ -265,7 +266,7 @@ where
}
if let Some(last) = self.last.as_mut() {
- let count_index = *count_index;
+ let count_index = *count_index as usize;
if count_index == 0 {
panic!("should compute last if count can be 0")
}
@@ -295,7 +296,7 @@ where
if needs_values {
source_iter.set(first_index);
let mut values = (&mut source_iter)
- .take(*count_index)
+ .take(*count_index as usize)
.map(|(_, v)| v.into_owned())
.collect::>();
@@ -305,9 +306,9 @@ where
if let Some(max) = self.max.as_mut() {
max.forced_push_at(
i,
- values
+ *values
.last()
- .context("expect some")
+ .ok_or(Error::Str("expect some"))
.inspect_err(|_| {
dbg!(
&values,
@@ -320,8 +321,7 @@ where
source.name()
);
})
- .unwrap()
- .clone(),
+ .unwrap(),
exit,
)?;
}
@@ -347,7 +347,7 @@ where
}
if let Some(min) = self.min.as_mut() {
- min.forced_push_at(i, values.first().unwrap().clone(), exit)?;
+ min.forced_push_at(i, *values.first().unwrap(), exit)?;
}
}
@@ -356,18 +356,18 @@ where
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
if let Some(average) = self.average.as_mut() {
- let avg = sum.clone() / len;
+ let avg = sum / len;
average.forced_push_at(i, avg, exit)?;
}
if needs_sum_or_cumulative {
if let Some(sum_vec) = self.sum.as_mut() {
- sum_vec.forced_push_at(i, sum.clone(), exit)?;
+ sum_vec.forced_push_at(i, sum, exit)?;
}
if let Some(cumulative_vec) = self.cumulative.as_mut() {
- let t = cumulative.as_ref().unwrap().clone() + sum;
- cumulative.replace(t.clone());
+ let t = cumulative.unwrap() + sum;
+ cumulative.replace(t);
cumulative_vec.forced_push_at(i, t, exit)?;
}
}
@@ -388,11 +388,11 @@ where
max_from: I,
source: &EagerVecBuilder,
first_indexes: &impl AnyIterableVec,
- count_indexes: &impl AnyIterableVec,
+ count_indexes: &impl AnyIterableVec,
exit: &Exit,
) -> Result<()>
where
- I2: StoredIndex + StoredType + CheckedSub,
+ I2: StoredIndex + StoredRaw + CheckedSub,
{
if self._90p.is_some()
|| self._75p.is_some()
@@ -440,7 +440,7 @@ where
}
if let Some(last) = self.last.as_mut() {
- let count_index = *count_index;
+ let count_index = *count_index as usize;
if count_index == 0 {
panic!("should compute last if count can be 0")
}
@@ -464,22 +464,22 @@ where
let source_max_iter = source_max_iter.as_mut().unwrap();
source_max_iter.set(first_index);
let mut values = source_max_iter
- .take(*count_index)
+ .take(*count_index as usize)
.map(|(_, v)| v.into_owned())
.collect::>();
values.sort_unstable();
- max.forced_push_at(i, values.last().unwrap().clone(), exit)?;
+ max.forced_push_at(i, *values.last().unwrap(), exit)?;
}
if let Some(min) = self.min.as_mut() {
let source_min_iter = source_min_iter.as_mut().unwrap();
source_min_iter.set(first_index);
let mut values = source_min_iter
- .take(*count_index)
+ .take(*count_index as usize)
.map(|(_, v)| v.into_owned())
.collect::>();
values.sort_unstable();
- min.forced_push_at(i, values.first().unwrap().clone(), exit)?;
+ min.forced_push_at(i, *values.first().unwrap(), exit)?;
}
}
@@ -488,7 +488,7 @@ where
let source_average_iter = source_average_iter.as_mut().unwrap();
source_average_iter.set(first_index);
let values = source_average_iter
- .take(*count_index)
+ .take(*count_index as usize)
.map(|(_, v)| v.into_owned())
.collect::>();
@@ -504,19 +504,19 @@ where
let source_sum_iter = source_sum_iter.as_mut().unwrap();
source_sum_iter.set(first_index);
let values = source_sum_iter
- .take(*count_index)
+ .take(*count_index as usize)
.map(|(_, v)| v.into_owned())
.collect::>();
let sum = values.into_iter().fold(T::from(0), |a, b| a + b);
if let Some(sum_vec) = self.sum.as_mut() {
- sum_vec.forced_push_at(i, sum.clone(), exit)?;
+ sum_vec.forced_push_at(i, sum, exit)?;
}
if let Some(cumulative_vec) = self.cumulative.as_mut() {
- let t = cumulative.as_ref().unwrap().clone() + sum;
- cumulative.replace(t.clone());
+ let t = cumulative.unwrap() + sum;
+ cumulative.replace(t);
cumulative_vec.forced_push_at(i, t, exit)?;
}
}
diff --git a/crates/brk_computer/src/grouped/computed.rs b/crates/brk_computer/src/grouped/computed.rs
new file mode 100644
index 000000000..849e61b59
--- /dev/null
+++ b/crates/brk_computer/src/grouped/computed.rs
@@ -0,0 +1,23 @@
+use std::ops::{Add, AddAssign, Div};
+
+use brk_vecs::StoredCompressed;
+
+pub trait ComputedType
+where
+ Self: StoredCompressed
+ + From
+ + Div
+ + Add