Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(BlocksService): check all materials prior to creating calcFrom.from_params #501

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 14 additions & 12 deletions src/services/blocks/BlocksService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -469,17 +469,6 @@ export class BlocksService extends AbstractService {
parentHash: Hash,
block: Block
): Promise<ICalcFee> {
const coefficients = api.consts.transactionPayment.weightToFee.map((c) => {
return {
// Anything that could overflow Number.MAX_SAFE_INTEGER needs to be serialized
// to BigInt or string.
coeffInteger: c.coeffInteger.toString(10),
coeffFrac: c.coeffFrac.toNumber(),
degree: c.degree.toNumber(),
negative: c.negative,
};
});

const parentParentHash: Hash = await this.getParentParentHash(
api,
parentHash,
Expand All @@ -498,12 +487,14 @@ export class BlocksService extends AbstractService {
const extrinsicBaseWeightExists =
api.consts.system.extrinsicBaseWeight ||
api.consts.system.blockWeights.perClass.normal.baseExtrinsic;
const { weightToFee } = api.consts.transactionPayment;

if (
!perByte ||
!extrinsicBaseWeightExists ||
(this.minCalcFeeRuntime && specVersion < this.minCalcFeeRuntime) ||
!multiplier
!multiplier ||
!weightToFee
) {
// This particular runtime version is not supported with fee calcs or
// does not have the necessay materials to build calcFee
Expand All @@ -513,6 +504,17 @@ export class BlocksService extends AbstractService {
};
}

const coefficients = weightToFee.map((c) => {
return {
// Anything that could overflow Number.MAX_SAFE_INTEGER needs to be serialized
// to BigInt or string.
coeffInteger: c.coeffInteger.toString(10),
coeffFrac: c.coeffFrac.toNumber(),
degree: c.degree.toNumber(),
negative: c.negative,
};
});

// Now that we know the exact runtime supports fee calcs, make sure we have
// the weights in the store
this.blockWeightStore[specVersion] ||= await this.getWeight(
Expand Down