Skip to content

Commit 123f14d

Browse files
authored
Ordered accumulation updates (#222)
* 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
1 parent e2ff014 commit 123f14d

36 files changed

+870
-440
lines changed

Blockchain/Sources/Blockchain/Config/ProtocolConfig+Preset.swift

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,13 @@ extension Ref where T == ProtocolConfig {
1111
preimagePurgePeriod: 28800,
1212
epochLength: 6,
1313
auditBiasFactor: 2,
14-
coreAccumulationGas: Gas(10_000_000), // TODO: check this
15-
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
16-
workPackageRefineGas: Gas(10_000_000), // TODO: check this
14+
coreAccumulationGas: Gas(100_000),
15+
workPackageAuthorizerGas: Gas(1_000_000),
16+
workPackageRefineGas: Gas(500_000_000),
17+
totalAccumulationGas: Gas(341_000_000),
1718
recentHistorySize: 8,
1819
maxWorkItems: 4,
20+
maxDepsInWorkReport: 8,
1921
maxTicketsPerExtrinsic: 4,
2022
maxLookupAnchorAge: 14400,
2123
transferMemoSize: 128,
@@ -49,11 +51,13 @@ extension Ref where T == ProtocolConfig {
4951
preimagePurgePeriod: 28800,
5052
epochLength: 12,
5153
auditBiasFactor: 2,
52-
coreAccumulationGas: Gas(10_000_000), // TODO: check this
53-
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
54-
workPackageRefineGas: Gas(10_000_000), // TODO: check this
54+
coreAccumulationGas: Gas(100_000),
55+
workPackageAuthorizerGas: Gas(1_000_000),
56+
workPackageRefineGas: Gas(500_000_000),
57+
totalAccumulationGas: Gas(341_000_000),
5558
recentHistorySize: 8,
5659
maxWorkItems: 4,
60+
maxDepsInWorkReport: 8,
5761
maxTicketsPerExtrinsic: 16,
5862
maxLookupAnchorAge: 14400,
5963
transferMemoSize: 128,
@@ -86,11 +90,13 @@ extension Ref where T == ProtocolConfig {
8690
preimagePurgePeriod: 28800,
8791
epochLength: 600,
8892
auditBiasFactor: 2,
89-
coreAccumulationGas: Gas(10_000_000), // TODO: check this
90-
workPackageAuthorizerGas: Gas(10_000_000), // TODO: check this
91-
workPackageRefineGas: Gas(10_000_000), // TODO: check this
93+
coreAccumulationGas: Gas(100_000),
94+
workPackageAuthorizerGas: Gas(1_000_000),
95+
workPackageRefineGas: Gas(500_000_000),
96+
totalAccumulationGas: Gas(341_000_000),
9297
recentHistorySize: 8,
9398
maxWorkItems: 4,
99+
maxDepsInWorkReport: 8,
94100
maxTicketsPerExtrinsic: 16,
95101
maxLookupAnchorAge: 14400,
96102
transferMemoSize: 128,

Blockchain/Sources/Blockchain/Config/ProtocolConfig.swift

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,21 +37,24 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
3737
// GR: The total gas allocated for a work-package’s Refine logic.
3838
public var workPackageRefineGas: Gas
3939

40+
// GT: The total gas allocated across all cores for Accumulation.
41+
public var totalAccumulationGas: Gas
42+
4043
// H = 8: The size of recent history, in blocks.
4144
public var recentHistorySize: Int
4245

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

49+
// J = 8: The maximum sum of dependency items in a work-report.
50+
public var maxDepsInWorkReport: Int
51+
4652
// K = 16: The maximum number of tickets which may be submitted in a single extrinsic.
4753
public var maxTicketsPerExtrinsic: Int
4854

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

52-
// WT = 128: The size of a transfer memo in octets.
53-
public var transferMemoSize: Int
54-
5558
// N = 2: The number of ticket entries per validator.
5659
public var ticketEntriesPerValidator: Int
5760

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

70-
// S = 4,000,000: The maximum size of service code in octets.
71-
public var maxServiceCodeSize: Int
72-
7373
// U = 5: The period in timeslots after which reported but unavailable work may be replaced.
7474
public var preimageReplacementPeriod: Int
7575

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

79-
// WC = 684: The basic size of our erasure-coded pieces.
79+
// WC = 4,000,000: The maximum size of service code in octets.
80+
public var maxServiceCodeSize: Int
81+
82+
// WE = 684: The basic size of our erasure-coded pieces.
8083
public var erasureCodedPieceSize: Int
8184

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

98+
// WT = 128: The size of a transfer memo in octets.
99+
public var transferMemoSize: Int
100+
95101
// Y = 500: The number of slots into an epoch at which ticket-submission ends.
96102
public var ticketSubmissionEndSlot: Int
97103

@@ -119,8 +125,10 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
119125
coreAccumulationGas: Gas,
120126
workPackageAuthorizerGas: Gas,
121127
workPackageRefineGas: Gas,
128+
totalAccumulationGas: Gas,
122129
recentHistorySize: Int,
123130
maxWorkItems: Int,
131+
maxDepsInWorkReport: Int,
124132
maxTicketsPerExtrinsic: Int,
125133
maxLookupAnchorAge: Int,
126134
transferMemoSize: Int,
@@ -154,8 +162,10 @@ public struct ProtocolConfig: Sendable, Codable, Equatable {
154162
self.coreAccumulationGas = coreAccumulationGas
155163
self.workPackageAuthorizerGas = workPackageAuthorizerGas
156164
self.workPackageRefineGas = workPackageRefineGas
165+
self.totalAccumulationGas = totalAccumulationGas
157166
self.recentHistorySize = recentHistorySize
158167
self.maxWorkItems = maxWorkItems
168+
self.maxDepsInWorkReport = maxDepsInWorkReport
159169
self.maxTicketsPerExtrinsic = maxTicketsPerExtrinsic
160170
self.maxLookupAnchorAge = maxLookupAnchorAge
161171
self.transferMemoSize = transferMemoSize
@@ -215,9 +225,13 @@ extension ProtocolConfig {
215225
? other.workPackageAuthorizerGas : workPackageAuthorizerGas,
216226
workPackageRefineGas: other.workPackageRefineGas.value != 0
217227
? other.workPackageRefineGas : workPackageRefineGas,
228+
totalAccumulationGas: other.totalAccumulationGas.value != 0
229+
? other.totalAccumulationGas : totalAccumulationGas,
218230
recentHistorySize: other.recentHistorySize != 0
219231
? other.recentHistorySize : recentHistorySize,
220232
maxWorkItems: other.maxWorkItems != 0 ? other.maxWorkItems : maxWorkItems,
233+
maxDepsInWorkReport: other.maxDepsInWorkReport != 0
234+
? other.maxDepsInWorkReport : maxDepsInWorkReport,
221235
maxTicketsPerExtrinsic: other.maxTicketsPerExtrinsic != 0
222236
? other.maxTicketsPerExtrinsic : maxTicketsPerExtrinsic,
223237
maxLookupAnchorAge: other.maxLookupAnchorAge != 0
@@ -295,8 +309,12 @@ extension ProtocolConfig {
295309
workPackageRefineGas = try decode(
296310
.workPackageRefineGas, defaultValue: Gas(0), required: required
297311
)
312+
totalAccumulationGas = try decode(
313+
.totalAccumulationGas, defaultValue: Gas(0), required: required
314+
)
298315
recentHistorySize = try decode(.recentHistorySize, defaultValue: 0, required: required)
299316
maxWorkItems = try decode(.maxWorkItems, defaultValue: 0, required: required)
317+
maxDepsInWorkReport = try decode(.maxDepsInWorkReport, defaultValue: 0, required: required)
300318
maxTicketsPerExtrinsic = try decode(
301319
.maxTicketsPerExtrinsic, defaultValue: 0, required: required
302320
)
@@ -434,6 +452,14 @@ extension ProtocolConfig {
434452
}
435453
}
436454

455+
public enum TotalAccumulationGas: ReadGas {
456+
public typealias TConfig = ProtocolConfigRef
457+
public typealias TOutput = Gas
458+
public static func read(config: ProtocolConfigRef) -> Gas {
459+
config.value.totalAccumulationGas
460+
}
461+
}
462+
437463
public enum RecentHistorySize: ReadInt {
438464
public typealias TConfig = ProtocolConfigRef
439465
public static func read(config: ProtocolConfigRef) -> Int {
@@ -448,6 +474,13 @@ extension ProtocolConfig {
448474
}
449475
}
450476

477+
public enum MaxDepsInWorkReport: ReadInt {
478+
public typealias TConfig = ProtocolConfigRef
479+
public static func read(config: ProtocolConfigRef) -> Int {
480+
config.value.maxDepsInWorkReport
481+
}
482+
}
483+
451484
public enum MaxTicketsPerExtrinsic: ReadInt {
452485
public typealias TConfig = ProtocolConfigRef
453486
public static func read(config: ProtocolConfigRef) -> Int {

Blockchain/Sources/Blockchain/RuntimeProtocols/AccumulateFunction.swift

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@ import Foundation
22
import Utils
33

44
public struct AccumulateArguments: Codable {
5+
/// o
56
public var result: WorkResult
7+
/// l
68
public var paylaodHash: Data32
9+
/// k
710
public var packageHash: Data32
11+
/// a
812
public var authorizationOutput: Data
913

1014
public init(result: WorkResult, paylaodHash: Data32, packageHash: Data32, authorizationOutput: Data) {
@@ -60,7 +64,7 @@ public struct AccumulateState {
6064
/// X
6165
public struct AccumlateResultContext {
6266
/// d
63-
public var serviceAccounts: [ServiceIndex: ServiceAccount]
67+
public var serviceAccounts: ServiceAccounts
6468
/// s: the accumulating service account index
6569
public var serviceIndex: ServiceIndex
6670
/// u
@@ -75,7 +79,7 @@ public protocol AccumulateFunction {
7579
func invoke(
7680
config: ProtocolConfigRef,
7781
// prior accounts
78-
accounts: ServiceAccounts,
82+
accounts: inout some ServiceAccounts,
7983
// u
8084
state: AccumulateState,
8185
// s

0 commit comments

Comments
 (0)