mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-04-29 17:19:57 -07:00
computer: store part 2
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
use std::{path::Path, thread};
|
||||
|
||||
use brk_core::{
|
||||
AddressData, EmptyAddressData, P2AAddressIndex, P2AAddressIndexOutputindex, P2PK33AddressIndex,
|
||||
P2PK33AddressIndexOutputindex, P2PK65AddressIndex, P2PK65AddressIndexOutputindex,
|
||||
P2PKHAddressIndex, P2PKHAddressIndexOutputindex, P2SHAddressIndex, P2SHAddressIndexOutputindex,
|
||||
P2TRAddressIndex, P2TRAddressIndexOutputindex, P2WPKHAddressIndex,
|
||||
P2WPKHAddressIndexOutputindex, P2WSHAddressIndex, P2WSHAddressIndexOutputindex, Unit, Version,
|
||||
AddressData, EmptyAddressData, Height, P2AAddressIndex, P2AAddressIndexOutputindex,
|
||||
P2PK33AddressIndex, P2PK33AddressIndexOutputindex, P2PK65AddressIndex,
|
||||
P2PK65AddressIndexOutputindex, P2PKHAddressIndex, P2PKHAddressIndexOutputindex,
|
||||
P2SHAddressIndex, P2SHAddressIndexOutputindex, P2TRAddressIndex, P2TRAddressIndexOutputindex,
|
||||
P2WPKHAddressIndex, P2WPKHAddressIndexOutputindex, P2WSHAddressIndex,
|
||||
P2WSHAddressIndexOutputindex, Result, Unit, Version,
|
||||
};
|
||||
use brk_store::Store;
|
||||
use fjall::TransactionalKeyspace;
|
||||
use brk_store::{AnyStore, Store};
|
||||
use fjall::{PersistMode, TransactionalKeyspace};
|
||||
use rayon::prelude::*;
|
||||
|
||||
const VERSION: Version = Version::ZERO;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Stores {
|
||||
keyspace: TransactionalKeyspace,
|
||||
|
||||
pub p2aaddressindex_to_addressdata: Store<P2AAddressIndex, AddressData>,
|
||||
pub p2aaddressindex_to_emptyaddressdata: Store<P2AAddressIndex, EmptyAddressData>,
|
||||
pub p2aaddressindex_to_utxos_received: Store<P2AAddressIndexOutputindex, Unit>,
|
||||
@@ -420,6 +424,8 @@ impl Stores {
|
||||
});
|
||||
|
||||
Ok(Self {
|
||||
keyspace: keyspace.clone(),
|
||||
|
||||
p2aaddressindex_to_addressdata,
|
||||
p2aaddressindex_to_emptyaddressdata,
|
||||
p2aaddressindex_to_utxos_received,
|
||||
@@ -461,4 +467,102 @@ impl Stores {
|
||||
p2wshaddressindex_to_utxos_sent,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn starting_height(&self) -> Height {
|
||||
self.as_slice()
|
||||
.into_iter()
|
||||
.map(|store| store.height().map(Height::incremented).unwrap_or_default())
|
||||
.min()
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
pub fn commit(&mut self, height: Height) -> Result<()> {
|
||||
self.as_mut_slice()
|
||||
.into_par_iter()
|
||||
.try_for_each(|store| store.commit(height))?;
|
||||
|
||||
self.keyspace
|
||||
.persist(PersistMode::SyncAll)
|
||||
.map_err(|e| e.into())
|
||||
}
|
||||
|
||||
pub fn rotate_memtables(&self) {
|
||||
self.as_slice()
|
||||
.into_iter()
|
||||
.for_each(|store| store.rotate_memtable());
|
||||
}
|
||||
|
||||
fn as_slice(&self) -> [&(dyn AnyStore + Send + Sync); 32] {
|
||||
[
|
||||
&self.p2aaddressindex_to_addressdata,
|
||||
&self.p2aaddressindex_to_emptyaddressdata,
|
||||
&self.p2aaddressindex_to_utxos_received,
|
||||
&self.p2aaddressindex_to_utxos_sent,
|
||||
&self.p2pk33addressindex_to_addressdata,
|
||||
&self.p2pk33addressindex_to_emptyaddressdata,
|
||||
&self.p2pk33addressindex_to_utxos_received,
|
||||
&self.p2pk33addressindex_to_utxos_sent,
|
||||
&self.p2pk65addressindex_to_addressdata,
|
||||
&self.p2pk65addressindex_to_emptyaddressdata,
|
||||
&self.p2pk65addressindex_to_utxos_received,
|
||||
&self.p2pk65addressindex_to_utxos_sent,
|
||||
&self.p2pkhaddressindex_to_addressdata,
|
||||
&self.p2pkhaddressindex_to_emptyaddressdata,
|
||||
&self.p2pkhaddressindex_to_utxos_received,
|
||||
&self.p2pkhaddressindex_to_utxos_sent,
|
||||
&self.p2shaddressindex_to_addressdata,
|
||||
&self.p2shaddressindex_to_emptyaddressdata,
|
||||
&self.p2shaddressindex_to_utxos_received,
|
||||
&self.p2shaddressindex_to_utxos_sent,
|
||||
&self.p2traddressindex_to_addressdata,
|
||||
&self.p2traddressindex_to_emptyaddressdata,
|
||||
&self.p2traddressindex_to_utxos_received,
|
||||
&self.p2traddressindex_to_utxos_sent,
|
||||
&self.p2wpkhaddressindex_to_addressdata,
|
||||
&self.p2wpkhaddressindex_to_emptyaddressdata,
|
||||
&self.p2wpkhaddressindex_to_utxos_received,
|
||||
&self.p2wpkhaddressindex_to_utxos_sent,
|
||||
&self.p2wshaddressindex_to_addressdata,
|
||||
&self.p2wshaddressindex_to_emptyaddressdata,
|
||||
&self.p2wshaddressindex_to_utxos_received,
|
||||
&self.p2wshaddressindex_to_utxos_sent,
|
||||
]
|
||||
}
|
||||
|
||||
fn as_mut_slice(&mut self) -> [&mut (dyn AnyStore + Send + Sync); 32] {
|
||||
[
|
||||
&mut self.p2aaddressindex_to_addressdata,
|
||||
&mut self.p2aaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2aaddressindex_to_utxos_received,
|
||||
&mut self.p2aaddressindex_to_utxos_sent,
|
||||
&mut self.p2pk33addressindex_to_addressdata,
|
||||
&mut self.p2pk33addressindex_to_emptyaddressdata,
|
||||
&mut self.p2pk33addressindex_to_utxos_received,
|
||||
&mut self.p2pk33addressindex_to_utxos_sent,
|
||||
&mut self.p2pk65addressindex_to_addressdata,
|
||||
&mut self.p2pk65addressindex_to_emptyaddressdata,
|
||||
&mut self.p2pk65addressindex_to_utxos_received,
|
||||
&mut self.p2pk65addressindex_to_utxos_sent,
|
||||
&mut self.p2pkhaddressindex_to_addressdata,
|
||||
&mut self.p2pkhaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2pkhaddressindex_to_utxos_received,
|
||||
&mut self.p2pkhaddressindex_to_utxos_sent,
|
||||
&mut self.p2shaddressindex_to_addressdata,
|
||||
&mut self.p2shaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2shaddressindex_to_utxos_received,
|
||||
&mut self.p2shaddressindex_to_utxos_sent,
|
||||
&mut self.p2traddressindex_to_addressdata,
|
||||
&mut self.p2traddressindex_to_emptyaddressdata,
|
||||
&mut self.p2traddressindex_to_utxos_received,
|
||||
&mut self.p2traddressindex_to_utxos_sent,
|
||||
&mut self.p2wpkhaddressindex_to_addressdata,
|
||||
&mut self.p2wpkhaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2wpkhaddressindex_to_utxos_received,
|
||||
&mut self.p2wpkhaddressindex_to_utxos_sent,
|
||||
&mut self.p2wshaddressindex_to_addressdata,
|
||||
&mut self.p2wshaddressindex_to_emptyaddressdata,
|
||||
&mut self.p2wshaddressindex_to_utxos_received,
|
||||
&mut self.p2wshaddressindex_to_utxos_sent,
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user