-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 6 second block time #672
Changes from 14 commits
5eb0175
d5250a1
a7f2f37
c37a4d2
8c8793a
5cdd524
761aada
e8be7af
ca493a2
3d0017d
d3db553
67f2441
f3cd136
f59f861
463f392
938605e
91d902c
867804b
1918d6b
4318938
4766872
ce92f88
a8b7c07
fd87fe9
8cde540
da8ca57
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,32 +39,19 @@ pub mod currency { | |
pub mod time { | ||
use crate::{BlockNumber, Moment}; | ||
|
||
/// Since BABE is probabilistic this is the average expected block time that | ||
/// we are targeting. Blocks will be produced at a minimum duration defined | ||
/// by `SLOT_DURATION`, but some slots will not be allocated to any | ||
/// authority and hence no block will be produced. We expect to have this | ||
/// block time on average following the defined slot duration and the value | ||
/// of `c` configured for BABE (where `1 - c` represents the probability of | ||
/// a slot being empty). | ||
/// This value is only used indirectly to define the unit constants below | ||
/// that are expressed in blocks. The rest of the code should use | ||
/// `SLOT_DURATION` instead (like the Timestamp pallet for calculating the | ||
/// minimum period). | ||
/// BLOCKS will be produced at a minimum duration defined by `SLOT_DURATION`. | ||
/// `SLOT_DURATION` is picked up by `pallet_timestamp` which is in turn picked | ||
/// up by `pallet_aura` to implement `fn slot_duration()`. | ||
/// | ||
/// If using BABE with secondary slots (default) then all of the slots will | ||
/// always be assigned, in which case `MILLISECS_PER_BLOCK` and | ||
/// `SLOT_DURATION` should have the same value. | ||
/// | ||
/// <https://research.web3.foundation/en/latest/polkadot/BABE/Babe/#6-practical-results> | ||
|
||
pub const MILLISECS_PER_BLOCK: u64 = 12000; | ||
/// Change this to adjust the block time. | ||
pub const MILLISECS_PER_BLOCK: u64 = 6000; | ||
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; | ||
|
||
// Time is measured by number of blocks. | ||
pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); | ||
pub const HOURS: BlockNumber = MINUTES * 60; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. session length uses this constant, and that shouldn't probably change as it would break conversion from block number to session |
||
pub const DAYS: BlockNumber = HOURS * 24; | ||
|
||
pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; | ||
pub const SECS_PER_BLOCK: Moment = MILLISECS_PER_BLOCK / 1000; | ||
pub const EPOCH_DURATION_IN_BLOCKS: BlockNumber = 4 * HOURS; | ||
} | ||
|
@@ -88,9 +75,9 @@ pub mod chain { | |
/// Minimum pool liquidity | ||
pub const MIN_POOL_LIQUIDITY: Balance = 1000; | ||
|
||
/// We allow for | ||
/// We allow for 2 seconds of compute with a 6 second average block. | ||
pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( | ||
WEIGHT_REF_TIME_PER_SECOND.saturating_div(2), | ||
WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. size of block (weight) is 4x what was before @jak-pan |
||
polkadot_primitives::v7::MAX_POV_SIZE as u64, | ||
); | ||
|
||
|
@@ -109,10 +96,10 @@ mod tests { | |
assert_eq!(DAYS / 24, HOURS); | ||
// 60 minuts in an hour | ||
assert_eq!(HOURS / 60, MINUTES); | ||
// 1 minute = 60s = 5 blocks 12s each | ||
assert_eq!(MINUTES, 5); | ||
// 1 minute = 60s = 10 blocks 6s each | ||
assert_eq!(MINUTES, 10); | ||
// 6s per block | ||
assert_eq!(SECS_PER_BLOCK, 12); | ||
assert_eq!(SECS_PER_BLOCK, 6); | ||
// 1s = 1000ms | ||
assert_eq!(MILLISECS_PER_BLOCK / 1000, SECS_PER_BLOCK); | ||
// Extra check for epoch time because changing it bricks the block production and requires regenesis | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't mean execution time right? It's just how much time we have to propose a block
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is node code, so the collators can have more time to propose blocks, size of block is defined in runtime