1+ import Codec
12import Utils
23
34public enum AccumulationError : Error {
@@ -7,7 +8,7 @@ public enum AccumulationError: Error {
78
89public struct AccumulationQueueItem : Sendable , Equatable , Codable {
910 public var workReport : WorkReport
10- public var dependencies : Set < Data32 >
11+ @ CodingAs < SortedSet < Data32 > > public var dependencies : Set < Data32 >
1112
1213 public init ( workReport: WorkReport , dependencies: Set < Data32 > ) {
1314 self . workReport = workReport
@@ -68,7 +69,6 @@ public protocol Accumulation: ServiceAccounts {
6869 > ,
6970 ProtocolConfig . TotalNumberOfCores
7071 > { get }
71- var entropyPool : EntropyPool { get }
7272 var accumlateFunction : AccumulateFunction { get }
7373 var onTransferFunction : OnTransferFunction { get }
7474 var accumulationQueue : StateKeys . AccumulationQueueKey . Value { get }
@@ -82,8 +82,9 @@ extension Accumulation {
8282 state: AccumulateState ,
8383 workReports: [ WorkReport ] ,
8484 service: ServiceIndex ,
85- block: BlockRef ,
86- privilegedGas: [ ServiceIndex : Gas ]
85+ privilegedGas: [ ServiceIndex : Gas ] ,
86+ entropy: Data32 ,
87+ timeslot: TimeslotIndex
8788 ) async throws -> SingleAccumulationOutput {
8889 var gas = Gas ( 0 )
8990 var arguments : [ AccumulateArguments ] = [ ]
@@ -111,9 +112,8 @@ extension Accumulation {
111112 serviceIndex: service,
112113 gas: gas,
113114 arguments: arguments,
114- initialIndex: Blake2b256 . hash ( service. encode ( ) , entropyPool. t0. data, block. header. timeslot. encode ( ) )
115- . data. decode ( UInt32 . self) ,
116- timeslot: block. header. timeslot
115+ initialIndex: Blake2b256 . hash ( service. encode ( ) , entropy. data, timeslot. encode ( ) ) . data. decode ( UInt32 . self) ,
116+ timeslot: timeslot
117117 )
118118
119119 return SingleAccumulationOutput (
@@ -127,10 +127,11 @@ extension Accumulation {
127127 /// parallelized accumulate function ∆*
128128 private mutating func parallelizedAccumulate(
129129 config: ProtocolConfigRef ,
130- block: BlockRef ,
131130 state: AccumulateState ,
132131 workReports: [ WorkReport ] ,
133- privilegedGas: [ ServiceIndex : Gas ]
132+ privilegedGas: [ ServiceIndex : Gas ] ,
133+ entropy: Data32 ,
134+ timeslot: TimeslotIndex
134135 ) async throws -> ParallelAccumulationOutput {
135136 var services = Set < ServiceIndex > ( )
136137 var gasUsed = Gas ( 0 )
@@ -165,8 +166,9 @@ extension Accumulation {
165166 state: state,
166167 workReports: workReports,
167168 service: service,
168- block: block,
169- privilegedGas: privilegedGas
169+ privilegedGas: privilegedGas,
170+ entropy: entropy,
171+ timeslot: timeslot
170172 )
171173 gasUsed += singleOutput. gasUsed
172174
@@ -214,11 +216,12 @@ extension Accumulation {
214216 /// outer accumulate function ∆+
215217 private mutating func outerAccumulate(
216218 config: ProtocolConfigRef ,
217- block: BlockRef ,
218219 state: AccumulateState ,
219220 workReports: [ WorkReport ] ,
220221 privilegedGas: [ ServiceIndex : Gas ] ,
221- gasLimit: Gas
222+ gasLimit: Gas ,
223+ entropy: Data32 ,
224+ timeslot: TimeslotIndex
222225 ) async throws -> AccumulationOutput {
223226 var i = 0
224227 var sumGasRequired = Gas ( 0 )
@@ -242,18 +245,20 @@ extension Accumulation {
242245 } else {
243246 let parallelOutput = try await parallelizedAccumulate (
244247 config: config,
245- block: block,
246248 state: state,
247249 workReports: Array ( workReports [ 0 ..< i] ) ,
248- privilegedGas: privilegedGas
250+ privilegedGas: privilegedGas,
251+ entropy: entropy,
252+ timeslot: timeslot
249253 )
250254 let outerOutput = try await outerAccumulate (
251255 config: config,
252- block: block,
253256 state: parallelOutput. state,
254257 workReports: Array ( workReports [ i ..< workReports. count] ) ,
255258 privilegedGas: [ : ] ,
256- gasLimit: gasLimit - parallelOutput. gasUsed
259+ gasLimit: gasLimit - parallelOutput. gasUsed,
260+ entropy: entropy,
261+ timeslot: timeslot
257262 )
258263 return AccumulationOutput (
259264 numAccumulated: i + outerOutput. numAccumulated,
@@ -305,7 +310,7 @@ extension Accumulation {
305310
306311 editAccumulatedItems (
307312 items: & newQueueItems,
308- accumulatedPackages: Set ( history. array. reduce ( into: Set < Data32 > ( ) ) { $0. formUnion ( $1) } )
313+ accumulatedPackages: Set ( history. array. reduce ( into: Set < Data32 > ( ) ) { $0. formUnion ( $1. array ) } )
309314 )
310315
311316 return ( zeroPrereqReports, newQueueItems)
@@ -328,16 +333,16 @@ extension Accumulation {
328333
329334 public mutating func update(
330335 config: ProtocolConfigRef ,
331- block: BlockRef ,
332- workReports: [ WorkReport ]
336+ workReports: [ WorkReport ] ,
337+ entropy: Data32 ,
338+ timeslot: TimeslotIndex
333339 ) async throws -> ( numAccumulated: Int , state: AccumulateState , commitments: Set < Commitment > ) {
334340 let sumPrevilegedGas = privilegedServices. basicGas. values. reduce ( Gas ( 0 ) ) { $0 + $1. value }
335341 let minTotalGas = config. value. workReportAccumulationGas * Gas( config. value. totalNumberOfCores) + sumPrevilegedGas
336342 let gasLimit = max ( config. value. totalAccumulationGas, minTotalGas)
337343
338344 let res = try await outerAccumulate (
339345 config: config,
340- block: block,
341346 state: AccumulateState (
342347 newServiceAccounts: [ : ] ,
343348 validatorQueue: validatorQueue,
@@ -346,7 +351,9 @@ extension Accumulation {
346351 ) ,
347352 workReports: workReports,
348353 privilegedGas: privilegedServices. basicGas,
349- gasLimit: gasLimit
354+ gasLimit: gasLimit,
355+ entropy: entropy,
356+ timeslot: timeslot
350357 )
351358
352359 var transferGroups = [ ServiceIndex: [ DeferredTransfers] ] ( )
0 commit comments