Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions cumulus/polkadot-omni-node/lib/src/nodes/aura.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ use sp_runtime::{
traits::{Block as BlockT, Header as HeaderT, UniqueSaturatedInto},
};
use sp_transaction_storage_proof::runtime_api::TransactionStorageApi;
use std::{marker::PhantomData, sync::Arc, time::Duration};
use std::{marker::PhantomData, ops::Sub, sync::Arc, time::Duration};

struct Verifier<Block, Client, AuraId> {
client: Arc<Client>,
Expand Down Expand Up @@ -414,6 +414,16 @@ where
>,
> + Send
+ Sync {
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u64 = 6000;

// Start 2 hours in the past to avoid timestamps immediately running into the future.
let initial_relay_slot = std::time::SystemTime::now()
.duration_since(std::time::UNIX_EPOCH)
.expect("Current time is always after UNIX_EPOCH; qed")
.sub(Duration::from_hours(2))
.as_millis() as u64 /
RELAY_CHAIN_SLOT_DURATION_MILLIS;

move |block: Hash, ()| {
let current_para_head = client
.header(block)
Expand All @@ -435,17 +445,21 @@ where
let relay_parent_offset =
client.runtime_api().relay_parent_offset(block).unwrap_or_default();

// Standard relay chain slot duration for all relay chain networks.
const RELAY_CHAIN_SLOT_DURATION_MILLIS: u64 = 6000;
// Each block gets a unique relay slot: initial_relay_slot + block_number
let target_relay_slot = initial_relay_slot + u64::from(current_block_number);

let relay_blocks_per_para_block =
(slot_duration.as_millis() / RELAY_CHAIN_SLOT_DURATION_MILLIS).max(1) as u32;

let relay_offset = (target_relay_slot as u32)
.saturating_sub(relay_blocks_per_para_block * current_block_number);

let mocked_parachain = MockValidationDataInherentDataProvider::<()> {
current_para_block: current_block_number,
para_id,
current_para_block_head,
relay_blocks_per_para_block,
relay_offset,
relay_parent_offset,
para_blocks_per_relay_epoch: 10,
upgrade_go_ahead: should_send_go_ahead.then(|| {
Expand All @@ -455,9 +469,9 @@ where
..Default::default()
};

let timestamp_provider = sp_timestamp::InherentDataProvider::new(
(slot_duration.as_millis() * current_block_number as u64).into(),
);
let timestamp = target_relay_slot * RELAY_CHAIN_SLOT_DURATION_MILLIS;

let timestamp_provider = sp_timestamp::InherentDataProvider::new(timestamp.into());

futures::future::ready(Ok((timestamp_provider, mocked_parachain)))
}
Expand Down
10 changes: 10 additions & 0 deletions prdoc/pr_10807.prdoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
title: 'Omni-node: Move timestamps closer to now'
doc:
- audience: Node Dev
description: |-
In omni-node dev-mode the timestamps where showing close to the unix epoch. Technically not a problem, but its a bit more aesthetic if they are closer to now, as requested in https://github.com/paritytech/polkadot-sdk/issues/10759.

I set them arbitrarily to two hours in the past so that they do not run immediately into the future.
crates:
- name: polkadot-omni-node-lib
bump: patch
Loading