Skip to content
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

Merged
merged 26 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
19 changes: 10 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,12 @@ cumulus-client-service = { git = "https://github.com/galacticcouncil/polkadot-sd
cumulus-client-collator = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-pallet-aura-ext = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-pallet-dmp-queue = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-pallet-parachain-system = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-pallet-parachain-system = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false, features = [
"parameterized-consensus-hook",
] }
cumulus-pallet-xcm = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-pallet-xcmp-queue = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-primitives-aura = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-primitives-core = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-primitives-parachain-inherent = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
cumulus-primitives-timestamp = { git = "https://github.com/galacticcouncil/polkadot-sdk", branch ="release-polkadot-v1.11.0-patch", default-features = false }
Expand Down
15 changes: 15 additions & 0 deletions launch-configs/zombienet/local.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,21 @@
"--no-hardware-benchmarks",
"--database=paritydb"
],
"genesis": {
"runtimeGenesis": {
"patch": {
"configuration": {
"config": {
"scheduling_lookahead": 2,
"async_backing_params": {
"max_candidate_depth": 3,
"allowed_ancestry_len": 2
}
}
}
}
}
},
"nodes": [
{
"name": "alice",
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "basilisk"
version = "16.0.0"
version = "17.0.0"
description = "Basilisk node"
authors = ["GalacticCouncil"]
edition = "2021"
Expand Down
24 changes: 15 additions & 9 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ use cumulus_client_service::{
build_network, build_relay_chain_interface, prepare_node_config, start_relay_chain_tasks, BuildNetworkParams,
CollatorSybilResistance, DARecoveryProfile, StartRelayChainTasksParams,
};
use cumulus_primitives_core::{relay_chain::CollatorPair, ParaId};
use cumulus_primitives_core::{
relay_chain::{CollatorPair, ValidationCode},
ParaId,
};
use cumulus_relay_chain_interface::{OverseerHandle, RelayChainInterface};

// Substrate Imports
Expand Down Expand Up @@ -251,7 +254,7 @@ async fn start_node_impl(
task_manager: &mut task_manager,
config: parachain_config,
keystore: params.keystore_container.keystore(),
backend,
backend: backend.clone(),
network: network.clone(),
sync_service: sync_service.clone(),
system_rpc_tx,
Expand Down Expand Up @@ -316,6 +319,7 @@ async fn start_node_impl(
if validator {
start_consensus(
client.clone(),
backend.clone(),
block_import,
prometheus_registry.as_ref(),
telemetry.as_ref().map(|t| t.handle()),
Expand Down Expand Up @@ -368,6 +372,7 @@ fn build_import_queue(

fn start_consensus(
client: Arc<ParachainClient>,
backend: Arc<ParachainBackend>,
block_import: ParachainBlockImport,
prometheus_registry: Option<&Registry>,
telemetry: Option<TelemetryHandle>,
Expand All @@ -382,7 +387,7 @@ fn start_consensus(
overseer_handle: OverseerHandle,
announce_block: Arc<dyn Fn(Hash, Option<Vec<u8>>) + Send + Sync>,
) -> Result<(), sc_service::Error> {
use cumulus_client_consensus_aura::collators::basic::{self as basic_aura, Params as BasicAuraParams};
use cumulus_client_consensus_aura::collators::lookahead::{self as aura, Params as AuraParams};

// NOTE: because we use Aura here explicitly, we can use `CollatorSybilResistance::Resistant`
// when starting the network.
Expand All @@ -404,11 +409,13 @@ fn start_consensus(
client.clone(),
);

let params = BasicAuraParams {
let params = AuraParams {
create_inherent_data_providers: move |_, ()| async move { Ok(()) },
block_import,
para_client: client,
para_client: client.clone(),
para_backend: backend.clone(),
relay_client: relay_chain_interface,
code_hash_provider: move |block_hash| client.code_at(block_hash).ok().map(|c| ValidationCode::from(c).hash()),
sync_oracle,
keystore,
collator_key,
Expand All @@ -417,12 +424,11 @@ fn start_consensus(
relay_chain_slot_duration,
proposer,
collator_service,
// Very limited proposal time.
authoring_duration: Duration::from_millis(500),
collation_request_receiver: None,
authoring_duration: Duration::from_millis(1500),
Copy link
Contributor

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

Copy link
Member

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

reinitialize: false,
};

let fut = basic_aura::run::<Block, sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _, _>(params);
let fut = aura::run::<Block, sp_consensus_aura::sr25519::AuthorityPair, _, _, _, _, _, _, _, _, _>(params);
task_manager.spawn_essential_handle().spawn("aura", None, fut);

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion primitives/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "primitives"
version = "6.6.3"
version = "6.6.4"
authors = ["GalacticCouncil"]
edition = "2021"
repository = "https://github.com/galacticcouncil/Basilisk-node"
Expand Down
35 changes: 11 additions & 24 deletions primitives/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The 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;
}
Expand All @@ -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),
Copy link
Member

Choose a reason for hiding this comment

The 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,
);

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion runtime/basilisk/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "basilisk-runtime"
version = "121.0.0"
version = "122.0.0"
authors = ["GalacticCouncil"]
edition = "2021"
homepage = "https://github.com/galacticcouncil/Basilisk-node"
Expand Down Expand Up @@ -74,6 +74,7 @@ cumulus-pallet-aura-ext = { workspace = true }
cumulus-pallet-parachain-system = { workspace = true }
cumulus-pallet-xcm = { workspace = true }
cumulus-pallet-xcmp-queue = { workspace = true }
cumulus-primitives-aura = { workspace = true }
cumulus-primitives-core = { workspace = true }
cumulus-primitives-utility = { workspace = true }
cumulus-primitives-parachain-inherent = { workspace = true }
Expand Down Expand Up @@ -200,6 +201,7 @@ std = [
"cumulus-pallet-aura-ext/std",
"cumulus-pallet-xcm/std",
"cumulus-pallet-xcmp-queue/std",
"cumulus-primitives-aura/std",
"cumulus-primitives-core/std",
"polkadot-xcm/std",
"xcm-builder/std",
Expand Down
9 changes: 9 additions & 0 deletions runtime/basilisk/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ impl_runtime_apis! {
}
}

impl cumulus_primitives_aura::AuraUnincludedSegmentApi<Block> for Runtime {
fn can_build_upon(
included_hash: <Block as BlockT>::Hash,
slot: cumulus_primitives_aura::Slot,
) -> bool {
ConsensusHook::can_build_upon(included_hash, slot)
}
}

#[cfg(feature = "runtime-benchmarks")]
impl frame_benchmarking::Benchmark<Block> for Runtime {
fn benchmark_metadata(extra: bool) -> (
Expand Down
30 changes: 4 additions & 26 deletions runtime/basilisk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ use frame_support::sp_runtime::{
};
use frame_system::pallet_prelude::BlockNumberFor;
pub use primitives::{
AccountId, Amount, AssetId, Balance, BlockNumber, CollectionId, Hash, Index, ItemId, Price, Signature,
constants::time::SLOT_DURATION, AccountId, Amount, AssetId, Balance, BlockNumber, CollectionId, Hash, Index,
ItemId, Price, Signature,
};
pub use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{ConstU32, ConstU64};
use sp_core::ConstU32;
use sp_std::{convert::From, marker::PhantomData, prelude::*, vec};
#[cfg(feature = "std")]
use sp_version::NativeVersion;
Expand Down Expand Up @@ -100,7 +101,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("basilisk"),
impl_name: create_runtime_str!("basilisk"),
authoring_version: 1,
spec_version: 121,
spec_version: 122,
impl_version: 0,
apis: apis::RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -359,30 +360,7 @@ mod benches {
);
}

jak-pan marked this conversation as resolved.
Show resolved Hide resolved
struct CheckInherents;

impl cumulus_pallet_parachain_system::CheckInherents<Block> for CheckInherents {
fn check_inherents(
block: &Block,
relay_state_proof: &cumulus_pallet_parachain_system::RelayChainStateProof,
) -> sp_inherents::CheckInherentsResult {
let relay_chain_slot = relay_state_proof
.read_slot()
.expect("Could not read the relay chain slot from the proof");

let inherent_data = cumulus_primitives_timestamp::InherentDataProvider::from_relay_chain_slot_and_duration(
relay_chain_slot,
sp_std::time::Duration::from_secs(6),
)
.create_inherent_data()
.expect("Could not create the timestamp inherent data");

inherent_data.check_extrinsics(block)
}
}

cumulus_pallet_parachain_system::register_validate_block! {
Runtime = Runtime,
BlockExecutor = cumulus_pallet_aura_ext::BlockExecutor::<Runtime, Executive>,
CheckInherents = CheckInherents,
}
Loading
Loading