Skip to content

Commit c816527

Browse files
author
Seulgi Kim
committed
Remove NotifyWork
1 parent 57061ee commit c816527

File tree

8 files changed

+19
-199
lines changed

8 files changed

+19
-199
lines changed

core/src/consensus/mod.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use ctypes::errors::SyntaxError;
4242
use ctypes::transaction::Action;
4343
use ctypes::util::unexpected::{Mismatch, OutOfBounds};
4444
use ctypes::{BlockHash, CommonParams, Header};
45-
use primitives::{Bytes, U256};
45+
use primitives::Bytes;
4646

4747
use self::bit_set::BitSet;
4848
use crate::account_provider::AccountProvider;
@@ -221,10 +221,6 @@ pub trait ConsensusEngine: Sync + Send {
221221

222222
fn register_time_gap_config_to_worker(&self, _time_gap_params: TimeGapParams) {}
223223

224-
fn score_to_target(&self, _score: &U256) -> U256 {
225-
U256::zero()
226-
}
227-
228224
fn block_reward(&self, block_number: u64) -> u64;
229225

230226
fn block_fee(&self, transactions: Box<dyn Iterator<Item = UnverifiedTransaction>>) -> u64 {

core/src/miner/miner.rs

Lines changed: 18 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ use super::mem_pool::{Error as MemPoolError, MemPool};
3636
pub use super::mem_pool_types::MemPoolFees;
3737
use super::mem_pool_types::{AccountDetails, MemPoolInput, TxOrigin, TxTimelock};
3838
use super::sealing_queue::SealingQueue;
39-
use super::work_notify::{NotifyWork, WorkPoster};
4039
use super::{MinerService, MinerStatus, TransactionImportResult};
4140
use crate::account_provider::{AccountProvider, Error as AccountProviderError};
4241
use crate::block::{Block, ClosedBlock, IsBlock};
@@ -54,8 +53,6 @@ use std::borrow::Borrow;
5453
/// Configures the behaviour of the miner.
5554
#[derive(Debug, PartialEq)]
5655
pub struct MinerOptions {
57-
/// URLs to notify when there is new work.
58-
pub new_work_notify: Vec<String>,
5956
/// Force the miner to reseal, even when nobody has asked for work.
6057
pub force_sealing: bool,
6158
/// Reseal on receipt of new external transactions.
@@ -87,7 +84,6 @@ pub struct MinerOptions {
8784
impl Default for MinerOptions {
8885
fn default() -> Self {
8986
MinerOptions {
90-
new_work_notify: vec![],
9187
force_sealing: false,
9288
reseal_on_external_transaction: true,
9389
reseal_on_own_transaction: true,
@@ -131,17 +127,11 @@ pub struct Miner {
131127
sealing_enabled: AtomicBool,
132128

133129
accounts: Option<Arc<AccountProvider>>,
134-
notifiers: RwLock<Vec<Box<dyn NotifyWork>>>,
135130
malicious_users: RwLock<HashSet<Address>>,
136131
immune_users: RwLock<HashSet<Address>>,
137132
}
138133

139134
impl Miner {
140-
/// Push listener that will handle new jobs
141-
pub fn add_work_listener(&self, notifier: Box<dyn NotifyWork>) {
142-
self.notifiers.write().push(notifier);
143-
}
144-
145135
pub fn new(
146136
options: MinerOptions,
147137
scheme: &Scheme,
@@ -170,12 +160,6 @@ impl Miner {
170160
options.mem_pool_fees,
171161
)));
172162

173-
let notifiers: Vec<Box<dyn NotifyWork>> = if options.new_work_notify.is_empty() {
174-
Vec::new()
175-
} else {
176-
vec![Box::new(WorkPoster::new(&options.new_work_notify))]
177-
};
178-
179163
Self {
180164
mem_pool,
181165
transaction_listener: RwLock::new(vec![]),
@@ -191,7 +175,6 @@ impl Miner {
191175
options,
192176
sealing_enabled: AtomicBool::new(true),
193177
accounts,
194-
notifiers: RwLock::new(notifiers),
195178
malicious_users: RwLock::new(HashSet::new()),
196179
immune_users: RwLock::new(HashSet::new()),
197180
}
@@ -412,50 +395,29 @@ impl Miner {
412395

413396
/// Prepares work which has to be done to seal.
414397
fn prepare_work(&self, block: ClosedBlock, original_work_hash: Option<H256>) {
415-
let (work, is_new) = {
416-
let mut sealing_work = self.sealing_work.lock();
417-
let last_work_hash = sealing_work.queue.peek_last_ref().map(|pb| pb.block().header().hash());
398+
let mut sealing_work = self.sealing_work.lock();
399+
let last_work_hash = sealing_work.queue.peek_last_ref().map(|pb| pb.block().header().hash());
400+
ctrace!(
401+
MINER,
402+
"prepare_work: Checking whether we need to reseal: orig={:?} last={:?}, this={:?}",
403+
original_work_hash,
404+
last_work_hash,
405+
block.block().header().hash()
406+
);
407+
if last_work_hash.map_or(true, |h| h != block.block().header().hash()) {
418408
ctrace!(
419409
MINER,
420-
"prepare_work: Checking whether we need to reseal: orig={:?} last={:?}, this={:?}",
421-
original_work_hash,
422-
last_work_hash,
410+
"prepare_work: Pushing a new, refreshed or borrowed pending {}...",
423411
block.block().header().hash()
424412
);
425-
let (work, is_new) = if last_work_hash.map_or(true, |h| h != block.block().header().hash()) {
426-
ctrace!(
427-
MINER,
428-
"prepare_work: Pushing a new, refreshed or borrowed pending {}...",
429-
block.block().header().hash()
430-
);
431-
let pow_hash = *block.block().header().hash();
432-
let number = block.block().header().number();
433-
let score = *block.block().header().score();
434-
let is_new = original_work_hash.map_or(true, |h| *block.block().header().hash() != h);
435-
sealing_work.queue.push(block);
436-
// If push notifications are enabled we assume all work items are used.
437-
if !self.notifiers.read().is_empty() && is_new {
438-
sealing_work.queue.use_last_ref();
439-
}
440-
(Some((pow_hash, score, number)), is_new)
441-
} else {
442-
(None, false)
443-
};
444-
ctrace!(
445-
MINER,
446-
"prepare_work: leaving (last={:?})",
447-
sealing_work.queue.peek_last_ref().map(|b| b.block().header().hash())
448-
);
449-
(work, is_new)
413+
sealing_work.queue.push(block);
414+
// If push notifications are enabled we assume all work items are used.
450415
};
451-
if is_new {
452-
if let Some((pow_hash, score, _number)) = work {
453-
let target = self.engine.score_to_target(&score);
454-
for notifier in self.notifiers.read().iter() {
455-
notifier.notify(pow_hash, target)
456-
}
457-
}
458-
}
416+
ctrace!(
417+
MINER,
418+
"prepare_work: leaving (last={:?})",
419+
sealing_work.queue.peek_last_ref().map(|b| b.block().header().hash())
420+
);
459421
}
460422

461423
/// Prepares new block for sealing including top transactions from queue.

core/src/miner/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ mod mem_pool_types;
2020
#[cfg_attr(feature = "cargo-clippy", allow(clippy::module_inception))]
2121
mod miner;
2222
mod sealing_queue;
23-
mod work_notify;
2423

2524
use std::ops::Range;
2625

core/src/miner/work_notify.rs

Lines changed: 0 additions & 119 deletions
This file was deleted.

foundry/config/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ impl Config {
9898
},
9999
mem_pool_fee_bump_shift: self.mining.mem_pool_fee_bump_shift.unwrap(),
100100
allow_create_shard: self.mining.allow_create_shard.unwrap_or(false),
101-
new_work_notify: self.mining.notify_work.clone().unwrap(),
102101
force_sealing: self.mining.force_sealing.unwrap(),
103102
reseal_on_own_transaction,
104103
reseal_on_external_transaction,
@@ -226,7 +225,6 @@ pub struct Mining {
226225
pub mem_pool_mem_limit: Option<usize>,
227226
pub mem_pool_fee_bump_shift: Option<usize>,
228227
pub allow_create_shard: Option<bool>,
229-
pub notify_work: Option<Vec<String>>,
230228
pub force_sealing: Option<bool>,
231229
pub reseal_on_txs: Option<String>,
232230
pub reseal_min_period: Option<u64>,
@@ -400,9 +398,6 @@ impl Mining {
400398
if other.allow_create_shard.is_some() {
401399
self.allow_create_shard = other.allow_create_shard;
402400
}
403-
if other.notify_work.is_some() {
404-
self.notify_work = other.notify_work.clone();
405-
}
406401
if other.force_sealing.is_some() {
407402
self.force_sealing = other.force_sealing;
408403
}
@@ -490,9 +485,6 @@ impl Mining {
490485
if matches.is_present("allow-create-shard") {
491486
self.allow_create_shard = Some(true)
492487
}
493-
if let Some(notify_work) = matches.values_of("notify-work") {
494-
self.notify_work = Some(notify_work.map(|a| a.into()).collect());
495-
}
496488
if matches.is_present("force-sealing") {
497489
self.force_sealing = Some(true);
498490
}

foundry/config/presets/config.dev.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ mem_pool_mem_limit = 4 # MB
88
mem_pool_size = 32768
99
mem_pool_fee_bump_shift = 3 # 12.5%
1010
allow_create_shard = false
11-
notify_work = []
1211
force_sealing = false
1312
reseal_on_txs = "all"
1413
reseal_min_period = 0

foundry/config/presets/config.prod.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ mem_pool_mem_limit = 512 # MB
88
mem_pool_size = 524288
99
mem_pool_fee_bump_shift = 3 # 12.5%
1010
allow_create_shard = false
11-
notify_work = []
1211
force_sealing = true
1312
reseal_on_txs = "all"
1413
reseal_min_period = 4000

foundry/foundry.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,14 +183,6 @@ args:
183183
long: allow-create-shard
184184
help: Make the miner allow CreateShard transactions
185185
takes_value: false
186-
- notify-work:
187-
long: notify-work
188-
value_name: URLS
189-
help: URLs to which work package notifications are pushed.
190-
takes_value: true
191-
multiple: true
192-
conflicts_with:
193-
- no-miner
194186
- force-sealing:
195187
long: force-sealing
196188
help: Force the node to author new blocks as if it were always sealing/mining.

0 commit comments

Comments
 (0)