Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions Blockchain/Sources/Blockchain/Config/ProtocolConfig+Preset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 4,
maxAuthorizationsQueueItems: 10,
coreAssignmentRotationPeriod: 6,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -84,7 +84,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 10,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -128,7 +128,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 4,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -172,7 +172,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 4,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -216,7 +216,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 4,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -260,7 +260,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 4,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -304,7 +304,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 4,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -348,7 +348,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 4,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -392,7 +392,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 4,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down Expand Up @@ -436,7 +436,7 @@ extension Ref where T == ProtocolConfig {
slotPeriodSeconds: 6,
maxAuthorizationsQueueItems: 80,
coreAssignmentRotationPeriod: 10,
maxAccumulationQueueItems: 1024,
minPublicServiceIndex: 1 << 16,
maxWorkPackageExtrinsics: 128,
maxIsAuthorizedCodeSize: 64000,
maxServiceCodeSize: 4_000_000,
Expand Down
22 changes: 11 additions & 11 deletions Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
/// R = 10: The rotation period of validator-core assignments, in timeslots.
public var coreAssignmentRotationPeriod: Int

/// S = 1024: The maximum number of entries in the accumulation queue.
public var maxAccumulationQueueItems: Int
/// S = 2^16: The minimum public service index. Services of indices below these may only be created by the Registrar.
public var minPublicServiceIndex: Int

/// T = 128: The maximum number of extrinsics in a work-package.
public var maxWorkPackageExtrinsics: Int
Expand Down Expand Up @@ -152,7 +152,7 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
slotPeriodSeconds: Int,
maxAuthorizationsQueueItems: Int,
coreAssignmentRotationPeriod: Int,
maxAccumulationQueueItems: Int,
minPublicServiceIndex: Int,
maxWorkPackageExtrinsics: Int,
maxIsAuthorizedCodeSize: Int,
maxServiceCodeSize: Int,
Expand Down Expand Up @@ -194,7 +194,7 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
self.slotPeriodSeconds = slotPeriodSeconds
self.maxAuthorizationsQueueItems = maxAuthorizationsQueueItems
self.coreAssignmentRotationPeriod = coreAssignmentRotationPeriod
self.maxAccumulationQueueItems = maxAccumulationQueueItems
self.minPublicServiceIndex = minPublicServiceIndex
self.maxWorkPackageExtrinsics = maxWorkPackageExtrinsics
self.maxIsAuthorizedCodeSize = maxIsAuthorizedCodeSize
self.maxServiceCodeSize = maxServiceCodeSize
Expand Down Expand Up @@ -273,8 +273,8 @@ extension ProtocolConfig {
? other.maxAuthorizationsQueueItems : maxAuthorizationsQueueItems,
coreAssignmentRotationPeriod: other.coreAssignmentRotationPeriod != 0
? other.coreAssignmentRotationPeriod : coreAssignmentRotationPeriod,
maxAccumulationQueueItems: other.maxAccumulationQueueItems != 0
? other.maxAccumulationQueueItems : maxAccumulationQueueItems,
minPublicServiceIndex: other.minPublicServiceIndex != 0
? other.minPublicServiceIndex : minPublicServiceIndex,
maxWorkPackageExtrinsics: other.maxWorkPackageExtrinsics != 0
? other.maxWorkPackageExtrinsics : maxWorkPackageExtrinsics,
maxIsAuthorizedCodeSize: other.maxIsAuthorizedCodeSize != 0
Expand Down Expand Up @@ -367,8 +367,8 @@ extension ProtocolConfig {
coreAssignmentRotationPeriod = try decode(
.coreAssignmentRotationPeriod, defaultValue: 0, required: required
)
maxAccumulationQueueItems = try decode(
.maxAccumulationQueueItems, defaultValue: 0, required: required
minPublicServiceIndex = try decode(
.minPublicServiceIndex, defaultValue: 0, required: required
)
maxWorkPackageExtrinsics = try decode(
.maxWorkPackageExtrinsics, defaultValue: 0, required: required
Expand Down Expand Up @@ -582,10 +582,10 @@ extension ProtocolConfig {
}
}

public enum MaxAccumulationQueueItems: ReadInt {
public enum MinPublicServiceIndex: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
config.value.maxAccumulationQueueItems
config.value.minPublicServiceIndex
}
}

Expand Down Expand Up @@ -812,7 +812,7 @@ extension ProtocolConfig {
slotPeriodSeconds: Int(slotPeriodSeconds),
maxAuthorizationsQueueItems: Int(maxAuthorizationsQueueItems),
coreAssignmentRotationPeriod: Int(coreAssignmentRotationPeriod),
maxAccumulationQueueItems: 1024, // S = 1024
minPublicServiceIndex: 1 << 16, // S = 2^16
maxWorkPackageExtrinsics: Int(maxWorkPackageExtrinsics),
maxIsAuthorizedCodeSize: Int(maxIsAuthorizedCodeSize),
maxServiceCodeSize: Int(maxServiceCodeSize),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import Codec
import Foundation
import Utils

// wrangled operand tuple
public struct OperandTuple: Codable {
public struct OperandTuple: Codable, Sendable {
/// p
public var packageHash: Data32
/// e
Expand Down Expand Up @@ -41,6 +40,61 @@ public struct DeferredTransfers: Codable, Sendable {
}
}

public struct AccumulationInput: Sendable, Codable {
public enum InputType: Sendable, Equatable {
case operandTuple
case deferredTransfers
}

public var inputType: InputType
public var operandTuple: OperandTuple?
public var deferredTransfers: DeferredTransfers?

public init(operandTuple: OperandTuple) {
inputType = .operandTuple
self.operandTuple = operandTuple
}

public init(deferredTransfers: DeferredTransfers) {
inputType = .deferredTransfers
self.deferredTransfers = deferredTransfers
}

// Encodable
public func encode(to encoder: Encoder) throws {
var container = encoder.unkeyedContainer()
switch inputType {
case .operandTuple:
try container.encode(UInt(0))
try container.encode(operandTuple.unwrap())
case .deferredTransfers:
try container.encode(UInt(1))
try container.encode(deferredTransfers.unwrap())
}
}

// Decodable
public init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
let variant = try container.decode(UInt.self)
switch variant {
case 0:
let operandTuple = try container.decode(OperandTuple.self)
self.init(operandTuple: operandTuple)
case 1:
let deferredTransfers = try container.decode(DeferredTransfers.self)
self.init(deferredTransfers: deferredTransfers)
default:
throw DecodingError.dataCorrupted(
DecodingError.Context(
codingPath: decoder.codingPath,
debugDescription: "Invalid AccumulationInput variant: \(variant)"
)
)
}
}
}

/// Characterization (i.e. values capable of representing) of state components
/// which are both needed and mutable by the accumulation process.
public struct AccumulateState: Sendable {
Expand All @@ -64,6 +118,8 @@ public struct AccumulateState: Sendable {
public var assigners: ConfigFixedSizeArray<ServiceIndex, ProtocolConfig.TotalNumberOfCores>
// v
public var delegator: ServiceIndex
// r
public var registrar: ServiceIndex
// z
public var alwaysAcc: [ServiceIndex: Gas]

Expand All @@ -77,13 +133,14 @@ public struct AccumulateState: Sendable {
manager: manager,
assigners: assigners,
delegator: delegator,
registrar: registrar,
alwaysAcc: alwaysAcc,
entropy: entropy
)
}
}

public class AccumlateResultContext {
public class AccumulateResultContext {
/// s: the accumulating service account index
public var serviceIndex: ServiceIndex
/// u
Expand Down
Loading