Skip to content

Commit fd846d6

Browse files
Seulgi Kimmajecty
authored andcommitted
Remove NotifyWork
1 parent d9ef016 commit fd846d6

File tree

9 files changed

+21
-199
lines changed

9 files changed

+21
-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::{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.
@@ -85,7 +82,6 @@ pub struct MinerOptions {
8582
impl Default for MinerOptions {
8683
fn default() -> Self {
8784
MinerOptions {
88-
new_work_notify: vec![],
8985
force_sealing: false,
9086
reseal_on_external_transaction: true,
9187
reseal_on_own_transaction: true,
@@ -128,17 +124,11 @@ pub struct Miner {
128124
sealing_enabled: AtomicBool,
129125

130126
accounts: Option<Arc<AccountProvider>>,
131-
notifiers: RwLock<Vec<Box<dyn NotifyWork>>>,
132127
malicious_users: RwLock<HashSet<Address>>,
133128
immune_users: RwLock<HashSet<Address>>,
134129
}
135130

136131
impl Miner {
137-
/// Push listener that will handle new jobs
138-
pub fn add_work_listener(&self, notifier: Box<dyn NotifyWork>) {
139-
self.notifiers.write().push(notifier);
140-
}
141-
142132
pub fn new(
143133
options: MinerOptions,
144134
scheme: &Scheme,
@@ -167,12 +157,6 @@ impl Miner {
167157
options.mem_pool_fees,
168158
)));
169159

170-
let notifiers: Vec<Box<dyn NotifyWork>> = if options.new_work_notify.is_empty() {
171-
Vec::new()
172-
} else {
173-
vec![Box::new(WorkPoster::new(&options.new_work_notify))]
174-
};
175-
176160
Self {
177161
mem_pool,
178162
transaction_listener: RwLock::new(vec![]),
@@ -188,7 +172,6 @@ impl Miner {
188172
options,
189173
sealing_enabled: AtomicBool::new(true),
190174
accounts,
191-
notifiers: RwLock::new(notifiers),
192175
malicious_users: RwLock::new(HashSet::new()),
193176
immune_users: RwLock::new(HashSet::new()),
194177
}
@@ -394,50 +377,29 @@ impl Miner {
394377

395378
/// Prepares work which has to be done to seal.
396379
fn prepare_work(&self, block: ClosedBlock, original_work_hash: Option<H256>) {
397-
let (work, is_new) = {
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());
380+
let mut sealing_work = self.sealing_work.lock();
381+
let last_work_hash = sealing_work.queue.peek_last_ref().map(|pb| pb.block().header().hash());
382+
ctrace!(
383+
MINER,
384+
"prepare_work: Checking whether we need to reseal: orig={:?} last={:?}, this={:?}",
385+
original_work_hash,
386+
last_work_hash,
387+
block.block().header().hash()
388+
);
389+
if last_work_hash.map_or(true, |h| h != block.block().header().hash()) {
400390
ctrace!(
401391
MINER,
402-
"prepare_work: Checking whether we need to reseal: orig={:?} last={:?}, this={:?}",
403-
original_work_hash,
404-
last_work_hash,
392+
"prepare_work: Pushing a new, refreshed or borrowed pending {}...",
405393
block.block().header().hash()
406394
);
407-
let (work, is_new) = if last_work_hash.map_or(true, |h| h != block.block().header().hash()) {
408-
ctrace!(
409-
MINER,
410-
"prepare_work: Pushing a new, refreshed or borrowed pending {}...",
411-
block.block().header().hash()
412-
);
413-
let pow_hash = *block.block().header().hash();
414-
let number = block.block().header().number();
415-
let score = *block.block().header().score();
416-
let is_new = original_work_hash.map_or(true, |h| *block.block().header().hash() != h);
417-
sealing_work.queue.push(block);
418-
// If push notifications are enabled we assume all work items are used.
419-
if !self.notifiers.read().is_empty() && is_new {
420-
sealing_work.queue.use_last_ref();
421-
}
422-
(Some((pow_hash, score, number)), is_new)
423-
} else {
424-
(None, false)
425-
};
426-
ctrace!(
427-
MINER,
428-
"prepare_work: leaving (last={:?})",
429-
sealing_work.queue.peek_last_ref().map(|b| b.block().header().hash())
430-
);
431-
(work, is_new)
395+
sealing_work.queue.push(block);
396+
// If push notifications are enabled we assume all work items are used.
432397
};
433-
if is_new {
434-
if let Some((pow_hash, score, _number)) = work {
435-
let target = self.engine.score_to_target(&score);
436-
for notifier in self.notifiers.read().iter() {
437-
notifier.notify(pow_hash, target)
438-
}
439-
}
440-
}
398+
ctrace!(
399+
MINER,
400+
"prepare_work: leaving (last={:?})",
401+
sealing_work.queue.peek_last_ref().map(|b| b.block().header().hash())
402+
);
441403
}
442404

443405
/// 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/sealing_queue.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ impl SealingQueue {
4242
/// Return a reference to the item at the top of the queue (or `None` if the queue is empty);
4343
/// this constitutes using the item and will remain in the queue for at least another
4444
/// `max_size` invocations of `push()`.
45-
pub fn use_last_ref(&mut self) -> Option<&ClosedBlock> {
45+
#[cfg(test)]
46+
fn use_last_ref(&mut self) -> Option<&ClosedBlock> {
4647
if let Some(x) = self.pending.take() {
4748
self.in_use.push(x);
4849
}

core/src/miner/work_notify.rs

Lines changed: 0 additions & 118 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,
@@ -225,7 +224,6 @@ pub struct Mining {
225224
pub mem_pool_mem_limit: Option<usize>,
226225
pub mem_pool_fee_bump_shift: Option<usize>,
227226
pub allow_create_shard: Option<bool>,
228-
pub notify_work: Option<Vec<String>>,
229227
pub force_sealing: Option<bool>,
230228
pub reseal_on_txs: Option<String>,
231229
pub reseal_min_period: Option<u64>,
@@ -398,9 +396,6 @@ impl Mining {
398396
if other.allow_create_shard.is_some() {
399397
self.allow_create_shard = other.allow_create_shard;
400398
}
401-
if other.notify_work.is_some() {
402-
self.notify_work = other.notify_work.clone();
403-
}
404399
if other.force_sealing.is_some() {
405400
self.force_sealing = other.force_sealing;
406401
}
@@ -485,9 +480,6 @@ impl Mining {
485480
if matches.is_present("allow-create-shard") {
486481
self.allow_create_shard = Some(true)
487482
}
488-
if let Some(notify_work) = matches.values_of("notify-work") {
489-
self.notify_work = Some(notify_work.map(|a| a.into()).collect());
490-
}
491483
if matches.is_present("force-sealing") {
492484
self.force_sealing = Some(true);
493485
}

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)