Skip to content

Commit

Permalink
fix: add block weights for Shiden network to support fee calculation (#…
Browse files Browse the repository at this point in the history
…688)

* create shiden base weight and controller

* add base weight and runtime version

* fixed spec version

* Update shidenControllers.ts

* ad min calc fee runtime

* manually add per class

* added shiden spec for calc

* indent on env file
  • Loading branch information
hoonsubin committed Oct 1, 2021
1 parent db18f02 commit 701ecef
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 7 deletions.
Binary file modified calc/pkg/calc_bg.wasm
Binary file not shown.
1 change: 0 additions & 1 deletion calc/pkg/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"files": [
"calc_bg.wasm",
"calc.js",
"calc_bg.js",
"calc.d.ts"
],
"main": "calc.js",
Expand Down
9 changes: 3 additions & 6 deletions calc/src/calc_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ impl Multiplier {
("westend", v) if 10 < v && v < 31 => V1((new_i128(inner), false)),
("westend", v) if 31 <= v => V2(new_u128(inner)),

("shiden", _v) => V2(new_u128(inner)),

("statemine", _v) => V2(new_u128(inner)),
("statemint", _v) => V2(new_u128(inner)),

Expand Down Expand Up @@ -149,12 +151,7 @@ impl CalcFee {
Some(calc)
}

pub fn calc_fee(
&self,
weight: Weight,
len: u32,
extrinsic_base_weight: Weight,
) -> String {
pub fn calc_fee(&self, weight: Weight, len: u32, extrinsic_base_weight: Weight) -> String {
let unadjusted_len_fee = self.per_byte_fee.saturating_mul(len.into());
let unadjusted_weight_fee = weight_to_fee(&weight, &self.polynomial);
let base_fee = weight_to_fee(&extrinsic_base_weight, &self.polynomial);
Expand Down
2 changes: 2 additions & 0 deletions src/chains-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { kusamaControllers } from './kusamaControllers';
import { mandalaControllers } from './mandalaControllers';
import { polkadotControllers } from './polkadotControllers';
import { polymeshControllers } from './polymeshControllers';
import { shidenControllers } from './shidenControllers';
import { soraControllers } from './soraControllers';
import { statemineControllers } from './statemineControllers';
import { statemintControllers } from './statemintControllers';
Expand All @@ -34,6 +35,7 @@ const specToControllerMap = {
statemint: statemintControllers,
westmine: statemineControllers,
westmint: statemintControllers,
shiden: shidenControllers,
sora: soraControllers,
};

Expand Down
3 changes: 3 additions & 0 deletions src/chains-config/metadata-consts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
import { kusamaDefinitions } from './kusamaConsts';
import { polkadotDefinitions } from './polkadotConsts';
import { polymeshDefinitions } from './polymeshConsts';
import { shidenDefinitions } from './shidenConsts';
import { westendDefinitions } from './westendConsts';

/**
Expand Down Expand Up @@ -85,6 +86,8 @@ export function getBlockWeight(specName: string): BlockWeightStore {
return generateBlockWeightStore(dockPoSMainnetDefinitions);
case 'dock-pos-test-runtime':
return generateBlockWeightStore(dockPoSTestnetDefinitions);
case 'shiden':
return generateBlockWeightStore(shidenDefinitions);
default:
return {};
}
Expand Down
18 changes: 18 additions & 0 deletions src/chains-config/metadata-consts/shidenConsts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { MetadataConsts } from '../../types/chains-config';

export const shidenDefinitions: MetadataConsts[] = [
{
runtimeVersions: [1, 2, 3, 6, 7, 8, 10, 14, 15],
perClass: {
normal: {
baseExtrinsic: BigInt(125000000),
},
operational: {
baseExtrinsic: BigInt(1),
},
mandatory: {
baseExtrinsic: BigInt(128000000000001),
},
},
},
];
34 changes: 34 additions & 0 deletions src/chains-config/shidenControllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { ControllerConfig } from '../types/chains-config';
import { initLRUCache } from './cache/lruCache';
import { getBlockWeight } from './metadata-consts';

/**
* Controllers for Shiden collator
*/
export const shidenControllers: ControllerConfig = {
controllers: [
'AccountsBalanceInfo',
'AccountsVestingInfo',
'Blocks',
'BlocksExtrinsics',
'BlocksTrace',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
'PalletsAssets',
'PalletsStorage',
'Paras',
'RuntimeCode',
'RuntimeMetadata',
'RuntimeSpec',
'TransactionFeeEstimate',
'TransactionMaterial',
'TransactionSubmit',
],
options: {
finalizes: true,
minCalcFeeRuntime: 1,
blockWeightStore: getBlockWeight('shiden'),
blockStore: initLRUCache(),
},
};

0 comments on commit 701ecef

Please sign in to comment.