Skip to content

Commit 5dd300f

Browse files
author
Ludo Galabru
committed
fix: logic determining start height
1 parent bbede8b commit 5dd300f

File tree

1 file changed

+12
-12
lines changed
  • components/ordhook-core/src/core

1 file changed

+12
-12
lines changed

components/ordhook-core/src/core/mod.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@ use chainhook_sdk::{
1212
utils::Context,
1313
};
1414

15-
use crate::config::{Config, LogConfig};
15+
use crate::{
16+
config::{Config, LogConfig},
17+
db::find_lazy_block_at_block_height,
18+
};
1619

1720
use crate::db::{
1821
find_last_block_inserted, find_latest_inscription_block_height, initialize_ordhook_db,
@@ -107,16 +110,8 @@ pub fn should_sync_ordhook_db(
107110
}
108111
};
109112

110-
let mut start_block =
111-
match open_readonly_ordhook_db_conn_rocks_db(&config.expected_cache_path(), &ctx) {
112-
Ok(blocks_db) => find_last_block_inserted(&blocks_db) as u64,
113-
Err(err) => {
114-
ctx.try_log(|logger| {
115-
warn!(logger, "{}", err);
116-
});
117-
0
118-
}
119-
};
113+
let blocks_db = open_readonly_ordhook_db_conn_rocks_db(&config.expected_cache_path(), &ctx)?;
114+
let mut start_block = find_last_block_inserted(&blocks_db) as u64;
120115

121116
if start_block == 0 {
122117
let _ = initialize_ordhook_db(&config.expected_cache_path(), &ctx);
@@ -126,7 +121,12 @@ pub fn should_sync_ordhook_db(
126121

127122
match find_latest_inscription_block_height(&inscriptions_db_conn, ctx)? {
128123
Some(height) => {
129-
start_block = start_block.min(height);
124+
if find_lazy_block_at_block_height(height as u32, 3, false, &blocks_db, &ctx).is_none()
125+
{
126+
start_block = start_block.min(height);
127+
} else {
128+
start_block = height;
129+
}
130130
}
131131
None => {
132132
start_block = start_block.min(config.get_ordhook_config().first_inscription_height);

0 commit comments

Comments
 (0)