Skip to content

Commit 81d6218

Browse files
committed
Introduce NextAllowedReseal type
NextAllowedReseal limits the lifetime of the inner lock.
1 parent 9e44a1d commit 81d6218

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

core/src/miner/miner.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ struct SealingWork {
113113

114114
pub struct Miner {
115115
mem_pool: Arc<RwLock<MemPool>>,
116-
next_allowed_reseal: Mutex<Instant>,
116+
next_allowed_reseal: NextAllowedReseal,
117117
next_mandatory_reseal: NextMandatoryReseal,
118118
sealing_block_last_request: Mutex<u64>,
119119
sealing_work: Mutex<SealingWork>,
@@ -129,6 +129,8 @@ pub struct Miner {
129129
immune_users: RwLock<HashSet<Address>>,
130130
}
131131

132+
type NextAllowedReseal = NextMandatoryReseal;
133+
132134
struct NextMandatoryReseal {
133135
instant: RwLock<Instant>,
134136
}
@@ -190,7 +192,7 @@ impl Miner {
190192

191193
Self {
192194
mem_pool,
193-
next_allowed_reseal: Mutex::new(Instant::now()),
195+
next_allowed_reseal: NextAllowedReseal::new(Instant::now()),
194196
next_mandatory_reseal: NextMandatoryReseal::new(Instant::now() + options.reseal_max_period),
195197
params: RwLock::new(AuthoringParams::default()),
196198
sealing_block_last_request: Mutex::new(0),
@@ -684,7 +686,7 @@ impl Miner {
684686

685687
/// Are we allowed to do a non-mandatory reseal?
686688
fn transaction_reseal_allowed(&self) -> bool {
687-
self.sealing_enabled.load(Ordering::Relaxed) && (Instant::now() > *self.next_allowed_reseal.lock())
689+
self.sealing_enabled.load(Ordering::Relaxed) && (Instant::now() > self.next_allowed_reseal.get())
688690
}
689691

690692
fn map_pending_block<F, T>(&self, f: F, latest_block_number: BlockNumber) -> Option<T>
@@ -935,7 +937,7 @@ impl MinerService for Miner {
935937
}
936938

937939
// Sealing successful
938-
*self.next_allowed_reseal.lock() = Instant::now() + self.options.reseal_min_period;
940+
self.next_allowed_reseal.set(Instant::now() + self.options.reseal_min_period);
939941
if !self.options.no_reseal_timer {
940942
chain.set_min_timer();
941943
}

0 commit comments

Comments
 (0)