Add additional types for offchain Phragmen (#2097)

* Add additional types for offchain Phragmen

* Trim down metadata toCallsOnly
This commit is contained in:
Jaco Greeff
2020-03-26 16:07:54 +01:00
committed by GitHub
parent 0906c7837a
commit a19928fef9
6 changed files with 335 additions and 15 deletions
@@ -2,16 +2,32 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { MetadataLatest } from '@polkadot/types/interfaces/metadata';
import { FunctionMetadataLatest, MetadataLatest } from '@polkadot/types/interfaces/metadata';
import { AnyJson, Registry } from '@polkadot/types/types';
import { Option, Text, Vec } from '@polkadot/types';
interface ModuleMetadataCallsOnly {
name: Text;
calls: FunctionMetadataLatest[];
}
function mapCalls (registry: Registry, calls: Option<Vec<FunctionMetadataLatest>>): FunctionMetadataLatest[] {
return calls.unwrapOr([] as FunctionMetadataLatest[]).map(({ args, documentation, name }) =>
registry.createType('FunctionMetadataLatest', {
args,
name,
documentation: documentation.map((doc) => doc.toString().trim())
})
);
}
/** @internal */
export default function toCallsOnly (registry: Registry, { extrinsic, modules }: MetadataLatest): AnyJson {
return registry.createType('MetadataLatest', {
// FIXME, this needs typing, not any
modules: modules.map(({ calls, name }): any => ({
modules: modules.map(({ calls, name }): ModuleMetadataCallsOnly => ({
name,
calls
calls: mapCalls(registry, calls)
})),
extrinsic
}).toJSON();
@@ -1928,7 +1928,7 @@
},
"fallback": "0x00",
"documentation": [
" True if the next session change will be a new era regardless of index."
" Mode of era forcing."
]
},
{
@@ -2065,6 +2065,77 @@
" The earliest era for which we have a pending, unapplied slash."
]
},
{
"name": "SnapshotValidators",
"modifier": "Optional",
"type": {
"Plain": "Vec<AccountId>"
},
"fallback": "0x00",
"documentation": [
" Snapshot of validators at the beginning of the current election window. This should only",
" have a value when [`EraElectionStatus`] == `ElectionStatus::Open(_)`."
]
},
{
"name": "SnapshotNominators",
"modifier": "Optional",
"type": {
"Plain": "Vec<AccountId>"
},
"fallback": "0x00",
"documentation": [
" Snapshot of nominators at the beginning of the current election window. This should only",
" have a value when [`EraElectionStatus`] == `ElectionStatus::Open(_)`."
]
},
{
"name": "QueuedElected",
"modifier": "Optional",
"type": {
"Plain": "ElectionResult"
},
"fallback": "0x00",
"documentation": [
" The next validator set. At the end of an era, if this is available (potentially from the",
" result of an offchain worker), it is immediately used. Otherwise, the on-chain election",
" is executed."
]
},
{
"name": "QueuedScore",
"modifier": "Optional",
"type": {
"Plain": "PhragmenScore"
},
"fallback": "0x00",
"documentation": [
" The score of the current [`QueuedElected`]."
]
},
{
"name": "EraElectionStatus",
"modifier": "Default",
"type": {
"Plain": "ElectionStatus"
},
"fallback": "0x00",
"documentation": [
" Flag to control the execution of the offchain election. When `Open(_)`, we accept",
" solutions to be submitted."
]
},
{
"name": "IsCurrentSessionFinal",
"modifier": "Default",
"type": {
"Plain": "bool"
},
"fallback": "0x00",
"documentation": [
" True if the current planned session is final."
]
},
{
"name": "StorageVersion",
"modifier": "Default",
@@ -2073,6 +2144,7 @@
},
"fallback": "0x02",
"documentation": [
" True if network has been upgraded to this version.",
" Storage version of the pallet.",
"",
" This is set to v3.0.0 for new networks."
@@ -2112,8 +2184,8 @@
" - O(1).",
" - Three extra DB entries.",
"",
" NOTE: Two of the storage writes (`Self::bonded`, `Self::payee`) are _never_ cleaned unless",
" the `origin` falls below _existential deposit_ and gets removed as dust.",
" NOTE: Two of the storage writes (`Self::bonded`, `Self::payee`) are _never_ cleaned",
" unless the `origin` falls below _existential deposit_ and gets removed as dust.",
" # </weight>"
]
},
@@ -2244,7 +2316,7 @@
"",
" # <weight>",
" - The transaction's complexity is proportional to the size of `targets`,",
" which is capped at `MAX_NOMINATIONS`.",
" which is capped at CompactAssignments::LIMIT.",
" - Both the reads and writes follow a similar pattern.",
" # </weight>"
]
@@ -2517,6 +2589,131 @@
"",
" - `stash`: The stash account to reap. Its balance must be zero."
]
},
{
"name": "submit_election_solution",
"args": [
{
"name": "winners",
"type": "Vec<ValidatorIndex>"
},
{
"name": "compact_assignments",
"type": "CompactAssignments"
},
{
"name": "score",
"type": "PhragmenScore"
},
{
"name": "era",
"type": "EraIndex"
}
],
"documentation": [
" Submit a phragmen result to the chain. If the solution:",
"",
" 1. is valid.",
" 2. has a better score than a potentially existing solution on chain.",
"",
" then, it will be _put_ on chain.",
"",
" A solution consists of two pieces of data:",
"",
" 1. `winners`: a flat vector of all the winners of the round.",
" 2. `assignments`: the compact version of an assignment vector that encodes the edge",
" weights.",
"",
" Both of which may be computed using [`phragmen`], or any other algorithm.",
"",
" Additionally, the submitter must provide:",
"",
" - The `score` that they claim their solution has.",
"",
" Both validators and nominators will be represented by indices in the solution. The",
" indices should respect the corresponding types ([`ValidatorIndex`] and",
" [`NominatorIndex`]). Moreover, they should be valid when used to index into",
" [`SnapshotValidators`] and [`SnapshotNominators`]. Any invalid index will cause the",
" solution to be rejected. These two storage items are set during the election window and",
" may be used to determine the indices.",
"",
" A solution is valid if:",
"",
" 0. It is submitted when [`EraElectionStatus`] is `Open`.",
" 1. Its claimed score is equal to the score computed on-chain.",
" 2. Presents the correct number of winners.",
" 3. All indexes must be value according to the snapshot vectors. All edge values must",
" also be correct and should not overflow the granularity of the ratio type (i.e. 256",
" or billion).",
" 4. For each edge, all targets are actually nominated by the voter.",
" 5. Has correct self-votes.",
"",
" A solutions score is consisted of 3 parameters:",
"",
" 1. `min { support.total }` for each support of a winner. This value should be maximized.",
" 2. `sum { support.total }` for each support of a winner. This value should be minimized.",
" 3. `sum { support.total^2 }` for each support of a winner. This value should be",
" minimized (to ensure less variance)",
"",
" # <weight>",
" E: number of edges. m: size of winner committee. n: number of nominators. d: edge degree",
" (16 for now) v: number of on-chain validator candidates.",
"",
" NOTE: given a solution which is reduced, we can enable a new check the ensure `|E| < n +",
" m`. We don't do this _yet_, but our offchain worker code executes it nonetheless.",
"",
" major steps (all done in `check_and_replace_solution`):",
"",
" - Storage: O(1) read `ElectionStatus`.",
" - Storage: O(1) read `PhragmenScore`.",
" - Storage: O(1) read `ValidatorCount`.",
" - Storage: O(1) length read from `SnapshotValidators`.",
"",
" - Storage: O(v) reads of `AccountId` to fetch `snapshot_validators`.",
" - Memory: O(m) iterations to map winner index to validator id.",
" - Storage: O(n) reads `AccountId` to fetch `snapshot_nominators`.",
" - Memory: O(n + m) reads to map index to `AccountId` for un-compact.",
"",
" - Storage: O(e) accountid reads from `Nomination` to read correct nominations.",
" - Storage: O(e) calls into `slashable_balance_of_extended` to convert ratio to staked.",
"",
" - Memory: build_support_map. O(e).",
" - Memory: evaluate_support: O(E).",
"",
" - Storage: O(e) writes to `QueuedElected`.",
" - Storage: O(1) write to `QueuedScore`",
"",
" The weight of this call is 1/10th of the blocks total weight.",
" # </weight>"
]
},
{
"name": "submit_election_solution_unsigned",
"args": [
{
"name": "winners",
"type": "Vec<ValidatorIndex>"
},
{
"name": "compact_assignments",
"type": "CompactAssignments"
},
{
"name": "score",
"type": "PhragmenScore"
},
{
"name": "era",
"type": "EraIndex"
}
],
"documentation": [
" Unsigned version of `submit_election_solution`.",
"",
" Note that this must pass the [`ValidateUnsigned`] check which only allows transactions",
" from the local node to be included. In other words, only the block author can include a",
" transaction in the block."
]
}
],
"events": [
@@ -2550,6 +2747,15 @@
" not be processed."
]
},
{
"name": "StakingElection",
"args": [
"ElectionCompute"
],
"documentation": [
" A new set of stakers was elected with the given computation method."
]
},
{
"name": "Bonded",
"args": [
@@ -2687,6 +2893,81 @@
"documentation": [
" Items are not sorted and unique."
]
},
{
"name": "PhragmenEarlySubmission",
"documentation": [
" The submitted result is received out of the open window."
]
},
{
"name": "PhragmenWeakSubmission",
"documentation": [
" The submitted result is not as good as the one stored on chain."
]
},
{
"name": "SnapshotUnavailable",
"documentation": [
" The snapshot data of the current window is missing."
]
},
{
"name": "PhragmenBogusWinnerCount",
"documentation": [
" Incorrect number of winners were presented."
]
},
{
"name": "PhragmenBogusWinner",
"documentation": [
" One of the submitted winners is not an active candidate on chain (index is out of range",
" in snapshot)."
]
},
{
"name": "PhragmenBogusCompact",
"documentation": [
" Error while building the assignment type from the compact. This can happen if an index",
" is invalid, or if the weights _overflow_."
]
},
{
"name": "PhragmenBogusNominator",
"documentation": [
" One of the submitted nominators is not an active nominator on chain."
]
},
{
"name": "PhragmenBogusNomination",
"documentation": [
" One of the submitted nominators has an edge to which they have not voted on chain."
]
},
{
"name": "PhragmenSlashedNomination",
"documentation": [
" One of the submitted nominators has an edge which is submitted before the last non-zero",
" slash of the target."
]
},
{
"name": "PhragmenBogusSelfVote",
"documentation": [
" A self vote must only be originated from a validator to ONLY themselves."
]
},
{
"name": "PhragmenBogusEdge",
"documentation": [
" The submitted result has unknown edges that are not among the presented winners."
]
},
{
"name": "PhragmenBogusScore",
"documentation": [
" The claimed score does not match with the one computed from the data."
]
}
]
},
@@ -6933,6 +7214,18 @@
" The primary structure that holds all offence records keyed by report identifiers."
]
},
{
"name": "DeferredOffences",
"modifier": "Default",
"type": {
"Plain": "Vec<DeferredOffenceOf>"
},
"fallback": "0x00",
"documentation": [
" Deferred reports that have been rejected by the offence handler and need to be submitted",
" at a later time."
]
},
{
"name": "ConcurrentReportsIndex",
"modifier": "Default",
@@ -6979,11 +7272,13 @@
"name": "Offence",
"args": [
"Kind",
"OpaqueTimeSlot"
"OpaqueTimeSlot",
"bool"
],
"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."
" (kind-specific) time slot. This event is not deposited for duplicate slashes. last",
" element indicates of the offence was applied (true) or queued (false)."
]
}
],
@@ -9188,7 +9483,8 @@
"CheckNonce",
"CheckWeight",
"ChargeTransactionPayment",
"CheckBlockGasLimit"
"CheckBlockGasLimit",
"LockStakingStatus"
]
}
}
File diff suppressed because one or more lines are too long
+4 -1
View File
@@ -25,7 +25,7 @@ import { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityJudgement
import { AuthIndex, AuthoritySignature, Heartbeat, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
import { CallMetadataV0, DoubleMapTypeLatest, DoubleMapTypeV10, DoubleMapTypeV11, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, DoubleMapTypeV9, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV8, ErrorMetadataV9, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV10, EventMetadataV11, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, FunctionMetadataV9, MapTypeLatest, MapTypeV0, MapTypeV10, MapTypeV11, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MapTypeV9, MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV10, MetadataV11, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, ModuleMetadataV9, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV10, PlainTypeV11, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, PlainTypeV9, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageEntryTypeV9, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV4, StorageHasherV5, StorageHasherV6, StorageHasherV7, StorageHasherV8, StorageHasherV9, StorageMetadataLatest, StorageMetadataV0, StorageMetadataV10, StorageMetadataV11, StorageMetadataV7, StorageMetadataV8, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
import { StorageKind } from '@polkadot/types/interfaces/offchain';
import { Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
import { DeferredOffenceOf, Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
import { AttestedCandidate, AuctionIndex, Bidder, CandidateReceipt, CollatorId, CollatorSignature, EgressQueueRoot, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, NewBidder, ParaId, ParaIdOf, ParaInfo, ParaScheduling, ParachainDispatchOrigin, Retriable, SlotRange, SubId, UpwardMessage, ValidityAttestation, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
import { RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
@@ -676,6 +676,9 @@ declare module '@polkadot/types/types/registry' {
OpaqueNetworkState: OpaqueNetworkState;
'Option<OpaqueNetworkState>': Option<OpaqueNetworkState>;
'Vec<OpaqueNetworkState>': Vec<OpaqueNetworkState>;
DeferredOffenceOf: DeferredOffenceOf;
'Option<DeferredOffenceOf>': Option<DeferredOffenceOf>;
'Vec<DeferredOffenceOf>': Vec<DeferredOffenceOf>;
Kind: Kind;
'Option<Kind>': Option<Kind>;
'Vec<Kind>': Vec<Kind>;
@@ -7,6 +7,7 @@ import { Definitions } from '../../types';
export default {
rpc: {},
types: {
DeferredOffenceOf: '(Vec<OffenceDetails>, Vec<Perbill>, SessionIndex)',
Kind: '[u8; 16]',
OffenceDetails: {
offender: 'Offender',
@@ -1,10 +1,14 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable */
import { ITuple } from '@polkadot/types/types';
import { Struct, U8aFixed, Vec } from '@polkadot/types/codec';
import { Bytes } from '@polkadot/types/primitive';
import { AccountId, Hash } from '@polkadot/types/interfaces/runtime';
import { IdentificationTuple } from '@polkadot/types/interfaces/session';
import { AccountId, Hash, Perbill } from '@polkadot/types/interfaces/runtime';
import { IdentificationTuple, SessionIndex } from '@polkadot/types/interfaces/session';
/** @name DeferredOffenceOf */
export interface DeferredOffenceOf extends ITuple<[Vec<OffenceDetails>, Vec<Perbill>, SessionIndex]> {}
/** @name Kind */
export interface Kind extends U8aFixed {}