Skip to content

Commit 04e44a0

Browse files
Seulgi Kimmajecty
authored andcommitted
Remove map_sealing_work
1 parent 0dd6f0e commit 04e44a0

File tree

6 files changed

+11
-70
lines changed

6 files changed

+11
-70
lines changed

core/src/miner/miner.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@ pub struct MinerOptions {
7878
/// Local transactions ignore this option.
7979
pub mem_pool_fee_bump_shift: usize,
8080
pub allow_create_shard: bool,
81-
/// How many historical work packages can we store before running out?
82-
pub work_queue_size: usize,
8381
/// Minimum fees configured by the machine.
8482
pub mem_pool_fees: MemPoolFees,
8583
}
@@ -98,7 +96,6 @@ impl Default for MinerOptions {
9896
mem_pool_memory_limit: Some(2 * 1024 * 1024),
9997
mem_pool_fee_bump_shift: 3,
10098
allow_create_shard: false,
101-
work_queue_size: 20,
10299
mem_pool_fees: Default::default(),
103100
}
104101
}
@@ -184,7 +181,7 @@ impl Miner {
184181
params: RwLock::new(AuthoringParams::default()),
185182
sealing_block_last_request: Mutex::new(0),
186183
sealing_work: Mutex::new(SealingWork {
187-
queue: SealingQueue::new(options.work_queue_size),
184+
queue: SealingQueue::new(),
188185
enabled: options.force_sealing,
189186
}),
190187
engine: scheme.engine.clone(),
@@ -881,19 +878,6 @@ impl MinerService for Miner {
881878
}
882879
}
883880

