Skip to content

Commit 0cb7b34

Browse files
authored
Update with new consumed Weight structures (#2928)
* Update with new consumed Weight structures * dispatch(Info, Error} optional in result * Update for maximumBlockWeight
1 parent a74382c commit 0cb7b34

File tree

11 files changed

+85
-77
lines changed

11 files changed

+85
-77
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"@babel/core": "^7.12.9",
2727
"@babel/register": "^7.12.1",
2828
"@babel/runtime": "^7.12.5",
29-
"@polkadot/dev": "^0.60.12",
29+
"@polkadot/dev": "^0.60.13",
3030
"@polkadot/ts": "^0.3.57",
3131
"@polkadot/typegen": "workspace:packages/typegen",
3232
"@types/jest": "^26.0.17",

packages/api-contract/src/base/Contract.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
55
import type { ApiTypes, DecorateMethod } from '@polkadot/api/types';
66
import type { Bytes } from '@polkadot/types';
7-
import type { AccountId, ContractExecResult, EventRecord } from '@polkadot/types/interfaces';
7+
import type { AccountId, ContractExecResult, EventRecord, Weight } from '@polkadot/types/interfaces';
88
import type { AnyJson, CodecArg, ISubmittableResult, Registry } from '@polkadot/types/types';
99
import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent } from '../types';
1010
import type { ContractCallResult, ContractCallSend, ContractGeneric, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types';
@@ -145,7 +145,9 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
145145
return gasLimit.lten(0)
146146
? isCall
147147
? MAX_CALL_GAS
148-
: this.api.consts.system.maximumBlockWeight.muln(64).divn(100)
148+
: this.api.consts.system.blockWeights
149+
? this.api.consts.system.blockWeights.perClass.normal.maxExtrinsic.sub(this.api.consts.system.blockWeights.perClass.normal.baseExtrinsic)
150+
: (this.api.consts.system.maximumBlockWeight as Weight).muln(64).divn(100)
149151
: gasLimit;
150152
}
151153

packages/api/src/augment/consts.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33

