@@ -15,7 +15,7 @@ const ForkInfo = params.ForkInfo;
15
15
const TOTAL_FORKS = params .TOTAL_FORKS ;
16
16
const getForkSeqByForkName = params .getForkSeqByForkName ;
17
17
18
- const DomainByTypeHashMap = std .AutoHashMap ([] const u8 , []const u8 );
18
+ const DomainByTypeHashMap = std .StringHashMap ( []const u8 );
19
19
const DomainByTypeByFork = std .ArrayList (DomainByTypeHashMap );
20
20
21
21
pub const ChainConfig = @import ("./chain/chain_config.zig" ).ChainConfig ;
@@ -173,7 +173,7 @@ pub const BeaconConfig = struct {
173
173
return if (fork .isForkPostElectra ()) self .chain .MAX_REQUEST_BLOB_SIDECARS_ELECTRA else self .chain .MAX_REQUEST_BLOB_SIDECARS ;
174
174
}
175
175
176
- pub fn getDomain (self : * BeaconConfig , state_slot : Slot , domain_type : DomainType , message_slot : ? Slot ) ! [32 ]u8 {
176
+ pub fn getDomain (self : * const BeaconConfig , state_slot : Slot , domain_type : DomainType , message_slot : ? Slot ) ! [32 ]u8 {
177
177
const slot = if (message_slot ) | s | s else state_slot ;
178
178
const epoch = @divFloor (slot , preset .SLOTS_PER_EPOCH );
179
179
const state_fork_info = self .getForkInfo (state_slot );
@@ -183,27 +183,29 @@ pub const BeaconConfig = struct {
183
183
}
184
184
185
185
// TODO: may not need this method
186
- pub fn getDomainByForkName (self : * BeaconConfig , fork_name : []const u8 , domain_type : DomainType ) ! [32 ]u8 {
186
+ pub fn getDomainByForkName (self : * const BeaconConfig , fork_name : []const u8 , domain_type : DomainType ) ! [32 ]u8 {
187
187
const fork_seq = getForkSeqByForkName (fork_name );
188
188
return try self .getDomainByForkSeq (fork_seq , domain_type );
189
189
}
190
190
191
- pub fn getDomainByForkSeq (self : * BeaconConfig , fork_seq : ForkSeq , domain_type : DomainType ) ! [32 ]u8 {
192
- if (fork_seq >= TOTAL_FORKS ) return error .ForkSeqOutOfRange ;
191
+ pub fn getDomainByForkSeq (self : * const BeaconConfig , fork_seq : ForkSeq , domain_type : DomainType ) ! [32 ]u8 {
192
+ if (@intFromEnum ( fork_seq ) >= TOTAL_FORKS ) return error .ForkSeqOutOfRange ;
193
193
194
- const domain_by_type = self .domain_cache .items [@intFromEnum (fork_seq )];
195
- const domain = domain_by_type .get (domain_type ) orelse {
194
+ var domain_by_type = self .domain_cache .items [@intFromEnum (fork_seq )];
195
+ var domain : [32 ]u8 = undefined ;
196
+
197
+ if (domain_by_type .get (& domain_type )) | d | @memcpy (& domain , d ) else {
196
198
const out = try self .allocator .create ([32 ]u8 );
197
199
const fork_info = self .forks_ascending_epoch_order [@intFromEnum (fork_seq )];
198
- computeDomain (domain_type , fork_info .version , self .genesis_validator_root , out );
199
- try domain_by_type .put (domain_type , out );
200
- return out ;
201
- };
200
+ try computeDomain (domain_type , fork_info .version , self .genesis_validator_root , out );
201
+ try domain_by_type .put (& domain_type , out );
202
+ @memcpy ( & domain , out ) ;
203
+ }
202
204
203
- return domain .* ;
205
+ return domain ;
204
206
}
205
207
206
- pub fn getDomainForVoluntaryExit (self : * BeaconConfig , state_slot : Slot , message_slot : ? Slot ) ! [32 ]u8 {
208
+ pub fn getDomainForVoluntaryExit (self : * const BeaconConfig , state_slot : Slot , message_slot : ? Slot ) ! [32 ]u8 {
207
209
const domain = if (state_slot < self .chain .DENEB_FORK_EPOCH * preset .SLOTS_PER_EPOCH ) {
208
210
return self .getDomain (state_slot , DOMAIN_VOLUNTARY_EXIT , message_slot );
209
211
} else {
@@ -217,17 +219,17 @@ pub const BeaconConfig = struct {
217
219
// may not need it for state-transition
218
220
};
219
221
220
- fn computeDomain (domain_type : DomainType , fork_version : Version , genesis_validators_root : Root , out : * [32 ]u8 ) void {
221
- computeForkDataRoot (fork_version , genesis_validators_root , out );
222
+ fn computeDomain (domain_type : DomainType , fork_version : Version , genesis_validators_root : Root , out : * [32 ]u8 ) ! void {
223
+ try computeForkDataRoot (fork_version , genesis_validators_root , out );
222
224
std .mem .copyForwards (u8 , out [0.. ], domain_type [0.. ]);
223
225
}
224
226
225
- fn computeForkDataRoot (current_version : Version , genesis_validators_root : Root , out : * [32 ]u8 ) void {
227
+ fn computeForkDataRoot (current_version : Version , genesis_validators_root : Root , out : * [32 ]u8 ) ! void {
226
228
const fork_data : ForkData = .{
227
229
.current_version = current_version ,
228
230
.genesis_validators_root = genesis_validators_root ,
229
231
};
230
- ssz .phase0 .ForkData .hashTreeRoot (& fork_data , out );
232
+ try ssz .phase0 .ForkData .hashTreeRoot (& fork_data , out );
231
233
}
232
234
233
235
// TODO: unit tests
0 commit comments