mirror of
https://github.com/alexgo-io/bitcoin-indexer.git
synced 2026-06-13 16:19:01 +08:00
fix: cache's ambitions
This commit is contained in:
@@ -591,7 +591,7 @@ async fn handle_command(opts: Opts, ctx: Context) -> Result<(), String> {
|
||||
hash: "".into(),
|
||||
};
|
||||
// let global_block_cache = HashMap::new();
|
||||
let (traversal, _) = retrieve_satoshi_point_using_local_storage(
|
||||
let traversal = retrieve_satoshi_point_using_local_storage(
|
||||
&hord_db_conn,
|
||||
&block_identifier,
|
||||
&transaction_identifier,
|
||||
@@ -873,7 +873,7 @@ pub async fn perform_hord_db_update(
|
||||
|
||||
let blocks_db = open_readwrite_hord_db_conn_rocks_db(&config.expected_cache_path(), &ctx)?;
|
||||
let inscriptions_db_conn_rw = open_readwrite_hord_db_conn(&config.expected_cache_path(), &ctx)?;
|
||||
|
||||
|
||||
let _ = fetch_and_cache_blocks_in_hord_db(
|
||||
&bitcoin_config,
|
||||
&blocks_db,
|
||||
|
||||
@@ -876,7 +876,7 @@ pub async fn fetch_and_cache_blocks_in_hord_db(
|
||||
};
|
||||
|
||||
let _ = blocks_db_rw.flush();
|
||||
|
||||
|
||||
if let Err(e) = update_hord_db_and_augment_bitcoin_block(
|
||||
&mut new_block,
|
||||
blocks_db_rw,
|
||||
@@ -961,7 +961,7 @@ pub fn retrieve_satoshi_point_using_local_storage(
|
||||
transaction_identifier: &TransactionIdentifier,
|
||||
inscription_number: u64,
|
||||
ctx: &Context,
|
||||
) -> Result<(TraversalResult, HashMap<u32, CompactedBlock>), String> {
|
||||
) -> Result<TraversalResult, String> {
|
||||
ctx.try_log(|logger| {
|
||||
slog::info!(
|
||||
logger,
|
||||
@@ -983,6 +983,8 @@ pub fn retrieve_satoshi_point_using_local_storage(
|
||||
let mut hops: u32 = 0;
|
||||
let mut local_block_cache = HashMap::new();
|
||||
loop {
|
||||
local_block_cache.clear();
|
||||
|
||||
hops += 1;
|
||||
let block = match local_block_cache.get(&ordinal_block_number) {
|
||||
Some(block) => block,
|
||||
@@ -1107,12 +1109,9 @@ pub fn retrieve_satoshi_point_using_local_storage(
|
||||
let height = Height(ordinal_block_number.into());
|
||||
let ordinal_number = height.starting_sat().0 + ordinal_offset;
|
||||
|
||||
Ok((
|
||||
TraversalResult {
|
||||
inscription_number,
|
||||
ordinal_number,
|
||||
transfers: hops,
|
||||
},
|
||||
local_block_cache,
|
||||
))
|
||||
Ok(TraversalResult {
|
||||
inscription_number,
|
||||
ordinal_number,
|
||||
transfers: hops,
|
||||
})
|
||||
}
|
||||
|
||||
@@ -146,21 +146,32 @@ pub fn update_hord_db_and_augment_bitcoin_block(
|
||||
let (traversal_tx, traversal_rx) = channel::<(TransactionIdentifier, _)>();
|
||||
let traversal_data_pool = ThreadPool::new(10);
|
||||
|
||||
let mut rng = thread_rng();
|
||||
transactions_ids.shuffle(&mut rng);
|
||||
|
||||
for transaction_id in transactions_ids.into_iter() {
|
||||
let moved_traversal_tx = traversal_tx.clone();
|
||||
let moved_ctx = ctx.clone();
|
||||
let block_identifier = new_block.block_identifier.clone();
|
||||
let moved_hord_db_path = hord_db_path.clone();
|
||||
traversal_data_pool.execute(move || {
|
||||
if let Ok(blocks_db) = open_readonly_hord_db_conn_rocks_db(&moved_hord_db_path, &moved_ctx) {
|
||||
let traversal = retrieve_satoshi_point_using_local_storage(
|
||||
&blocks_db,
|
||||
&block_identifier,
|
||||
&transaction_id,
|
||||
0,
|
||||
&moved_ctx,
|
||||
);
|
||||
let _ = moved_traversal_tx.send((transaction_id, traversal));
|
||||
traversal_data_pool.execute(move || loop {
|
||||
match open_readonly_hord_db_conn_rocks_db(&moved_hord_db_path, &moved_ctx) {
|
||||
Ok(blocks_db) => {
|
||||
let traversal = retrieve_satoshi_point_using_local_storage(
|
||||
&blocks_db,
|
||||
&block_identifier,
|
||||
&transaction_id,
|
||||
0,
|
||||
&moved_ctx,
|
||||
);
|
||||
let _ = moved_traversal_tx.send((transaction_id, traversal));
|
||||
break;
|
||||
}
|
||||
Err(e) => {
|
||||
moved_ctx.try_log(|logger| {
|
||||
slog::error!(logger, "unable to open rocksdb: {e}",);
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -168,7 +179,7 @@ pub fn update_hord_db_and_augment_bitcoin_block(
|
||||
let mut traversals_received = 0;
|
||||
while let Ok((transaction_identifier, traversal_result)) = traversal_rx.recv() {
|
||||
traversals_received += 1;
|
||||
let (traversal, _) = traversal_result?;
|
||||
let traversal = traversal_result?;
|
||||
traversals.insert(transaction_identifier, traversal);
|
||||
if traversals_received == expected_traversals {
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user