mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-13 22:11:06 +00:00
Use milliseconds for timestamp resolution (#3210)
* node: tabify constants file * node: define minimum period and slot duration in milliseconds * core: srml: use milliseconds for timestamp resolution * core: update slot_duration to millis in tests * node: bump spec_version * node: fix integration test * node: fix executor test * Update node/runtime/src/lib.rs Co-Authored-By: Kian Peymani <Kianenigma@users.noreply.github.com> * node: fix docs on timestamp resolution * node: add docs on u64 for millis
This commit is contained in:
@@ -764,7 +764,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
const SLOT_DURATION: u64 = 1;
|
||||
const SLOT_DURATION: u64 = 1000;
|
||||
|
||||
pub struct AuraTestNet {
|
||||
peers: Vec<Peer<(), DummySpecialization>>,
|
||||
|
||||
@@ -57,15 +57,14 @@ impl SignedDuration {
|
||||
duration_now() + self.offset
|
||||
} else {
|
||||
duration_now() - self.offset
|
||||
}.as_secs()) / slot_duration
|
||||
}.as_millis() as u64) / slot_duration
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the duration until the next slot, based on current duration since
|
||||
pub fn time_until_next(now: Duration, slot_duration: u64) -> Duration {
|
||||
let remaining_full_secs = slot_duration - (now.as_secs() % slot_duration) - 1;
|
||||
let remaining_nanos = 1_000_000_000 - now.subsec_nanos();
|
||||
Duration::new(remaining_full_secs, remaining_nanos)
|
||||
let remaining_full_millis = slot_duration - (now.as_millis() as u64 % slot_duration) - 1;
|
||||
Duration::from_millis(remaining_full_millis)
|
||||
}
|
||||
|
||||
/// Information about a slot.
|
||||
@@ -89,7 +88,7 @@ impl SlotInfo {
|
||||
if now < self.ends_at {
|
||||
self.ends_at.duration_since(now)
|
||||
} else {
|
||||
Duration::from_secs(0)
|
||||
Duration::from_millis(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -156,7 +155,7 @@ impl<SC: SlotCompatible + Unpin> Stream for Slots<SC> {
|
||||
};
|
||||
// reschedule delay for next slot.
|
||||
let ends_in = offset +
|
||||
time_until_next(Duration::from_secs(timestamp), slot_duration);
|
||||
time_until_next(Duration::from_millis(timestamp), slot_duration);
|
||||
let ends_at = Instant::now() + ends_in;
|
||||
self.inner_delay = Some(Delay::new(ends_in));
|
||||
|
||||
|
||||
@@ -354,7 +354,7 @@ impl srml_system::Trait for Runtime {
|
||||
}
|
||||
|
||||
impl srml_timestamp::Trait for Runtime {
|
||||
/// A timestamp: seconds since the unix epoch.
|
||||
/// A timestamp: milliseconds since the unix epoch.
|
||||
type Moment = u64;
|
||||
type OnTimestampSet = ();
|
||||
type MinimumPeriod = MinimumPeriod;
|
||||
@@ -540,7 +540,7 @@ cfg_if! {
|
||||
}
|
||||
|
||||
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
|
||||
fn slot_duration() -> u64 { 1 }
|
||||
fn slot_duration() -> u64 { 1000 }
|
||||
fn authorities() -> Vec<AuraId> { system::authorities() }
|
||||
}
|
||||
|
||||
@@ -548,7 +548,7 @@ cfg_if! {
|
||||
fn startup_data() -> babe_primitives::BabeConfiguration {
|
||||
babe_primitives::BabeConfiguration {
|
||||
median_required_blocks: 0,
|
||||
slot_duration: 3,
|
||||
slot_duration: 3000,
|
||||
c: (3, 10),
|
||||
}
|
||||
}
|
||||
@@ -731,7 +731,7 @@ cfg_if! {
|
||||
}
|
||||
|
||||
impl aura_primitives::AuraApi<Block, AuraId> for Runtime {
|
||||
fn slot_duration() -> u64 { 1 }
|
||||
fn slot_duration() -> u64 { 1000 }
|
||||
fn authorities() -> Vec<AuraId> { system::authorities() }
|
||||
}
|
||||
|
||||
@@ -739,7 +739,7 @@ cfg_if! {
|
||||
fn startup_data() -> babe_primitives::BabeConfiguration {
|
||||
babe_primitives::BabeConfiguration {
|
||||
median_required_blocks: 0,
|
||||
slot_duration: 1,
|
||||
slot_duration: 1000,
|
||||
c: (3, 10),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user