-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(
/blocks
): cache extrinsic base weight constants to improve perf…
…ormance (#478) This fixes a regression that happened when v2.1.2 was released. ie: [commit](5ec24e6). It achieves this by cacheing extrinsic weight constants from the metadata that are used in extrinsic fee calculations.
- Loading branch information
Showing
29 changed files
with
742 additions
and
181 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ControllerConfig } from '../types/chains-config'; | ||
import { getBlockWeight } from './metadata-consts'; | ||
|
||
/** | ||
* Kusama configuration for Sidecar. | ||
*/ | ||
export const kusamaControllers: ControllerConfig = { | ||
controllers: { | ||
Blocks: true, | ||
BlocksExtrinsics: true, | ||
AccountsStakingPayouts: true, | ||
AccountsBalanceInfo: true, | ||
AccountsStakingInfo: true, | ||
AccountsVestingInfo: true, | ||
NodeNetwork: true, | ||
NodeVersion: true, | ||
NodeTransactionPool: true, | ||
RuntimeCode: true, | ||
RuntimeSpec: true, | ||
RuntimeMetadata: true, | ||
TransactionDryRun: true, | ||
TransactionMaterial: true, | ||
TransactionFeeEstimate: true, | ||
TransactionSubmit: true, | ||
PalletsStakingProgress: true, | ||
PalletsStorage: true, | ||
}, | ||
options: { | ||
finalizes: true, | ||
minCalcFeeRuntime: 1062, | ||
blockWeightStore: getBlockWeight('kusama'), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { | ||
BlockWeightStore, | ||
ExtBaseWeightValue, | ||
MetadataConsts, | ||
PerClassValue, | ||
} from '../../types/chains-config'; | ||
import { kusamaDefinitions } from './kusamaConsts'; | ||
import { polkadotDefinitions } from './polkadotConsts'; | ||
import { westendDefinitions } from './westendConsts'; | ||
|
||
/** | ||
* Creates an object that maps each runtime to their appropriate weight data. | ||
* | ||
* Each runtime imports their own `chainDefinitions`. `chainDefinitions` | ||
* are arrays that store objects which group a set of runtimes version and associated | ||
* extrinsic weight data. | ||
* | ||
* Example return object: | ||
* { | ||
* ... | ||
* 24: { extrinsicBaseWeight: 125000000 }, | ||
* 25: { extrinsicBaseWeight: 125000000 }, | ||
* 26: { extrinsicBaseWeight: 125000000 }, | ||
* 27: { blockWeights: { perClass: [Object] } }, | ||
* 28: { blockWeights: { perClass: [Object] } } | ||
* ... | ||
* } | ||
* | ||
* @param chainDefinitions An array of objects that group data based on runtimes | ||
* and their extrinsicBaseWeight metadata | ||
*/ | ||
export function generateBlockWeightStore( | ||
chainDefinitions: MetadataConsts[] | ||
): BlockWeightStore { | ||
const blockWeightStore: BlockWeightStore = {}; | ||
|
||
for (const def of chainDefinitions) { | ||
const runtimeVersions = def.runtimeVersions; | ||
for (const version of runtimeVersions) { | ||
blockWeightStore[version] = {}; | ||
|
||
if ((def as ExtBaseWeightValue).extrinsicBaseWeight) { | ||
(blockWeightStore[ | ||
version | ||
] as ExtBaseWeightValue).extrinsicBaseWeight = (def as ExtBaseWeightValue).extrinsicBaseWeight; | ||
} else if ((def as PerClassValue).perClass) { | ||
(blockWeightStore[ | ||
version | ||
] as PerClassValue).perClass = (def as PerClassValue).perClass; | ||
} else { | ||
throw new Error( | ||
'No Valid weight type found while generating block weight store' | ||
); | ||
} | ||
} | ||
} | ||
|
||
return blockWeightStore; | ||
} | ||
|
||
/** | ||
* Returns a set of runtimes pointing to their blockWeightDefinitions specific to | ||
* a chain | ||
* | ||
* @param specName specName from the metadata of the current block being fetched | ||
*/ | ||
export function getBlockWeight(specName: string): BlockWeightStore { | ||
switch (specName) { | ||
case 'polkadot': | ||
return generateBlockWeightStore(polkadotDefinitions); | ||
case 'kusama': | ||
return generateBlockWeightStore(kusamaDefinitions); | ||
case 'westend': | ||
return generateBlockWeightStore(westendDefinitions); | ||
default: | ||
return {}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { MetadataConsts } from '../../types/chains-config'; | ||
import { extrinsicBaseWeight, perClass } from './substrateConsts'; | ||
|
||
export const kusamaDefinitions: MetadataConsts[] = [ | ||
{ | ||
runtimeVersions: [ | ||
1062, | ||
2005, | ||
2007, | ||
2008, | ||
2011, | ||
2012, | ||
2013, | ||
2015, | ||
2019, | ||
2022, | ||
2023, | ||
2024, | ||
2025, | ||
2026, | ||
], | ||
extrinsicBaseWeight, | ||
}, | ||
{ | ||
runtimeVersions: [2027, 2028, 2029], | ||
perClass, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { MetadataConsts } from '../../types/chains-config'; | ||
import { extrinsicBaseWeight, perClass } from './substrateConsts'; | ||
|
||
export const polkadotDefinitions: MetadataConsts[] = [ | ||
{ | ||
runtimeVersions: [ | ||
0, | ||
1, | ||
5, | ||
6, | ||
7, | ||
8, | ||
9, | ||
10, | ||
11, | ||
12, | ||
13, | ||
14, | ||
15, | ||
16, | ||
17, | ||
18, | ||
23, | ||
24, | ||
25, | ||
26, | ||
], | ||
extrinsicBaseWeight, | ||
}, | ||
{ | ||
runtimeVersions: [27, 28, 29], | ||
perClass, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** | ||
* WEIGHT NOTES (POLKADOT | KUSAMA) | ||
* | ||
* @constant extrinsicBaseWeight | ||
* @constant blockWeights | ||
* | ||
* The following weights are used for Polkadot and Kusama chains. Both are using | ||
* the same fee calculations currently, and share the same Integer values. Because | ||
* of this we are allowing them both to share the same set of variables in order | ||
* to keep things as DRY as possible. That being said, if Kusama or Polkadot ever | ||
* change their definitions for weight calculation those definitions can be added | ||
* directly to `./polkadotConsts`, and `./kusamaConsts` files. | ||
*/ | ||
|
||
import { IPerClass } from 'src/types/chains-config'; | ||
|
||
/** | ||
* Polkadot runtime versions before v27 | ||
* Kusama runtime versions before v2027 | ||
*/ | ||
export const extrinsicBaseWeight = BigInt(125000000); | ||
|
||
/** | ||
* Polkadot runtime versions after v26 | ||
* Kusama runtime versions after v2026 | ||
*/ | ||
export const perClass: IPerClass = { | ||
normal: { | ||
baseExtrinsic: BigInt(125000000), | ||
}, | ||
operational: { | ||
baseExtrinsic: BigInt(1), | ||
}, | ||
mandatory: { | ||
baseExtrinsic: BigInt(512000000000001), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { MetadataConsts } from '../../types/chains-config'; | ||
import { extrinsicBaseWeight, perClass } from './substrateConsts'; | ||
|
||
export const westendDefinitions: MetadataConsts[] = [ | ||
{ | ||
runtimeVersions: [ | ||
6, | ||
7, | ||
8, | ||
20, | ||
28, | ||
29, | ||
30, | ||
31, | ||
32, | ||
33, | ||
24, | ||
35, | ||
41, | ||
43, | ||
44, | ||
45, | ||
], | ||
extrinsicBaseWeight, | ||
}, | ||
{ | ||
runtimeVersions: [47, 48, 49], | ||
perClass, | ||
}, | ||
]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ControllerConfig } from '../types/chains-config'; | ||
import { getBlockWeight } from './metadata-consts'; | ||
|
||
/** | ||
* Polkadot configuration for Sidecar. | ||
*/ | ||
export const polkadotControllers: ControllerConfig = { | ||
controllers: { | ||
Blocks: true, | ||
BlocksExtrinsics: true, | ||
AccountsStakingPayouts: true, | ||
AccountsBalanceInfo: true, | ||
AccountsStakingInfo: true, | ||
AccountsVestingInfo: true, | ||
NodeNetwork: true, | ||
NodeVersion: true, | ||
NodeTransactionPool: true, | ||
RuntimeCode: true, | ||
RuntimeSpec: true, | ||
RuntimeMetadata: true, | ||
TransactionDryRun: true, | ||
TransactionMaterial: true, | ||
TransactionFeeEstimate: true, | ||
TransactionSubmit: true, | ||
PalletsStakingProgress: true, | ||
PalletsStorage: true, | ||
}, | ||
options: { | ||
finalizes: true, | ||
minCalcFeeRuntime: 0, | ||
blockWeightStore: getBlockWeight('polkadot'), | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { ControllerConfig } from '../types/chains-config'; | ||
import { getBlockWeight } from './metadata-consts'; | ||
|
||
/** | ||
* Westend configuration for Sidecar. | ||
*/ | ||
export const westendControllers: ControllerConfig = { | ||
controllers: { | ||
Blocks: true, | ||
BlocksExtrinsics: true, | ||
AccountsStakingPayouts: true, | ||
AccountsBalanceInfo: true, | ||
AccountsStakingInfo: true, | ||
AccountsVestingInfo: true, | ||
NodeNetwork: true, | ||
NodeVersion: true, | ||
NodeTransactionPool: true, | ||
RuntimeCode: true, | ||
RuntimeSpec: true, | ||
RuntimeMetadata: true, | ||
TransactionDryRun: true, | ||
TransactionMaterial: true, | ||
TransactionFeeEstimate: true, | ||
TransactionSubmit: true, | ||
PalletsStakingProgress: true, | ||
PalletsStorage: true, | ||
}, | ||
options: { | ||
finalizes: true, | ||
minCalcFeeRuntime: 6, | ||
blockWeightStore: getBlockWeight('westend'), | ||
}, | ||
}; |
Oops, something went wrong.