Skip to content

Commit 40f9960

Browse files
jacogrian.he
authored andcommitted
Update types for offences (polkadot-js#1317)
* Update static (doc) metadata * Offences types (definitions & generated) * Optional recentlyOffline
1 parent 8062572 commit 40f9960

File tree

13 files changed

+259
-92
lines changed

13 files changed

+259
-92
lines changed

packages/api-derive/src/staking/recentlyOffline.ts

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,45 @@ import { AccountId, BlockNumber } from '@plugnet/types/interfaces';
66
import { Codec } from '@plugnet/types/types';
77

88
import BN from 'bn.js';
9-
import { Observable } from 'rxjs';
9+
import { Observable, of } from 'rxjs';
1010
import { map } from 'rxjs/operators';
1111
import { ApiInterfaceRx } from '@plugnet/api/types';
1212
import { DerivedRecentlyOffline } from '../types';
1313

1414
import { drr } from '../util/drr';
1515

16+
type OfflineResult = [AccountId, BlockNumber, BN][] & Codec;
17+
18+
function expandDerived (recentlyOffline: OfflineResult): DerivedRecentlyOffline {
19+
return recentlyOffline.reduce((result: DerivedRecentlyOffline, [accountId, blockNumber, count]): DerivedRecentlyOffline => {
20+
const key = accountId.toString();
21+
22+
if (!result[key]) {
23+
result[key] = [];
24+
}
25+
26+
result[key].push({
27+
blockNumber,
28+
count
29+
});
30+
31+
return result;
32+
}, {});
33+
}
34+
1635
/**
1736
* @description Retrieve a keyed record of accounts recently reported to be offline
1837
*/
1938
export function recentlyOffline (api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> {
2039
return (): Observable<DerivedRecentlyOffline> =>
21-
api.query.staking
22-
.recentlyOffline<[AccountId, BlockNumber, BN][] & Codec>()
23-
.pipe(
24-
map((recentlyOffline): DerivedRecentlyOffline =>
25-
recentlyOffline.reduce((result: DerivedRecentlyOffline, [accountId, blockNumber, count]): DerivedRecentlyOffline => {
26-
const key = accountId.toString();
27-
28-
if (!result[key]) {
29-
result[key] = [];
30-
}
31-
32-
result[key].push({
33-
blockNumber,
34-
count
35-
});
36-
37-
return result;
38-
},
39-
{})
40-
),
41-
drr()
42-
);
40+
(
41+
// TODO recentlyOffline has been dropped for 2.x and replaced, figure out the
42+
// replacement as actually use and implement it
43+
api.query.staking.recentlyOffline
44+
? api.query.staking.recentlyOffline<OfflineResult>()
45+
: of([] as unknown as OfflineResult)
46+
).pipe(
47+
map(expandDerived),
48+
drr()
49+
);
4350
}

packages/types/src/Metadata/v7/latest.substrate.v7.json

Lines changed: 119 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,18 @@
435435
},
436436
"fallback": "0x00",
437437
"documentation": []
438+
},
439+
{
440+
"name": "Initialized",
441+
"modifier": "Optional",
442+
"type": {
443+
"PlainType": "bool"
444+
},
445+
"fallback": "0x00",
446+
"documentation": [
447+
" Temporary value (cleared at block finalization) which is true",
448+
" if per-block initialization has already been called for current block."
449+
]
438450
}
439451
]
440452
},
@@ -931,28 +943,6 @@
931943
" Minimum number of staking participants before emergency conditions are imposed."
932944
]
933945
},
934-
{
935-
"name": "OfflineSlash",
936-
"modifier": "Default",
937-
"type": {
938-
"PlainType": "Perbill"
939-
},
940-
"fallback": "0x40420f00",
941-
"documentation": [
942-
" Slash, per validator that is taken for the first time they are found to be offline."
943-
]
944-
},
945-
{
946-
"name": "OfflineSlashGrace",
947-
"modifier": "Default",
948-
"type": {
949-
"PlainType": "u32"
950-
},
951-
"fallback": "0x00000000",
952-
"documentation": [
953-
" Number of instances of offline reports before slashing begins for validators."
954-
]
955-
},
956946
{
957947
"name": "Invulnerables",
958948
"modifier": "Default",
@@ -1025,7 +1015,7 @@
10251015
"isLinked": true
10261016
}
10271017
},
1028-
"fallback": "0x0c00",
1018+
"fallback": "0x00",
10291019
"documentation": [
10301020
" The map from (wannabe) validator stash key to the preferences of that validator."
10311021
]
@@ -1134,54 +1124,54 @@
11341124
]
11351125
},
11361126
{
1137-
"name": "SlashCount",
1127+
"name": "ForceEra",
11381128
"modifier": "Default",
11391129
"type": {
1140-
"MapType": {
1141-
"hasher": "Blake2_256",
1142-
"key": "AccountId",
1143-
"value": "u32",
1144-
"isLinked": false
1145-
}
1130+
"PlainType": "Forcing"
11461131
},
1147-
"fallback": "0x00000000",
1132+
"fallback": "0x00",
11481133
"documentation": [
1149-
" The number of times a given validator has been reported offline. This gets decremented",
1150-
" by one each era that passes."
1134+
" True if the next session change will be a new era regardless of index."
11511135
]
11521136
},
11531137
{
1154-
"name": "RecentlyOffline",
1138+
"name": "SlashRewardFraction",
11551139
"modifier": "Default",
11561140
"type": {
1157-
"PlainType": "Vec<(AccountId,BlockNumber,u32)>"
1141+
"PlainType": "Perbill"
11581142
},
1159-
"fallback": "0x00",
1143+
"fallback": "0x00000000",
11601144
"documentation": [
1161-
" Most recent `RECENT_OFFLINE_COUNT` instances. (Who it was, when it was reported, how",
1162-
" many instances they were offline for)."
1145+
" The percentage of the slash that is distributed to reporters.",
1146+
"",
1147+
" The rest of the slashed value is handled by the `Slash`."
11631148
]
11641149
},
11651150
{
1166-
"name": "ForceEra",
1151+
"name": "BondedEras",
11671152
"modifier": "Default",
11681153
"type": {
1169-
"PlainType": "Forcing"
1154+
"PlainType": "Vec<(EraIndex,SessionIndex)>"
11701155
},
11711156
"fallback": "0x00",
11721157
"documentation": [
1173-
" True if the next session change will be a new era regardless of index."
1158+
" A mapping from still-bonded eras to the first session index of that era."
11741159
]
11751160
},
11761161
{
1177-
"name": "BondedEras",
1162+
"name": "EraSlashJournal",
11781163
"modifier": "Default",
11791164
"type": {
1180-
"PlainType": "Vec<(EraIndex,SessionIndex)>"
1165+
"MapType": {
1166+
"hasher": "Blake2_256",
1167+
"key": "EraIndex",
1168+
"value": "Vec<SlashJournalEntry>",
1169+
"isLinked": false
1170+
}
11811171
},
11821172
"fallback": "0x00",
11831173
"documentation": [
1184-
" A mapping from still-bonded eras to the first session index of that era."
1174+
" All slashes that have occurred in a given era."
11851175
]
11861176
}
11871177
]
@@ -1442,18 +1432,6 @@
14421432
" # </weight>"
14431433
]
14441434
},
1445-
{
1446-
"name": "set_offline_slash_grace",
1447-
"args": [
1448-
{
1449-
"name": "new",
1450-
"type": "Compact<u32>"
1451-
}
1452-
],
1453-
"documentation": [
1454-
" Set the offline slash grace period."
1455-
]
1456-
},
14571435
{
14581436
"name": "set_invulnerables",
14591437
"args": [
@@ -1478,24 +1456,23 @@
14781456
]
14791457
},
14801458
{
1481-
"name": "OfflineWarning",
1459+
"name": "Slash",
14821460
"args": [
14831461
"AccountId",
1484-
"u32"
1462+
"Balance"
14851463
],
14861464
"documentation": [
1487-
" One validator (and its nominators) has been given an offline-warning (it is still",
1488-
" within its grace). The accrued number of slashes is recorded, too."
1465+
" One validator (and its nominators) has been slashed by the given amount."
14891466
]
14901467
},
14911468
{
1492-
"name": "OfflineSlash",
1469+
"name": "OldSlashingReportDiscarded",
14931470
"args": [
1494-
"AccountId",
1495-
"Balance"
1471+
"SessionIndex"
14961472
],
14971473
"documentation": [
1498-
" One validator (and its nominators) has been slashed by the given amount."
1474+
" An old slashing report from a prior era was discarded because it could",
1475+
" not be processed."
14991476
]
15001477
}
15011478
],
@@ -4355,7 +4332,7 @@
43554332
"type": "Heartbeat"
43564333
},
43574334
{
4358-
"name": "_signature",
4335+
"name": "signature",
43594336
"type": "AuthoritySignature"
43604337
}
43614338
],
@@ -4374,6 +4351,83 @@
43744351
}
43754352
],
43764353
"constants": []
4354+
},
4355+
{
4356+
"name": "Offences",
4357+
"storage": {
4358+
"prefix": "Offences",
4359+
"items": [
4360+
{
4361+
"name": "Reports",
4362+
"modifier": "Optional",
4363+
"type": {
4364+
"MapType": {
4365+
"hasher": "Blake2_256",
4366+
"key": "ReportIdOf",
4367+
"value": "OffenceDetails",
4368+
"isLinked": false
4369+
}
4370+
},
4371+
"fallback": "0x00",
4372+
"documentation": [
4373+
" The primary structure that holds all offence records keyed by report identifiers."
4374+
]
4375+
},
4376+
{
4377+
"name": "ConcurrentReportsIndex",
4378+
"modifier": "Default",
4379+
"type": {
4380+
"DoubleMapType": {
4381+
"hasher": "Blake2_256",
4382+
"key1": "Kind",
4383+
"key2": "OpaqueTimeSlot",
4384+
"value": "Vec<ReportIdOf>",
4385+
"key2Hasher": "Blake2_256"
4386+
}
4387+
},
4388+
"fallback": "0x00",
4389+
"documentation": [
4390+
" A vector of reports of the same kind that happened at the same time slot."
4391+
]
4392+
},
4393+
{
4394+
"name": "ReportsByKindIndex",
4395+
"modifier": "Default",
4396+
"type": {
4397+
"MapType": {
4398+
"hasher": "Blake2_256",
4399+
"key": "Kind",
4400+
"value": "Bytes",
4401+
"isLinked": false
4402+
}
4403+
},
4404+
"fallback": "0x00",
4405+
"documentation": [
4406+
" Enumerates all reports of a kind along with the time they happened.",
4407+
"",
4408+
" All reports are sorted by the time of offence.",
4409+
"",
4410+
" Note that the actual type of this mapping is `Vec<u8>`, this is because values of",
4411+
" different types are not supported at the moment so we are doing the manual serialization."
4412+
]
4413+
}
4414+
]
4415+
},
4416+
"calls": [],
4417+
"events": [
4418+
{
4419+
"name": "Offence",
4420+
"args": [
4421+
"Kind",
4422+
"OpaqueTimeSlot"
4423+
],
4424+
"documentation": [
4425+
" There is an offence reported of the given `kind` happened at the `session_index` and",
4426+
" (kind-specific) time slot. This event is not deposited for duplicate slashes."
4427+
]
4428+
}
4429+
],
4430+
"constants": []
43774431
}
43784432
]
43794433
}

