mirror of
https://github.com/bitcoinresearchkit/brk.git
synced 2026-07-02 14:59:00 -07:00
bomputer: init
This commit is contained in:
@@ -59,6 +59,15 @@ impl BlkIndexToBlkRecap {
|
||||
self.tree.remove(&blk_index);
|
||||
});
|
||||
|
||||
while self.tree.last_entry().map(|last| *last.key()).is_some_and(|key| {
|
||||
if key >= self.tree.len() {
|
||||
self.tree.pop_last();
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}) {}
|
||||
|
||||
self.last_safe_height = self.tree.values().map(|recap| recap.height()).max();
|
||||
}
|
||||
|
||||
@@ -68,13 +77,12 @@ impl BlkIndexToBlkRecap {
|
||||
|
||||
if last_value.height() < start {
|
||||
return Some((*last_key, *last_value));
|
||||
} else if let Some((blk_index, _)) = self
|
||||
.tree
|
||||
.iter()
|
||||
.find(|(_, blk_recap)| blk_recap.is_younger_than(start))
|
||||
} else if let Some((blk_index, _)) =
|
||||
self.tree.iter().find(|(_, blk_recap)| blk_recap.is_younger_than(start))
|
||||
{
|
||||
if *blk_index != 0 {
|
||||
let blk_index = *blk_index - 1;
|
||||
// Temporary fix, need to rethink the whole thing
|
||||
let blk_index = (*blk_index).checked_sub(3).unwrap_or_default();
|
||||
return Some((blk_index, *self.tree.get(&blk_index).unwrap()));
|
||||
}
|
||||
}
|
||||
@@ -103,13 +111,10 @@ impl BlkIndexToBlkRecap {
|
||||
unreachable!();
|
||||
}
|
||||
|
||||
self.tree
|
||||
.insert(blk_index, BlkRecap::first(blk_metadata_and_block));
|
||||
self.tree.insert(blk_index, BlkRecap::first(blk_metadata_and_block));
|
||||
}
|
||||
|
||||
if self
|
||||
.last_safe_height
|
||||
.map_or(true, |safe_height| height >= safe_height)
|
||||
if self.last_safe_height.map_or(true, |safe_height| height >= safe_height)
|
||||
&& (height % TARGET_BLOCKS_PER_MONTH) == 0
|
||||
{
|
||||
self.export();
|
||||
|
||||
+5
-34
@@ -98,7 +98,7 @@ pub fn new(
|
||||
thread::spawn(move || {
|
||||
blk_index_to_blk_path
|
||||
.iter()
|
||||
.filter(|(blk_index, _)| blk_index >= &&starting_blk_index)
|
||||
.filter(|(blk_index, _)| **blk_index >= starting_blk_index)
|
||||
.try_for_each(move |(blk_index, blk_path)| {
|
||||
let blk_metadata = BlkMetadata::new(*blk_index, blk_path);
|
||||
|
||||
@@ -147,38 +147,6 @@ pub fn new(
|
||||
})
|
||||
});
|
||||
|
||||
// thread::spawn(move || {
|
||||
// recv_block_reader.iter().par_bridge().try_for_each(
|
||||
// move |(blk_metadata, mut block_state)| {
|
||||
// let raw_block = match block_state {
|
||||
// BlockState::Raw(vec) => vec,
|
||||
// _ => unreachable!(),
|
||||
// };
|
||||
|
||||
// let mut cursor = Cursor::new(raw_block);
|
||||
|
||||
// block_state = BlockState::Decoded(Block::consensus_decode(&mut cursor).unwrap());
|
||||
|
||||
// if send_block
|
||||
// .send(BlkMetadataAndBlock::new(
|
||||
// blk_metadata,
|
||||
// match block_state {
|
||||
// BlockState::Decoded(block) => block,
|
||||
// _ => unreachable!(),
|
||||
// },
|
||||
// ))
|
||||
// .is_err()
|
||||
// {
|
||||
// return ControlFlow::Break(());
|
||||
// }
|
||||
|
||||
// ControlFlow::Continue(())
|
||||
// },
|
||||
// );
|
||||
// });
|
||||
|
||||
// Can't use the previous code because .send() blocks all the threads if full
|
||||
// And other .par_iter() are also stuck because of that
|
||||
thread::spawn(move || {
|
||||
let mut bulk = vec![];
|
||||
|
||||
@@ -192,7 +160,9 @@ pub fn new(
|
||||
|
||||
let mut cursor = Cursor::new(raw_block);
|
||||
|
||||
*block_state = BlockState::Decoded(Block::consensus_decode(&mut cursor).unwrap());
|
||||
let block = Block::consensus_decode(&mut cursor).unwrap();
|
||||
|
||||
*block_state = BlockState::Decoded(block);
|
||||
});
|
||||
|
||||
bulk.drain(..).try_for_each(|(blk_metadata, block_state)| {
|
||||
@@ -219,6 +189,7 @@ pub fn new(
|
||||
return ControlFlow::Continue(());
|
||||
}
|
||||
|
||||
// Sending in bulk to not lock threads in standby
|
||||
drain_and_send(&mut bulk)
|
||||
});
|
||||
|
||||
|
||||
@@ -5,13 +5,13 @@ use bitcoincore_rpc::{Auth, Client};
|
||||
fn main() {
|
||||
let i = std::time::Instant::now();
|
||||
|
||||
let data_dir = Path::new("../../../bitcoin");
|
||||
let data_dir = Path::new("../../bitcoin");
|
||||
let url = "http://localhost:8332";
|
||||
let cookie = Path::new(data_dir).join(".cookie");
|
||||
let auth = Auth::CookieFile(cookie);
|
||||
let rpc = Client::new(url, auth).unwrap();
|
||||
|
||||
let start = Some(810078);
|
||||
let start = Some(749900);
|
||||
let end = None;
|
||||
|
||||
biter::new(data_dir, start, end, rpc)
|
||||
|
||||
Reference in New Issue
Block a user