Skip to content

Commit

Permalink
update judgements (#50)
Browse files Browse the repository at this point in the history
  • Loading branch information
xlc authored Aug 5, 2024
1 parent 31277d2 commit 34a8f2c
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 35 deletions.
10 changes: 5 additions & 5 deletions Blockchain/Sources/Blockchain/Types/Extrinsic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -21,7 +21,7 @@ public struct Extrinsic: Sendable, Equatable {

public init(
tickets: ExtrinsicTickets,
judgements: ExtrinsicJudgement,
judgements: ExtrinsicDisputes,
preimages: ExtrinsicPreimages,
availability: ExtrinsicAvailability,
reports: ExtrinsicGuarantees
Expand All @@ -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)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
32 changes: 19 additions & 13 deletions Blockchain/Sources/Blockchain/Types/JudgementsState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Data32>
// ψg: Work-reports judged to be correct
public var goodSet: Set<Data32>

// ψ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<Data32>

// ψ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<BandersnatchPublicKey>
// ψw: Work-reports whose validity is judged to be unknowable
public var wonkySet: Set<Data32>

// ψo: Validators who made a judgement found to be incorrect
public var punishSet: Set<Ed25519PublicKey>

public init(
allowSet: Set<Data32>,
goodSet: Set<Data32>,
banSet: Set<Data32>,
punishSet: Set<BandersnatchPublicKey>
wonkySet: Set<Data32>,
punishSet: Set<Ed25519PublicKey>
) {
self.allowSet = allowSet
self.goodSet = goodSet
self.banSet = banSet
self.wonkySet = wonkySet
self.punishSet = punishSet
}
}
Expand All @@ -28,8 +31,9 @@ extension JudgementsState: Dummy {
public typealias Config = ProtocolConfigRef
public static func dummy(config _: Config) -> JudgementsState {
JudgementsState(
allowSet: [],
goodSet: [],
banSet: [],
wonkySet: [],
punishSet: []
)
}
Expand All @@ -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)
}
}

0 comments on commit 34a8f2c

Please sign in to comment.