-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix compiler warning (that will become an error) #10683
Changes from all commits
afb3f4e
ef48147
86a56c0
569c8fc
70b1e0c
4b6fb23
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,7 +168,7 @@ pub struct Clique { | |
block_state_by_hash: RwLock<LruCache<H256, CliqueBlockState>>, | ||
proposals: RwLock<HashMap<Address, VoteType>>, | ||
signer: RwLock<Option<Box<EngineSigner>>>, | ||
step_service: Option<Arc<StepService>>, | ||
step_service: Option<StepService>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we disallow There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's planned for the follow up PR. :) |
||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -181,30 +181,33 @@ pub struct Clique { | |
pub block_state_by_hash: RwLock<LruCache<H256, CliqueBlockState>>, | ||
pub proposals: RwLock<HashMap<Address, VoteType>>, | ||
pub signer: RwLock<Option<Box<EngineSigner>>>, | ||
pub step_service: Option<Arc<StepService>>, | ||
pub step_service: Option<StepService>, | ||
} | ||
|
||
impl Clique { | ||
/// Initialize Clique engine from empty state. | ||
pub fn new(our_params: CliqueParams, machine: EthereumMachine) -> Result<Arc<Self>, Error> { | ||
pub fn new(params: CliqueParams, machine: EthereumMachine) -> Result<Arc<Self>, Error> { | ||
let mut engine = Clique { | ||
epoch_length: our_params.epoch, | ||
period: our_params.period, | ||
epoch_length: params.epoch, | ||
period: params.period, | ||
client: Default::default(), | ||
block_state_by_hash: RwLock::new(LruCache::new(STATE_CACHE_NUM)), | ||
proposals: Default::default(), | ||
signer: Default::default(), | ||
machine, | ||
step_service: None, | ||
}; | ||
|
||
let res = Arc::new(engine); | ||
|
||
if our_params.period > 0 { | ||
engine.step_service = Some(StepService::start(Arc::downgrade(&res) as Weak<Engine<_>>)); | ||
if params.period > 0 { | ||
engine.step_service = Some(StepService::new()); | ||
let engine = Arc::new(engine); | ||
let weak_eng = Arc::downgrade(&engine); | ||
if let Some(step_service) = &engine.step_service { | ||
step_service.start(weak_eng); | ||
} | ||
Ok(engine) | ||
} else { | ||
Ok(Arc::new(engine)) | ||
} | ||
|
||
Ok(res) | ||
} | ||
|
||
#[cfg(test)] | ||
|
@@ -345,6 +348,15 @@ impl Clique { | |
} | ||
} | ||
|
||
impl Drop for Clique { | ||
fn drop(&mut self) { | ||
if let Some(step_service) = &self.step_service { | ||
trace!(target: "shutdown", "Clique; stopping step service"); | ||
step_service.stop(); | ||
} | ||
} | ||
} | ||
|
||
impl Engine<EthereumMachine> for Clique { | ||
fn name(&self) -> &str { "Clique" } | ||
|
||
|
@@ -695,7 +707,7 @@ impl Engine<EthereumMachine> for Clique { | |
trace!(target: "engine", "populate_from_parent in sealing"); | ||
|
||
// It's unclear how to prevent creating new blocks unless we are authorized, the best way (and geth does this too) | ||
// it's just to ignore setting an correct difficulty here, we will check authorization in next step in generate_seal anyway. | ||
// it's just to ignore setting a correct difficulty here, we will check authorization in next step in generate_seal anyway. | ||
if let Some(signer) = self.signer.read().as_ref() { | ||
let state = match self.state(&parent) { | ||
Err(e) => { | ||
|
@@ -744,14 +756,6 @@ impl Engine<EthereumMachine> for Clique { | |
} | ||
} | ||
|
||
fn stop(&mut self) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we actually need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It is not used and it is broken. Either remove it or change it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's planned for the follow up PR. :) (What, you a mind reader @tomusdrw ???) |
||
if let Some(mut s) = self.step_service.as_mut() { | ||
Arc::get_mut(&mut s).map(|x| x.stop()); | ||
} else { | ||
warn!(target: "engine", "Stopping `CliqueStepService` failed requires mutable access"); | ||
} | ||
} | ||
|
||
/// Clique timestamp is set to parent + period , or current time which ever is higher. | ||
fn open_block_header_timestamp(&self, parent_timestamp: u64) -> u64 { | ||
let now = time::SystemTime::now().duration_since(time::UNIX_EPOCH).unwrap_or_default(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT
Clique
is the only engine that actually implsstop()
. And theArc::get_mut
here fails every time.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you change https://github.com/paritytech/parity-ethereum/blob/master/ethcore/src/engines/mod.rs#L429 to
fn stop(&self)
it is broken, becauseEngine
is stored asArc<Engine>
and doesn't support mutation.I'm sorry that I didn't catch when reviewing it :(