diff --git a/Cargo.lock b/Cargo.lock index 80963b3133..4e7becd520 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1177,7 +1177,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-primitives", "polkadot-service", - "primitives 6.7.0", + "primitives 6.7.1", "sc-basic-authorship", "sc-block-builder", "sc-chain-spec", @@ -1258,7 +1258,7 @@ dependencies = [ "polkadot-parachain-primitives", "pretty_assertions", "primitive-types 0.13.1", - "primitives 6.7.0", + "primitives 6.7.1", "scale-info", "sp-core", "sp-io", @@ -1289,7 +1289,7 @@ dependencies = [ [[package]] name = "basilisk-runtime" -version = "132.0.0" +version = "133.0.0" dependencies = [ "basilisk-adapters", "basilisk-math", @@ -1374,7 +1374,7 @@ dependencies = [ "polkadot-parachain-primitives", "polkadot-runtime-common", "primitive-types 0.13.1", - "primitives 6.7.0", + "primitives 6.7.1", "scale-info", "serde", "smallvec", @@ -8657,7 +8657,7 @@ dependencies = [ "pallet-uniques", "parity-scale-codec", "pretty_assertions", - "primitives 6.7.0", + "primitives 6.7.1", "scale-info", "serde", "sp-arithmetic", @@ -9092,7 +9092,7 @@ dependencies = [ "pallet-currencies", "parity-scale-codec", "pretty_assertions", - "primitives 6.7.0", + "primitives 6.7.1", "scale-info", "serde", "sp-core", @@ -9358,7 +9358,7 @@ dependencies = [ "pallet-utility", "pallet-xyk", "parity-scale-codec", - "primitives 6.7.0", + "primitives 6.7.1", "scale-info", "sp-api", "sp-core", @@ -9604,7 +9604,7 @@ dependencies = [ "pallet-xyk", "parity-scale-codec", "pretty_assertions", - "primitives 6.7.0", + "primitives 6.7.1", "scale-info", "sp-arithmetic", "sp-core", @@ -9633,7 +9633,7 @@ dependencies = [ "pallet-xyk", "pallet-xyk-liquidity-mining", "parity-scale-codec", - "primitives 6.7.0", + "primitives 6.7.1", "scale-info", "sp-arithmetic", "sp-core", @@ -11393,7 +11393,7 @@ dependencies = [ [[package]] name = "primitives" -version = "6.7.0" +version = "6.7.1" dependencies = [ "frame-support", "parity-scale-codec", @@ -12412,7 +12412,7 @@ dependencies = [ "polkadot-runtime-parachains", "polkadot-service", "pretty_assertions", - "primitives 6.7.0", + "primitives 6.7.1", "rococo-runtime", "sc-consensus-grandpa", "sp-api", diff --git a/README.md b/README.md index afd51c605b..a7388f22b1 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,12 @@ Prerequisites: * Grab `zombienet` utility used to start network from [releases](https://github.com/paritytech/zombienet/releases) -``` +```bash cd ./launch-configs/zombienet zombienet spawn local.json + +// Enable 2s blocktime +node scripts/assign_cores.js ``` ### Interaction with the node diff --git a/launch-configs/zombienet/local.json b/launch-configs/zombienet/local.json index 6169f0ffc9..16fadfc6e4 100644 --- a/launch-configs/zombienet/local.json +++ b/launch-configs/zombienet/local.json @@ -15,8 +15,11 @@ "patch": { "configuration": { "config": { + "scheduler_params": { + "num_cores": 3 + }, "async_backing_params": { - "max_candidate_depth": 3, + "max_candidate_depth": 6, "allowed_ancestry_len": 2 } } @@ -28,6 +31,7 @@ { "name": "alice", "ws_port": 9944, + "rpc_port": 9945, "validator": true }, { diff --git a/node/src/service.rs b/node/src/service.rs index 8f3cbcedeb..8932b89365 100644 --- a/node/src/service.rs +++ b/node/src/service.rs @@ -436,7 +436,7 @@ fn start_consensus( para_id, proposer, collator_service, - authoring_duration: Duration::from_millis(1500), + authoring_duration: Duration::from_millis(2000), reinitialize: false, slot_offset: Duration::from_secs(1), block_import_handle, diff --git a/primitives/Cargo.toml b/primitives/Cargo.toml index 023a509d44..a664a1afc2 100644 --- a/primitives/Cargo.toml +++ b/primitives/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "primitives" -version = "6.7.0" +version = "6.7.1" authors = ["GalacticCouncil"] edition = "2021" repository = "https://github.com/galacticcouncil/Basilisk-node" diff --git a/primitives/src/constants.rs b/primitives/src/constants.rs index c2d60f79f5..942e65c6ab 100644 --- a/primitives/src/constants.rs +++ b/primitives/src/constants.rs @@ -44,8 +44,12 @@ pub mod time { /// up by `pallet_aura` to implement `fn slot_duration()`. /// /// Change this to adjust the block time. - pub const MILLISECS_PER_BLOCK: u64 = 6000; - pub const SLOT_DURATION: u64 = MILLISECS_PER_BLOCK; + pub const MILLISECS_PER_BLOCK: u64 = 2000; + + // The slot duration determines the length of each author's turn and is decoupled from the block + // production interval. During their slot, authors are allowed to produce multiple blocks. **The + // slot duration is required to be at least 6s (same as on the relay chain).** + pub const SLOT_DURATION: u64 = 6000; // Time is measured by number of blocks. pub const MINUTES: BlockNumber = 60_000 / (MILLISECS_PER_BLOCK as BlockNumber); @@ -75,9 +79,9 @@ pub mod chain { /// Minimum pool liquidity pub const MIN_POOL_LIQUIDITY: Balance = 1000; - /// We allow for 2 seconds of compute with a 6 second average block. + /// We allow for 1.5 seconds of compute with a 2 second average block. pub const MAXIMUM_BLOCK_WEIGHT: Weight = Weight::from_parts( - WEIGHT_REF_TIME_PER_SECOND.saturating_mul(2), + WEIGHT_REF_TIME_PER_SECOND.saturating_mul(3).saturating_div(2), polkadot_primitives::v8::MAX_POV_SIZE as u64, ); @@ -96,10 +100,10 @@ mod tests { assert_eq!(DAYS / 24, HOURS); // 60 minuts in an hour assert_eq!(HOURS / 60, MINUTES); - // 1 minute = 60s = 10 blocks 6s each - assert_eq!(MINUTES, 10); - // 6s per block - assert_eq!(SECS_PER_BLOCK, 6); + // 1 minute = 60s = 10 blocks 2s each + assert_eq!(MINUTES, 30); + // 2s per block + assert_eq!(SECS_PER_BLOCK, 2); // 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 diff --git a/runtime/basilisk/Cargo.toml b/runtime/basilisk/Cargo.toml index 34e5e48245..98784acf47 100644 --- a/runtime/basilisk/Cargo.toml +++ b/runtime/basilisk/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "basilisk-runtime" -version = "132.0.0" +version = "133.0.0" authors = ["GalacticCouncil"] edition = "2021" homepage = "https://github.com/galacticcouncil/Basilisk-node" diff --git a/runtime/basilisk/src/lib.rs b/runtime/basilisk/src/lib.rs index 962d0f74f7..0554ecdb39 100644 --- a/runtime/basilisk/src/lib.rs +++ b/runtime/basilisk/src/lib.rs @@ -103,7 +103,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion { spec_name: Cow::Borrowed("basilisk"), impl_name: Cow::Borrowed("basilisk"), authoring_version: 1, - spec_version: 132, + spec_version: 133, impl_version: 0, apis: apis::RUNTIME_API_VERSIONS, transaction_version: 1, diff --git a/runtime/basilisk/src/system.rs b/runtime/basilisk/src/system.rs index 1f89c59081..286396cb16 100644 --- a/runtime/basilisk/src/system.rs +++ b/runtime/basilisk/src/system.rs @@ -61,7 +61,7 @@ pub const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75); pub const DEFAULT_RELAY_PARENT_OFFSET: u32 = 1; /// How many parachain blocks are processed by the relay chain per parent. Limits the number of /// blocks authored per slot. -pub const BLOCK_PROCESSING_VELOCITY: u32 = 1; +pub const BLOCK_PROCESSING_VELOCITY: u32 = 3; /// Maximum number of blocks simultaneously accepted by the Runtime, not yet included into the /// relay chain. pub const UNINCLUDED_SEGMENT_CAPACITY: u32 = (3 + DEFAULT_RELAY_PARENT_OFFSET) * BLOCK_PROCESSING_VELOCITY; @@ -242,7 +242,7 @@ impl pallet_timestamp::Config for Runtime { /// A timestamp: milliseconds since the unix epoch. type Moment = u64; type OnTimestampSet = (); - type MinimumPeriod = ConstU64<{ SLOT_DURATION / 2 }>; + type MinimumPeriod = ConstU64<0>; type WeightInfo = weights::pallet_timestamp::BasiliskWeight; } @@ -611,7 +611,7 @@ impl pallet_transaction_pause::Config for Runtime { } parameter_types! { - pub const RewardPerCollator: Balance = 15_240_000_000_000_000; // 6.35[BSX/block] * 2400[block] + pub const RewardPerCollator: Balance = 15_240_000_000_000_000; // fixed reward per session //GalacticCouncil collators pub ExcludedCollators: Vec = vec![ // bXn5CfJB2qHvqnuMqTpXn6un9Fjch8mwkb9i3JUsGVD4ChLoe diff --git a/scripts/assign_cores.js b/scripts/assign_cores.js new file mode 100644 index 0000000000..63c18635c3 --- /dev/null +++ b/scripts/assign_cores.js @@ -0,0 +1,165 @@ +#!/usr/bin/env node + +let ApiPromise; +let WsProvider; +let Keyring; +let cryptoWaitReady; + +try { + ({ ApiPromise, WsProvider, Keyring } = require("@polkadot/api")); + ({ cryptoWaitReady } = require("@polkadot/util-crypto")); +} catch (error) { + console.error( + "Missing JS deps. Run without installing into the repo via:\n" + + "npm exec --yes --package=@polkadot/api --package=@polkadot/util-crypto -- node scripts/assign_cores.js", + ); + process.exit(1); +} + +function parseArgs(argv) { + const defaults = { + ws: "ws://127.0.0.1:9945", + suri: "//Alice", + paraId: 2090, + cores: [0, 1, 2], + begin: 0, + finalized: true, + }; + + for (let i = 0; i < argv.length; i += 1) { + const arg = argv[i]; + if (arg === "--ws") { + defaults.ws = argv[++i]; + } else if (arg === "--suri") { + defaults.suri = argv[++i]; + } else if (arg === "--para") { + defaults.paraId = Number(argv[++i]); + } else if (arg === "--cores") { + defaults.cores = argv[++i] + .split(",") + .filter(Boolean) + .map((value) => Number(value.trim())); + } else if (arg === "--begin") { + defaults.begin = Number(argv[++i]); + } else if (arg === "--in-block") { + defaults.finalized = false; + } else if (arg === "--help" || arg === "-h") { + printHelp(); + process.exit(0); + } else { + throw new Error(`Unknown argument: ${arg}`); + } + } + + if (!defaults.cores.length || defaults.cores.some((core) => Number.isNaN(core))) { + throw new Error("Expected --cores to contain a comma-separated list of integers"); + } + + if (Number.isNaN(defaults.paraId)) { + throw new Error("Expected --para to be an integer"); + } + + if (Number.isNaN(defaults.begin)) { + throw new Error("Expected --begin to be an integer"); + } + + return defaults; +} + +function printHelp() { + console.log(`Assign relay-chain cores to a parachain on a local Zombienet relay node. + +Usage: + node scripts/assign_cores.js [options] + +Options: + --ws Relay-chain websocket endpoint (default: ws://127.0.0.1:9945) + --suri Signing account SURI (default: //Alice) + --para Parachain id to assign cores to (default: 2090) + --cores Comma-separated core indexes (default: 0,1,2) + --begin Relay block number to start assignment from (default: 0) + --in-block Exit once included in a block instead of waiting for finalization + --help, -h Show this message +`); +} + +async function main() { + const { ws, suri, paraId, cores, begin, finalized } = parseArgs(process.argv.slice(2)); + + await cryptoWaitReady(); + + const provider = new WsProvider(ws); + const api = await ApiPromise.create({ provider }); + const keyring = new Keyring({ type: "sr25519" }); + const signer = keyring.addFromUri(suri); + + const calls = cores.map((core) => + api.tx.coretime.assignCore( + core, + begin, + [[{ Task: paraId }, 57600]], + null, + ), + ); + + const tx = api.tx.sudo.sudo(api.tx.utility.batch(calls)); + + console.log( + `Submitting assign_core for para ${paraId} on cores [${cores.join(", ")}] via ${ws} as ${signer.address}`, + ); + + await new Promise(async (resolve, reject) => { + let unsub = null; + + try { + unsub = await tx.signAndSend(signer, ({ status, dispatchError, events }) => { + if (dispatchError) { + if (dispatchError.isModule) { + const decoded = api.registry.findMetaError(dispatchError.asModule); + reject( + new Error( + `${decoded.section}.${decoded.name}: ${decoded.docs.join(" ")}`, + ), + ); + } else { + reject(new Error(dispatchError.toString())); + } + return; + } + + if (status.isInBlock) { + console.log(`Included at ${status.asInBlock.toHex()}`); + if (!finalized) { + if (unsub) { + unsub(); + } + resolve(); + } + } + + if (status.isFinalized) { + console.log(`Finalized at ${status.asFinalized.toHex()}`); + for (const { event } of events) { + console.log(`Event: ${event.section}.${event.method}`); + } + if (unsub) { + unsub(); + } + resolve(); + } + }); + } catch (error) { + if (unsub) { + unsub(); + } + reject(error); + } + }); + + await api.disconnect(); +} + +main().catch((error) => { + console.error(error.message || error); + process.exit(1); +});