diff --git a/src/bin/inx-chronicle/api/routes.rs b/src/bin/inx-chronicle/api/routes.rs index 03a2a39ac..884a06b0c 100644 --- a/src/bin/inx-chronicle/api/routes.rs +++ b/src/bin/inx-chronicle/api/routes.rs @@ -105,7 +105,7 @@ pub fn password_verify( fn is_new_enough(slot_timestamp: u64) -> bool { // Panic: The slot timestamp is guaranteeed to be valid. - let timestamp = OffsetDateTime::from_unix_timestamp_nanos(slot_timestamp as _).unwrap(); + let timestamp = OffsetDateTime::from_unix_timestamp(slot_timestamp as _).unwrap(); OffsetDateTime::now_utc() <= timestamp + STALE_SLOT_DURATION } diff --git a/src/bin/inx-chronicle/cli/analytics.rs b/src/bin/inx-chronicle/cli/analytics.rs index 459a1b269..58c75b345 100644 --- a/src/bin/inx-chronicle/cli/analytics.rs +++ b/src/bin/inx-chronicle/cli/analytics.rs @@ -111,7 +111,7 @@ impl FillAnalyticsCommand { let (start_index, start_date) = ( start_index, start_date.unwrap_or( - OffsetDateTime::from_unix_timestamp_nanos(start_index.to_timestamp( + OffsetDateTime::from_unix_timestamp(start_index.to_timestamp( protocol_params.genesis_unix_timestamp(), protocol_params.slot_duration_in_seconds(), ) as _) @@ -140,7 +140,7 @@ impl FillAnalyticsCommand { let (end_index, end_date) = ( end_index, end_date.unwrap_or( - OffsetDateTime::from_unix_timestamp_nanos(end_index.to_timestamp( + OffsetDateTime::from_unix_timestamp(end_index.to_timestamp( protocol_params.genesis_unix_timestamp(), protocol_params.slot_duration_in_seconds(), ) as _) diff --git a/src/bin/inx-chronicle/inx/error.rs b/src/bin/inx-chronicle/inx/error.rs index d6bdf684d..bddb72e7f 100644 --- a/src/bin/inx-chronicle/inx/error.rs +++ b/src/bin/inx-chronicle/inx/error.rs @@ -15,4 +15,8 @@ pub enum InxWorkerError { MissingAppState, #[error("network changed from previous run. old network name: `{old}`, new network name: `{new}`")] NetworkChanged { old: String, new: String }, + #[error("node pruned required slots between `{start}` and `{end}`")] + SyncSlotGap { start: SlotIndex, end: SlotIndex }, + #[error("node confirmed slot index `{node}` is less than index in database `{db}`")] + SyncSlotIndexMismatch { node: SlotIndex, db: SlotIndex }, } diff --git a/src/bin/inx-chronicle/inx/mod.rs b/src/bin/inx-chronicle/inx/mod.rs index 4c485221d..49efd1820 100644 --- a/src/bin/inx-chronicle/inx/mod.rs +++ b/src/bin/inx-chronicle/inx/mod.rs @@ -114,6 +114,16 @@ impl InxWorker { node_status.latest_commitment.commitment_id.slot_index() ); + let mut node_configuration = inx.get_node_configuration().await?; + + debug!( + "Connected to network `{}` with base token `{}[{}]`.", + node_configuration.latest_parameters().network_name(), + node_configuration.base_token.name, + node_configuration.base_token.ticker_symbol + ); + + // Check if there is an unfixable gap in our node data. let start_index = if let Some(latest_committed_slot) = self .db .collection::() @@ -122,23 +132,13 @@ impl InxWorker { { latest_committed_slot.slot_index + 1 } else { - self.config.sync_start_slot + self.config.sync_start_slot.max( + node_configuration + .latest_parameters() + .first_slot_of(node_status.pruning_epoch + 1), + ) }; - let node_configuration = inx.get_node_configuration().await?; - - debug!( - "Connected to network `{}` with base token `{}[{}]`.", - node_configuration - .protocol_parameters - .last() - .unwrap() - .parameters - .network_name(), - node_configuration.base_token.name, - node_configuration.base_token.ticker_symbol - ); - if let Some(db_node_config) = self .db .collection::() @@ -223,7 +223,7 @@ impl InxWorker { info!( "Setting starting index to {} with timestamp {}", starting_index, - time::OffsetDateTime::from_unix_timestamp_nanos(slot_timestamp as _)? + time::OffsetDateTime::from_unix_timestamp(slot_timestamp as _)? .format(&time::format_description::well_known::Rfc3339)? ); @@ -245,7 +245,11 @@ impl InxWorker { .set_node_config(&node_configuration) .await?; - Ok((start_index, inx, node_configuration.latest_parameters().clone())) + Ok(( + start_index, + inx, + node_configuration.protocol_parameters.pop().unwrap().parameters, + )) } #[instrument(skip_all, fields(slot_index, created, consumed), err, level = "debug")]