Skip to content

Commit e082831

Browse files
authored
Merge pull request #776 from hyperware-ai/hf/cacher-fix-bootstrap-add-more-bootstrappers
hypermap-cacher: fix bootstrap & add more bootstrappers
2 parents eef82c4 + 0ff47ef commit e082831

File tree

2 files changed

+30
-19
lines changed
  • hyperdrive/packages
    • hns-indexer/hns-indexer/src
    • hypermap-cacher/hypermap-cacher/src

2 files changed

+30
-19
lines changed

hyperdrive/packages/hns-indexer/hns-indexer/src/lib.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,16 @@ const SUBSCRIPTION_TIMEOUT_S: u64 = 60;
3131
const DELAY_MS: u64 = 2_000;
3232
const CHECKPOINT_MS: u64 = 5 * 60 * 1_000; // 5 minutes
3333

34+
#[cfg(not(feature = "simulation-mode"))]
35+
const DEFAULT_NODES: &[&str] = &[
36+
"us-cacher-1.hypr",
37+
"eu-cacher-1.hypr",
38+
"nick.hypr",
39+
"nick1udwig.os",
40+
];
41+
#[cfg(feature = "simulation-mode")]
42+
const DEFAULT_NODES: &[&str] = &["fake.os"];
43+
3444
type PendingNotes = BTreeMap<u64, Vec<(String, String, eth::Bytes, u8)>>;
3545

3646
#[derive(serde::Serialize, serde::Deserialize)]
@@ -795,7 +805,7 @@ fn main(our: &Address, state: &mut StateV1) -> anyhow::Result<()> {
795805
// if block in state is < current_block, get logs from that part.
796806
info!("syncing old logs from block: {}", state.last_block);
797807

798-
let nodes: HashSet<String> = ["nick.hypr".to_string()].into_iter().collect();
808+
let nodes: HashSet<String> = DEFAULT_NODES.iter().map(|s| s.to_string()).collect();
799809
state.fetch_and_process_logs(nodes);
800810

801811
// set a timer tick so any pending logs will be processed

hyperdrive/packages/hypermap-cacher/hypermap-cacher/src/lib.rs

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,12 @@ const RETRY_DELAY_S: u64 = 10;
3737
const LOG_ITERATION_DELAY_MS: u64 = 200;
3838

3939
#[cfg(not(feature = "simulation-mode"))]
40-
const DEFAULT_NODES: &[&str] = &["nick.hypr", "nick1udwig.os"];
40+
const DEFAULT_NODES: &[&str] = &[
41+
"us-cacher-1.hypr",
42+
"eu-cacher-1.hypr",
43+
"nick.hypr",
44+
"nick1udwig.os",
45+
];
4146
#[cfg(feature = "simulation-mode")]
4247
const DEFAULT_NODES: &[&str] = &["fake.os"];
4348

@@ -784,22 +789,15 @@ impl State {
784789
self.last_cached_block + 1
785790
);
786791

787-
// Only run RPC bootstrap if we're behind the current chain head
788-
let current_chain_head = hypermap.provider.get_block_number()?;
789-
if self.last_cached_block < current_chain_head {
790-
self.cache_logs_and_update_manifest(hypermap)?;
792+
// Catch up remainder (or as fallback) using RPC
793+
self.cache_logs_and_update_manifest(hypermap)?;
794+
795+
// run it twice for fresh boot case:
796+
// - initial bootstrap takes much time
797+
// - in that time, the block you are updating to is no longer the head of the chain
798+
// - so run again to get to the head of the chain
799+
self.cache_logs_and_update_manifest(hypermap)?;
791800

792-
// run it twice for fresh boot case:
793-
// - initial bootstrap takes much time
794-
// - in that time, the block you are updating to is no longer the head of the chain
795-
// - so run again to get to the head of the chain
796-
self.cache_logs_and_update_manifest(hypermap)?;
797-
} else {
798-
info!(
799-
"Already caught up to chain head ({}), no RPC bootstrap needed",
800-
current_chain_head
801-
);
802-
}
803801
Ok(())
804802
}
805803

@@ -1184,10 +1182,13 @@ fn main_loop(
11841182
info!("Last cached block: {}", state.last_cached_block);
11851183

11861184
// Always bootstrap on start to get latest state from other nodes or RPC
1187-
if state.is_starting {
1185+
while state.is_starting {
11881186
match state.bootstrap_state(hypermap) {
11891187
Ok(_) => info!("Bootstrap process completed successfully."),
1190-
Err(e) => error!("Error during bootstrap process: {:?}", e),
1188+
Err(e) => {
1189+
error!("Error during bootstrap process: {:?}", e);
1190+
std::thread::sleep(std::time::Duration::from_secs(RETRY_DELAY_S));
1191+
}
11911192
}
11921193
}
11931194

0 commit comments

Comments
 (0)