884-
fn map_sealing_work<C, F, T>(&self, client: &C, f: F) -> Option<T>
885-
where
886-
C: AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo,
887-
F: FnOnce(&ClosedBlock) -> T, {
888-
ctrace!(MINER, "map_sealing_work: entering");
889-
self.prepare_work_sealing(client);
890-
ctrace!(MINER, "map_sealing_work: sealing prepared");
891-
let mut sealing_work = self.sealing_work.lock();
892-
let ret = sealing_work.queue.use_last_ref();
893-
ctrace!(MINER, "map_sealing_work: leaving use_last_ref={:?}", ret.as_ref().map(|b| b.block().header().hash()));
894-
ret.map(f)
895-
}
896-
897881
fn import_external_transactions<C: MiningBlockChainClient + EngineInfo + TermInfo>(
898882
&self,
899883
client: &C,

core/src/miner/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ pub use self::mem_pool_types::MemPoolFees;
3636
pub use self::miner::{AuthoringParams, Miner, MinerOptions};
3737
pub use self::stratum::{Config as StratumConfig, Error as StratumError, Stratum};
3838
use crate::account_provider::{AccountProvider, Error as AccountProviderError};
39-
use crate::block::ClosedBlock;
4039
use crate::client::{
4140
AccountData, BlockChainTrait, BlockProducer, EngineInfo, ImportBlock, MiningBlockChainClient, TermInfo,
4241
};
@@ -106,13 +105,6 @@ pub trait MinerService: Send + Sync {
106105
/// Will check the seal, but not actually insert the block into the chain.
107106
fn submit_seal<C: ImportBlock>(&self, chain: &C, pow_hash: BlockHash, seal: Vec<Bytes>) -> Result<(), Error>;
108107

109-
/// Get the sealing work package and if `Some`, apply some transform.
110-
fn map_sealing_work<C, F, T>(&self, client: &C, f: F) -> Option<T>
111-
where
112-
C: AccountData + BlockChainTrait + BlockProducer + ChainTimeInfo + EngineInfo + FindActionHandler + TermInfo,
113-
F: FnOnce(&ClosedBlock) -> T,
114-
Self: Sized;
115-
116108
/// Imports transactions to mem pool.
117109
fn import_external_transactions<C: MiningBlockChainClient + EngineInfo + TermInfo>(
118110
&self,

core/src/miner/sealing_queue.rs

Lines changed: 10 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,17 @@
1616

1717
use crate::block::ClosedBlock;
1818

19+
#[derive(Default)]
1920
pub struct SealingQueue {
2021
/// Not yet being sealed by a miner, but if one asks for work, we'd prefer they do this.
2122
pending: Option<ClosedBlock>,
2223
/// Currently being sealed by miners.
2324
in_use: Vec<ClosedBlock>,
24-
/// The maximum allowable number of items in_use.
25-
max_size: usize,
2625
}
2726

2827
impl SealingQueue {
29-
pub fn new(max_size: usize) -> Self {
30-
Self {
31-
pending: None,
32-
in_use: Vec::new(),
33-
max_size,
34-
}
28+
pub fn new() -> Self {
29+
Self::default()
3530
}
3631

3732
/// Return a reference to the item at the top of the queue (or `None` if the queue is empty);
@@ -50,9 +45,6 @@ impl SealingQueue {
5045
pub fn use_last_ref(&mut self) -> Option<&ClosedBlock> {
5146
if let Some(x) = self.pending.take() {
5247
self.in_use.push(x);
53-
if self.in_use.len() > self.max_size {
54-
self.in_use.remove(0);
55-
}
5648
}
5749
self.in_use.last()
5850
}
@@ -74,8 +66,6 @@ mod tests {
7466
use crate::scheme::Scheme;
7567
use crate::tests::helpers::get_temp_state_db;
7668

77-
const QUEUE_SIZE: usize = 2;
78-
7969
fn create_closed_block(address: Address) -> ClosedBlock {
8070
let scheme = Scheme::new_test();
8171
let genesis_header = scheme.genesis_header();
@@ -87,7 +77,7 @@ mod tests {
8777

8878
#[test]
8979
fn fail_to_find_when_pushed() {
90-
let mut q = SealingQueue::new(QUEUE_SIZE);
80+
let mut q = SealingQueue::new();
9181
let b = create_closed_block(Address::default());
9282
let h = b.hash();
9383

@@ -98,7 +88,7 @@ mod tests {
9888

9989
#[test]
10090
fn find_when_pushed_and_used() {
101-
let mut q = SealingQueue::new(QUEUE_SIZE);
91+
let mut q = SealingQueue::new();
10292
let b = create_closed_block(Address::default());
10393
let h = b.hash();
10494

@@ -110,7 +100,7 @@ mod tests {
110100

111101
#[test]
112102
fn find_when_others_used() {
113-
let mut q = SealingQueue::new(QUEUE_SIZE);
103+
let mut q = SealingQueue::new();
114104
let b1 = create_closed_block(Address::from(1));
115105
let b2 = create_closed_block(Address::from(2));
116106
let h1 = b1.hash();
@@ -123,24 +113,9 @@ mod tests {
123113
assert!(q.take_used_if(|b| b.hash() == h1).is_some());
124114
}
125115

126-
#[test]
127-
fn fail_to_find_when_too_many_used() {
128-
let mut q = SealingQueue::new(1);
129-
let b1 = create_closed_block(Address::from(1));
130-
let b2 = create_closed_block(Address::from(2));
131-
let h1 = b1.hash();
132-
133-
q.push(b1);
134-
q.use_last_ref();
135-
q.push(b2);
136-
q.use_last_ref();
137-
138-
assert!(q.take_used_if(|b| b.hash() == h1).is_none());
139-
}
140-
141116
#[test]
142117
fn fail_to_find_when_not_used_and_then_pushed() {
143-
let mut q = SealingQueue::new(QUEUE_SIZE);
118+
let mut q = SealingQueue::new();
144119
let b1 = create_closed_block(Address::from(1));
145120
let b2 = create_closed_block(Address::from(2));
146121
let h1 = b1.hash();
@@ -154,7 +129,7 @@ mod tests {
154129

155130
#[test]
156131
fn peek_correctly_after_push() {
157-
let mut q = SealingQueue::new(QUEUE_SIZE);
132+
let mut q = SealingQueue::new();
158133
let b1 = create_closed_block(Address::from(1));
159134
let b2 = create_closed_block(Address::from(2));
160135
let h1 = b1.hash();
@@ -169,7 +144,7 @@ mod tests {
169144

170145
#[test]
171146
fn inspect_correctly() {
172-
let mut q = SealingQueue::new(QUEUE_SIZE);
147+
let mut q = SealingQueue::new();
173148
let b1 = create_closed_block(Address::from(1));
174149
let b2 = create_closed_block(Address::from(2));
175150
let h1 = b1.hash();
@@ -186,7 +161,7 @@ mod tests {
186161

187162
#[test]
188163
fn fail_to_find_when_not_used_peeked_and_then_pushed() {
189-
let mut q = SealingQueue::new(QUEUE_SIZE);
164+
let mut q = SealingQueue::new();
190165
let b1 = create_closed_block(Address::from(1));
191166
let b2 = create_closed_block(Address::from(2));
192167
let h = b1.hash();

foundry/config/mod.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ impl Config {
107107
reseal_min_period: Duration::from_millis(self.mining.reseal_min_period.unwrap()),
108108
reseal_max_period: Duration::from_millis(self.mining.reseal_max_period.unwrap()),
109109
no_reseal_timer: self.mining.no_reseal_timer.unwrap(),
110-
work_queue_size: self.mining.work_queue_size.unwrap(),
111110
mem_pool_fees,
112111
})
113112
}
@@ -245,7 +244,6 @@ pub struct Mining {
245244
pub reseal_min_period: Option<u64>,
246245
pub reseal_max_period: Option<u64>,
247246
pub no_reseal_timer: Option<bool>,
248-
pub work_queue_size: Option<usize>,
249247
pub allowed_past_gap: Option<u64>,
250248
pub allowed_future_gap: Option<u64>,
251249
pub min_pay_transaction_cost: Option<u64>,
@@ -439,9 +437,6 @@ impl Mining {
439437
if other.no_reseal_timer.is_some() {
440438
self.no_reseal_timer = other.no_reseal_timer;
441439
}
442-
if other.work_queue_size.is_some() {
443-
self.work_queue_size = other.work_queue_size;
444-
}
445440
if other.min_pay_transaction_cost.is_some() {
446441
self.min_pay_transaction_cost = other.min_pay_transaction_cost;
447442
}
@@ -529,9 +524,6 @@ impl Mining {
529524
if matches.is_present("no-reseal-timer") {
530525
self.no_reseal_timer = Some(true);
531526
}
532-
if let Some(work_queue_size) = matches.value_of("work-queue-size") {
533-
self.work_queue_size = Some(work_queue_size.parse().map_err(|_| "Invalid size")?);
534-
}
535527
if let Some(allowed_past_gap) = matches.value_of("allowed-past-gap") {
536528
self.allowed_past_gap = Some(allowed_past_gap.parse().map_err(|_| "Invalid time gap")?);
537529
}

foundry/config/presets/config.dev.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ reseal_on_txs = "all"
1414
reseal_min_period = 0
1515
reseal_max_period = 120000
1616
no_reseal_timer = false
17-
work_queue_size = 20
1817
allowed_past_gap = 30000
1918
allowed_future_gap = 5000
2019

foundry/config/presets/config.prod.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ reseal_on_txs = "all"
1414
reseal_min_period = 4000
1515
reseal_max_period = 120000
1616
no_reseal_timer = false
17-
work_queue_size = 20
1817
allowed_past_gap = 30000
1918
allowed_future_gap = 5000
2019

0 commit comments

Comments
 (0)