@@ -22,190 +22,190 @@ private enum StateLayerValue: Sendable {
2222}
2323
2424// @unchecked because AnyHashable is not Sendable
25- public struct StateLayer : @ unchecked Sendable {
26- private var changes : [ AnyHashable : StateLayerValue ] = [ : ]
25+ public struct StateLayer : Sendable {
26+ private var changes : [ Data32 : StateLayerValue ] = [ : ]
2727
2828 public init ( backend: StateBackend ) async throws {
2929 let results = try await backend. batchRead ( StateKeys . prefetchKeys)
3030
3131 for (key, value) in results {
32- changes [ AnyHashable ( key) ] = try . init( value. unwrap ( ) )
32+ changes [ key. encode ( ) ] = try . init( value. unwrap ( ) )
3333 }
3434 }
3535
3636 public init ( changes: [ ( key: any StateKey , value: Codable & Sendable ) ] ) {
3737 for (key, value) in changes {
38- self . changes [ AnyHashable ( key) ] = . value( value)
38+ self . changes [ key. encode ( ) ] = . value( value)
3939 }
4040 }
4141
4242 // α: The core αuthorizations pool.
4343 public var coreAuthorizationPool : StateKeys . CoreAuthorizationPoolKey . Value {
4444 get {
45- changes [ StateKeys . CoreAuthorizationPoolKey ( ) ] !. value ( ) !
45+ changes [ StateKeys . CoreAuthorizationPoolKey ( ) . encode ( ) ] !. value ( ) !
4646 }
4747 set {
48- changes [ StateKeys . CoreAuthorizationPoolKey ( ) ] = . init( newValue)
48+ changes [ StateKeys . CoreAuthorizationPoolKey ( ) . encode ( ) ] = . init( newValue)
4949 }
5050 }
5151
5252 // φ: The authorization queue.
5353 public var authorizationQueue : StateKeys . AuthorizationQueueKey . Value {
5454 get {
55- changes [ StateKeys . AuthorizationQueueKey ( ) ] !. value ( ) !
55+ changes [ StateKeys . AuthorizationQueueKey ( ) . encode ( ) ] !. value ( ) !
5656 }
5757 set {
58- changes [ StateKeys . AuthorizationQueueKey ( ) ] = . init( newValue)
58+ changes [ StateKeys . AuthorizationQueueKey ( ) . encode ( ) ] = . init( newValue)
5959 }
6060 }
6161
6262 // β: Information on the most recent βlocks.
6363 public var recentHistory : StateKeys . RecentHistoryKey . Value {
6464 get {
65- changes [ StateKeys . RecentHistoryKey ( ) ] !. value ( ) !
65+ changes [ StateKeys . RecentHistoryKey ( ) . encode ( ) ] !. value ( ) !
6666 }
6767 set {
68- changes [ StateKeys . RecentHistoryKey ( ) ] = . init( newValue)
68+ changes [ StateKeys . RecentHistoryKey ( ) . encode ( ) ] = . init( newValue)
6969 }
7070 }
7171
7272 // γ: State concerning Safrole.
7373 public var safroleState : StateKeys . SafroleStateKey . Value {
7474 get {
75- changes [ StateKeys . SafroleStateKey ( ) ] !. value ( ) !
75+ changes [ StateKeys . SafroleStateKey ( ) . encode ( ) ] !. value ( ) !
7676 }
7777 set {
78- changes [ StateKeys . SafroleStateKey ( ) ] = . init( newValue)
78+ changes [ StateKeys . SafroleStateKey ( ) . encode ( ) ] = . init( newValue)
7979 }
8080 }
8181
8282 // ψ: past judgements
8383 public var judgements : StateKeys . JudgementsKey . Value {
8484 get {
85- changes [ StateKeys . JudgementsKey ( ) ] !. value ( ) !
85+ changes [ StateKeys . JudgementsKey ( ) . encode ( ) ] !. value ( ) !
8686 }
8787 set {
88- changes [ StateKeys . JudgementsKey ( ) ] = . init( newValue)
88+ changes [ StateKeys . JudgementsKey ( ) . encode ( ) ] = . init( newValue)
8989 }
9090 }
9191
9292 // η: The eηtropy accumulator and epochal raηdomness.
9393 public var entropyPool : StateKeys . EntropyPoolKey . Value {
9494 get {
95- changes [ StateKeys . EntropyPoolKey ( ) ] !. value ( ) !
95+ changes [ StateKeys . EntropyPoolKey ( ) . encode ( ) ] !. value ( ) !
9696 }
9797 set {
98- changes [ StateKeys . EntropyPoolKey ( ) ] = . init( newValue)
98+ changes [ StateKeys . EntropyPoolKey ( ) . encode ( ) ] = . init( newValue)
9999 }
100100 }
101101
102102 // ι: The validator keys and metadata to be drawn from next.
103103 public var validatorQueue : StateKeys . ValidatorQueueKey . Value {
104104 get {
105- changes [ StateKeys . ValidatorQueueKey ( ) ] !. value ( ) !
105+ changes [ StateKeys . ValidatorQueueKey ( ) . encode ( ) ] !. value ( ) !
106106 }
107107 set {
108- changes [ StateKeys . ValidatorQueueKey ( ) ] = . init( newValue)
108+ changes [ StateKeys . ValidatorQueueKey ( ) . encode ( ) ] = . init( newValue)
109109 }
110110 }
111111
112112 // κ: The validator κeys and metadata currently active.
113113 public var currentValidators : StateKeys . CurrentValidatorsKey . Value {
114114 get {
115- changes [ StateKeys . CurrentValidatorsKey ( ) ] !. value ( ) !
115+ changes [ StateKeys . CurrentValidatorsKey ( ) . encode ( ) ] !. value ( ) !
116116 }
117117 set {
118- changes [ StateKeys . CurrentValidatorsKey ( ) ] = . init( newValue)
118+ changes [ StateKeys . CurrentValidatorsKey ( ) . encode ( ) ] = . init( newValue)
119119 }
120120 }
121121
122122 // λ: The validator keys and metadata which were active in the prior epoch.
123123 public var previousValidators : StateKeys . PreviousValidatorsKey . Value {
124124 get {
125- changes [ StateKeys . PreviousValidatorsKey ( ) ] !. value ( ) !
125+ changes [ StateKeys . PreviousValidatorsKey ( ) . encode ( ) ] !. value ( ) !
126126 }
127127 set {
128- changes [ StateKeys . PreviousValidatorsKey ( ) ] = . init( newValue)
128+ changes [ StateKeys . PreviousValidatorsKey ( ) . encode ( ) ] = . init( newValue)
129129 }
130130 }
131131
132132 // ρ: The ρending reports, per core, which are being made available prior to accumulation.
133133 public var reports : StateKeys . ReportsKey . Value {
134134 get {
135- changes [ StateKeys . ReportsKey ( ) ] !. value ( ) !
135+ changes [ StateKeys . ReportsKey ( ) . encode ( ) ] !. value ( ) !
136136 }
137137 set {
138- changes [ StateKeys . ReportsKey ( ) ] = . init( newValue)
138+ changes [ StateKeys . ReportsKey ( ) . encode ( ) ] = . init( newValue)
139139 }
140140 }
141141
142142 // τ: The most recent block’s τimeslot.
143143 public var timeslot : StateKeys . TimeslotKey . Value {
144144 get {
145- changes [ StateKeys . TimeslotKey ( ) ] !. value ( ) !
145+ changes [ StateKeys . TimeslotKey ( ) . encode ( ) ] !. value ( ) !
146146 }
147147 set {
148- changes [ StateKeys . TimeslotKey ( ) ] = . init( newValue)
148+ changes [ StateKeys . TimeslotKey ( ) . encode ( ) ] = . init( newValue)
149149 }
150150 }
151151
152152 // χ: The privileged service indices.
153153 public var privilegedServices : StateKeys . PrivilegedServicesKey . Value {
154154 get {
155- changes [ StateKeys . PrivilegedServicesKey ( ) ] !. value ( ) !
155+ changes [ StateKeys . PrivilegedServicesKey ( ) . encode ( ) ] !. value ( ) !
156156 }
157157 set {
158- changes [ StateKeys . PrivilegedServicesKey ( ) ] = . init( newValue)
158+ changes [ StateKeys . PrivilegedServicesKey ( ) . encode ( ) ] = . init( newValue)
159159 }
160160 }
161161
162162 // π: The activity statistics for the validators.
163163 public var activityStatistics : StateKeys . ActivityStatisticsKey . Value {
164164 get {
165- changes [ StateKeys . ActivityStatisticsKey ( ) ] !. value ( ) !
165+ changes [ StateKeys . ActivityStatisticsKey ( ) . encode ( ) ] !. value ( ) !
166166 }
167167 set {
168- changes [ StateKeys . ActivityStatisticsKey ( ) ] = . init( newValue)
168+ changes [ StateKeys . ActivityStatisticsKey ( ) . encode ( ) ] = . init( newValue)
169169 }
170170 }
171171
172172 // ϑ: The accumulation queue.
173173 public var accumulationQueue : StateKeys . AccumulationQueueKey . Value {
174174 get {
175- changes [ StateKeys . AccumulationQueueKey ( ) ] !. value ( ) !
175+ changes [ StateKeys . AccumulationQueueKey ( ) . encode ( ) ] !. value ( ) !
176176 }
177177 set {
178- changes [ StateKeys . AccumulationQueueKey ( ) ] = . init( newValue)
178+ changes [ StateKeys . AccumulationQueueKey ( ) . encode ( ) ] = . init( newValue)
179179 }
180180 }
181181
182182 // ξ: The accumulation history.
183183 public var accumulationHistory : StateKeys . AccumulationHistoryKey . Value {
184184 get {
185- changes [ StateKeys . AccumulationHistoryKey ( ) ] !. value ( ) !
185+ changes [ StateKeys . AccumulationHistoryKey ( ) . encode ( ) ] !. value ( ) !
186186 }
187187 set {
188- changes [ StateKeys . AccumulationHistoryKey ( ) ] = . init( newValue)
188+ changes [ StateKeys . AccumulationHistoryKey ( ) . encode ( ) ] = . init( newValue)
189189 }
190190 }
191191
192192 // δ: The (prior) state of the service accounts.
193193 public subscript( serviceAccount index: ServiceIndex ) -> StateKeys . ServiceAccountKey . Value ? {
194194 get {
195- changes [ StateKeys . ServiceAccountKey ( index: index) ] ? . value ( )
195+ changes [ StateKeys . ServiceAccountKey ( index: index) . encode ( ) ] ? . value ( )
196196 }
197197 set {
198- changes [ StateKeys . ServiceAccountKey ( index: index) ] = . init( newValue)
198+ changes [ StateKeys . ServiceAccountKey ( index: index) . encode ( ) ] = . init( newValue)
199199 }
200200 }
201201
202202 // s
203203 public subscript( serviceAccount index: ServiceIndex , storageKey key: Data32 ) -> StateKeys . ServiceAccountStorageKey . Value ? {
204204 get {
205- changes [ StateKeys . ServiceAccountStorageKey ( index: index, key: key) ] ? . value ( )
205+ changes [ StateKeys . ServiceAccountStorageKey ( index: index, key: key) . encode ( ) ] ? . value ( )
206206 }
207207 set {
208- changes [ StateKeys . ServiceAccountStorageKey ( index: index, key: key) ] = . init( newValue)
208+ changes [ StateKeys . ServiceAccountStorageKey ( index: index, key: key) . encode ( ) ] = . init( newValue)
209209 }
210210 }
211211
@@ -214,10 +214,10 @@ public struct StateLayer: @unchecked Sendable {
214214 serviceAccount index: ServiceIndex , preimageHash hash: Data32
215215 ) -> StateKeys . ServiceAccountPreimagesKey . Value ? {
216216 get {
217- changes [ StateKeys . ServiceAccountPreimagesKey ( index: index, hash: hash) ] ? . value ( )
217+ changes [ StateKeys . ServiceAccountPreimagesKey ( index: index, hash: hash) . encode ( ) ] ? . value ( )
218218 }
219219 set {
220- changes [ StateKeys . ServiceAccountPreimagesKey ( index: index, hash: hash) ] = . init( newValue)
220+ changes [ StateKeys . ServiceAccountPreimagesKey ( index: index, hash: hash) . encode ( ) ] = . init( newValue)
221221 }
222222 }
223223
@@ -227,36 +227,51 @@ public struct StateLayer: @unchecked Sendable {
227227 ) -> StateKeys . ServiceAccountPreimageInfoKey . Value ? {
228228 get {
229229 changes [
230- StateKeys . ServiceAccountPreimageInfoKey ( index: index, hash: hash, length: length)
230+ StateKeys . ServiceAccountPreimageInfoKey (
231+ index: index, hash: hash, length: length
232+ ) . encode ( )
231233 ] ? . value ( )
232234 }
233235 set {
234- changes [ StateKeys . ServiceAccountPreimageInfoKey ( index: index, hash: hash, length: length) ] = . init( newValue)
236+ changes [
237+ StateKeys . ServiceAccountPreimageInfoKey (
238+ index: index, hash: hash, length: length
239+ ) . encode ( )
240+ ] = . init( newValue)
235241 }
236242 }
237243}
238244
239245extension StateLayer {
240- public func toKV( ) -> some Sequence < ( key: any StateKey , value: ( Codable & Sendable ) ? ) > {
241- changes. map { ( key: $0. key. base as! any StateKey , value: $0. value. value ( ) ) }
246+ public func toKV( ) -> some Sequence < ( key: Data32 , value: ( Codable & Sendable ) ? ) > {
247+ changes. map { ( key: $0. key, value: $0. value. value ( ) ) }
242248 }
243249}
244250
245251extension StateLayer {
246252 public func read< Key: StateKey > ( _ key: Key ) -> Key . Value ? {
247- changes [ key] as? Key . Value
253+ changes [ key. encode ( ) ] as? Key . Value
248254 }
249255
250256 public mutating func write< Key: StateKey > ( _ key: Key , value: Key . Value ? ) {
251- changes [ key] = . init( value)
257+ changes [ key. encode ( ) ] = . init( value)
252258 }
253259
254260 public subscript( key: any StateKey ) -> ( Codable & Sendable ) ? {
255261 get {
256- changes [ AnyHashable ( key) ] ? . value ( )
262+ changes [ key. encode ( ) ] ? . value ( )
263+ }
264+ set {
265+ changes [ key. encode ( ) ] = . init( newValue)
266+ }
267+ }
268+
269+ public subscript( key: Data32 ) -> ( Codable & Sendable ) ? {
270+ get {
271+ changes [ key] ? . value ( )
257272 }
258273 set {
259- changes [ AnyHashable ( key) ] = . init( newValue)
274+ changes [ key] = . init( newValue)
260275 }
261276 }
262277}
0 commit comments