fix: correctly handle v1 weights for historical blocks (#12065)

This commit is contained in:
Francis O'Brien 2025-12-15 02:44:24 +00:00 committed by GitHub
parent 0a49d3430c
commit 189b2d28c3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 20 additions and 11 deletions

View File

@ -30,9 +30,20 @@ function accumulateWeights (
const totalRefTime = new BN(0);
const totalProofSize = new BN(0);
if (!weight) {
return { totalProofSize, totalRefTime };
}
(['normal', 'operational', 'mandatory'] as const).forEach((cls) => {
totalRefTime.iadd(weight?.[cls].refTime.toBn() ?? new BN(0));
totalProofSize.iadd(weight?.[cls].proofSize.toBn() ?? new BN(0));
const classWeight = weight[cls];
if (classWeight) {
// convertWeight handles both V1 and V2 weights
const { v2Weight } = convertWeight(classWeight as V2Weight);
totalRefTime.iadd(isBn(v2Weight.refTime) ? v2Weight.refTime : v2Weight.refTime.toBn());
totalProofSize.iadd(isBn(v2Weight.proofSize) ? v2Weight.proofSize : v2Weight.proofSize.toBn());
}
});
return { totalProofSize, totalRefTime };

View File

@ -216,7 +216,7 @@ export interface Preimage extends PreimageBytes, PreimageStatus {
export interface V2WeightConstruct {
refTime: BN | ICompact<INumber>;
proofSize?: BN | ICompact<INumber>;
proofSize: BN | ICompact<INumber>;
}
export interface WeightResult {

View File

@ -32,13 +32,11 @@ interface Known {
// converts a weight construct to only contain BN values
function bnWeight (a: WeightSimple): BNWeight {
return {
proofSize: a.proofSize
? bnToBn(
isCompact(a.proofSize)
? a.proofSize.unwrap()
: a.proofSize
)
: BN_ZERO,
proofSize: bnToBn(
isCompact(a.proofSize)
? a.proofSize.unwrap()
: a.proofSize
),
refTime: bnToBn(
isCompact(a.refTime)
? a.refTime.unwrap()

View File

@ -33,7 +33,7 @@ export const ZERO_ACCOUNT = '0x9876543210abcdef9876543210abcdef9876543210abcdef9
const EMPTY_STATE: Partial<Result> = {
encodedCallLength: 0,
v1Weight: BN_ZERO,
v2Weight: { refTime: BN_ZERO },
v2Weight: { proofSize: BN_ZERO, refTime: BN_ZERO },
weight: BN_ZERO
};