@@ -114,7 +114,7 @@ struct SealingWork {
114114pub struct Miner {
115115 mem_pool : Arc < RwLock < MemPool > > ,
116116 next_allowed_reseal : Mutex < Instant > ,
117- next_mandatory_reseal : RwLock < Instant > ,
117+ next_mandatory_reseal : NextMandatoryReseal ,
118118 sealing_block_last_request : Mutex < u64 > ,
119119 sealing_work : Mutex < SealingWork > ,
120120 params : RwLock < AuthoringParams > ,
@@ -129,6 +129,26 @@ pub struct Miner {
129129 immune_users : RwLock < HashSet < Address > > ,
130130}
131131
132+ struct NextMandatoryReseal {
133+ instant : RwLock < Instant > ,
134+ }
135+
136+ impl NextMandatoryReseal {
137+ pub fn new ( instant : Instant ) -> Self {
138+ Self {
139+ instant : RwLock :: new ( instant) ,
140+ }
141+ }
142+
143+ pub fn get ( & self ) -> Instant {
144+ * self . instant . read ( )
145+ }
146+
147+ pub fn set ( & self , instant : Instant ) {
148+ * self . instant . write ( ) = instant;
149+ }
150+ }
151+
132152impl Miner {
133153 /// Push listener that will handle new jobs
134154 pub fn add_work_listener ( & self , notifier : Box < dyn NotifyWork > ) {
@@ -171,7 +191,7 @@ impl Miner {
171191 Self {
172192 mem_pool,
173193 next_allowed_reseal : Mutex :: new ( Instant :: now ( ) ) ,
174- next_mandatory_reseal : RwLock :: new ( Instant :: now ( ) + options. reseal_max_period ) ,
194+ next_mandatory_reseal : NextMandatoryReseal :: new ( Instant :: now ( ) + options. reseal_max_period ) ,
175195 params : RwLock :: new ( AuthoringParams :: default ( ) ) ,
176196 sealing_block_last_request : Mutex :: new ( 0 ) ,
177197 sealing_work : Mutex :: new ( SealingWork {
@@ -620,7 +640,7 @@ impl Miner {
620640 C : BlockChainTrait + ImportBlock , {
621641 if block. transactions ( ) . is_empty ( )
622642 && !self . options . force_sealing
623- && Instant :: now ( ) <= * self . next_mandatory_reseal . read ( )
643+ && Instant :: now ( ) <= self . next_mandatory_reseal . get ( )
624644 {
625645 cdebug ! ( MINER , "seal_block_internally: no sealing." ) ;
626646 return false
@@ -637,7 +657,7 @@ impl Miner {
637657 return false
638658 }
639659
640- * self . next_mandatory_reseal . write ( ) = Instant :: now ( ) + self . options . reseal_max_period ;
660+ self . next_mandatory_reseal . set ( Instant :: now ( ) + self . options . reseal_max_period ) ;
641661 let sealed = if self . engine_type ( ) . is_seal_first ( ) {
642662 block. lock ( ) . already_sealed ( )
643663 } else {
0 commit comments