Skip to content

Commit 01a77e1

Browse files
author
Hyunsik Jeong
committed
Add flag to disable reseal timer
1 parent 723833e commit 01a77e1

File tree

5 files changed

+25
-2
lines changed

5 files changed

+25
-2
lines changed

codechain/codechain.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,12 @@ args:
192192
takes_value: true
193193
conflicts_with:
194194
- no-miner
195+
- no-reseal-timer:
196+
long: no-reseal-timer
197+
help: Do not use reseal timer.
198+
takes_value: false
199+
conflicts_with:
200+
- no-miner
195201
- work-queue-size:
196202
long: work-queue-size
197203
value_name: ITEMS

codechain/config/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ impl Config {
8383
reseal_on_external_parcel,
8484
reseal_min_period: Duration::from_millis(self.mining.reseal_min_period.unwrap()),
8585
reseal_max_period: Duration::from_millis(self.mining.reseal_max_period.unwrap()),
86+
no_reseal_timer: self.mining.no_reseal_timer.unwrap(),
8687
work_queue_size: self.mining.work_queue_size.unwrap(),
8788
})
8889
}
@@ -218,6 +219,7 @@ pub struct Mining {
218219
pub reseal_on_txs: Option<String>,
219220
pub reseal_min_period: Option<u64>,
220221
pub reseal_max_period: Option<u64>,
222+
pub no_reseal_timer: Option<bool>,
221223
pub work_queue_size: Option<usize>,
222224
}
223225

@@ -375,6 +377,9 @@ impl Mining {
375377
if other.reseal_max_period.is_some() {
376378
self.reseal_max_period = other.reseal_max_period;
377379
}
380+
if other.no_reseal_timer.is_some() {
381+
self.no_reseal_timer = other.no_reseal_timer;
382+
}
378383
if other.work_queue_size.is_some() {
379384
self.work_queue_size = other.work_queue_size;
380385
}
@@ -412,6 +417,9 @@ impl Mining {
412417
if let Some(reseal_max_period) = matches.value_of("reseal-max-period") {
413418
self.reseal_max_period = Some(reseal_max_period.parse().map_err(|_| "Invalid period")?);
414419
}
420+
if matches.is_present("no-reseal-timer") {
421+
self.no_reseal_timer = Some(true);
422+
}
415423
if let Some(work_queue_size) = matches.value_of("work-queue-size") {
416424
self.work_queue_size = Some(work_queue_size.parse().map_err(|_| "Invalid size")?);
417425
}

codechain/config/presets/config.dev.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ force_sealing = false
1313
reseal_on_txs = "all"
1414
reseal_min_period = 0
1515
reseal_max_period = 120000
16+
no_reseal_timer = false
1617
work_queue_size = 20
1718

1819
[network]

codechain/config/presets/config.prod.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ force_sealing = true
1212
reseal_on_txs = "all"
1313
reseal_min_period = 4000
1414
reseal_max_period = 120000
15+
no_reseal_timer = false
1516
work_queue_size = 20
1617

1718
[network]

core/src/miner/miner.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ pub struct MinerOptions {
6262
pub reseal_min_period: Duration,
6363
/// Maximum period between blocks (enables force sealing after that).
6464
pub reseal_max_period: Duration,
65+
/// Disable the reseal timer
66+
pub no_reseal_timer: bool,
6567
/// Maximum size of the mem pool.
6668
pub mem_pool_size: usize,
6769
/// Maximum memory usage of parcels in the queue (current / future).
@@ -79,6 +81,7 @@ impl Default for MinerOptions {
7981
reseal_on_own_parcel: true,
8082
reseal_min_period: Duration::from_secs(2),
8183
reseal_max_period: Duration::from_secs(120),
84+
no_reseal_timer: false,
8285
mem_pool_size: 8192,
8386
mem_pool_memory_limit: Some(2 * 1024 * 1024),
8487
work_queue_size: 20,
@@ -746,13 +749,17 @@ impl MinerService for Miner {
746749
self.prepare_work(block, original_work_hash);
747750
// Set the reseal max timer, for creating empty blocks every reseal_max_period
748751
// Not related to next_mandatory_reseal, which is used in seal_and_import_block_internally
749-
chain.set_max_timer();
752+
if !self.options.no_reseal_timer {
753+
chain.set_max_timer();
754+
}
750755
}
751756
}
752757

753758
// Sealing successful
754759
*self.next_allowed_reseal.lock() = Instant::now() + self.options.reseal_min_period;
755-
chain.set_min_timer();
760+
if !self.options.no_reseal_timer {
761+
chain.set_min_timer();
762+
}
756763
}
757764
}
758765

0 commit comments

Comments
 (0)