Skip to content

Commit

Permalink
fix: timings corresponding to block time
Browse files Browse the repository at this point in the history
  • Loading branch information
Grigoriy Simonov committed Nov 22, 2024
1 parent f4a6a28 commit 8ee9f3d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .baedeker/up.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/sh
set -e
BDK_DIR=$(dirname $(readlink -f "$0"))
RUST_LOG=info baedeker --spec=docker -J$BDK_DIR/vendor/ --generator=docker_compose=$BDK_DIR/.bdk-env --generator=docker_compose_discover=$BDK_DIR/.bdk-env/discover.env --secret=file=$BDK_DIR/.bdk-env/secret --tla-str=relay_spec=rococo-local --tla-code=assethub_spec="import 'assethub-spec.json'" --input-modules='lib:baedeker-library/ops/nginx.libsonnet' --input-modules='lib:baedeker-library/ops/devtools.libsonnet' --tla-str=repoDir=$(realpath $BDK_DIR/..) $@ $BDK_DIR/rewrites.jsonnet
RUST_LOG=info baedeker --spec=docker -J$BDK_DIR/vendor/ --generator=docker_compose=$BDK_DIR/.bdk-env --generator=docker_compose_discover=$BDK_DIR/.bdk-env/discover.env --secret=file=$BDK_DIR/.bdk-env/secret --tla-str=relay_spec=westend-local --tla-code=assethub_spec="import 'assethub-spec.json'" --input-modules='lib:baedeker-library/ops/nginx.libsonnet' --input-modules='lib:baedeker-library/ops/devtools.libsonnet' --tla-str=repoDir=$(realpath $BDK_DIR/..) $@ $BDK_DIR/rewrites.jsonnet
cd $BDK_DIR/.bdk-env
docker compose up -d --wait --remove-orphans
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions js-packages/playgrounds/unique.ts
Original file line number Diff line number Diff line change
Expand Up @@ -590,18 +590,16 @@ export class ChainHelperBase {
}
return new Promise(async (resolve, reject) => {
try {
let inBlockResult;
const unsub = await sign((result: any) => {
const status = this.getTransactionStatus(result);

if(status === this.transactionStatus.SUCCESS) {
if (!result.status.isFinalized) {

Check failure on line 597 in js-packages/playgrounds/unique.ts

View workflow job for this annotation

GitHub Actions / codestyle / yarn_eslint

Unexpected space(s) after "if"
inBlockResult = result;
return;
}
this.logger.log(`${label} successful`);
unsub();
resolve({result: inBlockResult!, status, blockHash: inBlockResult!.status.asInBlock.toHuman()});
resolve({result, status, blockHash: result.status.toHuman().Finalized});
} else if(status === this.transactionStatus.FAIL) {
let moduleError = null;

Expand Down
3 changes: 2 additions & 1 deletion js-packages/test-utils/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ export const DONOR_FUNDING = 4_000_000n;

// App-promotion periods:
export const LOCKING_PERIOD = 12n; // 12 blocks of relay
export const UNLOCKING_PERIOD = 6n; // 6 blocks of parachain
export const CALCULATION_PERIOD = 12n; // 12 blocks of parachain
export const UNLOCKING_PERIOD = 24n; // 24 blocks of parachain

// Native contracts
export const COLLECTION_HELPER = '0x6c4e9fe1ae37a41e93cee429e8e1881abdcbb54f';
Expand Down
17 changes: 11 additions & 6 deletions js-packages/tests/sub/appPromotion/appPromotion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

import type {IKeyringPair} from '@polkadot/types/types';
import {
itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip, LOCKING_PERIOD, UNLOCKING_PERIOD,
itSub, usingPlaygrounds, Pallets, requirePalletsOrSkip, LOCKING_PERIOD,
CALCULATION_PERIOD,
} from '@unique/test-utils/util.js';
import {DevUniqueHelper} from '@unique/test-utils';
import {itEth, expect, SponsoringMode} from '@unique/test-utils/eth/util.js';
Expand All @@ -42,7 +43,7 @@ async function getAccounts(accountsNumber: number, balance?: bigint) {
}
// App promotion periods:
// LOCKING_PERIOD = 12 blocks of relay
// UNLOCKING_PERIOD = 6 blocks of parachain
// UNLOCKING_PERIOD = 12 blocks of parachain

describe('App promotion', () => {
before(async function () {
Expand All @@ -61,17 +62,21 @@ describe('App promotion', () => {

afterEach(async () => {
await usingPlaygrounds(async (helper) => {
const totalStakedBefore = await helper.staking.getTotalStaked();
let stakedByUsedAccs = 0n;
let unstakeTxs = [];
for(const account of usedAccounts) {
if(unstakeTxs.length === 3) {
await Promise.all(unstakeTxs);
unstakeTxs = [];
}
unstakeTxs.push(helper.staking.unstakeAll(account));
stakedByUsedAccs += await helper.staking.getTotalStaked({ Substrate: account.address });
}
await Promise.all(unstakeTxs);
usedAccounts = [];
expect(await helper.staking.getTotalStaked()).to.eq(0n); // there are no active stakes after each test
const stakedAfterUnstake = totalStakedBefore - stakedByUsedAccs;
expect(await helper.staking.getTotalStaked()).to.eq(stakedAfterUnstake); // there are no active stakes (for test accs) after each test
// Make sure previousCalculatedRecord is None to avoid problem with payout stakers;
await helper.admin.payoutStakers(palletAdmin, 100);
expect((await helper.getApi().query.appPromotion.previousCalculatedRecord() as any).isNone).to.be.true;
Expand Down Expand Up @@ -980,11 +985,11 @@ async function payUntilRewardFor(account: string, helper: DevUniqueHelper) {
throw Error(`Cannot find payout for ${account}`);
}

function calculateIncome(base: bigint, iter = 0, calcPeriod: bigint = UNLOCKING_PERIOD): bigint {
const DAY = 7200n;
function calculateIncome(base: bigint, iter = 0, calcPeriod: bigint = CALCULATION_PERIOD): bigint {
const BLOCKS_DAY = 14400n; // blocks per day
const ACCURACY = 1_000_000_000n;
// 453_256n / 1_000_000_000n = 0.0453256% /day
const income = base + base * (ACCURACY * (calcPeriod * 453_256n) / (1_000_000_000n * DAY)) / ACCURACY ;
const income = base + base * (ACCURACY * (calcPeriod * 453_256n) / (1_000_000_000n * BLOCKS_DAY)) / ACCURACY;

if(iter > 1) {
return calculateIncome(income, iter - 1, calcPeriod);
Expand Down
1 change: 1 addition & 0 deletions pallets/inflation/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ sp-core = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-std = { workspace = true }
up-common = { workspace = true }
4 changes: 3 additions & 1 deletion pallets/inflation/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,12 @@ use frame_system::pallet_prelude::BlockNumberFor;
pub use pallet::*;
use sp_runtime::{traits::BlockNumberProvider, Perbill};

use up_common::constants::RELAY_DAYS;

type BalanceOf<T> =
<<T as Config>::Currency as Inspect<<T as frame_system::Config>::AccountId>>::Balance;

pub const YEAR: u32 = 5_259_600; // 6-second block
pub const YEAR: u32 = RELAY_DAYS * 365 + RELAY_DAYS / 4; // 365 days plus quater of a day as average for leap year
// pub const YEAR: u32 = 2_629_800; // 12-second block
pub const TOTAL_YEARS_UNTIL_FLAT: u32 = 9;
pub const START_INFLATION_PERCENT: u32 = 10;
Expand Down

0 comments on commit 8ee9f3d

Please sign in to comment.