Skip to content

Commit

Permalink
fix timestamp conversion and start index
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Coats committed Feb 6, 2024
1 parent 84e091c commit fc06497
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/bin/inx-chronicle/api/routes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
4 changes: 2 additions & 2 deletions src/bin/inx-chronicle/cli/analytics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 _)
Expand Down Expand Up @@ -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 _)
Expand Down
4 changes: 4 additions & 0 deletions src/bin/inx-chronicle/inx/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
}
38 changes: 21 additions & 17 deletions src/bin/inx-chronicle/inx/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CommittedSlotCollection>()
Expand All @@ -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::<ApplicationStateCollection>()
Expand Down Expand Up @@ -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)?
);

Expand All @@ -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")]
Expand Down

0 comments on commit fc06497

Please sign in to comment.