Skip to content

Commit

Permalink
feat: ability to resume
Browse files Browse the repository at this point in the history
  • Loading branch information
lgalabru committed Aug 3, 2023
1 parent 20d9df6 commit 6c7eaa3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
16 changes: 16 additions & 0 deletions components/hord-cli/src/db/mod.rs
Expand Up @@ -528,6 +528,22 @@ pub fn find_latest_inscription_transfer_data(
Ok(None)
}

pub fn find_latest_transfers_block_height(
inscriptions_db_conn: &Connection,
_ctx: &Context,
) -> Option<u64> {
let args: &[&dyn ToSql] = &[];
let mut stmt = inscriptions_db_conn
.prepare("SELECT block_height FROM locations ORDER BY block_height DESC LIMIT 1")
.unwrap();
let mut rows = stmt.query(args).unwrap();
while let Ok(Some(row)) = rows.next() {
let block_height: u64 = row.get(0).unwrap();
return Some(block_height)
}
None
}

#[derive(Debug, Clone)]
pub struct TransferData {
pub inscription_offset_intra_output: u64,
Expand Down
12 changes: 6 additions & 6 deletions components/hord-cli/src/service/mod.rs
Expand Up @@ -12,7 +12,7 @@ use crate::core::{
};
use crate::db::{
find_latest_inscription_block_height, initialize_hord_db, insert_entry_in_blocks,
open_readonly_hord_db_conn, open_readwrite_hord_dbs, InscriptionHeigthHint, LazyBlock,
open_readonly_hord_db_conn, open_readwrite_hord_dbs, InscriptionHeigthHint, LazyBlock, find_latest_transfers_block_height,
};
use crate::scan::bitcoin::process_block_with_predicates;
use crate::service::http_api::{load_predicates_from_redis, start_predicate_api_server};
Expand Down Expand Up @@ -59,7 +59,6 @@ impl Service {
// std::thread::sleep(std::time::Duration::from_secs(1200));

let _ = initialize_hord_db(&self.config.expected_cache_path(), &self.ctx);

// Force rebuild
// {
// let blocks_db = open_readwrite_hord_db_conn_rocks_db(
Expand Down Expand Up @@ -107,16 +106,17 @@ impl Service {
})
.expect("unable to spawn thread");

let tip = {

let (cursor, tip) = {
let inscriptions_db_conn =
open_readonly_hord_db_conn(&self.config.expected_cache_path(), &self.ctx)?;
let cursor = find_latest_transfers_block_height(&inscriptions_db_conn, &self.ctx).unwrap_or(1);
match find_latest_inscription_block_height(&inscriptions_db_conn, &self.ctx)? {
Some(height) => height,
Some(height) => (cursor, height),
None => panic!(),
}
};

self.replay_transfers(775808, tip, Some(tx_replayer.clone()))
self.replay_transfers(cursor, tip, Some(tx_replayer.clone()))
.await?;
self.update_state(Some(tx_replayer.clone())).await?;

Expand Down

0 comments on commit 6c7eaa3

Please sign in to comment.