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-uniquediffbeforeafterboth1# ===== Rust builder =====2FROM ubuntu:22.04 as rust-builder3LABEL maintainer="Unique.Network"45ENV CARGO_HOME="/cargo-home"6ENV PATH="/cargo-home/bin:$PATH"7ENV TZ=UTC8RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone910RUN apt-get update && \11 apt-get install -y curl cmake pkg-config libssl-dev git clang llvm libudev-dev protobuf-compiler && \12 apt-get clean && \13 rm -r /var/lib/apt/lists/*1415RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none1617ARG RUST_TOOLCHAIN18RUN echo "Using Rust '$RUST_TOOLCHAIN'" && \19 rustup toolchain install $RUST_TOOLCHAIN && \20 rustup target add wasm32-unknown-unknown --toolchain ${RUST_TOOLCHAIN} && \21 rustup default $RUST_TOOLCHAIN && \22 rustup target list --installed && \23 rustup show2425RUN mkdir /unique_parachain26WORKDIR /unique_parachain2728# ===== BUILD UNIQUE =====29FROM rust-builder as builder-polkadot-bin3031WORKDIR /unique_parachain3233COPY . unique-chain/3435ARG RUNTIME_FEATURES36# registry for Updating registry. It is safe to cache it, because it only contains references to the dependency files,37# and the caches for the files themselves are set in Cargo.lock, which won't be updated because of --locked flag38# git for Updating git repository. It is safe to cache it, because git dependencies are cached by revision,39# revision is locked in Cargo.lock, and it is forbidden to update the Cargo.lock, because of --locked flag40# passed to cargo build41# target for built dependencies. Technically, it may be unsafe to cache it, but there was no bugs in the caching logic42# of it to this day (Ignoring incremental compilation, which is explicitly disabled by CARGO_INCREMENTAL=0). Only the43# fully built crates will be cached depending on the crate source, version and feature set, which are locked by44# Cargo.lock, which can't be updated because of the --locked flag.45RUN --mount=type=cache,target=/cargo-home/registry \46 --mount=type=cache,target=/cargo-home/git \47 --mount=type=cache,target=/unique_parachain/unique-chain/target \48 cd unique-chain && \49 echo "Using runtime features '$RUNTIME_FEATURES'" && \50 CARGO_INCREMENTAL=0 cargo build --profile integration-tests --features="$RUNTIME_FEATURES" --locked && \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/{}"' \;5354# ===== BIN ======5556FROM ubuntu:22.04 as builder-polkadot5758COPY --from=builder-polkadot-bin /unique_parachain/unique-chain/unique-collator /bin/unique-collator59COPY --from=builder-polkadot-bin /unique_parachain/unique-chain/wasm /wasm60ENTRYPOINT ["/bin/unique-collator"]1# ===== Rust builder =====2FROM ubuntu:22.04 as rust-builder3LABEL maintainer="Unique.Network"45ENV CARGO_HOME="/cargo-home"6ENV PATH="/cargo-home/bin:$PATH"7ENV TZ=UTC8RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone910RUN apt-get update && \11 apt-get install -y curl cmake pkg-config libssl-dev git clang llvm libudev-dev protobuf-compiler && \12 apt-get clean && \13 rm -r /var/lib/apt/lists/*1415RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain none1617ARG RUST_TOOLCHAIN18RUN echo "Using Rust '$RUST_TOOLCHAIN'" && \19 rustup toolchain install $RUST_TOOLCHAIN && \20 rustup target add wasm32-unknown-unknown --toolchain ${RUST_TOOLCHAIN} && \21 rustup default $RUST_TOOLCHAIN && \22 rustup target list --installed && \23 rustup show2425RUN mkdir /unique_parachain26WORKDIR /unique_parachain2728# ===== BUILD UNIQUE =====29FROM rust-builder as builder-polkadot-bin3031WORKDIR /unique_parachain3233COPY . unique-chain/3435ARG RUNTIME_FEATURES36# registry for Updating registry. It is safe to cache it, because it only contains references to the dependency files,37# and the caches for the files themselves are set in Cargo.lock, which won't be updated because of --locked flag38# git for Updating git repository. It is safe to cache it, because git dependencies are cached by revision,39# revision is locked in Cargo.lock, and it is forbidden to update the Cargo.lock, because of --locked flag40# passed to cargo build41# target for built dependencies. Technically, it may be unsafe to cache it, but there was no bugs in the caching logic42# of it to this day (Ignoring incremental compilation, which is explicitly disabled by CARGO_INCREMENTAL=0). Only the43# fully built crates will be cached depending on the crate source, version and feature set, which are locked by44# Cargo.lock, which can't be updated because of the --locked flag.45RUN --mount=type=cache,target=/cargo-home/registry \46 --mount=type=cache,target=/cargo-home/git \47 --mount=type=cache,target=/unique_parachain/unique-chain/target \48 cd unique-chain && \49 echo "Using runtime features '$RUNTIME_FEATURES'" && \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/ && \52 cd target/integration-tests/wbuild && find . -name "*.wasm" -exec sh -c 'mkdir -p "../../../wasm/$(dirname {})"; cp {} "../../../wasm/{}"' \;5354# ===== BIN ======5556FROM ubuntu:22.04 as builder-polkadot5758COPY --from=builder-polkadot-bin /unique_parachain/unique-chain/unique-collator /bin/unique-collator59COPY --from=builder-polkadot-bin /unique_parachain/unique-chain/wasm /wasm60ENTRYPOINT ["/bin/unique-collator"].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.tomldiffbeforeafterboth--- a/runtime/opal/Cargo.toml
+++ b/runtime/opal/Cargo.toml
@@ -232,6 +232,7 @@
preimage = []
refungible = []
session-test-timings = []
+fast-inflation = []
################################################################################
# local dependencies
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