Skip to content
Merged
Show file tree
Hide file tree
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
53 changes: 30 additions & 23 deletions packages/api-derive/src/staking/recentlyOffline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
);
}
184 changes: 119 additions & 65 deletions packages/types/src/Metadata/v7/latest.substrate.v7.json
Original file line number Diff line number Diff line change
Expand Up @@ -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."
]
}
]
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -1025,7 +1015,7 @@
"isLinked": true
}
},
"fallback": "0x0c00",
"fallback": "0x00",
"documentation": [
" The map from (wannabe) validator stash key to the preferences of that validator."
]
Expand Down Expand Up @@ -1134,54 +1124,54 @@
]
},
{
"name": "SlashCount",
"name": "ForceEra",
"modifier": "Default",
"type": {
"MapType": {
"hasher": "Blake2_256",
"key": "AccountId",
"value": "u32",
"isLinked": false
}
"PlainType": "Forcing"
},
"fallback": "0x00000000",
"fallback": "0x00",
"documentation": [
" The number of times a given validator has been reported offline. This gets decremented",
" by one each era that passes."
" True if the next session change will be a new era regardless of index."
]
},
{
"name": "RecentlyOffline",
"name": "SlashRewardFraction",
"modifier": "Default",
"type": {
"PlainType": "Vec<(AccountId,BlockNumber,u32)>"
"PlainType": "Perbill"
},
"fallback": "0x00",
"fallback": "0x00000000",
"documentation": [
" Most recent `RECENT_OFFLINE_COUNT` instances. (Who it was, when it was reported, how",
" many instances they were offline for)."
" The percentage of the slash that is distributed to reporters.",
"",
" The rest of the slashed value is handled by the `Slash`."
]
},
{
"name": "ForceEra",
"name": "BondedEras",
"modifier": "Default",
"type": {
"PlainType": "Forcing"
"PlainType": "Vec<(EraIndex,SessionIndex)>"
},
"fallback": "0x00",
"documentation": [
" True if the next session change will be a new era regardless of index."
" A mapping from still-bonded eras to the first session index of that era."
]
},
{
"name": "BondedEras",
"name": "EraSlashJournal",
"modifier": "Default",
"type": {
"PlainType": "Vec<(EraIndex,SessionIndex)>"
"MapType": {
"hasher": "Blake2_256",
"key": "EraIndex",
"value": "Vec<SlashJournalEntry>",
"isLinked": false
}
},
"fallback": "0x00",
"documentation": [
" A mapping from still-bonded eras to the first session index of that era."
" All slashes that have occurred in a given era."
]
}
]
Expand Down Expand Up @@ -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": [
Expand All @@ -1478,24 +1456,23 @@
]
},
{
"name": "OfflineWarning",
"name": "Slash",
"args": [
"AccountId",
"u32"
"Balance"
],
"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."
" One validator (and its nominators) has been slashed by the given amount."
]
},
{
"name": "OfflineSlash",
"name": "OldSlashingReportDiscarded",
"args": [
"AccountId",
"Balance"
"SessionIndex"
],
"documentation": [
" One validator (and its nominators) has been slashed by the given amount."
" An old slashing report from a prior era was discarded because it could",
" not be processed."
]
}
],
Expand Down Expand Up @@ -4355,7 +4332,7 @@
"type": "Heartbeat"
},
{
"name": "_signature",
"name": "signature",
"type": "AuthoritySignature"
}
],
Expand All @@ -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": []
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion packages/types/src/Metadata/v7/static.ts

Large diffs are not rendered by default.

32 changes: 30 additions & 2 deletions packages/types/src/interfaceRegistry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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>;
Expand Down Expand Up @@ -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>;
Expand Down
Loading