Cater for Babe & Aura combo authors (#1305)
* Cater for Babe & Aura combo authors * Re-add BabeWeight (until metadata updated) * BabeWeight to registry * Remove abrs definitions * Bump metadata static
This commit is contained in:
@@ -32,7 +32,7 @@ export default class HeaderExtended extends _Header {
|
||||
if (pitem) {
|
||||
const [engine, data] = pitem.asPreRuntime;
|
||||
|
||||
if (engine.isAbrs || engine.isBabe || engine.isAura) {
|
||||
if (engine.isBabe || engine.isAura) {
|
||||
this._author = engine.extractAuthor(data, sessionValidators);
|
||||
}
|
||||
} else {
|
||||
@@ -45,13 +45,6 @@ export default class HeaderExtended extends _Header {
|
||||
if (engine.isAura) {
|
||||
this._author = engine.extractAuthor(data, sessionValidators);
|
||||
}
|
||||
} else {
|
||||
const [sitem] = header.digest.logsWith('SealV0');
|
||||
|
||||
// extract author from the seal (pre substrate 1.0, backwards compat)
|
||||
if (sitem) {
|
||||
this._author = sessionValidators[sitem.asSealV0[0].modn(sessionValidators.length)];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -317,7 +317,7 @@
|
||||
"name": "Authorities",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"PlainType": "Vec<(AuthorityId,BabeWeight)>"
|
||||
"PlainType": "Vec<(AuthorityId,BabeAuthorityWeight)>"
|
||||
},
|
||||
"fallback": "0x00",
|
||||
"documentation": [
|
||||
@@ -348,6 +348,30 @@
|
||||
" Current slot number."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "SecondarySlots",
|
||||
"modifier": "Default",
|
||||
"type": {
|
||||
"PlainType": "(bool,bool)"
|
||||
},
|
||||
"fallback": "0x0101",
|
||||
"documentation": [
|
||||
" Whether secondary slots are enabled in case the VRF-based slot is",
|
||||
" empty for the current epoch and the next epoch, respectively."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "PendingSecondarySlotsChange",
|
||||
"modifier": "Optional",
|
||||
"type": {
|
||||
"PlainType": "bool"
|
||||
},
|
||||
"fallback": "0x00",
|
||||
"documentation": [
|
||||
" Pending change to enable/disable secondary slots which will be",
|
||||
" triggered at `current_epoch + 2`."
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Randomness",
|
||||
"modifier": "Default",
|
||||
@@ -414,13 +438,28 @@
|
||||
}
|
||||
]
|
||||
},
|
||||
"calls": [],
|
||||
"calls": [
|
||||
{
|
||||
"name": "set_pending_secondary_slots_change",
|
||||
"args": [
|
||||
{
|
||||
"name": "change",
|
||||
"type": "Option<bool>"
|
||||
}
|
||||
],
|
||||
"documentation": [
|
||||
" Sets a pending change to enable / disable secondary slot assignment.",
|
||||
" The pending change will be set at the end of the current epoch and",
|
||||
" will be enacted at `current_epoch + 2`."
|
||||
]
|
||||
}
|
||||
],
|
||||
"events": null,
|
||||
"constants": [
|
||||
{
|
||||
"name": "EpochDuration",
|
||||
"type": "u64",
|
||||
"value": "0x6b01000000000000",
|
||||
"value": "0x6400000000000000",
|
||||
"documentation": [
|
||||
" The number of **slots** that an epoch takes. We couple sessions to",
|
||||
" epochs, i.e. we start a new session once the new epoch begins."
|
||||
@@ -496,7 +535,7 @@
|
||||
{
|
||||
"name": "MinimumPeriod",
|
||||
"type": "Moment",
|
||||
"value": "0x3903000000000000",
|
||||
"value": "0xb80b000000000000",
|
||||
"documentation": [
|
||||
" The minimum period between blocks. Beware that this is different to the *expected* period",
|
||||
" that the block production apparatus provides. Your chosen consensus system will generally",
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -4,10 +4,9 @@
|
||||
import { Compact, Option, Vec } from './codec';
|
||||
import { Bytes, Data, Fixed64, H160, H256, H512, Null, StorageData, StorageHasher, StorageKey, Text, Type, bool, i128, i16, i256, i32, i64, i8, u128, u16, u256, u32, u64, u8, usize } from './primitive';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, Consensus, ConsensusEngineId, Digest, DigestItem, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, Hash, Header, ImmortalEra, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, Moment, MortalEra, Origin, Perbill, Permill, Phantom, PhantomData, PreRuntime, Seal, SealV0, Signature, SignedBlock, Sr25519Signature, ValidatorId, Weight, WeightMultiplier } from './interfaces/runtime';
|
||||
import { RawAuraBorosPreDigest } from './interfaces/abrs';
|
||||
import { InclusionHeight, Uncle, UncleEntryItem } from './interfaces/authorship';
|
||||
import { RawAuraPreDigest } from './interfaces/aura';
|
||||
import { BabeWeight, RawBabePreDigest, SlotNumber } from './interfaces/babe';
|
||||
import { BabeAuthorityWeight, BabeBlockWeight, BabeWeight, RawBabePreDigest, RawBabePreDigestPrimary, RawBabePreDigestSecondary, SlotNumber } from './interfaces/babe';
|
||||
import { BalanceLock, VestingSchedule, WithdrawReasons } from './interfaces/balances';
|
||||
import { MemberCount, ProposalIndex, Votes } from './interfaces/collective';
|
||||
import { AuthorityId } from './interfaces/consensus';
|
||||
@@ -250,9 +249,6 @@ export interface InterfaceRegistry {
|
||||
Consensus: Consensus;
|
||||
'Option<Consensus>': Option<Consensus>;
|
||||
'Vec<Consensus>': Vec<Consensus>;
|
||||
RawAuraBorosPreDigest: RawAuraBorosPreDigest;
|
||||
'Option<RawAuraBorosPreDigest>': Option<RawAuraBorosPreDigest>;
|
||||
'Vec<RawAuraBorosPreDigest>': Vec<RawAuraBorosPreDigest>;
|
||||
InclusionHeight: InclusionHeight;
|
||||
'Option<InclusionHeight>': Option<InclusionHeight>;
|
||||
'Vec<InclusionHeight>': Vec<InclusionHeight>;
|
||||
@@ -265,6 +261,14 @@ export interface InterfaceRegistry {
|
||||
RawAuraPreDigest: RawAuraPreDigest;
|
||||
'Option<RawAuraPreDigest>': Option<RawAuraPreDigest>;
|
||||
'Vec<RawAuraPreDigest>': Vec<RawAuraPreDigest>;
|
||||
BabeAuthorityWeight: BabeAuthorityWeight;
|
||||
'Compact<BabeAuthorityWeight>': Compact<BabeAuthorityWeight>;
|
||||
'Option<BabeAuthorityWeight>': Option<BabeAuthorityWeight>;
|
||||
'Vec<BabeAuthorityWeight>': Vec<BabeAuthorityWeight>;
|
||||
BabeBlockWeight: BabeBlockWeight;
|
||||
'Compact<BabeBlockWeight>': Compact<BabeBlockWeight>;
|
||||
'Option<BabeBlockWeight>': Option<BabeBlockWeight>;
|
||||
'Vec<BabeBlockWeight>': Vec<BabeBlockWeight>;
|
||||
BabeWeight: BabeWeight;
|
||||
'Compact<BabeWeight>': Compact<BabeWeight>;
|
||||
'Option<BabeWeight>': Option<BabeWeight>;
|
||||
@@ -272,6 +276,12 @@ export interface InterfaceRegistry {
|
||||
RawBabePreDigest: RawBabePreDigest;
|
||||
'Option<RawBabePreDigest>': Option<RawBabePreDigest>;
|
||||
'Vec<RawBabePreDigest>': Vec<RawBabePreDigest>;
|
||||
RawBabePreDigestPrimary: RawBabePreDigestPrimary;
|
||||
'Option<RawBabePreDigestPrimary>': Option<RawBabePreDigestPrimary>;
|
||||
'Vec<RawBabePreDigestPrimary>': Vec<RawBabePreDigestPrimary>;
|
||||
RawBabePreDigestSecondary: RawBabePreDigestSecondary;
|
||||
'Option<RawBabePreDigestSecondary>': Option<RawBabePreDigestSecondary>;
|
||||
'Vec<RawBabePreDigestSecondary>': Vec<RawBabePreDigestSecondary>;
|
||||
SlotNumber: SlotNumber;
|
||||
'Compact<SlotNumber>': Compact<SlotNumber>;
|
||||
'Option<SlotNumber>': Option<SlotNumber>;
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export default {
|
||||
types: {
|
||||
RawAuraBorosPreDigest: {
|
||||
_enum: {
|
||||
Aura: 'RawAuraPreDigest',
|
||||
Babe: 'RawBabePreDigest'
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -1,4 +0,0 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './types';
|
||||
@@ -1,18 +0,0 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { Enum } from '../../codec';
|
||||
import { RawAuraPreDigest } from '../aura';
|
||||
import { RawBabePreDigest } from '../babe';
|
||||
|
||||
/** Enum */
|
||||
export interface RawAuraBorosPreDigest extends Enum {
|
||||
/** 0:: Aura(RawAuraPreDigest) */
|
||||
readonly isAura: boolean;
|
||||
/** RawAuraPreDigest */
|
||||
readonly asAura: RawAuraPreDigest;
|
||||
/** 1:: Babe(RawBabePreDigest) */
|
||||
readonly isBabe: boolean;
|
||||
/** RawBabePreDigest */
|
||||
readonly asBabe: RawBabePreDigest;
|
||||
}
|
||||
@@ -4,13 +4,28 @@
|
||||
|
||||
export default {
|
||||
types: {
|
||||
BabeAuthorityWeight: 'u64',
|
||||
BabeBlockWeight: 'u32',
|
||||
// TODO Remove as soon as merged and metadata static updated
|
||||
BabeWeight: 'u64',
|
||||
RawBabePreDigest: {
|
||||
slotNumber: 'SlotNumber',
|
||||
_enum: {
|
||||
Primary: 'RawBabePreDigestPrimary',
|
||||
Secondary: 'RawBabePreDigestSecondary'
|
||||
}
|
||||
},
|
||||
RawBabePreDigestPrimary: {
|
||||
authorityIndex: 'u32', // AuthorityIndex (also in aura, not same size there)
|
||||
slotNumber: 'SlotNumber',
|
||||
weight: 'BabeBlockWeight',
|
||||
vrfOutput: 'H256', // should be '[u8; 32]' (generator support lacking here)
|
||||
vrfProof: 'H256' // should be '[u8; 32]'
|
||||
},
|
||||
RawBabePreDigestSecondary: {
|
||||
authorityIndex: 'u32', // AuthorityIndex (also in aura, not same size there)
|
||||
slotNumber: 'SlotNumber',
|
||||
weight: 'BabeBlockWeight'
|
||||
},
|
||||
SlotNumber: 'u64'
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,23 +1,53 @@
|
||||
// Auto-generated via `yarn build:interfaces`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { Struct } from '../../codec';
|
||||
import { Enum, Struct } from '../../codec';
|
||||
import { H256, u32, u64 } from '../../primitive';
|
||||
|
||||
/** u64 */
|
||||
export type BabeAuthorityWeight = u64;
|
||||
|
||||
/** u32 */
|
||||
export type BabeBlockWeight = u32;
|
||||
|
||||
/** u64 */
|
||||
export type BabeWeight = u64;
|
||||
|
||||
/** Enum */
|
||||
export interface RawBabePreDigest extends Enum {
|
||||
/** 0:: Primary(RawBabePreDigestPrimary) */
|
||||
readonly isPrimary: boolean;
|
||||
/** RawBabePreDigestPrimary */
|
||||
readonly asPrimary: RawBabePreDigestPrimary;
|
||||
/** 1:: Secondary(RawBabePreDigestSecondary) */
|
||||
readonly isSecondary: boolean;
|
||||
/** RawBabePreDigestSecondary */
|
||||
readonly asSecondary: RawBabePreDigestSecondary;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface RawBabePreDigest extends Struct {
|
||||
/** SlotNumber */
|
||||
readonly slotNumber: SlotNumber;
|
||||
export interface RawBabePreDigestPrimary extends Struct {
|
||||
/** u32 */
|
||||
readonly authorityIndex: u32;
|
||||
/** SlotNumber */
|
||||
readonly slotNumber: SlotNumber;
|
||||
/** BabeBlockWeight */
|
||||
readonly weight: BabeBlockWeight;
|
||||
/** H256 */
|
||||
readonly vrfOutput: H256;
|
||||
/** H256 */
|
||||
readonly vrfProof: H256;
|
||||
}
|
||||
|
||||
/** Struct */
|
||||
export interface RawBabePreDigestSecondary extends Struct {
|
||||
/** u32 */
|
||||
readonly authorityIndex: u32;
|
||||
/** SlotNumber */
|
||||
readonly slotNumber: SlotNumber;
|
||||
/** BabeBlockWeight */
|
||||
readonly weight: BabeBlockWeight;
|
||||
}
|
||||
|
||||
/** u64 */
|
||||
export type SlotNumber = u64;
|
||||
|
||||
@@ -6,7 +6,6 @@
|
||||
export { default as runtime } from './runtime/definitions';
|
||||
|
||||
// substrate types
|
||||
export { default as abrs } from './abrs/definitions';
|
||||
export { default as authorship } from './authorship/definitions';
|
||||
export { default as aura } from './aura/definitions';
|
||||
export { default as babe } from './babe/definitions';
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './runtime/types';
|
||||
export * from './abrs/types';
|
||||
export * from './authorship/types';
|
||||
export * from './aura/types';
|
||||
export * from './babe/types';
|
||||
|
||||
@@ -11,12 +11,11 @@ import { createType } from '../../codec/create';
|
||||
import Bytes from '../Bytes';
|
||||
import U32 from '../U32';
|
||||
|
||||
const CID_ABRS = 0x53524241; // 'ABRS'
|
||||
const CID_AURA = 0x61727561; // 'aura'
|
||||
const CID_BABE = 0x45424142; // 'BABE'
|
||||
const CID_GRPA = 0x4b4e5246; // 'FRNK' (don't ask, used to be afg1)
|
||||
|
||||
export { CID_ABRS, CID_AURA, CID_BABE, CID_GRPA };
|
||||
export { CID_AURA, CID_BABE, CID_GRPA };
|
||||
|
||||
/**
|
||||
* @name ConsensusEngineId
|
||||
@@ -38,13 +37,6 @@ export default class ConsensusEngineId extends U32 {
|
||||
.reduce((result, char): number => (result * 256) + char.charCodeAt(0), 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if the engine matches abrs
|
||||
*/
|
||||
public get isAbrs (): boolean {
|
||||
return this.eq(CID_ABRS);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description `true` if the engine matches aura
|
||||
*/
|
||||
@@ -66,16 +58,6 @@ export default class ConsensusEngineId extends U32 {
|
||||
return this.eq(CID_GRPA);
|
||||
}
|
||||
|
||||
private getAbrsAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
|
||||
const pre = createType('RawAuraBorosPreDigest', bytes.toU8a(true));
|
||||
|
||||
return sessionValidators[
|
||||
pre.isBabe
|
||||
? pre.asBabe.authorityIndex.toNumber()
|
||||
: pre.asAura.slotNumber.modn(sessionValidators.length)
|
||||
];
|
||||
}
|
||||
|
||||
private getAuraAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
|
||||
return sessionValidators[
|
||||
createType('RawAuraPreDigest', bytes.toU8a(true))
|
||||
@@ -85,20 +67,20 @@ export default class ConsensusEngineId extends U32 {
|
||||
}
|
||||
|
||||
private getBabeAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
|
||||
return sessionValidators[
|
||||
createType('RawBabePreDigest', bytes.toU8a(true))
|
||||
.authorityIndex
|
||||
.toNumber()
|
||||
];
|
||||
const digest = createType('RawBabePreDigest', bytes.toU8a(true));
|
||||
|
||||
return sessionValidators[(
|
||||
digest.isPrimary
|
||||
? digest.asPrimary
|
||||
: digest.asSecondary
|
||||
).authorityIndex.toNumber()];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From the input bytes, decode into an author
|
||||
*/
|
||||
public extractAuthor (bytes: Bytes, sessionValidators: AccountId[]): AccountId {
|
||||
if (this.isAbrs) {
|
||||
return this.getAbrsAuthor(bytes, sessionValidators);
|
||||
} else if (this.isAura) {
|
||||
if (this.isAura) {
|
||||
return this.getAuraAuthor(bytes, sessionValidators);
|
||||
} else if (this.isBabe) {
|
||||
return this.getBabeAuthor(bytes, sessionValidators);
|
||||
|
||||
Reference in New Issue
Block a user