diff --git a/Blockchain/Sources/Blockchain/Types/ExtrinsicTickets.swift b/Blockchain/Sources/Blockchain/Types/ExtrinsicTickets.swift index 2a9ddbe8..f38f7e4a 100644 --- a/Blockchain/Sources/Blockchain/Types/ExtrinsicTickets.swift +++ b/Blockchain/Sources/Blockchain/Types/ExtrinsicTickets.swift @@ -3,15 +3,15 @@ import Utils public struct ExtrinsicTickets: Sendable { public struct TicketItem: Sendable { - public var ticketIndex: TicketIndex - public var proof: BandersnatchRintVRFProof + public var attempt: TicketIndex + public var signature: BandersnatchRintVRFProof public init( - ticketIndex: TicketIndex, - proof: BandersnatchRintVRFProof + attempt: TicketIndex, + signature: BandersnatchRintVRFProof ) { - self.ticketIndex = ticketIndex - self.proof = proof + self.attempt = attempt + self.signature = signature } } @@ -34,14 +34,14 @@ extension ExtrinsicTickets: Dummy { extension ExtrinsicTickets.TicketItem: ScaleCodec.Codable { public init(from decoder: inout some ScaleCodec.Decoder) throws { try self.init( - ticketIndex: decoder.decode(), - proof: decoder.decode() + attempt: decoder.decode(), + signature: decoder.decode() ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { - try encoder.encode(ticketIndex) - try encoder.encode(proof) + try encoder.encode(attempt) + try encoder.encode(signature) } } diff --git a/Blockchain/Sources/Blockchain/Types/Header.swift b/Blockchain/Sources/Blockchain/Types/Header.swift index 1c8e5dd6..0b138d59 100644 --- a/Blockchain/Sources/Blockchain/Types/Header.swift +++ b/Blockchain/Sources/Blockchain/Types/Header.swift @@ -3,21 +3,21 @@ import Utils public struct Header: Sendable { public struct EpochMarker: Sendable { - public var randomness: Data32 - public var keys: ConfigFixedSizeArray< + public var entropy: Data32 + public var validators: ConfigFixedSizeArray< BandersnatchPublicKey, ProtocolConfig.TotalNumberOfValidators > public init( - randomness: Data32, - keys: ConfigFixedSizeArray< + entropy: Data32, + validators: ConfigFixedSizeArray< BandersnatchPublicKey, ProtocolConfig.TotalNumberOfValidators > ) { - self.randomness = randomness - self.keys = keys + self.entropy = entropy + self.validators = validators } } @@ -140,14 +140,14 @@ extension Header: ScaleCodec.Encodable { extension Header.EpochMarker: ScaleCodec.Encodable { public init(withConfig config: ProtocolConfigRef, from decoder: inout some ScaleCodec.Decoder) throws { try self.init( - randomness: decoder.decode(), - keys: ConfigFixedSizeArray(withConfig: config, from: &decoder) + entropy: decoder.decode(), + validators: ConfigFixedSizeArray(withConfig: config, from: &decoder) ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { - try encoder.encode(randomness) - try encoder.encode(keys) + try encoder.encode(entropy) + try encoder.encode(validators) } } diff --git a/Blockchain/Sources/Blockchain/Types/SafroleState.swift b/Blockchain/Sources/Blockchain/Types/SafroleState.swift index 370e822b..1e949724 100644 --- a/Blockchain/Sources/Blockchain/Types/SafroleState.swift +++ b/Blockchain/Sources/Blockchain/Types/SafroleState.swift @@ -3,15 +3,15 @@ import Utils public struct SafroleState: Sendable { // γk - public var pendingValidators: ConfigFixedSizeArray< + public var nextValidators: ConfigFixedSizeArray< ValidatorKey, ProtocolConfig.TotalNumberOfValidators > // γz - public var epochRoot: BandersnatchRingVRFRoot + public var ticketsVerifierKey: BandersnatchRingVRFRoot // γs - public var slotSealerSeries: Either< + public var ticketsOrKeys: Either< ConfigFixedSizeArray< Ticket, ProtocolConfig.EpochLength @@ -23,18 +23,18 @@ public struct SafroleState: Sendable { > // γa - public var ticketAccumulator: ConfigLimitedSizeArray< + public var ticketsAccumulator: ConfigLimitedSizeArray< Ticket, ProtocolConfig.Int0, ProtocolConfig.EpochLength > public init( - pendingValidators: ConfigFixedSizeArray< + nextValidators: ConfigFixedSizeArray< ValidatorKey, ProtocolConfig.TotalNumberOfValidators >, - epochRoot: BandersnatchRingVRFRoot, - slotSealerSeries: Either< + ticketsVerifierKey: BandersnatchRingVRFRoot, + ticketsOrKeys: Either< ConfigFixedSizeArray< Ticket, ProtocolConfig.EpochLength @@ -44,16 +44,16 @@ public struct SafroleState: Sendable { ProtocolConfig.EpochLength > >, - ticketAccumulator: ConfigLimitedSizeArray< + ticketsAccumulator: ConfigLimitedSizeArray< Ticket, ProtocolConfig.Int0, ProtocolConfig.EpochLength > ) { - self.pendingValidators = pendingValidators - self.epochRoot = epochRoot - self.slotSealerSeries = slotSealerSeries - self.ticketAccumulator = ticketAccumulator + self.nextValidators = nextValidators + self.ticketsVerifierKey = ticketsVerifierKey + self.ticketsOrKeys = ticketsOrKeys + self.ticketsAccumulator = ticketsAccumulator } } @@ -61,10 +61,10 @@ extension SafroleState: Dummy { public typealias Config = ProtocolConfigRef public static func dummy(withConfig config: Config) -> SafroleState { SafroleState( - pendingValidators: ConfigFixedSizeArray(withConfig: config, defaultValue: ValidatorKey.dummy(withConfig: config)), - epochRoot: BandersnatchRingVRFRoot(), - slotSealerSeries: .right(ConfigFixedSizeArray(withConfig: config, defaultValue: BandersnatchPublicKey())), - ticketAccumulator: ConfigLimitedSizeArray(withConfig: config) + nextValidators: ConfigFixedSizeArray(withConfig: config, defaultValue: ValidatorKey.dummy(withConfig: config)), + ticketsVerifierKey: BandersnatchRingVRFRoot(), + ticketsOrKeys: .right(ConfigFixedSizeArray(withConfig: config, defaultValue: BandersnatchPublicKey())), + ticketsAccumulator: ConfigLimitedSizeArray(withConfig: config) ) } } @@ -72,21 +72,21 @@ extension SafroleState: Dummy { extension SafroleState: ScaleCodec.Encodable { public init(withConfig config: ProtocolConfigRef, from decoder: inout some ScaleCodec.Decoder) throws { try self.init( - pendingValidators: ConfigFixedSizeArray(withConfig: config, from: &decoder), - epochRoot: decoder.decode(), - slotSealerSeries: Either( + nextValidators: ConfigFixedSizeArray(withConfig: config, from: &decoder), + ticketsVerifierKey: decoder.decode(), + ticketsOrKeys: Either( from: &decoder, decodeLeft: { try ConfigFixedSizeArray(withConfig: config, from: &$0) }, decodeRight: { try ConfigFixedSizeArray(withConfig: config, from: &$0) } ), - ticketAccumulator: ConfigLimitedSizeArray(withConfig: config, from: &decoder) + ticketsAccumulator: ConfigLimitedSizeArray(withConfig: config, from: &decoder) ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { - try encoder.encode(pendingValidators) - try encoder.encode(epochRoot) - try encoder.encode(slotSealerSeries) - try encoder.encode(ticketAccumulator) + try encoder.encode(nextValidators) + try encoder.encode(ticketsVerifierKey) + try encoder.encode(ticketsOrKeys) + try encoder.encode(ticketsAccumulator) } } diff --git a/Blockchain/Sources/Blockchain/Types/Ticket.swift b/Blockchain/Sources/Blockchain/Types/Ticket.swift index 7e4d82a6..aa7bb19e 100644 --- a/Blockchain/Sources/Blockchain/Types/Ticket.swift +++ b/Blockchain/Sources/Blockchain/Types/Ticket.swift @@ -2,27 +2,27 @@ import ScaleCodec import Utils public struct Ticket: Sendable { - public var identifier: Data32 - public var entryIndex: TicketIndex + public var id: Data32 + public var attempt: TicketIndex } extension Ticket: Dummy { public typealias Config = ProtocolConfigRef public static func dummy(withConfig _: Config) -> Ticket { - Ticket(identifier: Data32(), entryIndex: 0) + Ticket(id: Data32(), attempt: 0) } } extension Ticket: ScaleCodec.Codable { public init(from decoder: inout some ScaleCodec.Decoder) throws { try self.init( - identifier: decoder.decode(), - entryIndex: decoder.decode() + id: decoder.decode(), + attempt: decoder.decode() ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { - try encoder.encode(identifier) - try encoder.encode(entryIndex) + try encoder.encode(id) + try encoder.encode(attempt) } } diff --git a/Blockchain/Sources/Blockchain/Types/ValidatorKey.swift b/Blockchain/Sources/Blockchain/Types/ValidatorKey.swift index 5e3421b6..102255ef 100644 --- a/Blockchain/Sources/Blockchain/Types/ValidatorKey.swift +++ b/Blockchain/Sources/Blockchain/Types/ValidatorKey.swift @@ -2,20 +2,20 @@ import ScaleCodec import Utils public struct ValidatorKey: Sendable { - public var bandersnatchKey: BandersnatchPublicKey - public var ed25519Key: Ed25519PublicKey - public var blsKey: BLSKey + public var bandersnatch: BandersnatchPublicKey + public var ed25519: Ed25519PublicKey + public var bls: BLSKey public var metadata: Data128 public init( - bandersnatchKey: BandersnatchPublicKey, - ed25519Key: Ed25519PublicKey, - blsKey: BLSKey, + bandersnatch: BandersnatchPublicKey, + ed25519: Ed25519PublicKey, + bls: BLSKey, metadata: Data128 ) { - self.bandersnatchKey = bandersnatchKey - self.ed25519Key = ed25519Key - self.blsKey = blsKey + self.bandersnatch = bandersnatch + self.ed25519 = ed25519 + self.bls = bls self.metadata = metadata } } @@ -24,9 +24,9 @@ extension ValidatorKey: Dummy { public typealias Config = ProtocolConfigRef public static func dummy(withConfig _: Config) -> ValidatorKey { ValidatorKey( - bandersnatchKey: BandersnatchPublicKey(), - ed25519Key: Ed25519PublicKey(), - blsKey: BLSKey(), + bandersnatch: BandersnatchPublicKey(), + ed25519: Ed25519PublicKey(), + bls: BLSKey(), metadata: Data128() ) } @@ -35,17 +35,17 @@ extension ValidatorKey: Dummy { extension ValidatorKey: ScaleCodec.Codable { public init(from decoder: inout some ScaleCodec.Decoder) throws { try self.init( - bandersnatchKey: decoder.decode(), - ed25519Key: decoder.decode(), - blsKey: decoder.decode(), + bandersnatch: decoder.decode(), + ed25519: decoder.decode(), + bls: decoder.decode(), metadata: decoder.decode() ) } public func encode(in encoder: inout some ScaleCodec.Encoder) throws { - try encoder.encode(bandersnatchKey) - try encoder.encode(ed25519Key) - try encoder.encode(blsKey) + try encoder.encode(bandersnatch) + try encoder.encode(ed25519) + try encoder.encode(bls) try encoder.encode(metadata) } } diff --git a/Blockchain/Sources/Blockchain/Types/primitives.swift b/Blockchain/Sources/Blockchain/Types/primitives.swift index e0055678..ee2ef32d 100644 --- a/Blockchain/Sources/Blockchain/Types/primitives.swift +++ b/Blockchain/Sources/Blockchain/Types/primitives.swift @@ -7,12 +7,12 @@ public typealias Gas = UInt64 public typealias DataLength = UInt32 public typealias ValidatorIndex = UInt32 // TODO: confirm this public typealias CoreIndex = UInt32 // TODO: confirm this -public typealias TicketIndex = UInt8 // TODO: confirm this +public typealias TicketIndex = UInt8 public typealias Ed25519PublicKey = Data32 public typealias Ed25519Signature = Data64 public typealias BandersnatchPublicKey = Data32 public typealias BandersnatchSignature = Data64 public typealias BandersnatchRintVRFProof = Data784 -public typealias BandersnatchRingVRFRoot = Data32 +public typealias BandersnatchRingVRFRoot = Data384 public typealias BLSKey = Data144 diff --git a/Utils/Sources/Utils/ConstValue.swift b/Utils/Sources/Utils/ConstValue.swift index 70a0d58f..fc30c9a2 100644 --- a/Utils/Sources/Utils/ConstValue.swift +++ b/Utils/Sources/Utils/ConstValue.swift @@ -67,6 +67,12 @@ public enum ConstUInt144: ConstInt { } } +public enum ConstUInt384: ConstInt { + public static var value: Int { + 384 + } +} + public enum ConstUInt784: ConstInt { public static var value: Int { 784 diff --git a/Utils/Sources/Utils/FixedSizeData.swift b/Utils/Sources/Utils/FixedSizeData.swift index 182110b3..bdf99dd3 100644 --- a/Utils/Sources/Utils/FixedSizeData.swift +++ b/Utils/Sources/Utils/FixedSizeData.swift @@ -43,4 +43,5 @@ public typealias Data64 = FixedSizeData public typealias Data96 = FixedSizeData public typealias Data128 = FixedSizeData public typealias Data144 = FixedSizeData +public typealias Data384 = FixedSizeData public typealias Data784 = FixedSizeData