difftreelog
refactor(collator-selection) session config
in: master
4 files changed
runtime/common/config/substrate.rsdiffbeforeafterboth--- a/runtime/common/config/substrate.rs
+++ b/runtime/common/config/substrate.rs
@@ -35,7 +35,6 @@
runtime_common::DealWithFees, Runtime, Event, Call, Origin, PalletInfo, System, Balances,
Treasury, SS58Prefix, Aura, Session, SessionKeys, CollatorSelection, Version,
};
-use xcm::v1::BodyId;
use up_common::{types::*, constants::*};
parameter_types! {
@@ -218,9 +217,8 @@
}
parameter_types! {
- pub const Period: u32 = 6 * HOURS;
- pub const Offset: u32 = 0;
- //pub const MaxAuthorities: u32 = 100_000;
+ pub const SessionPeriod: BlockNumber = 6 * HOURS;
+ pub const SessionOffset: BlockNumber = 0;
}
impl pallet_session::Config for Runtime {
@@ -228,8 +226,8 @@
type ValidatorId = <Self as frame_system::Config>::AccountId;
// we don't have stash and controller, thus we don't need the convert as well.
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
- type ShouldEndSession = pallet_session::PeriodicSessions<Period, Offset>;
- type NextSessionRotation = pallet_session::PeriodicSessions<Period, Offset>;
+ type ShouldEndSession = pallet_session::PeriodicSessions<SessionPeriod, SessionOffset>;
+ type NextSessionRotation = pallet_session::PeriodicSessions<SessionPeriod, SessionOffset>;
type SessionManager = CollatorSelection;
// Essentially just Aura, but lets be pedantic.
type SessionHandler = <SessionKeys as sp_runtime::traits::OpaqueKeys>::KeyTypeIdProviders;
@@ -252,24 +250,20 @@
pub const PotId: PalletId = PalletId(*b"PotStake");
pub const MaxCandidates: u32 = 1000;
pub const MinCandidates: u32 = 5;
- pub const SessionLength: BlockNumber = 6 * HOURS;
pub const MaxInvulnerables: u32 = 100;
- pub const ExecutiveBody: BodyId = BodyId::Executive;
}
-
-// We allow root only to execute privileged collator selection operations.
-pub type CollatorSelectionUpdateOrigin = EnsureRoot<AccountId>;
impl pallet_collator_selection::Config for Runtime {
type Event = Event;
type Currency = Balances;
- type UpdateOrigin = CollatorSelectionUpdateOrigin;
+ // We allow root only to execute privileged collator selection operations.
+ type UpdateOrigin = EnsureRoot<AccountId>;
type PotId = PotId;
type MaxCandidates = MaxCandidates;
type MinCandidates = MinCandidates;
type MaxInvulnerables = MaxInvulnerables;
- // should be a multiple of session or things will get inconsistent
- type KickThreshold = Period;
+ // Should be a multiple of session or things will get inconsistent.
+ type KickThreshold = SessionPeriod;
type ValidatorId = <Self as frame_system::Config>::AccountId;
type ValidatorIdOf = pallet_collator_selection::IdentityCollator;
type ValidatorRegistration = Session;
tests/package.jsondiffbeforeafterboth1{2 "name": "unique-tests",3 "version": "1.0.0",4 "description": "Unique Chain Tests",5 "main": "",6 "devDependencies": {7 "@polkadot/ts": "0.4.22",8 "@polkadot/typegen": "9.2.2",9 "@types/chai": "^4.3.1",10 "@types/chai-as-promised": "^7.1.5",11 "@types/chai-like": "^1.1.1",12 "@types/mocha": "^9.1.1",13 "@types/node": "^17.0.35",14 "@typescript-eslint/eslint-plugin": "^5.26.0",15 "@typescript-eslint/parser": "^5.26.0",16 "chai": "^4.3.6",17 "eslint": "^8.16.0",18 "mocha": "^10.0.0",19 "ts-node": "^10.8.0",20 "typescript": "^4.7.2"21 },22 "mocha": {23 "timeout": 9999999,24 "require": "ts-node/register"25 },26 "scripts": {27 "lint": "eslint --ext .ts,.js src/",28 "fix": "eslint --ext .ts,.js src/ --fix",29 "test": "mocha --timeout 9999999 -r ts-node/register './src/**/*.test.ts'",30 "testEth": "mocha --timeout 9999999 -r ts-node/register './**/eth/**/*.test.ts'",31 "testEthMarketplace": "mocha --timeout 9999999 -r ts-node/register './**/eth/marketplace/**/*.test.ts'",32 "testEthNesting": "mocha --timeout 9999999 -r ts-node/register './**/eth/nesting/**/*.test.ts'",33 "load": "mocha --timeout 9999999 -r ts-node/register './**/*.load.ts'",34 "loadTransfer": "ts-node src/transfer.nload.ts",35 "testCollision": "mocha --timeout 9999999 -r ts-node/register ./src/collision-tests/*.test.ts",36 "testEvent": "mocha --timeout 9999999 -r ts-node/register ./src/check-event/*.test.ts",37 "testNesting": "mocha --timeout 9999999 -r ts-node/register ./**/nest.test.ts",38 "testUnnesting": "mocha --timeout 9999999 -r ts-node/register ./**/unnest.test.ts",39 "testStructure": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/**.test.ts",40 "testProperties": "mocha --timeout 9999999 -r ts-node/register ./**/properties.test.ts",41 "testMigration": "mocha --timeout 9999999 -r ts-node/register ./**/nesting/migration-check.test.ts",42 "testRmrk": "mocha --timeout 9999999 -r ts-node/register ./**/rmrk/**.test.ts",43 "testAddCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/addCollectionAdmin.test.ts",44 "testSetSchemaVersion": "mocha --timeout 9999999 -r ts-node/register ./**/setSchemaVersion.test.ts",45 "testSetCollectionLimits": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionLimits.test.ts",46 "testSetCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/setCollectionSponsor.test.ts",47 "testConfirmSponsorship": "mocha --timeout 9999999 -r ts-node/register ./**/confirmSponsorship.test.ts",48 "testRemoveCollectionAdmin": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionAdmin.test.ts",49 "testRemoveCollectionSponsor": "mocha --timeout 9999999 -r ts-node/register ./**/removeCollectionSponsor.test.ts",50 "testRemoveFromAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromAllowList.test.ts",51 "testConnection": "mocha --timeout 9999999 -r ts-node/register ./**/connection.test.ts",52 "testContracts": "mocha --timeout 9999999 -r ts-node/register ./**/contracts.test.ts",53 "testCreateItem": "mocha --timeout 9999999 -r ts-node/register ./**/createItem.test.ts",54 "testCreateMultipleItems": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItems.test.ts",55 "testCreateMultipleItemsEx": "mocha --timeout 9999999 -r ts-node/register ./**/createMultipleItemsEx.test.ts",56 "testApprove": "mocha --timeout 9999999 -r ts-node/register ./**/approve.test.ts",57 "testTransferFrom": "mocha --timeout 9999999 -r ts-node/register ./**/transferFrom.test.ts",58 "testCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/createCollection.test.ts",59 "testDestroyCollection": "mocha --timeout 9999999 -r ts-node/register ./**/destroyCollection.test.ts",60 "testToggleContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/toggleContractAllowList.test.ts",61 "testAddToContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/addToContractAllowList.test.ts",62 "testTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/transfer.test.ts",63 "testBurnItem": "mocha --timeout 9999999 -r ts-node/register ./**/burnItem.test.ts",64 "testAdminTransferAndBurn": "mocha --timeout 9999999 -r ts-node/register ./**/adminTransferAndBurn.test.ts",65 "testSetMintPermission": "mocha --timeout 9999999 -r ts-node/register ./**/setMintPermission.test.ts",66 "testCreditFeesToTreasury": "mocha --timeout 9999999 -r ts-node/register ./**/creditFeesToTreasury.test.ts",67 "testContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/contractSponsoring.test.ts",68 "testEnableContractSponsoring": "mocha --timeout 9999999 -r ts-node/register ./**/enableContractSponsoring.test.ts",69 "testRemoveFromContractAllowList": "mocha --timeout 9999999 -r ts-node/register ./**/removeFromContractAllowList.test.ts",70 "testSetContractSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setContractSponsoringRateLimit.test.ts",71 "testSetOffchainSchema": "mocha --timeout 9999999 -r ts-node/register ./**/setOffchainSchema.test.ts",72 "testOverflow": "mocha --timeout 9999999 -r ts-node/register ./**/overflow.test.ts",73 "testSetVariableMetadataSponsoringRateLimit": "mocha --timeout 9999999 -r ts-node/register ./**/setVariableMetadataSponsoringRateLimit.test.ts",74 "testInflation": "mocha --timeout 9999999 -r ts-node/register ./**/inflation.test.ts",75 "testScheduler": "mocha --timeout 9999999 -r ts-node/register ./**/scheduler.test.ts",76 "testSchedulingEVM": "mocha --timeout 9999999 -r ts-node/register ./**/eth/scheduling.test.ts",77 "testXcmTransfer": "mocha --timeout 9999999 -r ts-node/register ./**/xcmTransfer.test.ts",78 "testShuffleCollators": "mocha --timeout 9999999 -r ts-node/register ./**/shuffleCollators.test.ts",79 "testPalletPresence": "mocha --timeout 9999999 -r ts-node/register ./**/pallet-presence.test.ts",80 "testBlockProduction": "mocha --timeout 9999999 -r ts-node/register ./**/block-production.test.ts",81 "testEnableDisableTransfers": "mocha --timeout 9999999 -r ts-node/register ./**/enableDisableTransfer.test.ts",82 "testLimits": "mocha --timeout 9999999 -r ts-node/register ./**/limits.test.ts",83 "testEthCreateCollection": "mocha --timeout 9999999 -r ts-node/register ./**/eth/createCollection.test.ts",84 "testRFT": "mocha --timeout 9999999 -r ts-node/register ./**/refungible.test.ts",85 "testFT": "mocha --timeout 9999999 -r ts-node/register ./**/fungible.test.ts",86 "testRPC": "mocha --timeout 9999999 -r ts-node/register ./**/rpc.test.ts",87 "polkadot-types-fetch-metadata": "curl -H 'Content-Type: application/json' -d '{\"id\":\"1\", \"jsonrpc\":\"2.0\", \"method\": \"state_getMetadata\", \"params\":[]}' http://localhost:9933 > src/interfaces/metadata.json",88 "polkadot-types-from-defs": "ts-node ./node_modules/.bin/polkadot-types-from-defs --endpoint src/interfaces/metadata.json --input src/interfaces/ --package .",89 "polkadot-types-from-chain": "ts-node ./node_modules/.bin/polkadot-types-from-chain --endpoint src/interfaces/metadata.json --output src/interfaces/ --package .",90 "polkadot-types": "echo \"export default {}\" > src/interfaces/lookup.ts && yarn polkadot-types-fetch-metadata && yarn polkadot-types-from-defs && yarn polkadot-types-from-defs && yarn polkadot-types-from-chain"91 },92 "author": "",93 "license": "SEE LICENSE IN ../LICENSE",94 "homepage": "",95 "dependencies": {96 "@polkadot/api": "9.2.2",97 "@polkadot/api-contract": "9.2.2",98 "@polkadot/util-crypto": "10.1.1",99 "bignumber.js": "^9.0.2",100 "chai-as-promised": "^7.1.1",101 "chai-like": "^1.1.1",102 "find-process": "^1.4.7",103 "solc": "0.8.14-fixed",104 "web3": "^1.7.3"105 },106 "standard": {107 "globals": [108 "it",109 "assert",110 "beforeEach",111 "afterEach",112 "describe",113 "contract",114 "artifacts"115 ]116 },117 "resolutions": {118 "simple-get": "^4.0.1"119 }120}tests/src/collatorSelection.test.tsdiffbeforeafterboth--- /dev/null
+++ b/tests/src/collatorSelection.test.ts
@@ -0,0 +1,108 @@
+// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
+// This file is part of Unique Network.
+
+// Unique Network is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+
+// Unique Network is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+// You should have received a copy of the GNU General Public License
+// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
+
+import {IKeyringPair} from '@polkadot/types/types';
+import privateKey from './substrate/privateKey';
+import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
+import waitNewBlocks from './substrate/wait-new-blocks';
+import {expect} from 'chai';
+import {getBlockNumber, getGenericResult} from './util/helpers';
+
+let alice: IKeyringPair;
+let bob: IKeyringPair;
+let charlie: IKeyringPair;
+let dave: IKeyringPair;
+//let eve: IKeyringPair;
+
+// todo Most preferable to launch this test in parallel somehow -- or change the session period (6 hrs) for Opal specifically.
+describe('Integration Test: Dynamic shuffling of collators', () => {
+ before(async () => {
+ await usingApi(async api => {
+ alice = privateKey('//Alice');
+ bob = privateKey('//Bob');
+ charlie = privateKey('//Charlie');
+ dave = privateKey('//Dave');
+ //eve = privateKey('//Eve');
+
+ const txC = api.tx.session.setKeys(
+ '0x' + Buffer.from(charlie.addressRaw).toString('hex'),
+ '0x0',
+ );
+ const eventsC = await submitTransactionAsync(charlie, txC);
+ const resultC = getGenericResult(eventsC);
+ expect(resultC.success).to.be.true;
+
+ const txD = api.tx.session.setKeys(
+ '0x' + Buffer.from(dave.addressRaw).toString('hex'),
+ '0x0',
+ );
+ const eventsD = await submitTransactionAsync(dave, txD);
+ const resultD = getGenericResult(eventsD);
+ expect(resultD.success).to.be.true;
+
+ const validators = (await api.query.session.validators()).toJSON();
+ expect(validators).to.contain(alice.address).and.contain(bob.address).and.be.length(2);
+ });
+ });
+
+ it('Change invulnerables and make sure they start producing blocks', async () => {
+ await usingApi(async (api) => {
+ const tx = api.tx.collatorSelection.setInvulnerables([
+ charlie.address,
+ dave.address,
+ ]);
+ const sudoTx = api.tx.sudo.sudo(tx as any);
+ const events = await submitTransactionAsync(alice, sudoTx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+
+ const newInvulnerables = (await api.query.collatorSelection.invulnerables()).toJSON();
+ expect(newInvulnerables).to.contain(charlie.address).and.contain(dave.address).and.be.length(2);
+
+ const expectedSessionIndex = (await api.query.session.currentIndex() as any).toNumber() + 2;
+ let currentSessionIndex = -1;
+ console.log('Waiting for the session after the next.'
+ + ' This might take a while -- check SessionPeriod in pallet_session::Config for session time.');
+ while (currentSessionIndex < expectedSessionIndex) {
+ await waitNewBlocks(api, 1);
+ currentSessionIndex = (await api.query.session.currentIndex() as any).toNumber();
+ // todo implement a timeout in case new blocks are not being produced? session length needed
+ }
+
+ const newValidators = (await api.query.session.validators()).toJSON();
+ expect(newValidators).to.contain(charlie.address).and.contain(dave.address).and.be.length(2);
+
+ const lastBlockNumber = await getBlockNumber(api);
+ await waitNewBlocks(api, 1);
+ const lastCharlieBlock = (await api.query.collatorSelection.lastAuthoredBlock(charlie.address) as any).toNumber();
+ const lastDaveBlock = (await api.query.collatorSelection.lastAuthoredBlock(dave.address) as any).toNumber();
+ expect(lastCharlieBlock >= lastBlockNumber || lastDaveBlock >= lastBlockNumber).to.be.true;
+ });
+ });
+
+ after(async () => {
+ await usingApi(async (api) => {
+ const tx = api.tx.collatorSelection.setInvulnerables([
+ alice.address,
+ bob.address,
+ ]);
+ const sudoTx = api.tx.sudo.sudo(tx as any);
+ const events = await submitTransactionAsync(alice, sudoTx);
+ const result = getGenericResult(events);
+ expect(result.success).to.be.true;
+ });
+ });
+});
tests/src/shuffleCollators.test.tsdiffbeforeafterboth--- a/tests/src/shuffleCollators.test.ts
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.
-// This file is part of Unique Network.
-
-// Unique Network is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-
-// Unique Network is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-
-// You should have received a copy of the GNU General Public License
-// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.
-
-import {IKeyringPair} from '@polkadot/types/types';
-import privateKey from './substrate/privateKey';
-import usingApi, {submitTransactionAsync} from './substrate/substrate-api';
-import waitNewBlocks from './substrate/wait-new-blocks';
-import {expect} from 'chai';
-import {getBlockNumber, getGenericResult} from './util/helpers';
-
-let alice: IKeyringPair;
-let bob: IKeyringPair;
-let charlie: IKeyringPair;
-let dave: IKeyringPair;
-//let eve: IKeyringPair;
-
-describe('Integration Test: Dynamic shuffling of collators', () => {
- before(async () => {
- await usingApi(async () => {
- alice = privateKey('//Alice');
- bob = privateKey('//Bob');
- charlie = privateKey('//Charlie');
- dave = privateKey('//Dave');
- //eve = privateKey('//Eve');
- });
- });
-
- it('Change invulnerables and make sure they start producing blocks', async () => {
- await usingApi(async (api) => {
- const txC = api.tx.session.setKeys(
- '0x' + Buffer.from(charlie.addressRaw).toString('hex'),
- '0x0',
- );
- const eventsC = await submitTransactionAsync(charlie, txC);
- const resultC = getGenericResult(eventsC);
- expect(resultC.success).to.be.true;
-
- const txD = api.tx.session.setKeys(
- '0x' + Buffer.from(dave.addressRaw).toString('hex'),
- '0x0',
- );
- const eventsD = await submitTransactionAsync(dave, txD);
- const resultD = getGenericResult(eventsD);
- expect(resultD.success).to.be.true;
-
- const tx = api.tx.collatorSelection.setInvulnerables([
- charlie.address,
- dave.address,
- ]);
- const sudoTx = api.tx.sudo.sudo(tx as any);
- const events = await submitTransactionAsync(alice, sudoTx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
-
- const newInvulnerables = (await api.query.collatorSelection.invulnerables()).toJSON();
- expect(newInvulnerables).to.contain(charlie.address).and.contain(dave.address);
- expect(newInvulnerables).to.be.length(2);
-
- const expectedSessionIndex = (await api.query.session.currentIndex() as any).toNumber() + 2;
- let currentSessionIndex = -1;
- console.log('Waiting for the session after the next. This might take a while...');
- while (currentSessionIndex < expectedSessionIndex) {
- await waitNewBlocks(api, 1);
- currentSessionIndex = (await api.query.session.currentIndex() as any).toNumber();
- // todo implement a timeout in case new blocks are not being produced? session length needed
- }
-
- const newValidators = (await api.query.session.validators()).toJSON();
- expect(newValidators).to.contain(charlie.address).and.contain(dave.address);
- expect(newValidators).to.be.length(2);
-
- const lastBlockNumber = await getBlockNumber(api);
- await waitNewBlocks(api, 1);
- const lastCharlieBlock = (await api.query.collatorSelection.lastAuthoredBlock(charlie.address) as any).toNumber();
- const lastDaveBlock = (await api.query.collatorSelection.lastAuthoredBlock(dave.address) as any).toNumber();
- expect(lastCharlieBlock >= lastBlockNumber || lastDaveBlock >= lastBlockNumber).to.be.true;
- });
- });
-
- after(async () => {
- await usingApi(async (api) => {
- const tx = api.tx.collatorSelection.setInvulnerables([
- alice.address,
- bob.address,
- ]);
- const sudoTx = api.tx.sudo.sudo(tx as any);
- const events = await submitTransactionAsync(alice, sudoTx);
- const result = getGenericResult(events);
- expect(result.success).to.be.true;
- });
- });
-});