global: crates cleanup

This commit is contained in:
nym21
2025-02-24 00:25:58 +01:00
parent 8acbcc548c
commit 2f93fd7c36
21 changed files with 138 additions and 67 deletions

View File

@@ -9,6 +9,7 @@ license = { workspace = true }
bitcoin = { workspace = true }
brk_parser = { workspace = true }
brk_logger = { workspace = true }
byteview = { workspace = true }
color-eyre = { workspace = true }
derive_deref = { workspace = true }
fjall = { workspace = true }

View File

@@ -47,7 +47,7 @@ impl<const MODE: u8> Indexer<MODE> {
}
impl Indexer<CACHED_GETS> {
pub fn index(&mut self, bitcoin_dir: &Path, rpc: &'static rpc::Client, exit: &Exit) -> color_eyre::Result<()> {
pub fn index(&mut self, parser: &Parser, rpc: &'static rpc::Client, exit: &Exit) -> color_eyre::Result<()> {
info!("Started indexing...");
let check_collisions = true;
@@ -80,8 +80,6 @@ impl Indexer<CACHED_GETS> {
let mut idxs = starting_indexes;
let parser = Parser::new(bitcoin_dir, rpc);
parser.parse(Some(idxs.height), None)
.iter()
.try_for_each(|(height, block, blockhash)| -> color_eyre::Result<()> {

View File

@@ -1,7 +1,10 @@
use std::{path::Path, thread::sleep, time::Duration};
use brk_indexer::{Indexer, rpc::RpcApi};
use brk_parser::rpc::{self};
use brk_parser::{
Parser,
rpc::{self},
};
use hodor::Exit;
use log::info;
use storable_vec::CACHED_GETS;
@@ -18,6 +21,8 @@ fn main() -> color_eyre::Result<()> {
)?));
let exit = Exit::new();
let parser = Parser::new(data_dir, rpc);
loop {
let block_count = rpc.get_blockchain_info().unwrap().blocks as usize;
@@ -27,7 +32,7 @@ fn main() -> color_eyre::Result<()> {
let mut indexer: Indexer<CACHED_GETS> = Indexer::import(Path::new("../../_outputs/indexes"))?;
indexer.index(data_dir, rpc, &exit)?;
indexer.index(&parser, rpc, &exit)?;
dbg!(i.elapsed());

View File

@@ -5,9 +5,9 @@ use std::{
};
use brk_parser::Height;
use byteview::ByteView;
use fjall::{
PartitionCreateOptions, PersistMode, ReadTransaction, Result, Slice, TransactionalKeyspace,
TransactionalPartitionHandle,
PartitionCreateOptions, PersistMode, ReadTransaction, Result, TransactionalKeyspace, TransactionalPartitionHandle,
};
use storable_vec::{Value, Version};
use zerocopy::{Immutable, IntoBytes};
@@ -27,9 +27,9 @@ const CHECK_COLLISISONS: bool = true;
impl<K, V> Store<K, V>
where
K: Into<Slice> + Ord + Immutable + IntoBytes,
V: Into<Slice> + TryFrom<Slice>,
<V as TryFrom<Slice>>::Error: error::Error + Send + Sync + 'static,
K: Into<ByteView> + Ord + Immutable + IntoBytes,
V: Into<ByteView> + TryFrom<ByteView>,
<V as TryFrom<ByteView>>::Error: error::Error + Send + Sync + 'static,
{
pub fn import(path: &Path, version: Version) -> color_eyre::Result<Self> {
let meta = StoreMeta::checked_open(path, version)?;
@@ -62,7 +62,7 @@ where
if let Some(v) = self.puts.get(key) {
Ok(Some(Value::Ref(v)))
} else if let Some(slice) = self.rtx.get(&self.part, key.as_bytes())? {
Ok(Some(Value::Owned(V::try_from(slice)?)))
Ok(Some(Value::Owned(V::try_from(slice.into())?)))
} else {
Ok(None)
}
@@ -97,7 +97,7 @@ where
mem::take(&mut self.dels)
.into_iter()
.for_each(|key| wtx.remove(&self.part, key));
.for_each(|key| wtx.remove(&self.part, key.into()));
mem::take(&mut self.puts).into_iter().for_each(|(key, value)| {
if CHECK_COLLISISONS {
@@ -106,7 +106,7 @@ where
unreachable!();
}
}
wtx.insert(&self.part, key, value)
wtx.insert(&self.part, key.into(), value.into())
});
wtx.commit()?;

View File

@@ -1,7 +1,7 @@
use std::ops::Add;
use byteview::ByteView;
use derive_deref::{Deref, DerefMut};
use fjall::Slice;
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -68,13 +68,13 @@ impl From<Addressindex> for usize {
}
}
impl TryFrom<Slice> for Addressindex {
impl TryFrom<ByteView> for Addressindex {
type Error = storable_vec::Error;
fn try_from(value: Slice) -> Result<Self, Self::Error> {
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<Addressindex> for Slice {
impl From<Addressindex> for ByteView {
fn from(value: Addressindex) -> Self {
Self::new(value.as_bytes())
}

View File

@@ -1,7 +1,7 @@
use std::hash::Hasher;
use byteview::ByteView;
use derive_deref::Deref;
use fjall::Slice;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
use super::{Addressbytes, Addresstype, BlockHash, Txid};
@@ -22,18 +22,18 @@ impl From<[u8; 8]> for AddressHash {
Self(value)
}
}
impl TryFrom<Slice> for AddressHash {
impl TryFrom<ByteView> for AddressHash {
type Error = storable_vec::Error;
fn try_from(value: Slice) -> Result<Self, Self::Error> {
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&AddressHash> for Slice {
impl From<&AddressHash> for ByteView {
fn from(value: &AddressHash) -> Self {
Self::new(value.as_bytes())
}
}
impl From<AddressHash> for Slice {
impl From<AddressHash> for ByteView {
fn from(value: AddressHash) -> Self {
Self::from(&value)
}
@@ -46,18 +46,18 @@ impl From<&BlockHash> for BlockHashPrefix {
Self(copy_first_8bytes(&value[..]).unwrap())
}
}
impl TryFrom<Slice> for BlockHashPrefix {
impl TryFrom<ByteView> for BlockHashPrefix {
type Error = storable_vec::Error;
fn try_from(value: Slice) -> Result<Self, Self::Error> {
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&BlockHashPrefix> for Slice {
impl From<&BlockHashPrefix> for ByteView {
fn from(value: &BlockHashPrefix) -> Self {
Self::new(value.as_bytes())
}
}
impl From<BlockHashPrefix> for Slice {
impl From<BlockHashPrefix> for ByteView {
fn from(value: BlockHashPrefix) -> Self {
Self::from(&value)
}
@@ -70,18 +70,18 @@ impl From<&Txid> for TxidPrefix {
Self(copy_first_8bytes(&value[..]).unwrap())
}
}
impl TryFrom<Slice> for TxidPrefix {
impl TryFrom<ByteView> for TxidPrefix {
type Error = storable_vec::Error;
fn try_from(value: Slice) -> Result<Self, Self::Error> {
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<&TxidPrefix> for Slice {
impl From<&TxidPrefix> for ByteView {
fn from(value: &TxidPrefix) -> Self {
Self::new(value.as_bytes())
}
}
impl From<TxidPrefix> for Slice {
impl From<TxidPrefix> for ByteView {
fn from(value: TxidPrefix) -> Self {
Self::from(&value)
}

View File

@@ -1,7 +1,7 @@
use std::ops::{Add, AddAssign, Sub};
use byteview::ByteView;
use derive_deref::{Deref, DerefMut};
use fjall::Slice;
use serde::Serialize;
use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};
@@ -89,13 +89,13 @@ impl From<Txindex> for usize {
}
}
impl TryFrom<Slice> for Txindex {
impl TryFrom<ByteView> for Txindex {
type Error = storable_vec::Error;
fn try_from(value: Slice) -> Result<Self, Self::Error> {
fn try_from(value: ByteView) -> Result<Self, Self::Error> {
Ok(Self::read_from_bytes(&value)?)
}
}
impl From<Txindex> for Slice {
impl From<Txindex> for ByteView {
fn from(value: Txindex) -> Self {
Self::new(value.as_bytes())
}