difftreelog
Merge pull request #1017 from UniqueNetwork/feature/speedup-inflation-pallet
in: master
11 files changed
.docker/Dockerfile-chain-devdiffbeforeafterboth--- a/.docker/Dockerfile-chain-dev
+++ b/.docker/Dockerfile-chain-dev
@@ -21,7 +21,7 @@
WORKDIR /dev_chain
-RUN cargo build --profile integration-tests --features=${NETWORK}-runtime
+RUN cargo build --profile integration-tests --features=${NETWORK}-runtime,fast-inflation
RUN echo "$NETWORK"
-CMD cargo run --profile integration-tests --features=${NETWORK}-runtime -- --dev -linfo --rpc-cors=all --unsafe-rpc-external
+CMD cargo run --profile integration-tests --features=${NETWORK}-runtime,fast-inflation -- --dev -linfo --rpc-cors=all --unsafe-rpc-external
.docker/Dockerfile-uniquediffbeforeafterboth--- a/.docker/Dockerfile-unique
+++ b/.docker/Dockerfile-unique
@@ -47,7 +47,7 @@
--mount=type=cache,target=/unique_parachain/unique-chain/target \
cd unique-chain && \
echo "Using runtime features '$RUNTIME_FEATURES'" && \
- CARGO_INCREMENTAL=0 cargo build --profile integration-tests --features="$RUNTIME_FEATURES" --locked && \
+ CARGO_INCREMENTAL=0 cargo build --profile integration-tests --features=fast-inflation,"$RUNTIME_FEATURES" --locked && \
mv ./target/integration-tests/unique-collator /unique_parachain/unique-chain/ && \
cd target/integration-tests/wbuild && find . -name "*.wasm" -exec sh -c 'mkdir -p "../../../wasm/$(dirname {})"; cp {} "../../../wasm/{}"' \;
.docker/docker-compose.gov.j2diffbeforeafterboth--- a/.docker/docker-compose.gov.j2
+++ b/.docker/docker-compose.gov.j2
@@ -21,4 +21,4 @@
options:
max-size: "1m"
max-file: "3"
- command: cargo run --profile integration-tests --features={{ NETWORK }}-runtime,gov-test-timings -- --dev -linfo --rpc-cors=all --unsafe-rpc-external
+ command: cargo run --profile integration-tests --features={{ NETWORK }}-runtime,gov-test-timings,fast-inflation -- --dev -linfo --rpc-cors=all --unsafe-rpc-external
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 - (blockInterval / 5)) {
unsubscribe();
resolve();
} else {
js-packages/tests/eth/util/playgrounds/unique.dev.tsdiffbeforeafterboth--- a/js-packages/tests/eth/util/playgrounds/unique.dev.ts
+++ b/js-packages/tests/eth/util/playgrounds/unique.dev.ts
@@ -460,7 +460,7 @@
fromCollectionId(collectionId: number): string {
if(collectionId >= 0xffffffff || collectionId < 0) throw new Error('collectionId overflow');
- return (web3 as any).utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8, '0')}`);
+ return web3.default.utils.toChecksumAddress(`0x17c4e6453cc49aaaaeaca894e6d9683e${collectionId.toString(16).padStart(8, '0')}`);
}
extractTokenId(address: string): { collectionId: number, tokenId: number } {
@@ -590,8 +590,8 @@
connectWeb3(wsEndpoint: string) {
if(this.web3 !== null) return;
- this.web3Provider = new (web3 as any).providers.WebsocketProvider(wsEndpoint);
- this.web3 = new (web3 as any)(this.web3Provider);
+ this.web3Provider = new web3.default.providers.WebsocketProvider(wsEndpoint);
+ this.web3 = new web3.default(this.web3Provider);
}
override async disconnect() {
js-packages/tests/inflation.seqtest.tsdiffbeforeafterboth--- a/js-packages/tests/inflation.seqtest.ts
+++ b/js-packages/tests/inflation.seqtest.ts
@@ -17,13 +17,19 @@
import type {IKeyringPair} from '@polkadot/types/types';
import {expect, itSub, usingPlaygrounds} from './util/index.js';
+const TREASURY = '5EYCAe5ijiYfyeZ2JJCGq56LmPyNRAKzpG4QkoQkkQNB5e6Z';
+
// todo:playgrounds requires sudo, look into on the later stage
describe('integration test: Inflation', () => {
let superuser: IKeyringPair;
before(async () => {
- await usingPlaygrounds(async (_, privateKey) => {
+ await usingPlaygrounds(async (helper, privateKey) => {
superuser = await privateKey('//Alice');
+ const api = helper.getApi();
+
+ const relayBlock = (await api.query.parachainSystem.lastRelayChainBlockNumber()).toNumber();
+ await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [helper.constructApiCall('api.tx.inflation.startInflation', [relayBlock])])).to.not.be.rejected;
});
});
@@ -36,10 +42,6 @@
// Make sure superuser can't start inflation without explicit sudo
await expect(helper.executeExtrinsic(superuser, 'api.tx.inflation.startInflation', [1])).to.be.rejectedWith(/BadOrigin/);
- // Start inflation on relay block 1 (Alice is sudo)
- const tx = helper.constructApiCall('api.tx.inflation.startInflation', [1]);
- await expect(helper.executeExtrinsic(superuser, 'api.tx.sudo.sudo', [tx])).to.not.be.rejected;
-
const blockInterval = (helper.getApi().consts.inflation.inflationBlockInterval as any).toBigInt();
const totalIssuanceStart = ((await helper.callRpc('api.query.inflation.startingYearTotalIssuance', [])) as any).toBigInt();
const blockInflation = (await helper.callRpc('api.query.inflation.blockInflation', []) as any).toBigInt();
@@ -55,4 +57,22 @@
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();
+ 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 + 1);
+
+ const treasuryBalanceAfter = await helper.balance.getSubstrate(TREASURY);
+ expect(Number(treasuryBalanceAfter)).to.be.eqls(Number(treasuryBalanceBefore + blockInflation));
+ });
});
pallets/inflation/Cargo.tomldiffbeforeafterboth--- a/pallets/inflation/Cargo.toml
+++ b/pallets/inflation/Cargo.toml
@@ -27,6 +27,7 @@
'sp-std/std',
]
try-runtime = ["frame-support/try-runtime"]
+fast-inflation = []
[dependencies]
parity-scale-codec = { workspace = true }
runtime/common/config/pallets/mod.rsdiffbeforeafterboth--- a/runtime/common/config/pallets/mod.rs
+++ b/runtime/common/config/pallets/mod.rs
@@ -101,8 +101,14 @@
type WeightInfo = pallet_balances::weights::SubstrateWeight<Self>;
}
+// every time per how many blocks inflation is applied
+#[cfg(feature = "fast-inflation")]
+parameter_types! {
+ pub const InflationBlockInterval: BlockNumber = 10;
+}
+#[cfg(not(feature = "fast-inflation"))]
parameter_types! {
- pub const InflationBlockInterval: BlockNumber = 100; // every time per how many blocks inflation is applied
+ pub const InflationBlockInterval: BlockNumber = 100;
}
/// Pallet-inflation needs block number in on_initialize, where there is no `validation_data` exists yet
runtime/opal/Cargo.tomldiffbeforeafterboth1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6build = 'build.rs'7description = 'Opal Runtime'8edition = '2021'9homepage = 'https://unique.network'10license = 'GPLv3'11name = 'opal-runtime'12repository = 'https://github.com/UniqueNetwork/unique-chain'13version.workspace = true1415[package.metadata.docs.rs]16targets = ['x86_64-unknown-linux-gnu']1718[features]19default = ['opal-runtime', 'std']20limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing']21opal-runtime = [22 'app-promotion',23 'collator-selection',24 'foreign-assets',25 'governance',26 'pallet-test-utils',27 'preimage',28 'refungible',29]30pov-estimate = []31runtime-benchmarks = [32 "pallet-preimage/runtime-benchmarks",33 'cumulus-pallet-parachain-system/runtime-benchmarks',34 'frame-benchmarking',35 'frame-support/runtime-benchmarks',36 'frame-system-benchmarking',37 'frame-system/runtime-benchmarks',38 'pallet-app-promotion/runtime-benchmarks',39 'pallet-balances/runtime-benchmarks',40 'pallet-collator-selection/runtime-benchmarks',41 'pallet-collective/runtime-benchmarks',42 'pallet-common/runtime-benchmarks',43 'pallet-configuration/runtime-benchmarks',44 'pallet-democracy/runtime-benchmarks',45 'pallet-ethereum/runtime-benchmarks',46 'pallet-evm-coder-substrate/runtime-benchmarks',47 'pallet-evm-migration/runtime-benchmarks',48 'pallet-foreign-assets/runtime-benchmarks',49 'pallet-fungible/runtime-benchmarks',50 'pallet-identity/runtime-benchmarks',51 'pallet-inflation/runtime-benchmarks',52 'pallet-maintenance/runtime-benchmarks',53 'pallet-membership/runtime-benchmarks',54 'pallet-nonfungible/runtime-benchmarks',55 'pallet-ranked-collective/runtime-benchmarks',56 'pallet-referenda/runtime-benchmarks',57 'pallet-refungible/runtime-benchmarks',58 'pallet-scheduler/runtime-benchmarks',59 'pallet-structure/runtime-benchmarks',60 'pallet-timestamp/runtime-benchmarks',61 'pallet-unique/runtime-benchmarks',62 'pallet-utility/runtime-benchmarks',63 'pallet-xcm/runtime-benchmarks',64 'sp-runtime/runtime-benchmarks',65 'staging-xcm-builder/runtime-benchmarks',66]67std = [68 'cumulus-pallet-aura-ext/std',69 'cumulus-pallet-parachain-system/std',70 'cumulus-pallet-xcm/std',71 'cumulus-pallet-xcmp-queue/std',72 'cumulus-primitives-aura/std',73 'cumulus-primitives-core/std',74 'cumulus-primitives-utility/std',75 'frame-executive/std',76 'frame-support/std',77 'frame-system-rpc-runtime-api/std',78 'frame-system/std',79 'frame-try-runtime/std',80 'pallet-aura/std',81 'pallet-balances/std',82 'pallet-collective/std',83 'pallet-democracy/std',84 'pallet-gov-origins/std',85 'pallet-membership/std',86 'pallet-ranked-collective/std',87 'pallet-referenda/std',88 'pallet-scheduler/std',89 'parity-scale-codec/std',90 # 'pallet-contracts/std',91 # 'pallet-contracts-primitives/std',92 # 'pallet-contracts-rpc-runtime-api/std',93 # 'pallet-contract-helpers/std',94 "pallet-authorship/std",95 "pallet-preimage/std",96 "pallet-session/std",97 "pallet-state-trie-migration/std",98 "sp-consensus-aura/std",99 'app-promotion-rpc/std',100 'evm-coder/std',101 'fp-rpc/std',102 'fp-self-contained/std',103 'pallet-app-promotion/std',104 'pallet-balances-adapter/std',105 'pallet-base-fee/std',106 'pallet-charge-transaction/std',107 'pallet-collator-selection/std',108 'pallet-common/std',109 'pallet-configuration/std',110 'pallet-ethereum/std',111 'pallet-evm-coder-substrate/std',112 'pallet-evm-contract-helpers/std',113 'pallet-evm-migration/std',114 'pallet-evm-transaction-payment/std',115 'pallet-evm/std',116 'pallet-fungible/std',117 'pallet-identity/std',118 'pallet-inflation/std',119 'pallet-nonfungible/std',120 'pallet-refungible/std',121 'pallet-structure/std',122 'pallet-sudo/std',123 'pallet-timestamp/std',124 'pallet-transaction-payment-rpc-runtime-api/std',125 'pallet-transaction-payment/std',126 'pallet-treasury/std',127 'pallet-unique/std',128 'pallet-utility/std',129 'parachain-info/std',130 'serde',131 'sp-api/std',132 'sp-block-builder/std',133 'sp-core/std',134 'sp-inherents/std',135 'sp-io/std',136 'sp-offchain/std',137 'sp-runtime/std',138 'sp-session/std',139 'sp-std/std',140 'sp-storage/std',141 'sp-transaction-pool/std',142 'sp-version/std',143 'staging-xcm-builder/std',144 'staging-xcm-executor/std',145 'staging-xcm/std',146 'up-common/std',147 'up-data-structs/std',148 'up-pov-estimate-rpc/std',149 'up-rpc/std',150 'up-sponsorship/std',151152 "orml-tokens/std",153 "orml-traits/std",154 "orml-vesting/std",155 "orml-xcm-support/std",156 "orml-xtokens/std",157 "pallet-foreign-assets/std",158159 'pallet-maintenance/std',160 'pallet-test-utils?/std',161]162try-runtime = [163 "pallet-authorship/try-runtime",164 "pallet-collator-selection/try-runtime",165 "pallet-identity/try-runtime",166 "pallet-preimage/try-runtime",167 "pallet-session/try-runtime",168 "pallet-state-trie-migration/try-runtime",169 'cumulus-pallet-aura-ext/try-runtime',170 'cumulus-pallet-dmp-queue/try-runtime',171 'cumulus-pallet-parachain-system/try-runtime',172 'cumulus-pallet-xcm/try-runtime',173 'cumulus-pallet-xcmp-queue/try-runtime',174 'fp-self-contained/try-runtime',175 'frame-executive/try-runtime',176 'frame-support/try-runtime',177 'frame-system/try-runtime',178 'frame-try-runtime',179 'frame-try-runtime?/try-runtime',180 'orml-tokens/try-runtime',181 'orml-vesting/try-runtime',182 'orml-xtokens/try-runtime',183 'pallet-app-promotion/try-runtime',184 'pallet-aura/try-runtime',185 'pallet-balances-adapter/try-runtime',186 'pallet-balances/try-runtime',187 'pallet-base-fee/try-runtime',188 'pallet-charge-transaction/try-runtime',189 'pallet-collective/try-runtime',190 'pallet-collective/try-runtime',191 'pallet-common/try-runtime',192 'pallet-configuration/try-runtime',193 'pallet-democracy/try-runtime',194 'pallet-democracy/try-runtime',195 'pallet-ethereum/try-runtime',196 'pallet-evm-coder-substrate/try-runtime',197 'pallet-evm-contract-helpers/try-runtime',198 'pallet-evm-migration/try-runtime',199 'pallet-evm-transaction-payment/try-runtime',200 'pallet-evm/try-runtime',201 'pallet-foreign-assets/try-runtime',202 'pallet-fungible/try-runtime',203 'pallet-gov-origins/try-runtime',204 'pallet-inflation/try-runtime',205 'pallet-maintenance/try-runtime',206 'pallet-membership/try-runtime',207 'pallet-membership/try-runtime',208 'pallet-nonfungible/try-runtime',209 'pallet-ranked-collective/try-runtime',210 'pallet-referenda/try-runtime',211 'pallet-refungible/try-runtime',212 'pallet-scheduler/try-runtime',213 'pallet-scheduler/try-runtime',214 'pallet-structure/try-runtime',215 'pallet-sudo/try-runtime',216 'pallet-test-utils?/try-runtime',217 'pallet-timestamp/try-runtime',218 'pallet-transaction-payment/try-runtime',219 'pallet-treasury/try-runtime',220 'pallet-unique/try-runtime',221 'pallet-utility/try-runtime',222 'pallet-xcm/try-runtime',223 'parachain-info/try-runtime',224]225226app-promotion = []227collator-selection = []228foreign-assets = []229gov-test-timings = []230governance = []231lookahead = []232preimage = []233refungible = []234session-test-timings = []235fast-inflation = []236237################################################################################238# local dependencies239240[dependencies]241cumulus-pallet-aura-ext = { workspace = true }242cumulus-pallet-dmp-queue = { workspace = true }243cumulus-pallet-parachain-system = { workspace = true }244cumulus-pallet-xcm = { workspace = true }245cumulus-pallet-xcmp-queue = { workspace = true }246cumulus-primitives-aura = { workspace = true }247cumulus-primitives-core = { workspace = true }248cumulus-primitives-timestamp = { workspace = true }249cumulus-primitives-utility = { workspace = true }250frame-executive = { workspace = true }251frame-support = { workspace = true }252frame-system = { workspace = true }253frame-system-rpc-runtime-api = { workspace = true }254orml-tokens = { workspace = true }255orml-traits = { workspace = true }256orml-vesting = { workspace = true }257orml-xcm-support = { workspace = true }258orml-xtokens = { workspace = true }259pallet-aura = { workspace = true }260pallet-authorship = { workspace = true }261pallet-balances = { features = ["insecure_zero_ed"], workspace = true }262pallet-preimage = { workspace = true }263pallet-session = { workspace = true }264pallet-state-trie-migration = { workspace = true }265pallet-sudo = { workspace = true }266pallet-timestamp = { workspace = true }267pallet-transaction-payment = { workspace = true }268pallet-transaction-payment-rpc-runtime-api = { workspace = true }269pallet-treasury = { workspace = true }270pallet-utility = { workspace = true }271pallet-xcm = { workspace = true }272parachain-info = { workspace = true }273parity-scale-codec = { workspace = true }274polkadot-parachain-primitives = { workspace = true }275smallvec = { workspace = true }276sp-api = { workspace = true }277sp-arithmetic = { workspace = true }278sp-block-builder = { workspace = true }279sp-consensus-aura = { workspace = true }280sp-core = { workspace = true }281sp-inherents = { workspace = true }282sp-io = { workspace = true }283sp-offchain = { workspace = true }284sp-runtime = { workspace = true }285sp-session = { workspace = true }286sp-std = { workspace = true }287sp-storage = { workspace = true }288sp-transaction-pool = { workspace = true }289sp-version = { workspace = true }290staging-xcm = { workspace = true }291staging-xcm-builder = { workspace = true }292staging-xcm-executor = { workspace = true }293294app-promotion-rpc = { workspace = true }295derivative = { workspace = true }296evm-coder = { workspace = true }297fp-evm = { workspace = true }298fp-rpc = { workspace = true }299fp-self-contained = { workspace = true }300log = { workspace = true }301num_enum = { workspace = true }302pallet-app-promotion = { workspace = true }303pallet-balances-adapter = { workspace = true }304pallet-base-fee = { workspace = true }305pallet-charge-transaction = { workspace = true }306pallet-collator-selection = { workspace = true }307pallet-collective = { workspace = true }308pallet-common = { workspace = true }309pallet-configuration = { workspace = true }310pallet-democracy = { workspace = true }311pallet-ethereum = { workspace = true }312pallet-evm = { workspace = true }313pallet-evm-coder-substrate = { workspace = true }314pallet-evm-contract-helpers = { workspace = true }315pallet-evm-migration = { workspace = true }316pallet-evm-precompile-simple = { workspace = true }317pallet-evm-transaction-payment = { workspace = true }318pallet-foreign-assets = { workspace = true }319pallet-fungible = { workspace = true }320pallet-gov-origins = { workspace = true }321pallet-identity = { workspace = true }322pallet-inflation = { workspace = true }323pallet-maintenance = { workspace = true }324pallet-membership = { workspace = true }325pallet-nonfungible = { workspace = true }326pallet-ranked-collective = { workspace = true }327pallet-referenda = { workspace = true }328pallet-refungible = { workspace = true }329pallet-scheduler = { workspace = true }330pallet-structure = { workspace = true }331pallet-unique = { workspace = true }332precompile-utils-macro = { workspace = true }333scale-info = { workspace = true }334up-common = { workspace = true }335up-data-structs = { workspace = true }336up-pov-estimate-rpc = { workspace = true }337up-rpc = { workspace = true }338up-sponsorship = { workspace = true }339340################################################################################341# Optional dependencies342343frame-benchmarking = { workspace = true, optional = true }344frame-system-benchmarking = { workspace = true, optional = true }345frame-try-runtime = { workspace = true, optional = true }346serde = { workspace = true, optional = true }347348################################################################################349# Test dependencies350351pallet-test-utils = { workspace = true, optional = true }352353################################################################################354# Other Dependencies355356hex-literal = { workspace = true }357impl-trait-for-tuples = { workspace = true }358359[build-dependencies]360substrate-wasm-builder = { workspace = true }runtime/quartz/Cargo.tomldiffbeforeafterboth--- a/runtime/quartz/Cargo.toml
+++ b/runtime/quartz/Cargo.toml
@@ -221,6 +221,7 @@
preimage = []
refungible = []
session-test-timings = []
+fast-inflation = []
################################################################################
# local dependencies
runtime/unique/Cargo.tomldiffbeforeafterboth--- a/runtime/unique/Cargo.toml
+++ b/runtime/unique/Cargo.toml
@@ -224,6 +224,7 @@
preimage = []
refungible = []
session-test-timings = []
+fast-inflation = []
################################################################################
# local dependencies