diff --git a/node/log_entry_sync/src/sync_manager/config.rs b/node/log_entry_sync/src/sync_manager/config.rs index 15d540c..d9d281f 100644 --- a/node/log_entry_sync/src/sync_manager/config.rs +++ b/node/log_entry_sync/src/sync_manager/config.rs @@ -32,6 +32,8 @@ pub struct LogSyncConfig { pub remove_finalized_block_interval_minutes: u64, // watch_loop (eth_getLogs) trigger interval pub watch_loop_wait_time_ms: u64, + // force to sync log from start block number + pub force_log_sync_from_start_block_number: bool, } #[derive(Clone)] @@ -58,6 +60,7 @@ impl LogSyncConfig { default_finalized_block_count: u64, remove_finalized_block_interval_minutes: u64, watch_loop_wait_time_ms: u64, + force_log_sync_from_start_block_number: bool, ) -> Self { Self { rpc_endpoint_url, @@ -73,6 +76,7 @@ impl LogSyncConfig { default_finalized_block_count, remove_finalized_block_interval_minutes, watch_loop_wait_time_ms, + force_log_sync_from_start_block_number, } } } diff --git a/node/log_entry_sync/src/sync_manager/mod.rs b/node/log_entry_sync/src/sync_manager/mod.rs index 401462f..f85d7d7 100644 --- a/node/log_entry_sync/src/sync_manager/mod.rs +++ b/node/log_entry_sync/src/sync_manager/mod.rs @@ -102,7 +102,14 @@ impl LogSyncManager { block_hash_cache, }; - let (mut start_block_number, mut start_block_hash) = + let (mut start_block_number, mut start_block_hash) = if log_sync_manager + .config + .force_log_sync_from_start_block_number + { + let block_number = log_sync_manager.config.start_block_number; + let block_hash = log_sync_manager.get_block(block_number.into()).await?.1; + (block_number, block_hash) + } else { match log_sync_manager.store.get_sync_progress()? { // No previous progress, so just use config. None => { @@ -112,7 +119,8 @@ impl LogSyncManager { (block_number, block_hash) } Some((block_number, block_hash)) => (block_number, block_hash), - }; + } + }; let (mut finalized_block_number, mut finalized_block_hash) = match log_sync_manager.get_block(BlockNumber::Finalized).await { diff --git a/node/src/config/convert.rs b/node/src/config/convert.rs index 450fbd0..58c0152 100644 --- a/node/src/config/convert.rs +++ b/node/src/config/convert.rs @@ -156,6 +156,7 @@ impl ZgsConfig { self.default_finalized_block_count, self.remove_finalized_block_interval_minutes, self.watch_loop_wait_time_ms, + self.force_log_sync_from_start_block_number, )) } diff --git a/node/src/config/mod.rs b/node/src/config/mod.rs index ff6ab1c..e5d2bf1 100644 --- a/node/src/config/mod.rs +++ b/node/src/config/mod.rs @@ -33,6 +33,7 @@ build_config! { (blockchain_rpc_endpoint, (String), "http://127.0.0.1:8545".to_string()) (log_contract_address, (String), "".to_string()) (log_sync_start_block_number, (u64), 0) + (force_log_sync_from_start_block_number, (bool), false) (confirmation_block_count, (u64), 12) (log_page_size, (u64), 999) (max_cache_data_size, (usize), 100 * 1024 * 1024) // 100 MB