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