mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-11 17:41:08 +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:
@@ -264,7 +264,7 @@ mod tests {
|
||||
use consensus_common::{Environment, Proposer, BlockImportParams, BlockOrigin, ForkChoiceStrategy};
|
||||
use node_primitives::DigestItem;
|
||||
use node_runtime::{BalancesCall, Call, UncheckedExtrinsic};
|
||||
use node_runtime::constants::{currency::CENTS, time::SECS_PER_BLOCK};
|
||||
use node_runtime::constants::{currency::CENTS, time::SLOT_DURATION};
|
||||
use parity_codec::{Encode, Decode};
|
||||
use primitives::{
|
||||
crypto::Pair as CryptoPair, blake2_256,
|
||||
@@ -365,7 +365,7 @@ mod tests {
|
||||
// even though there's only one authority some slots might be empty,
|
||||
// so we must keep trying the next slots until we can claim one.
|
||||
let babe_pre_digest = loop {
|
||||
inherent_data.replace_data(timestamp::INHERENT_IDENTIFIER, &(slot_num * SECS_PER_BLOCK));
|
||||
inherent_data.replace_data(timestamp::INHERENT_IDENTIFIER, &(slot_num * SLOT_DURATION));
|
||||
if let Some(babe_pre_digest) = babe::test_helpers::claim_slot(
|
||||
&*service.client(),
|
||||
&parent_id,
|
||||
|
||||
@@ -463,7 +463,7 @@ mod tests {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(42)),
|
||||
function: Call::Timestamp(timestamp::Call::set(42 * 1000)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(0, 0))),
|
||||
@@ -485,7 +485,7 @@ mod tests {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(42)),
|
||||
function: Call::Timestamp(timestamp::Call::set(42 * 1000)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(0, 0))),
|
||||
@@ -500,7 +500,7 @@ mod tests {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(52)),
|
||||
function: Call::Timestamp(timestamp::Call::set(52 * 1000)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((bob(), signed_extra(0, 0))),
|
||||
@@ -528,7 +528,7 @@ mod tests {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(time)),
|
||||
function: Call::Timestamp(timestamp::Call::set(time * 1000)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((alice(), signed_extra(nonce, 0))),
|
||||
@@ -784,7 +784,7 @@ mod tests {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(42)),
|
||||
function: Call::Timestamp(timestamp::Call::set(42 * 1000)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(0, 0))),
|
||||
@@ -983,7 +983,7 @@ mod tests {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(42)),
|
||||
function: Call::Timestamp(timestamp::Call::set(42 * 1000)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(0, 0))),
|
||||
@@ -1000,7 +1000,7 @@ mod tests {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(52)),
|
||||
function: Call::Timestamp(timestamp::Call::set(52 * 1000)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(1, 0))),
|
||||
@@ -1147,7 +1147,7 @@ mod tests {
|
||||
|
||||
xts.insert(0, CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(time)),
|
||||
function: Call::Timestamp(timestamp::Call::set(time * 1000)),
|
||||
});
|
||||
|
||||
// NOTE: this is super slow. Can probably be improved.
|
||||
@@ -1213,7 +1213,7 @@ mod tests {
|
||||
vec![
|
||||
CheckedExtrinsic {
|
||||
signed: None,
|
||||
function: Call::Timestamp(timestamp::Call::set(time)),
|
||||
function: Call::Timestamp(timestamp::Call::set(time * 1000)),
|
||||
},
|
||||
CheckedExtrinsic {
|
||||
signed: Some((charlie(), signed_extra(nonce, 0))),
|
||||
|
||||
@@ -50,7 +50,9 @@ pub type Index = u64;
|
||||
/// A hash of some data used by the chain.
|
||||
pub type Hash = primitives::H256;
|
||||
|
||||
/// A timestamp: seconds since the unix epoch.
|
||||
/// A timestamp: milliseconds since the unix epoch.
|
||||
/// `u64` is enough to represent a duration of half a billion years, when the
|
||||
/// time scale is milliseconds.
|
||||
pub type Timestamp = u64;
|
||||
|
||||
/// Digest item type.
|
||||
|
||||
@@ -18,21 +18,25 @@
|
||||
|
||||
/// Money matters.
|
||||
pub mod currency {
|
||||
use node_primitives::Balance;
|
||||
use node_primitives::Balance;
|
||||
|
||||
pub const MILLICENTS: Balance = 1_000_000_000;
|
||||
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
|
||||
pub const DOLLARS: Balance = 100 * CENTS;
|
||||
pub const MILLICENTS: Balance = 1_000_000_000;
|
||||
pub const CENTS: Balance = 1_000 * MILLICENTS; // assume this is worth about a cent.
|
||||
pub const DOLLARS: Balance = 100 * CENTS;
|
||||
}
|
||||
|
||||
/// Time.
|
||||
pub mod time {
|
||||
use node_primitives::Moment;
|
||||
use node_primitives::Moment;
|
||||
|
||||
pub const SECS_PER_BLOCK: Moment = 6;
|
||||
pub const MINUTES: Moment = 60 / SECS_PER_BLOCK;
|
||||
pub const HOURS: Moment = MINUTES * 60;
|
||||
pub const DAYS: Moment = HOURS * 24;
|
||||
pub const MILLISECS_PER_BLOCK: Moment = 6000;
|
||||
pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000;
|
||||
pub const SLOT_DURATION: Moment = 6000;
|
||||
|
||||
// These time units are defined in number of blocks.
|
||||
pub const MINUTES: Moment = 60 / SECS_PER_BLOCK;
|
||||
pub const HOURS: Moment = MINUTES * 60;
|
||||
pub const DAYS: Moment = HOURS * 24;
|
||||
}
|
||||
|
||||
// CRITICAL NOTE: The system module maintains two constants: a _maximum_ block weight and a
|
||||
@@ -45,8 +49,8 @@ pub mod time {
|
||||
// the ratio that `system` module uses to find normal transaction quota.
|
||||
/// Fee-related.
|
||||
pub mod fee {
|
||||
pub use runtime_primitives::Perbill;
|
||||
pub use runtime_primitives::Perbill;
|
||||
|
||||
/// The block saturation level. Fees will be updates based on this value.
|
||||
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
|
||||
}
|
||||
/// The block saturation level. Fees will be updates based on this value.
|
||||
pub const TARGET_BLOCK_FULLNESS: Perbill = Perbill::from_percent(25);
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
|
||||
// and set impl_version to equal spec_version. If only runtime
|
||||
// implementation changes and behavior does not, then leave spec_version as
|
||||
// is and increment impl_version.
|
||||
spec_version: 121,
|
||||
spec_version: 122,
|
||||
impl_version: 122,
|
||||
apis: RUNTIME_API_VERSIONS,
|
||||
};
|
||||
@@ -166,7 +166,7 @@ impl balances::Trait for Runtime {
|
||||
}
|
||||
|
||||
parameter_types! {
|
||||
pub const MinimumPeriod: u64 = SECS_PER_BLOCK / 2;
|
||||
pub const MinimumPeriod: Moment = SLOT_DURATION / 2;
|
||||
}
|
||||
impl timestamp::Trait for Runtime {
|
||||
type Moment = Moment;
|
||||
|
||||
Reference in New Issue
Block a user