Update types for offences (#1317)

* Update static (doc) metadata

* Offences types (definitions & generated)

* Optional recentlyOffline
This commit is contained in:
Jaco Greeff
2019-08-17 10:45:18 +02:00
committed by GitHub
parent 9f2785ad8a
commit 35a296037a
13 changed files with 271 additions and 104 deletions
@@ -6,38 +6,45 @@ import { AccountId, BlockNumber } from '@polkadot/types/interfaces';
import { Codec } from '@polkadot/types/types';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { DerivedRecentlyOffline } from '../types';
import { drr } from '../util/drr';
type OfflineResult = [AccountId, BlockNumber, BN][] & Codec;
function expandDerived (recentlyOffline: OfflineResult): DerivedRecentlyOffline {
return recentlyOffline.reduce((result: DerivedRecentlyOffline, [accountId, blockNumber, count]): DerivedRecentlyOffline => {
const key = accountId.toString();
if (!result[key]) {
result[key] = [];
}
result[key].push({
blockNumber,
count
});
return result;
}, {});
}
/**
* @description Retrieve a keyed record of accounts recently reported to be offline
*/
export function recentlyOffline (api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> {
return (): Observable<DerivedRecentlyOffline> =>
api.query.staking
.recentlyOffline<[AccountId, BlockNumber, BN][] & Codec>()
.pipe(
map((recentlyOffline): DerivedRecentlyOffline =>
recentlyOffline.reduce((result: DerivedRecentlyOffline, [accountId, blockNumber, count]): DerivedRecentlyOffline => {
const key = accountId.toString();
if (!result[key]) {
result[key] = [];
}
result[key].push({
blockNumber,
count
});
return result;
},
{})
),
drr()
);
(
// TODO recentlyOffline has been dropped for 2.x and replaced, figure out the
// replacement as actually use and implement it
api.query.staking.recentlyOffline
? api.query.staking.recentlyOffline<OfflineResult>()
: of([] as unknown as OfflineResult)
).pipe(
map(expandDerived),
drr()
);
}
@@ -435,6 +435,18 @@
},
"fallback": "0x00",
"documentation": []
},
{
"name": "Initialized",
"modifier": "Optional",
"type": {
"PlainType": "bool"
},
"fallback": "0x00",
"documentation": [
" Temporary value (cleared at block finalization) which is true",
" if per-block initialization has already been called for current block."
]
}
]
},
@@ -931,28 +943,6 @@
" Minimum number of staking participants before emergency conditions are imposed."
]
},
{
"name": "OfflineSlash",
"modifier": "Default",
"type": {
"PlainType": "Perbill"
},
"fallback": "0x40420f00",
"documentation": [
" Slash, per validator that is taken for the first time they are found to be offline."
]
},
{
"name": "OfflineSlashGrace",
"modifier": "Default",
"type": {
"PlainType": "u32"
},
"fallback": "0x00000000",
"documentation": [
" Number of instances of offline reports before slashing begins for validators."
]
},
{
"name": "Invulnerables",
"modifier": "Default",
@@ -1025,7 +1015,7 @@
"isLinked": true
}
},
"fallback": "0x0c00",
"fallback": "0x00",
"documentation": [
" The map from (wannabe) validator stash key to the preferences of that validator."
]
@@ -1133,35 +1123,6 @@
" This is used to derive rewards and punishments."
]
},
{
"name": "SlashCount",
"modifier": "Default",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "AccountId",
"value": "u32",
"isLinked": false
}
},
"fallback": "0x00000000",
"documentation": [
" The number of times a given validator has been reported offline. This gets decremented",
" by one each era that passes."
]
},
{
"name": "RecentlyOffline",
"modifier": "Default",
"type": {
"PlainType": "Vec<(AccountId,BlockNumber,u32)>"
},
"fallback": "0x00",
"documentation": [
" Most recent `RECENT_OFFLINE_COUNT` instances. (Who it was, when it was reported, how",
" many instances they were offline for)."
]
},
{
"name": "ForceEra",
"modifier": "Default",
@@ -1173,6 +1134,19 @@
" True if the next session change will be a new era regardless of index."
]
},
{
"name": "SlashRewardFraction",
"modifier": "Default",
"type": {
"PlainType": "Perbill"
},
"fallback": "0x00000000",
"documentation": [
" The percentage of the slash that is distributed to reporters.",
"",
" The rest of the slashed value is handled by the `Slash`."
]
},
{
"name": "BondedEras",
"modifier": "Default",
@@ -1183,6 +1157,22 @@
"documentation": [
" A mapping from still-bonded eras to the first session index of that era."
]
},
{
"name": "EraSlashJournal",
"modifier": "Default",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "EraIndex",
"value": "Vec<SlashJournalEntry>",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": [
" All slashes that have occurred in a given era."
]
}
]
},
@@ -1442,18 +1432,6 @@
" # </weight>"
]
},
{
"name": "set_offline_slash_grace",
"args": [
{
"name": "new",
"type": "Compact<u32>"
}
],
"documentation": [
" Set the offline slash grace period."
]
},
{
"name": "set_invulnerables",
"args": [
@@ -1478,18 +1456,7 @@
]
},
{
"name": "OfflineWarning",
"args": [
"AccountId",
"u32"
],
"documentation": [
" One validator (and its nominators) has been given an offline-warning (it is still",
" within its grace). The accrued number of slashes is recorded, too."
]
},
{
"name": "OfflineSlash",
"name": "Slash",
"args": [
"AccountId",
"Balance"
@@ -1497,6 +1464,16 @@
"documentation": [
" One validator (and its nominators) has been slashed by the given amount."
]
},
{
"name": "OldSlashingReportDiscarded",
"args": [
"SessionIndex"
],
"documentation": [
" An old slashing report from a prior era was discarded because it could",
" not be processed."
]
}
],
"constants": [
@@ -4355,7 +4332,7 @@
"type": "Heartbeat"
},
{
"name": "_signature",
"name": "signature",
"type": "AuthoritySignature"
}
],
@@ -4374,6 +4351,83 @@
}
],
"constants": []
},
{
"name": "Offences",
"storage": {
"prefix": "Offences",
"items": [
{
"name": "Reports",
"modifier": "Optional",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "ReportIdOf",
"value": "OffenceDetails",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": [
" The primary structure that holds all offence records keyed by report identifiers."
]
},
{
"name": "ConcurrentReportsIndex",
"modifier": "Default",
"type": {
"DoubleMapType": {
"hasher": "Blake2_256",
"key1": "Kind",
"key2": "OpaqueTimeSlot",
"value": "Vec<ReportIdOf>",
"key2Hasher": "Blake2_256"
}
},
"fallback": "0x00",
"documentation": [
" A vector of reports of the same kind that happened at the same time slot."
]
},
{
"name": "ReportsByKindIndex",
"modifier": "Default",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "Kind",
"value": "Bytes",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": [
" Enumerates all reports of a kind along with the time they happened.",
"",
" All reports are sorted by the time of offence.",
"",
" Note that the actual type of this mapping is `Vec<u8>`, this is because values of",
" different types are not supported at the moment so we are doing the manual serialization."
]
}
]
},
"calls": [],
"events": [
{
"name": "Offence",
"args": [
"Kind",
"OpaqueTimeSlot"
],
"documentation": [
" There is an offence reported of the given `kind` happened at the `session_index` and",
" (kind-specific) time slot. This event is not deposited for duplicate slashes."
]
}
],
"constants": []
}
]
}
File diff suppressed because one or more lines are too long
+30 -2
View File
@@ -17,8 +17,9 @@ import { ApprovalFlag, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } fro
import { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from './interfaces/genericAsset';
import { AuthorityWeight, NextAuthority, PendingPause, PendingResume, StoredPendingChange, StoredState } from './interfaces/grandpa';
import { AuthIndex, AuthoritySignature, Heartbeat, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from './interfaces/imOnline';
import { Keys, SessionIndex, SessionKeysPolkadot, SessionKeysSubstrate } from './interfaces/session';
import { EraIndex, EraRewards, Exposure, Forcing, IndividualExposure, MomentOf, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from './interfaces/staking';
import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from './interfaces/offences';
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeysPolkadot, SessionKeysSubstrate } from './interfaces/session';
import { EraIndex, EraRewards, Exposure, Forcing, IndividualExposure, MomentOf, RewardDestination, SlashJournalEntry, StakingLedger, UnlockChunk, ValidatorPrefs } from './interfaces/staking';
import { DigestOf, Event, EventId, EventIndex, EventRecord, EventRecord0to76, Key, Phase } from './interfaces/system';
import { TreasuryProposal } from './interfaces/treasury';
import { BlockAttestations, IncludedBlocks, MoreAttestations } from './interfaces/attestations';
@@ -460,6 +461,30 @@ export interface InterfaceRegistry {
OpaqueNetworkState: OpaqueNetworkState;
'Option<OpaqueNetworkState>': Option<OpaqueNetworkState>;
'Vec<OpaqueNetworkState>': Vec<OpaqueNetworkState>;
Kind: Kind;
'Option<Kind>': Option<Kind>;
'Vec<Kind>': Vec<Kind>;
OffenceDetails: OffenceDetails;
'Option<OffenceDetails>': Option<OffenceDetails>;
'Vec<OffenceDetails>': Vec<OffenceDetails>;
Offender: Offender;
'Option<Offender>': Option<Offender>;
'Vec<Offender>': Vec<Offender>;
OpaqueTimeSlot: OpaqueTimeSlot;
'Option<OpaqueTimeSlot>': Option<OpaqueTimeSlot>;
'Vec<OpaqueTimeSlot>': Vec<OpaqueTimeSlot>;
ReportIdOf: ReportIdOf;
'Option<ReportIdOf>': Option<ReportIdOf>;
'Vec<ReportIdOf>': Vec<ReportIdOf>;
Reporter: Reporter;
'Option<Reporter>': Option<Reporter>;
'Vec<Reporter>': Vec<Reporter>;
FullIdentification: FullIdentification;
'Option<FullIdentification>': Option<FullIdentification>;
'Vec<FullIdentification>': Vec<FullIdentification>;
IdentificationTuple: IdentificationTuple;
'Option<IdentificationTuple>': Option<IdentificationTuple>;
'Vec<IdentificationTuple>': Vec<IdentificationTuple>;
SessionIndex: SessionIndex;
'Compact<SessionIndex>': Compact<SessionIndex>;
'Option<SessionIndex>': Option<SessionIndex>;
@@ -495,6 +520,9 @@ export interface InterfaceRegistry {
RewardDestination: RewardDestination;
'Option<RewardDestination>': Option<RewardDestination>;
'Vec<RewardDestination>': Vec<RewardDestination>;
SlashJournalEntry: SlashJournalEntry;
'Option<SlashJournalEntry>': Option<SlashJournalEntry>;
'Vec<SlashJournalEntry>': Vec<SlashJournalEntry>;
StakingLedger: StakingLedger;
'Option<StakingLedger>': Option<StakingLedger>;
'Vec<StakingLedger>': Vec<StakingLedger>;
@@ -19,6 +19,7 @@ export { default as elections } from './elections/definitions';
export { default as genericAsset } from './genericAsset/definitions';
export { default as grandpa } from './grandpa/definitions';
export { default as imOnline } from './imOnline/definitions';
export { default as offences } from './offences/definitions';
export { default as session } from './session/definitions';
export { default as staking } from './staking/definitions';
export { default as system } from './system/definitions';
@@ -0,0 +1,17 @@
// 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: {
Kind: '[u8; 16]',
OffenceDetails: {
offender: 'Offender',
reporters: 'Vec<Reporter>'
},
Offender: 'IdentificationTuple',
OpaqueTimeSlot: 'Bytes',
ReportIdOf: 'Hash',
Reporter: 'AccountId'
}
};
@@ -0,0 +1,4 @@
// Auto-generated via `yarn build:interfaces`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
export * from './types';
@@ -0,0 +1,31 @@
// Auto-generated via `yarn build:interfaces`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Codec } from '../../types';
import { Struct, Vec } from '../../codec';
import { Bytes } from '../../primitive';
import { AccountId, Hash } from '../runtime';
import { IdentificationTuple } from '../session';
/** Uint8Array & Codec */
export type Kind = Uint8Array & Codec;
/** Struct */
export interface OffenceDetails extends Struct {
/** Offender */
readonly offender: Offender;
/** Vec<Reporter> */
readonly reporters: Vec<Reporter>;
}
/** IdentificationTuple */
export type Offender = IdentificationTuple;
/** Bytes */
export type OpaqueTimeSlot = Bytes;
/** AccountId */
export type Reporter = AccountId;
/** Hash */
export type ReportIdOf = Hash;
@@ -4,6 +4,8 @@
export default {
types: {
FullIdentification: 'Exposure',
IdentificationTuple: '(ValidatorId, FullIdentification)',
SessionIndex: 'u32',
// The runtime definition of SessionKeys are passes as a Trait to session
@@ -3,7 +3,14 @@
import { Codec } from '../../types';
import { u32 } from '../../primitive';
import { AccountId } from '../runtime';
import { AccountId, ValidatorId } from '../runtime';
import { Exposure } from '../staking';
/** Exposure */
export type FullIdentification = Exposure;
/** [ValidatorId, FullIdentification] & Codec */
export type IdentificationTuple = [ValidatorId, FullIdentification] & Codec;
/** SessionKeysSubstrate */
export type Keys = SessionKeysSubstrate;
@@ -33,6 +33,11 @@ export default {
'Controller'
]
},
SlashJournalEntry: {
who: 'AccountId',
amount: 'Balance',
ownSlash: 'Balance'
},
StakingLedger: {
stash: 'AccountId',
total: 'Compact<Balance>',
@@ -57,6 +57,16 @@ export interface RewardDestination extends Enum {
readonly isController: boolean;
}
/** Struct */
export interface SlashJournalEntry extends Struct {
/** AccountId */
readonly who: AccountId;
/** Balance */
readonly amount: Balance;
/** Balance */
readonly ownSlash: Balance;
}
/** Struct */
export interface StakingLedger extends Struct {
/** AccountId */
+1
View File
@@ -15,6 +15,7 @@ export * from './elections/types';
export * from './genericAsset/types';
export * from './grandpa/types';
export * from './imOnline/types';
export * from './offences/types';
export * from './session/types';
export * from './staking/types';
export * from './system/types';