@@ -9,7 +9,7 @@ use std::cmp::Ordering;
9
9
use std:: io:: { Read , Write } ;
10
10
use std:: ops:: RangeInclusive ;
11
11
use std:: str:: FromStr ;
12
- use std:: sync:: LazyLock ;
12
+ use std:: sync:: { Arc , LazyLock } ;
13
13
use superstruct:: superstruct;
14
14
use types:: historical_summary:: HistoricalSummary ;
15
15
use types:: { BeaconState , ChainSpec , Epoch , EthSpec , Hash256 , List , Slot , Validator } ;
@@ -100,7 +100,7 @@ pub struct HDiffBuffer {
100
100
state : Vec < u8 > ,
101
101
balances : Vec < u64 > ,
102
102
inactivity_scores : Vec < u64 > ,
103
- validators : Vec < Validator > ,
103
+ validators : Arc < [ Validator ] > ,
104
104
historical_roots : Vec < Hash256 > ,
105
105
historical_summaries : Vec < HistoricalSummary > ,
106
106
}
@@ -184,6 +184,7 @@ impl HDiffBuffer {
184
184
vec ! [ ]
185
185
} ;
186
186
let validators = std:: mem:: take ( beacon_state. validators_mut ( ) ) . to_vec ( ) ;
187
+ let validators = Arc :: from ( validators) ;
187
188
let historical_roots = std:: mem:: take ( beacon_state. historical_roots_mut ( ) ) . to_vec ( ) ;
188
189
let historical_summaries =
189
190
if let Ok ( historical_summaries) = beacon_state. historical_summaries_mut ( ) {
@@ -282,8 +283,11 @@ impl HDiff {
282
283
self . balances_diff ( ) . apply ( & mut source. balances , config) ?;
283
284
self . inactivity_scores_diff ( )
284
285
. apply ( & mut source. inactivity_scores , config) ?;
285
- self . validators_diff ( )
286
- . apply ( & mut source. validators , config) ?;
286
+
287
+ let mut validators_vec = source. validators . to_vec ( ) ;
288
+ self . validators_diff ( ) . apply ( & mut validators_vec, config) ?;
289
+ source. validators = Arc :: from ( validators_vec) ;
290
+
287
291
self . historical_roots ( ) . apply ( & mut source. historical_roots ) ;
288
292
self . historical_summaries ( )
289
293
. apply ( & mut source. historical_summaries ) ;
@@ -972,15 +976,15 @@ mod tests {
972
976
state : vec ! [ 0 , 1 , 2 , 3 , 3 , 2 , 1 , 0 ] ,
973
977
balances : pre_balances,
974
978
inactivity_scores : pre_inactivity_scores,
975
- validators : pre_validators,
979
+ validators : Arc :: from ( pre_validators) ,
976
980
historical_roots : pre_historical_roots,
977
981
historical_summaries : pre_historical_summaries,
978
982
} ;
979
983
let post_buffer = HDiffBuffer {
980
984
state : vec ! [ 0 , 1 , 3 , 2 , 2 , 3 , 1 , 1 ] ,
981
985
balances : post_balances,
982
986
inactivity_scores : post_inactivity_scores,
983
- validators : post_validators,
987
+ validators : Arc :: from ( post_validators) ,
984
988
historical_roots : post_historical_roots,
985
989
historical_summaries : post_historical_summaries,
986
990
} ;
0 commit comments