git.delta.rocks / unique-network / refs/commits / 83c9d6351207

difftreelog

feat speedup inflation pallet

Grigoriy Simonov2023-11-15parent: #aea35c0.patch.diff
in: master

4 files changed

modifiedjs-packages/tests/creditFeesToTreasury.seqtest.tsdiffbeforeafterboth
33 const blockInterval = inflationBlockInterval.toNumber();33 const blockInterval = inflationBlockInterval.toNumber();
34 const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {34 const unsubscribe = await api.rpc.chain.subscribeNewHeads(head => {
35 const currentBlock = head.number.toNumber();35 const currentBlock = head.number.toNumber();
36 if(currentBlock % blockInterval < blockInterval - 10) {36 if(currentBlock % blockInterval < blockInterval - 2) {
37 unsubscribe();37 unsubscribe();
38 resolve();38 resolve();
39 } else {39 } else {
modifiedjs-packages/tests/inflation.seqtest.tsdiffbeforeafterboth
17import type {IKeyringPair} from '@polkadot/types/types';17import type {IKeyringPair} from '@polkadot/types/types';
18import {expect, itSub, usingPlaygrounds} from './util/index.js';18import {expect, itSub, usingPlaygrounds} from './util/index.js';
19
20const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
1921
20// todo:playgrounds requires sudo, look into on the later stage22// todo:playgrounds requires sudo, look into on the later stage
21describe('integration test: Inflation', () => {23describe('integration test: Inflation', () => {
56 expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);58 expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);
57 });59 });
60
61 itSub('Inflation happens after inflation block interval', async ({helper}) => {
62 const api = helper.getApi();
63 const blockInterval = await api.consts.inflation.inflationBlockInterval.toNumber();
64
65 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;
69
70 await helper.wait.forRelayBlockNumber(startBlock);
71
72 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);
73
74 await helper.wait.forRelayBlockNumber(startBlock + blockInterval);
75
76 const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
77 expect(Number(treasuryBalanceAfter)).to.be.eqls(Number(treasuryBalanceBefore + blockInflation));
78 });
58});79});
5980
modifiedpallets/inflation/src/tests.rsdiffbeforeafterboth
106106
107parameter_types! {107parameter_types! {
108 pub TreasuryAccountId: u64 = 1234;108 pub TreasuryAccountId: u64 = 1234;
109 pub const InflationBlockInterval: u32 = 100; // every time per how many blocks inflation is applied109 pub const InflationBlockInterval: u32 = 10; // every time per how many blocks inflation is applied
110 pub static MockBlockNumberProvider: u32 = 0;110 pub static MockBlockNumberProvider: u32 = 0;
111}111}
112112
modifiedruntime/common/config/pallets/mod.rsdiffbeforeafterboth
102}102}
103103
104parameter_types! {104parameter_types! {
105 pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied105 pub const InflationBlockInterval: BlockNumber = 10; // every time per how many blocks inflation is applied
106}106}
107107
108/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet108/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet