From cf08e470ef7a4b07471a26f33914bf34110f5ec2 Mon Sep 17 00:00:00 2001 From: nym21 Date: Fri, 31 Oct 2025 21:37:02 +0100 Subject: [PATCH] global: snapshot --- Cargo.lock | 249 ++++++++---------- crates/brk_cli/Cargo.toml | 2 +- crates/brk_computer/Cargo.toml | 1 + crates/brk_computer/src/chain.rs | 106 ++++---- crates/brk_computer/src/fetched.rs | 4 +- .../brk_computer/src/grouped/builder_eager.rs | 18 +- .../brk_computer/src/grouped/builder_lazy.rs | 17 +- .../src/grouped/ratio_from_dateindex.rs | 1 - .../src/grouped/sd_from_dateindex.rs | 1 - crates/brk_computer/src/grouped/source.rs | 3 + .../src/grouped/value_from_txindex.rs | 14 +- crates/brk_computer/src/indexes.rs | 10 +- crates/brk_computer/src/price.rs | 62 ++--- .../src/stateful/addresstype/addresscount.rs | 1 + .../addresstype/height_to_addresscount.rs | 1 + .../addresstype/indexes_to_addresscount.rs | 1 + .../src/stateful/addresstype/typeindex_map.rs | 23 ++ crates/brk_computer/src/stateful/mod.rs | 184 ++++++++----- crates/brk_computer/src/stateful/range_map.rs | 6 +- .../src/stateful/withaddressdatasource.rs | 2 + crates/brk_computer/src/states/supply.rs | 1 + crates/brk_computer/src/traits.rs | 11 +- crates/brk_error/src/lib.rs | 20 +- crates/brk_grouper/src/address.rs | 1 + crates/brk_grouper/src/by_address_type.rs | 1 + crates/brk_grouper/src/by_age_range.rs | 1 + crates/brk_grouper/src/by_amount_range.rs | 1 + crates/brk_grouper/src/by_epoch.rs | 1 + crates/brk_grouper/src/by_ge_amount.rs | 1 + crates/brk_grouper/src/by_lt_amount.rs | 1 + crates/brk_grouper/src/by_max_age.rs | 1 + crates/brk_grouper/src/by_min_age.rs | 1 + crates/brk_grouper/src/by_spendable_type.rs | 1 + crates/brk_grouper/src/by_term.rs | 1 + crates/brk_grouper/src/filter.rs | 1 + crates/brk_grouper/src/utxo.rs | 1 + crates/brk_indexer/BENCH.md | 8 +- crates/brk_indexer/examples/indexer_read.rs | 25 ++ .../examples/indexer_read_speed.rs | 102 +++++++ .../examples/indexer_single_vs_multi.rs | 24 +- crates/brk_indexer/src/indexes.rs | 1 + crates/brk_indexer/src/lib.rs | 28 +- crates/brk_indexer/src/stores_v2.rs | 79 ++---- crates/brk_query/src/params.rs | 4 +- crates/brk_reader/src/xor_bytes.rs | 1 + crates/brk_store/src/v2/mod.rs | 1 + crates/brk_types/src/address.rs | 1 + crates/brk_types/src/addressbytes.rs | 8 + crates/brk_types/src/addressbyteshash.rs | 4 + crates/brk_types/src/anyaddressindex.rs | 3 + crates/brk_types/src/bitcoin.rs | 5 + crates/brk_types/src/block.rs | 3 + crates/brk_types/src/blockhash.rs | 5 + crates/brk_types/src/blockhashprefix.rs | 5 + crates/brk_types/src/bytes.rs | 5 + crates/brk_types/src/cents.rs | 10 + crates/brk_types/src/date.rs | 5 + crates/brk_types/src/dateindex.rs | 4 + crates/brk_types/src/decadeindex.rs | 7 + crates/brk_types/src/difficultyepoch.rs | 4 + crates/brk_types/src/dollars.rs | 14 + crates/brk_types/src/emptyaddressdata.rs | 2 + crates/brk_types/src/emptyaddressindex.rs | 4 + crates/brk_types/src/emptyoutputindex.rs | 4 + crates/brk_types/src/feerate.rs | 4 + crates/brk_types/src/format.rs | 1 + crates/brk_types/src/halvingepoch.rs | 4 + crates/brk_types/src/height.rs | 12 + crates/brk_types/src/loadedaddressdata.rs | 2 + crates/brk_types/src/loadedaddressindex.rs | 4 + crates/brk_types/src/metric.rs | 2 + crates/brk_types/src/metrics.rs | 3 + crates/brk_types/src/monthindex.rs | 7 + crates/brk_types/src/ohlc.rs | 36 ++- crates/brk_types/src/opreturnindex.rs | 4 + crates/brk_types/src/outputtype.rs | 2 + crates/brk_types/src/p2aaddressindex.rs | 7 + crates/brk_types/src/p2abytes.rs | 2 + crates/brk_types/src/p2msoutputindex.rs | 4 + crates/brk_types/src/p2pk33addressindex.rs | 7 + crates/brk_types/src/p2pk33bytes.rs | 2 + crates/brk_types/src/p2pk65addressindex.rs | 7 + crates/brk_types/src/p2pk65bytes.rs | 2 + crates/brk_types/src/p2pkhaddressindex.rs | 7 + crates/brk_types/src/p2pkhbytes.rs | 2 + crates/brk_types/src/p2shaddressindex.rs | 8 + crates/brk_types/src/p2shbytes.rs | 2 + crates/brk_types/src/p2traddressindex.rs | 7 + crates/brk_types/src/p2trbytes.rs | 2 + crates/brk_types/src/p2wpkhaddressindex.rs | 7 + crates/brk_types/src/p2wpkhbytes.rs | 2 + crates/brk_types/src/p2wshaddressindex.rs | 7 + crates/brk_types/src/p2wshbytes.rs | 2 + crates/brk_types/src/pool.rs | 1 + crates/brk_types/src/pools.rs | 1 + crates/brk_types/src/quarterindex.rs | 5 + crates/brk_types/src/rawlocktime.rs | 2 + crates/brk_types/src/sats.rs | 20 ++ crates/brk_types/src/semesterindex.rs | 5 + crates/brk_types/src/stored_bool.rs | 2 + crates/brk_types/src/stored_f32.rs | 9 + crates/brk_types/src/stored_f64.rs | 7 + crates/brk_types/src/stored_i16.rs | 5 + crates/brk_types/src/stored_string.rs | 5 + crates/brk_types/src/stored_u16.rs | 17 ++ crates/brk_types/src/stored_u32.rs | 18 ++ crates/brk_types/src/stored_u64.rs | 31 ++- crates/brk_types/src/stored_u8.rs | 5 + crates/brk_types/src/timestamp.rs | 8 + crates/brk_types/src/txid.rs | 5 + crates/brk_types/src/txidprefix.rs | 6 + crates/brk_types/src/txindex.rs | 10 + crates/brk_types/src/txinindex.rs | 5 + crates/brk_types/src/txout.rs | 2 + crates/brk_types/src/txoutindex.rs | 6 + crates/brk_types/src/txversion.rs | 3 + crates/brk_types/src/typeindex.rs | 9 + crates/brk_types/src/typeindexandoutpoint.rs | 4 + crates/brk_types/src/typeindexandtxindex.rs | 6 + crates/brk_types/src/unit.rs | 2 + crates/brk_types/src/unknownoutputindex.rs | 4 + crates/brk_types/src/vin.rs | 3 + crates/brk_types/src/vout.rs | 7 + crates/brk_types/src/weekindex.rs | 6 + crates/brk_types/src/weight.rs | 5 + crates/brk_types/src/yearindex.rs | 8 + docs/TODO.md | 2 +- 127 files changed, 1059 insertions(+), 450 deletions(-) create mode 100644 crates/brk_indexer/examples/indexer_read.rs create mode 100644 crates/brk_indexer/examples/indexer_read_speed.rs diff --git a/Cargo.lock b/Cargo.lock index 8c2ef27cd..e3a412ae2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -32,9 +32,9 @@ dependencies = [ [[package]] name = "aho-corasick" -version = "1.1.3" +version = "1.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916" +checksum = "ddd31a130427c27518df266943a5308ed92d4b226cc639f5a8f1002816174301" dependencies = [ "memchr", ] @@ -494,6 +494,15 @@ dependencies = [ "generic-array", ] +[[package]] +name = "block2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" +dependencies = [ + "objc2", +] + [[package]] name = "brk" version = "0.0.111" @@ -655,6 +664,7 @@ dependencies = [ "rayon", "rustc-hash", "serde", + "smallvec", "vecdb", "zerocopy", ] @@ -1428,9 +1438,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.42" +version = "1.2.44" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81bbf3b3619004ad9bd139f62a9ab5cfe467f307455a0d307b0cf58bf070feaa" +checksum = "37521ac7aabe3d13122dc382493e20c9416f299d2ccd5b3a5340a2570cdeb0f3" dependencies = [ "find-msvc-tools", "jobserver", @@ -1477,9 +1487,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.50" +version = "4.5.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c2cfd7bf8a6017ddaa4e32ffe7403d547790db06bd171c1c53926faab501623" +checksum = "4c26d721170e0295f191a69bd9a1f93efcdb0aff38684b61ab5750468972e5f5" dependencies = [ "clap_builder", "clap_derive", @@ -1487,9 +1497,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.50" +version = "4.5.51" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0a4c05b9e80c5ccd3a7ef080ad7b6ba7d6fc00a985b8b157197075677c82c7a0" +checksum = "75835f0c7bf681bfd05abe44e965760fea999a5286c6eb2d59883634fd02011a" dependencies = [ "anstream", "anstyle", @@ -1746,11 +1756,11 @@ dependencies = [ [[package]] name = "ctrlc" -version = "3.5.0" +version = "3.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "881c5d0a13b2f1498e2306e82cbada78390e152d4b1378fb28a84f4dcd0dc4f3" +checksum = "73736a89c4aff73035ba2ed2e565061954da00d4970fc9ac25dcc85a2a20d790" dependencies = [ - "dispatch", + "dispatch2", "nix", "windows-sys 0.61.2", ] @@ -1834,9 +1844,9 @@ dependencies = [ [[package]] name = "deranged" -version = "0.5.4" +version = "0.5.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a41953f86f8a05768a6cda24def994fd2f424b04ec5c719cf89989779f199071" +checksum = "ececcb659e7ba858fb4f10388c250a7252eb0a27373f1a72b8748afdd248e587" dependencies = [ "powerfmt", ] @@ -1895,32 +1905,17 @@ dependencies = [ ] [[package]] -name = "dirs" -version = "6.0.0" +name = "dispatch2" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c3e8aa94d75141228480295a7d0e7feb620b1a5ad9f12bc40be62411e38cce4e" -dependencies = [ - "dirs-sys", -] - -[[package]] -name = "dirs-sys" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +checksum = "89a09f22a6c6069a18470eb92d2298acf25463f14256d24778e1230d789a2aec" dependencies = [ + "bitflags 2.10.0", + "block2", "libc", - "option-ext", - "redox_users", - "windows-sys 0.61.2", + "objc2", ] -[[package]] -name = "dispatch" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b" - [[package]] name = "displaydoc" version = "0.2.5" @@ -1970,9 +1965,9 @@ checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" [[package]] name = "endian-type" -version = "0.1.2" +version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" +checksum = "869b0adbda23651a9c5c0c3d270aac9fcb52e8622a8f2b17e57802d7791962f2" [[package]] name = "enum_dispatch" @@ -2120,6 +2115,12 @@ version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + [[package]] name = "form_urlencoded" version = "1.2.2" @@ -2305,9 +2306,7 @@ version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" dependencies = [ - "allocator-api2", - "equivalent", - "foldhash", + "foldhash 0.1.5", ] [[package]] @@ -2317,6 +2316,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5419bdc4f6a9207fbeba6d11b604d481addf78ecd10c11ad51e76c2f6482748d" dependencies = [ "allocator-api2", + "equivalent", + "foldhash 0.2.0", ] [[package]] @@ -2449,9 +2450,9 @@ dependencies = [ [[package]] name = "icu_collections" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "200072f5d0e3614556f94a9930d5dc3e0662a652823904c3a75dc3b0af7fee47" +checksum = "4c6b649701667bbe825c3b7e6388cb521c23d88644678e83c0c4d0a621a34b43" dependencies = [ "displaydoc", "potential_utf", @@ -2462,9 +2463,9 @@ dependencies = [ [[package]] name = "icu_locale_core" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cde2700ccaed3872079a65fb1a78f6c0a36c91570f28755dda67bc8f7d9f00a" +checksum = "edba7861004dd3714265b4db54a3c390e880ab658fec5f7db895fae2046b5bb6" dependencies = [ "displaydoc", "litemap", @@ -2475,11 +2476,10 @@ dependencies = [ [[package]] name = "icu_normalizer" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "436880e8e18df4d7bbc06d58432329d6458cc84531f7ac5f024e93deadb37979" +checksum = "5f6c8828b67bf8908d82127b2054ea1b4427ff0230ee9141c54251934ab1b599" dependencies = [ - "displaydoc", "icu_collections", "icu_normalizer_data", "icu_properties", @@ -2490,42 +2490,38 @@ dependencies = [ [[package]] name = "icu_normalizer_data" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00210d6893afc98edb752b664b8890f0ef174c8adbb8d0be9710fa66fbbf72d3" +checksum = "7aedcccd01fc5fe81e6b489c15b247b8b0690feb23304303a9e560f37efc560a" [[package]] name = "icu_properties" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "016c619c1eeb94efb86809b015c58f479963de65bdb6253345c1a1276f22e32b" +checksum = "e93fcd3157766c0c8da2f8cff6ce651a31f0810eaa1c51ec363ef790bbb5fb99" dependencies = [ - "displaydoc", "icu_collections", "icu_locale_core", "icu_properties_data", "icu_provider", - "potential_utf", "zerotrie", "zerovec", ] [[package]] name = "icu_properties_data" -version = "2.0.1" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "298459143998310acd25ffe6810ed544932242d3f07083eee1084d83a71bd632" +checksum = "02845b3647bb045f1100ecd6480ff52f34c35f82d9880e029d329c21d1054899" [[package]] name = "icu_provider" -version = "2.0.0" +version = "2.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03c80da27b5f4187909049ee2d72f276f0d9f99a42c306bd0131ecfe04d8e5af" +checksum = "85962cf0ce02e1e0a629cc34e7ca3e373ce20dda4c4d7294bbd0bf1fdb59e614" dependencies = [ "displaydoc", "icu_locale_core", - "stable_deref_trait", - "tinystr", "writeable", "yoke", "zerofrom", @@ -2699,9 +2695,9 @@ dependencies = [ [[package]] name = "js-sys" -version = "0.3.81" +version = "0.3.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec48937a97411dcb524a265206ccd4c90bb711fca92b2792c407f268825b9305" +checksum = "b011eec8cc36da2aab2d5cff675ec18454fad408585853910a202391cf9f8e65" dependencies = [ "once_cell", "wasm-bindgen", @@ -2797,9 +2793,9 @@ checksum = "df1d3c3b53da64cf5760482273a98e575c651a67eec7f77df96b5b642de8f039" [[package]] name = "litemap" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "241eaef5fd12c88705a01fc1066c48c4b36e0dd4377dcdc7ec3942cea7a69956" +checksum = "6373607a59f0be73a39b6fe456b8192fcc3585f602af20751600e974dd455e77" [[package]] name = "lock_api" @@ -3085,6 +3081,21 @@ dependencies = [ "syn 2.0.108", ] +[[package]] +name = "objc2" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c2599ce0ec54857b29ce62166b0ed9b4f6f1a70ccc9a71165b6154caca8c05" +dependencies = [ + "objc2-encode", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + [[package]] name = "object" version = "0.37.3" @@ -3106,12 +3117,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "option-ext" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" - [[package]] name = "outref" version = "0.5.2" @@ -3166,9 +3171,9 @@ dependencies = [ [[package]] name = "oxc-miette" -version = "2.5.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5c42cefdcbebec6b0b72229ac0e02261a6770cb7ba39ccc5475a856164066db1" +checksum = "f02105a875f3751a0b44b4c822b01177728dd9049ae6fb419e9b04887d730ed1" dependencies = [ "cfg-if", "owo-colors", @@ -3181,9 +3186,9 @@ dependencies = [ [[package]] name = "oxc-miette-derive" -version = "2.5.1" +version = "2.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05bbaa5b6b98826bb62b164406f703bee72c5287af9986f9c863fa8ea992b476" +checksum = "003b4612827f6501183873fb0735da92157e3c7daa71c40921c7d2758fec2229" dependencies = [ "proc-macro2", "quote", @@ -3813,13 +3818,12 @@ checksum = "7edddbd0b52d732b21ad9a5fab5c704c14cd949e5e9a1ec5929a24fded1b904c" [[package]] name = "pnp" -version = "0.12.3" +version = "0.12.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a10a726fb86dab6571b148c0f52cf619a4aabf0ac4fcf578bd4cd2178fb0e6d0" +checksum = "7adbc1ab7344e1e77be663e91cb129e989e398c319df7a9b8dbda9dd6758df38" dependencies = [ "byteorder", "concurrent_lru", - "dirs", "fancy-regex", "miniz_oxide", "pathdiff", @@ -3847,9 +3851,9 @@ dependencies = [ [[package]] name = "potential_utf" -version = "0.1.3" +version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84df19adbe5b5a0782edcab45899906947ab039ccf4573713735ee7de1e6b08a" +checksum = "b73949432f5e2a09657003c25bca5e19a0e9c84f8058ca374f49e0ebe605af77" dependencies = [ "zerovec", ] @@ -3962,9 +3966,9 @@ checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" [[package]] name = "radix_trie" -version = "0.2.1" +version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +checksum = "3b4431027dcd37fc2a73ef740b5f233aa805897935b8bce0195e41bbf9a3289a" dependencies = [ "endian-type", "nibble_vec", @@ -4094,17 +4098,6 @@ dependencies = [ "bitflags 2.10.0", ] -[[package]] -name = "redox_users" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a4e608c6638b9c18977b00b475ac1f28d14e84b27d8d42f70e0bf1e3dec127ac" -dependencies = [ - "getrandom 0.2.16", - "libredox", - "thiserror 2.0.17", -] - [[package]] name = "ref-cast" version = "1.0.25" @@ -4156,11 +4149,11 @@ checksum = "7a2d987857b319362043e95f5353c0535c1f58eec5336fdfcf626430af7def58" [[package]] name = "regress" -version = "0.10.4" +version = "0.10.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "145bb27393fe455dd64d6cbc8d059adfa392590a45eadf079c01b11857e7b010" +checksum = "2057b2325e68a893284d1538021ab90279adac1139957ca2a74426c6f118fb48" dependencies = [ - "hashbrown 0.15.5", + "hashbrown 0.16.0", "memchr", ] @@ -4393,7 +4386,6 @@ version = "0.2.17" dependencies = [ "allocative", "libc", - "log", "memmap2", "parking_lot 0.12.5", "rayon", @@ -4851,9 +4843,9 @@ checksum = "40868e7c1d2f0b8d73e4a8c7f0ff63af4f6d19be117e90bd73eb1d62cf831c6b" [[package]] name = "tinystr" -version = "0.8.1" +version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d4f6d1145dcb577acf783d4e601bc1d76a13337bb54e6233add580b07344c8b" +checksum = "42d3e9c45c09de15d06dd8acf5f4e0e399e85927b7f00711024eb7ae10fa4869" dependencies = [ "displaydoc", "zerovec", @@ -5160,9 +5152,9 @@ checksum = "81b79ad29b5e19de4260020f8919b443b2ef0277d242ce532ec7b7a2cc8b6007" [[package]] name = "unicode-ident" -version = "1.0.20" +version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "462eeb75aeb73aea900253ce739c8e18a67423fadf006037cd3ff27e82748a06" +checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" [[package]] name = "unicode-linebreak" @@ -5350,9 +5342,9 @@ dependencies = [ [[package]] name = "wasm-bindgen" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1da10c01ae9f1ae40cbfac0bac3b1e724b320abfcf52229f80b547c0d250e2d" +checksum = "da95793dfc411fbbd93f5be7715b0578ec61fe87cb1a42b12eb625caa5c5ea60" dependencies = [ "cfg-if", "once_cell", @@ -5361,25 +5353,11 @@ dependencies = [ "wasm-bindgen-shared", ] -[[package]] -name = "wasm-bindgen-backend" -version = "0.2.104" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "671c9a5a66f49d8a47345ab942e2cb93c7d1d0339065d4f8139c486121b43b19" -dependencies = [ - "bumpalo", - "log", - "proc-macro2", - "quote", - "syn 2.0.108", - "wasm-bindgen-shared", -] - [[package]] name = "wasm-bindgen-macro" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ca60477e4c59f5f2986c50191cd972e3a50d8a95603bc9434501cf156a9a119" +checksum = "04264334509e04a7bf8690f2384ef5265f05143a4bff3889ab7a3269adab59c2" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -5387,22 +5365,22 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9f07d2f20d4da7b26400c9f4a0511e6e0345b040694e8a75bd41d578fa4421d7" +checksum = "420bc339d9f322e562942d52e115d57e950d12d88983a14c79b86859ee6c7ebc" dependencies = [ + "bumpalo", "proc-macro2", "quote", "syn 2.0.108", - "wasm-bindgen-backend", "wasm-bindgen-shared", ] [[package]] name = "wasm-bindgen-shared" -version = "0.2.104" +version = "0.2.105" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bad67dc8b2a1a6e5448428adec4c3e84c43e561d8c9ee8a9e5aabeb193ec41d1" +checksum = "76f218a38c84bcb33c25ec7059b07847d465ce0e0a76b995e134a45adcb6af76" dependencies = [ "unicode-ident", ] @@ -5736,9 +5714,9 @@ checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" [[package]] name = "writeable" -version = "0.6.1" +version = "0.6.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea2f10b9bb0928dfb1b42b65e1f9e36f7f54dbdf08457afefb38afcdec4fa2bb" +checksum = "9edde0db4769d2dc68579893f2306b26c6ecfbe0ef499b013d731b7b9247e0b9" [[package]] name = "xxhash-rust" @@ -5754,11 +5732,10 @@ checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" [[package]] name = "yoke" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f41bb01b8226ef4bfd589436a297c53d118f65921786300e427be8d487695cc" +checksum = "72d6e5c6afb84d73944e5cedb052c4680d5657337201555f9f2a16b7406d4954" dependencies = [ - "serde", "stable_deref_trait", "yoke-derive", "zerofrom", @@ -5766,9 +5743,9 @@ dependencies = [ [[package]] name = "yoke-derive" -version = "0.8.0" +version = "0.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38da3c9736e16c5d3c8c597a9aaa5d1fa565d0532ae05e27c24aa62fb32c0ab6" +checksum = "b659052874eb698efe5b9e8cf382204678a0086ebf46982b79d6ca3182927e5d" dependencies = [ "proc-macro2", "quote", @@ -5819,9 +5796,9 @@ dependencies = [ [[package]] name = "zerotrie" -version = "0.2.2" +version = "0.2.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36f0bbd478583f79edad978b407914f61b2972f5af6fa089686016be8f9af595" +checksum = "2a59c17a5562d507e4b54960e8569ebee33bee890c70aa3fe7b97e85a9fd7851" dependencies = [ "displaydoc", "yoke", @@ -5830,9 +5807,9 @@ dependencies = [ [[package]] name = "zerovec" -version = "0.11.4" +version = "0.11.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e7aa2bd55086f1ab526693ecbe444205da57e25f4489879da80635a46d90e73b" +checksum = "6c28719294829477f525be0186d13efa9a3c602f7ec202ca9e353d310fb9a002" dependencies = [ "yoke", "zerofrom", @@ -5841,9 +5818,9 @@ dependencies = [ [[package]] name = "zerovec-derive" -version = "0.11.1" +version = "0.11.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b96237efa0c878c64bd89c436f661be4e46b2f3eff1ebb976f7ef2321d2f58f" +checksum = "eadce39539ca5cb3985590102671f2567e659fca9666581ad3411d59207951f3" dependencies = [ "proc-macro2", "quote", @@ -5872,9 +5849,9 @@ checksum = "2f06ae92f42f5e5c42443fd094f245eb656abf56dd7cce9b8b263236565e00f2" [[package]] name = "zopfli" -version = "0.8.2" +version = "0.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "edfc5ee405f504cd4984ecc6f14d02d55cfda60fa4b689434ef4102aae150cd7" +checksum = "f05cd8797d63865425ff89b5c4a48804f35ba0ce8d125800027ad6017d2b5249" dependencies = [ "bumpalo", "crc32fast", diff --git a/crates/brk_cli/Cargo.toml b/crates/brk_cli/Cargo.toml index e0d7990c5..638cc4c35 100644 --- a/crates/brk_cli/Cargo.toml +++ b/crates/brk_cli/Cargo.toml @@ -23,7 +23,7 @@ brk_reader = { workspace = true } brk_rpc = { workspace = true } brk_server = { workspace = true } vecdb = { workspace = true } -clap = { version = "4.5.50", features = ["derive", "string"] } +clap = { version = "4.5.51", features = ["derive", "string"] } color-eyre = "0.6.5" log = { workspace = true } minreq = { workspace = true } diff --git a/crates/brk_computer/Cargo.toml b/crates/brk_computer/Cargo.toml index e1d8f8b07..92aba721c 100644 --- a/crates/brk_computer/Cargo.toml +++ b/crates/brk_computer/Cargo.toml @@ -29,5 +29,6 @@ pco = "0.4.7" rayon = { workspace = true } rustc-hash = { workspace = true } serde = { workspace = true } +smallvec = "1.15.1" vecdb = { workspace = true } zerocopy = { workspace = true } diff --git a/crates/brk_computer/src/chain.rs b/crates/brk_computer/src/chain.rs index a0dc50af5..031f208be 100644 --- a/crates/brk_computer/src/chain.rs +++ b/crates/brk_computer/src/chain.rs @@ -98,7 +98,7 @@ pub struct Vecs { pub indexes_to_tx_vsize: ComputedVecsFromTxindex, pub indexes_to_tx_weight: ComputedVecsFromTxindex, pub indexes_to_unknownoutput_count: ComputedVecsFromHeight, - pub txinindex_to_value: LazyVecFrom2, + pub txinindex_to_value: EagerVec, pub indexes_to_input_count: ComputedVecsFromTxindex, pub txindex_to_is_coinbase: LazyVecFrom2, pub indexes_to_output_count: ComputedVecsFromTxindex, @@ -158,29 +158,8 @@ impl Vecs { let compute_dollars = price.is_some(); - let txinindex_to_value = LazyVecFrom2::init( - "value", - version + Version::ZERO, - indexes.txinindex_to_txoutindex.boxed_clone(), - indexer.vecs.txoutindex_to_value.boxed_clone(), - |index: TxInIndex, txinindex_to_txoutindex_iter, txoutindex_to_value_iter| { - txinindex_to_txoutindex_iter.next_at(index.to_usize()).map( - |(txinindex, txoutindex)| { - let txoutindex = txoutindex.into_owned(); - if txoutindex == TxOutIndex::COINBASE { - Sats::MAX - } else if let Some((_, value)) = - txoutindex_to_value_iter.next_at(txoutindex.to_usize()) - { - value.into_owned() - } else { - dbg!(txinindex, txoutindex); - panic!() - } - }, - ) - }, - ); + let txinindex_to_value: EagerVec = + EagerVec::forced_import_compressed(&db, "value", version + Version::ZERO)?; let txindex_to_weight = LazyVecFrom2::init( "weight", @@ -192,12 +171,7 @@ impl Vecs { txindex_to_base_size_iter .next_at(index) .map(|(_, base_size)| { - let base_size = base_size.into_owned(); - let total_size = txindex_to_total_size_iter - .next_at(index) - .unwrap() - .1 - .into_owned(); + let total_size = txindex_to_total_size_iter.next_at(index).unwrap().1; // This is the exact definition of a weight unit, as defined by BIP-141 (quote above). let wu = usize::from(base_size) * 3 + usize::from(total_size); @@ -214,9 +188,7 @@ impl Vecs { |index: TxIndex, iter| { let index = index.to_usize(); iter.next_at(index).map(|(_, weight)| { - StoredU64::from( - bitcoin::Weight::from(weight.into_owned()).to_vbytes_ceil() as usize - ) + StoredU64::from(bitcoin::Weight::from(weight).to_vbytes_ceil() as usize) }) }, ); @@ -230,12 +202,10 @@ impl Vecs { txindex_to_height_iter .next_at(index.to_usize()) .map(|(_, height)| { - let height = height.into_owned(); let txindex = height_to_first_txindex_iter .next_at(height.to_usize()) .unwrap() - .1 - .into_owned(); + .1; StoredBool::from(index == txindex) }) }, @@ -255,20 +225,11 @@ impl Vecs { txindex_to_first_txinindex_iter .next_at(txindex) .map(|(_, first_index)| { - let first_index = usize::from(first_index.into_owned()); - let count = *txindex_to_input_count_iter - .next_at(txindex) - .unwrap() - .1 - .into_owned(); + let first_index = usize::from(first_index); + let count = *txindex_to_input_count_iter.next_at(txindex).unwrap().1; let range = first_index..first_index + count as usize; range.into_iter().fold(Sats::ZERO, |total, txinindex| { - total - + txinindex_to_value_iter - .next_at(txinindex) - .unwrap() - .1 - .into_owned() + total + txinindex_to_value_iter.next_at(txinindex).unwrap().1 }) }) }, @@ -302,19 +263,11 @@ impl Vecs { txindex_to_first_txoutindex_iter .next_at(txindex) .map(|(_, first_index)| { - let first_index = usize::from(first_index.into_owned()); - let count = *txindex_to_output_count_iter - .next_at(txindex) - .unwrap() - .1 - .into_owned(); + let first_index = usize::from(first_index); + let count = *txindex_to_output_count_iter.next_at(txindex).unwrap().1; let range = first_index..first_index + count as usize; range.into_iter().fold(Sats::ZERO, |total, txoutindex| { - let v = txoutindex_to_value_iter - .next_at(txoutindex) - .unwrap() - .1 - .into_owned(); + let v = txoutindex_to_value_iter.next_at(txoutindex).unwrap().1; total + v }) }) @@ -1424,6 +1377,41 @@ impl Vecs { compute_indexes_to_tx_vany(&mut self.indexes_to_tx_v2, TxVersion::TWO)?; compute_indexes_to_tx_vany(&mut self.indexes_to_tx_v3, TxVersion::THREE)?; + let mut txoutindex_to_value_iter = indexer.vecs.txoutindex_to_value.into_iter(); + self.txinindex_to_value.compute_transform( + starting_indexes.txinindex, + &indexes.txinindex_to_txoutindex, + |(txinindex, txoutindex, ..)| { + let value = if txoutindex == TxOutIndex::COINBASE { + Sats::MAX + } else { + txoutindex_to_value_iter.unwrap_get_inner(txoutindex) + }; + (txinindex, value) + }, + exit, + )?; + + // indexes.txinindex_to_txoutindex.boxed_clone(), + // indexer.vecs.txoutindex_to_value.boxed_clone(), + // |index: TxInIndex, txinindex_to_txoutindex_iter, txoutindex_to_value_iter| { + // txinindex_to_txoutindex_iter.next_at(index.to_usize()).map( + // |(txinindex, txoutindex)| { + // let txoutindex = txoutindex; + // if txoutindex == TxOutIndex::COINBASE { + // Sats::MAX + // } else if let Some((_, value)) = + // txoutindex_to_value_iter.next_at(txoutindex.to_usize()) + // { + // value + // } else { + // dbg!(txinindex, txoutindex); + // panic!() + // } + // }, + // ) + // }, + // self.indexes_to_output_value.compute_all( // indexer, // indexes, diff --git a/crates/brk_computer/src/fetched.rs b/crates/brk_computer/src/fetched.rs index df95a979c..7e0a4b125 100644 --- a/crates/brk_computer/src/fetched.rs +++ b/crates/brk_computer/src/fetched.rs @@ -78,7 +78,6 @@ impl Vecs { height_to_timestamp .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { - let v = v.into_owned(); self.height_to_price_ohlc_in_cents.forced_push_at( i, self.fetcher @@ -103,8 +102,7 @@ impl Vecs { indexes .dateindex_to_date .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let d = v.into_owned(); + .try_for_each(|(i, d)| -> Result<()> { if prev.is_none() { let i = i.to_usize(); prev.replace(if i > 0 { diff --git a/crates/brk_computer/src/grouped/builder_eager.rs b/crates/brk_computer/src/grouped/builder_eager.rs index 5d74f17fe..f6c3314c1 100644 --- a/crates/brk_computer/src/grouped/builder_eager.rs +++ b/crates/brk_computer/src/grouped/builder_eager.rs @@ -222,7 +222,7 @@ where cumulative_vec.iter().unwrap_get_inner(index) }); source.iter_at(index).try_for_each(|(i, v)| -> Result<()> { - cumulative += v.into_owned(); + cumulative += v; cumulative_vec.forced_push_at(i, cumulative, exit)?; Ok(()) })?; @@ -263,8 +263,6 @@ where first_indexes .iter_at(index) .try_for_each(|(index, first_index)| -> Result<()> { - let first_index = first_index.into_owned(); - let count_index = count_indexes_iter.unwrap_get_inner(index); if let Some(first) = self.first.as_mut() { @@ -286,7 +284,7 @@ where // dbg!(first_index, count_index, last_index); // }) // .unwrap() - // .into_owned(); + // ; last.forced_push_at(index, v, exit)?; } @@ -306,7 +304,7 @@ where source_iter.set(first_index); let mut values = (&mut source_iter) .take(*count_index as usize) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect::>(); if needs_sorted { @@ -436,8 +434,6 @@ where first_indexes .iter_at(index) .try_for_each(|(index, first_index, ..)| -> Result<()> { - let first_index = first_index.into_owned(); - let count_index = count_indexes_iter.unwrap_get_inner(index); if let Some(first) = self.first.as_mut() { @@ -474,7 +470,7 @@ where source_max_iter.set(first_index); let mut values = source_max_iter .take(*count_index as usize) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect::>(); values.sort_unstable(); max.forced_push_at(index, *values.last().unwrap(), exit)?; @@ -485,7 +481,7 @@ where source_min_iter.set(first_index); let mut values = source_min_iter .take(*count_index as usize) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect::>(); values.sort_unstable(); min.forced_push_at(index, *values.first().unwrap(), exit)?; @@ -498,7 +494,7 @@ where source_average_iter.set(first_index); let values = source_average_iter .take(*count_index as usize) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect::>(); let len = values.len(); @@ -514,7 +510,7 @@ where source_sum_iter.set(first_index); let values = source_sum_iter .take(*count_index as usize) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect::>(); let sum = values.into_iter().fold(T::from(0), |a, b| a + b); diff --git a/crates/brk_computer/src/grouped/builder_lazy.rs b/crates/brk_computer/src/grouped/builder_lazy.rs index b3172e33e..08192cb0b 100644 --- a/crates/brk_computer/src/grouped/builder_lazy.rs +++ b/crates/brk_computer/src/grouped/builder_lazy.rs @@ -71,9 +71,7 @@ where if i.to_usize() >= len_source.len() { return None; } - source - .next_at(S1I::min_from(i)) - .map(|(_, cow)| cow.into_owned()) + source.next_at(S1I::min_from(i)).map(|(_, v)| v) }, )) }), @@ -100,7 +98,7 @@ where } source .next_at(S1I::max_from(i, source.len())) - .map(|(_, cow)| cow.into_owned()) + .map(|(_, v)| v) }, )) }), @@ -118,7 +116,7 @@ where return None; } S1I::inclusive_range_from(i, source.len()) - .flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned())) + .flat_map(|i| source.next_at(i).map(|(_, v)| v)) .min() }, )) @@ -137,7 +135,7 @@ where return None; } S1I::inclusive_range_from(i, source.len()) - .flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned())) + .flat_map(|i| source.next_at(i).map(|(_, v)| v)) .max() }, )) @@ -156,7 +154,7 @@ where return None; } let vec = S1I::inclusive_range_from(i, source.len()) - .flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned())) + .flat_map(|i| source.next_at(i).map(|(_, v)| v)) .collect::>(); if vec.is_empty() { return None; @@ -186,7 +184,7 @@ where return None; } let vec = S1I::inclusive_range_from(i, source.len()) - .flat_map(|i| source.next_at(i).map(|(_, cow)| cow.into_owned())) + .flat_map(|i| source.next_at(i).map(|(_, v)| v)) .collect::>(); if vec.is_empty() { return None; @@ -209,7 +207,7 @@ where } source .next_at(S1I::max_from(i, source.len())) - .map(|(_, cow)| cow.into_owned()) + .map(|(_, v)| v) }, )) }), @@ -259,6 +257,7 @@ pub struct LazyVecBuilderOptions { } impl From for LazyVecBuilderOptions { + #[inline] fn from(value: VecBuilderOptions) -> Self { Self { average: value.average(), diff --git a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs index 6cbbc0982..5c6f684a8 100644 --- a/crates/brk_computer/src/grouped/ratio_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/ratio_from_dateindex.rs @@ -440,7 +440,6 @@ impl ComputedRatioVecsFromDateIndex { .unwrap() .forced_push_at(index, StoredF32::NAN, exit)?; } else { - let ratio = ratio.into_owned(); let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos); sorted.insert(pos, ratio); diff --git a/crates/brk_computer/src/grouped/sd_from_dateindex.rs b/crates/brk_computer/src/grouped/sd_from_dateindex.rs index 796925602..3696ef52a 100644 --- a/crates/brk_computer/src/grouped/sd_from_dateindex.rs +++ b/crates/brk_computer/src/grouped/sd_from_dateindex.rs @@ -545,7 +545,6 @@ impl ComputedStandardDeviationVecsFromDateIndex { v.forced_push_at(index, StoredF32::NAN, exit)? } } else { - let ratio = ratio.into_owned(); let pos = sorted.binary_search(&ratio).unwrap_or_else(|pos| pos); sorted.insert(pos, ratio); diff --git a/crates/brk_computer/src/grouped/source.rs b/crates/brk_computer/src/grouped/source.rs index 5a04d2882..6dc6519f0 100644 --- a/crates/brk_computer/src/grouped/source.rs +++ b/crates/brk_computer/src/grouped/source.rs @@ -29,18 +29,21 @@ impl Source { } impl From for Source { + #[inline] fn from(value: bool) -> Self { if value { Self::Compute } else { Self::None } } } impl From> for Source { + #[inline] fn from(value: AnyBoxedIterableVec) -> Self { Self::Vec(value) } } impl From>> for Source { + #[inline] fn from(value: Option>) -> Self { if let Some(v) = value { Self::Vec(v) diff --git a/crates/brk_computer/src/grouped/value_from_txindex.rs b/crates/brk_computer/src/grouped/value_from_txindex.rs index d21e8a3b8..c6985da6c 100644 --- a/crates/brk_computer/src/grouped/value_from_txindex.rs +++ b/crates/brk_computer/src/grouped/value_from_txindex.rs @@ -59,10 +59,8 @@ impl ComputedValueVecsFromTxindex { version + VERSION, source_vec.map_or_else(|| sats.txindex.as_ref().unwrap().boxed_clone(), |s| s), |txindex: TxIndex, iter| { - iter.next_at(txindex.to_usize()).map(|(_, value)| { - let sats = value.into_owned(); - Bitcoin::from(sats) - }) + iter.next_at(txindex.to_usize()) + .map(|(_, sats)| Bitcoin::from(sats)) }, ); @@ -87,15 +85,13 @@ impl ComputedValueVecsFromTxindex { txindex_to_height_iter, height_to_price_close_iter| { let txindex = txindex.to_usize(); - txindex_to_btc_iter.next_at(txindex).and_then(|(_, value)| { - let btc = value.into_owned(); + txindex_to_btc_iter.next_at(txindex).and_then(|(_, btc)| { txindex_to_height_iter .next_at(txindex) - .and_then(|(_, value)| { - let height = value.into_owned(); + .and_then(|(_, height)| { height_to_price_close_iter .next_at(height.to_usize()) - .map(|(_, close)| *close.into_owned() * btc) + .map(|(_, close)| *close * btc) }) }) }, diff --git a/crates/brk_computer/src/indexes.rs b/crates/brk_computer/src/indexes.rs index b962eb18d..0ae11852a 100644 --- a/crates/brk_computer/src/indexes.rs +++ b/crates/brk_computer/src/indexes.rs @@ -119,7 +119,6 @@ impl Vecs { txinindex_to_outpoint_iter .next_at(index.to_usize()) .map(|(_, outpoint)| { - let outpoint = outpoint.into_owned(); if outpoint.is_coinbase() { return TxOutIndex::COINBASE; } @@ -127,7 +126,6 @@ impl Vecs { .next_at(outpoint.txindex().to_usize()) .unwrap() .1 - .into_owned() + outpoint.vout() }) }, @@ -164,10 +162,10 @@ impl Vecs { txindex_to_first_txinindex_iter .next_at(txindex) .map(|(_, start)| { - let start = usize::from(start.into_owned()); + let start = usize::from(start); let end = txindex_to_first_txinindex_iter .next_at(txindex + 1) - .map(|(_, v)| usize::from(v.into_owned())) + .map(|(_, v)| usize::from(v)) .unwrap_or_else(|| txinindex_to_txoutindex_iter.len()); StoredU64::from((start..end).count()) }) @@ -184,10 +182,10 @@ impl Vecs { txindex_to_first_txoutindex_iter .next_at(txindex) .map(|(_, start)| { - let start = usize::from(start.into_owned()); + let start = usize::from(start); let end = txindex_to_first_txoutindex_iter .next_at(txindex + 1) - .map(|(_, v)| usize::from(v.into_owned())) + .map(|(_, v)| usize::from(v)) .unwrap_or_else(|| txoutindex_to_value_iter.len()); StoredU64::from((start..end).count()) }) diff --git a/crates/brk_computer/src/price.rs b/crates/brk_computer/src/price.rs index 65e54e6ea..8a035b771 100644 --- a/crates/brk_computer/src/price.rs +++ b/crates/brk_computer/src/price.rs @@ -389,11 +389,8 @@ impl Vecs { .height_to_price_ohlc_in_cents .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { - self.height_to_price_ohlc.forced_push_at( - i, - OHLCDollars::from(v.into_owned()), - exit, - )?; + self.height_to_price_ohlc + .forced_push_at(i, OHLCDollars::from(v), exit)?; Ok(()) })?; self.height_to_price_ohlc.safe_flush(exit)?; @@ -433,11 +430,8 @@ impl Vecs { .dateindex_to_price_ohlc_in_cents .iter_at(index) .try_for_each(|(i, v)| -> Result<()> { - self.dateindex_to_price_ohlc.forced_push_at( - i, - OHLCDollars::from(v.into_owned()), - exit, - )?; + self.dateindex_to_price_ohlc + .forced_push_at(i, OHLCDollars::from(v), exit)?; Ok(()) })?; self.dateindex_to_price_ohlc.safe_flush(exit)?; @@ -544,8 +538,7 @@ impl Vecs { .weekindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { 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); @@ -585,8 +578,7 @@ impl Vecs { .difficultyepoch .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { let open = difficultyepoch_first_iter.unwrap_get_inner(i); let high = difficultyepoch_max_iter.unwrap_get_inner(i); let low = difficultyepoch_min_iter.unwrap_get_inner(i); @@ -622,8 +614,7 @@ impl Vecs { .monthindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { let open = monthindex_first_iter.unwrap_get_inner(i); let high = monthindex_max_iter.unwrap_get_inner(i); let low = monthindex_min_iter.unwrap_get_inner(i); @@ -663,8 +654,7 @@ impl Vecs { .quarterindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { let open = quarterindex_first_iter.unwrap_get_inner(i); let high = quarterindex_max_iter.unwrap_get_inner(i); let low = quarterindex_min_iter.unwrap_get_inner(i); @@ -704,8 +694,7 @@ impl Vecs { .semesterindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { let open = semesterindex_first_iter.unwrap_get_inner(i); let high = semesterindex_max_iter.unwrap_get_inner(i); let low = semesterindex_min_iter.unwrap_get_inner(i); @@ -737,8 +726,7 @@ impl Vecs { .yearindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { let open = yearindex_first_iter.unwrap_get_inner(i); let high = yearindex_max_iter.unwrap_get_inner(i); let low = yearindex_min_iter.unwrap_get_inner(i); @@ -781,8 +769,7 @@ impl Vecs { .decadeindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { let open = decadeindex_first_iter.unwrap_get_inner(i); let high = decadeindex_max_iter.unwrap_get_inner(i); let low = decadeindex_min_iter.unwrap_get_inner(i); @@ -897,8 +884,7 @@ impl Vecs { self.chainindexes_to_price_close_in_sats .height .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.height_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { @@ -939,8 +925,7 @@ impl Vecs { .as_ref() .unwrap() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.dateindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { @@ -977,8 +962,7 @@ impl Vecs { .weekindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.weekindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { @@ -1015,8 +999,7 @@ impl Vecs { .difficultyepoch .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.difficultyepoch_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { @@ -1054,8 +1037,7 @@ impl Vecs { .monthindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.monthindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { @@ -1092,8 +1074,7 @@ impl Vecs { .quarterindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.quarterindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { @@ -1130,8 +1111,7 @@ impl Vecs { .semesterindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.semesterindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { @@ -1168,8 +1148,7 @@ impl Vecs { .yearindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.yearindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { @@ -1209,8 +1188,7 @@ impl Vecs { .decadeindex .unwrap_last() .iter_at(index) - .try_for_each(|(i, v)| -> Result<()> { - let close = v.into_owned(); + .try_for_each(|(i, close)| -> Result<()> { self.decadeindex_to_price_ohlc_in_sats.forced_push_at( i, OHLCSats { diff --git a/crates/brk_computer/src/stateful/addresstype/addresscount.rs b/crates/brk_computer/src/stateful/addresstype/addresscount.rs index 1b46bb483..b7ffdb455 100644 --- a/crates/brk_computer/src/stateful/addresstype/addresscount.rs +++ b/crates/brk_computer/src/stateful/addresstype/addresscount.rs @@ -9,6 +9,7 @@ use super::AddressTypeToHeightToAddressCount; pub struct AddressTypeToAddressCount(ByAddressType); impl From<(&AddressTypeToHeightToAddressCount, Height)> for AddressTypeToAddressCount { + #[inline] fn from((groups, starting_height): (&AddressTypeToHeightToAddressCount, Height)) -> Self { if let Some(prev_height) = starting_height.decremented() { Self(ByAddressType { diff --git a/crates/brk_computer/src/stateful/addresstype/height_to_addresscount.rs b/crates/brk_computer/src/stateful/addresstype/height_to_addresscount.rs index efb5b43b5..73e039abb 100644 --- a/crates/brk_computer/src/stateful/addresstype/height_to_addresscount.rs +++ b/crates/brk_computer/src/stateful/addresstype/height_to_addresscount.rs @@ -11,6 +11,7 @@ use super::AddressTypeToAddressCount; pub struct AddressTypeToHeightToAddressCount(ByAddressType>); impl From>> for AddressTypeToHeightToAddressCount { + #[inline] fn from(value: ByAddressType>) -> Self { Self(value) } diff --git a/crates/brk_computer/src/stateful/addresstype/indexes_to_addresscount.rs b/crates/brk_computer/src/stateful/addresstype/indexes_to_addresscount.rs index d0d28797f..ae8e32af5 100644 --- a/crates/brk_computer/src/stateful/addresstype/indexes_to_addresscount.rs +++ b/crates/brk_computer/src/stateful/addresstype/indexes_to_addresscount.rs @@ -13,6 +13,7 @@ use super::AddressTypeToHeightToAddressCount; pub struct AddressTypeToIndexesToAddressCount(ByAddressType>); impl From>> for AddressTypeToIndexesToAddressCount { + #[inline] fn from(value: ByAddressType>) -> Self { Self(value) } diff --git a/crates/brk_computer/src/stateful/addresstype/typeindex_map.rs b/crates/brk_computer/src/stateful/addresstype/typeindex_map.rs index 5a2f382a3..4489231f6 100644 --- a/crates/brk_computer/src/stateful/addresstype/typeindex_map.rs +++ b/crates/brk_computer/src/stateful/addresstype/typeindex_map.rs @@ -66,3 +66,26 @@ impl Default for AddressTypeToTypeIndexMap { }) } } + +impl AddressTypeToTypeIndexMap> +where + T: Copy, +{ + pub fn merge_vec(mut self, other: Self) -> Self { + for (address_type, other_map) in other.0.into_iter_typed() { + let self_map = self.0.get_mut_unwrap(address_type); + for (typeindex, mut other_vec) in other_map { + self_map + .entry(typeindex) + .and_modify(|self_vec| { + if other_vec.len() > self_vec.len() { + mem::swap(self_vec, &mut other_vec); + } + self_vec.extend(other_vec.iter().copied()); + }) + .or_insert(other_vec); + } + } + self + } +} diff --git a/crates/brk_computer/src/stateful/mod.rs b/crates/brk_computer/src/stateful/mod.rs index 301eb5b23..173b021e6 100644 --- a/crates/brk_computer/src/stateful/mod.rs +++ b/crates/brk_computer/src/stateful/mod.rs @@ -8,16 +8,17 @@ use brk_types::{ AnyAddressDataIndexEnum, AnyAddressIndex, CheckedSub, DateIndex, Dollars, EmptyAddressData, EmptyAddressIndex, Height, LoadedAddressData, LoadedAddressIndex, OutputType, P2AAddressIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, P2TRAddressIndex, - P2WPKHAddressIndex, P2WSHAddressIndex, Sats, StoredU64, Timestamp, TxInIndex, TxOutIndex, - TypeIndex, Version, + P2WPKHAddressIndex, P2WSHAddressIndex, Sats, StoredU64, Timestamp, TxInIndex, TxIndex, + TxOutIndex, TypeIndex, Version, }; use log::info; use rayon::prelude::*; use rustc_hash::FxHashMap; +use smallvec::SmallVec; use vecdb::{ - AnyCloneableIterableVec, AnyStoredVec, AnyVec, CollectableVec, Database, EagerVec, Exit, - Format, GenericStoredVec, ImportOptions, LazyVecFrom1, PAGE_SIZE, RawVec, Reader, Stamp, - StoredIndex, VecIterator, + AnyCloneableIterableVec, AnyIterableVec, AnyStoredVec, AnyVec, BoxedVecIterator, + CollectableVec, Database, EagerVec, Exit, Format, GenericStoredVec, ImportOptions, + LazyVecFrom1, PAGE_SIZE, RawVec, Reader, Stamp, StoredIndex, VecIterator, }; use crate::{ @@ -44,6 +45,8 @@ use range_map::*; use r#trait::*; use withaddressdatasource::*; +type TxIndexVec = SmallVec<[TxIndex; 4]>; + const VERSION: Version = Version::new(21); #[derive(Clone, Traversable)] @@ -186,12 +189,7 @@ impl Vecs { .as_ref() .unwrap() .boxed_clone(), - |height: Height, iter| { - iter.next_at(height.to_usize()).map(|(_, value)| { - let d: Dollars = value.into_owned(); - d - }) - }, + |height: Height, iter| iter.next_at(height.to_usize()).map(|(_, d)| d), ) }), indexes_to_market_cap: compute_dollars.then(|| { @@ -519,8 +517,12 @@ impl Vecs { starting_indexes: &mut Indexes, exit: &Exit, ) -> Result<()> { - let height_to_first_txoutindex = &indexer.vecs.height_to_first_txoutindex; - let height_to_first_txinindex = &indexer.vecs.height_to_first_txinindex; + let dateindex_to_first_height = &indexes.dateindex_to_first_height; + let dateindex_to_height_count = &indexes.dateindex_to_height_count; + let dateindex_to_price_close = price + .as_ref() + .map(|price| price.timeindexes_to_price_close.dateindex.as_ref().unwrap()); + let height_to_date_fixed = &indexes.height_to_date_fixed; let height_to_first_p2aaddressindex = &indexer.vecs.height_to_first_p2aaddressindex; let height_to_first_p2pk33addressindex = &indexer.vecs.height_to_first_p2pk33addressindex; let height_to_first_p2pk65addressindex = &indexer.vecs.height_to_first_p2pk65addressindex; @@ -529,38 +531,42 @@ impl Vecs { let height_to_first_p2traddressindex = &indexer.vecs.height_to_first_p2traddressindex; let height_to_first_p2wpkhaddressindex = &indexer.vecs.height_to_first_p2wpkhaddressindex; let height_to_first_p2wshaddressindex = &indexer.vecs.height_to_first_p2wshaddressindex; - let height_to_output_count = chain.indexes_to_output_count.height.unwrap_sum(); + let height_to_first_txindex = &indexer.vecs.height_to_first_txindex; + let height_to_first_txinindex = &indexer.vecs.height_to_first_txinindex; + let height_to_first_txoutindex = &indexer.vecs.height_to_first_txoutindex; let height_to_input_count = chain.indexes_to_input_count.height.unwrap_sum(); - let txinindex_to_outpoint = &indexer.vecs.txinindex_to_outpoint; - let txindex_to_first_txoutindex = &indexer.vecs.txindex_to_first_txoutindex; - let txoutindex_to_value = &indexer.vecs.txoutindex_to_value; - let txindex_to_height = &indexer.vecs.txindex_to_height; + let height_to_output_count = chain.indexes_to_output_count.height.unwrap_sum(); + let height_to_price_close = price + .as_ref() + .map(|price| &price.chainindexes_to_price_close.height); let height_to_timestamp_fixed = &indexes.height_to_timestamp_fixed; - let txoutindex_to_txindex = &indexer.vecs.txoutindex_to_txindex; - let txoutindex_to_outputtype = &indexer.vecs.txoutindex_to_outputtype; - let txoutindex_to_typeindex = &indexer.vecs.txoutindex_to_typeindex; + let height_to_tx_count = chain.indexes_to_tx_count.height.as_ref().unwrap(); let height_to_unclaimed_rewards = chain .indexes_to_unclaimed_rewards .sats .height .as_ref() .unwrap(); - let height_to_price_close = price - .as_ref() - .map(|price| &price.chainindexes_to_price_close.height); - let dateindex_to_price_close = price - .as_ref() - .map(|price| price.timeindexes_to_price_close.dateindex.as_ref().unwrap()); - let height_to_date_fixed = &indexes.height_to_date_fixed; - let dateindex_to_first_height = &indexes.dateindex_to_first_height; - let dateindex_to_height_count = &indexes.dateindex_to_height_count; + let txindex_to_first_txoutindex = &indexer.vecs.txindex_to_first_txoutindex; + let txindex_to_height = &indexer.vecs.txindex_to_height; + let txindex_to_input_count = &indexes.txindex_to_input_count; + let txindex_to_output_count = &indexes.txindex_to_output_count; + let txinindex_to_outpoint = &indexer.vecs.txinindex_to_outpoint; + let txoutindex_to_outputtype = &indexer.vecs.txoutindex_to_outputtype; + let txoutindex_to_txindex = &indexer.vecs.txoutindex_to_txindex; + let txoutindex_to_typeindex = &indexer.vecs.txoutindex_to_typeindex; + let txoutindex_to_value = &indexer.vecs.txoutindex_to_value; let mut height_to_price_close_iter = height_to_price_close.as_ref().map(|v| v.into_iter()); let mut height_to_timestamp_fixed_iter = height_to_timestamp_fixed.into_iter(); let base_version = Version::ZERO - + height_to_first_txoutindex.version() - + height_to_first_txinindex.version() + + dateindex_to_first_height.version() + + dateindex_to_height_count.version() + + dateindex_to_price_close + .as_ref() + .map_or(Version::ZERO, |v| v.version()) + + height_to_date_fixed.version() + height_to_first_p2aaddressindex.version() + height_to_first_p2pk33addressindex.version() + height_to_first_p2pk65addressindex.version() @@ -569,26 +575,26 @@ impl Vecs { + height_to_first_p2traddressindex.version() + height_to_first_p2wpkhaddressindex.version() + height_to_first_p2wshaddressindex.version() - + height_to_timestamp_fixed.version() - + height_to_output_count.version() + + height_to_first_txindex.version() + + height_to_first_txinindex.version() + + height_to_first_txoutindex.version() + height_to_input_count.version() - + txinindex_to_outpoint.version() - + txoutindex_to_value.version() - + txindex_to_height.version() - + txindex_to_first_txoutindex.version() - + txoutindex_to_txindex.version() - + txoutindex_to_outputtype.version() - + txoutindex_to_typeindex.version() - + height_to_unclaimed_rewards.version() + + height_to_output_count.version() + height_to_price_close .as_ref() .map_or(Version::ZERO, |v| v.version()) - + dateindex_to_price_close - .as_ref() - .map_or(Version::ZERO, |v| v.version()) - + height_to_date_fixed.version() - + dateindex_to_first_height.version() - + dateindex_to_height_count.version(); + + height_to_timestamp_fixed.version() + + height_to_tx_count.version() + + height_to_unclaimed_rewards.version() + + txindex_to_first_txoutindex.version() + + txindex_to_height.version() + + txindex_to_input_count.version() + + txindex_to_output_count.version() + + txinindex_to_outpoint.version() + + txoutindex_to_outputtype.version() + + txoutindex_to_txindex.version() + + txoutindex_to_typeindex.version() + + txoutindex_to_value.version(); let mut separate_utxo_vecs = self.utxo_cohorts.iter_separate_mut().collect::>(); let mut separate_address_vecs = @@ -748,8 +754,11 @@ impl Vecs { let ir = IndexerReaders::new(indexer); - let mut height_to_first_txoutindex_iter = height_to_first_txoutindex.into_iter(); - let mut height_to_first_txinindex_iter = height_to_first_txinindex.into_iter(); + let mut dateindex_to_first_height_iter = dateindex_to_first_height.into_iter(); + let mut dateindex_to_height_count_iter = dateindex_to_height_count.into_iter(); + let mut dateindex_to_price_close_iter = + dateindex_to_price_close.as_ref().map(|v| v.into_iter()); + let mut height_to_date_fixed_iter = height_to_date_fixed.into_iter(); let mut height_to_first_p2aaddressindex_iter = height_to_first_p2aaddressindex.into_iter(); let mut height_to_first_p2pk33addressindex_iter = @@ -766,14 +775,15 @@ impl Vecs { height_to_first_p2wpkhaddressindex.into_iter(); let mut height_to_first_p2wshaddressindex_iter = height_to_first_p2wshaddressindex.into_iter(); - let mut height_to_output_count_iter = height_to_output_count.into_iter(); + let mut height_to_first_txindex_iter = height_to_first_txindex.into_iter(); + let mut height_to_first_txinindex_iter = height_to_first_txinindex.into_iter(); + let mut height_to_first_txoutindex_iter = height_to_first_txoutindex.into_iter(); let mut height_to_input_count_iter = height_to_input_count.into_iter(); + let mut height_to_output_count_iter = height_to_output_count.into_iter(); + let mut height_to_tx_count_iter = height_to_tx_count.into_iter(); let mut height_to_unclaimed_rewards_iter = height_to_unclaimed_rewards.into_iter(); - let mut dateindex_to_price_close_iter = - dateindex_to_price_close.as_ref().map(|v| v.into_iter()); - let mut height_to_date_fixed_iter = height_to_date_fixed.into_iter(); - let mut dateindex_to_first_height_iter = dateindex_to_first_height.into_iter(); - let mut dateindex_to_height_count_iter = dateindex_to_height_count.into_iter(); + let mut txindex_to_input_count_iter = txindex_to_input_count.boxed_iter(); + let mut txindex_to_output_count_iter = txindex_to_output_count.boxed_iter(); let height_to_price_close_vec = height_to_price_close.map(|height_to_price_close| height_to_price_close.collect()); @@ -841,15 +851,29 @@ impl Vecs { let price = height_to_price_close_iter .as_mut() .map(|i| *i.unwrap_get_inner(height)); + let first_txindex = height_to_first_txindex_iter.unwrap_get_inner(height); let first_txoutindex = height_to_first_txoutindex_iter .unwrap_get_inner(height) .to_usize(); let first_txinindex = height_to_first_txinindex_iter .unwrap_get_inner(height) .to_usize(); + let tx_count = height_to_tx_count_iter.unwrap_get_inner(height); let output_count = height_to_output_count_iter.unwrap_get_inner(height); let input_count = height_to_input_count_iter.unwrap_get_inner(height); + let txoutindex_to_txindex = build_txoutindex_to_txindex( + first_txindex, + u64::from(tx_count), + &mut txindex_to_output_count_iter, + ); + + let txinindex_to_txindex = build_txinindex_to_txindex( + first_txindex, + u64::from(tx_count), + &mut txindex_to_input_count_iter, + ); + let first_addressindexes: ByAddressType = ByAddressType { p2a: height_to_first_p2aaddressindex_iter .unwrap_get_inner(height) @@ -1499,8 +1523,7 @@ impl Vecs { .loaded .get_any_or_read(loadedaddressindex, reader) .unwrap() - .unwrap() - .into_owned(); + .unwrap(); WithAddressDataSource::FromLoadedAddressDataVec(( loadedaddressindex, @@ -1514,8 +1537,7 @@ impl Vecs { .empty .get_any_or_read(emtpyaddressindex, reader) .unwrap() - .unwrap() - .into_owned(); + .unwrap(); WithAddressDataSource::FromEmptyAddressDataVec(( emtpyaddressindex, @@ -1969,7 +1991,7 @@ impl AnyAddressIndexes { OutputType::P2A => self.p2a.get_any_or_read(typeindex.into(), reader), _ => unreachable!(), }; - result.unwrap().unwrap().into_owned() + result.unwrap().unwrap() } fn update_or_push( @@ -2104,3 +2126,43 @@ impl VecsReaders { .get_unwrap(address_type) } } + +fn build_txoutindex_to_txindex<'a>( + block_first_txindex: TxIndex, + block_tx_count: u64, + txindex_to_output_count: &mut BoxedVecIterator<'a, TxIndex, StoredU64>, +) -> Vec { + let mut vec = Vec::new(); + + let block_first_txindex = block_first_txindex.to_usize(); + for tx_offset in 0..block_tx_count as usize { + let txindex = TxIndex::from(block_first_txindex + tx_offset); + let output_count = u64::from(txindex_to_output_count.unwrap_get_inner(txindex)); + + for _ in 0..output_count { + vec.push(txindex); + } + } + + vec +} + +fn build_txinindex_to_txindex<'a>( + block_first_txindex: TxIndex, + block_tx_count: u64, + txindex_to_input_count: &mut BoxedVecIterator<'a, TxIndex, StoredU64>, +) -> Vec { + let mut vec = Vec::new(); + + let block_first_txindex = block_first_txindex.to_usize(); + for tx_offset in 0..block_tx_count as usize { + let txindex = TxIndex::from(block_first_txindex + tx_offset); + let input_count = u64::from(txindex_to_input_count.unwrap_get_inner(txindex)); + + for _ in 0..input_count { + vec.push(txindex); + } + } + + vec +} diff --git a/crates/brk_computer/src/stateful/range_map.rs b/crates/brk_computer/src/stateful/range_map.rs index 99ddb67e8..42686c44e 100644 --- a/crates/brk_computer/src/stateful/range_map.rs +++ b/crates/brk_computer/src/stateful/range_map.rs @@ -25,10 +25,11 @@ where I: StoredIndex, T: StoredIndex + StoredRaw, { + #[inline] fn from(vec: &RawVec) -> Self { Self( vec.into_iter() - .map(|(i, v)| (v.into_owned(), i)) + .map(|(i, v)| (v, i)) .collect::>(), ) } @@ -39,10 +40,11 @@ where I: StoredIndex, T: StoredIndex + StoredCompressed, { + #[inline] fn from(vec: &CompressedVec) -> Self { Self( vec.into_iter() - .map(|(i, v)| (v.into_owned(), i)) + .map(|(i, v)| (v, i)) .collect::>(), ) } diff --git a/crates/brk_computer/src/stateful/withaddressdatasource.rs b/crates/brk_computer/src/stateful/withaddressdatasource.rs index 215db498c..79ac4b7da 100644 --- a/crates/brk_computer/src/stateful/withaddressdatasource.rs +++ b/crates/brk_computer/src/stateful/withaddressdatasource.rs @@ -26,6 +26,7 @@ impl WithAddressDataSource { } impl From> for WithAddressDataSource { + #[inline] fn from(value: WithAddressDataSource) -> Self { match value { WithAddressDataSource::New(v) => Self::New(v.into()), @@ -40,6 +41,7 @@ impl From> for WithAddressDataSource> for WithAddressDataSource { + #[inline] fn from(value: WithAddressDataSource) -> Self { match value { WithAddressDataSource::New(v) => Self::New(v.into()), diff --git a/crates/brk_computer/src/states/supply.rs b/crates/brk_computer/src/states/supply.rs index b7705b6cd..63792042c 100644 --- a/crates/brk_computer/src/states/supply.rs +++ b/crates/brk_computer/src/states/supply.rs @@ -41,6 +41,7 @@ impl SubAssign<&SupplyState> for SupplyState { } impl From<&LoadedAddressData> for SupplyState { + #[inline] fn from(value: &LoadedAddressData) -> Self { Self { utxo_count: value.utxo_count() as u64, diff --git a/crates/brk_computer/src/traits.rs b/crates/brk_computer/src/traits.rs index 6ebc89beb..5ae870be0 100644 --- a/crates/brk_computer/src/traits.rs +++ b/crates/brk_computer/src/traits.rs @@ -41,7 +41,7 @@ impl ComputeDCAStackViaLen for EagerVec { let index = max_from.min(DateIndex::from(self.len())); closes.iter_at(index).try_for_each(|(i, closes)| { - let price = *closes.into_owned(); + let price = *closes; let i_usize = i.to_usize(); if prev.is_none() { if i_usize == 0 { @@ -91,7 +91,7 @@ impl ComputeDCAStackViaLen for EagerVec { let index = max_from.min(DateIndex::from(self.len())); closes.iter_at(index).try_for_each(|(i, closes)| { - let price = *closes.into_owned(); + let price = *closes; let i_usize = i.to_usize(); if prev.is_none() { if i_usize == 0 { @@ -152,7 +152,6 @@ impl ComputeDCAAveragePriceViaLen for EagerVec { let first_price_date = DateIndex::try_from(Date::new(2010, 7, 12)).unwrap(); stacks.iter_at(index).try_for_each(|(i, stack)| { - let stack = stack.into_owned(); let mut avg_price = Dollars::from(f64::NAN); if i > first_price_date { avg_price = DCA_AMOUNT @@ -185,7 +184,6 @@ impl ComputeDCAAveragePriceViaLen for EagerVec { let from_usize = from.to_usize(); stacks.iter_at(index).try_for_each(|(i, stack)| { - let stack = stack.into_owned(); let mut avg_price = Dollars::from(f64::NAN); if i >= from { avg_price = DCA_AMOUNT * (i.to_usize() + 1 - from_usize) / Bitcoin::from(stack); @@ -223,7 +221,7 @@ where let index = max_from.min(I::from(self.len())); sats.iter_at(index).try_for_each(|(i, sats)| { - let (i, v) = (i, Bitcoin::from(sats.into_owned())); + let (i, v) = (i, Bitcoin::from(sats)); self.forced_push_at(i, v, exit) })?; @@ -261,7 +259,7 @@ where let index = max_from.min(I::from(self.len())); bitcoin.iter_at(index).try_for_each(|(i, bitcoin)| { let dollars = price_iter.unwrap_get_inner(i); - let (i, v) = (i, *dollars * bitcoin.into_owned()); + let (i, v) = (i, *dollars * bitcoin); self.forced_push_at(i, v, exit) })?; @@ -298,7 +296,6 @@ where let index = max_from.min(I::from(self.len())); let mut close_iter = close.iter(); ath.iter_at(index).try_for_each(|(i, ath)| { - let ath = ath.into_owned(); if ath == Dollars::ZERO { self.forced_push_at(i, StoredF32::default(), exit) } else { diff --git a/crates/brk_error/src/lib.rs b/crates/brk_error/src/lib.rs index 32207b57c..e7cc2c0d8 100644 --- a/crates/brk_error/src/lib.rs +++ b/crates/brk_error/src/lib.rs @@ -44,108 +44,126 @@ pub enum Error { } impl From for Error { + #[inline] fn from(value: bitcoin::block::Bip34Error) -> Self { Self::BitcoinBip34Error(value) } } impl From for Error { + #[inline] fn from(value: bitcoin::consensus::encode::Error) -> Self { Self::BitcoinConsensusEncode(value) } } impl From for Error { + #[inline] fn from(value: bitcoin::consensus::encode::FromHexError) -> Self { Self::BitcoinHexError(value) } } impl From for Error { + #[inline] fn from(value: bitcoin::hex::HexToArrayError) -> Self { Self::BitcoinHexToArrayError(value) } } impl From for Error { + #[inline] fn from(value: bitcoin::address::FromScriptError) -> Self { Self::BitcoinFromScriptError(value) } } impl From for Error { + #[inline] fn from(value: time::SystemTimeError) -> Self { Self::SystemTimeError(value) } } impl From for Error { + #[inline] fn from(error: sonic_rs::Error) -> Self { Self::SonicRS(error) } } impl From for Error { + #[inline] fn from(value: io::Error) -> Self { Self::IO(value) } } impl From for Error { + #[inline] fn from(value: vecdb::Error) -> Self { Self::VecDB(value) } } impl From for Error { + #[inline] fn from(value: vecdb::SeqDBError) -> Self { Self::SeqDB(value) } } impl From for Error { + #[inline] fn from(value: bitcoincore_rpc::Error) -> Self { Self::BitcoinRPC(value) } } impl From for Error { + #[inline] fn from(value: minreq::Error) -> Self { Self::Minreq(value) } } impl From for Error { + #[inline] fn from(value: jiff::Error) -> Self { Self::Jiff(value) } } // impl From for Error { -// fn from(value: fjall3::Error) -> Self { +// #[inline] +// fn from(value: fjall3::Error) -> Self { // Self::FjallV3(value) // } // } impl From for Error { + #[inline] fn from(value: fjall2::Error) -> Self { Self::FjallV2(value) } } impl From<&'static str> for Error { + #[inline] fn from(value: &'static str) -> Self { Self::Str(value) } } impl From> for Error { + #[inline] fn from(_: zerocopy::error::ConvertError) -> Self { Self::ZeroCopyError } } impl From> for Error { + #[inline] fn from(_: zerocopy::error::SizeError) -> Self { Self::ZeroCopyError } diff --git a/crates/brk_grouper/src/address.rs b/crates/brk_grouper/src/address.rs index 192c47029..e3a10e032 100644 --- a/crates/brk_grouper/src/address.rs +++ b/crates/brk_grouper/src/address.rs @@ -46,6 +46,7 @@ impl AddressGroups> { } impl From> for AddressGroups> { + #[inline] fn from(value: AddressGroups) -> Self { Self { amount_range: ByAmountRange::from(value.amount_range), diff --git a/crates/brk_grouper/src/by_address_type.rs b/crates/brk_grouper/src/by_address_type.rs index b17f1856f..726a8f82d 100644 --- a/crates/brk_grouper/src/by_address_type.rs +++ b/crates/brk_grouper/src/by_address_type.rs @@ -231,6 +231,7 @@ impl ByAddressType> { } impl From> for ByAddressType> { + #[inline] fn from(value: ByAddressType) -> Self { Self { p2pk65: (Filter::Type(OutputType::P2PK65), value.p2pk65).into(), diff --git a/crates/brk_grouper/src/by_age_range.rs b/crates/brk_grouper/src/by_age_range.rs index 28fca5f30..92cefb2b9 100644 --- a/crates/brk_grouper/src/by_age_range.rs +++ b/crates/brk_grouper/src/by_age_range.rs @@ -30,6 +30,7 @@ pub struct ByAgeRange { } impl From> for ByAgeRange> { + #[inline] fn from(value: ByAgeRange) -> Self { Self { up_to_1d: (Filter::LowerThan(1), value.up_to_1d).into(), diff --git a/crates/brk_grouper/src/by_amount_range.rs b/crates/brk_grouper/src/by_amount_range.rs index 00c007022..2d6452bf4 100644 --- a/crates/brk_grouper/src/by_amount_range.rs +++ b/crates/brk_grouper/src/by_amount_range.rs @@ -26,6 +26,7 @@ pub struct ByAmountRange { } impl From> for ByAmountRange> { + #[inline] fn from(value: ByAmountRange) -> Self { #[allow(clippy::inconsistent_digit_grouping)] Self { diff --git a/crates/brk_grouper/src/by_epoch.rs b/crates/brk_grouper/src/by_epoch.rs index 3e3cadcbe..d42c2ca61 100644 --- a/crates/brk_grouper/src/by_epoch.rs +++ b/crates/brk_grouper/src/by_epoch.rs @@ -14,6 +14,7 @@ pub struct ByEpoch { } impl From> for ByEpoch> { + #[inline] fn from(value: ByEpoch) -> Self { Self { _0: (Filter::Epoch(HalvingEpoch::new(0)), value._0).into(), diff --git a/crates/brk_grouper/src/by_ge_amount.rs b/crates/brk_grouper/src/by_ge_amount.rs index 648ed25f2..a11ee2ded 100644 --- a/crates/brk_grouper/src/by_ge_amount.rs +++ b/crates/brk_grouper/src/by_ge_amount.rs @@ -63,6 +63,7 @@ impl ByGreatEqualAmount> { } impl From> for ByGreatEqualAmount> { + #[inline] fn from(value: ByGreatEqualAmount) -> Self { Self { _1sat: (Filter::GreaterOrEqual(Sats::_1.into()), value._1sat).into(), diff --git a/crates/brk_grouper/src/by_lt_amount.rs b/crates/brk_grouper/src/by_lt_amount.rs index 6b3db9303..5eaf35d7a 100644 --- a/crates/brk_grouper/src/by_lt_amount.rs +++ b/crates/brk_grouper/src/by_lt_amount.rs @@ -63,6 +63,7 @@ impl ByLowerThanAmount> { } impl From> for ByLowerThanAmount> { + #[inline] fn from(value: ByLowerThanAmount) -> Self { Self { _10sats: (Filter::LowerThan(Sats::_10.into()), value._10sats).into(), diff --git a/crates/brk_grouper/src/by_max_age.rs b/crates/brk_grouper/src/by_max_age.rs index d91a48f97..abad40848 100644 --- a/crates/brk_grouper/src/by_max_age.rs +++ b/crates/brk_grouper/src/by_max_age.rs @@ -78,6 +78,7 @@ impl ByMaxAge> { } impl From> for ByMaxAge> { + #[inline] fn from(value: ByMaxAge) -> Self { Self { _1w: (Filter::LowerThan(7), value._1w).into(), diff --git a/crates/brk_grouper/src/by_min_age.rs b/crates/brk_grouper/src/by_min_age.rs index 0f70ee79c..d37802979 100644 --- a/crates/brk_grouper/src/by_min_age.rs +++ b/crates/brk_grouper/src/by_min_age.rs @@ -79,6 +79,7 @@ impl ByMinAge> { } impl From> for ByMinAge> { + #[inline] fn from(value: ByMinAge) -> Self { Self { _1d: (Filter::GreaterOrEqual(1), value._1d).into(), diff --git a/crates/brk_grouper/src/by_spendable_type.rs b/crates/brk_grouper/src/by_spendable_type.rs index 7a211c406..6350f403e 100644 --- a/crates/brk_grouper/src/by_spendable_type.rs +++ b/crates/brk_grouper/src/by_spendable_type.rs @@ -114,6 +114,7 @@ impl BySpendableType> { } impl From> for BySpendableType> { + #[inline] fn from(value: BySpendableType) -> Self { Self { p2pk65: (Filter::Type(OutputType::P2PK65), value.p2pk65).into(), diff --git a/crates/brk_grouper/src/by_term.rs b/crates/brk_grouper/src/by_term.rs index 68389a6b2..322cf114d 100644 --- a/crates/brk_grouper/src/by_term.rs +++ b/crates/brk_grouper/src/by_term.rs @@ -23,6 +23,7 @@ impl ByTerm> { } impl From> for ByTerm> { + #[inline] fn from(value: ByTerm) -> Self { Self { short: (Filter::LowerThan(5 * 30), value.short).into(), diff --git a/crates/brk_grouper/src/filter.rs b/crates/brk_grouper/src/filter.rs index dde3831f2..055ed48be 100644 --- a/crates/brk_grouper/src/filter.rs +++ b/crates/brk_grouper/src/filter.rs @@ -71,6 +71,7 @@ impl Filtered { } impl From<(Filter, T)> for Filtered { + #[inline] fn from(value: (Filter, T)) -> Self { Self(value.0, value.1) } diff --git a/crates/brk_grouper/src/utxo.rs b/crates/brk_grouper/src/utxo.rs index d13208b6b..c46e508d9 100644 --- a/crates/brk_grouper/src/utxo.rs +++ b/crates/brk_grouper/src/utxo.rs @@ -82,6 +82,7 @@ impl UTXOGroups> { } impl From> for UTXOGroups> { + #[inline] fn from(value: UTXOGroups) -> Self { Self { all: (Filter::All, value.all).into(), diff --git a/crates/brk_indexer/BENCH.md b/crates/brk_indexer/BENCH.md index ee193329c..d979fea54 100644 --- a/crates/brk_indexer/BENCH.md +++ b/crates/brk_indexer/BENCH.md @@ -3,13 +3,13 @@ MBP M3 Pro 0..920750 -Time: 13h 6mn + +Time: 13h 6mn (checked) / 12h 20mn (unchecked) RAM: Peak: ~12GB -After finish: ~8GB -After restart ~6.5GB +After auto compaction: ~6.5GB -storage: 230GB +storage: 223GB mode: checked diff --git a/crates/brk_indexer/examples/indexer_read.rs b/crates/brk_indexer/examples/indexer_read.rs new file mode 100644 index 000000000..f3cb4d0a0 --- /dev/null +++ b/crates/brk_indexer/examples/indexer_read.rs @@ -0,0 +1,25 @@ +use brk_error::Result; +use brk_indexer::Indexer; +use brk_types::Sats; +use std::{fs, path::Path}; + +fn main() -> Result<()> { + brk_logger::init(Some(Path::new(".log")))?; + + let outputs_dir = Path::new(&std::env::var("HOME").unwrap()).join(".brk"); + fs::create_dir_all(&outputs_dir)?; + + let indexer = Indexer::forced_import(&outputs_dir)?; + + let mut sum = Sats::ZERO; + let mut count: usize = 0; + + for value in indexer.vecs.txoutindex_to_value.clean_values().unwrap() { + sum += value; + count += 1; + } + + println!("sum = {sum}, count = {count}"); + + Ok(()) +} diff --git a/crates/brk_indexer/examples/indexer_read_speed.rs b/crates/brk_indexer/examples/indexer_read_speed.rs new file mode 100644 index 000000000..32091ebae --- /dev/null +++ b/crates/brk_indexer/examples/indexer_read_speed.rs @@ -0,0 +1,102 @@ +use brk_error::Result; +use brk_indexer::Indexer; +use brk_types::Sats; +use std::{fs, path::Path, time::Instant}; + +fn run_benchmark(indexer: &Indexer) -> (Sats, std::time::Duration, usize) { + let start = Instant::now(); + let mut sum = Sats::ZERO; + let mut count = 0; + + for value in indexer.vecs.txoutindex_to_value.clean_values().unwrap() { + // for value in indexer.vecs.txoutindex_to_value.values() { + sum += value; + count += 1; + } + + let duration = start.elapsed(); + (sum, duration, count) +} + +fn main() -> Result<()> { + brk_logger::init(Some(Path::new(".log")))?; + + let outputs_dir = Path::new(&std::env::var("HOME").unwrap()).join(".brk"); + fs::create_dir_all(&outputs_dir)?; + + println!("\n╔════════════════════════════════════════════════════════╗"); + println!("║ BRK INDEXER SEQUENTIAL READ BENCHMARK ║"); + println!("╚════════════════════════════════════════════════════════╝\n"); + + println!("Loading indexer from: {}", outputs_dir.display()); + let indexer = Indexer::forced_import(&outputs_dir)?; + println!("✅ Indexer loaded\n"); + + // Warmup run + println!("🔥 Warmup run..."); + let (sum, duration, count) = run_benchmark(&indexer); + println!(" Sum: {} sats", sum); + println!(" Time: {:.3}s", duration.as_secs_f64()); + println!(" Count: {} values\n", count); + + // Benchmark runs + let num_runs = 4; + let mut throughputs: Vec = Vec::new(); + + println!("📊 Running {} benchmark iterations...\n", num_runs); + + for run in 1..=num_runs { + let (_, duration, count) = run_benchmark(&indexer); + let estimated_bytes = count * 8; + let throughput = estimated_bytes as f64 / duration.as_secs_f64() / (1024.0 * 1024.0); + let values_per_sec = count as f64 / duration.as_secs_f64() / 1_000_000.0; + + throughputs.push(throughput); + + println!( + "Run {:2}/{num_runs}: {:.3}s - {:>6.0} MB/s - {:>6.1}M values/s", + run, + duration.as_secs_f64(), + throughput, + values_per_sec + ); + } + + // Statistics + let mean = throughputs.iter().sum::() / throughputs.len() as f64; + let min = throughputs.iter().cloned().fold(f64::INFINITY, f64::min); + let max = throughputs + .iter() + .cloned() + .fold(f64::NEG_INFINITY, f64::max); + let variance = + throughputs.iter().map(|x| (x - mean).powi(2)).sum::() / throughputs.len() as f64; + let std_dev = variance.sqrt(); + let cv = (std_dev / mean) * 100.0; + + println!("\n╔════════════════════════════════════════════════════════╗"); + println!("║ 📊 SUMMARY STATISTICS ║"); + println!("╚════════════════════════════════════════════════════════╝\n"); + + println!( + "Values: {} ({:.2} MB)", + count, + (count * 8) as f64 / (1024.0 * 1024.0) + ); + println!("Mean: {:.0} MB/s", mean); + println!("Min: {:.0} MB/s", min); + println!("Max: {:.0} MB/s", max); + println!("StdDev: {:.1} MB/s", std_dev); + println!("Variance: {:.1}%", cv); + + if cv < 2.0 { + println!("✅ Excellent consistency"); + } else if cv < 5.0 { + println!("✅ Good consistency"); + } else { + println!("⚠️ High variance"); + } + + println!(); + Ok(()) +} diff --git a/crates/brk_indexer/examples/indexer_single_vs_multi.rs b/crates/brk_indexer/examples/indexer_single_vs_multi.rs index 84107ea9f..8594536a8 100644 --- a/crates/brk_indexer/examples/indexer_single_vs_multi.rs +++ b/crates/brk_indexer/examples/indexer_single_vs_multi.rs @@ -300,21 +300,21 @@ fn run_method2( .txoutindex_to_value .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); let output_types: Vec<_> = vecs .txoutindex_to_outputtype .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); let typeindexes: Vec<_> = vecs .txoutindex_to_typeindex .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); let _outputs: Vec<_> = (0..outputs_per_block) @@ -330,7 +330,7 @@ fn run_method2( .txinindex_to_outpoint .iter_at(input_block_start) .take(inputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); let txindex_to_first_txoutindex_reader = vecs.txindex_to_first_txoutindex.create_reader(); @@ -384,7 +384,7 @@ fn run_method4( vecs.txoutindex_to_value .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect::>() }); @@ -392,7 +392,7 @@ fn run_method4( vecs.txoutindex_to_outputtype .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect::>() }); @@ -400,7 +400,7 @@ fn run_method4( vecs.txoutindex_to_typeindex .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect::>() }); @@ -420,7 +420,7 @@ fn run_method4( .txinindex_to_outpoint .iter_at(input_block_start) .take(inputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); let txindex_to_first_txoutindex_reader = vecs.txindex_to_first_txoutindex.create_reader(); @@ -541,21 +541,21 @@ fn run_method6( .txoutindex_to_value .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); let output_types: Vec<_> = vecs .txoutindex_to_outputtype .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); let typeindexes: Vec<_> = vecs .txoutindex_to_typeindex .iter_at(block_start) .take(outputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); // Read inputs sequentially @@ -566,7 +566,7 @@ fn run_method6( .txinindex_to_outpoint .iter_at(input_block_start) .take(inputs_per_block) - .map(|(_, v)| v.into_owned()) + .map(|(_, v)| v) .collect(); let txindex_to_first_txoutindex_reader = vecs.txindex_to_first_txoutindex.create_reader(); diff --git a/crates/brk_indexer/src/indexes.rs b/crates/brk_indexer/src/indexes.rs index d43a70e5d..c76bece15 100644 --- a/crates/brk_indexer/src/indexes.rs +++ b/crates/brk_indexer/src/indexes.rs @@ -86,6 +86,7 @@ impl Indexes { } impl From<(Height, &mut Vecs, &Stores)> for Indexes { + #[inline] fn from((min_height, vecs, stores): (Height, &mut Vecs, &Stores)) -> Self { // Height at which we want to start: min last saved + 1 or 0 let vecs_starting_height = vecs.starting_height(); diff --git a/crates/brk_indexer/src/lib.rs b/crates/brk_indexer/src/lib.rs index c3e71fbeb..2b75f2ff6 100644 --- a/crates/brk_indexer/src/lib.rs +++ b/crates/brk_indexer/src/lib.rs @@ -81,7 +81,7 @@ impl Indexer { check_collisions: bool, ) -> Result { let (starting_indexes, prev_hash) = if let Some(hash) = - VecIterator::last(self.vecs.height_to_blockhash.iter()).map(|(_, v)| v.into_owned()) + VecIterator::last(self.vecs.height_to_blockhash.iter()).map(|(_, v)| v) { let (height, hash) = client.get_closest_valid_height(hash)?; let starting_indexes = @@ -265,13 +265,13 @@ impl Indexer { .ok_or(Error::Str("Expect txoutindex to not be none")) .inspect_err(|_| { dbg!(outpoint.txid, prev_txindex, vout); - })?.into_owned() + })? + vout; let outpoint = OutPoint::new(prev_txindex, vout); let outputtype = vecs.txoutindex_to_outputtype.get_pushed_or_read(txoutindex, &readers.txoutindex_to_outputtype)? - .ok_or(Error::Str("Expect outputtype to not be none"))?.into_owned(); + .ok_or(Error::Str("Expect outputtype to not be none"))?; let mut tuple = ( vin, @@ -286,7 +286,7 @@ impl Indexer { let typeindex = vecs .txoutindex_to_typeindex .get_pushed_or_read(txoutindex, &readers.txoutindex_to_typeindex)? - .ok_or(Error::Str("Expect typeindex to not be none"))?.into_owned(); + .ok_or(Error::Str("Expect typeindex to not be none"))?; tuple.3 = Some((outputtype, typeindex)); } @@ -377,56 +377,56 @@ impl Indexer { typeindex.into(), &readers.p2pk65addressindex_to_p2pk65bytes, )? - .map(|v| AddressBytes::from(v.into_owned())), + .map(AddressBytes::from), OutputType::P2PK33 => vecs .p2pk33addressindex_to_p2pk33bytes .get_pushed_or_read( typeindex.into(), &readers.p2pk33addressindex_to_p2pk33bytes, )? - .map(|v| AddressBytes::from(v.into_owned())), + .map(AddressBytes::from), OutputType::P2PKH => vecs .p2pkhaddressindex_to_p2pkhbytes .get_pushed_or_read( typeindex.into(), &readers.p2pkhaddressindex_to_p2pkhbytes, )? - .map(|v| AddressBytes::from(v.into_owned())), + .map(AddressBytes::from), OutputType::P2SH => vecs .p2shaddressindex_to_p2shbytes .get_pushed_or_read( typeindex.into(), &readers.p2shaddressindex_to_p2shbytes, )? - .map(|v| AddressBytes::from(v.into_owned())), + .map(AddressBytes::from), OutputType::P2WPKH => vecs .p2wpkhaddressindex_to_p2wpkhbytes .get_pushed_or_read( typeindex.into(), &readers.p2wpkhaddressindex_to_p2wpkhbytes, )? - .map(|v| AddressBytes::from(v.into_owned())), + .map(AddressBytes::from), OutputType::P2WSH => vecs .p2wshaddressindex_to_p2wshbytes .get_pushed_or_read( typeindex.into(), &readers.p2wshaddressindex_to_p2wshbytes, )? - .map(|v| AddressBytes::from(v.into_owned())), + .map(AddressBytes::from), OutputType::P2TR => vecs .p2traddressindex_to_p2trbytes .get_pushed_or_read( typeindex.into(), &readers.p2traddressindex_to_p2trbytes, )? - .map(|v| AddressBytes::from(v.into_owned())), + .map(AddressBytes::from), OutputType::P2A => vecs .p2aaddressindex_to_p2abytes .get_pushed_or_read( typeindex.into(), &readers.p2aaddressindex_to_p2abytes, )? - .map(|v| AddressBytes::from(v.into_owned())), + .map(AddressBytes::from), _ => { unreachable!() } @@ -677,8 +677,6 @@ impl Indexer { dbg!(txindex, len); })?; - let prev_txid = prev_txid.as_ref(); - // If another Txid needs to be added to the list // We need to check that it's also a coinbase tx otherwise par_iter inputs needs to be updated let only_known_dup_txids = [ @@ -694,7 +692,7 @@ impl Indexer { .into(), ]; - let is_dup = only_known_dup_txids.contains(prev_txid); + let is_dup = only_known_dup_txids.contains(&prev_txid); if !is_dup { dbg!(height, txindex, prev_txid, prev_txindex); diff --git a/crates/brk_indexer/src/stores_v2.rs b/crates/brk_indexer/src/stores_v2.rs index f3ce4e8e5..67b4b56b4 100644 --- a/crates/brk_indexer/src/stores_v2.rs +++ b/crates/brk_indexer/src/stores_v2.rs @@ -1,4 +1,4 @@ -use std::{borrow::Cow, fs, path::Path}; +use std::{fs, path::Path}; use brk_error::Result; use brk_grouper::ByAddressType; @@ -162,7 +162,7 @@ impl Stores { vecs.height_to_blockhash .iter_at(starting_indexes.height) .for_each(|(_, v)| { - let blockhashprefix = BlockHashPrefix::from(v.into_owned()); + let blockhashprefix = BlockHashPrefix::from(v); self.blockhashprefix_to_height.remove(blockhashprefix); }); @@ -176,15 +176,11 @@ impl Stores { .height_to_first_p2pk65addressindex .iter() .get(starting_indexes.height) - .map(Cow::into_owned) { let mut p2pk65addressindex_to_p2pk65bytes_iter = vecs.p2pk65addressindex_to_p2pk65bytes.iter(); - while let Some(typedbytes) = p2pk65addressindex_to_p2pk65bytes_iter - .get(index) - .map(Cow::into_owned) - { + while let Some(typedbytes) = p2pk65addressindex_to_p2pk65bytes_iter.get(index) { let bytes = AddressBytes::from(typedbytes); let hash = AddressBytesHash::from(&bytes); self.addressbyteshash_to_typeindex.remove(hash); @@ -196,15 +192,11 @@ impl Stores { .height_to_first_p2pk33addressindex .iter() .get(starting_indexes.height) - .map(Cow::into_owned) { let mut p2pk33addressindex_to_p2pk33bytes_iter = vecs.p2pk33addressindex_to_p2pk33bytes.iter(); - while let Some(typedbytes) = p2pk33addressindex_to_p2pk33bytes_iter - .get(index) - .map(Cow::into_owned) - { + while let Some(typedbytes) = p2pk33addressindex_to_p2pk33bytes_iter.get(index) { let bytes = AddressBytes::from(typedbytes); let hash = AddressBytesHash::from(&bytes); self.addressbyteshash_to_typeindex.remove(hash); @@ -216,15 +208,11 @@ impl Stores { .height_to_first_p2pkhaddressindex .iter() .get(starting_indexes.height) - .map(Cow::into_owned) { let mut p2pkhaddressindex_to_p2pkhbytes_iter = vecs.p2pkhaddressindex_to_p2pkhbytes.iter(); - while let Some(typedbytes) = p2pkhaddressindex_to_p2pkhbytes_iter - .get(index) - .map(Cow::into_owned) - { + while let Some(typedbytes) = p2pkhaddressindex_to_p2pkhbytes_iter.get(index) { let bytes = AddressBytes::from(typedbytes); let hash = AddressBytesHash::from(&bytes); self.addressbyteshash_to_typeindex.remove(hash); @@ -236,15 +224,11 @@ impl Stores { .height_to_first_p2shaddressindex .iter() .get(starting_indexes.height) - .map(Cow::into_owned) { let mut p2shaddressindex_to_p2shbytes_iter = vecs.p2shaddressindex_to_p2shbytes.iter(); - while let Some(typedbytes) = p2shaddressindex_to_p2shbytes_iter - .get(index) - .map(Cow::into_owned) - { + while let Some(typedbytes) = p2shaddressindex_to_p2shbytes_iter.get(index) { let bytes = AddressBytes::from(typedbytes); let hash = AddressBytesHash::from(&bytes); self.addressbyteshash_to_typeindex.remove(hash); @@ -256,15 +240,11 @@ impl Stores { .height_to_first_p2traddressindex .iter() .get(starting_indexes.height) - .map(Cow::into_owned) { let mut p2traddressindex_to_p2trbytes_iter = vecs.p2traddressindex_to_p2trbytes.iter(); - while let Some(typedbytes) = p2traddressindex_to_p2trbytes_iter - .get(index) - .map(Cow::into_owned) - { + while let Some(typedbytes) = p2traddressindex_to_p2trbytes_iter.get(index) { let bytes = AddressBytes::from(typedbytes); let hash = AddressBytesHash::from(&bytes); self.addressbyteshash_to_typeindex.remove(hash); @@ -276,15 +256,11 @@ impl Stores { .height_to_first_p2wpkhaddressindex .iter() .get(starting_indexes.height) - .map(Cow::into_owned) { let mut p2wpkhaddressindex_to_p2wpkhbytes_iter = vecs.p2wpkhaddressindex_to_p2wpkhbytes.iter(); - while let Some(typedbytes) = p2wpkhaddressindex_to_p2wpkhbytes_iter - .get(index) - .map(Cow::into_owned) - { + while let Some(typedbytes) = p2wpkhaddressindex_to_p2wpkhbytes_iter.get(index) { let bytes = AddressBytes::from(typedbytes); let hash = AddressBytesHash::from(&bytes); self.addressbyteshash_to_typeindex.remove(hash); @@ -296,15 +272,11 @@ impl Stores { .height_to_first_p2wshaddressindex .iter() .get(starting_indexes.height) - .map(Cow::into_owned) { let mut p2wshaddressindex_to_p2wshbytes_iter = vecs.p2wshaddressindex_to_p2wshbytes.iter(); - while let Some(typedbytes) = p2wshaddressindex_to_p2wshbytes_iter - .get(index) - .map(Cow::into_owned) - { + while let Some(typedbytes) = p2wshaddressindex_to_p2wshbytes_iter.get(index) { let bytes = AddressBytes::from(typedbytes); let hash = AddressBytesHash::from(&bytes); self.addressbyteshash_to_typeindex.remove(hash); @@ -316,14 +288,10 @@ impl Stores { .height_to_first_p2aaddressindex .iter() .get(starting_indexes.height) - .map(Cow::into_owned) { let mut p2aaddressindex_to_p2abytes_iter = vecs.p2aaddressindex_to_p2abytes.iter(); - while let Some(typedbytes) = p2aaddressindex_to_p2abytes_iter - .get(index) - .map(Cow::into_owned) - { + while let Some(typedbytes) = p2aaddressindex_to_p2abytes_iter.get(index) { let bytes = AddressBytes::from(typedbytes); let hash = AddressBytesHash::from(&bytes); self.addressbyteshash_to_typeindex.remove(hash); @@ -340,7 +308,7 @@ impl Stores { vecs.txindex_to_txid .iter_at(starting_indexes.txindex) .for_each(|(txindex, txid)| { - let txidprefix = TxidPrefix::from(&txid.into_owned()); + let txidprefix = TxidPrefix::from(&txid); // "d5d27987d2a3dfc724e359870c6644b40e497bdc0589a033220fe15429d88599" let is_not_first_dup = txindex != TxIndex::new(142783) @@ -368,15 +336,7 @@ impl Stores { ) .filter(|((_, outputtype), _)| outputtype.is_address()) .for_each(|((txoutindex, outputtype), (_, typeindex))| { - let outputtype = outputtype.into_owned(); - let typeindex = typeindex.into_owned(); - - let txindex = vecs - .txoutindex_to_txindex - .iter() - .get(txoutindex) - .unwrap() - .into_owned(); + let txindex = vecs.txoutindex_to_txindex.iter().get(txoutindex).unwrap(); let vout = Vout::from( txoutindex.to_usize() @@ -385,7 +345,6 @@ impl Stores { .iter() .get(txindex) .unwrap() - .into_owned() .to_usize(), ); let outpoint = OutPoint::new(txindex, vout); @@ -400,8 +359,6 @@ impl Stores { vecs.txinindex_to_outpoint .iter_at(starting_indexes.txinindex) .for_each(|(_, outpoint)| { - let outpoint = outpoint.into_owned(); - if outpoint.is_coinbase() { return; } @@ -415,7 +372,6 @@ impl Stores { .iter() .get(txindex) .unwrap() - .into_owned() + vout; // Only process if this output was created before the rollback point @@ -424,16 +380,11 @@ impl Stores { .txoutindex_to_outputtype .iter() .get(txoutindex) - .unwrap() - .into_owned(); + .unwrap(); if outputtype.is_address() { - let typeindex = vecs - .txoutindex_to_typeindex - .iter() - .get(txoutindex) - .unwrap() - .into_owned(); + let typeindex = + vecs.txoutindex_to_typeindex.iter().get(txoutindex).unwrap(); self.addresstype_to_typeindex_and_unspentoutpoint .get_mut(outputtype) diff --git a/crates/brk_query/src/params.rs b/crates/brk_query/src/params.rs index d4d83ff0f..d1a967750 100644 --- a/crates/brk_query/src/params.rs +++ b/crates/brk_query/src/params.rs @@ -1,7 +1,6 @@ use std::ops::Deref; use brk_types::{Format, Index, Metric, Metrics}; -use derive_deref::Deref; use schemars::JsonSchema; use serde::Deserialize; @@ -28,6 +27,7 @@ impl Deref for Params { } impl From<(Index, Metric, ParamsOpt)> for Params { + #[inline] fn from((index, metric, rest): (Index, Metric, ParamsOpt)) -> Self { Self { index, @@ -38,6 +38,7 @@ impl From<(Index, Metric, ParamsOpt)> for Params { } impl From<(Index, Metrics, ParamsOpt)> for Params { + #[inline] fn from((index, metrics, rest): (Index, Metrics, ParamsOpt)) -> Self { Self { index, @@ -118,6 +119,7 @@ pub struct ParamsDeprec { } impl From for Params { + #[inline] fn from(value: ParamsDeprec) -> Self { Params { index: value.index, diff --git a/crates/brk_reader/src/xor_bytes.rs b/crates/brk_reader/src/xor_bytes.rs index c54ba4d48..3747ace0d 100644 --- a/crates/brk_reader/src/xor_bytes.rs +++ b/crates/brk_reader/src/xor_bytes.rs @@ -8,6 +8,7 @@ pub const XOR_LEN: usize = 8; pub struct XORBytes([u8; XOR_LEN]); impl From<&Path> for XORBytes { + #[inline] fn from(value: &Path) -> Self { Self( fs::read(value.join("xor.dat")) diff --git a/crates/brk_store/src/v2/mod.rs b/crates/brk_store/src/v2/mod.rs index 732a04f92..467d9e328 100644 --- a/crates/brk_store/src/v2/mod.rs +++ b/crates/brk_store/src/v2/mod.rs @@ -265,6 +265,7 @@ where K: Into, V: Into, { + #[inline] fn from(value: Item) -> Self { match value { Item::Value { key, value } => Self { diff --git a/crates/brk_types/src/address.rs b/crates/brk_types/src/address.rs index a802f7876..4d2be6d8e 100644 --- a/crates/brk_types/src/address.rs +++ b/crates/brk_types/src/address.rs @@ -24,6 +24,7 @@ impl fmt::Display for Address { } impl From for Address { + #[inline] fn from(address: String) -> Self { Self { address } } diff --git a/crates/brk_types/src/addressbytes.rs b/crates/brk_types/src/addressbytes.rs index fe88aff0f..3d0c89d9b 100644 --- a/crates/brk_types/src/addressbytes.rs +++ b/crates/brk_types/src/addressbytes.rs @@ -130,48 +130,56 @@ impl TryFrom<(&ScriptBuf, OutputType)> for AddressBytes { } impl From for AddressBytes { + #[inline] fn from(value: P2PK65Bytes) -> Self { Self::P2PK65(Box::new(value)) } } impl From for AddressBytes { + #[inline] fn from(value: P2PK33Bytes) -> Self { Self::P2PK33(Box::new(value)) } } impl From for AddressBytes { + #[inline] fn from(value: P2PKHBytes) -> Self { Self::P2PKH(Box::new(value)) } } impl From for AddressBytes { + #[inline] fn from(value: P2SHBytes) -> Self { Self::P2SH(Box::new(value)) } } impl From for AddressBytes { + #[inline] fn from(value: P2WPKHBytes) -> Self { Self::P2WPKH(Box::new(value)) } } impl From for AddressBytes { + #[inline] fn from(value: P2WSHBytes) -> Self { Self::P2WSH(Box::new(value)) } } impl From for AddressBytes { + #[inline] fn from(value: P2TRBytes) -> Self { Self::P2TR(Box::new(value)) } } impl From for AddressBytes { + #[inline] fn from(value: P2ABytes) -> Self { Self::P2A(Box::new(value)) } diff --git a/crates/brk_types/src/addressbyteshash.rs b/crates/brk_types/src/addressbyteshash.rs index eb673262d..6363f4327 100644 --- a/crates/brk_types/src/addressbyteshash.rs +++ b/crates/brk_types/src/addressbyteshash.rs @@ -22,24 +22,28 @@ use super::AddressBytes; pub struct AddressBytesHash(u64); impl From<&AddressBytes> for AddressBytesHash { + #[inline] fn from(address_bytes: &AddressBytes) -> Self { Self(address_bytes.hash()) } } impl From for AddressBytesHash { + #[inline] fn from(value: ByteView) -> Self { Self::read_from_bytes(&value).unwrap() } } impl From for ByteView { + #[inline] fn from(value: AddressBytesHash) -> Self { Self::from(&value) } } impl From<&AddressBytesHash> for ByteView { + #[inline] fn from(value: &AddressBytesHash) -> Self { Self::new(value.as_bytes()) } diff --git a/crates/brk_types/src/anyaddressindex.rs b/crates/brk_types/src/anyaddressindex.rs index 5946dff28..1f492b81d 100644 --- a/crates/brk_types/src/anyaddressindex.rs +++ b/crates/brk_types/src/anyaddressindex.rs @@ -17,6 +17,7 @@ impl AnyAddressIndex { } impl From for AnyAddressIndex { + #[inline] fn from(value: LoadedAddressIndex) -> Self { if u32::from(value) >= MIN_EMPTY_INDEX { panic!("{value} is higher than MIN_EMPTY_INDEX ({MIN_EMPTY_INDEX})") @@ -26,6 +27,7 @@ impl From for AnyAddressIndex { } impl From for AnyAddressIndex { + #[inline] fn from(value: EmptyAddressIndex) -> Self { Self(*value + MIN_EMPTY_INDEX) } @@ -54,6 +56,7 @@ pub enum AnyAddressDataIndexEnum { } impl From for AnyAddressDataIndexEnum { + #[inline] fn from(value: AnyAddressIndex) -> Self { let uvalue = u32::from(value.0); if uvalue >= MIN_EMPTY_INDEX { diff --git a/crates/brk_types/src/bitcoin.rs b/crates/brk_types/src/bitcoin.rs index caf006aaf..8255667ef 100644 --- a/crates/brk_types/src/bitcoin.rs +++ b/crates/brk_types/src/bitcoin.rs @@ -68,30 +68,35 @@ impl Div for Bitcoin { } impl From for Bitcoin { + #[inline] fn from(value: Sats) -> Self { Self(f64::from(value) / (f64::from(Sats::ONE_BTC))) } } impl From for Bitcoin { + #[inline] fn from(value: f64) -> Self { Self(value) } } impl From for Bitcoin { + #[inline] fn from(value: StoredF64) -> Self { Self(*value) } } impl From for f64 { + #[inline] fn from(value: Bitcoin) -> Self { value.0 } } impl From for Bitcoin { + #[inline] fn from(value: usize) -> Self { Self(value as f64) } diff --git a/crates/brk_types/src/block.rs b/crates/brk_types/src/block.rs index 048ba6b71..2afaaa395 100644 --- a/crates/brk_types/src/block.rs +++ b/crates/brk_types/src/block.rs @@ -33,6 +33,7 @@ impl Block { } impl From<(Height, bitcoin::Block)> for Block { + #[inline] fn from((height, block): (Height, bitcoin::Block)) -> Self { Self::from((height, block.block_hash(), block)) } @@ -57,6 +58,7 @@ impl From<(Height, BlockHash, bitcoin::Block)> for Block { } impl From for Block { + #[inline] fn from(value: ReadBlock) -> Self { value.block } @@ -77,6 +79,7 @@ pub struct ReadBlock { } impl From<(Block, BlkMetadata, Vec)> for ReadBlock { + #[inline] fn from((block, metadata, tx_metadata): (Block, BlkMetadata, Vec)) -> Self { Self { block, diff --git a/crates/brk_types/src/blockhash.rs b/crates/brk_types/src/blockhash.rs index 804cc25be..04de16ef2 100644 --- a/crates/brk_types/src/blockhash.rs +++ b/crates/brk_types/src/blockhash.rs @@ -22,30 +22,35 @@ impl TryFrom<&str> for BlockHash { } impl From for BlockHash { + #[inline] fn from(value: bitcoin::BlockHash) -> Self { unsafe { mem::transmute(value) } } } impl From<&bitcoin::BlockHash> for &BlockHash { + #[inline] fn from(value: &bitcoin::BlockHash) -> Self { unsafe { mem::transmute(value) } } } impl From for bitcoin::BlockHash { + #[inline] fn from(value: BlockHash) -> Self { unsafe { mem::transmute(value) } } } impl From<&BlockHash> for &bitcoin::BlockHash { + #[inline] fn from(value: &BlockHash) -> Self { unsafe { mem::transmute(value) } } } impl From<&BlockHash> for bitcoin::BlockHash { + #[inline] fn from(value: &BlockHash) -> Self { bitcoin::BlockHash::from_slice(&value.0).unwrap() } diff --git a/crates/brk_types/src/blockhashprefix.rs b/crates/brk_types/src/blockhashprefix.rs index 23658d3c7..583640785 100644 --- a/crates/brk_types/src/blockhashprefix.rs +++ b/crates/brk_types/src/blockhashprefix.rs @@ -24,30 +24,35 @@ use super::BlockHash; pub struct BlockHashPrefix(u64); impl From for BlockHashPrefix { + #[inline] fn from(value: BlockHash) -> Self { Self::from(&value) } } impl From<&BlockHash> for BlockHashPrefix { + #[inline] fn from(value: &BlockHash) -> Self { Self(u64::from_ne_bytes(copy_first_8bytes(&value[..]).unwrap())) } } impl From for BlockHashPrefix { + #[inline] fn from(value: ByteView) -> Self { Self::read_from_bytes(&value).unwrap() } } impl From<&BlockHashPrefix> for ByteView { + #[inline] fn from(value: &BlockHashPrefix) -> Self { Self::new(value.as_bytes()) } } impl From for ByteView { + #[inline] fn from(value: BlockHashPrefix) -> Self { Self::from(&value) } diff --git a/crates/brk_types/src/bytes.rs b/crates/brk_types/src/bytes.rs index dc3282904..c6769e70b 100644 --- a/crates/brk_types/src/bytes.rs +++ b/crates/brk_types/src/bytes.rs @@ -20,6 +20,7 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; )] pub struct U8x2([u8; 2]); impl From<&[u8]> for U8x2 { + #[inline] fn from(slice: &[u8]) -> Self { let mut arr = [0; 2]; arr.copy_from_slice(slice); @@ -45,6 +46,7 @@ impl From<&[u8]> for U8x2 { )] pub struct U8x20([u8; 20]); impl From<&[u8]> for U8x20 { + #[inline] fn from(slice: &[u8]) -> Self { let mut arr = [0; 20]; arr.copy_from_slice(slice); @@ -70,6 +72,7 @@ impl From<&[u8]> for U8x20 { )] pub struct U8x32([u8; 32]); impl From<&[u8]> for U8x32 { + #[inline] fn from(slice: &[u8]) -> Self { let mut arr = [0; 32]; arr.copy_from_slice(slice); @@ -95,6 +98,7 @@ impl From<&[u8]> for U8x32 { )] pub struct U8x33(#[serde(with = "serde_bytes")] [u8; 33]); impl From<&[u8]> for U8x33 { + #[inline] fn from(slice: &[u8]) -> Self { let mut arr = [0; 33]; arr.copy_from_slice(slice); @@ -120,6 +124,7 @@ impl From<&[u8]> for U8x33 { )] pub struct U8x65(#[serde(with = "serde_bytes")] [u8; 65]); impl From<&[u8]> for U8x65 { + #[inline] fn from(slice: &[u8]) -> Self { let mut arr = [0; 65]; arr.copy_from_slice(slice); diff --git a/crates/brk_types/src/cents.rs b/crates/brk_types/src/cents.rs index 64ee633ad..33f60a6e3 100644 --- a/crates/brk_types/src/cents.rs +++ b/crates/brk_types/src/cents.rs @@ -47,30 +47,35 @@ impl Cents { } impl From for Cents { + #[inline] fn from(value: Dollars) -> Self { Self((*value * 100.0).round() as i64) } } impl From for f64 { + #[inline] fn from(value: Cents) -> Self { value.0 as f64 } } impl From for Cents { + #[inline] fn from(value: i64) -> Self { Self(value) } } impl From for Cents { + #[inline] fn from(value: u64) -> Self { Self(value as i64) } } impl From for usize { + #[inline] fn from(value: Cents) -> Self { if value.0 < 0 { panic!() @@ -80,18 +85,21 @@ impl From for usize { } impl From for Cents { + #[inline] fn from(value: usize) -> Self { Self(value as i64) } } impl From for i64 { + #[inline] fn from(value: Cents) -> Self { value.0 } } impl From for u64 { + #[inline] fn from(value: Cents) -> Self { if value.0 < 0 { panic!("Shouldn't convert neg cents to u64") @@ -122,6 +130,7 @@ impl Div for Cents { } impl From for Cents { + #[inline] fn from(value: u128) -> Self { if value > i64::MAX as u128 { panic!("u128 bigger than i64") @@ -131,6 +140,7 @@ impl From for Cents { } impl From for u128 { + #[inline] fn from(value: Cents) -> Self { if value.0 < 0 { panic!("Shouldn't convert neg cents to u128") diff --git a/crates/brk_types/src/date.rs b/crates/brk_types/src/date.rs index 7b2987adb..af6de7ab6 100644 --- a/crates/brk_types/src/date.rs +++ b/crates/brk_types/src/date.rs @@ -77,24 +77,28 @@ impl Default for Date { } impl From for Date { + #[inline] fn from(value: Date_) -> Self { Self::new(value.year() as u16, value.month() as u8, value.day() as u8) } } impl From for Date_ { + #[inline] fn from(value: Date) -> Self { Self::new(value.year() as i16, value.month() as i8, value.day() as i8).unwrap() } } impl From for jiff::Timestamp { + #[inline] fn from(value: Date) -> Self { Self::from(Timestamp::from(value)) } } impl From for Date { + #[inline] fn from(value: Timestamp) -> Self { Self::from(Date_::from( jiff::Timestamp::from(value).to_zoned(TimeZone::UTC), @@ -103,6 +107,7 @@ impl From for Date { } impl From for Date { + #[inline] fn from(value: DateIndex) -> Self { if value == DateIndex::default() { Date::INDEX_ZERO diff --git a/crates/brk_types/src/dateindex.rs b/crates/brk_types/src/dateindex.rs index 98d720cf6..e64f252a1 100644 --- a/crates/brk_types/src/dateindex.rs +++ b/crates/brk_types/src/dateindex.rs @@ -35,24 +35,28 @@ impl DateIndex { } impl From for usize { + #[inline] fn from(value: DateIndex) -> Self { value.0 as usize } } impl From for u64 { + #[inline] fn from(value: DateIndex) -> Self { value.0 as u64 } } impl From for DateIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for i64 { + #[inline] fn from(value: DateIndex) -> Self { value.0 as i64 } diff --git a/crates/brk_types/src/decadeindex.rs b/crates/brk_types/src/decadeindex.rs index 6a355c7da..f152a89de 100644 --- a/crates/brk_types/src/decadeindex.rs +++ b/crates/brk_types/src/decadeindex.rs @@ -31,24 +31,28 @@ use super::{Date, DateIndex, YearIndex}; pub struct DecadeIndex(u16); impl From for DecadeIndex { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for u16 { + #[inline] fn from(value: DecadeIndex) -> Self { value.0 } } impl From for DecadeIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for usize { + #[inline] fn from(value: DecadeIndex) -> Self { value.0 as usize } @@ -84,12 +88,14 @@ impl Div for DecadeIndex { } impl From for DecadeIndex { + #[inline] fn from(value: DateIndex) -> Self { Self::from(Date::from(value)) } } impl From for DecadeIndex { + #[inline] fn from(value: Date) -> Self { let year = value.year(); if year < 2000 { @@ -106,6 +112,7 @@ impl CheckedSub for DecadeIndex { } impl From for DecadeIndex { + #[inline] fn from(value: YearIndex) -> Self { let v = usize::from(value); if v == 0 { diff --git a/crates/brk_types/src/difficultyepoch.rs b/crates/brk_types/src/difficultyepoch.rs index 25344b4ea..69f7d565c 100644 --- a/crates/brk_types/src/difficultyepoch.rs +++ b/crates/brk_types/src/difficultyepoch.rs @@ -33,18 +33,21 @@ pub const BLOCKS_PER_DIFF_EPOCHS: u32 = 2016; pub struct DifficultyEpoch(u16); impl From for DifficultyEpoch { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for DifficultyEpoch { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for usize { + #[inline] fn from(value: DifficultyEpoch) -> Self { value.0 as usize } @@ -80,6 +83,7 @@ impl Div for DifficultyEpoch { } impl From for DifficultyEpoch { + #[inline] fn from(value: Height) -> Self { Self((u32::from(value) / BLOCKS_PER_DIFF_EPOCHS) as u16) } diff --git a/crates/brk_types/src/dollars.rs b/crates/brk_types/src/dollars.rs index 468319668..e206ea8bf 100644 --- a/crates/brk_types/src/dollars.rs +++ b/crates/brk_types/src/dollars.rs @@ -56,60 +56,70 @@ impl Dollars { } impl From for Dollars { + #[inline] fn from(value: f32) -> Self { Self(value as f64) } } impl From for Dollars { + #[inline] fn from(value: f64) -> Self { Self(value) } } impl From for Dollars { + #[inline] fn from(value: Cents) -> Self { Self(f64::from(value) / 100.0) } } impl From for f32 { + #[inline] fn from(value: Dollars) -> Self { value.0 as f32 } } impl From for f64 { + #[inline] fn from(value: Dollars) -> Self { value.0 } } impl From> for Dollars { + #[inline] fn from(value: Open) -> Self { *value } } impl From> for Dollars { + #[inline] fn from(value: High) -> Self { *value } } impl From> for Dollars { + #[inline] fn from(value: Low) -> Self { *value } } impl From> for Dollars { + #[inline] fn from(value: Close) -> Self { *value } } impl From for Dollars { + #[inline] fn from(value: usize) -> Self { Self(value as f64) } @@ -301,24 +311,28 @@ impl Mul for Dollars { } impl From for Dollars { + #[inline] fn from(value: u128) -> Self { Self::from(Cents::from(value)) } } impl From for Dollars { + #[inline] fn from(value: StoredF64) -> Self { Self(*value) } } impl From> for u128 { + #[inline] fn from(value: Close) -> Self { u128::from(*value) } } impl From for u128 { + #[inline] fn from(value: Dollars) -> Self { u128::from(Cents::from(value)) } diff --git a/crates/brk_types/src/emptyaddressdata.rs b/crates/brk_types/src/emptyaddressdata.rs index 44bf973e5..f48d5d467 100644 --- a/crates/brk_types/src/emptyaddressdata.rs +++ b/crates/brk_types/src/emptyaddressdata.rs @@ -16,12 +16,14 @@ pub struct EmptyAddressData { } impl From for EmptyAddressData { + #[inline] fn from(value: LoadedAddressData) -> Self { Self::from(&value) } } impl From<&LoadedAddressData> for EmptyAddressData { + #[inline] fn from(value: &LoadedAddressData) -> Self { if value.sent != value.received { dbg!(&value); diff --git a/crates/brk_types/src/emptyaddressindex.rs b/crates/brk_types/src/emptyaddressindex.rs index 7e3d9b90e..eada35e28 100644 --- a/crates/brk_types/src/emptyaddressindex.rs +++ b/crates/brk_types/src/emptyaddressindex.rs @@ -27,23 +27,27 @@ use crate::TypeIndex; pub struct EmptyAddressIndex(TypeIndex); impl From for EmptyAddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for EmptyAddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } } impl From for EmptyAddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for usize { + #[inline] fn from(value: EmptyAddressIndex) -> Self { usize::from(value.0) } diff --git a/crates/brk_types/src/emptyoutputindex.rs b/crates/brk_types/src/emptyoutputindex.rs index 37477a8c5..d9ff8b2fa 100644 --- a/crates/brk_types/src/emptyoutputindex.rs +++ b/crates/brk_types/src/emptyoutputindex.rs @@ -27,21 +27,25 @@ use crate::TypeIndex; )] pub struct EmptyOutputIndex(TypeIndex); impl From for EmptyOutputIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for u64 { + #[inline] fn from(value: EmptyOutputIndex) -> Self { Self::from(value.0) } } impl From for usize { + #[inline] fn from(value: EmptyOutputIndex) -> Self { Self::from(value.0) } } impl From for EmptyOutputIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/feerate.rs b/crates/brk_types/src/feerate.rs index 9e055bdc8..1df95a900 100644 --- a/crates/brk_types/src/feerate.rs +++ b/crates/brk_types/src/feerate.rs @@ -25,6 +25,7 @@ use super::{Sats, StoredU64}; pub struct FeeRate(f64); impl From<(Sats, StoredU64)> for FeeRate { + #[inline] fn from((sats, vsize): (Sats, StoredU64)) -> Self { let sats = u64::from(sats); let vsize = u64::from(vsize); @@ -33,11 +34,13 @@ impl From<(Sats, StoredU64)> for FeeRate { } impl From for FeeRate { + #[inline] fn from(value: f64) -> Self { Self(value) } } impl From for f64 { + #[inline] fn from(value: FeeRate) -> Self { value.0 } @@ -64,6 +67,7 @@ impl Div for FeeRate { } impl From for FeeRate { + #[inline] fn from(value: usize) -> Self { Self(value as f64) } diff --git a/crates/brk_types/src/format.rs b/crates/brk_types/src/format.rs index 4c7bb5419..482ec45c7 100644 --- a/crates/brk_types/src/format.rs +++ b/crates/brk_types/src/format.rs @@ -13,6 +13,7 @@ pub enum Format { } impl From> for Format { + #[inline] fn from(value: Option) -> Self { if let Some(value) = value { let value = value.to_lowercase(); diff --git a/crates/brk_types/src/halvingepoch.rs b/crates/brk_types/src/halvingepoch.rs index 4319ca02f..9e383ac77 100644 --- a/crates/brk_types/src/halvingepoch.rs +++ b/crates/brk_types/src/halvingepoch.rs @@ -39,18 +39,21 @@ impl HalvingEpoch { } impl From for HalvingEpoch { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for HalvingEpoch { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for usize { + #[inline] fn from(value: HalvingEpoch) -> Self { value.0 as usize } @@ -79,6 +82,7 @@ impl Add for HalvingEpoch { } impl From for HalvingEpoch { + #[inline] fn from(value: Height) -> Self { Self((u32::from(value) / BLOCKS_PER_HALVING) as u16) } diff --git a/crates/brk_types/src/height.rs b/crates/brk_types/src/height.rs index c341dc8cd..4b7c532a2 100644 --- a/crates/brk_types/src/height.rs +++ b/crates/brk_types/src/height.rs @@ -173,46 +173,54 @@ impl Rem for Height { } impl From for Height { + #[inline] fn from(value: u32) -> Self { Self(value) } } impl From for Height { + #[inline] fn from(value: u64) -> Self { Self(value as u32) } } impl From for Height { + #[inline] fn from(value: StoredU64) -> Self { Self(*value as u32) } } impl From for Height { + #[inline] fn from(value: usize) -> Self { Self(value as u32) } } impl From for usize { + #[inline] fn from(value: Height) -> Self { value.0 as usize } } impl From for u32 { + #[inline] fn from(value: Height) -> Self { value.0 } } impl From for u64 { + #[inline] fn from(value: Height) -> Self { value.0 as u64 } } impl From for Height { + #[inline] fn from(value: bitcoin::locktime::absolute::Height) -> Self { Self(value.to_consensus_u32()) } @@ -226,18 +234,21 @@ impl TryFrom<&std::path::Path> for Height { } impl From for Height { + #[inline] fn from(value: ByteView) -> Self { Self(u32::from_be_bytes(copy_first_4bytes(&value).unwrap())) } } impl From for ByteView { + #[inline] fn from(value: Height) -> Self { Self::new(&value.0.to_be_bytes()) } } impl From for Height { + #[inline] fn from(value: Stamp) -> Self { let u = u64::from(value); assert!(u <= u32::MAX as u64); @@ -246,6 +257,7 @@ impl From for Height { } impl From for Stamp { + #[inline] fn from(value: Height) -> Self { Self::from(value.0 as u64) } diff --git a/crates/brk_types/src/loadedaddressdata.rs b/crates/brk_types/src/loadedaddressdata.rs index 79e40e88f..f91d9fe48 100644 --- a/crates/brk_types/src/loadedaddressdata.rs +++ b/crates/brk_types/src/loadedaddressdata.rs @@ -104,12 +104,14 @@ impl LoadedAddressData { } impl From for LoadedAddressData { + #[inline] fn from(value: EmptyAddressData) -> Self { Self::from(&value) } } impl From<&EmptyAddressData> for LoadedAddressData { + #[inline] fn from(value: &EmptyAddressData) -> Self { Self { tx_count: value.tx_count, diff --git a/crates/brk_types/src/loadedaddressindex.rs b/crates/brk_types/src/loadedaddressindex.rs index a280ff510..6ad82e5b0 100644 --- a/crates/brk_types/src/loadedaddressindex.rs +++ b/crates/brk_types/src/loadedaddressindex.rs @@ -27,22 +27,26 @@ use crate::TypeIndex; pub struct LoadedAddressIndex(TypeIndex); impl From for LoadedAddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for LoadedAddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } } impl From for usize { + #[inline] fn from(value: LoadedAddressIndex) -> Self { usize::from(value.0) } } impl From for u32 { + #[inline] fn from(value: LoadedAddressIndex) -> Self { u32::from(value.0) } diff --git a/crates/brk_types/src/metric.rs b/crates/brk_types/src/metric.rs index 5abdf1b20..99c332fec 100644 --- a/crates/brk_types/src/metric.rs +++ b/crates/brk_types/src/metric.rs @@ -12,12 +12,14 @@ pub struct Metric { } impl From for Metric { + #[inline] fn from(metric: String) -> Self { Self { metric } } } impl From<&str> for Metric { + #[inline] fn from(metric: &str) -> Self { Self { metric: metric.to_string(), diff --git a/crates/brk_types/src/metrics.rs b/crates/brk_types/src/metrics.rs index cf2326daa..9f0f97784 100644 --- a/crates/brk_types/src/metrics.rs +++ b/crates/brk_types/src/metrics.rs @@ -16,6 +16,7 @@ const MAX_VECS: usize = 32; const MAX_STRING_SIZE: usize = 64 * MAX_VECS; impl From for Metrics { + #[inline] fn from(metric: Metric) -> Self { Self { metrics: vec![metric], @@ -24,12 +25,14 @@ impl From for Metrics { } impl From for Metrics { + #[inline] fn from(value: String) -> Self { Self::from(Metric::from(value.replace("-", "_").to_lowercase())) } } impl<'a> From> for Metrics { + #[inline] fn from(value: Vec<&'a str>) -> Self { Self { metrics: value diff --git a/crates/brk_types/src/monthindex.rs b/crates/brk_types/src/monthindex.rs index d697d9d02..334612085 100644 --- a/crates/brk_types/src/monthindex.rs +++ b/crates/brk_types/src/monthindex.rs @@ -31,30 +31,35 @@ use super::{Date, DateIndex, YearIndex}; pub struct MonthIndex(u16); impl From for MonthIndex { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for u16 { + #[inline] fn from(value: MonthIndex) -> Self { value.0 } } impl From for MonthIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for u64 { + #[inline] fn from(value: MonthIndex) -> Self { value.0 as u64 } } impl From for usize { + #[inline] fn from(value: MonthIndex) -> Self { value.0 as usize } @@ -90,12 +95,14 @@ impl Div for MonthIndex { } impl From for MonthIndex { + #[inline] fn from(value: DateIndex) -> Self { Self::from(Date::from(value)) } } impl From for MonthIndex { + #[inline] fn from(value: Date) -> Self { Self(u16::from(YearIndex::from(value)) * 12 + value.month() as u16 - 1) } diff --git a/crates/brk_types/src/ohlc.rs b/crates/brk_types/src/ohlc.rs index 401a04061..4d8e8c946 100644 --- a/crates/brk_types/src/ohlc.rs +++ b/crates/brk_types/src/ohlc.rs @@ -23,6 +23,7 @@ pub struct OHLCCents { } impl From<(Open, High, Low, Close)> for OHLCCents { + #[inline] fn from(value: (Open, High, Low, Close)) -> Self { Self { open: value.0, @@ -34,6 +35,7 @@ impl From<(Open, High, Low, Close)> for OHLCCents { } impl From> for OHLCCents { + #[inline] fn from(value: Close) -> Self { Self { open: Open::from(value), @@ -92,6 +94,7 @@ impl Serialize for OHLCDollars { } impl From<(Open, High, Low, Close)> for OHLCDollars { + #[inline] fn from(value: (Open, High, Low, Close)) -> Self { Self { open: value.0, @@ -103,6 +106,7 @@ impl From<(Open, High, Low, Close)> for OHLC } impl From> for OHLCDollars { + #[inline] fn from(value: Close) -> Self { Self { open: Open::from(value), @@ -114,12 +118,14 @@ impl From> for OHLCDollars { } impl From for OHLCDollars { + #[inline] fn from(value: OHLCCents) -> Self { Self::from(&value) } } impl From<&OHLCCents> for OHLCDollars { + #[inline] fn from(value: &OHLCCents) -> Self { Self { open: value.open.into(), @@ -164,6 +170,7 @@ impl Serialize for OHLCSats { } impl From<(Open, High, Low, Close)> for OHLCSats { + #[inline] fn from(value: (Open, High, Low, Close)) -> Self { Self { open: value.0, @@ -175,6 +182,7 @@ impl From<(Open, High, Low, Close)> for OHLCSats { } impl From> for OHLCSats { + #[inline] fn from(value: Close) -> Self { Self { open: Open::from(value), @@ -226,6 +234,7 @@ impl From for Open where T: From, { + #[inline] fn from(value: usize) -> Self { Self(T::from(value)) } @@ -235,6 +244,7 @@ impl From for Open where T: From, { + #[inline] fn from(value: f64) -> Self { Self(T::from(value)) } @@ -244,6 +254,7 @@ impl From> for f64 where f64: From, { + #[inline] fn from(value: Open) -> Self { Self::from(value.0) } @@ -253,6 +264,7 @@ impl From> for StoredF64 where StoredF64: From, { + #[inline] fn from(value: Open) -> Self { Self::from(value.0) } @@ -262,12 +274,14 @@ impl From> for Open where T: Copy, { + #[inline] fn from(value: Close) -> Self { Self(*value) } } impl From> for Open { + #[inline] fn from(value: Open) -> Self { Self(Dollars::from(*value)) } @@ -342,6 +356,7 @@ impl From for High where T: From, { + #[inline] fn from(value: usize) -> Self { Self(T::from(value)) } @@ -351,6 +366,7 @@ impl From for High where T: From, { + #[inline] fn from(value: f64) -> Self { Self(T::from(value)) } @@ -360,6 +376,7 @@ impl From> for f64 where f64: From, { + #[inline] fn from(value: High) -> Self { Self::from(value.0) } @@ -369,6 +386,7 @@ impl From> for StoredF64 where StoredF64: From, { + #[inline] fn from(value: High) -> Self { Self::from(value.0) } @@ -378,12 +396,14 @@ impl From> for High where T: Copy, { + #[inline] fn from(value: Close) -> Self { Self(*value) } } impl From> for High { + #[inline] fn from(value: High) -> Self { Self(Dollars::from(*value)) } @@ -458,6 +478,7 @@ impl From for Low where T: From, { + #[inline] fn from(value: usize) -> Self { Self(T::from(value)) } @@ -467,6 +488,7 @@ impl From for Low where T: From, { + #[inline] fn from(value: f64) -> Self { Self(T::from(value)) } @@ -476,6 +498,7 @@ impl From> for f64 where f64: From, { + #[inline] fn from(value: Low) -> Self { Self::from(value.0) } @@ -485,6 +508,7 @@ impl From> for StoredF64 where StoredF64: From, { + #[inline] fn from(value: Low) -> Self { Self::from(value.0) } @@ -494,12 +518,14 @@ impl From> for Low where T: Copy, { + #[inline] fn from(value: Close) -> Self { Self(*value) } } impl From> for Low { + #[inline] fn from(value: Low) -> Self { Self(Dollars::from(*value)) } @@ -575,6 +601,7 @@ impl From for Close where T: From, { + #[inline] fn from(value: usize) -> Self { Self(T::from(value)) } @@ -584,6 +611,7 @@ impl From for Close where T: From, { + #[inline] fn from(value: f32) -> Self { Self(T::from(value)) } @@ -593,6 +621,7 @@ impl From for Close where T: From, { + #[inline] fn from(value: f64) -> Self { Self(T::from(value)) } @@ -602,6 +631,7 @@ impl From> for f32 where f32: From, { + #[inline] fn from(value: Close) -> Self { Self::from(value.0) } @@ -611,6 +641,7 @@ impl From> for f64 where f64: From, { + #[inline] fn from(value: Close) -> Self { Self::from(value.0) } @@ -620,6 +651,7 @@ impl From> for StoredF64 where StoredF64: From, { + #[inline] fn from(value: Close) -> Self { Self::from(value.0) } @@ -629,9 +661,11 @@ where // where // B: From, // { -// fn from(value: Close) -> Self { +// #[inline] +// fn from(value: Close) -> Self { // Self(B::from(*value)) impl From> for Close { + #[inline] fn from(value: Close) -> Self { Self(Dollars::from(*value)) } diff --git a/crates/brk_types/src/opreturnindex.rs b/crates/brk_types/src/opreturnindex.rs index 1fb8de761..56a2eeb18 100644 --- a/crates/brk_types/src/opreturnindex.rs +++ b/crates/brk_types/src/opreturnindex.rs @@ -28,21 +28,25 @@ use crate::TypeIndex; pub struct OpReturnIndex(TypeIndex); impl From for OpReturnIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for usize { + #[inline] fn from(value: OpReturnIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: OpReturnIndex) -> Self { Self::from(*value) } } impl From for OpReturnIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/outputtype.rs b/crates/brk_types/src/outputtype.rs index 4732fefcc..7d8e977fc 100644 --- a/crates/brk_types/src/outputtype.rs +++ b/crates/brk_types/src/outputtype.rs @@ -836,6 +836,7 @@ impl OutputType { } impl From<&ScriptBuf> for OutputType { + #[inline] fn from(script: &ScriptBuf) -> Self { if script.is_p2pk() { let bytes = script.as_bytes(); @@ -877,6 +878,7 @@ impl From<&ScriptBuf> for OutputType { } impl From for OutputType { + #[inline] fn from(value: AddressType) -> Self { match value { AddressType::P2a => Self::P2A, diff --git a/crates/brk_types/src/p2aaddressindex.rs b/crates/brk_types/src/p2aaddressindex.rs index 2c139d36a..964ff86f7 100644 --- a/crates/brk_types/src/p2aaddressindex.rs +++ b/crates/brk_types/src/p2aaddressindex.rs @@ -27,36 +27,43 @@ use crate::TypeIndex; )] pub struct P2AAddressIndex(TypeIndex); impl From for P2AAddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for TypeIndex { + #[inline] fn from(value: P2AAddressIndex) -> Self { value.0 } } impl From for u32 { + #[inline] fn from(value: P2AAddressIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2AAddressIndex) -> Self { Self::from(*value) } } impl From for P2AAddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for usize { + #[inline] fn from(value: P2AAddressIndex) -> Self { Self::from(*value) } } impl From for P2AAddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2abytes.rs b/crates/brk_types/src/p2abytes.rs index 1598660d9..b2d1dd67e 100644 --- a/crates/brk_types/src/p2abytes.rs +++ b/crates/brk_types/src/p2abytes.rs @@ -24,12 +24,14 @@ use crate::U8x2; pub struct P2ABytes(U8x2); impl From<&[u8]> for P2ABytes { + #[inline] fn from(value: &[u8]) -> Self { Self(U8x2::from(value)) } } impl From for P2ABytes { + #[inline] fn from(value: U8x2) -> Self { Self(value) } diff --git a/crates/brk_types/src/p2msoutputindex.rs b/crates/brk_types/src/p2msoutputindex.rs index 600d13ddd..4fdb14369 100644 --- a/crates/brk_types/src/p2msoutputindex.rs +++ b/crates/brk_types/src/p2msoutputindex.rs @@ -27,21 +27,25 @@ use crate::TypeIndex; )] pub struct P2MSOutputIndex(TypeIndex); impl From for P2MSOutputIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for usize { + #[inline] fn from(value: P2MSOutputIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2MSOutputIndex) -> Self { Self::from(*value) } } impl From for P2MSOutputIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2pk33addressindex.rs b/crates/brk_types/src/p2pk33addressindex.rs index 7089b540d..d5c5f508e 100644 --- a/crates/brk_types/src/p2pk33addressindex.rs +++ b/crates/brk_types/src/p2pk33addressindex.rs @@ -27,36 +27,43 @@ use crate::TypeIndex; )] pub struct P2PK33AddressIndex(TypeIndex); impl From for P2PK33AddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for TypeIndex { + #[inline] fn from(value: P2PK33AddressIndex) -> Self { value.0 } } impl From for u32 { + #[inline] fn from(value: P2PK33AddressIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2PK33AddressIndex) -> Self { Self::from(*value) } } impl From for P2PK33AddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for usize { + #[inline] fn from(value: P2PK33AddressIndex) -> Self { Self::from(*value) } } impl From for P2PK33AddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2pk33bytes.rs b/crates/brk_types/src/p2pk33bytes.rs index 1f2da2710..7ded0132c 100644 --- a/crates/brk_types/src/p2pk33bytes.rs +++ b/crates/brk_types/src/p2pk33bytes.rs @@ -24,12 +24,14 @@ use crate::U8x33; pub struct P2PK33Bytes(U8x33); impl From<&[u8]> for P2PK33Bytes { + #[inline] fn from(value: &[u8]) -> Self { Self(U8x33::from(value)) } } impl From for P2PK33Bytes { + #[inline] fn from(value: U8x33) -> Self { Self(value) } diff --git a/crates/brk_types/src/p2pk65addressindex.rs b/crates/brk_types/src/p2pk65addressindex.rs index 263223b0b..df4e9f89a 100644 --- a/crates/brk_types/src/p2pk65addressindex.rs +++ b/crates/brk_types/src/p2pk65addressindex.rs @@ -27,36 +27,43 @@ use crate::TypeIndex; )] pub struct P2PK65AddressIndex(TypeIndex); impl From for P2PK65AddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for TypeIndex { + #[inline] fn from(value: P2PK65AddressIndex) -> Self { value.0 } } impl From for u32 { + #[inline] fn from(value: P2PK65AddressIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2PK65AddressIndex) -> Self { Self::from(*value) } } impl From for usize { + #[inline] fn from(value: P2PK65AddressIndex) -> Self { Self::from(*value) } } impl From for P2PK65AddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for P2PK65AddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2pk65bytes.rs b/crates/brk_types/src/p2pk65bytes.rs index 6daf853fd..b771c4e0f 100644 --- a/crates/brk_types/src/p2pk65bytes.rs +++ b/crates/brk_types/src/p2pk65bytes.rs @@ -24,12 +24,14 @@ use crate::U8x65; pub struct P2PK65Bytes(U8x65); impl From<&[u8]> for P2PK65Bytes { + #[inline] fn from(value: &[u8]) -> Self { Self(U8x65::from(value)) } } impl From for P2PK65Bytes { + #[inline] fn from(value: U8x65) -> Self { Self(value) } diff --git a/crates/brk_types/src/p2pkhaddressindex.rs b/crates/brk_types/src/p2pkhaddressindex.rs index 3548bebeb..e5f047a48 100644 --- a/crates/brk_types/src/p2pkhaddressindex.rs +++ b/crates/brk_types/src/p2pkhaddressindex.rs @@ -27,36 +27,43 @@ use crate::TypeIndex; )] pub struct P2PKHAddressIndex(TypeIndex); impl From for P2PKHAddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for TypeIndex { + #[inline] fn from(value: P2PKHAddressIndex) -> Self { value.0 } } impl From for usize { + #[inline] fn from(value: P2PKHAddressIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2PKHAddressIndex) -> Self { Self::from(*value) } } impl From for u32 { + #[inline] fn from(value: P2PKHAddressIndex) -> Self { Self::from(*value) } } impl From for P2PKHAddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for P2PKHAddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2pkhbytes.rs b/crates/brk_types/src/p2pkhbytes.rs index 8001ca37e..29a295a24 100644 --- a/crates/brk_types/src/p2pkhbytes.rs +++ b/crates/brk_types/src/p2pkhbytes.rs @@ -24,12 +24,14 @@ use crate::U8x20; pub struct P2PKHBytes(U8x20); impl From<&[u8]> for P2PKHBytes { + #[inline] fn from(value: &[u8]) -> Self { Self(U8x20::from(value)) } } impl From for P2PKHBytes { + #[inline] fn from(value: U8x20) -> Self { Self(value) } diff --git a/crates/brk_types/src/p2shaddressindex.rs b/crates/brk_types/src/p2shaddressindex.rs index 31c5ca2e5..8b1dddcd2 100644 --- a/crates/brk_types/src/p2shaddressindex.rs +++ b/crates/brk_types/src/p2shaddressindex.rs @@ -27,41 +27,49 @@ use crate::TypeIndex; )] pub struct P2SHAddressIndex(TypeIndex); impl From for P2SHAddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for TypeIndex { + #[inline] fn from(value: P2SHAddressIndex) -> Self { value.0 } } impl From for u32 { + #[inline] fn from(value: P2SHAddressIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2SHAddressIndex) -> Self { Self::from(*value) } } impl From for P2SHAddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for P2SHAddressIndex { + #[inline] fn from(value: u64) -> Self { Self(TypeIndex::from(value)) } } impl From for usize { + #[inline] fn from(value: P2SHAddressIndex) -> Self { Self::from(*value) } } impl From for P2SHAddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2shbytes.rs b/crates/brk_types/src/p2shbytes.rs index 662abc557..394c1c15a 100644 --- a/crates/brk_types/src/p2shbytes.rs +++ b/crates/brk_types/src/p2shbytes.rs @@ -24,12 +24,14 @@ use crate::U8x20; pub struct P2SHBytes(U8x20); impl From<&[u8]> for P2SHBytes { + #[inline] fn from(value: &[u8]) -> Self { Self(U8x20::from(value)) } } impl From for P2SHBytes { + #[inline] fn from(value: U8x20) -> Self { Self(value) } diff --git a/crates/brk_types/src/p2traddressindex.rs b/crates/brk_types/src/p2traddressindex.rs index 74eb25421..56ad36c10 100644 --- a/crates/brk_types/src/p2traddressindex.rs +++ b/crates/brk_types/src/p2traddressindex.rs @@ -27,36 +27,43 @@ use crate::TypeIndex; )] pub struct P2TRAddressIndex(TypeIndex); impl From for P2TRAddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for TypeIndex { + #[inline] fn from(value: P2TRAddressIndex) -> Self { value.0 } } impl From for u32 { + #[inline] fn from(value: P2TRAddressIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2TRAddressIndex) -> Self { Self::from(*value) } } impl From for P2TRAddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for usize { + #[inline] fn from(value: P2TRAddressIndex) -> Self { Self::from(*value) } } impl From for P2TRAddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2trbytes.rs b/crates/brk_types/src/p2trbytes.rs index 52c0007eb..5df37b298 100644 --- a/crates/brk_types/src/p2trbytes.rs +++ b/crates/brk_types/src/p2trbytes.rs @@ -24,12 +24,14 @@ use crate::U8x32; pub struct P2TRBytes(U8x32); impl From<&[u8]> for P2TRBytes { + #[inline] fn from(value: &[u8]) -> Self { Self(U8x32::from(value)) } } impl From for P2TRBytes { + #[inline] fn from(value: U8x32) -> Self { Self(value) } diff --git a/crates/brk_types/src/p2wpkhaddressindex.rs b/crates/brk_types/src/p2wpkhaddressindex.rs index 77812f5f7..40cd64601 100644 --- a/crates/brk_types/src/p2wpkhaddressindex.rs +++ b/crates/brk_types/src/p2wpkhaddressindex.rs @@ -27,36 +27,43 @@ use crate::TypeIndex; )] pub struct P2WPKHAddressIndex(TypeIndex); impl From for P2WPKHAddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for TypeIndex { + #[inline] fn from(value: P2WPKHAddressIndex) -> Self { value.0 } } impl From for u32 { + #[inline] fn from(value: P2WPKHAddressIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2WPKHAddressIndex) -> Self { Self::from(*value) } } impl From for usize { + #[inline] fn from(value: P2WPKHAddressIndex) -> Self { Self::from(*value) } } impl From for P2WPKHAddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for P2WPKHAddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2wpkhbytes.rs b/crates/brk_types/src/p2wpkhbytes.rs index ec9d83e16..69e445bed 100644 --- a/crates/brk_types/src/p2wpkhbytes.rs +++ b/crates/brk_types/src/p2wpkhbytes.rs @@ -24,12 +24,14 @@ use crate::U8x20; pub struct P2WPKHBytes(U8x20); impl From<&[u8]> for P2WPKHBytes { + #[inline] fn from(value: &[u8]) -> Self { Self(U8x20::from(value)) } } impl From for P2WPKHBytes { + #[inline] fn from(value: U8x20) -> Self { Self(value) } diff --git a/crates/brk_types/src/p2wshaddressindex.rs b/crates/brk_types/src/p2wshaddressindex.rs index 7da8a901f..12f0878a8 100644 --- a/crates/brk_types/src/p2wshaddressindex.rs +++ b/crates/brk_types/src/p2wshaddressindex.rs @@ -27,36 +27,43 @@ use crate::TypeIndex; )] pub struct P2WSHAddressIndex(TypeIndex); impl From for P2WSHAddressIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for TypeIndex { + #[inline] fn from(value: P2WSHAddressIndex) -> Self { value.0 } } impl From for u32 { + #[inline] fn from(value: P2WSHAddressIndex) -> Self { Self::from(*value) } } impl From for u64 { + #[inline] fn from(value: P2WSHAddressIndex) -> Self { Self::from(*value) } } impl From for P2WSHAddressIndex { + #[inline] fn from(value: u32) -> Self { Self(TypeIndex::from(value)) } } impl From for usize { + #[inline] fn from(value: P2WSHAddressIndex) -> Self { Self::from(*value) } } impl From for P2WSHAddressIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/p2wshbytes.rs b/crates/brk_types/src/p2wshbytes.rs index 3bb91cba1..e80f7bb18 100644 --- a/crates/brk_types/src/p2wshbytes.rs +++ b/crates/brk_types/src/p2wshbytes.rs @@ -24,12 +24,14 @@ use crate::U8x32; pub struct P2WSHBytes(U8x32); impl From<&[u8]> for P2WSHBytes { + #[inline] fn from(value: &[u8]) -> Self { Self(U8x32::from(value)) } } impl From for P2WSHBytes { + #[inline] fn from(value: U8x32) -> Self { Self(value) } diff --git a/crates/brk_types/src/pool.rs b/crates/brk_types/src/pool.rs index b9c329a50..e28d40a4c 100644 --- a/crates/brk_types/src/pool.rs +++ b/crates/brk_types/src/pool.rs @@ -19,6 +19,7 @@ impl Pool { } impl From<(usize, JSONPool)> for Pool { + #[inline] fn from((index, pool): (usize, JSONPool)) -> Self { Self { id: (index as u8).into(), diff --git a/crates/brk_types/src/pools.rs b/crates/brk_types/src/pools.rs index 37c78d112..f15176116 100644 --- a/crates/brk_types/src/pools.rs +++ b/crates/brk_types/src/pools.rs @@ -1168,6 +1168,7 @@ pub fn pools() -> &'static Pools { } impl From<[JSONPool; POOL_COUNT]> for Pools { + #[inline] fn from(value: [JSONPool; POOL_COUNT]) -> Self { Pools( value diff --git a/crates/brk_types/src/quarterindex.rs b/crates/brk_types/src/quarterindex.rs index bb32d7245..6e45b8119 100644 --- a/crates/brk_types/src/quarterindex.rs +++ b/crates/brk_types/src/quarterindex.rs @@ -31,24 +31,28 @@ use super::MonthIndex; pub struct QuarterIndex(u16); impl From for QuarterIndex { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for QuarterIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for u16 { + #[inline] fn from(value: QuarterIndex) -> Self { value.0 } } impl From for usize { + #[inline] fn from(value: QuarterIndex) -> Self { value.0 as usize } @@ -84,6 +88,7 @@ impl Div for QuarterIndex { } impl From for QuarterIndex { + #[inline] fn from(value: MonthIndex) -> Self { Self((usize::from(value) / 3) as u16) } diff --git a/crates/brk_types/src/rawlocktime.rs b/crates/brk_types/src/rawlocktime.rs index f4cb8e6f4..03f817a69 100644 --- a/crates/brk_types/src/rawlocktime.rs +++ b/crates/brk_types/src/rawlocktime.rs @@ -20,12 +20,14 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; pub struct RawLockTime(u32); impl From for RawLockTime { + #[inline] fn from(value: LockTime) -> Self { Self(value.to_consensus_u32()) } } impl From for LockTime { + #[inline] fn from(value: RawLockTime) -> Self { let value = value.0; if value < LOCK_TIME_THRESHOLD { diff --git a/crates/brk_types/src/sats.rs b/crates/brk_types/src/sats.rs index c5f3925bb..c87597989 100644 --- a/crates/brk_types/src/sats.rs +++ b/crates/brk_types/src/sats.rs @@ -81,6 +81,15 @@ impl Add for Sats { type Output = Self; fn add(self, rhs: Self) -> Self::Output { Self::from(self.0 + rhs.0) + // Self::from( + // self.0 + // .checked_add(rhs.0) + // .or_else(|| { + // dbg!(rhs); + // panic!(); + // }) + // .unwrap(), + // ) } } @@ -185,59 +194,69 @@ impl Div for Sats { } impl From for Sats { + #[inline] fn from(value: u64) -> Self { Self(value) } } impl From for Sats { + #[inline] fn from(value: usize) -> Self { Self(value as u64) } } impl From for Sats { + #[inline] fn from(value: f64) -> Self { Self(value.round() as u64) } } impl From for f64 { + #[inline] fn from(value: Sats) -> Self { value.0 as f64 } } impl From for usize { + #[inline] fn from(value: Sats) -> Self { value.0 as usize } } impl From for Sats { + #[inline] fn from(value: Amount) -> Self { Self(value.to_sat()) } } impl From for Amount { + #[inline] fn from(value: Sats) -> Self { Self::from_sat(value.0) } } impl From for Sats { + #[inline] fn from(value: Bitcoin) -> Self { Self((f64::from(value) * (Sats::ONE_BTC.0 as f64)).round() as u64) } } impl From for u64 { + #[inline] fn from(value: Sats) -> Self { value.0 } } impl From for Sats { + #[inline] fn from(value: u128) -> Self { if value > u64::MAX as u128 { panic!("u128 bigger than u64") @@ -247,6 +266,7 @@ impl From for Sats { } impl From for u128 { + #[inline] fn from(value: Sats) -> Self { value.0 as u128 } diff --git a/crates/brk_types/src/semesterindex.rs b/crates/brk_types/src/semesterindex.rs index 8650239ff..3b3ea7c8f 100644 --- a/crates/brk_types/src/semesterindex.rs +++ b/crates/brk_types/src/semesterindex.rs @@ -31,24 +31,28 @@ use super::MonthIndex; pub struct SemesterIndex(u16); impl From for SemesterIndex { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for SemesterIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for u16 { + #[inline] fn from(value: SemesterIndex) -> Self { value.0 } } impl From for usize { + #[inline] fn from(value: SemesterIndex) -> Self { value.0 as usize } @@ -84,6 +88,7 @@ impl Div for SemesterIndex { } impl From for SemesterIndex { + #[inline] fn from(value: MonthIndex) -> Self { Self((usize::from(value) / 6) as u16) } diff --git a/crates/brk_types/src/stored_bool.rs b/crates/brk_types/src/stored_bool.rs index b60957c99..8224b8362 100644 --- a/crates/brk_types/src/stored_bool.rs +++ b/crates/brk_types/src/stored_bool.rs @@ -38,12 +38,14 @@ impl StoredBool { } impl From for StoredBool { + #[inline] fn from(value: bool) -> Self { if value { Self(1) } else { Self(0) } } } impl From for usize { + #[inline] fn from(value: StoredBool) -> Self { value.0 as usize } diff --git a/crates/brk_types/src/stored_f32.rs b/crates/brk_types/src/stored_f32.rs index 78bc253f2..71af8b01c 100644 --- a/crates/brk_types/src/stored_f32.rs +++ b/crates/brk_types/src/stored_f32.rs @@ -37,12 +37,14 @@ impl StoredF32 { } impl From for StoredF32 { + #[inline] fn from(value: f32) -> Self { Self(value) } } impl From for StoredF32 { + #[inline] fn from(value: f64) -> Self { if value > f32::MAX as f64 { panic!("f64 is too big") @@ -52,24 +54,28 @@ impl From for StoredF32 { } impl From for f64 { + #[inline] fn from(value: StoredF32) -> Self { value.0 as f64 } } impl From for StoredF32 { + #[inline] fn from(value: StoredF64) -> Self { Self(*value as f32) } } impl From for StoredF32 { + #[inline] fn from(value: usize) -> Self { Self(value as f32) } } impl From for StoredF32 { + #[inline] fn from(value: StoredU32) -> Self { Self(f32::from(value)) } @@ -115,18 +121,21 @@ impl AddAssign for StoredF32 { } impl From for f32 { + #[inline] fn from(value: StoredF32) -> Self { value.0 } } impl From for StoredF32 { + #[inline] fn from(value: Dollars) -> Self { StoredF32::from(f64::from(value)) } } impl From> for StoredF32 { + #[inline] fn from(value: Close) -> Self { Self::from(*value) } diff --git a/crates/brk_types/src/stored_f64.rs b/crates/brk_types/src/stored_f64.rs index fa5a94b42..c6568a589 100644 --- a/crates/brk_types/src/stored_f64.rs +++ b/crates/brk_types/src/stored_f64.rs @@ -34,18 +34,21 @@ impl StoredF64 { } impl From for StoredF64 { + #[inline] fn from(value: f64) -> Self { Self(value) } } impl From for StoredF64 { + #[inline] fn from(value: f32) -> Self { Self(value as f64) } } impl From for StoredF64 { + #[inline] fn from(value: usize) -> Self { Self(value as f64) } @@ -113,18 +116,21 @@ impl AddAssign for StoredF64 { } impl From for f64 { + #[inline] fn from(value: StoredF64) -> Self { value.0 } } impl From for f32 { + #[inline] fn from(value: StoredF64) -> Self { value.0 as f32 } } impl From for StoredF64 { + #[inline] fn from(value: Dollars) -> Self { Self(f64::from(value)) } @@ -169,6 +175,7 @@ impl Ord for StoredF64 { } impl From for StoredF64 { + #[inline] fn from(value: Bitcoin) -> Self { Self(f64::from(value)) } diff --git a/crates/brk_types/src/stored_i16.rs b/crates/brk_types/src/stored_i16.rs index d09ee64e4..cc7b9ad76 100644 --- a/crates/brk_types/src/stored_i16.rs +++ b/crates/brk_types/src/stored_i16.rs @@ -33,12 +33,14 @@ impl StoredI16 { } impl From for StoredI16 { + #[inline] fn from(value: i16) -> Self { Self(value) } } impl From for StoredI16 { + #[inline] fn from(value: usize) -> Self { if value > i16::MAX as usize { panic!("usize too big (value = {value})") @@ -74,6 +76,7 @@ impl AddAssign for StoredI16 { } impl From for StoredI16 { + #[inline] fn from(value: f64) -> Self { if value < 0.0 || value > i16::MAX as f64 { panic!() @@ -83,12 +86,14 @@ impl From for StoredI16 { } impl From for f64 { + #[inline] fn from(value: StoredI16) -> Self { value.0 as f64 } } impl From for usize { + #[inline] fn from(value: StoredI16) -> Self { value.0 as usize } diff --git a/crates/brk_types/src/stored_string.rs b/crates/brk_types/src/stored_string.rs index f5a314bf6..eabea2b7a 100644 --- a/crates/brk_types/src/stored_string.rs +++ b/crates/brk_types/src/stored_string.rs @@ -23,18 +23,21 @@ impl StoredString { } impl From for StoredString { + #[inline] fn from(value: String) -> Self { Self(value) } } impl From> for StoredString { + #[inline] fn from(value: Cow<'_, str>) -> Self { Self(value.to_string()) } } impl From for StoredString { + #[inline] fn from(value: ByteView) -> Self { let bytes = &*value; Self(String::from_utf8_lossy(bytes).into_owned()) @@ -42,12 +45,14 @@ impl From for StoredString { } impl From for ByteView { + #[inline] fn from(value: StoredString) -> Self { Self::from(&value) } } impl From<&StoredString> for ByteView { + #[inline] fn from(value: &StoredString) -> Self { Self::new(value.as_bytes()) } diff --git a/crates/brk_types/src/stored_u16.rs b/crates/brk_types/src/stored_u16.rs index 724aa081c..261ec154a 100644 --- a/crates/brk_types/src/stored_u16.rs +++ b/crates/brk_types/src/stored_u16.rs @@ -42,12 +42,14 @@ impl StoredU16 { } impl From for StoredU16 { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for StoredU16 { + #[inline] fn from(value: usize) -> Self { if value > u16::MAX as usize { panic!("usize too big (value = {value})") @@ -83,6 +85,7 @@ impl AddAssign for StoredU16 { } impl From for StoredU16 { + #[inline] fn from(value: f64) -> Self { if value < 0.0 || value > u16::MAX as f64 { panic!() @@ -92,84 +95,98 @@ impl From for StoredU16 { } impl From for f64 { + #[inline] fn from(value: StoredU16) -> Self { value.0 as f64 } } impl From for usize { + #[inline] fn from(value: StoredU16) -> Self { value.0 as usize } } impl From for StoredU16 { + #[inline] fn from(value: P2PK65AddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: P2PK33AddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: P2PKHAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: OpReturnIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: P2MSOutputIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: P2SHAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: P2WSHAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: P2WPKHAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: P2TRAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: P2AAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: UnknownOutputIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU16 { + #[inline] fn from(value: EmptyOutputIndex) -> Self { Self::from(usize::from(value)) } diff --git a/crates/brk_types/src/stored_u32.rs b/crates/brk_types/src/stored_u32.rs index 5c8ae6296..96b0fca17 100644 --- a/crates/brk_types/src/stored_u32.rs +++ b/crates/brk_types/src/stored_u32.rs @@ -46,18 +46,21 @@ impl StoredU32 { } impl From for StoredU32 { + #[inline] fn from(value: u32) -> Self { Self(value) } } impl From for f32 { + #[inline] fn from(value: StoredU32) -> Self { value.0 as f32 } } impl From for StoredU32 { + #[inline] fn from(value: usize) -> Self { if value > u32::MAX as usize { panic!("usize too big (value = {value})") @@ -113,6 +116,7 @@ impl Mul for StoredU32 { } impl From for StoredU32 { + #[inline] fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { panic!() @@ -122,84 +126,98 @@ impl From for StoredU32 { } impl From for f64 { + #[inline] fn from(value: StoredU32) -> Self { value.0 as f64 } } impl From for usize { + #[inline] fn from(value: StoredU32) -> Self { value.0 as usize } } impl From for StoredU32 { + #[inline] fn from(value: P2PK65AddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: P2PK33AddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: P2PKHAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: OpReturnIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: P2MSOutputIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: P2SHAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: P2WSHAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: P2WPKHAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: P2TRAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: P2AAddressIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: UnknownOutputIndex) -> Self { Self::from(usize::from(value)) } } impl From for StoredU32 { + #[inline] fn from(value: EmptyOutputIndex) -> Self { Self::from(usize::from(value)) } diff --git a/crates/brk_types/src/stored_u64.rs b/crates/brk_types/src/stored_u64.rs index 185122650..44150afc4 100644 --- a/crates/brk_types/src/stored_u64.rs +++ b/crates/brk_types/src/stored_u64.rs @@ -7,9 +7,9 @@ use vecdb::{CheckedSub, PrintableIndex, StoredCompressed}; use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; use super::{ - DateIndex, EmptyOutputIndex, Height, TxInIndex, MonthIndex, OpReturnIndex, TxOutIndex, - P2AAddressIndex, P2MSOutputIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, - P2SHAddressIndex, P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxIndex, + DateIndex, EmptyOutputIndex, Height, MonthIndex, OpReturnIndex, P2AAddressIndex, + P2MSOutputIndex, P2PK33AddressIndex, P2PK65AddressIndex, P2PKHAddressIndex, P2SHAddressIndex, + P2TRAddressIndex, P2WPKHAddressIndex, P2WSHAddressIndex, TxInIndex, TxIndex, TxOutIndex, UnknownOutputIndex, YearIndex, }; @@ -42,24 +42,28 @@ impl StoredU64 { } impl From for StoredU64 { + #[inline] fn from(value: u64) -> Self { Self(value) } } impl From for u64 { + #[inline] fn from(value: StoredU64) -> Self { value.0 } } impl From for usize { + #[inline] fn from(value: StoredU64) -> Self { value.0 as usize } } impl From for StoredU64 { + #[inline] fn from(value: usize) -> Self { Self(value as u64) } @@ -92,6 +96,7 @@ impl AddAssign for StoredU64 { } impl From for StoredU64 { + #[inline] fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { panic!() @@ -101,120 +106,140 @@ impl From for StoredU64 { } impl From for f64 { + #[inline] fn from(value: StoredU64) -> Self { value.0 as f64 } } impl From for StoredU64 { + #[inline] fn from(value: TxIndex) -> Self { Self(*value as u64) } } impl From for StoredU64 { + #[inline] fn from(value: TxInIndex) -> Self { Self(*value) } } impl From for StoredU64 { + #[inline] fn from(value: Height) -> Self { Self(*value as u64) } } impl From for StoredU64 { + #[inline] fn from(value: TxOutIndex) -> Self { Self(*value) } } impl From for StoredU64 { + #[inline] fn from(value: DateIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: MonthIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: YearIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2PK65AddressIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2PK33AddressIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2PKHAddressIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: OpReturnIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2MSOutputIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2SHAddressIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2WSHAddressIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2WPKHAddressIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2TRAddressIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: P2AAddressIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: UnknownOutputIndex) -> Self { Self::from(u64::from(value)) } } impl From for StoredU64 { + #[inline] fn from(value: EmptyOutputIndex) -> Self { Self::from(u64::from(value)) } diff --git a/crates/brk_types/src/stored_u8.rs b/crates/brk_types/src/stored_u8.rs index 55cce6d8c..13340c83a 100644 --- a/crates/brk_types/src/stored_u8.rs +++ b/crates/brk_types/src/stored_u8.rs @@ -34,12 +34,14 @@ impl StoredU8 { } impl From for StoredU8 { + #[inline] fn from(value: u8) -> Self { Self(value) } } impl From for StoredU8 { + #[inline] fn from(value: usize) -> Self { Self(value as u8) } @@ -72,6 +74,7 @@ impl AddAssign for StoredU8 { } impl From for StoredU8 { + #[inline] fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { panic!() @@ -81,6 +84,7 @@ impl From for StoredU8 { } impl From for f64 { + #[inline] fn from(value: StoredU8) -> Self { value.0 as f64 } @@ -94,6 +98,7 @@ impl Add for StoredU8 { } impl From for usize { + #[inline] fn from(value: StoredU8) -> Self { value.0 as usize } diff --git a/crates/brk_types/src/timestamp.rs b/crates/brk_types/src/timestamp.rs index 9575b38d3..bf4119b3d 100644 --- a/crates/brk_types/src/timestamp.rs +++ b/crates/brk_types/src/timestamp.rs @@ -81,36 +81,42 @@ impl Timestamp { } impl From for Timestamp { + #[inline] fn from(value: u32) -> Self { Self(value) } } impl From for Timestamp { + #[inline] fn from(value: jiff::Timestamp) -> Self { Self(value.as_second() as u32) } } impl From for jiff::Timestamp { + #[inline] fn from(value: Timestamp) -> Self { jiff::Timestamp::from_second(*value as i64).unwrap() } } impl From for Timestamp { + #[inline] fn from(value: bitcoin::locktime::absolute::Time) -> Self { Self(value.to_consensus_u32()) } } impl From for Timestamp { + #[inline] fn from(value: usize) -> Self { Self(value as u32) } } impl From for Timestamp { + #[inline] fn from(value: Date) -> Self { Self::from( jiff::civil::Date::from(value) @@ -148,6 +154,7 @@ impl AddAssign for Timestamp { } impl From for Timestamp { + #[inline] fn from(value: f64) -> Self { if value < 0.0 || value > u32::MAX as f64 { panic!() @@ -157,6 +164,7 @@ impl From for Timestamp { } impl From for f64 { + #[inline] fn from(value: Timestamp) -> Self { value.0 as f64 } diff --git a/crates/brk_types/src/txid.rs b/crates/brk_types/src/txid.rs index 019c2c625..c14b850c5 100644 --- a/crates/brk_types/src/txid.rs +++ b/crates/brk_types/src/txid.rs @@ -29,30 +29,35 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; pub struct Txid([u8; 32]); impl From for Txid { + #[inline] fn from(value: bitcoin::Txid) -> Self { unsafe { mem::transmute(value) } } } impl From<&bitcoin::Txid> for &Txid { + #[inline] fn from(value: &bitcoin::Txid) -> Self { unsafe { mem::transmute(value) } } } impl From for bitcoin::Txid { + #[inline] fn from(value: Txid) -> Self { unsafe { mem::transmute(value) } } } impl From<&Txid> for bitcoin::Txid { + #[inline] fn from(value: &Txid) -> Self { bitcoin::Txid::from_slice(&value.0).unwrap() } } impl From<&Txid> for &bitcoin::Txid { + #[inline] fn from(value: &Txid) -> Self { unsafe { mem::transmute(value) } } diff --git a/crates/brk_types/src/txidprefix.rs b/crates/brk_types/src/txidprefix.rs index 3dc31a33c..4029539d0 100644 --- a/crates/brk_types/src/txidprefix.rs +++ b/crates/brk_types/src/txidprefix.rs @@ -24,36 +24,42 @@ use super::Txid; pub struct TxidPrefix(u64); impl From for TxidPrefix { + #[inline] fn from(value: Txid) -> Self { Self::from(&value) } } impl From<&Txid> for TxidPrefix { + #[inline] fn from(value: &Txid) -> Self { Self(u64::from_ne_bytes(copy_first_8bytes(&value[..]).unwrap())) } } impl From for TxidPrefix { + #[inline] fn from(value: ByteView) -> Self { Self::read_from_bytes(&value).unwrap() } } impl From<&TxidPrefix> for ByteView { + #[inline] fn from(value: &TxidPrefix) -> Self { Self::new(value.as_bytes()) } } impl From for ByteView { + #[inline] fn from(value: TxidPrefix) -> Self { Self::from(&value) } } impl From<[u8; 8]> for TxidPrefix { + #[inline] fn from(value: [u8; 8]) -> Self { Self(u64::from_ne_bytes(value)) } diff --git a/crates/brk_types/src/txindex.rs b/crates/brk_types/src/txindex.rs index 98b060617..a467402c0 100644 --- a/crates/brk_types/src/txindex.rs +++ b/crates/brk_types/src/txindex.rs @@ -83,57 +83,67 @@ impl CheckedSub for TxIndex { } impl From for TxIndex { + #[inline] fn from(value: u32) -> Self { Self(value) } } impl From for u32 { + #[inline] fn from(value: TxIndex) -> Self { value.0 } } impl From for TxIndex { + #[inline] fn from(value: u64) -> Self { Self(value as u32) } } impl From for u64 { + #[inline] fn from(value: TxIndex) -> Self { value.0 as u64 } } impl From for TxIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u32) } } impl From for usize { + #[inline] fn from(value: TxIndex) -> Self { value.0 as usize } } impl From for TxIndex { + #[inline] fn from(value: ByteView) -> Self { Self(u32::from_be_bytes(copy_first_4bytes(&value).unwrap())) } } impl From for ByteView { + #[inline] fn from(value: TxIndex) -> Self { Self::new(&value.to_be_bytes()) } } impl From for StoredU32 { + #[inline] fn from(value: TxIndex) -> Self { Self::from(value.0) } } impl From<&[u8]> for TxIndex { + #[inline] fn from(value: &[u8]) -> Self { Self(u32::from_be_bytes(copy_first_4bytes(value).unwrap())) } diff --git a/crates/brk_types/src/txinindex.rs b/crates/brk_types/src/txinindex.rs index 61d522630..047b53c82 100644 --- a/crates/brk_types/src/txinindex.rs +++ b/crates/brk_types/src/txinindex.rs @@ -73,6 +73,7 @@ impl CheckedSub for TxInIndex { } impl From for u32 { + #[inline] fn from(value: TxInIndex) -> Self { if value.0 > u32::MAX as u64 { panic!() @@ -82,22 +83,26 @@ impl From for u32 { } impl From for TxInIndex { + #[inline] fn from(value: u64) -> Self { Self(value) } } impl From for u64 { + #[inline] fn from(value: TxInIndex) -> Self { value.0 } } impl From for TxInIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u64) } } impl From for usize { + #[inline] fn from(value: TxInIndex) -> Self { value.0 as usize } diff --git a/crates/brk_types/src/txout.rs b/crates/brk_types/src/txout.rs index f45756742..c7559ea5b 100644 --- a/crates/brk_types/src/txout.rs +++ b/crates/brk_types/src/txout.rs @@ -62,6 +62,7 @@ impl TxOut { } impl From for TxOut { + #[inline] fn from(txout: bitcoin::TxOut) -> Self { Self { script_pubkey: txout.script_pubkey, @@ -74,6 +75,7 @@ impl From for TxOut { } impl From<(ScriptBuf, Sats)> for TxOut { + #[inline] fn from((script, value): (ScriptBuf, Sats)) -> Self { Self { script_pubkey: script, diff --git a/crates/brk_types/src/txoutindex.rs b/crates/brk_types/src/txoutindex.rs index fdf815baa..e39dd1283 100644 --- a/crates/brk_types/src/txoutindex.rs +++ b/crates/brk_types/src/txoutindex.rs @@ -83,6 +83,7 @@ impl CheckedSub for TxOutIndex { } impl From for u32 { + #[inline] fn from(value: TxOutIndex) -> Self { if value.0 > u32::MAX as u64 { panic!() @@ -92,28 +93,33 @@ impl From for u32 { } impl From for TxOutIndex { + #[inline] fn from(value: u64) -> Self { Self(value) } } impl From for u64 { + #[inline] fn from(value: TxOutIndex) -> Self { value.0 } } impl From for TxOutIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u64) } } impl From for usize { + #[inline] fn from(value: TxOutIndex) -> Self { value.0 as usize } } impl From<&[u8]> for TxOutIndex { + #[inline] fn from(value: &[u8]) -> Self { Self(u64::from_be_bytes(copy_first_8bytes(value).unwrap())) } diff --git a/crates/brk_types/src/txversion.rs b/crates/brk_types/src/txversion.rs index 4098c323c..47f75e531 100644 --- a/crates/brk_types/src/txversion.rs +++ b/crates/brk_types/src/txversion.rs @@ -34,6 +34,7 @@ impl TxVersion { } impl From for TxVersion { + #[inline] fn from(value: bitcoin::transaction::Version) -> Self { match value.0 { 1 => Self::ONE, @@ -45,12 +46,14 @@ impl From for TxVersion { } impl From for bitcoin::transaction::Version { + #[inline] fn from(value: TxVersion) -> Self { Self(value.0 as i32) } } impl From for StoredU16 { + #[inline] fn from(value: TxVersion) -> Self { Self::from(value.0) } diff --git a/crates/brk_types/src/typeindex.rs b/crates/brk_types/src/typeindex.rs index d0efabc93..4efd72bdc 100644 --- a/crates/brk_types/src/typeindex.rs +++ b/crates/brk_types/src/typeindex.rs @@ -59,33 +59,39 @@ impl TypeIndex { } impl From for TypeIndex { + #[inline] fn from(value: u32) -> Self { Self(value) } } impl From for u32 { + #[inline] fn from(value: TypeIndex) -> Self { value.0 } } impl From for TypeIndex { + #[inline] fn from(value: u64) -> Self { Self(value as u32) } } impl From for u64 { + #[inline] fn from(value: TypeIndex) -> Self { value.0 as u64 } } impl From for TypeIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u32) } } impl From for usize { + #[inline] fn from(value: TypeIndex) -> Self { value.0 as usize } @@ -112,17 +118,20 @@ impl Add for TypeIndex { } impl From<&[u8]> for TypeIndex { + #[inline] fn from(value: &[u8]) -> Self { Self(u32::from_be_bytes(copy_first_4bytes(value).unwrap())) } } impl From for TypeIndex { + #[inline] fn from(value: ByteView) -> Self { Self::from(value.as_bytes()) } } impl From for ByteView { + #[inline] fn from(value: TypeIndex) -> Self { Self::new(&value.0.to_be_bytes()) } diff --git a/crates/brk_types/src/typeindexandoutpoint.rs b/crates/brk_types/src/typeindexandoutpoint.rs index 1dc8f98be..1232502bd 100644 --- a/crates/brk_types/src/typeindexandoutpoint.rs +++ b/crates/brk_types/src/typeindexandoutpoint.rs @@ -25,6 +25,7 @@ impl Hash for TypeIndexAndOutPoint { } impl From<(TypeIndex, OutPoint)> for TypeIndexAndOutPoint { + #[inline] fn from(value: (TypeIndex, OutPoint)) -> Self { Self { typeindexandtxindex: TypeIndexAndTxIndex::from((value.0, value.1.txindex())), @@ -34,6 +35,7 @@ impl From<(TypeIndex, OutPoint)> for TypeIndexAndOutPoint { } impl From for TypeIndexAndOutPoint { + #[inline] fn from(value: ByteView) -> Self { Self { typeindexandtxindex: TypeIndexAndTxIndex::from(&value[0..8]), @@ -43,11 +45,13 @@ impl From for TypeIndexAndOutPoint { } impl From for ByteView { + #[inline] fn from(value: TypeIndexAndOutPoint) -> Self { ByteView::from(&value) } } impl From<&TypeIndexAndOutPoint> for ByteView { + #[inline] fn from(value: &TypeIndexAndOutPoint) -> Self { ByteView::from( [ diff --git a/crates/brk_types/src/typeindexandtxindex.rs b/crates/brk_types/src/typeindexandtxindex.rs index 6c46fca96..7ee0ae1b7 100644 --- a/crates/brk_types/src/typeindexandtxindex.rs +++ b/crates/brk_types/src/typeindexandtxindex.rs @@ -37,18 +37,21 @@ impl TypeIndexAndTxIndex { } impl From<(TypeIndex, TxIndex)> for TypeIndexAndTxIndex { + #[inline] fn from((typeindex, txindex): (TypeIndex, TxIndex)) -> Self { Self((u64::from(typeindex) << 32) | u64::from(txindex)) } } impl From for TypeIndexAndTxIndex { + #[inline] fn from(value: ByteView) -> Self { Self::from(&*value) } } impl From<&[u8]> for TypeIndexAndTxIndex { + #[inline] fn from(value: &[u8]) -> Self { let typeindex = TypeIndex::from(&value[0..4]); let txindex = TxIndex::from(&value[4..8]); @@ -57,17 +60,20 @@ impl From<&[u8]> for TypeIndexAndTxIndex { } impl From for ByteView { + #[inline] fn from(value: TypeIndexAndTxIndex) -> Self { ByteView::from(&value) } } impl From<&TypeIndexAndTxIndex> for ByteView { + #[inline] fn from(value: &TypeIndexAndTxIndex) -> Self { ByteView::from(value.0.to_be_bytes().as_slice()) } } impl From for u64 { + #[inline] fn from(value: TypeIndexAndTxIndex) -> Self { value.0 } diff --git a/crates/brk_types/src/unit.rs b/crates/brk_types/src/unit.rs index 9fdb4f8be..5bc52d041 100644 --- a/crates/brk_types/src/unit.rs +++ b/crates/brk_types/src/unit.rs @@ -4,11 +4,13 @@ use byteview::ByteView; pub struct Unit; impl From for Unit { + #[inline] fn from(_: ByteView) -> Self { Self } } impl From for ByteView { + #[inline] fn from(_: Unit) -> Self { Self::new(&[]) } diff --git a/crates/brk_types/src/unknownoutputindex.rs b/crates/brk_types/src/unknownoutputindex.rs index 0014b78dc..c17da6b30 100644 --- a/crates/brk_types/src/unknownoutputindex.rs +++ b/crates/brk_types/src/unknownoutputindex.rs @@ -28,21 +28,25 @@ use crate::TypeIndex; pub struct UnknownOutputIndex(TypeIndex); impl From for UnknownOutputIndex { + #[inline] fn from(value: TypeIndex) -> Self { Self(value) } } impl From for u64 { + #[inline] fn from(value: UnknownOutputIndex) -> Self { Self::from(*value) } } impl From for usize { + #[inline] fn from(value: UnknownOutputIndex) -> Self { Self::from(*value) } } impl From for UnknownOutputIndex { + #[inline] fn from(value: usize) -> Self { Self(TypeIndex::from(value)) } diff --git a/crates/brk_types/src/vin.rs b/crates/brk_types/src/vin.rs index ebaf27c1f..827a5db5c 100644 --- a/crates/brk_types/src/vin.rs +++ b/crates/brk_types/src/vin.rs @@ -14,6 +14,7 @@ impl Vin { const U16_MAX_AS_U32: u32 = u16::MAX as u32; impl From for Vin { + #[inline] fn from(value: u32) -> Self { if value > U16_MAX_AS_U32 { panic!() @@ -24,6 +25,7 @@ impl From for Vin { const U16_MAX_AS_USIZE: usize = u16::MAX as usize; impl From for Vin { + #[inline] fn from(value: usize) -> Self { if value > U16_MAX_AS_USIZE { panic!() @@ -33,6 +35,7 @@ impl From for Vin { } impl From for u64 { + #[inline] fn from(value: Vin) -> Self { value.0 as u64 } diff --git a/crates/brk_types/src/vout.rs b/crates/brk_types/src/vout.rs index 7f35e0a38..57a413aa7 100644 --- a/crates/brk_types/src/vout.rs +++ b/crates/brk_types/src/vout.rs @@ -47,6 +47,7 @@ impl Vout { const U16_MAX_AS_U32: u32 = u16::MAX as u32; impl From for Vout { + #[inline] fn from(value: u32) -> Self { if value > U16_MAX_AS_U32 { panic!() @@ -57,6 +58,7 @@ impl From for Vout { const U16_MAX_AS_USIZE: usize = u16::MAX as usize; impl From for Vout { + #[inline] fn from(value: usize) -> Self { if value > U16_MAX_AS_USIZE { panic!() @@ -66,30 +68,35 @@ impl From for Vout { } impl From for u16 { + #[inline] fn from(value: Vout) -> Self { value.0 } } impl From for u32 { + #[inline] fn from(value: Vout) -> Self { value.0 as u32 } } impl From for u64 { + #[inline] fn from(value: Vout) -> Self { value.0 as u64 } } impl From for usize { + #[inline] fn from(value: Vout) -> Self { value.0 as usize } } impl From<&[u8]> for Vout { + #[inline] fn from(value: &[u8]) -> Self { Self(u16::from_be_bytes(copy_first_2bytes(value).unwrap())) } diff --git a/crates/brk_types/src/weekindex.rs b/crates/brk_types/src/weekindex.rs index 6aa2364f3..b4617a37a 100644 --- a/crates/brk_types/src/weekindex.rs +++ b/crates/brk_types/src/weekindex.rs @@ -31,24 +31,28 @@ use super::{Date, DateIndex}; pub struct WeekIndex(u16); impl From for WeekIndex { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for u16 { + #[inline] fn from(value: WeekIndex) -> Self { value.0 } } impl From for WeekIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for usize { + #[inline] fn from(value: WeekIndex) -> Self { value.0 as usize } @@ -84,12 +88,14 @@ impl Add for WeekIndex { } impl From for WeekIndex { + #[inline] fn from(value: DateIndex) -> Self { Self::from(Date::from(value)) } } impl From for WeekIndex { + #[inline] fn from(value: Date) -> Self { let date = jiff::civil::Date::from(value).iso_week_date(); diff --git a/crates/brk_types/src/weight.rs b/crates/brk_types/src/weight.rs index c25ff8a5f..4d3fe008a 100644 --- a/crates/brk_types/src/weight.rs +++ b/crates/brk_types/src/weight.rs @@ -28,30 +28,35 @@ use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout}; pub struct Weight(u64); impl From for Weight { + #[inline] fn from(value: bitcoin::Weight) -> Self { Self(value.to_wu()) } } impl From for bitcoin::Weight { + #[inline] fn from(value: Weight) -> Self { Self::from_wu(value.0) } } impl From for Weight { + #[inline] fn from(value: usize) -> Self { Self(value as u64) } } impl From for Weight { + #[inline] fn from(value: f64) -> Self { Self(value as u64) } } impl From for f64 { + #[inline] fn from(value: Weight) -> Self { value.0 as f64 } diff --git a/crates/brk_types/src/yearindex.rs b/crates/brk_types/src/yearindex.rs index edea9ad91..67878a103 100644 --- a/crates/brk_types/src/yearindex.rs +++ b/crates/brk_types/src/yearindex.rs @@ -31,24 +31,28 @@ use super::{Date, DateIndex, MonthIndex}; pub struct YearIndex(u16); impl From for YearIndex { + #[inline] fn from(value: u16) -> Self { Self(value) } } impl From for YearIndex { + #[inline] fn from(value: usize) -> Self { Self(value as u16) } } impl From for u64 { + #[inline] fn from(value: YearIndex) -> Self { value.0 as u64 } } impl From for usize { + #[inline] fn from(value: YearIndex) -> Self { value.0 as usize } @@ -84,18 +88,21 @@ impl Div for YearIndex { } impl From for YearIndex { + #[inline] fn from(value: DateIndex) -> Self { Self::from(Date::from(value)) } } impl From for YearIndex { + #[inline] fn from(value: Date) -> Self { Self(value.year() - 2009) } } impl From for u16 { + #[inline] fn from(value: YearIndex) -> Self { value.0 } @@ -108,6 +115,7 @@ impl CheckedSub for YearIndex { } impl From for YearIndex { + #[inline] fn from(value: MonthIndex) -> Self { Self((usize::from(value) / 12) as u16) } diff --git a/docs/TODO.md b/docs/TODO.md index cecb311e4..13e795b29 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -90,7 +90,6 @@ - FEAT: save height and version in one file - _STRUCTS_ - _TRAVERSABLE_ - - UX: Improve `tree_node`, it's too verbose at the moment - _GLOBAL_ - PERF: https://davidlattimore.github.io/posts/2025/09/02/rustforge-wild-performance-tricks.html - __DOCS__ @@ -150,3 +149,4 @@ - check `TODO`s in codebase - rename `output` to `txout` or `vout`, `input` to `txin` or `vin` - https://マリウス.com/thoughts-on-cloudflare/ + - tor: https://news.ycombinator.com/item?id=45683380