mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-26 18:07:58 +00:00
Independence of Slot-based algorithms from system Timestamp (#12224)
* Remove timestamp from SlotInfo * Expose as millis instead of secs * Nits * Fix test after field removal * Yet another test fix * On the fly timestamp computation * Removed slot timestamp from logs * Removed reference to timestamp from slots subsystem * Slot based algorithm tests do not require timstamp inherent anymore * Remove junk files * Further tests cleanup * Trigger pipeline * Apply code suggestions * Trigger pipeline Co-authored-by: André Silva <andrerfosilva@gmail.com>
This commit is contained in:
@@ -42,7 +42,6 @@ use sp_consensus::{Proposal, Proposer, SelectChain, SyncOracle};
|
||||
use sp_consensus_slots::{Slot, SlotDuration};
|
||||
use sp_inherents::CreateInherentDataProviders;
|
||||
use sp_runtime::traits::{Block as BlockT, HashFor, Header as HeaderT};
|
||||
use sp_timestamp::Timestamp;
|
||||
use std::{fmt::Debug, ops::Deref, time::Duration};
|
||||
|
||||
/// The changes that need to applied to the storage to create the state for a block.
|
||||
@@ -252,7 +251,7 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
where
|
||||
Self: Sync,
|
||||
{
|
||||
let (timestamp, slot) = (slot_info.timestamp, slot_info.slot);
|
||||
let slot = slot_info.slot;
|
||||
let telemetry = self.telemetry();
|
||||
let logging_target = self.logging_target();
|
||||
|
||||
@@ -316,23 +315,14 @@ pub trait SimpleSlotWorker<B: BlockT> {
|
||||
return None
|
||||
}
|
||||
|
||||
debug!(
|
||||
target: logging_target,
|
||||
"Starting authorship at slot {}; timestamp = {}", slot, *timestamp,
|
||||
);
|
||||
debug!(target: logging_target, "Starting authorship at slot: {slot}");
|
||||
|
||||
telemetry!(
|
||||
telemetry;
|
||||
CONSENSUS_DEBUG;
|
||||
"slots.starting_authorship";
|
||||
"slot_num" => *slot,
|
||||
"timestamp" => *timestamp,
|
||||
);
|
||||
telemetry!(telemetry; CONSENSUS_DEBUG; "slots.starting_authorship"; "slot_num" => slot);
|
||||
|
||||
let proposer = match self.proposer(&slot_info.chain_head).await {
|
||||
Ok(p) => p,
|
||||
Err(err) => {
|
||||
warn!(target: logging_target, "Unable to author block in slot {:?}: {}", slot, err,);
|
||||
warn!(target: logging_target, "Unable to author block in slot {slot:?}: {err}");
|
||||
|
||||
telemetry!(
|
||||
telemetry;
|
||||
@@ -440,44 +430,35 @@ impl<T: SimpleSlotWorker<B> + Send + Sync, B: BlockT>
|
||||
|
||||
/// Slot specific extension that the inherent data provider needs to implement.
|
||||
pub trait InherentDataProviderExt {
|
||||
/// The current timestamp that will be found in the
|
||||
/// [`InherentData`](`sp_inherents::InherentData`).
|
||||
fn timestamp(&self) -> Timestamp;
|
||||
|
||||
/// The current slot that will be found in the [`InherentData`](`sp_inherents::InherentData`).
|
||||
fn slot(&self) -> Slot;
|
||||
}
|
||||
|
||||
/// Small macro for implementing `InherentDataProviderExt` for inherent data provider tuple.
|
||||
macro_rules! impl_inherent_data_provider_ext_tuple {
|
||||
( T, S $(, $TN:ident)* $( , )?) => {
|
||||
impl<T, S, $( $TN ),*> InherentDataProviderExt for (T, S, $($TN),*)
|
||||
( S $(, $TN:ident)* $( , )?) => {
|
||||
impl<S, $( $TN ),*> InherentDataProviderExt for (S, $($TN),*)
|
||||
where
|
||||
T: Deref<Target = Timestamp>,
|
||||
S: Deref<Target = Slot>,
|
||||
{
|
||||
fn timestamp(&self) -> Timestamp {
|
||||
*self.0.deref()
|
||||
}
|
||||
|
||||
fn slot(&self) -> Slot {
|
||||
*self.1.deref()
|
||||
*self.0.deref()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl_inherent_data_provider_ext_tuple!(T, S);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B, C);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B, C, D);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B, C, D, E);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B, C, D, E, F);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B, C, D, E, F, G);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B, C, D, E, F, G, H);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B, C, D, E, F, G, H, I);
|
||||
impl_inherent_data_provider_ext_tuple!(T, S, A, B, C, D, E, F, G, H, I, J);
|
||||
impl_inherent_data_provider_ext_tuple!(S);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B, C);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B, C, D);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B, C, D, E);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B, C, D, E, F);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B, C, D, E, F, G);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B, C, D, E, F, G, H);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B, C, D, E, F, G, H, I);
|
||||
impl_inherent_data_provider_ext_tuple!(S, A, B, C, D, E, F, G, H, I, J);
|
||||
|
||||
/// Start a new slot worker.
|
||||
///
|
||||
@@ -806,7 +787,6 @@ mod test {
|
||||
super::slots::SlotInfo {
|
||||
slot: slot.into(),
|
||||
duration: SLOT_DURATION,
|
||||
timestamp: Default::default(),
|
||||
inherent_data: Default::default(),
|
||||
ends_at: Instant::now() + SLOT_DURATION,
|
||||
chain_head: Header::new(
|
||||
|
||||
@@ -50,8 +50,6 @@ pub fn time_until_next_slot(slot_duration: Duration) -> Duration {
|
||||
pub struct SlotInfo<B: BlockT> {
|
||||
/// The slot number as found in the inherent data.
|
||||
pub slot: Slot,
|
||||
/// Current timestamp as found in the inherent data.
|
||||
pub timestamp: sp_timestamp::Timestamp,
|
||||
/// The instant at which the slot ends.
|
||||
pub ends_at: Instant,
|
||||
/// The inherent data.
|
||||
@@ -72,7 +70,6 @@ impl<B: BlockT> SlotInfo<B> {
|
||||
/// `ends_at` is calculated using `timestamp` and `duration`.
|
||||
pub fn new(
|
||||
slot: Slot,
|
||||
timestamp: sp_timestamp::Timestamp,
|
||||
inherent_data: InherentData,
|
||||
duration: Duration,
|
||||
chain_head: B::Header,
|
||||
@@ -80,7 +77,6 @@ impl<B: BlockT> SlotInfo<B> {
|
||||
) -> Self {
|
||||
Self {
|
||||
slot,
|
||||
timestamp,
|
||||
inherent_data,
|
||||
duration,
|
||||
chain_head,
|
||||
@@ -175,7 +171,6 @@ where
|
||||
);
|
||||
}
|
||||
|
||||
let timestamp = inherent_data_providers.timestamp();
|
||||
let slot = inherent_data_providers.slot();
|
||||
let inherent_data = inherent_data_providers.create_inherent_data()?;
|
||||
|
||||
@@ -183,14 +178,7 @@ where
|
||||
if slot > self.last_slot {
|
||||
self.last_slot = slot;
|
||||
|
||||
break Ok(SlotInfo::new(
|
||||
slot,
|
||||
timestamp,
|
||||
inherent_data,
|
||||
self.slot_duration,
|
||||
chain_head,
|
||||
None,
|
||||
))
|
||||
break Ok(SlotInfo::new(slot, inherent_data, self.slot_duration, chain_head, None))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user