packages/types/src/Metadata/v7/static.ts

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

packages/types/src/interfaceRegistry.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ import { ApprovalFlag, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } fro
1717
import { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from './interfaces/genericAsset';
1818
import { AuthorityWeight, NextAuthority, PendingPause, PendingResume, StoredPendingChange, StoredState } from './interfaces/grandpa';
1919
import { AuthIndex, AuthoritySignature, Heartbeat, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from './interfaces/imOnline';
20-
import { Keys, SessionIndex, SessionKeysPolkadot, SessionKeysSubstrate } from './interfaces/session';
21-
import { EraIndex, EraRewards, Exposure, Forcing, IndividualExposure, MomentOf, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from './interfaces/staking';
20+
import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from './interfaces/offences';
21+
import { FullIdentification, IdentificationTuple, Keys, SessionIndex, SessionKeysPolkadot, SessionKeysSubstrate } from './interfaces/session';
22+
import { EraIndex, EraRewards, Exposure, Forcing, IndividualExposure, MomentOf, RewardDestination, SlashJournalEntry, StakingLedger, UnlockChunk, ValidatorPrefs } from './interfaces/staking';
2223
import { DigestOf, Event, EventId, EventIndex, EventRecord, EventRecord0to76, Key, Phase } from './interfaces/system';
2324
import { TreasuryProposal } from './interfaces/treasury';
2425
import { BlockAttestations, IncludedBlocks, MoreAttestations } from './interfaces/attestations';
@@ -460,6 +461,30 @@ export interface InterfaceRegistry {
460461
OpaqueNetworkState: OpaqueNetworkState;
461462
'Option<OpaqueNetworkState>': Option<OpaqueNetworkState>;
462463
'Vec<OpaqueNetworkState>': Vec<OpaqueNetworkState>;
464+
Kind: Kind;
465+
'Option<Kind>': Option<Kind>;
466+
'Vec<Kind>': Vec<Kind>;
467+
OffenceDetails: OffenceDetails;
468+
'Option<OffenceDetails>': Option<OffenceDetails>;
469+
'Vec<OffenceDetails>': Vec<OffenceDetails>;
470+
Offender: Offender;
471+
'Option<Offender>': Option<Offender>;
472+
'Vec<Offender>': Vec<Offender>;
473+
OpaqueTimeSlot: OpaqueTimeSlot;
474+
'Option<OpaqueTimeSlot>': Option<OpaqueTimeSlot>;
475+
'Vec<OpaqueTimeSlot>': Vec<OpaqueTimeSlot>;
476+
ReportIdOf: ReportIdOf;
477+
'Option<ReportIdOf>': Option<ReportIdOf>;
478+
'Vec<ReportIdOf>': Vec<ReportIdOf>;
479+
Reporter: Reporter;
480+
'Option<Reporter>': Option<Reporter>;
481+
'Vec<Reporter>': Vec<Reporter>;
482+
FullIdentification: FullIdentification;
483+
'Option<FullIdentification>': Option<FullIdentification>;
484+
'Vec<FullIdentification>': Vec<FullIdentification>;
485+
IdentificationTuple: IdentificationTuple;
486+
'Option<IdentificationTuple>': Option<IdentificationTuple>;
487+
'Vec<IdentificationTuple>': Vec<IdentificationTuple>;
463488
SessionIndex: SessionIndex;
464489
'Compact<SessionIndex>': Compact<SessionIndex>;
465490
'Option<SessionIndex>': Option<SessionIndex>;
@@ -495,6 +520,9 @@ export interface InterfaceRegistry {
495520
RewardDestination: RewardDestination;
496521
'Option<RewardDestination>': Option<RewardDestination>;
497522
'Vec<RewardDestination>': Vec<RewardDestination>;
523+
SlashJournalEntry: SlashJournalEntry;
524+
'Option<SlashJournalEntry>': Option<SlashJournalEntry>;
525+
'Vec<SlashJournalEntry>': Vec<SlashJournalEntry>;
498526
StakingLedger: StakingLedger;
499527
'Option<StakingLedger>': Option<StakingLedger>;
500528
'Vec<StakingLedger>': Vec<StakingLedger>;

0 commit comments

Comments
 (0)