@@ -117,7 +117,7 @@ pub struct Miner {
117
117
next_mandatory_reseal : NextMandatoryReseal ,
118
118
sealing_block_last_request : Mutex < u64 > ,
119
119
sealing_work : Mutex < SealingWork > ,
120
- params : RwLock < AuthoringParams > ,
120
+ params : Params ,
121
121
engine : Arc < dyn CodeChainEngine > ,
122
122
options : MinerOptions ,
123
123
@@ -151,6 +151,29 @@ impl NextMandatoryReseal {
151
151
}
152
152
}
153
153
154
+ struct Params {
155
+ params : RwLock < AuthoringParams > ,
156
+ }
157
+
158
+ impl Params {
159
+ pub fn new ( params : AuthoringParams ) -> Self {
160
+ Self {
161
+ params : RwLock :: new ( params) ,
162
+ }
163
+ }
164
+
165
+ pub fn get ( & self ) -> AuthoringParams {
166
+ self . params . read ( ) . clone ( )
167
+ }
168
+
169
+ pub fn apply < F > ( & self , f : F )
170
+ where
171
+ F : FnOnce ( & mut AuthoringParams ) -> ( ) , {
172
+ let mut params = self . params . write ( ) ;
173
+ f ( & mut params) ;
174
+ }
175
+ }
176
+
154
177
impl Miner {
155
178
/// Push listener that will handle new jobs
156
179
pub fn add_work_listener ( & self , notifier : Box < dyn NotifyWork > ) {
@@ -194,7 +217,7 @@ impl Miner {
194
217
mem_pool,
195
218
next_allowed_reseal : NextAllowedReseal :: new ( Instant :: now ( ) ) ,
196
219
next_mandatory_reseal : NextMandatoryReseal :: new ( Instant :: now ( ) + options. reseal_max_period ) ,
197
- params : RwLock :: new ( AuthoringParams :: default ( ) ) ,
220
+ params : Params :: new ( AuthoringParams :: default ( ) ) ,
198
221
sealing_block_last_request : Mutex :: new ( 0 ) ,
199
222
sealing_work : Mutex :: new ( SealingWork {
200
223
queue : SealingQueue :: new ( options. work_queue_size ) ,
@@ -492,7 +515,7 @@ impl Miner {
492
515
493
516
let last_work_hash = sealing_work. queue . peek_last_ref ( ) . map ( |pb| * pb. block ( ) . header ( ) . hash ( ) ) ;
494
517
ctrace ! ( MINER , "prepare_block: No existing work - making new block" ) ;
495
- let params = self . params . read ( ) . clone ( ) ;
518
+ let params = self . params . get ( ) ;
496
519
let open_block = chain. prepare_open_block ( parent_block_id, params. author , params. extra_data ) ;
497
520
let ( block_number, parent_hash) = {
498
521
let header = open_block. block ( ) . header ( ) ;
@@ -731,11 +754,11 @@ impl MinerService for Miner {
731
754
}
732
755
733
756
fn authoring_params ( & self ) -> AuthoringParams {
734
- self . params . read ( ) . clone ( )
757
+ self . params . get ( )
735
758
}
736
759
737
760
fn set_author ( & self , address : Address ) -> Result < ( ) , AccountProviderError > {
738
- self . params . write ( ) . author = address;
761
+ self . params . apply ( |params| params . author = address) ;
739
762
740
763
if self . engine_type ( ) . need_signer_key ( ) && self . engine . seals_internally ( ) . is_some ( ) {
741
764
if let Some ( ref ap) = self . accounts {
@@ -759,7 +782,7 @@ impl MinerService for Miner {
759
782
}
760
783
761
784
fn set_extra_data ( & self , extra_data : Bytes ) {
762
- self . params . write ( ) . extra_data = extra_data;
785
+ self . params . apply ( |params| params . extra_data = extra_data) ;
763
786
}
764
787
765
788
fn minimal_fee ( & self ) -> u64 {
0 commit comments