44
import type { Vec, u16, u32, u64 } from '@polkadot/types';
55
import type { Codec } from '@polkadot/types/types';
6-
import type { Balance, BalanceOf, BlockNumber, LockIdentifier, ModuleId, Moment, Perbill, Percent, Permill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
6+
import type { Balance, BalanceOf, BlockNumber, LockIdentifier, ModuleId, Moment, Perbill, Percent, Permill, RuntimeDbWeight } from '@polkadot/types/interfaces/runtime';
77
import type { SessionIndex } from '@polkadot/types/interfaces/session';
88
import type { EraIndex } from '@polkadot/types/interfaces/staking';
99
import type { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support';
10+
import type { BlockWeights } from '@polkadot/types/interfaces/system';
1011
import type { ApiTypes } from '@polkadot/api/types';
1112

1213
declare module '@polkadot/api/types/consts' {
@@ -314,30 +315,18 @@ declare module '@polkadot/api/types/consts' {
314315
};
315316
system: {
316317
[key: string]: Codec;
317-
/**
318-
* The base weight of executing a block, independent of the transactions in the block.
319-
**/
320-
blockExecutionWeight: Weight & AugmentedConst<ApiType>;
321318
/**
322319
* The maximum number of blocks to allow in mortal eras.
323320
**/
324321
blockHashCount: BlockNumber & AugmentedConst<ApiType>;
325322
/**
326-
* The weight of runtime database operations the runtime can invoke.
327-
**/
328-
dbWeight: RuntimeDbWeight & AugmentedConst<ApiType>;
329-
/**
330-
* The base weight of an Extrinsic in the block, independent of the of extrinsic being executed.
331-
**/
332-
extrinsicBaseWeight: Weight & AugmentedConst<ApiType>;
333-
/**
334-
* The maximum length of a block (in bytes).
323+
* The weight configuration (limits & base values) for each class of extrinsics and block.
335324
**/
336-
maximumBlockLength: u32 & AugmentedConst<ApiType>;
325+
blockWeights: BlockWeights & AugmentedConst<ApiType>;
337326
/**
338-
* The maximum weight of a block.
327+
* The weight of runtime database operations the runtime can invoke.
339328
**/
340-
maximumBlockWeight: Weight & AugmentedConst<ApiType>;
329+
dbWeight: RuntimeDbWeight & AugmentedConst<ApiType>;
341330
};
342331
timestamp: {
343332
[key: string]: Codec;

packages/api/src/augment/query.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import type { AuthIndex } from '@polkadot/types/interfaces/imOnline';
1818
import type { DeferredOffenceOf, Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
1919
import type { ProxyAnnouncement, ProxyDefinition } from '@polkadot/types/interfaces/proxy';
2020
import type { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
21-
import type { AccountId, AccountIndex, AssetId, Balance, BalanceOf, BlockNumber, ExtrinsicsWeight, Hash, KeyTypeId, Moment, OpaqueCall, Perbill, Releases, ValidatorId } from '@polkadot/types/interfaces/runtime';
21+
import type { AccountId, AccountIndex, AssetId, Balance, BalanceOf, BlockNumber, Hash, KeyTypeId, Moment, OpaqueCall, Perbill, Releases, ValidatorId } from '@polkadot/types/interfaces/runtime';
2222
import type { Scheduled, TaskAddress } from '@polkadot/types/interfaces/scheduler';
2323
import type { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
2424
import type { Bid, BidKind, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
2525
import type { ActiveEraInfo, ElectionResult, ElectionScore, ElectionStatus, EraIndex, EraRewardPoints, Exposure, Forcing, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
26-
import type { AccountInfo, DigestOf, EventIndex, EventRecord, LastRuntimeUpgradeInfo, Phase } from '@polkadot/types/interfaces/system';
26+
import type { AccountInfo, ConsumedWeight, DigestOf, EventIndex, EventRecord, LastRuntimeUpgradeInfo, Phase } from '@polkadot/types/interfaces/system';
2727
import type { Bounty, BountyIndex, OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
2828
import type { Multiplier } from '@polkadot/types/interfaces/txpayment';
2929
import type { Multisig } from '@polkadot/types/interfaces/utility';
@@ -822,7 +822,7 @@ declare module '@polkadot/api/types/storage' {
822822
/**
823823
* The current weight for the block.
824824
**/
825-
blockWeight: AugmentedQuery<ApiType, () => Observable<ExtrinsicsWeight>> & QueryableStorageEntry<ApiType>;
825+
blockWeight: AugmentedQuery<ApiType, () => Observable<ConsumedWeight>> & QueryableStorageEntry<ApiType>;
826826
/**
827827
* Digest of the current block, also part of the block header.
828828
**/

packages/metadata/src/v12/static-substrate.json

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@
3939
"name": "BlockWeight",
4040
"modifier": "Default",
4141
"type": {
42-
"Plain": "ExtrinsicsWeight"
42+
"Plain": "ConsumedWeight"
4343
},
44-
"fallback": "0x00000000000000000000000000000000",
44+
"fallback": "0x000000000000000000000000000000000000000000000000",
4545
"documentation": [
4646
" The current weight for the block."
4747
]
@@ -462,14 +462,6 @@
462462
" The maximum number of blocks to allow in mortal eras."
463463
]
464464
},
465-
{
466-
"name": "MaximumBlockWeight",
467-
"type": "Weight",
468-
"value": "0x00204aa9d1010000",
469-
"documentation": [
470-
" The maximum weight of a block."
471-
]
472-
},
473465
{
474466
"name": "DbWeight",
475467
"type": "RuntimeDbWeight",
@@ -479,27 +471,11 @@
479471
]
480472
},
481473
{
482-
"name": "BlockExecutionWeight",
483-
"type": "Weight",
484-
"value": "0x00f2052a01000000",
485-
"documentation": [
486-
" The base weight of executing a block, independent of the transactions in the block."
487-
]
488-
},
489-
{
490-
"name": "ExtrinsicBaseWeight",
491-
"type": "Weight",
492-
"value": "0x4059730700000000",
493-
"documentation": [
494-
" The base weight of an Extrinsic in the block, independent of the of extrinsic being executed."
495-
]
496-
},
497-
{
498-
"name": "MaximumBlockLength",
499-
"type": "u32",
500-
"value": "0x00005000",
474+
"name": "BlockWeights",
475+
"type": "BlockWeights",
476+
"value": "0x00f2052a0100000000204aa9d1010000405973070000000001c06e96a62e010000010098f73e5d010000010000000000000000405973070000000001c0f6e810a30100000100204aa9d1010000010088526a740000004059730700000000000000",
501477
"documentation": [
502-
" The maximum length of a block (in bytes)."
478+
" The weight configuration (limits & base values) for each class of extrinsics and block."
503479
]
504480
}
505481
],

packages/metadata/src/v12/static.ts

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

packages/types/src/augment/registry.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import type { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, Vouching
4444
import type { ActiveEraInfo, CompactAssignments, CompactAssignmentsTo257, CompactScore, CompactScoreCompact, ElectionCompute, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, NominatorIndexCompact, OffchainAccuracy, OffchainAccuracyCompact, PhragmenScore, Points, RewardDestination, RewardDestinationTo257, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorIndexCompact, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
4545
import type { ApiId, KeyValueOption, ReadProof, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/state';
4646
import type { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support';
47-
import type { AccountInfo, ApplyExtrinsicResult, ChainProperties, ChainType, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, Phase, RawOrigin, RefCount, RefCountTo259, SyncState, SystemOrigin, TransactionValidityError, UnknownTransaction } from '@polkadot/types/interfaces/system';
47+
import type { AccountInfo, ApplyExtrinsicResult, BlockWeights, ChainProperties, ChainType, ConsumedWeight, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, PerDispatchClass, Phase, RawOrigin, RefCount, RefCountTo259, SyncState, SystemOrigin, TransactionValidityError, UnknownTransaction, WeightPerClass } from '@polkadot/types/interfaces/system';
4848
import type { Bounty, BountyIndex, BountyStatus, BountyStatusActive, BountyStatusCuratorProposed, BountyStatusPendingPayout, OpenTip, OpenTipFinderTo225, OpenTipTip, OpenTipTo225, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
4949
import type { Multiplier } from '@polkadot/types/interfaces/txpayment';
5050
import type { Multisig, Timepoint } from '@polkadot/types/interfaces/utility';
@@ -1167,12 +1167,18 @@ declare module '@polkadot/types/types/registry' {
11671167
ApplyExtrinsicResult: ApplyExtrinsicResult;
11681168
'Option<ApplyExtrinsicResult>': Option<ApplyExtrinsicResult>;
11691169
'Vec<ApplyExtrinsicResult>': Vec<ApplyExtrinsicResult>;
1170+
BlockWeights: BlockWeights;
1171+
'Option<BlockWeights>': Option<BlockWeights>;
1172+
'Vec<BlockWeights>': Vec<BlockWeights>;
11701173
ChainProperties: ChainProperties;
11711174
'Option<ChainProperties>': Option<ChainProperties>;
11721175
'Vec<ChainProperties>': Vec<ChainProperties>;
11731176
ChainType: ChainType;
11741177
'Option<ChainType>': Option<ChainType>;
11751178
'Vec<ChainType>': Vec<ChainType>;
1179+
ConsumedWeight: ConsumedWeight;
1180+
'Option<ConsumedWeight>': Option<ConsumedWeight>;
1181+
'Vec<ConsumedWeight>': Vec<ConsumedWeight>;
11761182
DigestOf: DigestOf;
11771183
'Option<DigestOf>': Option<DigestOf>;
11781184
'Vec<DigestOf>': Vec<DigestOf>;
@@ -1264,6 +1270,9 @@ declare module '@polkadot/types/types/registry' {
12641270
PeerInfo: PeerInfo;
12651271
'Option<PeerInfo>': Option<PeerInfo>;
12661272
'Vec<PeerInfo>': Vec<PeerInfo>;
1273+
PerDispatchClass: PerDispatchClass;
1274+
'Option<PerDispatchClass>': Option<PerDispatchClass>;
1275+
'Vec<PerDispatchClass>': Vec<PerDispatchClass>;
12671276
Phase: Phase;
12681277
'Option<Phase>': Option<Phase>;
12691278
'Vec<Phase>': Vec<Phase>;
@@ -1290,6 +1299,9 @@ declare module '@polkadot/types/types/registry' {
12901299
UnknownTransaction: UnknownTransaction;
12911300
'Option<UnknownTransaction>': Option<UnknownTransaction>;
12921301
'Vec<UnknownTransaction>': Vec<UnknownTransaction>;
1302+
WeightPerClass: WeightPerClass;
1303+
'Option<WeightPerClass>': Option<WeightPerClass>;
1304+
'Vec<WeightPerClass>': Vec<WeightPerClass>;
12931305
Bounty: Bounty;
12941306
'Option<Bounty>': Option<Bounty>;
12951307
'Vec<Bounty>': Vec<Bounty>;

packages/types/src/interfaces/system/definitions.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,11 @@ export default {
139139
data: 'AccountData'
140140
},
141141
ApplyExtrinsicResult: 'Result<DispatchOutcome, TransactionValidityError>',
142+
BlockWeights: {
143+
baseBlock: 'Weight',
144+
maxBlock: 'Weight',
145+
perClass: 'PerDispatchClass'
146+
},
142147
ChainProperties: {
143148
ss58Format: 'Option<u8>',
144149
tokenDecimals: 'Option<u32>',
@@ -152,6 +157,7 @@ export default {
152157
Custom: 'Text'
153158
}
154159
},
160+
ConsumedWeight: 'PerDispatchClass',
155161
DigestOf: 'Digest',
156162
DispatchClass: {
157163
_enum: ['Normal', 'Operational', 'Mandatory']
@@ -283,6 +289,11 @@ export default {
283289
bestHash: 'Hash',
284290
bestNumber: 'BlockNumber'
285291
},
292+
PerDispatchClass: {
293+
normal: 'WeightPerClass',
294+
operational: 'WeightPerClass',
295+
mandatory: 'WeightPerClass'
296+
},
286297
Phase: {
287298
_enum: {
288299
ApplyExtrinsic: 'u32',
@@ -317,6 +328,12 @@ export default {
317328
NoUnsignedValidator: 'Null',
318329
Custom: 'u8'
319330
}
331+
},
332+
WeightPerClass: {
333+
baseExtrinsic: 'Weight',
334+
maxExtrinsic: 'Weight',
335+
maxTotal: 'Option<Weight>',
336+
reserved: 'Option<Weight>'
320337
}
321338
}
322339
} as Definitions;

packages/types/src/interfaces/system/types.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ export interface ApplyExtrinsicResult extends Result<DispatchOutcome, Transactio
2121
readonly asOk: DispatchOutcome;
2222
}
2323

24+
/** @name BlockWeights */
25+
export interface BlockWeights extends Struct {
26+
readonly baseBlock: Weight;
27+
readonly maxBlock: Weight;
28+
readonly perClass: PerDispatchClass;
29+
}
30+
2431
/** @name ChainProperties */
2532
export interface ChainProperties extends Struct {
2633
readonly ss58Format: Option<u8>;
@@ -37,6 +44,9 @@ export interface ChainType extends Enum {
3744
readonly asCustom: Text;
3845
}
3946

47+
/** @name ConsumedWeight */
48+
export interface ConsumedWeight extends PerDispatchClass {}
49+
4050
/** @name DigestOf */
4151
export interface DigestOf extends Digest {}
4252

@@ -238,6 +248,13 @@ export interface PeerPing extends Struct {
238248
readonly secs: u64;
239249
}
240250

251+
/** @name PerDispatchClass */
252+
export interface PerDispatchClass extends Struct {
253+
readonly normal: WeightPerClass;
254+
readonly operational: WeightPerClass;
255+
readonly mandatory: WeightPerClass;
256+
}
257+
241258
/** @name Phase */
242259
export interface Phase extends Enum {
243260
readonly isApplyExtrinsic: boolean;
@@ -286,4 +303,12 @@ export interface UnknownTransaction extends Enum {
286303
readonly asCustom: u8;
287304
}
288305

306+
/** @name WeightPerClass */
307+
export interface WeightPerClass extends Struct {
308+
readonly baseExtrinsic: Weight;
309+
readonly maxExtrinsic: Weight;
310+
readonly maxTotal: Option<Weight>;
311+
readonly reserved: Option<Weight>;
312+
}
313+
289314
export type PHANTOM_SYSTEM = 'system';

packages/types/src/types/extrinsic.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@
44
import { ExtrinsicStatus } from '../interfaces/author';
55
import { EcdsaSignature, Ed25519Signature, Sr25519Signature } from '../interfaces/extrinsics';
66
import { Address, Balance, Call, H256, Index } from '../interfaces/runtime';
7-
import { EventRecord } from '../interfaces/system';
7+
import { DispatchError, DispatchInfo, EventRecord } from '../interfaces/system';
88
import { Codec } from './codec';
99
import { AnyJson, AnyNumber, AnyU8a } from './helpers';
1010
import { ICompact, IKeyringPair, IMethod, IRuntimeVersion } from './interfaces';
1111

1212
export interface ISubmittableResult {
13+
readonly dispatchError?: DispatchError;
14+
readonly dispatchInfo?: DispatchInfo;
1315
readonly events: EventRecord[];
1416
readonly status: ExtrinsicStatus;
1517
readonly isCompleted: boolean;

0 commit comments

Comments
 (0)