Skip to content

Commit 0195fe7

Browse files
committed
Add reseal-on-txs option
1 parent d8e4f96 commit 0195fe7

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed

codechain/codechain.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,15 @@ args:
128128
long: force-sealing
129129
help: Force the node to author new blocks as if it were always sealing/mining.
130130
takes_value: false
131+
- reseal-on-txs:
132+
long: reseal-on-txs
133+
help: Specify which transactions should force the node to reseal a block.
134+
takes_value: true
135+
possible_values:
136+
- none
137+
- own
138+
- ext
139+
- all
131140
- reseal-min-period:
132141
long: reseal-min-period
133142
value_name: MS

codechain/config/mod.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,35 @@ pub struct Config {
4545
}
4646

4747
impl Config {
48-
pub fn miner_options(&self) -> MinerOptions {
49-
MinerOptions {
48+
pub fn miner_options(&self) -> Result<MinerOptions, String> {
49+
let (reseal_on_own_parcel, reseal_on_external_parcel) = match self.mining.reseal_on_txs.as_ref() {
50+
"all" => (true, true),
51+
"own" => (true, false),
52+
"ext" => (false, true),
53+
"none" => (false, false),
54+
x => {
55+
return Err(format!(
56+
"{} isn't a valid value for reseal-on-txs. Possible values are all, own, ext, none",
57+
x
58+
))
59+
}
60+
};
61+
62+
Ok(MinerOptions {
5063
mem_pool_size: self.mining.mem_pool_size,
5164
mem_pool_memory_limit: match self.mining.mem_pool_mem_limit {
5265
0 => None,
5366
mem_size => Some(mem_size * 1024 * 1024),
5467
},
5568
new_work_notify: self.mining.notify_work.clone(),
5669
force_sealing: self.mining.force_sealing,
70+
reseal_on_own_parcel,
71+
reseal_on_external_parcel,
5772
reseal_min_period: Duration::from_millis(self.mining.reseal_min_period),
5873
reseal_max_period: Duration::from_millis(self.mining.reseal_max_period),
5974
work_queue_size: self.mining.work_queue_size,
6075
..MinerOptions::default()
61-
}
76+
})
6277
}
6378

6479
pub fn rpc_http_config(&self) -> RpcHttpConfig {
@@ -142,6 +157,7 @@ pub struct Mining {
142157
pub mem_pool_mem_limit: usize,
143158
pub notify_work: Vec<String>,
144159
pub force_sealing: bool,
160+
pub reseal_on_txs: String,
145161
pub reseal_min_period: u64,
146162
pub reseal_max_period: u64,
147163
pub work_queue_size: usize,
@@ -255,6 +271,9 @@ impl Mining {
255271
if matches.is_present("force-sealing") {
256272
self.force_sealing = true;
257273
}
274+
if let Some(reseal_on_txs) = matches.value_of("reseal-on-txs") {
275+
self.reseal_on_txs = reseal_on_txs.to_string();
276+
}
258277
if let Some(reseal_min_period) = matches.value_of("reseal-min-period") {
259278
self.reseal_min_period = reseal_min_period.parse().map_err(|_| "Invalid period")?;
260279
}

codechain/config/presets/config.dev.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mem_pool_mem_limit = 4 # MB
99
mem_pool_size = 8192
1010
notify_work = []
1111
force_sealing = false
12+
reseal_on_txs = "all"
1213
reseal_min_period = 0
1314
reseal_max_period = 120000
1415
work_queue_size = 20

codechain/run_node.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ fn stratum_start(cfg: StratumConfig, miner: Arc<Miner>, client: Arc<Client>) ->
106106
}
107107

108108
fn new_miner(config: &config::Config, scheme: &Scheme, ap: Arc<AccountProvider>) -> Result<Arc<Miner>, String> {
109-
let miner = Miner::new(config.miner_options(), scheme, Some(ap.clone()));
109+
let miner = Miner::new(config.miner_options()?, scheme, Some(ap.clone()));
110110
match miner.engine_type() {
111111
EngineType::PoW => match &config.mining.author {
112112
Some(ref author) => {

0 commit comments

Comments
 (0)