Skip to content

Commit

Permalink
Ordered accumulation updates (#222)
Browse files Browse the repository at this point in the history
* fix service accounts

* accumulate execution updates

* many state updates

* fix chainspec

* fix

* updated based on master branch changes

* fix lint

* integrate accumulate history and ready queue

* lint

* fix

* add coding as

* fix comment

* update submodule

* fix codec jam tests
  • Loading branch information
qiweiii authored Nov 12, 2024
1 parent e2ff014 commit 123f14d
Show file tree
Hide file tree
Showing 36 changed files with 870 additions and 440 deletions.
24 changes: 15 additions & 9 deletions Blockchain/Sources/Blockchain/Config/ProtocolConfig+Preset.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ extension Ref where T == ProtocolConfig {
preimagePurgePeriod: 28800,
epochLength: 6,
auditBiasFactor: 2,
coreAccumulationGas: Gas(10_000_000), // TODO: check this
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
workPackageRefineGas: Gas(10_000_000), // TODO: check this
coreAccumulationGas: Gas(100_000),
workPackageAuthorizerGas: Gas(1_000_000),
workPackageRefineGas: Gas(500_000_000),
totalAccumulationGas: Gas(341_000_000),
recentHistorySize: 8,
maxWorkItems: 4,
maxDepsInWorkReport: 8,
maxTicketsPerExtrinsic: 4,
maxLookupAnchorAge: 14400,
transferMemoSize: 128,
Expand Down Expand Up @@ -49,11 +51,13 @@ extension Ref where T == ProtocolConfig {
preimagePurgePeriod: 28800,
epochLength: 12,
auditBiasFactor: 2,
coreAccumulationGas: Gas(10_000_000), // TODO: check this
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
workPackageRefineGas: Gas(10_000_000), // TODO: check this
coreAccumulationGas: Gas(100_000),
workPackageAuthorizerGas: Gas(1_000_000),
workPackageRefineGas: Gas(500_000_000),
totalAccumulationGas: Gas(341_000_000),
recentHistorySize: 8,
maxWorkItems: 4,
maxDepsInWorkReport: 8,
maxTicketsPerExtrinsic: 16,
maxLookupAnchorAge: 14400,
transferMemoSize: 128,
Expand Down Expand Up @@ -86,11 +90,13 @@ extension Ref where T == ProtocolConfig {
preimagePurgePeriod: 28800,
epochLength: 600,
auditBiasFactor: 2,
coreAccumulationGas: Gas(10_000_000), // TODO: check this
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
workPackageRefineGas: Gas(10_000_000), // TODO: check this
coreAccumulationGas: Gas(100_000),
workPackageAuthorizerGas: Gas(1_000_000),
workPackageRefineGas: Gas(500_000_000),
totalAccumulationGas: Gas(341_000_000),
recentHistorySize: 8,
maxWorkItems: 4,
maxDepsInWorkReport: 8,
maxTicketsPerExtrinsic: 16,
maxLookupAnchorAge: 14400,
transferMemoSize: 128,
Expand Down
47 changes: 40 additions & 7 deletions Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,24 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
// GR: The total gas allocated for a work-package’s Refine logic.
public var workPackageRefineGas: Gas

// GT: The total gas allocated across all cores for Accumulation.
public var totalAccumulationGas: Gas

// H = 8: The size of recent history, in blocks.
public var recentHistorySize: Int

// I = 4: The maximum amount of work items in a package.
public var maxWorkItems: Int

// J = 8: The maximum sum of dependency items in a work-report.
public var maxDepsInWorkReport: Int

// K = 16: The maximum number of tickets which may be submitted in a single extrinsic.
public var maxTicketsPerExtrinsic: Int

// L = 14, 400: The maximum age in timeslots of the lookup anchor.
public var maxLookupAnchorAge: Int

// WT = 128: The size of a transfer memo in octets.
public var transferMemoSize: Int

// N = 2: The number of ticket entries per validator.
public var ticketEntriesPerValidator: Int

Expand All @@ -67,16 +70,16 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
// R = 10: The rotation period of validator-core assignments, in timeslots.
public var coreAssignmentRotationPeriod: Int

// S = 4,000,000: The maximum size of service code in octets.
public var maxServiceCodeSize: Int

// U = 5: The period in timeslots after which reported but unavailable work may be replaced.
public var preimageReplacementPeriod: Int

// V = 1023: The total number of validators.
public var totalNumberOfValidators: Int

// WC = 684: The basic size of our erasure-coded pieces.
// WC = 4,000,000: The maximum size of service code in octets.
public var maxServiceCodeSize: Int

// WE = 684: The basic size of our erasure-coded pieces.
public var erasureCodedPieceSize: Int

// WM = 2^11: The maximum number of entries in a work-package manifest.
Expand All @@ -92,6 +95,9 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
// WS = 6: The size of an exported segment in erasure-coded pieces.
public var erasureCodedSegmentSize: Int

// WT = 128: The size of a transfer memo in octets.
public var transferMemoSize: Int

// Y = 500: The number of slots into an epoch at which ticket-submission ends.
public var ticketSubmissionEndSlot: Int

Expand Down Expand Up @@ -119,8 +125,10 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
coreAccumulationGas: Gas,
workPackageAuthorizerGas: Gas,
workPackageRefineGas: Gas,
totalAccumulationGas: Gas,
recentHistorySize: Int,
maxWorkItems: Int,
maxDepsInWorkReport: Int,
maxTicketsPerExtrinsic: Int,
maxLookupAnchorAge: Int,
transferMemoSize: Int,
Expand Down Expand Up @@ -154,8 +162,10 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
self.coreAccumulationGas = coreAccumulationGas
self.workPackageAuthorizerGas = workPackageAuthorizerGas
self.workPackageRefineGas = workPackageRefineGas
self.totalAccumulationGas = totalAccumulationGas
self.recentHistorySize = recentHistorySize
self.maxWorkItems = maxWorkItems
self.maxDepsInWorkReport = maxDepsInWorkReport
self.maxTicketsPerExtrinsic = maxTicketsPerExtrinsic
self.maxLookupAnchorAge = maxLookupAnchorAge
self.transferMemoSize = transferMemoSize
Expand Down Expand Up @@ -215,9 +225,13 @@ extension ProtocolConfig {
? other.workPackageAuthorizerGas : workPackageAuthorizerGas,
workPackageRefineGas: other.workPackageRefineGas.value != 0
? other.workPackageRefineGas : workPackageRefineGas,
totalAccumulationGas: other.totalAccumulationGas.value != 0
? other.totalAccumulationGas : totalAccumulationGas,
recentHistorySize: other.recentHistorySize != 0
? other.recentHistorySize : recentHistorySize,
maxWorkItems: other.maxWorkItems != 0 ? other.maxWorkItems : maxWorkItems,
maxDepsInWorkReport: other.maxDepsInWorkReport != 0
? other.maxDepsInWorkReport : maxDepsInWorkReport,
maxTicketsPerExtrinsic: other.maxTicketsPerExtrinsic != 0
? other.maxTicketsPerExtrinsic : maxTicketsPerExtrinsic,
maxLookupAnchorAge: other.maxLookupAnchorAge != 0
Expand Down Expand Up @@ -295,8 +309,12 @@ extension ProtocolConfig {
workPackageRefineGas = try decode(
.workPackageRefineGas, defaultValue: Gas(0), required: required
)
totalAccumulationGas = try decode(
.totalAccumulationGas, defaultValue: Gas(0), required: required
)
recentHistorySize = try decode(.recentHistorySize, defaultValue: 0, required: required)
maxWorkItems = try decode(.maxWorkItems, defaultValue: 0, required: required)
maxDepsInWorkReport = try decode(.maxDepsInWorkReport, defaultValue: 0, required: required)
maxTicketsPerExtrinsic = try decode(
.maxTicketsPerExtrinsic, defaultValue: 0, required: required
)
Expand Down Expand Up @@ -434,6 +452,14 @@ extension ProtocolConfig {
}
}

public enum TotalAccumulationGas: ReadGas {
public typealias TConfig = ProtocolConfigRef
public typealias TOutput = Gas
public static func read(config: ProtocolConfigRef) -> Gas {
config.value.totalAccumulationGas
}
}

public enum RecentHistorySize: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
Expand All @@ -448,6 +474,13 @@ extension ProtocolConfig {
}
}

public enum MaxDepsInWorkReport: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
config.value.maxDepsInWorkReport
}
}

public enum MaxTicketsPerExtrinsic: ReadInt {
public typealias TConfig = ProtocolConfigRef
public static func read(config: ProtocolConfigRef) -> Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ import Foundation
import Utils

public struct AccumulateArguments: Codable {
/// o
public var result: WorkResult
/// l
public var paylaodHash: Data32
/// k
public var packageHash: Data32
/// a
public var authorizationOutput: Data

public init(result: WorkResult, paylaodHash: Data32, packageHash: Data32, authorizationOutput: Data) {
Expand Down Expand Up @@ -60,7 +64,7 @@ public struct AccumulateState {
/// X
public struct AccumlateResultContext {
/// d
public var serviceAccounts: [ServiceIndex: ServiceAccount]
public var serviceAccounts: ServiceAccounts
/// s: the accumulating service account index
public var serviceIndex: ServiceIndex
/// u
Expand All @@ -75,7 +79,7 @@ public protocol AccumulateFunction {
func invoke(
config: ProtocolConfigRef,
// prior accounts
accounts: ServiceAccounts,
accounts: inout some ServiceAccounts,
// u
state: AccumulateState,
// s
Expand Down
Loading

0 comments on commit 123f14d

Please sign in to comment.