global: versions

This commit is contained in:
nym21
2025-05-26 11:34:37 +02:00
parent a8ee4cf57f
commit 34919aba05
32 changed files with 883 additions and 577 deletions

View File

@@ -18,7 +18,7 @@ pub use brk_parser::*;
use bitcoin::{Transaction, TxIn, TxOut};
use brk_exit::Exit;
use brk_vec::{AnyVec, Compressed, VecIterator};
use brk_vec::{AnyVec, Compressed, VecIterator, Version};
use color_eyre::eyre::{ContextCompat, eyre};
use fjall::TransactionalKeyspace;
use log::{error, info};
@@ -33,6 +33,7 @@ pub use vecs::*;
const SNAPSHOT_BLOCK_RANGE: usize = 1000;
const COLLISIONS_CHECKED_UP_TO: u32 = 893_000;
const VERSION: Version = Version::ONE;
#[derive(Clone)]
pub struct Indexer {
@@ -62,6 +63,7 @@ impl Indexer {
pub fn import_vecs(&mut self) -> color_eyre::Result<()> {
self.vecs = Some(Vecs::forced_import(
&self.path.join("vecs/indexed"),
VERSION + Version::ZERO,
self.compressed,
)?);
Ok(())
@@ -70,7 +72,10 @@ impl Indexer {
/// Do NOT import multiple times are things will break !!!
/// Clone struct instead
pub fn import_stores(&mut self) -> color_eyre::Result<()> {
self.stores = Some(Stores::forced_import(&self.path.join("stores"))?);
self.stores = Some(Stores::forced_import(
&self.path.join("stores"),
VERSION + Version::ZERO,
)?);
Ok(())
}

View File

@@ -42,12 +42,10 @@ where
name: &str,
version: Version,
) -> color_eyre::Result<Self> {
let version = MAJOR_FJALL_VERSION + version;
let (meta, partition) = StoreMeta::checked_open(
&keyspace,
&path.join(format!("meta/{name}")),
version,
MAJOR_FJALL_VERSION + version,
|| {
Self::open_partition_handle(&keyspace, name).inspect_err(|_| {
eprintln!("Delete {path:?} and try again");

View File

@@ -25,15 +25,17 @@ pub struct Stores {
pub txidprefix_to_txindex: Store<TxidPrefix, TxIndex>,
}
const VERSION: Version = Version::ZERO;
impl Stores {
pub fn forced_import(path: &Path) -> color_eyre::Result<Self> {
pub fn forced_import(path: &Path, version: Version) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
let keyspace = match Self::open_keyspace(path) {
Ok(keyspace) => keyspace,
Err(_) => {
fs::remove_dir_all(path)?;
return Self::forced_import(path);
return Self::forced_import(path, version);
}
};
@@ -43,7 +45,7 @@ impl Stores {
keyspace.clone(),
path,
"addressbyteshash_to_outputtypeindex",
Version::ZERO,
version + VERSION + Version::ZERO,
)
});
let blockhashprefix_to_height = scope.spawn(|| {
@@ -51,7 +53,7 @@ impl Stores {
keyspace.clone(),
path,
"blockhashprefix_to_height",
Version::ZERO,
version + VERSION + Version::ZERO,
)
});
let txidprefix_to_txindex = scope.spawn(|| {
@@ -59,7 +61,7 @@ impl Stores {
keyspace.clone(),
path,
"txidprefix_to_txindex",
Version::ZERO,
version + VERSION + Version::ZERO,
)
});

View File

@@ -12,6 +12,8 @@ use rayon::prelude::*;
use crate::Indexes;
const VERSION: Version = Version::ZERO;
#[derive(Clone)]
pub struct Vecs {
pub emptyoutputindex_to_txindex: IndexedVec<EmptyOutputIndex, TxIndex>,
@@ -63,267 +65,276 @@ pub struct Vecs {
}
impl Vecs {
pub fn forced_import(path: &Path, compressed: Compressed) -> color_eyre::Result<Self> {
pub fn forced_import(
path: &Path,
version: Version,
compressed: Compressed,
) -> color_eyre::Result<Self> {
fs::create_dir_all(path)?;
Ok(Self {
emptyoutputindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_blockhash: IndexedVec::forced_import(
path,
"blockhash",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
height_to_difficulty: IndexedVec::forced_import(
path,
"difficulty",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_emptyoutputindex: IndexedVec::forced_import(
path,
"first_emptyoutputindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_inputindex: IndexedVec::forced_import(
path,
"first_inputindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_opreturnindex: IndexedVec::forced_import(
path,
"first_opreturnindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_outputindex: IndexedVec::forced_import(
path,
"first_outputindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2aindex: IndexedVec::forced_import(
path,
"first_p2aindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2msindex: IndexedVec::forced_import(
path,
"first_p2msindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2pk33index: IndexedVec::forced_import(
path,
"first_p2pk33index",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2pk65index: IndexedVec::forced_import(
path,
"first_p2pk65index",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2pkhindex: IndexedVec::forced_import(
path,
"first_p2pkhindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2shindex: IndexedVec::forced_import(
path,
"first_p2shindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2trindex: IndexedVec::forced_import(
path,
"first_p2trindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2wpkhindex: IndexedVec::forced_import(
path,
"first_p2wpkhindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_p2wshindex: IndexedVec::forced_import(
path,
"first_p2wshindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_txindex: IndexedVec::forced_import(
path,
"first_txindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_first_unknownoutputindex: IndexedVec::forced_import(
path,
"first_unknownoutputindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_timestamp: IndexedVec::forced_import(
path,
"timestamp",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_total_size: IndexedVec::forced_import(
path,
"total_size",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_weight: IndexedVec::forced_import(
path,
"weight",
version + VERSION + Version::ZERO,
compressed,
)?,
height_to_weight: IndexedVec::forced_import(path, "weight", Version::ZERO, compressed)?,
inputindex_to_outputindex: IndexedVec::forced_import(
path,
"outputindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
opreturnindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
outputindex_to_outputtype: IndexedVec::forced_import(
path,
"outputtype",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
outputindex_to_outputtypeindex: IndexedVec::forced_import(
path,
"outputtypeindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
outputindex_to_value: IndexedVec::forced_import(
path,
"value",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
p2aindex_to_p2abytes: IndexedVec::forced_import(
path,
"p2abytes",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
p2msindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
p2pk33index_to_p2pk33bytes: IndexedVec::forced_import(
path,
"p2pk33bytes",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
p2pk65index_to_p2pk65bytes: IndexedVec::forced_import(
path,
"p2pk65bytes",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
p2pkhindex_to_p2pkhbytes: IndexedVec::forced_import(
path,
"p2pkhbytes",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
p2shindex_to_p2shbytes: IndexedVec::forced_import(
path,
"p2shbytes",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
p2trindex_to_p2trbytes: IndexedVec::forced_import(
path,
"p2trbytes",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
p2wpkhindex_to_p2wpkhbytes: IndexedVec::forced_import(
path,
"p2wpkhbytes",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
p2wshindex_to_p2wshbytes: IndexedVec::forced_import(
path,
"p2wshbytes",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
txindex_to_base_size: IndexedVec::forced_import(
path,
"base_size",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
txindex_to_first_inputindex: IndexedVec::forced_import(
path,
"first_inputindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
txindex_to_first_outputindex: IndexedVec::forced_import(
path,
"first_outputindex",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
txindex_to_is_explicitly_rbf: IndexedVec::forced_import(
path,
"is_explicitly_rbf",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
txindex_to_rawlocktime: IndexedVec::forced_import(
path,
"rawlocktime",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
txindex_to_total_size: IndexedVec::forced_import(
path,
"total_size",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
txindex_to_txid: IndexedVec::forced_import(
path,
"txid",
Version::ZERO,
version + VERSION + Version::ZERO,
Compressed::NO,
)?,
txindex_to_txversion: IndexedVec::forced_import(
path,
"txversion",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
unknownoutputindex_to_txindex: IndexedVec::forced_import(
path,
"txindex",
Version::ZERO,
version + VERSION + Version::ZERO,
compressed,
)?,
})