difftreelog
Merge pull request #1017 from UniqueNetwork/feature/speedup-inflation-pallet
in: master
11 files changed
.docker/Dockerfile-chain-devdiffbeforeafterboth212122WORKDIR /dev_chain22WORKDIR /dev_chain232324RUN cargo build --profile integration-tests --features=${NETWORK}-runtime24RUN cargo build --profile integration-tests --features=${NETWORK}-runtime,fast-inflation25RUN echo "$NETWORK"25RUN echo "$NETWORK"262627CMD cargo run --profile integration-tests --features=${NETWORK}-runtime -- --dev -linfo --rpc-cors=all --unsafe-rpc-external27CMD cargo run --profile integration-tests --features=${NETWORK}-runtime,fast-inflation -- --dev -linfo --rpc-cors=all --unsafe-rpc-external2828.docker/Dockerfile-uniquediffbeforeafterboth47 --mount=type=cache,target=/unique_parachain/unique-chain/target \47 --mount=type=cache,target=/unique_parachain/unique-chain/target \48 cd unique-chain && \48 cd unique-chain && \49 echo "Using runtime features '$RUNTIME_FEATURES'" && \49 echo "Using runtime features '$RUNTIME_FEATURES'" && \50 CARGO_INCREMENTAL=0 cargo build --profile integration-tests --features="$RUNTIME_FEATURES" --locked && \50 CARGO_INCREMENTAL=0 cargo build --profile integration-tests --features=fast-inflation,"$RUNTIME_FEATURES" --locked && \51 mv ./target/integration-tests/unique-collator /unique_parachain/unique-chain/ && \51 mv ./target/integration-tests/unique-collator /unique_parachain/unique-chain/ && \52 cd target/integration-tests/wbuild && find . -name "*.wasm" -exec sh -c 'mkdir -p "../../../wasm/$(dirname {})"; cp {} "../../../wasm/{}"' \;52 cd target/integration-tests/wbuild && find . -name "*.wasm" -exec sh -c 'mkdir -p "../../../wasm/$(dirname {})"; cp {} "../../../wasm/{}"' \;5353.docker/docker-compose.gov.j2diffbeforeafterboth21 options:21 options:22 max-size: "1m"22 max-size: "1m"23 max-file: "3"23 max-file: "3"24 command: cargo run --profile integration-tests --features={{ NETWORK }}-runtime,gov-test-timings -- --dev -linfo --rpc-cors=all --unsafe-rpc-external24 command: cargo run --profile integration-tests --features={{ NETWORK }}-runtime,gov-test-timings,fast-inflation -- --dev -linfo --rpc-cors=all --unsafe-rpc-external2525js-packages/tests/creditFeesToTreasury.seqtest.tsdiffbeforeafterboth33 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 - (blockInterval / 5)) {37 unsubscribe();37 unsubscribe();38 resolve();38 resolve();39 } else {39 } else {js-packages/tests/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth460460461 fromCollectionId(collectionId: number): string {461 fromCollectionId(collectionId: number): string {462 if(collectionId >= 0xffffffff || collectionId < 0) throw new Error('collectionId overflow');462 if(collectionId >= 0xffffffff || collectionId < 0) throw new Error('collectionId overflow');463 return (web3 as any).utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8, '0')}`);463 return web3.default.utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8, '0')}`);464 }464 }465465466 extractTokenId(address: string): { collectionId: number, tokenId: number } {466 extractTokenId(address: string): { collectionId: number, tokenId: number } {590590591 connectWeb3(wsEndpoint: string) {591 connectWeb3(wsEndpoint: string) {592 if(this.web3 !== null) return;592 if(this.web3 !== null) return;593 this.web3Provider = new (web3 as any).providers.WebsocketProvider(wsEndpoint);593 this.web3Provider = new web3.default.providers.WebsocketProvider(wsEndpoint);594 this.web3 = new (web3 as any)(this.web3Provider);594 this.web3 = new web3.default(this.web3Provider);595 }595 }596596597 override async disconnect() {597 override async disconnect() {js-packages/tests/inflation.seqtest.tsdiffbeforeafterboth17import 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';1920const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';192120// todo:playgrounds requires sudo, look into on the later stage22// todo:playgrounds requires sudo, look into on the later stage21describe('integration test: Inflation', () => {23describe('integration test: Inflation', () => {22 let superuser: IKeyringPair;24 let superuser: IKeyringPair;232524 before(async () => {26 before(async () => {25 await usingPlaygrounds(async (_, privateKey) => {27 await usingPlaygrounds(async (helper, privateKey) => {26 superuser = await privateKey('//Alice');28 superuser = await privateKey('//Alice');29 const api = helper.getApi();3031 const relayBlock = (await api.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();32 await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [helper.constructApiCall('api.tx.inflation.startInflation', [relayBlock])])).to.not.be.rejected;27 });33 });28 });34 });293536 // Make sure superuser can't start inflation without explicit sudo42 // Make sure superuser can't start inflation without explicit sudo37 await expect(helper.executeExtrinsic(superuser, 'api.tx.inflation.startInflation', [1])).to.be.rejectedWith(/BadOrigin/);43 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;424443 const blockInterval = (helper.getApi().consts.inflation.inflationBlockInterval as any).toBigInt();45 const blockInterval = (helper.getApi().consts.inflation.inflationBlockInterval as any).toBigInt();44 const totalIssuanceStart = ((await helper.callRpc('api.query.inflation.startingYearTotalIssuance', [])) as any).toBigInt();46 const totalIssuanceStart = ((await helper.callRpc('api.query.inflation.startingYearTotalIssuance', [])) as any).toBigInt();56 expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);58 expect(Math.abs(Number(expectedInflation))).to.be.lessThanOrEqual(tolerance);57 });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 const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();67 const startBlock = (relayBlock + blockInterval) - (relayBlock % blockInterval) + 1;6869 await helper.wait.forRelayBlockNumber(startBlock);7071 const treasuryBalanceBefore = await helper.balance.getSubstrate(TREASURY);7273 await helper.wait.forRelayBlockNumber(startBlock + blockInterval + 1);7475 const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);76 expect(Number(treasuryBalanceAfter)).to.be.eqls(Number(treasuryBalanceBefore + blockInflation));77 });58});78});5979pallets/inflation/Cargo.tomldiffbeforeafterboth27 'sp-std/std',27 'sp-std/std',28]28]29try-runtime = ["frame-support/try-runtime"]29try-runtime = ["frame-support/try-runtime"]30fast-inflation = []303131[dependencies]32[dependencies]32parity-scale-codec = { workspace = true }33parity-scale-codec = { workspace = true }runtime/common/config/pallets/mod.rsdiffbeforeafterboth101 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;101 type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;102}102}103103104// every time per how many blocks inflation is applied105#[cfg(feature = "fast-inflation")]106parameter_types! {107 pub const InflationBlockInterval: BlockNumber = 10;108}109#[cfg(not(feature = "fast-inflation"))]104parameter_types! {110parameter_types! {105 pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied111 pub const InflationBlockInterval: BlockNumber = 100;106}112}107113108/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet114/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yetruntime/opal/Cargo.tomldiffbeforeafterboth232preimage = []232preimage = []233refungible = []233refungible = []234session-test-timings = []234session-test-timings = []235fast-inflation = []235236236################################################################################237################################################################################237# local dependencies238# local dependenciesruntime/quartz/Cargo.tomldiffbeforeafterboth221preimage = []221preimage = []222refungible = []222refungible = []223session-test-timings = []223session-test-timings = []224fast-inflation = []224225225################################################################################226################################################################################226# local dependencies227# local dependenciesruntime/unique/Cargo.tomldiffbeforeafterboth224preimage = []224preimage = []225refungible = []225refungible = []226session-test-timings = []226session-test-timings = []227fast-inflation = []227228228################################################################################229################################################################################229# local dependencies230# local dependencies