@@ -114,7 +114,7 @@ struct SealingWork {
114
114
pub struct Miner {
115
115
mem_pool : Arc < RwLock < MemPool > > ,
116
116
next_allowed_reseal : Mutex < Instant > ,
117
- next_mandatory_reseal : RwLock < Instant > ,
117
+ next_mandatory_reseal : NextMandatoryReseal ,
118
118
sealing_block_last_request : Mutex < u64 > ,
119
119
sealing_work : Mutex < SealingWork > ,
120
120
params : RwLock < AuthoringParams > ,
@@ -129,6 +129,26 @@ pub struct Miner {
129
129
immune_users : RwLock < HashSet < Address > > ,
130
130
}
131
131
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
+
132
152
impl Miner {
133
153
/// Push listener that will handle new jobs
134
154
pub fn add_work_listener ( & self , notifier : Box < dyn NotifyWork > ) {
@@ -171,7 +191,7 @@ impl Miner {
171
191
Self {
172
192
mem_pool,
173
193
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 ) ,
175
195
params : RwLock :: new ( AuthoringParams :: default ( ) ) ,
176
196
sealing_block_last_request : Mutex :: new ( 0 ) ,
177
197
sealing_work : Mutex :: new ( SealingWork {
@@ -620,7 +640,7 @@ impl Miner {
620
640
C : BlockChainTrait + ImportBlock , {
621
641
if block. transactions ( ) . is_empty ( )
622
642
&& !self . options . force_sealing
623
- && Instant :: now ( ) <= * self . next_mandatory_reseal . read ( )
643
+ && Instant :: now ( ) <= self . next_mandatory_reseal . get ( )
624
644
{
625
645
cdebug ! ( MINER , "seal_block_internally: no sealing." ) ;
626
646
return false
@@ -637,7 +657,7 @@ impl Miner {
637
657
return false
638
658
}
639
659
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 ) ;
641
661
let sealed = if self . engine_type ( ) . is_seal_first ( ) {
642
662
block. lock ( ) . already_sealed ( )
643
663
} else {
0 commit comments