Skip to content

Commit

Permalink
feat: speedup inflation pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigoriy Simonov committed Oct 17, 2023
1 parent 8af05a8 commit 1ccc06a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pallets/inflation/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl frame_system::Config for Test {

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;
}

Expand Down
2 changes: 1 addition & 1 deletion pallets/nonfungible/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1225,7 +1225,7 @@ impl<T: Config> Pallet<T> {
nesting_budget,
)? {
// Pass, token existence and ouroboros checks are done in `check_indirectly_owned`
} else if nesting.collection_admin && handle.is_owner_or_admin(&sender) {
} else if nesting.collection_admin && handle.is_owner_or_admin(sender) {
// token existence and ouroboros checks are done in `get_checked_topmost_owner`
let _ = <PalletStructure<T>>::get_checked_topmost_owner(
handle.id,
Expand Down
2 changes: 1 addition & 1 deletion runtime/common/config/pallets/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl pallet_balances_adapter::Config for Runtime {
}

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
Expand Down
2 changes: 1 addition & 1 deletion tests/src/creditFeesToTreasury.seqtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ function skipInflationBlock(api: ApiPromise): Promise<void> {
const blockInterval = api.consts.inflation.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 {
Expand Down
21 changes: 21 additions & 0 deletions tests/src/inflation.seqtest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
import {IKeyringPair} from '@polkadot/types/types';
import {expect, itSub, usingPlaygrounds} from './util';

const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';

// todo:playgrounds requires sudo, look into on the later stage
describe('integration test: Inflation', () => {
let superuser: IKeyringPair;
Expand Down Expand Up @@ -55,4 +57,23 @@ describe('integration test: Inflation', () => {

expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);
});

itSub('Inflation happens after inflation block interval', async ({helper}) => {
const api = helper.getApi();
const blockInterval = await api.consts.inflation.inflationBlockInterval.toNumber();

const relayBlock = (await api.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();
await helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [helper.constructApiCall('api.tx.inflation.startInflation', [relayBlock])]);
const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();
const startBlock = (relayBlock + blockInterval) - (relayBlock % blockInterval) + 1;

await helper.wait.forRelayBlockNumber(startBlock);

const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);

await helper.wait.forRelayBlockNumber(startBlock + blockInterval);

const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
expect(Number(treasuryBalanceAfter)).to.be.eqls(Number(treasuryBalanceBefore + blockInflation));
});
});

0 comments on commit 1ccc06a

Please sign in to comment.