Skip to content

Commit

Permalink
Merge pull request #278 from Concordium/timestamptz
Browse files Browse the repository at this point in the history
Use timestamptz for storing slot_time
  • Loading branch information
limemloh authored Oct 24, 2024
2 parents e519e00 + 286d5c2 commit b3133bc
Show file tree
Hide file tree
Showing 15 changed files with 27 additions and 28 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion backend-rust/migrations/0001_initialize.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ CREATE TABLE blocks(
NOT NULL,
-- Timestamp for when the block was baked.
slot_time
TIMESTAMP
TIMESTAMPTZ
NOT NULL,
-- Milliseconds between the slot_time of this block and the block below (height - 1).
-- For the genesis block it will be 0.
Expand Down
7 changes: 3 additions & 4 deletions backend-rust/src/graphql_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,7 +1174,7 @@ type AccountIndex = i64;
type TransactionIndex = i64;
type Amount = i64; // TODO: should be UnsignedLong in graphQL
type Energy = i64; // TODO: should be UnsignedLong in graphQL
type DateTime = chrono::NaiveDateTime; // TODO check format matches.
type DateTime = chrono::DateTime<chrono::Utc>; // TODO check format matches.
type ContractIndex = UnsignedLong; // TODO check format.
type BigInteger = u64; // TODO check format.
type MetadataUrl = String;
Expand Down Expand Up @@ -3869,12 +3869,11 @@ pub fn events_from_summary(
}
BlockItemSummaryDetails::Update(details) => {
vec![Event::ChainUpdateEnqueued(ChainUpdateEnqueued {
effective_time: chrono::DateTime::from_timestamp(
effective_time: DateTime::from_timestamp(
details.effective_time.seconds.try_into()?,
0,
)
.context("Failed to parse effective time")?
.naive_utc(),
.context("Failed to parse effective time")?,
payload: true, // placeholder
})]
}
Expand Down
14 changes: 7 additions & 7 deletions backend-rust/src/indexer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::graphql_api::{
CredentialDeploymentTransactionType, DbTransactionType, UpdateTransactionType,
};
use anyhow::Context;
use chrono::NaiveDateTime;
use chrono::{DateTime, Utc};
use concordium_rust_sdk::{
base::{contracts_common::to_bytes, smart_contracts::WasmVersion},
common::types::Amount,
Expand Down Expand Up @@ -555,7 +555,7 @@ struct BlockProcessingContext {
last_finalized_hash: String,
/// The slot time of the last processed block.
/// This is used when computing the block time.
last_block_slot_time: NaiveDateTime,
last_block_slot_time: DateTime<Utc>,
}

/// Raw block information fetched from a Concordium Node.
Expand All @@ -577,7 +577,7 @@ async fn save_genesis_data(endpoint: v2::Endpoint, pool: &PgPool) -> anyhow::Res
{
let genesis_block_info = client.get_block_info(genesis_height).await?.response;
let block_hash = genesis_block_info.block_hash.to_string();
let slot_time = genesis_block_info.block_slot_time.naive_utc();
let slot_time = genesis_block_info.block_slot_time;
let genesis_tokenomics = client.get_tokenomics_info(genesis_height).await?.response;
let total_staked = match genesis_tokenomics {
RewardsOverview::V0 {
Expand Down Expand Up @@ -672,7 +672,7 @@ struct PreparedBlock {
/// Absolute height of the block.
height: i64,
/// Block slot time (UTC).
slot_time: NaiveDateTime,
slot_time: DateTime<Utc>,
/// Id of the validator which constructed the block. Is only None for the
/// genesis block.
baker_id: Option<i64>,
Expand All @@ -691,7 +691,7 @@ impl PreparedBlock {
let height = i64::try_from(data.finalized_block_info.height.height)?;
let hash = data.finalized_block_info.block_hash.to_string();
let block_last_finalized = data.block_info.block_last_finalized.to_string();
let slot_time = data.block_info.block_slot_time.naive_utc();
let slot_time = data.block_info.block_slot_time;
let baker_id = if let Some(index) = data.block_info.block_baker {
Some(i64::try_from(index.id.index)?)
} else {
Expand Down Expand Up @@ -767,7 +767,7 @@ impl PreparedBlock {
SELECT * FROM UNNEST(
$1::BIGINT[],
$2::TEXT[],
$3::TIMESTAMP[],
$3::TIMESTAMPTZ[],
$4::BIGINT[],
$5::BIGINT[],
$6::BIGINT[],
Expand Down Expand Up @@ -795,7 +795,7 @@ SELECT * FROM UNNEST(
UPDATE blocks
SET finalization_time = EXTRACT("MILLISECONDS" FROM finalizer.slot_time - blocks.slot_time),
finalized_by = finalizer.height
FROM UNNEST($1::BIGINT[], $2::TEXT[], $3::TIMESTAMP[]) AS finalizer(height, finalized, slot_time)
FROM UNNEST($1::BIGINT[], $2::TEXT[], $3::TIMESTAMPTZ[]) AS finalizer(height, finalized, slot_time)
JOIN blocks last ON finalizer.finalized = last.hash
WHERE blocks.finalization_time IS NULL AND blocks.height <= last.height
"#,
Expand Down

0 comments on commit b3133bc

Please sign in to comment.