Skip to content

Commit

Permalink
fix: support fee calculation for Bifrost (#853)
Browse files Browse the repository at this point in the history
* fix: support fee calculation for Bifrost

* fix: lint error
  • Loading branch information
ark930 committed Mar 1, 2022
1 parent 7f29c46 commit cd33db7
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 1 deletion.
Binary file modified calc/pkg/calc_bg.wasm
Binary file not shown.
4 changes: 3 additions & 1 deletion calc/src/calc_fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ impl Multiplier {
("acala", _v) => V2(new_u128(inner)),
("crust", _v) => V2(new_u128(inner)),

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

_ => {
info!("Unsupported runtime: {}#{}", spec_name, spec_version);
return None;
Expand Down Expand Up @@ -263,7 +265,7 @@ mod test_fees {
// Test against V2 calc
assert_eq!(Multiplier::calc(&V2(new_u128(inner)), 1000000000000), 500);

// Test against V1 calc
// Test against V1 calc
assert_eq!(Multiplier::calc(&V1((new_i128(inner), false)), 1000000000), 1000000000);
assert_eq!(Multiplier::calc(&V1((new_i128(inner), true)), 1000000000), 1000000000);

Expand Down
33 changes: 33 additions & 0 deletions src/chains-config/bifrostControllers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import { ControllerConfig } from '../types/chains-config';
import { initLRUCache } from './cache/lruCache';
import { getBlockWeight } from './metadata-consts';

/**
* Controllers for Bifrost collator
*/
export const bifrostControllers: ControllerConfig = {
controllers: [
'AccountsBalanceInfo',
'AccountsValidate',
'Blocks',
'BlocksExtrinsics',
'NodeNetwork',
'NodeTransactionPool',
'NodeVersion',
'PalletsStorage',
'Paras',
'RuntimeCode',
'RuntimeMetadata',
'RuntimeSpec',
'TransactionDryRun',
'TransactionFeeEstimate',
'TransactionMaterial',
'TransactionSubmit',
],
options: {
finalizes: true,
minCalcFeeRuntime: 1,
blockWeightStore: getBlockWeight('bifrost'),
blockStore: initLRUCache(),
},
};
2 changes: 2 additions & 0 deletions src/chains-config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { controllers } from '../controllers';
import { ControllerConfig } from '../types/chains-config';
import { acalaControllers } from './acalaControllers';
import { astarControllers } from './astarControllers';
import { bifrostControllers } from './bifrostControllers';
import { calamariControllers } from './calamariControllers';
import { crustControllers } from './crustControllers';
import { defaultControllers } from './defaultControllers';
Expand Down Expand Up @@ -49,6 +50,7 @@ const specToControllerMap = {
acala: acalaControllers,
manta: mantaControllers,
crust: crustControllers,
bifrost: bifrostControllers,
};

/**
Expand Down
12 changes: 12 additions & 0 deletions src/chains-config/metadata-consts/bifrostConsts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { MetadataConsts } from '../../types/chains-config';
import { extrinsicBaseWeight } from './substrateConsts';

export const bifrostDefinitions: MetadataConsts[] = [
{
runtimeVersions: [
1, 801, 802, 803, 804, 805, 900, 901, 902, 903, 904, 906, 907, 908, 909,
910, 912, 913, 914, 915, 916, 918, 920, 922, 923, 924, 925, 926, 927,
],
extrinsicBaseWeight,
},
];
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 @@ -8,6 +8,7 @@ import {
} from '../../types/chains-config';
import { acalaDefinitions } from './acalaConsts';
import { astarDefinitions } from './astarConsts';
import { bifrostDefinitions } from './bifrostConsts';
import { calamariDefinitions } from './calamariConsts';
import { crustDefinitions } from './crustConsts';
import {
Expand Down Expand Up @@ -112,6 +113,8 @@ export function getBlockWeight(specName: string): BlockWeightStore {
return generateBlockWeightStore(mantaDefinitions);
case 'crust':
return generateBlockWeightStore(crustDefinitions);
case 'bifrost':
return generateBlockWeightStore(bifrostDefinitions);
default:
return {};
}
Expand Down

0 comments on commit cd33db7

Please sign in to comment.