From 34a8f2cfe932f800958ffcc44a8273fefe267c1a Mon Sep 17 00:00:00 2001 From: Xiliang Chen Date: Mon, 5 Aug 2024 20:07:23 +1200 Subject: [PATCH] update judgements (#50) --- .../Sources/Blockchain/Types/Extrinsic.swift | 10 +++--- ...udgement.swift => ExtrinsicDisputes.swift} | 32 +++++++++---------- .../Blockchain/Types/JudgementsState.swift | 32 +++++++++++-------- 3 files changed, 39 insertions(+), 35 deletions(-) rename Blockchain/Sources/Blockchain/Types/{ExtrinsicJudgement.swift => ExtrinsicDisputes.swift} (70%) diff --git a/Blockchain/Sources/Blockchain/Types/Extrinsic.swift b/Blockchain/Sources/Blockchain/Types/Extrinsic.swift index 4f87fb7e..4cee502f 100644 --- a/Blockchain/Sources/Blockchain/Types/Extrinsic.swift +++ b/Blockchain/Sources/Blockchain/Types/Extrinsic.swift @@ -6,8 +6,8 @@ public struct Extrinsic: Sendable, Equatable { // permissioning of block authoring public var tickets: ExtrinsicTickets - // EJ: Votes, by validators, on dispute(s) arising between them presently taking place - public var judgements: ExtrinsicJudgement + // ED: Votes, by validators, on dispute(s) arising between them presently taking place + public var judgements: ExtrinsicDisputes // EP: Static data which is presently being requested to be available for workloads to be able to fetch on demand public var preimages: ExtrinsicPreimages @@ -21,7 +21,7 @@ public struct Extrinsic: Sendable, Equatable { public init( tickets: ExtrinsicTickets, - judgements: ExtrinsicJudgement, + judgements: ExtrinsicDisputes, preimages: ExtrinsicPreimages, availability: ExtrinsicAvailability, reports: ExtrinsicGuarantees @@ -39,7 +39,7 @@ extension Extrinsic: Dummy { public static func dummy(config: Config) -> Extrinsic { Extrinsic( tickets: ExtrinsicTickets.dummy(config: config), - judgements: ExtrinsicJudgement.dummy(config: config), + judgements: ExtrinsicDisputes.dummy(config: config), preimages: ExtrinsicPreimages.dummy(config: config), availability: ExtrinsicAvailability.dummy(config: config), reports: ExtrinsicGuarantees.dummy(config: config) @@ -51,7 +51,7 @@ extension Extrinsic: ScaleCodec.Encodable { public init(config: ProtocolConfigRef, from decoder: inout some ScaleCodec.Decoder) throws { try self.init( tickets: ExtrinsicTickets(config: config, from: &decoder), - judgements: ExtrinsicJudgement(config: config, from: &decoder), + judgements: ExtrinsicDisputes(config: config, from: &decoder), preimages: decoder.decode(), availability: ExtrinsicAvailability(config: config, from: &decoder), reports: ExtrinsicGuarantees(config: config, from: &decoder) diff --git a/Blockchain/Sources/Blockchain/Types/ExtrinsicJudgement.swift b/Blockchain/Sources/Blockchain/Types/ExtrinsicDisputes.swift similarity index 70% rename from Blockchain/Sources/Blockchain/Types/ExtrinsicJudgement.swift rename to Blockchain/Sources/Blockchain/Types/ExtrinsicDisputes.swift index 2ce2c93f..68351026 100644 --- a/Blockchain/Sources/Blockchain/Types/ExtrinsicJudgement.swift +++ b/Blockchain/Sources/Blockchain/Types/ExtrinsicDisputes.swift @@ -1,17 +1,17 @@ import ScaleCodec import Utils -public struct ExtrinsicJudgement: Sendable, Equatable { - public struct JudgementItem: Sendable, Equatable { +public struct ExtrinsicDisputes: Sendable, Equatable { + public struct VerdictItem: Sendable, Equatable { public struct SignatureItem: Sendable, Equatable { public var isValid: Bool public var validatorIndex: ValidatorIndex - public var signature: BandersnatchSignature + public var signature: Ed25519Signature public init( isValid: Bool, validatorIndex: ValidatorIndex, - signature: BandersnatchSignature + signature: Ed25519Signature ) { self.isValid = isValid self.validatorIndex = validatorIndex @@ -37,37 +37,35 @@ public struct ExtrinsicJudgement: Sendable, Equatable { } } - public typealias JudgementsList = [JudgementItem] - - public var judgements: JudgementsList + public var verdicts: [VerdictItem] public init( - judgements: JudgementsList + verdicts: [VerdictItem] ) { - self.judgements = judgements + self.verdicts = verdicts } } -extension ExtrinsicJudgement: Dummy { +extension ExtrinsicDisputes: Dummy { public typealias Config = ProtocolConfigRef - public static func dummy(config _: Config) -> ExtrinsicJudgement { - ExtrinsicJudgement(judgements: []) + public static func dummy(config _: Config) -> ExtrinsicDisputes { + ExtrinsicDisputes(verdicts: []) } } -extension ExtrinsicJudgement: ScaleCodec.Encodable { +extension ExtrinsicDisputes: ScaleCodec.Encodable { public init(config: ProtocolConfigRef, from decoder: inout some ScaleCodec.Decoder) throws { try self.init( - judgements: decoder.decode(.array { try JudgementItem(config: config, from: &$0) }) + verdicts: decoder.decode(.array { try VerdictItem(config: config, from: &$0) }) ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { - try encoder.encode(judgements) + try encoder.encode(verdicts) } } -extension ExtrinsicJudgement.JudgementItem: ScaleCodec.Encodable { +extension ExtrinsicDisputes.VerdictItem: ScaleCodec.Encodable { public init(config: ProtocolConfigRef, from decoder: inout some ScaleCodec.Decoder) throws { try self.init( reportHash: decoder.decode(), @@ -81,7 +79,7 @@ extension ExtrinsicJudgement.JudgementItem: ScaleCodec.Encodable { } } -extension ExtrinsicJudgement.JudgementItem.SignatureItem: ScaleCodec.Codable { +extension ExtrinsicDisputes.VerdictItem.SignatureItem: ScaleCodec.Codable { public init(from decoder: inout some ScaleCodec.Decoder) throws { try self.init( isValid: decoder.decode(), diff --git a/Blockchain/Sources/Blockchain/Types/JudgementsState.swift b/Blockchain/Sources/Blockchain/Types/JudgementsState.swift index 989c1db2..1e1e1baf 100644 --- a/Blockchain/Sources/Blockchain/Types/JudgementsState.swift +++ b/Blockchain/Sources/Blockchain/Types/JudgementsState.swift @@ -2,24 +2,27 @@ import ScaleCodec import Utils public struct JudgementsState: Sendable, Equatable { - // ψa: The allow-set contains the hashes of all work-reports which were disputed and judged to be accurate. - public var allowSet: Set + // ψg: Work-reports judged to be correct + public var goodSet: Set - // ψb: The ban-set contains the hashes of all work-reports which were disputed and whose accuracy - // could not be confidently confirmed. + // ψb: Work-reports judged to be incorrect public var banSet: Set - // ψp; he punish-set is a set of keys of Bandersnatch keys which were found to have guaranteed - // a report which was confidently found to be invalid. - public var punishSet: Set + // ψw: Work-reports whose validity is judged to be unknowable + public var wonkySet: Set + + // ψo: Validators who made a judgement found to be incorrect + public var punishSet: Set public init( - allowSet: Set, + goodSet: Set, banSet: Set, - punishSet: Set + wonkySet: Set, + punishSet: Set ) { - self.allowSet = allowSet + self.goodSet = goodSet self.banSet = banSet + self.wonkySet = wonkySet self.punishSet = punishSet } } @@ -28,8 +31,9 @@ extension JudgementsState: Dummy { public typealias Config = ProtocolConfigRef public static func dummy(config _: Config) -> JudgementsState { JudgementsState( - allowSet: [], + goodSet: [], banSet: [], + wonkySet: [], punishSet: [] ) } @@ -38,15 +42,17 @@ extension JudgementsState: Dummy { extension JudgementsState: ScaleCodec.Codable { public init(from decoder: inout some ScaleCodec.Decoder) throws { try self.init( - allowSet: decoder.decode(), + goodSet: decoder.decode(), banSet: decoder.decode(), + wonkySet: decoder.decode(), punishSet: decoder.decode() ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { - try encoder.encode(allowSet) + try encoder.encode(goodSet) try encoder.encode(banSet) + try encoder.encode(wonkySet) try encoder.encode(punishSet) } }