difftreelog
feat speedup inflation pallet
in: master
4 files changed
js-packages/tests/creditFeesToTreasury.seqtest.tsdiffbeforeafterboth--- a/js-packages/tests/creditFeesToTreasury.seqtest.ts
+++ b/js-packages/tests/creditFeesToTreasury.seqtest.ts
@@ -33,7 +33,7 @@
const blockInterval = inflationBlockInterval.toNumber();
const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
const currentBlock = head.number.toNumber();
- if(currentBlock % blockInterval < blockInterval - 10) {
+ if(currentBlock % blockInterval < blockInterval - 2) {
unsubscribe();
resolve();
} else {
js-packages/tests/inflation.seqtest.tsdiffbeforeafterboth1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import type {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from './util/index.js';1920// todo:playgrounds requires sudo, look into on the later stage21describe('integration test: Inflation', () => {22 let superuser: IKeyringPair;2324 before(async () => {25 await usingPlaygrounds(async (_, privateKey) => {26 superuser = await privateKey('//Alice');27 });28 });2930 itSub('First year inflation is 10%', async ({helper}) => {31 // Make sure non-sudo can't start inflation32 const [bob] = await helper.arrange.createAccounts([10n], superuser);3334 await expect(helper.executeExtrinsic(bob, 'api.tx.inflation.startInflation', [1])).to.be.rejectedWith(/BadOrigin/);3536 // Make sure superuser can't start inflation without explicit sudo37 await expect(helper.executeExtrinsic(superuser, 'api.tx.inflation.startInflation', [1])).to.be.rejectedWith(/BadOrigin/);3839 // Start inflation on relay block 1 (Alice is sudo)40 const tx = helper.constructApiCall('api.tx.inflation.startInflation', [1]);41 await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [tx])).to.not.be.rejected;4243 const blockInterval = (helper.getApi().consts.inflation.inflationBlockInterval as any).toBigInt();44 const totalIssuanceStart = ((await helper.callRpc('api.query.inflation.startingYearTotalIssuance', [])) as any).toBigInt();45 const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();4647 const YEAR = 5259600n; // 6-second block. Blocks in one year48 // const YEAR = 2629800n; // 12-second block. Blocks in one year4950 const totalExpectedInflation = totalIssuanceStart / 10n;51 const totalActualInflation = blockInflation * YEAR / blockInterval;5253 const tolerance = 0.00001; // Relative difference per year between theoretical and actual inflation54 const expectedInflation = totalExpectedInflation / totalActualInflation - 1n;5556 expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);57 });58});1// Copyright 2019-2022 Unique Network (Gibraltar) Ltd.2// This file is part of Unique Network.34// Unique Network is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.89// Unique Network is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.1314// You should have received a copy of the GNU General Public License15// along with Unique Network. If not, see <http://www.gnu.org/licenses/>.1617import type {IKeyringPair} from '@polkadot/types/types';18import {expect, itSub, usingPlaygrounds} from './util/index.js';1920const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';2122// todo:playgrounds requires sudo, look into on the later stage23describe('integration test: Inflation', () => {24 let superuser: IKeyringPair;2526 before(async () => {27 await usingPlaygrounds(async (_, privateKey) => {28 superuser = await privateKey('//Alice');29 });30 });3132 itSub('First year inflation is 10%', async ({helper}) => {33 // Make sure non-sudo can't start inflation34 const [bob] = await helper.arrange.createAccounts([10n], superuser);3536 await expect(helper.executeExtrinsic(bob, 'api.tx.inflation.startInflation', [1])).to.be.rejectedWith(/BadOrigin/);3738 // Make sure superuser can't start inflation without explicit sudo39 await expect(helper.executeExtrinsic(superuser, 'api.tx.inflation.startInflation', [1])).to.be.rejectedWith(/BadOrigin/);4041 // Start inflation on relay block 1 (Alice is sudo)42 const tx = helper.constructApiCall('api.tx.inflation.startInflation', [1]);43 await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [tx])).to.not.be.rejected;4445 const blockInterval = (helper.getApi().consts.inflation.inflationBlockInterval as any).toBigInt();46 const totalIssuanceStart = ((await helper.callRpc('api.query.inflation.startingYearTotalIssuance', [])) as any).toBigInt();47 const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();4849 const YEAR = 5259600n; // 6-second block. Blocks in one year50 // const YEAR = 2629800n; // 12-second block. Blocks in one year5152 const totalExpectedInflation = totalIssuanceStart / 10n;53 const totalActualInflation = blockInflation * YEAR / blockInterval;5455 const tolerance = 0.00001; // Relative difference per year between theoretical and actual inflation56 const expectedInflation = totalExpectedInflation / totalActualInflation - 1n;5758 expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);59 });6061 itSub('Inflation happens after inflation block interval', async ({helper}) => {62 const api = helper.getApi();63 const blockInterval = await api.consts.inflation.inflationBlockInterval.toNumber();6465 const relayBlock = (await api.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();66 await helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [helper.constructApiCall('api.tx.inflation.startInflation', [relayBlock])]);67 const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();68 const startBlock = (relayBlock + blockInterval) - (relayBlock % blockInterval) + 1;6970 await helper.wait.forRelayBlockNumber(startBlock);7172 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);7374 await helper.wait.forRelayBlockNumber(startBlock + blockInterval);7576 const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);77 expect(Number(treasuryBalanceAfter)).to.be.eqls(Number(treasuryBalanceBefore + blockInflation));78 });79});pallets/inflation/src/tests.rsdiffbeforeafterboth--- a/pallets/inflation/src/tests.rs
+++ b/pallets/inflation/src/tests.rs
@@ -106,7 +106,7 @@
parameter_types! {
pub TreasuryAccountId: u64 = 1234;
- pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied
+ pub const InflationBlockInterval: u32 = 10; // every time per how many blocks inflation is applied
pub static MockBlockNumberProvider: u32 = 0;
}
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -102,7 +102,7 @@
}
parameter_types! {
- pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied
+ pub const InflationBlockInterval: BlockNumber = 10; // every time per how many blocks inflation is applied
}
/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet