git.delta.rocks / unique-network / refs/commits / 32f66f7e1404

difftreelog

Merge pull request #1017 from UniqueNetwork/feature/speedup-inflation-pallet

Yaroslav Bolyukin2023-11-16parents: #aea35c0 #cc9eeb2.patch.diff
in: master

11 files changed

modified.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
modified.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/{}"' \;
 
modified.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
modifiedjs-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 {
modifiedjs-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() {
modifiedjs-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));
+  });
 });
modifiedpallets/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 }
modifiedruntime/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
modifiedruntime/opal/Cargo.tomldiffbeforeafterboth
--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -232,6 +232,7 @@
 preimage = []
 refungible = []
 session-test-timings = []
+fast-inflation = []
 
 ################################################################################
 # local dependencies
modifiedruntime/quartz/Cargo.tomldiffbeforeafterboth
before · runtime/quartz/Cargo.toml
1################################################################################2# Package34[package]5authors = ['Unique Network <support@uniquenetwork.io>']6build = 'build.rs'7description = 'Quartz Runtime'8edition = '2021'9homepage = 'https://unique.network'10license = 'GPLv3'11name = 'quartz-runtime'12repository = 'https://github.com/UniqueNetwork/unique-chain'13version.workspace = true1415[package.metadata.docs.rs]16targets = ['x86_64-unknown-linux-gnu']1718[features]19become-sapphire = []20default = ['quartz-runtime', 'std']21limit-testing = ['pallet-unique/limit-testing', 'up-data-structs/limit-testing']22pov-estimate = []23quartz-runtime = ['app-promotion', 'collator-selection', 'foreign-assets', 'governance', 'preimage', 'refungible']24runtime-benchmarks = [25	"pallet-preimage/runtime-benchmarks",26	'cumulus-pallet-parachain-system/runtime-benchmarks',27	'frame-benchmarking',28	'frame-support/runtime-benchmarks',29	'frame-system-benchmarking',30	'frame-system/runtime-benchmarks',31	'pallet-app-promotion/runtime-benchmarks',32	'pallet-balances/runtime-benchmarks',33	'pallet-collator-selection/runtime-benchmarks',34	'pallet-collective/runtime-benchmarks',35	'pallet-collective/runtime-benchmarks',36	'pallet-common/runtime-benchmarks',37	'pallet-configuration/runtime-benchmarks',38	'pallet-democracy/runtime-benchmarks',39	'pallet-democracy/runtime-benchmarks',40	'pallet-ethereum/runtime-benchmarks',41	'pallet-evm-coder-substrate/runtime-benchmarks',42	'pallet-evm-migration/runtime-benchmarks',43	'pallet-foreign-assets/runtime-benchmarks',44	'pallet-fungible/runtime-benchmarks',45	'pallet-identity/runtime-benchmarks',46	'pallet-inflation/runtime-benchmarks',47	'pallet-maintenance/runtime-benchmarks',48	'pallet-membership/runtime-benchmarks',49	'pallet-membership/runtime-benchmarks',50	'pallet-nonfungible/runtime-benchmarks',51	'pallet-ranked-collective/runtime-benchmarks',52	'pallet-referenda/runtime-benchmarks',53	'pallet-refungible/runtime-benchmarks',54	'pallet-scheduler/runtime-benchmarks',55	'pallet-scheduler/runtime-benchmarks',56	'pallet-structure/runtime-benchmarks',57	'pallet-timestamp/runtime-benchmarks',58	'pallet-unique/runtime-benchmarks',59	'pallet-utility/runtime-benchmarks',60	'pallet-xcm/runtime-benchmarks',61	'sp-runtime/runtime-benchmarks',62	'staging-xcm-builder/runtime-benchmarks',63]64std = [65	'cumulus-pallet-aura-ext/std',66	'cumulus-pallet-parachain-system/std',67	'cumulus-pallet-xcm/std',68	'cumulus-pallet-xcmp-queue/std',69	'cumulus-primitives-core/std',70	'cumulus-primitives-utility/std',71	'frame-executive/std',72	'frame-support/std',73	'frame-system-rpc-runtime-api/std',74	'frame-system/std',75	'frame-try-runtime/std',76	'pallet-aura/std',77	'pallet-balances-adapter/std',78	'pallet-balances/std',79	'pallet-collective/std',80	'pallet-democracy/std',81	'pallet-membership/std',82	'pallet-scheduler/std',83	'parity-scale-codec/std',84	# 'pallet-contracts/std',85	# 'pallet-contracts-primitives/std',86	# 'pallet-contracts-rpc-runtime-api/std',87	# 'pallet-contract-helpers/std',88	"pallet-authorship/std",89	"pallet-identity/std",90	"pallet-preimage/std",91	"pallet-session/std",92	"pallet-state-trie-migration/std",93	"sp-consensus-aura/std",94	'app-promotion-rpc/std',95	'evm-coder/std',96	'fp-rpc/std',97	'fp-self-contained/std',98	'pallet-app-promotion/std',99	'pallet-base-fee/std',100	'pallet-charge-transaction/std',101	'pallet-collator-selection/std',102	'pallet-collective/std',103	'pallet-common/std',104	'pallet-configuration/std',105	'pallet-democracy/std',106	'pallet-ethereum/std',107	'pallet-evm-coder-substrate/std',108	'pallet-evm-contract-helpers/std',109	'pallet-evm-migration/std',110	'pallet-evm-transaction-payment/std',111	'pallet-evm/std',112	'pallet-fungible/std',113	'pallet-gov-origins/std',114	'pallet-inflation/std',115	'pallet-membership/std',116	'pallet-nonfungible/std',117	'pallet-ranked-collective/std',118	'pallet-referenda/std',119	'pallet-refungible/std',120	'pallet-scheduler/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-transaction-pool/std',141	'sp-version/std',142	'staging-xcm-builder/std',143	'staging-xcm-executor/std',144	'staging-xcm/std',145	'up-common/std',146	'up-data-structs/std',147	'up-pov-estimate-rpc/std',148	'up-rpc/std',149	'up-sponsorship/std',150151	"orml-tokens/std",152	"orml-traits/std",153	"orml-vesting/std",154	"orml-xcm-support/std",155	"orml-xtokens/std",156	"pallet-foreign-assets/std",157	"pallet-maintenance/std",158]159try-runtime = [160	"pallet-authorship/try-runtime",161	"pallet-collator-selection/try-runtime",162	"pallet-identity/try-runtime",163	"pallet-preimage/try-runtime",164	"pallet-session/try-runtime",165	"pallet-state-trie-migration/try-runtime",166	'cumulus-pallet-aura-ext/try-runtime',167	'cumulus-pallet-dmp-queue/try-runtime',168	'cumulus-pallet-parachain-system/try-runtime',169	'cumulus-pallet-xcm/try-runtime',170	'cumulus-pallet-xcmp-queue/try-runtime',171	'fp-self-contained/try-runtime',172	'frame-executive/try-runtime',173	'frame-support/try-runtime',174	'frame-system/try-runtime',175	'frame-try-runtime',176	'orml-tokens/try-runtime',177	'orml-vesting/try-runtime',178	'orml-xtokens/try-runtime',179	'pallet-app-promotion/try-runtime',180	'pallet-aura/try-runtime',181	'pallet-balances-adapter/try-runtime',182	'pallet-balances/try-runtime',183	'pallet-charge-transaction/try-runtime',184	'pallet-collective/try-runtime',185	'pallet-common/try-runtime',186	'pallet-configuration/try-runtime',187	'pallet-democracy/try-runtime',188	'pallet-ethereum/try-runtime',189	'pallet-evm-coder-substrate/try-runtime',190	'pallet-evm-contract-helpers/try-runtime',191	'pallet-evm-migration/try-runtime',192	'pallet-evm-transaction-payment/try-runtime',193	'pallet-evm/try-runtime',194	'pallet-foreign-assets/try-runtime',195	'pallet-fungible/try-runtime',196	'pallet-gov-origins/try-runtime',197	'pallet-inflation/try-runtime',198	'pallet-maintenance/try-runtime',199	'pallet-membership/try-runtime',200	'pallet-nonfungible/try-runtime',201	'pallet-ranked-collective/try-runtime',202	'pallet-referenda/try-runtime',203	'pallet-refungible/try-runtime',204	'pallet-scheduler/try-runtime',205	'pallet-structure/try-runtime',206	'pallet-sudo/try-runtime',207	'pallet-timestamp/try-runtime',208	'pallet-transaction-payment/try-runtime',209	'pallet-treasury/try-runtime',210	'pallet-unique/try-runtime',211	'pallet-utility/try-runtime',212	'pallet-xcm/try-runtime',213	'parachain-info/try-runtime',214]215216app-promotion = []217collator-selection = []218foreign-assets = []219gov-test-timings = []220governance = []221preimage = []222refungible = []223session-test-timings = []224225################################################################################226# local dependencies227228[dependencies]229cumulus-pallet-aura-ext = { workspace = true }230cumulus-pallet-dmp-queue = { workspace = true }231cumulus-pallet-parachain-system = { workspace = true }232cumulus-pallet-xcm = { workspace = true }233cumulus-pallet-xcmp-queue = { workspace = true }234cumulus-primitives-core = { workspace = true }235cumulus-primitives-timestamp = { workspace = true }236cumulus-primitives-utility = { workspace = true }237frame-executive = { workspace = true }238frame-support = { workspace = true }239frame-system = { workspace = true }240frame-system-rpc-runtime-api = { workspace = true }241orml-tokens = { workspace = true }242orml-traits = { workspace = true }243orml-vesting = { workspace = true }244orml-xcm-support = { workspace = true }245orml-xtokens = { workspace = true }246pallet-aura = { workspace = true }247pallet-authorship = { workspace = true }248pallet-balances = { features = ["insecure_zero_ed"], workspace = true }249pallet-preimage = { workspace = true }250pallet-session = { workspace = true }251pallet-state-trie-migration = { workspace = true }252pallet-sudo = { workspace = true }253pallet-timestamp = { workspace = true }254pallet-transaction-payment = { workspace = true }255pallet-transaction-payment-rpc-runtime-api = { workspace = true }256pallet-treasury = { workspace = true }257pallet-utility = { workspace = true }258pallet-xcm = { workspace = true }259parachain-info = { workspace = true }260parity-scale-codec = { workspace = true }261polkadot-parachain-primitives = { workspace = true }262smallvec = { workspace = true }263sp-api = { workspace = true }264sp-arithmetic = { workspace = true }265sp-block-builder = { workspace = true }266sp-consensus-aura = { workspace = true }267sp-core = { workspace = true }268sp-inherents = { workspace = true }269sp-io = { workspace = true }270sp-offchain = { workspace = true }271sp-runtime = { workspace = true }272sp-session = { workspace = true }273sp-std = { workspace = true }274sp-storage = { workspace = true }275sp-transaction-pool = { workspace = true }276sp-version = { workspace = true }277staging-xcm = { workspace = true }278staging-xcm-builder = { workspace = true }279staging-xcm-executor = { workspace = true }280281app-promotion-rpc = { workspace = true }282derivative = { workspace = true }283fp-evm = { workspace = true }284log = { workspace = true }285pallet-app-promotion = { workspace = true }286pallet-balances-adapter = { workspace = true }287pallet-collator-selection = { workspace = true }288pallet-collective = { workspace = true }289pallet-common = { workspace = true }290pallet-configuration = { workspace = true }291pallet-democracy = { workspace = true }292pallet-fungible = { workspace = true }293pallet-gov-origins = { workspace = true }294pallet-identity = { workspace = true }295pallet-inflation = { workspace = true }296pallet-membership = { workspace = true }297pallet-nonfungible = { workspace = true }298pallet-ranked-collective = { workspace = true }299pallet-referenda = { workspace = true }300pallet-refungible = { workspace = true }301pallet-scheduler = { workspace = true }302pallet-structure = { workspace = true }303pallet-unique = { workspace = true }304scale-info = { workspace = true }305up-common = { workspace = true }306up-data-structs = { workspace = true }307up-pov-estimate-rpc = { workspace = true }308up-rpc = { workspace = true }309# pallet-contract-helpers = { path = '../pallets/contract-helpers', default-features = false, version = '0.1.0' }310evm-coder = { workspace = true }311fp-rpc = { workspace = true }312fp-self-contained = { workspace = true }313num_enum = { version = "0.7.0", default-features = false }314pallet-base-fee = { workspace = true }315pallet-charge-transaction = { workspace = true }316pallet-ethereum = { workspace = true }317pallet-evm = { workspace = true }318pallet-evm-coder-substrate = { workspace = true }319pallet-evm-contract-helpers = { workspace = true }320pallet-evm-migration = { workspace = true }321pallet-evm-precompile-simple = { workspace = true }322pallet-evm-transaction-payment = { workspace = true }323pallet-foreign-assets = { workspace = true }324pallet-maintenance = { workspace = true }325precompile-utils-macro = { workspace = true }326up-sponsorship = { workspace = true }327328################################################################################329# Optional dependencies330331frame-benchmarking = { workspace = true, optional = true }332frame-system-benchmarking = { workspace = true, optional = true }333frame-try-runtime = { workspace = true, optional = true }334serde = { workspace = true, optional = true }335336337################################################################################338# Test dependencies339340pallet-test-utils = { workspace = true }341342################################################################################343# Other Dependencies344345hex-literal = { workspace = true }346impl-trait-for-tuples = { workspace = true }347348[build-dependencies]349substrate-wasm-builder = { workspace = true }
modifiedruntime/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