From f23907768f35820635fb5df3e3e900ad51f47bb8 Mon Sep 17 00:00:00 2001 From: nym21 Date: Sat, 6 Dec 2025 21:35:19 +0100 Subject: [PATCH] global: fixes --- Cargo.lock | 188 +++++++----------- crates/brk_bundler/Cargo.toml | 4 +- crates/brk_cli/Cargo.toml | 1 + crates/brk_cli/src/main.rs | 10 +- crates/brk_computer/src/chain.rs | 184 ++++++++++++++--- crates/brk_computer/src/fetched.rs | 4 +- .../brk_computer/src/grouped/builder_eager.rs | 32 +-- .../brk_computer/src/grouped/from_txindex.rs | 4 +- .../src/grouped/price_percentiles.rs | 9 + crates/brk_computer/src/lib.rs | 26 ++- crates/brk_computer/src/pools/mod.rs | 2 +- .../src/stateful/address_cohort.rs | 2 +- .../src/stateful/address_indexes.rs | 44 +++- .../brk_computer/src/stateful/common/push.rs | 46 ++--- crates/brk_computer/src/stateful/flushable.rs | 10 + crates/brk_computer/src/stateful/mod.rs | 4 +- .../brk_computer/src/stateful/utxo_cohorts.rs | 2 +- crates/brk_computer/src/traits.rs | 8 +- crates/brk_monitor/examples/mempool.rs | 2 +- crates/brk_monitor/src/lib.rs | 4 +- crates/brk_query/Cargo.toml | 1 + crates/brk_query/examples/main.rs | 2 +- crates/brk_query/src/async.rs | 10 +- crates/brk_query/src/chain/addresses.rs | 107 +++------- crates/brk_query/src/lib.rs | 15 +- crates/brk_query/src/vecs.rs | 1 + crates/brk_server/examples/main.rs | 2 +- crates/brk_types/src/addresschainstats.rs | 6 +- crates/brk_types/src/addressmempoolstats.rs | 2 +- crates/brk_types/src/addressstats.rs | 2 +- 30 files changed, 439 insertions(+), 295 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 80d10b318..b28401185 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -593,6 +593,7 @@ dependencies = [ "brk_indexer", "brk_iterator", "brk_logger", + "brk_monitor", "brk_query", "brk_reader", "brk_rpc", @@ -769,6 +770,7 @@ dependencies = [ "brk_computer", "brk_error", "brk_indexer", + "brk_monitor", "brk_reader", "brk_rpc", "brk_traversable", @@ -842,9 +844,7 @@ dependencies = [ [[package]] name = "brk_rolldown" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3b364266a980e4ef9103403d7df033a296bae3e9070a1813e26fd38efa8e178c" +version = "0.5.1" dependencies = [ "anyhow", "append-only-vec", @@ -870,7 +870,6 @@ dependencies = [ "brk_string_wizard", "commondir", "css-module-lexer", - "dunce", "futures", "indexmap", "itertools 0.14.0", @@ -897,9 +896,7 @@ dependencies = [ [[package]] name = "brk_rolldown_common" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "827632ee8afa97703c8f071e0745887ab58e552d1905d1d98c86ee346130cb06" +version = "0.5.1" dependencies = [ "anyhow", "arcstr", @@ -929,9 +926,7 @@ dependencies = [ [[package]] name = "brk_rolldown_dev_common" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "358da3a5f3f5138de180d12802b887260e724ec7f57fb50a5d71d17b18f37908" +version = "0.5.1" dependencies = [ "brk_rolldown_common", "brk_rolldown_error", @@ -940,9 +935,7 @@ dependencies = [ [[package]] name = "brk_rolldown_devtools" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "40934290db9fd9d230af056565a485f8189f3b83b44a5d4216da3d66826cc610" +version = "0.5.1" dependencies = [ "blake3", "brk_rolldown_devtools_action", @@ -956,9 +949,7 @@ dependencies = [ [[package]] name = "brk_rolldown_devtools_action" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a249525f317d69cc220254fa55c2f93cada5aefae238d2a9c00b96c8c502595b" +version = "0.5.1" dependencies = [ "serde", "ts-rs", @@ -966,9 +957,7 @@ dependencies = [ [[package]] name = "brk_rolldown_ecmascript" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ac3c00fb7dca60e30c97d14a34bb27343f4fd433363eeb8e3aa630075b49eb6" +version = "0.5.1" dependencies = [ "arcstr", "brk_rolldown_error", @@ -979,9 +968,7 @@ dependencies = [ [[package]] name = "brk_rolldown_ecmascript_utils" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f65855f91040323a46eeb93471948e19382d74597eeb25b233eacbc8593be6b5" +version = "0.5.1" dependencies = [ "brk_rolldown_common", "oxc", @@ -990,9 +977,7 @@ dependencies = [ [[package]] name = "brk_rolldown_error" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "630677b212d97019f49374f77404c873535eada9cce670c6fc0212c658f96e36" +version = "0.5.1" dependencies = [ "anyhow", "arcstr", @@ -1010,9 +995,7 @@ dependencies = [ [[package]] name = "brk_rolldown_fs" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12d79615fdbaa3202d16b48e914754e4ea333b4a30b6d2b3bd1474914f8f7b6e" +version = "0.5.1" dependencies = [ "oxc_resolver", "vfs", @@ -1020,9 +1003,7 @@ dependencies = [ [[package]] name = "brk_rolldown_plugin" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "723f806cd14b933f477902e80c66f14aabdd480ed076417bc7381ea9ed8d2509" +version = "0.5.1" dependencies = [ "anyhow", "arcstr", @@ -1050,9 +1031,7 @@ dependencies = [ [[package]] name = "brk_rolldown_plugin_chunk_import_map" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1edd58ab6d786f046bf8ee5cabf164723fa44eb355f5cecfe50493fc64bbcbb" +version = "0.5.1" dependencies = [ "arcstr", "brk_rolldown_common", @@ -1065,9 +1044,7 @@ dependencies = [ [[package]] name = "brk_rolldown_plugin_data_uri" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "02abd52b8d1039bfbea205b2187bb70aaa0d5a4a98f6b98964081da3c643b974" +version = "0.5.1" dependencies = [ "arcstr", "base64-simd", @@ -1080,9 +1057,7 @@ dependencies = [ [[package]] name = "brk_rolldown_plugin_hmr" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddaa6d6b746c58932c0a2be7349828b57af1e60c6915cc44a66f1f8cea4fa425" +version = "0.5.1" dependencies = [ "arcstr", "brk_rolldown_common", @@ -1092,9 +1067,7 @@ dependencies = [ [[package]] name = "brk_rolldown_plugin_oxc_runtime" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4d8bc78ecc86eba7cc81f47a5d12615f828c1e845eaad19a468b838fc8493a7" +version = "0.5.1" dependencies = [ "arcstr", "brk_rolldown_plugin", @@ -1104,9 +1077,7 @@ dependencies = [ [[package]] name = "brk_rolldown_resolver" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04131fec652171bc12654fecbefcce8f3c9b36a146056bb8352df38a6e046df3" +version = "0.5.1" dependencies = [ "anyhow", "arcstr", @@ -1121,9 +1092,7 @@ dependencies = [ [[package]] name = "brk_rolldown_sourcemap" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "63136e1550beeee9fed780ec88d87377e91f885ebe9912a4af4c62031655abcc" +version = "0.5.1" dependencies = [ "brk_rolldown_utils", "memchr", @@ -1134,18 +1103,14 @@ dependencies = [ [[package]] name = "brk_rolldown_std_utils" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cb5489323b1194d0f0d194760202e19b516fc1c5f311d3220b6ae55749b746ff" +version = "0.5.1" dependencies = [ "regex", ] [[package]] name = "brk_rolldown_tracing" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "99301f73f3c567eb708c4720c62d24ce799d62e2320d0c8e4dbffe30b5ecc8c2" +version = "0.5.1" dependencies = [ "tracing", "tracing-chrome", @@ -1154,9 +1119,7 @@ dependencies = [ [[package]] name = "brk_rolldown_utils" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693bbb5c14cd63f1b9eea2de4443d923fc5a690bdcce778c4f34cbb6c4cdae6c" +version = "0.5.1" dependencies = [ "anyhow", "arcstr", @@ -1248,9 +1211,7 @@ dependencies = [ [[package]] name = "brk_string_wizard" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6ac938b032f908cebd47d4bccde3c1c94430b08c35f384d35efde47f151c4a4" +version = "0.5.1" dependencies = [ "memchr", "oxc_index", @@ -1964,12 +1925,6 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d3a5ccdfd6c5e7e2fea9c5cf256f2a08216047fab19c621c3da64e9ae4a1462d" -[[package]] -name = "dunce" -version = "1.0.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" - [[package]] name = "dwrote" version = "0.11.5" @@ -3316,9 +3271,9 @@ checksum = "9c6901729fa79e91a0913333229e9ca5dc725089d1c363b2f4b4760709dc4a52" [[package]] name = "oxc" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87899ddffc6f9f155c7be64151a24baeae290feb60cc2baf832cf1be003a0fd5" +checksum = "a84dd7448a9e9c8b7d5a3af20d1a66ef5516dc3a575d7cfcf291736bcd2d733f" dependencies = [ "oxc_allocator", "oxc_ast", @@ -3382,9 +3337,9 @@ dependencies = [ [[package]] name = "oxc_allocator" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "674f1447d47e26970ff13d8da8140ffb0d7fde347ab9af3e5c00e67943d4bc9b" +checksum = "5b360908629f56d1b18f60e0aa5a70122fb61e33543078fafbe565edb759d77f" dependencies = [ "allocator-api2", "bumpalo", @@ -3397,9 +3352,9 @@ dependencies = [ [[package]] name = "oxc_ast" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d6c0d01c611150a159b448272d08d198e57a69531b78c599133310a1e38177e2" +checksum = "89e58ea2b49f8940307bb2d012ca0d2a744f6d98e9f96fc87b0a89c8578d57bf" dependencies = [ "bitflags 2.10.0", "oxc_allocator", @@ -3414,9 +3369,9 @@ dependencies = [ [[package]] name = "oxc_ast_macros" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43a3373b0b8c5c1914cc7082f31cd81f3412f395f5e81970689fb6d547847a11" +checksum = "91c6039e721360dd47a101f7ae1e183f90b3c812cd4ed52e0221d791f70d184a" dependencies = [ "phf", "proc-macro2", @@ -3426,9 +3381,9 @@ dependencies = [ [[package]] name = "oxc_ast_visit" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8169aac113a81df22d73872e3a54dc6fa6c7465890b3379f83088977a894bdf9" +checksum = "11ecdea97ef3f0e7ee7d9b0d29327040acfe30c8c4593bdf4e0bc8fea0d75899" dependencies = [ "oxc_allocator", "oxc_ast", @@ -3438,9 +3393,9 @@ dependencies = [ [[package]] name = "oxc_cfg" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "070b4b6ecfcf81f43c87049a19cc69f81a2c720d26f8d52eff67f718b9107de1" +checksum = "99efc2ae6e378cb26414e2ce7bad8d909a978753ffd46484a5b4a359c40dca0d" dependencies = [ "bitflags 2.10.0", "itertools 0.14.0", @@ -3452,9 +3407,9 @@ dependencies = [ [[package]] name = "oxc_codegen" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ace497cd606cd1dc74553cce8afec424b0b6ca3b97723610111df2797e3627ff" +checksum = "0de87539d889ed530f5811c5c17af31b3346e3b709c1fd6b9e2a5e00c4bac934" dependencies = [ "bitflags 2.10.0", "cow-utils", @@ -3473,9 +3428,9 @@ dependencies = [ [[package]] name = "oxc_compat" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3e0856e92b71c10152f9f2f8a25b827e13751e21f5b766b0730a6339a7e9657d" +checksum = "7319a884684197f2a524231d05d25df2a0155c49a9dc6400980410c746779731" dependencies = [ "cow-utils", "oxc-browserslist", @@ -3486,18 +3441,18 @@ dependencies = [ [[package]] name = "oxc_data_structures" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b2b15eb8528cea49be898e99b523653b27daed396fdf77d048547d94f091199c" +checksum = "e0e95d9a0caba623cc004b9d420951a7d490a0cd172912ac776df12a51063353" dependencies = [ "ropey", ] [[package]] name = "oxc_diagnostics" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd2de22e8e8c94f10adc58f13ae94550e350b82e5143962c0e5c0cb9932acf5d" +checksum = "cbf468b479ee17919e8bc11c31c405f059762abb78c90cb0931f5e94d7eac30b" dependencies = [ "cow-utils", "oxc-miette", @@ -3506,9 +3461,9 @@ dependencies = [ [[package]] name = "oxc_ecmascript" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "665d01392d92af2c7904a1106d19272fd62e4ab45079519f8c33fae5046b53a5" +checksum = "c5af7a036c4e13de3f0b6bfa7bcf22326c3e1da32210b65ec114c96e17e8d77d" dependencies = [ "cow-utils", "num-bigint", @@ -3521,9 +3476,9 @@ dependencies = [ [[package]] name = "oxc_estree" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66ed73e88c330b977905de971e7a06ba4309c6658a83cfcf63f2013b37922beb" +checksum = "bb9bac2f3fd66cdb7b538e551d9d72b01ceb9009244c25d370684dce01301114" dependencies = [ "dragonbox_ecma", "itoa", @@ -3543,9 +3498,9 @@ dependencies = [ [[package]] name = "oxc_isolated_declarations" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c0f557d328bacc724cd18961131aee3f8ff8dd191e8161c59c2a0362d8e146e" +checksum = "a645efa67f8bf7c68cefc35766a36a5136753b0cbf5237abc8c6206970348eca" dependencies = [ "bitflags 2.10.0", "oxc_allocator", @@ -3560,9 +3515,9 @@ dependencies = [ [[package]] name = "oxc_mangler" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6adc903fc3ac929ff1329a7449580f1ea5a290658cb196af9eb00dc655e89d45" +checksum = "4f944d504ae8d359db077de7c1869691da098bce01155639fdf324d8df9de857" dependencies = [ "itertools 0.14.0", "oxc_allocator", @@ -3577,9 +3532,9 @@ dependencies = [ [[package]] name = "oxc_minifier" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15933b28ce93793d88d5a481cd12ed4c848d78d660855a6c9a2e6a9d17436def" +checksum = "0995fd7b64ca4433ce12c4b3701574c1fb494c2a879442096d18cdbbe945547f" dependencies = [ "cow-utils", "oxc_allocator", @@ -3602,9 +3557,9 @@ dependencies = [ [[package]] name = "oxc_parser" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b9e94af4e21a37daf13e4b8c2233566daa0e85cc25cf50bf2670ae6235b41767" +checksum = "12077275a0b65791602bbd398bc83253328e8ab656a2218a7d6bb571787551f9" dependencies = [ "bitflags 2.10.0", "cow-utils", @@ -3625,9 +3580,9 @@ dependencies = [ [[package]] name = "oxc_regular_expression" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1bb5d767d654aac7cb95bffe2ae0bcc953e6c8330e0aa311b4c06edb65da384c" +checksum = "b02e8106836d7128a3fac86db05409910c3d96fe46d465cd071877a12802d5b3" dependencies = [ "bitflags 2.10.0", "oxc_allocator", @@ -3668,9 +3623,9 @@ dependencies = [ [[package]] name = "oxc_semantic" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e38d51bf83b46fdb16caa8992da99a3c3df4cd7ae200bfe7abe6c5f7bbd52b65" +checksum = "f474c2a181362369f44a0ffe3bc780b286602c920a8ec166f12d7818664b391a" dependencies = [ "itertools 0.14.0", "oxc_allocator", @@ -3703,9 +3658,9 @@ dependencies = [ [[package]] name = "oxc_span" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ad5a043ad3a15cafe9d50c3f8e289546d2ff66d039285af30829d667a81bbf2" +checksum = "4106c63cc7e72fc8b34943b2b85ce1f5350cdd5c7ad70757d1691ac0ebded943" dependencies = [ "compact_str", "oxc-miette", @@ -3717,9 +3672,9 @@ dependencies = [ [[package]] name = "oxc_syntax" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d87f83a206be495b3536c4ed11f6e444efbdaead4dc778192b2c2038afdd7acb" +checksum = "25aa1d1b60990a801ec16f7f984ea148bfbcb330590aeabf3cf639537401ebca" dependencies = [ "bitflags 2.10.0", "cow-utils", @@ -3738,9 +3693,9 @@ dependencies = [ [[package]] name = "oxc_transformer" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac3e5343d946d84ba975673d1fc2b2c238bac8a4f862de99bda5b53bf5dbd516" +checksum = "baed8f7ad713ba560917e3b6e0a8fb07d2ad98df08cdfcaed5f98ba7fe3dc80c" dependencies = [ "base64 0.22.1", "compact_str", @@ -3754,7 +3709,6 @@ dependencies = [ "oxc_data_structures", "oxc_diagnostics", "oxc_ecmascript", - "oxc_parser", "oxc_regular_expression", "oxc_semantic", "oxc_span", @@ -3768,9 +3722,9 @@ dependencies = [ [[package]] name = "oxc_transformer_plugins" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a8fbfa79a74b201a4cf305485e42e18099403e01868465270c40e0535d6239e2" +checksum = "34b1b2873f1d50d88d28d521bfe8572b40ea3cd88f8d46e59896bed97b342fe7" dependencies = [ "cow-utils", "itoa", @@ -3790,9 +3744,9 @@ dependencies = [ [[package]] name = "oxc_traverse" -version = "0.98.0" +version = "0.101.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8dd74744115efb7fbd2e3ff40d55ab8ef1c9071577ea2f682a4a2e627473e5b8" +checksum = "634336ede7a5007a8e3ef629cd3c224c7ccbba5d3a9e332e69250e4fb853456b" dependencies = [ "itoa", "oxc_allocator", @@ -4394,17 +4348,17 @@ dependencies = [ [[package]] name = "rolldown-notify" -version = "8.2.4" +version = "9.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e9122f313b71e7632260ee45f068ff70239bff876997fe78aecf2eabaf4fd709" +checksum = "58d681610d5f1818f4bd2a3c5ccaf92d494abf5ba5cabab1f707a652d9f7c5d8" dependencies = [ "bitflags 2.10.0", "inotify", "kqueue", "libc", - "log", "mio", "rolldown-notify-types", + "tracing", "walkdir", "windows-sys 0.61.2", ] diff --git a/crates/brk_bundler/Cargo.toml b/crates/brk_bundler/Cargo.toml index 8655aff3b..debb67f7d 100644 --- a/crates/brk_bundler/Cargo.toml +++ b/crates/brk_bundler/Cargo.toml @@ -11,7 +11,7 @@ build = "build.rs" [dependencies] log = { workspace = true } notify = "8.2.0" -rolldown = { version = "0.4.0", package = "brk_rolldown" } -# brk_rolldown = { path = "../../../rolldown/crates/rolldown"} +rolldown = { path = "../../../rolldown/crates/rolldown", package = "brk_rolldown" } +# rolldown = { version = "0.5.0", package = "brk_rolldown", features = ["experimental"] } sugar_path = "1.2.1" tokio = { workspace = true } diff --git a/crates/brk_cli/Cargo.toml b/crates/brk_cli/Cargo.toml index 7fb7f8c21..0ca8d3b64 100644 --- a/crates/brk_cli/Cargo.toml +++ b/crates/brk_cli/Cargo.toml @@ -16,6 +16,7 @@ brk_error = { workspace = true } brk_fetcher = { workspace = true } brk_indexer = { workspace = true } brk_iterator = { workspace = true } +brk_monitor = { workspace = true } brk_query = { workspace = true } brk_logger = { workspace = true } brk_reader = { workspace = true } diff --git a/crates/brk_cli/src/main.rs b/crates/brk_cli/src/main.rs index 6843ca79f..f6fc9e10b 100644 --- a/crates/brk_cli/src/main.rs +++ b/crates/brk_cli/src/main.rs @@ -14,6 +14,7 @@ use brk_computer::Computer; use brk_error::Result; use brk_indexer::Indexer; use brk_iterator::Blocks; +use brk_monitor::Mempool; use brk_query::AsyncQuery; use brk_reader::Reader; use brk_server::{Server, VERSION}; @@ -57,7 +58,14 @@ pub fn run() -> color_eyre::Result<()> { let mut computer = Computer::forced_import(&config.brkdir(), &indexer, config.fetcher())?; - let query = AsyncQuery::build(&reader, &indexer, &computer); + let mempool = Mempool::new(&client); + + let mempool_clone = mempool.clone(); + thread::spawn(move || { + mempool_clone.start(); + }); + + let query = AsyncQuery::build(&reader, &indexer, &computer, Some(mempool)); let website = config.website(); diff --git a/crates/brk_computer/src/chain.rs b/crates/brk_computer/src/chain.rs index 4c9951b1d..d07df579d 100644 --- a/crates/brk_computer/src/chain.rs +++ b/crates/brk_computer/src/chain.rs @@ -173,30 +173,77 @@ impl Vecs { } macro_rules! computed_h { ($name:expr, $source:expr, $opts:expr) => { - ComputedVecsFromHeight::forced_import(&db, $name, $source, version + v0, indexes, $opts)? + ComputedVecsFromHeight::forced_import( + &db, + $name, + $source, + version + v0, + indexes, + $opts, + )? }; ($name:expr, $source:expr, $v:expr, $opts:expr) => { - ComputedVecsFromHeight::forced_import(&db, $name, $source, version + $v, indexes, $opts)? + ComputedVecsFromHeight::forced_import( + &db, + $name, + $source, + version + $v, + indexes, + $opts, + )? }; } macro_rules! computed_di { ($name:expr, $opts:expr) => { - ComputedVecsFromDateIndex::forced_import(&db, $name, Source::Compute, version + v0, indexes, $opts)? + ComputedVecsFromDateIndex::forced_import( + &db, + $name, + Source::Compute, + version + v0, + indexes, + $opts, + )? }; ($name:expr, $v:expr, $opts:expr) => { - ComputedVecsFromDateIndex::forced_import(&db, $name, Source::Compute, version + $v, indexes, $opts)? + ComputedVecsFromDateIndex::forced_import( + &db, + $name, + Source::Compute, + version + $v, + indexes, + $opts, + )? }; } macro_rules! computed_tx { ($name:expr, $source:expr, $opts:expr) => { - ComputedVecsFromTxindex::forced_import(&db, $name, $source, version + v0, indexes, $opts)? + ComputedVecsFromTxindex::forced_import( + &db, + $name, + $source, + version + v0, + indexes, + $opts, + )? }; } let last = || VecBuilderOptions::default().add_last(); let sum = || VecBuilderOptions::default().add_sum(); let sum_cum = || VecBuilderOptions::default().add_sum().add_cumulative(); - let stats = || VecBuilderOptions::default().add_average().add_minmax().add_percentiles(); - let full_stats = || VecBuilderOptions::default().add_average().add_minmax().add_percentiles().add_sum().add_cumulative(); + let stats = || { + VecBuilderOptions::default() + .add_average() + .add_minmax() + .add_percentiles() + }; + let full_stats = || { + VecBuilderOptions::default() + .add_average() + .add_minmax() + .add_percentiles() + .add_sum() + .add_cumulative() + }; let txinindex_to_value: EagerVec> = eager!("value"); @@ -299,7 +346,10 @@ impl Vecs { yearindex_to_block_count_target, decadeindex_to_block_count_target, height_to_interval: eager!("interval"), - timeindexes_to_timestamp: computed_di!("timestamp", VecBuilderOptions::default().add_first()), + timeindexes_to_timestamp: computed_di!( + "timestamp", + VecBuilderOptions::default().add_first() + ), indexes_to_block_interval: computed_h!("block_interval", Source::None, stats()), indexes_to_block_count: computed_h!("block_count", Source::Compute, sum_cum()), indexes_to_1w_block_count: computed_di!("1w_block_count", last()), @@ -328,7 +378,7 @@ impl Vecs { indexes_to_tx_v3: computed_h!("tx_v3", Source::Compute, sum_cum()), indexes_to_sent: ComputedValueVecsFromHeight::forced_import( &db, - "sent", + "sent_sum", Source::Compute, version + Version::ZERO, VecBuilderOptions::default().add_sum(), @@ -400,36 +450,120 @@ impl Vecs { indexes_to_p2wpkh_count: computed_h!("p2wpkh_count", Source::Compute, full_stats()), indexes_to_p2wsh_count: computed_h!("p2wsh_count", Source::Compute, full_stats()), indexes_to_opreturn_count: computed_h!("opreturn_count", Source::Compute, full_stats()), - indexes_to_unknownoutput_count: computed_h!("unknownoutput_count", Source::Compute, full_stats()), - indexes_to_emptyoutput_count: computed_h!("emptyoutput_count", Source::Compute, full_stats()), + indexes_to_unknownoutput_count: computed_h!( + "unknownoutput_count", + Source::Compute, + full_stats() + ), + indexes_to_emptyoutput_count: computed_h!( + "emptyoutput_count", + Source::Compute, + full_stats() + ), indexes_to_exact_utxo_count: computed_h!("exact_utxo_count", Source::Compute, last()), indexes_to_subsidy_usd_1y_sma: compute_dollars - .then(|| ComputedVecsFromDateIndex::forced_import(&db, "subsidy_usd_1y_sma", Source::Compute, version + v0, indexes, last())) + .then(|| { + ComputedVecsFromDateIndex::forced_import( + &db, + "subsidy_usd_1y_sma", + Source::Compute, + version + v0, + indexes, + last(), + ) + }) .transpose()?, indexes_to_puell_multiple: compute_dollars - .then(|| ComputedVecsFromDateIndex::forced_import(&db, "puell_multiple", Source::Compute, version + v0, indexes, last())) + .then(|| { + ComputedVecsFromDateIndex::forced_import( + &db, + "puell_multiple", + Source::Compute, + version + v0, + indexes, + last(), + ) + }) .transpose()?, indexes_to_hash_rate: computed_h!("hash_rate", Source::Compute, v5, last()), indexes_to_hash_rate_1w_sma: computed_di!("hash_rate_1w_sma", last()), indexes_to_hash_rate_1m_sma: computed_di!("hash_rate_1m_sma", last()), indexes_to_hash_rate_2m_sma: computed_di!("hash_rate_2m_sma", last()), indexes_to_hash_rate_1y_sma: computed_di!("hash_rate_1y_sma", last()), - indexes_to_difficulty_as_hash: computed_h!("difficulty_as_hash", Source::Compute, last()), - indexes_to_difficulty_adjustment: computed_h!("difficulty_adjustment", Source::Compute, sum()), - indexes_to_blocks_before_next_difficulty_adjustment: computed_h!("blocks_before_next_difficulty_adjustment", Source::Compute, v2, last()), - indexes_to_days_before_next_difficulty_adjustment: computed_h!("days_before_next_difficulty_adjustment", Source::Compute, v2, last()), - indexes_to_blocks_before_next_halving: computed_h!("blocks_before_next_halving", Source::Compute, v2, last()), - indexes_to_days_before_next_halving: computed_h!("days_before_next_halving", Source::Compute, v2, last()), + indexes_to_difficulty_as_hash: computed_h!( + "difficulty_as_hash", + Source::Compute, + last() + ), + indexes_to_difficulty_adjustment: computed_h!( + "difficulty_adjustment", + Source::Compute, + sum() + ), + indexes_to_blocks_before_next_difficulty_adjustment: computed_h!( + "blocks_before_next_difficulty_adjustment", + Source::Compute, + v2, + last() + ), + indexes_to_days_before_next_difficulty_adjustment: computed_h!( + "days_before_next_difficulty_adjustment", + Source::Compute, + v2, + last() + ), + indexes_to_blocks_before_next_halving: computed_h!( + "blocks_before_next_halving", + Source::Compute, + v2, + last() + ), + indexes_to_days_before_next_halving: computed_h!( + "days_before_next_halving", + Source::Compute, + v2, + last() + ), indexes_to_hash_price_ths: computed_h!("hash_price_ths", Source::Compute, v4, last()), indexes_to_hash_price_phs: computed_h!("hash_price_phs", Source::Compute, v4, last()), indexes_to_hash_value_ths: computed_h!("hash_value_ths", Source::Compute, v4, last()), indexes_to_hash_value_phs: computed_h!("hash_value_phs", Source::Compute, v4, last()), - indexes_to_hash_price_ths_min: computed_h!("hash_price_ths_min", Source::Compute, v4, last()), - indexes_to_hash_price_phs_min: computed_h!("hash_price_phs_min", Source::Compute, v4, last()), - indexes_to_hash_price_rebound: computed_h!("hash_price_rebound", Source::Compute, v4, last()), - indexes_to_hash_value_ths_min: computed_h!("hash_value_ths_min", Source::Compute, v4, last()), - indexes_to_hash_value_phs_min: computed_h!("hash_value_phs_min", Source::Compute, v4, last()), - indexes_to_hash_value_rebound: computed_h!("hash_value_rebound", Source::Compute, v4, last()), + indexes_to_hash_price_ths_min: computed_h!( + "hash_price_ths_min", + Source::Compute, + v4, + last() + ), + indexes_to_hash_price_phs_min: computed_h!( + "hash_price_phs_min", + Source::Compute, + v4, + last() + ), + indexes_to_hash_price_rebound: computed_h!( + "hash_price_rebound", + Source::Compute, + v4, + last() + ), + indexes_to_hash_value_ths_min: computed_h!( + "hash_value_ths_min", + Source::Compute, + v4, + last() + ), + indexes_to_hash_value_phs_min: computed_h!( + "hash_value_phs_min", + Source::Compute, + v4, + last() + ), + indexes_to_hash_value_rebound: computed_h!( + "hash_value_rebound", + Source::Compute, + v4, + last() + ), indexes_to_inflation_rate: computed_di!("inflation_rate", last()), indexes_to_annualized_volume: computed_di!("annualized_volume", last()), indexes_to_annualized_volume_btc: computed_di!("annualized_volume_btc", last()), diff --git a/crates/brk_computer/src/fetched.rs b/crates/brk_computer/src/fetched.rs index 003dccf77..c744ff7cd 100644 --- a/crates/brk_computer/src/fetched.rs +++ b/crates/brk_computer/src/fetched.rs @@ -94,7 +94,7 @@ impl Vecs { prev_timestamp = Some(v); Ok(()) })?; - self.height_to_price_ohlc_in_cents.safe_flush(exit)?; + self.height_to_price_ohlc_in_cents.safe_write(exit)?; let index = starting_indexes .dateindex @@ -130,7 +130,7 @@ impl Vecs { Ok(()) })?; - self.dateindex_to_price_ohlc_in_cents.safe_flush(exit)?; + self.dateindex_to_price_ohlc_in_cents.safe_write(exit)?; Ok(()) } diff --git a/crates/brk_computer/src/grouped/builder_eager.rs b/crates/brk_computer/src/grouped/builder_eager.rs index 11d4b613a..eae7e618e 100644 --- a/crates/brk_computer/src/grouped/builder_eager.rs +++ b/crates/brk_computer/src/grouped/builder_eager.rs @@ -238,7 +238,7 @@ where Ok(()) })?; - self.safe_flush(exit)?; + self.safe_write(exit)?; Ok(()) } @@ -335,7 +335,7 @@ where Ok(()) })?; - self.safe_flush(exit)?; + self.safe_write(exit)?; Ok(()) } @@ -460,7 +460,7 @@ where Ok(()) })?; - self.safe_flush(exit)?; + self.safe_write(exit)?; Ok(()) } @@ -527,42 +527,42 @@ where self.cumulative.u() } - pub fn safe_flush(&mut self, exit: &Exit) -> Result<()> { + pub fn safe_write(&mut self, exit: &Exit) -> Result<()> { if let Some(first) = self.first.as_mut() { - first.safe_flush(exit)?; + first.safe_write(exit)?; } if let Some(last) = self.last.as_mut() { - last.safe_flush(exit)?; + last.safe_write(exit)?; } if let Some(min) = self.min.as_mut() { - min.safe_flush(exit)?; + min.safe_write(exit)?; } if let Some(max) = self.max.as_mut() { - max.safe_flush(exit)?; + max.safe_write(exit)?; } if let Some(median) = self.median.as_mut() { - median.safe_flush(exit)?; + median.safe_write(exit)?; } if let Some(average) = self.average.as_mut() { - average.safe_flush(exit)?; + average.safe_write(exit)?; } if let Some(sum) = self.sum.as_mut() { - sum.safe_flush(exit)?; + sum.safe_write(exit)?; } if let Some(cumulative) = self.cumulative.as_mut() { - cumulative.safe_flush(exit)?; + cumulative.safe_write(exit)?; } if let Some(pct90) = self.pct90.as_mut() { - pct90.safe_flush(exit)?; + pct90.safe_write(exit)?; } if let Some(pct75) = self.pct75.as_mut() { - pct75.safe_flush(exit)?; + pct75.safe_write(exit)?; } if let Some(pct25) = self.pct25.as_mut() { - pct25.safe_flush(exit)?; + pct25.safe_write(exit)?; } if let Some(pct10) = self.pct10.as_mut() { - pct10.safe_flush(exit)?; + pct10.safe_write(exit)?; } Ok(()) diff --git a/crates/brk_computer/src/grouped/from_txindex.rs b/crates/brk_computer/src/grouped/from_txindex.rs index 546056cb6..c7ab45cbd 100644 --- a/crates/brk_computer/src/grouped/from_txindex.rs +++ b/crates/brk_computer/src/grouped/from_txindex.rs @@ -330,7 +330,7 @@ impl ComputedVecsFromTxindex { Ok(()) })?; - self.height.safe_flush(exit)?; + self.height.safe_write(exit)?; self.compute_after_height(indexes, starting_indexes, exit) } @@ -455,7 +455,7 @@ impl ComputedVecsFromTxindex { Ok(()) })?; - self.height.safe_flush(exit)?; + self.height.safe_write(exit)?; self.compute_after_height(indexes, starting_indexes, exit) } diff --git a/crates/brk_computer/src/grouped/price_percentiles.rs b/crates/brk_computer/src/grouped/price_percentiles.rs index 2f5af4888..73e5683c7 100644 --- a/crates/brk_computer/src/grouped/price_percentiles.rs +++ b/crates/brk_computer/src/grouped/price_percentiles.rs @@ -95,6 +95,15 @@ impl Flushable for PricePercentiles { } Ok(()) } + + fn safe_write(&mut self, exit: &Exit) -> Result<()> { + for vec in self.vecs.iter_mut().flatten() { + if let Some(height_vec) = vec.height.as_mut() { + height_vec.safe_write(exit)?; + } + } + Ok(()) + } } impl Traversable for PricePercentiles { diff --git a/crates/brk_computer/src/lib.rs b/crates/brk_computer/src/lib.rs index 36613e0f0..0727e43a7 100644 --- a/crates/brk_computer/src/lib.rs +++ b/crates/brk_computer/src/lib.rs @@ -57,12 +57,14 @@ impl Computer { fetcher: Option, ) -> Result { info!("Importing computer..."); + let import_start = Instant::now(); let computed_path = outputs_path.join("computed"); const STACK_SIZE: usize = 512 * 1024 * 1024; let big_thread = || thread::Builder::new().stack_size(STACK_SIZE); + let i = Instant::now(); let (indexes, fetched, blks) = thread::scope(|s| -> Result<_> { let fetched_handle = fetcher .map(|fetcher| { @@ -81,7 +83,9 @@ impl Computer { Ok((indexes, fetched, blks)) })?; + info!("Imported indexes/fetched/blks in {:?}", i.elapsed()); + let i = Instant::now(); let (price, constants, market) = thread::scope(|s| -> Result<_> { let constants_handle = big_thread().spawn_scoped(s, || { constants::Vecs::forced_import(&computed_path, VERSION, &indexes) @@ -100,7 +104,9 @@ impl Computer { Ok((price, constants, market)) })?; + info!("Imported price/constants/market in {:?}", i.elapsed()); + let i = Instant::now(); let (chain, pools, cointime) = thread::scope(|s| -> Result<_> { let chain_handle = big_thread().spawn_scoped(s, || { chain::Vecs::forced_import( @@ -124,10 +130,15 @@ impl Computer { Ok((chain, pools, cointime)) })?; + info!("Imported chain/pools/cointime in {:?}", i.elapsed()); // Threads inside + let i = Instant::now(); let stateful = stateful::Vecs::forced_import(&computed_path, VERSION, &indexes, price.as_ref())?; + info!("Imported stateful in {:?}", i.elapsed()); + + info!("Total import time: {:?}", import_start.elapsed()); Ok(Self { constants, @@ -150,6 +161,7 @@ impl Computer { reader: &Reader, exit: &Exit, ) -> Result<()> { + let compute_start = Instant::now(); info!("Computing indexes..."); let i = Instant::now(); let mut starting_indexes = self.indexes.compute(indexer, starting_indexes, exit)?; @@ -163,12 +175,9 @@ impl Computer { info!("Computing prices..."); let i = Instant::now(); - self.price.um().compute( - &self.indexes, - &starting_indexes, - fetched, - exit, - )?; + self.price + .um() + .compute(&self.indexes, &starting_indexes, fetched, exit)?; info!("Computed prices in {:?}", i.elapsed()); } @@ -231,6 +240,7 @@ impl Computer { info!("Computed pools in {:?}", i.elapsed()); info!("Computing stateful..."); + let i = Instant::now(); self.stateful.compute( indexer, &self.indexes, @@ -239,8 +249,10 @@ impl Computer { &mut starting_indexes, exit, )?; + info!("Computed stateful in {:?}", i.elapsed()); info!("Computing cointime..."); + let i = Instant::now(); self.cointime.compute( &self.indexes, &starting_indexes, @@ -249,7 +261,9 @@ impl Computer { &self.stateful, exit, )?; + info!("Computed cointime in {:?}", i.elapsed()); + info!("Total compute time: {:?}", compute_start.elapsed()); Ok(()) } } diff --git a/crates/brk_computer/src/pools/mod.rs b/crates/brk_computer/src/pools/mod.rs index f642eff08..3a46aa77a 100644 --- a/crates/brk_computer/src/pools/mod.rs +++ b/crates/brk_computer/src/pools/mod.rs @@ -205,7 +205,7 @@ impl Vecs { Ok(()) })?; - self.height_to_pool.safe_flush(exit)?; + self.height_to_pool.safe_write(exit)?; Ok(()) } } diff --git a/crates/brk_computer/src/stateful/address_cohort.rs b/crates/brk_computer/src/stateful/address_cohort.rs index 7c3d12645..5eb4349bd 100644 --- a/crates/brk_computer/src/stateful/address_cohort.rs +++ b/crates/brk_computer/src/stateful/address_cohort.rs @@ -154,7 +154,7 @@ impl DynCohortVecs for Vecs { } fn safe_flush_stateful_vecs(&mut self, height: Height, exit: &Exit) -> Result<()> { - self.height_to_addr_count.safe_flush(exit)?; + self.height_to_addr_count.safe_write(exit)?; self.inner .safe_flush_stateful_vecs(height, exit, &mut self.state.um().inner) diff --git a/crates/brk_computer/src/stateful/address_indexes.rs b/crates/brk_computer/src/stateful/address_indexes.rs index 1206c9f67..fbc6b1cc1 100644 --- a/crates/brk_computer/src/stateful/address_indexes.rs +++ b/crates/brk_computer/src/stateful/address_indexes.rs @@ -1,4 +1,4 @@ -use brk_error::Result; +use brk_error::{Error, Result}; use brk_traversable::Traversable; use brk_types::{ AnyAddressIndex, EmptyAddressData, EmptyAddressIndex, Height, LoadedAddressData, @@ -93,6 +93,48 @@ impl AnyAddressIndexesVecs { } } + pub fn get_anyaddressindex_once( + &self, + address_type: OutputType, + typeindex: TypeIndex, + ) -> Result { + match address_type { + OutputType::P2PK33 => self + .p2pk33 + .read_at_once(typeindex.into()) + .map_err(|e| e.into()), + OutputType::P2PK65 => self + .p2pk65 + .read_at_once(typeindex.into()) + .map_err(|e| e.into()), + OutputType::P2PKH => self + .p2pkh + .read_at_once(typeindex.into()) + .map_err(|e| e.into()), + OutputType::P2SH => self + .p2sh + .read_at_once(typeindex.into()) + .map_err(|e| e.into()), + OutputType::P2TR => self + .p2tr + .read_at_once(typeindex.into()) + .map_err(|e| e.into()), + OutputType::P2WPKH => self + .p2wpkh + .read_at_once(typeindex.into()) + .map_err(|e| e.into()), + OutputType::P2WSH => self + .p2wsh + .read_at_once(typeindex.into()) + .map_err(|e| e.into()), + OutputType::P2A => self + .p2a + .read_at_once(typeindex.into()) + .map_err(|e| e.into()), + _ => Err(Error::UnsupportedType(address_type.to_string())), + } + } + pub fn update_or_push( &mut self, address_type: OutputType, diff --git a/crates/brk_computer/src/stateful/common/push.rs b/crates/brk_computer/src/stateful/common/push.rs index 5324a3b5a..b28b9e3df 100644 --- a/crates/brk_computer/src/stateful/common/push.rs +++ b/crates/brk_computer/src/stateful/common/push.rs @@ -135,40 +135,40 @@ impl Vecs { exit: &Exit, state: &mut CohortState, ) -> Result<()> { - self.height_to_supply.safe_flush(exit)?; - self.height_to_utxo_count.safe_flush(exit)?; - self.height_to_sent.safe_flush(exit)?; - self.height_to_satdays_destroyed.safe_flush(exit)?; - self.height_to_satblocks_destroyed.safe_flush(exit)?; + self.height_to_supply.safe_write(exit)?; + self.height_to_utxo_count.safe_write(exit)?; + self.height_to_sent.safe_write(exit)?; + self.height_to_satdays_destroyed.safe_write(exit)?; + self.height_to_satblocks_destroyed.safe_write(exit)?; if let Some(height_to_realized_cap) = self.height_to_realized_cap.as_mut() { - height_to_realized_cap.safe_flush(exit)?; - self.height_to_realized_profit.um().safe_flush(exit)?; - self.height_to_realized_loss.um().safe_flush(exit)?; - self.height_to_value_created.um().safe_flush(exit)?; - self.height_to_value_destroyed.um().safe_flush(exit)?; - self.height_to_supply_in_profit.um().safe_flush(exit)?; - self.height_to_supply_in_loss.um().safe_flush(exit)?; - self.height_to_unrealized_profit.um().safe_flush(exit)?; - self.height_to_unrealized_loss.um().safe_flush(exit)?; - self.dateindex_to_supply_in_profit.um().safe_flush(exit)?; - self.dateindex_to_supply_in_loss.um().safe_flush(exit)?; - self.dateindex_to_unrealized_profit.um().safe_flush(exit)?; - self.dateindex_to_unrealized_loss.um().safe_flush(exit)?; - self.height_to_min_price_paid.um().safe_flush(exit)?; - self.height_to_max_price_paid.um().safe_flush(exit)?; + height_to_realized_cap.safe_write(exit)?; + self.height_to_realized_profit.um().safe_write(exit)?; + self.height_to_realized_loss.um().safe_write(exit)?; + self.height_to_value_created.um().safe_write(exit)?; + self.height_to_value_destroyed.um().safe_write(exit)?; + self.height_to_supply_in_profit.um().safe_write(exit)?; + self.height_to_supply_in_loss.um().safe_write(exit)?; + self.height_to_unrealized_profit.um().safe_write(exit)?; + self.height_to_unrealized_loss.um().safe_write(exit)?; + self.dateindex_to_supply_in_profit.um().safe_write(exit)?; + self.dateindex_to_supply_in_loss.um().safe_write(exit)?; + self.dateindex_to_unrealized_profit.um().safe_write(exit)?; + self.dateindex_to_unrealized_loss.um().safe_write(exit)?; + self.height_to_min_price_paid.um().safe_write(exit)?; + self.height_to_max_price_paid.um().safe_write(exit)?; if self.height_to_adjusted_value_created.is_some() { self.height_to_adjusted_value_created .um() - .safe_flush(exit)?; + .safe_write(exit)?; self.height_to_adjusted_value_destroyed .um() - .safe_flush(exit)?; + .safe_write(exit)?; } // Uses Flushable trait - Option impl handles None case - self.price_percentiles.safe_flush(exit)?; + self.price_percentiles.safe_write(exit)?; } state.commit(height)?; diff --git a/crates/brk_computer/src/stateful/flushable.rs b/crates/brk_computer/src/stateful/flushable.rs index ded2fd130..449e93f39 100644 --- a/crates/brk_computer/src/stateful/flushable.rs +++ b/crates/brk_computer/src/stateful/flushable.rs @@ -14,6 +14,9 @@ use vecdb::Exit; pub trait Flushable { /// Safely flush data to disk. fn safe_flush(&mut self, exit: &Exit) -> Result<()>; + + /// Write to mmap without fsync. Data visible to readers immediately but not durable. + fn safe_write(&mut self, exit: &Exit) -> Result<()>; } /// Trait for stateful components that track data indexed by height. @@ -42,6 +45,13 @@ impl Flushable for Option { } Ok(()) } + + fn safe_write(&mut self, exit: &Exit) -> Result<()> { + if let Some(inner) = self.as_mut() { + inner.safe_write(exit)?; + } + Ok(()) + } } /// Blanket implementation for Option where T: HeightFlushable diff --git a/crates/brk_computer/src/stateful/mod.rs b/crates/brk_computer/src/stateful/mod.rs index 2118c65c8..6b086a985 100644 --- a/crates/brk_computer/src/stateful/mod.rs +++ b/crates/brk_computer/src/stateful/mod.rs @@ -1473,8 +1473,8 @@ impl Vecs { self.utxo_cohorts.safe_flush_stateful_vecs(height, exit)?; self.address_cohorts .safe_flush_stateful_vecs(height, exit)?; - self.height_to_unspendable_supply.safe_flush(exit)?; - self.height_to_opreturn_supply.safe_flush(exit)?; + self.height_to_unspendable_supply.safe_write(exit)?; + self.height_to_opreturn_supply.safe_write(exit)?; self.addresstype_to_height_to_addr_count .values_mut() .try_for_each(|v| v.safe_flush(exit))?; diff --git a/crates/brk_computer/src/stateful/utxo_cohorts.rs b/crates/brk_computer/src/stateful/utxo_cohorts.rs index caf758cfc..2a63d2fcf 100644 --- a/crates/brk_computer/src/stateful/utxo_cohorts.rs +++ b/crates/brk_computer/src/stateful/utxo_cohorts.rs @@ -617,7 +617,7 @@ impl Vecs { // Using traits ensures we can't forget to flush any field self.0.par_iter_aggregate_mut().try_for_each(|v| { v.price_to_amount.flush_at_height(height, exit)?; - v.inner.price_percentiles.safe_flush(exit)?; + v.inner.price_percentiles.safe_write(exit)?; Ok(()) }) } diff --git a/crates/brk_computer/src/traits.rs b/crates/brk_computer/src/traits.rs index 14ab37430..2ebebb863 100644 --- a/crates/brk_computer/src/traits.rs +++ b/crates/brk_computer/src/traits.rs @@ -74,7 +74,7 @@ impl ComputeDCAStackViaLen for EagerVec> { self.truncate_push_at(i, stack) })?; - self.safe_flush(exit)?; + self.safe_write(exit)?; Ok(()) } @@ -118,7 +118,7 @@ impl ComputeDCAStackViaLen for EagerVec> { self.truncate_push_at(i, stack) })?; - self.safe_flush(exit)?; + self.safe_write(exit)?; Ok(()) } @@ -176,7 +176,7 @@ impl ComputeDCAAveragePriceViaLen for EagerVec> { self.truncate_push_at(i, avg_price) })?; - self.safe_flush(exit)?; + self.safe_write(exit)?; Ok(()) } @@ -208,7 +208,7 @@ impl ComputeDCAAveragePriceViaLen for EagerVec> { self.truncate_push_at(i, avg_price) })?; - self.safe_flush(exit)?; + self.safe_write(exit)?; Ok(()) } diff --git a/crates/brk_monitor/examples/mempool.rs b/crates/brk_monitor/examples/mempool.rs index 77ef5742c..4eb3abe48 100644 --- a/crates/brk_monitor/examples/mempool.rs +++ b/crates/brk_monitor/examples/mempool.rs @@ -14,7 +14,7 @@ fn main() -> Result<()> { Auth::CookieFile(bitcoin_dir.join(".cookie")), )?; - let mempool = Mempool::new(client); + let mempool = Mempool::new(&client); let mempool_clone = mempool.clone(); thread::spawn(move || { diff --git a/crates/brk_monitor/src/lib.rs b/crates/brk_monitor/src/lib.rs index 9149818c0..925f184d2 100644 --- a/crates/brk_monitor/src/lib.rs +++ b/crates/brk_monitor/src/lib.rs @@ -19,8 +19,8 @@ const MAX_FETCHES_PER_CYCLE: usize = 10_000; pub struct Mempool(Arc); impl Mempool { - pub fn new(client: Client) -> Self { - Self(Arc::new(MempoolInner::new(client))) + pub fn new(client: &Client) -> Self { + Self(Arc::new(MempoolInner::new(client.clone()))) } } diff --git a/crates/brk_query/Cargo.toml b/crates/brk_query/Cargo.toml index 0cd296157..609f5a2ce 100644 --- a/crates/brk_query/Cargo.toml +++ b/crates/brk_query/Cargo.toml @@ -16,6 +16,7 @@ bitcoin = { workspace = true } brk_computer = { workspace = true } brk_error = { workspace = true } brk_indexer = { workspace = true } +brk_monitor = { workspace = true } brk_reader = { workspace = true } brk_rpc = { workspace = true } brk_traversable = { workspace = true } diff --git a/crates/brk_query/examples/main.rs b/crates/brk_query/examples/main.rs index aadefc815..ffdf86f3f 100644 --- a/crates/brk_query/examples/main.rs +++ b/crates/brk_query/examples/main.rs @@ -36,7 +36,7 @@ pub fn main() -> Result<()> { let computer = Computer::forced_import(&outputs_dir, &indexer, None)?; - let query = Query::build(&reader, &indexer, &computer); + let query = Query::build(&reader, &indexer, &computer, None); dbg!(query.search_and_format(Params { index: Index::Height, diff --git a/crates/brk_query/src/async.rs b/crates/brk_query/src/async.rs index 680d84628..8fe1f8b75 100644 --- a/crates/brk_query/src/async.rs +++ b/crates/brk_query/src/async.rs @@ -3,6 +3,7 @@ use std::collections::BTreeMap; use brk_computer::Computer; use brk_error::Result; use brk_indexer::Indexer; +use brk_monitor::Mempool; use brk_reader::Reader; use brk_types::{ Address, AddressStats, Height, Index, IndexInfo, Limit, Metric, MetricCount, Transaction, @@ -21,8 +22,13 @@ use crate::{ pub struct AsyncQuery(Query); impl AsyncQuery { - pub fn build(reader: &Reader, indexer: &Indexer, computer: &Computer) -> Self { - Self(Query::build(reader, indexer, computer)) + pub fn build( + reader: &Reader, + indexer: &Indexer, + computer: &Computer, + mempool: Option, + ) -> Self { + Self(Query::build(reader, indexer, computer, mempool)) } pub fn inner(&self) -> &Query { diff --git a/crates/brk_query/src/chain/addresses.rs b/crates/brk_query/src/chain/addresses.rs index 74a5157e8..3a2157b8e 100644 --- a/crates/brk_query/src/chain/addresses.rs +++ b/crates/brk_query/src/chain/addresses.rs @@ -3,10 +3,10 @@ use std::str::FromStr; use bitcoin::{Network, PublicKey, ScriptBuf}; use brk_error::{Error, Result}; use brk_types::{ - Address, AddressBytes, AddressChainStats, AddressHash, AddressMempoolStats, AddressStats, - AnyAddressDataIndexEnum, OutputType, + Address, AddressBytes, AddressChainStats, AddressHash, AddressStats, AnyAddressDataIndexEnum, + OutputType, }; -use vecdb::{IterableVec, TypedVecIterator}; +use vecdb::TypedVecIterator; use crate::Query; @@ -44,68 +44,20 @@ pub fn get_address(Address { address }: Address, query: &Query) -> Result stateful - .any_address_indexes - .p2pk33 - .iter()? - .get_unwrap(type_index.into()), - OutputType::P2PK65 => stateful - .any_address_indexes - .p2pk65 - .iter()? - .get_unwrap(type_index.into()), - OutputType::P2PKH => stateful - .any_address_indexes - .p2pkh - .iter()? - .get_unwrap(type_index.into()), - OutputType::P2SH => stateful - .any_address_indexes - .p2sh - .iter()? - .get_unwrap(type_index.into()), - OutputType::P2TR => stateful - .any_address_indexes - .p2tr - .iter()? - .get_unwrap(type_index.into()), - OutputType::P2WPKH => stateful - .any_address_indexes - .p2wpkh - .iter()? - .get_unwrap(type_index.into()), - OutputType::P2WSH => stateful - .any_address_indexes - .p2wsh - .iter()? - .get_unwrap(type_index.into()), - OutputType::P2A => stateful - .any_address_indexes - .p2a - .iter()? - .get_unwrap(type_index.into()), - t => { - return Err(Error::UnsupportedType(t.to_string())); - } - }; + let any_address_index = computer + .stateful + .any_address_indexes + .get_anyaddressindex_once(outputtype, type_index)?; let address_data = match any_address_index.to_enum() { - AnyAddressDataIndexEnum::Loaded(index) => { - stateful.addresses_data.loaded.iter()?.get_unwrap(index) - } - AnyAddressDataIndexEnum::Empty(index) => stateful + AnyAddressDataIndexEnum::Loaded(index) => computer + .stateful + .addresses_data + .loaded + .iter()? + .get_unwrap(index), + AnyAddressDataIndexEnum::Empty(index) => computer + .stateful .addresses_data .empty .iter()? @@ -115,20 +67,19 @@ pub fn get_address(Address { address }: Address, query: &Query) -> Result { reader: Reader, indexer: &'a Indexer, computer: &'a Computer, + mempool: Option, } impl Query { - pub fn build(reader: &Reader, indexer: &Indexer, computer: &Computer) -> Self { + pub fn build( + reader: &Reader, + indexer: &Indexer, + computer: &Computer, + mempool: Option, + ) -> Self { let reader = reader.clone(); let indexer = Box::leak(Box::new(indexer.clone())); let computer = Box::leak(Box::new(computer.clone())); @@ -53,6 +60,7 @@ impl Query { reader, indexer, computer, + mempool, })) } @@ -274,6 +282,11 @@ impl Query { self.0.computer } + #[inline] + pub fn mempool(&self) -> Option<&Mempool> { + self.0.mempool.as_ref() + } + #[inline] pub fn vecs(&self) -> &'static Vecs<'static> { self.0.vecs diff --git a/crates/brk_query/src/vecs.rs b/crates/brk_query/src/vecs.rs index 2ebb3c524..281a6ec0a 100644 --- a/crates/brk_query/src/vecs.rs +++ b/crates/brk_query/src/vecs.rs @@ -110,6 +110,7 @@ impl<'a> Vecs<'a> { // Not the most performant or type safe but only built once so that's okay fn insert(&mut self, vec: &'a dyn AnyExportableVec) { let name = vec.name(); + dbg!(vec.region_name()); let serialized_index = vec.index_type_to_string(); let index = Index::try_from(serialized_index) .inspect_err(|_| { diff --git a/crates/brk_server/examples/main.rs b/crates/brk_server/examples/main.rs index f7cf1a6aa..220f3a110 100644 --- a/crates/brk_server/examples/main.rs +++ b/crates/brk_server/examples/main.rs @@ -53,7 +53,7 @@ fn run() -> Result<()> { let exit = Exit::new(); exit.set_ctrlc_handler(); - let query = AsyncQuery::build(&reader, &indexer, &computer); + let query = AsyncQuery::build(&reader, &indexer, &computer, None); let future = async move { let server = Server::new(&query, None); diff --git a/crates/brk_types/src/addresschainstats.rs b/crates/brk_types/src/addresschainstats.rs index 33f0aca2b..4f2199d06 100644 --- a/crates/brk_types/src/addresschainstats.rs +++ b/crates/brk_types/src/addresschainstats.rs @@ -9,7 +9,7 @@ use serde::Serialize; pub struct AddressChainStats { /// Total number of transaction outputs that funded this address #[schemars(example = 5)] - pub funded_txo_count: u64, + pub funded_txo_count: u32, /// Total amount in satoshis received by this address across all funded outputs #[schemars(example = Sats::new(15007599040))] @@ -17,7 +17,7 @@ pub struct AddressChainStats { /// Total number of transaction outputs spent from this address #[schemars(example = 5)] - pub spent_txo_count: u64, + pub spent_txo_count: u32, /// Total amount in satoshis spent from this address #[schemars(example = Sats::new(15007599040))] @@ -25,7 +25,7 @@ pub struct AddressChainStats { /// Total number of confirmed transactions involving this address #[schemars(example = 10)] - pub tx_count: Option, + pub tx_count: u32, /// Index of this address within its type on the blockchain #[schemars(example = TypeIndex::new(0))] diff --git a/crates/brk_types/src/addressmempoolstats.rs b/crates/brk_types/src/addressmempoolstats.rs index 90cb1f70f..d35ea21ab 100644 --- a/crates/brk_types/src/addressmempoolstats.rs +++ b/crates/brk_types/src/addressmempoolstats.rs @@ -7,7 +7,7 @@ use serde::Serialize; /// /// Based on mempool.space's format. /// -#[derive(Debug, Default, Serialize, JsonSchema)] +#[derive(Debug, Default, Clone, Serialize, JsonSchema)] pub struct AddressMempoolStats { /// Number of unconfirmed transaction outputs funding this address #[schemars(example = 0)] diff --git a/crates/brk_types/src/addressstats.rs b/crates/brk_types/src/addressstats.rs index afa9fe163..5a000ee9b 100644 --- a/crates/brk_types/src/addressstats.rs +++ b/crates/brk_types/src/addressstats.rs @@ -15,5 +15,5 @@ pub struct AddressStats { pub chain_stats: AddressChainStats, /// Statistics for unconfirmed transactions in the mempool - pub mempool_stats: AddressMempoolStats, + pub mempool_stats: Option, }