From bb61b3dc228b776658d543f5de298f96d94d7808 Mon Sep 17 00:00:00 2001 From: nym21 Date: Wed, 26 Feb 2025 10:07:05 +0100 Subject: [PATCH] global: init readmes --- .gitignore | 3 ++ Cargo.lock | 20 ++++++------ Cargo.toml | 6 ++-- crates/brk/Cargo.toml | 4 ++- crates/brk_cli/README.md | 1 + crates/brk_computer/README.md | 1 + crates/brk_computer/src/lib.rs | 4 +-- crates/brk_computer/src/main.rs | 12 ++++--- crates/brk_core/README.md | 1 + crates/brk_core/src/structs/compressed.rs | 5 +++ crates/brk_core/src/structs/unit.rs | 2 ++ crates/brk_fetcher/README.md | 1 + crates/brk_indexer/README.md | 2 +- crates/brk_parser/README.md | 6 ++-- crates/brk_parser/src/lib.rs | 4 +++ crates/brk_parser/src/main.rs | 4 +++ crates/brk_server/README.md | 1 + crates/hodor/Cargo.toml | 2 +- crates/hodor/src/lib.rs | 40 +++++++++++------------ 19 files changed, 75 insertions(+), 44 deletions(-) create mode 100644 crates/brk_cli/README.md create mode 100644 crates/brk_computer/README.md create mode 100644 crates/brk_core/README.md create mode 100644 crates/brk_fetcher/README.md create mode 100644 crates/brk_server/README.md diff --git a/.gitignore b/.gitignore index d0bd3df09..6ba4d7b64 100644 --- a/.gitignore +++ b/.gitignore @@ -36,3 +36,6 @@ _outputs # Python .ropeproject + +# Logs +.log diff --git a/Cargo.lock b/Cargo.lock index 575ab6cd3..834bca84f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -324,7 +324,7 @@ checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36" [[package]] name = "brk" -version = "0.0.0" +version = "0.0.1" dependencies = [ "brk_computer", "brk_core", @@ -337,11 +337,11 @@ dependencies = [ [[package]] name = "brk_cli" -version = "0.0.0" +version = "0.0.1" [[package]] name = "brk_computer" -version = "0.0.0" +version = "0.0.1" dependencies = [ "brk_core", "brk_indexer", @@ -353,7 +353,7 @@ dependencies = [ [[package]] name = "brk_core" -version = "0.0.0" +version = "0.0.1" dependencies = [ "bitcoin", "bitcoincore-rpc", @@ -368,7 +368,7 @@ dependencies = [ [[package]] name = "brk_fetcher" -version = "0.0.0" +version = "0.0.1" dependencies = [ "brk_core", "brk_indexer", @@ -383,7 +383,7 @@ dependencies = [ [[package]] name = "brk_indexer" -version = "0.0.0" +version = "0.0.1" dependencies = [ "bitcoin", "bitcoincore-rpc", @@ -403,7 +403,7 @@ dependencies = [ [[package]] name = "brk_logger" -version = "0.0.0" +version = "0.0.1" dependencies = [ "color-eyre", "env_logger", @@ -412,7 +412,7 @@ dependencies = [ [[package]] name = "brk_parser" -version = "0.0.0" +version = "0.0.1" dependencies = [ "bitcoin", "bitcoincore-rpc", @@ -427,7 +427,7 @@ dependencies = [ [[package]] name = "brk_server" -version = "0.0.0" +version = "0.0.1" dependencies = [ "axum", "brk_computer", @@ -927,7 +927,7 @@ checksum = "3011d1213f159867b13cfd6ac92d2cd5f1345762c63be3554e84092d85a50bbd" [[package]] name = "hodor" -version = "0.1.0" +version = "0.1.1" dependencies = [ "ctrlc", "log", diff --git a/Cargo.toml b/Cargo.toml index 9036a25ce..557e7a09f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,11 @@ [workspace] -members = ["crates/*"] resolver = "2" +members = ["crates/*"] +package.description = "The Bitcoin Research Kit is a suite of tools designed to help you extract, explore and analyze the data stored from your Bitcoin Core node" package.license = "MIT" package.edition = "2024" -package.version = "0.0.0" +package.version = "0.0.1" +package.repository = "https://github.com/bitcoinresearchkit/brk" [workspace.dependencies] bitcoin = { version = "0.32.5", features = ["serde"] } diff --git a/crates/brk/Cargo.toml b/crates/brk/Cargo.toml index 4eb1c0886..b49427f7b 100644 --- a/crates/brk/Cargo.toml +++ b/crates/brk/Cargo.toml @@ -1,7 +1,9 @@ [package] name = "brk" -description = "The Bitcoin Research Kit is a suite of tools designed to help you extract, explore and analyze the data stored from your node" +description.workspace = true license.workspace = true +readme.workspace = true +repository.workspace = true edition.workspace = true version.workspace = true diff --git a/crates/brk_cli/README.md b/crates/brk_cli/README.md new file mode 100644 index 000000000..fb5f600d1 --- /dev/null +++ b/crates/brk_cli/README.md @@ -0,0 +1 @@ +# BRK Cli diff --git a/crates/brk_computer/README.md b/crates/brk_computer/README.md new file mode 100644 index 000000000..4851b1013 --- /dev/null +++ b/crates/brk_computer/README.md @@ -0,0 +1 @@ +# BRK Computer diff --git a/crates/brk_computer/src/lib.rs b/crates/brk_computer/src/lib.rs index f7f2270a1..cddbc6bde 100644 --- a/crates/brk_computer/src/lib.rs +++ b/crates/brk_computer/src/lib.rs @@ -2,7 +2,7 @@ use std::path::{Path, PathBuf}; use brk_indexer::Indexer; pub use brk_parser::rpc; -use hodor::Exit; +use hodor::Hodor; mod storage; @@ -29,7 +29,7 @@ impl Computer { } impl Computer { - pub fn compute(&mut self, mut indexer: Indexer, exit: &Exit) -> color_eyre::Result<()> { + pub fn compute(&mut self, mut indexer: Indexer, hodor: &Hodor) -> color_eyre::Result<()> { let height_count = indexer.vecs.height_to_size.len(); let txindexes_count = indexer.vecs.txindex_to_txid.len(); let txinindexes_count = indexer.vecs.txinindex_to_txoutindex.len(); diff --git a/crates/brk_computer/src/main.rs b/crates/brk_computer/src/main.rs index 678cabe18..2250a8540 100644 --- a/crates/brk_computer/src/main.rs +++ b/crates/brk_computer/src/main.rs @@ -2,18 +2,22 @@ use std::path::Path; use brk_computer::Computer; use brk_indexer::Indexer; -use hodor::Exit; +use hodor::Hodor; pub fn main() -> color_eyre::Result<()> { color_eyre::install()?; - let exit = Exit::new(); + let hodor = Hodor::new(); let i = std::time::Instant::now(); - let outputs_dir = Path::new("../_outputs"); + let outputs_dir = Path::new("../../_outputs"); - Computer::import(&outputs_dir.join("computed"))?.compute(Indexer::import(&outputs_dir.join("indexes"))?, &exit)?; + let indexer = Indexer::import(&outputs_dir.join("indexes"))?; + + let mut computer = Computer::import(&outputs_dir.join("computed"))?; + + computer.compute(indexer, &hodor)?; dbg!(i.elapsed()); diff --git a/crates/brk_core/README.md b/crates/brk_core/README.md new file mode 100644 index 000000000..0f1719a80 --- /dev/null +++ b/crates/brk_core/README.md @@ -0,0 +1 @@ +# BRK Core diff --git a/crates/brk_core/src/structs/compressed.rs b/crates/brk_core/src/structs/compressed.rs index 4f78919bd..8a612e0d0 100644 --- a/crates/brk_core/src/structs/compressed.rs +++ b/crates/brk_core/src/structs/compressed.rs @@ -88,6 +88,11 @@ impl From for ByteView { Self::from(&value) } } +impl From<[u8; 8]> for TxidPrefix { + fn from(value: [u8; 8]) -> Self { + Self(value) + } +} fn copy_first_8bytes(slice: &[u8]) -> Result<[u8; 8], ()> { let mut buf: [u8; 8] = [0; 8]; diff --git a/crates/brk_core/src/structs/unit.rs b/crates/brk_core/src/structs/unit.rs index e9754fb93..177c6c568 100644 --- a/crates/brk_core/src/structs/unit.rs +++ b/crates/brk_core/src/structs/unit.rs @@ -1,6 +1,8 @@ use byteview::ByteView; +#[derive(Debug)] pub struct Unit(); + impl From for Unit { fn from(_: ByteView) -> Self { Self() diff --git a/crates/brk_fetcher/README.md b/crates/brk_fetcher/README.md new file mode 100644 index 000000000..549046768 --- /dev/null +++ b/crates/brk_fetcher/README.md @@ -0,0 +1 @@ +# BRK Fetcher diff --git a/crates/brk_indexer/README.md b/crates/brk_indexer/README.md index 74de013f0..4021af02e 100644 --- a/crates/brk_indexer/README.md +++ b/crates/brk_indexer/README.md @@ -1,4 +1,4 @@ -# Indexer +# BRK Indexer A [Bitcoin Core](https://bitcoincore.org/en/about/) node indexer which iterates over the chain (via `../iterator`) and creates a database of the vecs (`../storable_vec`) and key/value stores ([`fjall`](https://crates.io/crates/fjall)) that can be used in your Rust code. diff --git a/crates/brk_parser/README.md b/crates/brk_parser/README.md index d66ae4cc8..bec735b1f 100644 --- a/crates/brk_parser/README.md +++ b/crates/brk_parser/README.md @@ -1,9 +1,9 @@ -# biter +# BRK Parser -Biter (Bitcoin Block Iterator) is a very fast and simple Rust library which reads raw block files (*blkXXXXX.dat*) from Bitcoin Core Node and creates an iterator over all the requested blocks in sequential order (0, 1, 2, ...). +A very fast and simple Rust library which reads raw block files (*blkXXXXX.dat*) from Bitcoin Core node and creates an iterator over all the requested blocks in sequential order (0, 1, 2, ...). The element returned by the iterator is a tuple which includes the: -- Height: `usize` +- Height: `Height` - Block: `Block` (from `bitcoin-rust`) - Block's Hash: `BlockHash` (also from `bitcoin-rust`) diff --git a/crates/brk_parser/src/lib.rs b/crates/brk_parser/src/lib.rs index ad9cda4ec..b526c0c60 100644 --- a/crates/brk_parser/src/lib.rs +++ b/crates/brk_parser/src/lib.rs @@ -54,6 +54,10 @@ impl Parser { } } + pub fn get(&self, height: Height) -> Block { + self.parse(Some(height), Some(height)).iter().next().unwrap().1 + } + /// /// Returns a crossbeam channel receiver that receives `(Height, Block, BlockHash)` tuples from an **inclusive** range (`start` and `end`) /// diff --git a/crates/brk_parser/src/main.rs b/crates/brk_parser/src/main.rs index 3e820a0bd..8244c7cdd 100644 --- a/crates/brk_parser/src/main.rs +++ b/crates/brk_parser/src/main.rs @@ -1,6 +1,7 @@ use std::path::Path; use bitcoincore_rpc::{Auth, Client}; +use brk_core::Height; use brk_parser::Parser; fn main() { @@ -24,5 +25,8 @@ fn main() { println!("{height}: {hash}"); }); + parser.get(Height::new(0)); + parser.get(Height::new(840_000)); + dbg!(i.elapsed()); } diff --git a/crates/brk_server/README.md b/crates/brk_server/README.md new file mode 100644 index 000000000..744ea2968 --- /dev/null +++ b/crates/brk_server/README.md @@ -0,0 +1 @@ +# BRK Server diff --git a/crates/hodor/Cargo.toml b/crates/hodor/Cargo.toml index 0100d6fc9..930167702 100644 --- a/crates/hodor/Cargo.toml +++ b/crates/hodor/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "hodor" description = "Hold the door, an exit blocker that can wait until a task is completed" -version = "0.1.0" +version = "0.1.1" edition = { workspace = true } license = { workspace = true } diff --git a/crates/hodor/src/lib.rs b/crates/hodor/src/lib.rs index 726f85642..9f23494ae 100644 --- a/crates/hodor/src/lib.rs +++ b/crates/hodor/src/lib.rs @@ -1,8 +1,8 @@ use std::{ process::exit, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, thread::sleep, time::Duration, @@ -11,32 +11,32 @@ use std::{ use log::info; #[derive(Default, Clone)] -pub struct Exit { - blocked: Arc, - active: Arc, +pub struct Hodor { + holding: Arc, + triggered: Arc, } -impl Exit { +impl Hodor { pub fn new() -> Self { let s = Self { - active: Arc::new(AtomicBool::new(false)), - blocked: Arc::new(AtomicBool::new(false)), + triggered: Arc::new(AtomicBool::new(false)), + holding: Arc::new(AtomicBool::new(false)), }; - let active = s.active.clone(); + let triggered = s.triggered.clone(); - let _blocked = s.blocked.clone(); - let blocked = move || _blocked.load(Ordering::SeqCst); + let holding = s.holding.clone(); + let is_holding = move || holding.load(Ordering::SeqCst); ctrlc::set_handler(move || { info!("Exitting..."); - active.store(true, Ordering::SeqCst); + triggered.store(true, Ordering::SeqCst); - if blocked() { - info!("Waiting to exit safely"); + if is_holding() { + info!("Waiting to exit safely..."); - while blocked() { + while is_holding() { sleep(Duration::from_millis(50)); } } @@ -48,15 +48,15 @@ impl Exit { s } - pub fn block(&self) { - self.blocked.store(true, Ordering::SeqCst); + pub fn hold(&self) { + self.holding.store(true, Ordering::SeqCst); } - pub fn unblock(&self) { - self.blocked.store(false, Ordering::SeqCst); + pub fn release(&self) { + self.holding.store(false, Ordering::SeqCst); } - pub fn blocked(&self) -> bool { - self.active.load(Ordering::SeqCst) + pub fn triggered(&self) -> bool { + self.triggered.load(Ordering::SeqCst) } }